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
1=== modified file 'Nux/Area.h'
2--- Nux/Area.h 2012-01-28 05:35:42 +0000
3+++ Nux/Area.h 2012-02-17 20:49:19 +0000
4@@ -515,7 +515,7 @@
5 const char* character);
6
7 virtual bool AcceptKeyNavFocus();
8-
9+
10 virtual Area* KeyNavIteration(KeyNavDirection direction);
11
12 bool HasKeyFocus() const;
13
14=== modified file 'Nux/InputArea.cpp'
15--- Nux/InputArea.cpp 2012-01-04 00:47:59 +0000
16+++ Nux/InputArea.cpp 2012-02-17 20:49:19 +0000
17@@ -44,6 +44,7 @@
18 : Area(NUX_FILE_LINE_PARAM)
19 , area_color_(color::Green)
20 , accept_key_nav_focus_on_mouse_down_(true)
21+ , accept_key_nav_focus_on_mouse_enter_(false)
22 {
23 SetGeometry(0, 0, 1, 1);
24
25@@ -79,11 +80,6 @@
26 return GetWindowThread()->GetWindowCompositor().GetKeyFocusArea() == this;
27 }
28
29- void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
30- {
31- accept_key_nav_focus_on_mouse_down_ = accept;
32- }
33-
34 bool InputArea::IsMouseInside()
35 {
36 return mouse_in_;
37@@ -399,9 +395,24 @@
38 return false;
39 }
40
41- bool InputArea::AcceptKeyNavFocusOnMouseDown()
42+ bool InputArea::AcceptKeyNavFocusOnMouseDown() const
43 {
44 return accept_key_nav_focus_on_mouse_down_;
45 }
46+
47+ bool InputArea::AcceptKeyNavFocusOnMouseEnter() const
48+ {
49+ return accept_key_nav_focus_on_mouse_enter_;
50+ }
51+
52+ void InputArea::SetAcceptKeyNavFocusOnMouseDown(bool accept)
53+ {
54+ accept_key_nav_focus_on_mouse_down_ = accept;
55+ }
56+
57+ void InputArea::SetAcceptKeyNavFocusOnMouseEnter(bool accept)
58+ {
59+ accept_key_nav_focus_on_mouse_enter_ = accept;
60+ }
61 }
62
63
64=== modified file 'Nux/InputArea.h'
65--- Nux/InputArea.h 2012-01-04 00:47:59 +0000
66+++ Nux/InputArea.h 2012-02-17 20:49:19 +0000
67@@ -59,7 +59,6 @@
68 virtual void OverlayDrawing(GraphicsEngine &graphics_engine) {}
69
70 bool HasKeyboardFocus();
71- void SetAcceptKeyNavFocusOnMouseDown(bool accept);
72
73 bool MouseFocusOnOtherArea();
74 void CaptureMouseDownAnyWhereElse(bool b);
75@@ -82,6 +81,9 @@
76
77 void SetKeyboardReceiverIgnoreMouseDownOutside(bool ignore_mouse_down_outside);
78
79+ void SetAcceptKeyNavFocusOnMouseDown(bool accept);
80+ void SetAcceptKeyNavFocusOnMouseEnter(bool accept);
81+
82 bool KeyboardReceiverIgnoreMouseDownOutside();
83
84 virtual bool IsArea() const
85@@ -147,8 +149,6 @@
86
87 int _dnd_safety_x;
88 int _dnd_safety_y;
89-
90- bool accept_key_nav_focus_on_mouse_down_;
91
92 protected:
93 bool _capture_mouse_down_any_where_else;
94@@ -156,6 +156,10 @@
95
96 bool _keyboard_receiver_ignore_mouse_down_outside;
97
98+ bool accept_key_nav_focus_on_mouse_down_;
99+ bool accept_key_nav_focus_on_mouse_enter_;
100+
101+
102 #if defined(NUX_OS_LINUX)
103 // DnD support
104 // Rather than being implemented with signals, DND support is implemented with protected virtual function.
105@@ -307,7 +311,8 @@
106 protected:
107
108 virtual bool AcceptKeyNavFocus();
109- virtual bool AcceptKeyNavFocusOnMouseDown();
110+ virtual bool AcceptKeyNavFocusOnMouseDown() const;
111+ virtual bool AcceptKeyNavFocusOnMouseEnter() const;
112
113 // == Signals with 1 to 1 mapping to input device ==
114 virtual void EmitMouseDownSignal (int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
115
116=== modified file 'Nux/WindowCompositor.cpp'
117--- Nux/WindowCompositor.cpp 2012-02-04 00:19:46 +0000
118+++ Nux/WindowCompositor.cpp 2012-02-17 20:49:19 +0000
119@@ -430,9 +430,16 @@
120
121 mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState());
122 }
123-
124 // The area we found under the mouse pointer receives a "mouse enter signal".
125 SetMouseOverArea(hit_view);
126+
127+ if (mouse_over_area_ != GetKeyFocusArea() &&
128+ mouse_over_area_ && mouse_over_area_->AcceptKeyNavFocusOnMouseEnter())
129+ {
130+ SetKeyFocusArea(mouse_over_area_);
131+ }
132+
133+
134 mouse_over_area_->EmitMouseEnterSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState());
135 emit_delta = false;
136 }
137@@ -476,7 +483,8 @@
138 // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different
139 // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch
140 // make mouse_over_area_ the new receiver(if it accept keyboard events).
141- if (mouse_over_area_ != GetKeyFocusArea() and mouse_over_area_->AcceptKeyNavFocusOnMouseDown())
142+ if (mouse_over_area_ != GetKeyFocusArea() &&
143+ mouse_over_area_ && mouse_over_area_->AcceptKeyNavFocusOnMouseDown())
144 {
145 InputArea* grab_area = GetKeyboardGrabArea();
146 if (grab_area)
147
148=== modified file 'configure.ac'
149--- configure.ac 2012-02-12 23:28:17 +0000
150+++ configure.ac 2012-02-17 20:49:19 +0000
151@@ -22,7 +22,7 @@
152 # The number format is : year/month/day
153 # e.g.: december 5th, 2011 is: 20111205
154 # To make more than one API change in a day, add a number to the date. Like 20111205.xx
155-m4_define([nux_abi_version], [20120212.01])
156+m4_define([nux_abi_version], [20120217.01])
157
158 m4_define([nux_version],
159 [nux_major_version.nux_minor_version.nux_micro_version])
160
161=== modified file 'tests/Makefile.am'
162--- tests/Makefile.am 2012-02-13 15:22:30 +0000
163+++ tests/Makefile.am 2012-02-17 20:49:19 +0000
164@@ -13,6 +13,7 @@
165 xtest-vlayout-key-navigation \
166 xtest-scrollbar \
167 xtest-focus-on-mouse-down \
168+ xtest-focus-on-mouse-enter \
169 xtest-keynav-directions
170
171 # Please keep alphabetical
172@@ -198,6 +199,14 @@
173 xtest_focus_on_mouse_down_LDADD = $(TestLibs)
174 xtest_focus_on_mouse_down_LDFLAGS = -lpthread -lXtst
175
176+xtest_focus_on_mouse_enter_SOURCES = xtest-focus-on-mouse-enter.cpp \
177+ nux_automated_test_framework.cpp \
178+ nux_automated_test_framework.h
179+
180+xtest_focus_on_mouse_enter_CPPFLAGS = $(TestFlags)
181+xtest_focus_on_mouse_enter_LDADD = $(TestLibs)
182+xtest_focus_on_mouse_enter_LDFLAGS = -lpthread -lXtst
183+
184 xtest_scrollbar_SOURCES = xtest-scrollbar.cpp \
185 nux_automated_test_framework.cpp \
186 nux_automated_test_framework.h \
187@@ -230,7 +239,7 @@
188 check-headless: gtest-nux-core
189 @gtester --verbose -k -o=test-nux-results.xml ./gtest-nux-core
190
191-test-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-directions
192+test-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
193 ./test-graphics-display
194 ./test-empty-window
195 ./xtest-button
196@@ -241,6 +250,7 @@
197 ./xtest-vlayout-key-navigation
198 ./xtest-scrollbar
199 ./xtest-focus-on-mouse-down
200+ ./xtest-focus-on-mouse-enter
201 ./xtest-keynav-directions
202
203 check-report:
204
205=== modified file 'tests/Readme.txt'
206--- tests/Readme.txt 2012-01-30 08:43:49 +0000
207+++ tests/Readme.txt 2012-02-17 20:49:19 +0000
208@@ -48,5 +48,8 @@
209 xtest-focus-on-mouse-down
210 Make sure that AcceptKeyNavFocusOnMouseDown works well.
211
212+xtest-focus-on-mouse-enter
213+ Make sure that AcceptKeyNavFocusOnMouseEnter works well.
214+
215 xtest-keynav-direction
216- Test key navigation. Especially test the direction a key nav is coming from when the view is getting the focus.
217\ No newline at end of file
218+ Test key navigation. Especially test the direction a key nav is coming from when the view is getting the focus.
219
220=== added file 'tests/xtest-focus-on-mouse-enter.cpp'
221--- tests/xtest-focus-on-mouse-enter.cpp 1970-01-01 00:00:00 +0000
222+++ tests/xtest-focus-on-mouse-enter.cpp 2012-02-17 20:49:19 +0000
223@@ -0,0 +1,140 @@
224+/*
225+ * Copyright 2012 Inalogic Inc.
226+ *
227+ * This program is free software: you can redistribute it and/or modify it
228+ * under the terms of the GNU General Public License version 3, as published
229+ * by the Free Software Foundation.
230+ *
231+ * This program is distributed in the hope that it will be useful, but
232+ * WITHOUT ANY WARRANTY; without even the implied warranties of
233+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
234+ * PURPOSE. See the GNU General Public License for more details.
235+ *
236+ * You should have received a copy of the GNU General Public License
237+ * version 3 along with this program. If not, see
238+ * <http://www.gnu.org/licenses/>
239+ *
240+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
241+ *
242+ */
243+
244+#include "Nux/Nux.h"
245+#include "Nux/WindowThread.h"
246+#include "Nux/VLayout.h"
247+#include "Nux/ProgramFramework/ProgramTemplate.h"
248+#include "Nux/ProgramFramework/TestView.h"
249+#include <X11/extensions/XTest.h>
250+#include <X11/keysym.h>
251+#include "nux_automated_test_framework.h"
252+
253+class FocusOnMouseEnterTest: public ProgramTemplate
254+{
255+public:
256+ FocusOnMouseEnterTest(const char* program_name, int window_width, int window_height, int program_life_span);
257+ ~FocusOnMouseEnterTest();
258+
259+ virtual void UserInterfaceSetup();
260+
261+ TestView* focus_view_;
262+ TestView* no_focus_view_;
263+};
264+
265+FocusOnMouseEnterTest::FocusOnMouseEnterTest(const char* program_name,
266+ int window_width,
267+ int window_height,
268+ int program_life_span)
269+: ProgramTemplate(program_name, window_width, window_height, program_life_span)
270+, focus_view_(nullptr)
271+, no_focus_view_(nullptr)
272+{
273+}
274+
275+FocusOnMouseEnterTest::~FocusOnMouseEnterTest()
276+{}
277+
278+void FocusOnMouseEnterTest::UserInterfaceSetup()
279+{
280+ nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
281+ main_layout->SetSpaceBetweenChildren(10);
282+ main_layout->SetPadding(10, 10);
283+
284+ no_focus_view_ = new TestView(NUX_TRACKER_LOCATION);
285+ no_focus_view_->can_focus_ = true;
286+ no_focus_view_->SetAcceptKeyNavFocusOnMouseEnter(false);
287+ main_layout->AddView(no_focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
288+
289+ focus_view_ = new TestView(NUX_TRACKER_LOCATION);
290+ focus_view_->can_focus_ = true;
291+ focus_view_->SetAcceptKeyNavFocusOnMouseEnter(true);
292+ main_layout->AddView(focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
293+
294+ static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
295+
296+ nux::ColorLayer background(nux::Color(0xFF4D4D4D));
297+ static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
298+}
299+
300+FocusOnMouseEnterTest* focus_on_mouse_enter_test = nullptr;
301+
302+void TestingThread(nux::NThread* thread, void* user_data)
303+{
304+ while (focus_on_mouse_enter_test->ReadyToGo() == false)
305+ {
306+ nuxDebugMsg("Waiting to start");
307+ nux::SleepForMilliseconds(300);
308+ }
309+
310+ nux::SleepForMilliseconds(1000);
311+
312+ nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
313+
314+ NuxAutomatedTestFramework test(wnd_thread);
315+
316+ test.Startup();
317+
318+ // Set the mouse at coordinates (0, 0) (top-left corner) on the display
319+ test.PutMouseAt(0, 0);
320+
321+ test.TestReportMsg(focus_on_mouse_enter_test->focus_view_, "Focus view created");
322+ test.TestReportMsg(focus_on_mouse_enter_test->no_focus_view_, "No focus view created");
323+
324+ // Move mouse to center of no_focus_view_
325+ test.ViewSendMouseMotionToCenter(focus_on_mouse_enter_test->no_focus_view_);
326+ nux::SleepForMilliseconds(500);
327+ test.TestReportMsg(!focus_on_mouse_enter_test->no_focus_view_->has_focus_, "no_focus_view_ did not take the focus");
328+
329+ // Move mouse to center of focus_view_
330+ test.ViewSendMouseMotionToCenter(focus_on_mouse_enter_test->focus_view_);
331+ nux::SleepForMilliseconds(500);
332+ test.TestReportMsg(focus_on_mouse_enter_test->focus_view_->has_focus_, "focus_view_ has the focus");
333+
334+ if (test.WhenDoneTerminateProgram())
335+ {
336+ nux::SleepForMilliseconds(1000);
337+ wnd_thread->ExitMainLoop();
338+ }
339+ nuxDebugMsg("Exit testing thread");
340+}
341+
342+int main(int argc, char** argv)
343+{
344+ int xstatus = XInitThreads();
345+ nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
346+
347+ focus_on_mouse_enter_test = new FocusOnMouseEnterTest("Focus On Mouse Enter Test", 300, 300, 15000);
348+ focus_on_mouse_enter_test->Startup();
349+ focus_on_mouse_enter_test->UserInterfaceSetup();
350+
351+ nux::SystemThread* test_thread = nux::CreateSystemThread(focus_on_mouse_enter_test->GetWindowThread(),
352+ &TestingThread,
353+ focus_on_mouse_enter_test->GetWindowThread());
354+
355+ test_thread->Start(focus_on_mouse_enter_test);
356+
357+ focus_on_mouse_enter_test->Run();
358+
359+ delete test_thread;
360+ delete focus_on_mouse_enter_test;
361+
362+ return 0;
363+}

Subscribers

People subscribed via source and target branches

to all changes: