Nux

Merge lp:~azzar1/nux/focus-on-enter into lp:nux/2.0

Proposed by Andrea Azzarone
Status: Merged
Approved by: Jay Taoko
Approved revision: 578
Merged at revision: 576
Proposed branch: lp:~azzar1/nux/focus-on-enter
Merge into: lp:nux/2.0
Diff against target: 363 lines (+193/-16)
8 files modified
Nux/Area.h (+1/-1)
Nux/InputArea.cpp (+17/-6)
Nux/InputArea.h (+9/-4)
Nux/WindowCompositor.cpp (+10/-2)
configure.ac (+1/-1)
tests/Makefile.am (+11/-1)
tests/Readme.txt (+4/-1)
tests/xtest-focus-on-mouse-enter.cpp (+140/-0)
To merge this branch: bzr merge lp:~azzar1/nux/focus-on-enter
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Review via email: mp+93564@code.launchpad.net

Description of the change

Adds the support for the "focus on mouse enter" feature.

To post a comment you must log in.
lp:~azzar1/nux/focus-on-enter updated
577. By Andrea Azzarone

Change abi version.

578. By Andrea Azzarone

Fixes.

Revision history for this message
Jay Taoko (jaytaoko) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Nux/Area.h'
--- Nux/Area.h 2012-01-28 05:35:42 +0000
+++ Nux/Area.h 2012-02-17 20:49:19 +0000
@@ -515,7 +515,7 @@
515 const char* character);515 const char* character);
516516
517 virtual bool AcceptKeyNavFocus();517 virtual bool AcceptKeyNavFocus();
518 518
519 virtual Area* KeyNavIteration(KeyNavDirection direction);519 virtual Area* KeyNavIteration(KeyNavDirection direction);
520520
521 bool HasKeyFocus() const;521 bool HasKeyFocus() const;
522522
=== modified file 'Nux/InputArea.cpp'
--- Nux/InputArea.cpp 2012-01-04 00:47:59 +0000
+++ Nux/InputArea.cpp 2012-02-17 20:49:19 +0000
@@ -44,6 +44,7 @@
44 : Area(NUX_FILE_LINE_PARAM)44 : Area(NUX_FILE_LINE_PARAM)
45 , area_color_(color::Green)45 , area_color_(color::Green)
46 , accept_key_nav_focus_on_mouse_down_(true)46 , accept_key_nav_focus_on_mouse_down_(true)
47 , accept_key_nav_focus_on_mouse_enter_(false)
47 {48 {
48 SetGeometry(0, 0, 1, 1);49 SetGeometry(0, 0, 1, 1);
4950
@@ -79,11 +80,6 @@
79 return GetWindowThread()->GetWindowCompositor().GetKeyFocusArea() == this;80 return GetWindowThread()->GetWindowCompositor().GetKeyFocusArea() == this;
80 }81 }
8182
82 void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
83 {
84 accept_key_nav_focus_on_mouse_down_ = accept;
85 }
86
87 bool InputArea::IsMouseInside()83 bool InputArea::IsMouseInside()
88 {84 {
89 return mouse_in_;85 return mouse_in_;
@@ -399,9 +395,24 @@
399 return false;395 return false;
400 }396 }
401 397
402 bool InputArea::AcceptKeyNavFocusOnMouseDown()398 bool InputArea::AcceptKeyNavFocusOnMouseDown() const
403 {399 {
404 return accept_key_nav_focus_on_mouse_down_;400 return accept_key_nav_focus_on_mouse_down_;
405 }401 }
402
403 bool InputArea::AcceptKeyNavFocusOnMouseEnter() const
404 {
405 return accept_key_nav_focus_on_mouse_enter_;
406 }
407
408 void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
409 {
410 accept_key_nav_focus_on_mouse_down_ = accept;
411 }
412
413 void InputArea::SetAcceptKeyNavFocusOnMouseEnter(bool accept)
414 {
415 accept_key_nav_focus_on_mouse_enter_ = accept;
416 }
406}417}
407418
408419
=== modified file 'Nux/InputArea.h'
--- Nux/InputArea.h 2012-01-04 00:47:59 +0000
+++ Nux/InputArea.h 2012-02-17 20:49:19 +0000
@@ -59,7 +59,6 @@
59 virtual void OverlayDrawing(GraphicsEngine &graphics_engine) {}59 virtual void OverlayDrawing(GraphicsEngine &graphics_engine) {}
6060
61 bool HasKeyboardFocus();61 bool HasKeyboardFocus();
62 void SetAcceptKeyNavFocusOnMouseDown(bool accept);
6362
64 bool MouseFocusOnOtherArea();63 bool MouseFocusOnOtherArea();
65 void CaptureMouseDownAnyWhereElse(bool b);64 void CaptureMouseDownAnyWhereElse(bool b);
@@ -82,6 +81,9 @@
8281
83 void SetKeyboardReceiverIgnoreMouseDownOutside(bool ignore_mouse_down_outside);82 void SetKeyboardReceiverIgnoreMouseDownOutside(bool ignore_mouse_down_outside);
8483
84 void SetAcceptKeyNavFocusOnMouseDown(bool accept);
85 void SetAcceptKeyNavFocusOnMouseEnter(bool accept);
86
85 bool KeyboardReceiverIgnoreMouseDownOutside();87 bool KeyboardReceiverIgnoreMouseDownOutside();
8688
87 virtual bool IsArea() const89 virtual bool IsArea() const
@@ -147,8 +149,6 @@
147 149
148 int _dnd_safety_x;150 int _dnd_safety_x;
149 int _dnd_safety_y;151 int _dnd_safety_y;
150
151 bool accept_key_nav_focus_on_mouse_down_;
152152
153 protected:153 protected:
154 bool _capture_mouse_down_any_where_else;154 bool _capture_mouse_down_any_where_else;
@@ -156,6 +156,10 @@
156156
157 bool _keyboard_receiver_ignore_mouse_down_outside;157 bool _keyboard_receiver_ignore_mouse_down_outside;
158158
159 bool accept_key_nav_focus_on_mouse_down_;
160 bool accept_key_nav_focus_on_mouse_enter_;
161
162
159#if defined(NUX_OS_LINUX)163#if defined(NUX_OS_LINUX)
160 // DnD support164 // DnD support
161 // Rather than being implemented with signals, DND support is implemented with protected virtual function.165 // Rather than being implemented with signals, DND support is implemented with protected virtual function.
@@ -307,7 +311,8 @@
307 protected:311 protected:
308312
309 virtual bool AcceptKeyNavFocus();313 virtual bool AcceptKeyNavFocus();
310 virtual bool AcceptKeyNavFocusOnMouseDown();314 virtual bool AcceptKeyNavFocusOnMouseDown() const;
315 virtual bool AcceptKeyNavFocusOnMouseEnter() const;
311316
312 // == Signals with 1 to 1 mapping to input device ==317 // == Signals with 1 to 1 mapping to input device ==
313 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);318 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
314319
=== modified file 'Nux/WindowCompositor.cpp'
--- Nux/WindowCompositor.cpp 2012-02-04 00:19:46 +0000
+++ Nux/WindowCompositor.cpp 2012-02-17 20:49:19 +0000
@@ -430,9 +430,16 @@
430430
431 mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState());431 mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState());
432 }432 }
433
434 // The area we found under the mouse pointer receives a "mouse enter signal".433 // The area we found under the mouse pointer receives a "mouse enter signal".
435 SetMouseOverArea(hit_view);434 SetMouseOverArea(hit_view);
435
436 if (mouse_over_area_ != GetKeyFocusArea() &&
437 mouse_over_area_ && mouse_over_area_->AcceptKeyNavFocusOnMouseEnter())
438 {
439 SetKeyFocusArea(mouse_over_area_);
440 }
441
442
436 mouse_over_area_->EmitMouseEnterSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState());443 mouse_over_area_->EmitMouseEnterSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState());
437 emit_delta = false;444 emit_delta = false;
438 }445 }
@@ -476,7 +483,8 @@
476 // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different483 // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different
477 // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch484 // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch
478 // make mouse_over_area_ the new receiver(if it accept keyboard events).485 // make mouse_over_area_ the new receiver(if it accept keyboard events).
479 if (mouse_over_area_ != GetKeyFocusArea() and mouse_over_area_->AcceptKeyNavFocusOnMouseDown())486 if (mouse_over_area_ != GetKeyFocusArea() &&
487 mouse_over_area_ && mouse_over_area_->AcceptKeyNavFocusOnMouseDown())
480 {488 {
481 InputArea* grab_area = GetKeyboardGrabArea();489 InputArea* grab_area = GetKeyboardGrabArea();
482 if (grab_area)490 if (grab_area)
483491
=== modified file 'configure.ac'
--- configure.ac 2012-02-12 23:28:17 +0000
+++ configure.ac 2012-02-17 20:49:19 +0000
@@ -22,7 +22,7 @@
22# The number format is : year/month/day22# The number format is : year/month/day
23# e.g.: december 5th, 2011 is: 2011120523# e.g.: december 5th, 2011 is: 20111205
24# To make more than one API change in a day, add a number to the date. Like 20111205.xx24# To make more than one API change in a day, add a number to the date. Like 20111205.xx
25m4_define([nux_abi_version], [20120212.01])25m4_define([nux_abi_version], [20120217.01])
2626
27m4_define([nux_version],27m4_define([nux_version],
28 [nux_major_version.nux_minor_version.nux_micro_version])28 [nux_major_version.nux_minor_version.nux_micro_version])
2929
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2012-02-13 15:22:30 +0000
+++ tests/Makefile.am 2012-02-17 20:49:19 +0000
@@ -13,6 +13,7 @@
13 xtest-vlayout-key-navigation \13 xtest-vlayout-key-navigation \
14 xtest-scrollbar \14 xtest-scrollbar \
15 xtest-focus-on-mouse-down \15 xtest-focus-on-mouse-down \
16 xtest-focus-on-mouse-enter \
16 xtest-keynav-directions17 xtest-keynav-directions
1718
18# Please keep alphabetical19# Please keep alphabetical
@@ -198,6 +199,14 @@
198xtest_focus_on_mouse_down_LDADD = $(TestLibs)199xtest_focus_on_mouse_down_LDADD = $(TestLibs)
199xtest_focus_on_mouse_down_LDFLAGS = -lpthread -lXtst200xtest_focus_on_mouse_down_LDFLAGS = -lpthread -lXtst
200201
202xtest_focus_on_mouse_enter_SOURCES = xtest-focus-on-mouse-enter.cpp \
203 nux_automated_test_framework.cpp \
204 nux_automated_test_framework.h
205
206xtest_focus_on_mouse_enter_CPPFLAGS = $(TestFlags)
207xtest_focus_on_mouse_enter_LDADD = $(TestLibs)
208xtest_focus_on_mouse_enter_LDFLAGS = -lpthread -lXtst
209
201xtest_scrollbar_SOURCES = xtest-scrollbar.cpp \210xtest_scrollbar_SOURCES = xtest-scrollbar.cpp \
202 nux_automated_test_framework.cpp \211 nux_automated_test_framework.cpp \
203 nux_automated_test_framework.h \212 nux_automated_test_framework.h \
@@ -230,7 +239,7 @@
230check-headless: gtest-nux-core239check-headless: gtest-nux-core
231 @gtester --verbose -k -o=test-nux-results.xml ./gtest-nux-core240 @gtester --verbose -k -o=test-nux-results.xml ./gtest-nux-core
232241
233test-apps: test-graphics-display test-empty-window xtest-button xtest-mouse-events xtest-mouse-buttons xtest-hgrid-key-navigation xtest-hlayout-key-navigation xtest-vlayout-key-navigation xtest-scrollbar xtest-focus-on-mouse-down xtest-keynav-directions242test-apps: test-graphics-display test-empty-window xtest-button xtest-mouse-events xtest-mouse-buttons xtest-hgrid-key-navigation xtest-hlayout-key-navigation xtest-vlayout-key-navigation xtest-scrollbar xtest-focus-on-mouse-down xtest-focus-on-mouse-enter xtest-keynav-directions
234 ./test-graphics-display243 ./test-graphics-display
235 ./test-empty-window244 ./test-empty-window
236 ./xtest-button245 ./xtest-button
@@ -241,6 +250,7 @@
241 ./xtest-vlayout-key-navigation250 ./xtest-vlayout-key-navigation
242 ./xtest-scrollbar251 ./xtest-scrollbar
243 ./xtest-focus-on-mouse-down252 ./xtest-focus-on-mouse-down
253 ./xtest-focus-on-mouse-enter
244 ./xtest-keynav-directions254 ./xtest-keynav-directions
245255
246check-report:256check-report:
247257
=== modified file 'tests/Readme.txt'
--- tests/Readme.txt 2012-01-30 08:43:49 +0000
+++ tests/Readme.txt 2012-02-17 20:49:19 +0000
@@ -48,5 +48,8 @@
48xtest-focus-on-mouse-down48xtest-focus-on-mouse-down
49 Make sure that AcceptKeyNavFocusOnMouseDown works well.49 Make sure that AcceptKeyNavFocusOnMouseDown works well.
5050
51xtest-focus-on-mouse-enter
52 Make sure that AcceptKeyNavFocusOnMouseEnter works well.
53
51xtest-keynav-direction54xtest-keynav-direction
52 Test key navigation. Especially test the direction a key nav is coming from when the view is getting the focus.
53\ No newline at end of file55\ No newline at end of file
56 Test key navigation. Especially test the direction a key nav is coming from when the view is getting the focus.
5457
=== added file 'tests/xtest-focus-on-mouse-enter.cpp'
--- tests/xtest-focus-on-mouse-enter.cpp 1970-01-01 00:00:00 +0000
+++ tests/xtest-focus-on-mouse-enter.cpp 2012-02-17 20:49:19 +0000
@@ -0,0 +1,140 @@
1/*
2 * Copyright 2012 Inalogic Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
18 *
19 */
20
21#include "Nux/Nux.h"
22#include "Nux/WindowThread.h"
23#include "Nux/VLayout.h"
24#include "Nux/ProgramFramework/ProgramTemplate.h"
25#include "Nux/ProgramFramework/TestView.h"
26#include <X11/extensions/XTest.h>
27#include <X11/keysym.h>
28#include "nux_automated_test_framework.h"
29
30class FocusOnMouseEnterTest: public ProgramTemplate
31{
32public:
33 FocusOnMouseEnterTest(const char* program_name, int window_width, int window_height, int program_life_span);
34 ~FocusOnMouseEnterTest();
35
36 virtual void UserInterfaceSetup();
37
38 TestView* focus_view_;
39 TestView* no_focus_view_;
40};
41
42FocusOnMouseEnterTest::FocusOnMouseEnterTest(const char* program_name,
43 int window_width,
44 int window_height,
45 int program_life_span)
46: ProgramTemplate(program_name, window_width, window_height, program_life_span)
47, focus_view_(nullptr)
48, no_focus_view_(nullptr)
49{
50}
51
52FocusOnMouseEnterTest::~FocusOnMouseEnterTest()
53{}
54
55void FocusOnMouseEnterTest::UserInterfaceSetup()
56{
57 nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
58 main_layout->SetSpaceBetweenChildren(10);
59 main_layout->SetPadding(10, 10);
60
61 no_focus_view_ = new TestView(NUX_TRACKER_LOCATION);
62 no_focus_view_->can_focus_ = true;
63 no_focus_view_->SetAcceptKeyNavFocusOnMouseEnter(false);
64 main_layout->AddView(no_focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
65
66 focus_view_ = new TestView(NUX_TRACKER_LOCATION);
67 focus_view_->can_focus_ = true;
68 focus_view_->SetAcceptKeyNavFocusOnMouseEnter(true);
69 main_layout->AddView(focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
70
71 static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
72
73 nux::ColorLayer background(nux::Color(0xFF4D4D4D));
74 static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
75}
76
77FocusOnMouseEnterTest* focus_on_mouse_enter_test = nullptr;
78
79void TestingThread(nux::NThread* thread, void* user_data)
80{
81 while (focus_on_mouse_enter_test->ReadyToGo() == false)
82 {
83 nuxDebugMsg("Waiting to start");
84 nux::SleepForMilliseconds(300);
85 }
86
87 nux::SleepForMilliseconds(1000);
88
89 nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
90
91 NuxAutomatedTestFramework test(wnd_thread);
92
93 test.Startup();
94
95 // Set the mouse at coordinates (0, 0) (top-left corner) on the display
96 test.PutMouseAt(0, 0);
97
98 test.TestReportMsg(focus_on_mouse_enter_test->focus_view_, "Focus view created");
99 test.TestReportMsg(focus_on_mouse_enter_test->no_focus_view_, "No focus view created");
100
101 // Move mouse to center of no_focus_view_
102 test.ViewSendMouseMotionToCenter(focus_on_mouse_enter_test->no_focus_view_);
103 nux::SleepForMilliseconds(500);
104 test.TestReportMsg(!focus_on_mouse_enter_test->no_focus_view_->has_focus_, "no_focus_view_ did not take the focus");
105
106 // Move mouse to center of focus_view_
107 test.ViewSendMouseMotionToCenter(focus_on_mouse_enter_test->focus_view_);
108 nux::SleepForMilliseconds(500);
109 test.TestReportMsg(focus_on_mouse_enter_test->focus_view_->has_focus_, "focus_view_ has the focus");
110
111 if (test.WhenDoneTerminateProgram())
112 {
113 nux::SleepForMilliseconds(1000);
114 wnd_thread->ExitMainLoop();
115 }
116 nuxDebugMsg("Exit testing thread");
117}
118
119int main(int argc, char** argv)
120{
121 int xstatus = XInitThreads();
122 nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
123
124 focus_on_mouse_enter_test = new FocusOnMouseEnterTest("Focus On Mouse Enter Test", 300, 300, 15000);
125 focus_on_mouse_enter_test->Startup();
126 focus_on_mouse_enter_test->UserInterfaceSetup();
127
128 nux::SystemThread* test_thread = nux::CreateSystemThread(focus_on_mouse_enter_test->GetWindowThread(),
129 &TestingThread,
130 focus_on_mouse_enter_test->GetWindowThread());
131
132 test_thread->Start(focus_on_mouse_enter_test);
133
134 focus_on_mouse_enter_test->Run();
135
136 delete test_thread;
137 delete focus_on_mouse_enter_test;
138
139 return 0;
140}

Subscribers

People subscribed via source and target branches

to all changes: