Merge lp:~njpatel/nux/weak-ptrs-on-window-compostor-3.0 into lp:nux/3.0
- weak-ptrs-on-window-compostor-3.0
- Merge into 3.0
Proposed by
Neil J. Patel
Status: | Merged |
---|---|
Approved by: | Martin Mrazik |
Approved revision: | 655 |
Merged at revision: | 656 |
Proposed branch: | lp:~njpatel/nux/weak-ptrs-on-window-compostor-3.0 |
Merge into: | lp:nux/3.0 |
Prerequisite: | lp:~njpatel/nux/input-area-ungrab-on-destroy-3.0 |
Diff against target: |
1438 lines (+455/-320) 7 files modified
Nux/Area.cpp (+2/-0) Nux/WindowCompositor.cpp (+129/-207) Nux/WindowCompositor.h (+16/-32) configure.ac (+1/-1) tests/gtest-nux-area.cpp (+96/-47) tests/gtest-nux-input-area.cpp (+1/-1) tests/gtest-nux-windowcompositor.cpp (+210/-32) |
To merge this branch: | bzr merge lp:~njpatel/nux/weak-ptrs-on-window-compostor-3.0 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
Review via email: mp+125015@code.launchpad.net |
Commit message
WindowCompostior: use ObjectWeakPtr to handle focus and mouse areas
So they get automatically nullified when the handled objects are destroyed,
also Make Area to unset the key-focus paths on destroy.
Description of the change
It can happen that during the WindowCompostit
At this point I've also moved the existing Area* references that were using the destroyed signal to ObjectWeakPtr's.
To post a comment you must log in.
Revision history for this message
Unity Merger (unity-merger) wrote : | # |
No proposals found for merge of lp:~njpatel/nux/input-area-ungrab-on-destroy-3.0 into lp:nux/3.0.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Nux/Area.cpp' | |||
2 | --- Nux/Area.cpp 2012-05-31 21:50:05 +0000 | |||
3 | +++ Nux/Area.cpp 2012-09-18 18:30:40 +0000 | |||
4 | @@ -68,6 +68,8 @@ | |||
5 | 68 | 68 | ||
6 | 69 | Area::~Area() | 69 | Area::~Area() |
7 | 70 | { | 70 | { |
8 | 71 | ResetDownwardPathToKeyFocusArea(); | ||
9 | 72 | ResetUpwardPathToKeyFocusArea(); | ||
10 | 71 | } | 73 | } |
11 | 72 | 74 | ||
12 | 73 | const NString &Area::GetBaseString() const | 75 | const NString &Area::GetBaseString() const |
13 | 74 | 76 | ||
14 | === modified file 'Nux/WindowCompositor.cpp' | |||
15 | --- Nux/WindowCompositor.cpp 2012-08-02 17:46:47 +0000 | |||
16 | +++ Nux/WindowCompositor.cpp 2012-09-18 18:30:40 +0000 | |||
17 | @@ -58,7 +58,6 @@ | |||
18 | 58 | m_CurrentWindow = NULL; | 58 | m_CurrentWindow = NULL; |
19 | 59 | m_MenuWindow = NULL; | 59 | m_MenuWindow = NULL; |
20 | 60 | _mouse_over_area = NULL; | 60 | _mouse_over_area = NULL; |
21 | 61 | key_focus_area_ = NULL; | ||
22 | 62 | _always_on_front_window = NULL; | 61 | _always_on_front_window = NULL; |
23 | 63 | inside_event_cycle_ = false; | 62 | inside_event_cycle_ = false; |
24 | 64 | inside_rendering_cycle_ = false; | 63 | inside_rendering_cycle_ = false; |
25 | @@ -67,11 +66,8 @@ | |||
26 | 67 | _pending_exclusive_input_mode_action = false; | 66 | _pending_exclusive_input_mode_action = false; |
27 | 68 | 67 | ||
28 | 69 | _dnd_area = NULL; | 68 | _dnd_area = NULL; |
29 | 70 | mouse_over_area_ = NULL; | ||
30 | 71 | mouse_owner_area_ = NULL; | ||
31 | 72 | _mouse_over_menu_page = NULL; | 69 | _mouse_over_menu_page = NULL; |
32 | 73 | _mouse_owner_menu_page = NULL; | 70 | _mouse_owner_menu_page = NULL; |
33 | 74 | mouse_owner_base_window_ = NULL; | ||
34 | 75 | _starting_menu_event_cycle = false; | 71 | _starting_menu_event_cycle = false; |
35 | 76 | _menu_is_active = false; | 72 | _menu_is_active = false; |
36 | 77 | _enable_nux_new_event_architecture = true; | 73 | _enable_nux_new_event_architecture = true; |
37 | @@ -99,12 +95,7 @@ | |||
38 | 99 | 95 | ||
39 | 100 | void WindowCompositor::BeforeDestructor() | 96 | void WindowCompositor::BeforeDestructor() |
40 | 101 | { | 97 | { |
47 | 102 | if (key_focus_area_) | 98 | key_focus_area_ = NULL; |
42 | 103 | { | ||
43 | 104 | key_focus_area_->ResetDownwardPathToKeyFocusArea(); | ||
44 | 105 | key_focus_area_->ResetUpwardPathToKeyFocusArea(); | ||
45 | 106 | key_focus_area_ = NULL; | ||
46 | 107 | } | ||
48 | 108 | } | 99 | } |
49 | 109 | 100 | ||
50 | 110 | WindowCompositor::~WindowCompositor() | 101 | WindowCompositor::~WindowCompositor() |
51 | @@ -186,17 +177,12 @@ | |||
52 | 186 | { | 177 | { |
53 | 187 | _view_window_list.erase(it); | 178 | _view_window_list.erase(it); |
54 | 188 | 179 | ||
56 | 189 | if (_view_window_list.size()) | 180 | if (!_view_window_list.empty()) |
57 | 190 | m_SelectedWindow = _view_window_list.front(); | 181 | m_SelectedWindow = _view_window_list.front(); |
58 | 191 | } | 182 | } |
59 | 192 | _window_to_texture_map.erase(window.GetPointer()); | 183 | _window_to_texture_map.erase(window.GetPointer()); |
60 | 193 | } | 184 | } |
61 | 194 | 185 | ||
62 | 195 | Area* WindowCompositor::GetMouseOwnerArea() | ||
63 | 196 | { | ||
64 | 197 | return mouse_owner_area_; | ||
65 | 198 | } | ||
66 | 199 | |||
67 | 200 | //! Get Mouse position relative to the top left corner of the window. | 186 | //! Get Mouse position relative to the top left corner of the window. |
68 | 201 | Point WindowCompositor::GetMousePosition() | 187 | Point WindowCompositor::GetMousePosition() |
69 | 202 | { | 188 | { |
70 | @@ -213,24 +199,24 @@ | |||
71 | 213 | 199 | ||
72 | 214 | void WindowCompositor::GetAreaUnderMouse(const Point& mouse_position, | 200 | void WindowCompositor::GetAreaUnderMouse(const Point& mouse_position, |
73 | 215 | NuxEventType event_type, | 201 | NuxEventType event_type, |
76 | 216 | InputArea** area_under_mouse_pointer, | 202 | ObjectWeakPtr<InputArea>& area_under_mouse_pointer, |
77 | 217 | BaseWindow** window) | 203 | ObjectWeakPtr<BaseWindow>& window) |
78 | 218 | { | 204 | { |
80 | 219 | *area_under_mouse_pointer = NULL; | 205 | window = NULL; |
81 | 206 | area_under_mouse_pointer = NULL; | ||
82 | 220 | 207 | ||
83 | 221 | // Go through the list of BaseWindo and find the first area over which the | 208 | // Go through the list of BaseWindo and find the first area over which the |
84 | 222 | // mouse pointer is. | 209 | // mouse pointer is. |
85 | 223 | WindowList::iterator window_it; | 210 | WindowList::iterator window_it; |
86 | 224 | |||
87 | 225 | for (window_it = _view_window_list.begin(); window_it != _view_window_list.end(); ++window_it) | 211 | for (window_it = _view_window_list.begin(); window_it != _view_window_list.end(); ++window_it) |
88 | 226 | { | 212 | { |
89 | 227 | if ((*window_it).IsValid() && (*window_it)->IsVisible()) | 213 | if ((*window_it).IsValid() && (*window_it)->IsVisible()) |
90 | 228 | { | 214 | { |
92 | 229 | InputArea* area = static_cast<InputArea*>((*window_it)->FindAreaUnderMouse(mouse_position, event_type)); | 215 | Area* area = (*window_it)->FindAreaUnderMouse(mouse_position, event_type); |
93 | 230 | if (area) | 216 | if (area) |
94 | 231 | { | 217 | { |
97 | 232 | *area_under_mouse_pointer = area; | 218 | area_under_mouse_pointer = static_cast<InputArea*>(area); |
98 | 233 | *window = (*window_it).GetPointer(); | 219 | window = *window_it; |
99 | 234 | return; | 220 | return; |
100 | 235 | } | 221 | } |
101 | 236 | } | 222 | } |
102 | @@ -238,91 +224,55 @@ | |||
103 | 238 | 224 | ||
104 | 239 | // If area_under_mouse_pointer is NULL, then the mouse pointer is not over | 225 | // If area_under_mouse_pointer is NULL, then the mouse pointer is not over |
105 | 240 | // any of the BaseWindow. Try the main window layout. | 226 | // any of the BaseWindow. Try the main window layout. |
107 | 241 | if (*area_under_mouse_pointer == NULL) | 227 | if (!area_under_mouse_pointer.IsValid()) |
108 | 242 | { | 228 | { |
109 | 243 | Layout* main_window_layout = window_thread_->GetLayout(); | 229 | Layout* main_window_layout = window_thread_->GetLayout(); |
110 | 244 | if (main_window_layout) | 230 | if (main_window_layout) |
144 | 245 | *area_under_mouse_pointer = static_cast<InputArea*>(main_window_layout->FindAreaUnderMouse(mouse_position, event_type)); | 231 | area_under_mouse_pointer = static_cast<InputArea*>(main_window_layout->FindAreaUnderMouse(mouse_position, event_type)); |
145 | 246 | } | 232 | } |
146 | 247 | } | 233 | } |
147 | 248 | 234 | ||
148 | 249 | void WindowCompositor::OnMouseOverViewDestroyed(Object* object) | 235 | void WindowCompositor::SetMouseOverArea(InputArea* area) |
149 | 250 | { | 236 | { |
150 | 251 | if (mouse_over_area_ == object) | 237 | if (mouse_over_area_ == area) |
151 | 252 | { | 238 | return; |
152 | 253 | mouse_over_area_ = NULL; | 239 | |
153 | 254 | } | 240 | mouse_over_area_ = area; |
154 | 255 | } | 241 | } |
155 | 256 | 242 | ||
156 | 257 | void WindowCompositor::SetMouseOverArea(Area* area) | 243 | void WindowCompositor::SetMouseOwnerArea(InputArea* area) |
124 | 258 | { | ||
125 | 259 | mouse_over_area_ = static_cast<InputArea*>(area); | ||
126 | 260 | |||
127 | 261 | mouse_over_view_connection_.disconnect(); | ||
128 | 262 | |||
129 | 263 | if (mouse_over_area_) | ||
130 | 264 | { | ||
131 | 265 | mouse_over_view_connection_ = mouse_over_area_->object_destroyed.connect(sigc::mem_fun(this, &WindowCompositor::OnMouseOverViewDestroyed)); | ||
132 | 266 | } | ||
133 | 267 | } | ||
134 | 268 | |||
135 | 269 | void WindowCompositor::OnMouseOwnerViewDestroyed(Object* object) | ||
136 | 270 | { | ||
137 | 271 | if (mouse_owner_area_ == object) | ||
138 | 272 | { | ||
139 | 273 | mouse_owner_area_ = NULL; | ||
140 | 274 | } | ||
141 | 275 | } | ||
142 | 276 | |||
143 | 277 | void WindowCompositor::SetMouseOwnerArea(Area* area) | ||
157 | 278 | { | 244 | { |
158 | 279 | if (mouse_owner_area_ == area) | 245 | if (mouse_owner_area_ == area) |
159 | 280 | return; | 246 | return; |
160 | 281 | 247 | ||
162 | 282 | mouse_owner_area_ = static_cast<InputArea*>(area); | 248 | mouse_owner_area_ = area; |
163 | 283 | dnd_safety_x_ = 0; | 249 | dnd_safety_x_ = 0; |
164 | 284 | dnd_safety_y_ = 0; | 250 | dnd_safety_y_ = 0; |
165 | 285 | |||
166 | 286 | mouse_owner_view_connection_.disconnect(); | ||
167 | 287 | |||
168 | 288 | if (mouse_owner_area_) | ||
169 | 289 | { | ||
170 | 290 | mouse_owner_view_connection_ = mouse_owner_area_->object_destroyed.connect(sigc::mem_fun(this, &WindowCompositor::OnMouseOwnerViewDestroyed)); | ||
171 | 291 | } | ||
172 | 292 | } | 251 | } |
173 | 293 | 252 | ||
175 | 294 | void WindowCompositor::OnMouseOwnerBaseWindowDestroyed(Object* object) | 253 | ObjectWeakPtr<InputArea> const& WindowCompositor::GetMouseOwnerArea() const |
176 | 295 | { | 254 | { |
181 | 296 | if (mouse_owner_base_window_ == object) | 255 | return mouse_owner_area_; |
178 | 297 | { | ||
179 | 298 | mouse_owner_base_window_ = NULL; | ||
180 | 299 | } | ||
182 | 300 | } | 256 | } |
183 | 301 | 257 | ||
184 | 302 | void WindowCompositor::SetMouseOwnerBaseWindow(BaseWindow* base_window) | 258 | void WindowCompositor::SetMouseOwnerBaseWindow(BaseWindow* base_window) |
185 | 303 | { | 259 | { |
194 | 304 | mouse_owner_base_window_ = base_window; | 260 | if (mouse_owner_base_window_ != base_window) |
195 | 305 | 261 | mouse_owner_base_window_ = base_window; | |
188 | 306 | mouse_owner_basewindow_connection_.disconnect(); | ||
189 | 307 | |||
190 | 308 | if (mouse_owner_base_window_) | ||
191 | 309 | { | ||
192 | 310 | mouse_owner_basewindow_connection_ = mouse_owner_base_window_->object_destroyed.connect(sigc::mem_fun(this, &WindowCompositor::OnMouseOwnerBaseWindowDestroyed)); | ||
193 | 311 | } | ||
196 | 312 | } | 262 | } |
197 | 313 | 263 | ||
198 | 314 | void WindowCompositor::DndEventCycle(Event& event) | 264 | void WindowCompositor::DndEventCycle(Event& event) |
199 | 315 | { | 265 | { |
200 | 316 | if (event.type == NUX_DND_MOVE) | 266 | if (event.type == NUX_DND_MOVE) |
201 | 317 | { | 267 | { |
208 | 318 | InputArea* hit_area = NULL; | 268 | ObjectWeakPtr<InputArea> hit_area; |
209 | 319 | BaseWindow* hit_base_window = NULL; | 269 | ObjectWeakPtr<BaseWindow> hit_base_window; |
210 | 320 | 270 | ||
211 | 321 | GetAreaUnderMouse(Point(event.x, event.y), event.type, &hit_area, &hit_base_window); | 271 | GetAreaUnderMouse(Point(event.x, event.y), event.type, hit_area, hit_base_window); |
212 | 322 | 272 | ||
213 | 323 | if (hit_area) | 273 | if (hit_area.IsValid()) |
214 | 324 | { | 274 | { |
216 | 325 | SetDnDArea(hit_area); | 275 | SetDnDArea(hit_area.GetPointer()); |
217 | 326 | hit_area->HandleDndMove(event); | 276 | hit_area->HandleDndMove(event); |
218 | 327 | } | 277 | } |
219 | 328 | else | 278 | else |
220 | @@ -356,7 +306,7 @@ | |||
221 | 356 | 306 | ||
222 | 357 | _mouse_position = Point(event.x, event.y); | 307 | _mouse_position = Point(event.x, event.y); |
223 | 358 | 308 | ||
225 | 359 | if (mouse_owner_area_ == NULL) | 309 | if (!mouse_owner_area_.IsValid()) |
226 | 360 | { | 310 | { |
227 | 361 | // Context: The left mouse button is not down over an area. | 311 | // Context: The left mouse button is not down over an area. |
228 | 362 | // We look for the area where the mouse pointer is located. | 312 | // We look for the area where the mouse pointer is located. |
229 | @@ -370,8 +320,8 @@ | |||
230 | 370 | (event.type == NUX_WINDOW_MOUSELEAVE) || | 320 | (event.type == NUX_WINDOW_MOUSELEAVE) || |
231 | 371 | (event.type == NUX_MOUSE_RELEASED)) | 321 | (event.type == NUX_MOUSE_RELEASED)) |
232 | 372 | { | 322 | { |
235 | 373 | InputArea* hit_view = NULL; // The view under the mouse | 323 | ObjectWeakPtr<InputArea> hit_view; // The view under the mouse |
236 | 374 | BaseWindow* hit_base_window = NULL; // The BaseWindow below the mouse pointer. | 324 | ObjectWeakPtr<BaseWindow> hit_base_window; // The BaseWindow below the mouse pointer. |
237 | 375 | 325 | ||
238 | 376 | // Look for the area below the mouse pointer in the BaseWindow. | 326 | // Look for the area below the mouse pointer in the BaseWindow. |
239 | 377 | Area* pointer_grab_area = GetPointerGrabArea(); | 327 | Area* pointer_grab_area = GetPointerGrabArea(); |
240 | @@ -379,7 +329,7 @@ | |||
241 | 379 | { | 329 | { |
242 | 380 | // If there is a pending mouse pointer grab, test that area only | 330 | // If there is a pending mouse pointer grab, test that area only |
243 | 381 | hit_view = NUX_STATIC_CAST(InputArea*, pointer_grab_area->FindAreaUnderMouse(Point(event.x, event.y), event.type)); | 331 | hit_view = NUX_STATIC_CAST(InputArea*, pointer_grab_area->FindAreaUnderMouse(Point(event.x, event.y), event.type)); |
245 | 382 | if ((hit_view == NULL) && (event.type == NUX_MOUSE_PRESSED)) | 332 | if (!hit_view.IsValid() && event.type == NUX_MOUSE_PRESSED) |
246 | 383 | { | 333 | { |
247 | 384 | Geometry geo = pointer_grab_area->GetAbsoluteGeometry(); | 334 | Geometry geo = pointer_grab_area->GetAbsoluteGeometry(); |
248 | 385 | int x = event.x - geo.x; | 335 | int x = event.x - geo.x; |
249 | @@ -390,15 +340,15 @@ | |||
250 | 390 | } | 340 | } |
251 | 391 | else | 341 | else |
252 | 392 | { | 342 | { |
255 | 393 | GetAreaUnderMouse(Point(event.x, event.y), event.type, &hit_view, &hit_base_window); | 343 | GetAreaUnderMouse(Point(event.x, event.y), event.type, hit_view, hit_base_window); |
256 | 394 | SetMouseOwnerBaseWindow(hit_base_window); | 344 | SetMouseOwnerBaseWindow(hit_base_window.GetPointer()); |
257 | 395 | } | 345 | } |
258 | 396 | 346 | ||
259 | 397 | Geometry hit_view_geo; | 347 | Geometry hit_view_geo; |
260 | 398 | int hit_view_x = 0; | 348 | int hit_view_x = 0; |
261 | 399 | int hit_view_y = 0; | 349 | int hit_view_y = 0; |
262 | 400 | 350 | ||
264 | 401 | if (hit_view) | 351 | if (hit_view.IsValid()) |
265 | 402 | { | 352 | { |
266 | 403 | hit_view_geo = hit_view->GetAbsoluteGeometry(); | 353 | hit_view_geo = hit_view->GetAbsoluteGeometry(); |
267 | 404 | hit_view_x = event.x - hit_view_geo.x; | 354 | hit_view_x = event.x - hit_view_geo.x; |
268 | @@ -407,11 +357,11 @@ | |||
269 | 407 | 357 | ||
270 | 408 | if (event.type == NUX_WINDOW_MOUSELEAVE) | 358 | if (event.type == NUX_WINDOW_MOUSELEAVE) |
271 | 409 | { | 359 | { |
273 | 410 | if (mouse_over_area_ != NULL) | 360 | if (mouse_over_area_.IsValid()) |
274 | 411 | { | 361 | { |
275 | 412 | // The area where the mouse was in the previous cycle and the area returned by GetAreaUnderMouse are different. | 362 | // The area where the mouse was in the previous cycle and the area returned by GetAreaUnderMouse are different. |
276 | 413 | // The area from the previous cycle receive a "mouse leave signal". | 363 | // The area from the previous cycle receive a "mouse leave signal". |
278 | 414 | Geometry geo = mouse_over_area_->GetAbsoluteGeometry(); | 364 | Geometry const& geo = mouse_over_area_->GetAbsoluteGeometry(); |
279 | 415 | int x = event.x - geo.x; | 365 | int x = event.x - geo.x; |
280 | 416 | int y = event.y - geo.y; | 366 | int y = event.y - geo.y; |
281 | 417 | 367 | ||
282 | @@ -419,28 +369,28 @@ | |||
283 | 419 | SetMouseOverArea(NULL); | 369 | SetMouseOverArea(NULL); |
284 | 420 | } | 370 | } |
285 | 421 | } | 371 | } |
287 | 422 | else if (hit_view && (event.type == NUX_MOUSE_MOVE)) | 372 | else if (hit_view.IsValid() && event.type == NUX_MOUSE_MOVE) |
288 | 423 | { | 373 | { |
289 | 424 | bool emit_delta = true; | 374 | bool emit_delta = true; |
290 | 425 | if (hit_view != mouse_over_area_) | 375 | if (hit_view != mouse_over_area_) |
291 | 426 | { | 376 | { |
293 | 427 | if (mouse_over_area_ != NULL) | 377 | if (mouse_over_area_.IsValid()) |
294 | 428 | { | 378 | { |
295 | 429 | // The area where the mouse was in the previous cycle and the area returned by GetAreaUnderMouse are different. | 379 | // The area where the mouse was in the previous cycle and the area returned by GetAreaUnderMouse are different. |
296 | 430 | // The area from the previous cycle receive a "mouse leave signal". | 380 | // The area from the previous cycle receive a "mouse leave signal". |
298 | 431 | Geometry geo = mouse_over_area_->GetAbsoluteGeometry(); | 381 | Geometry const& geo = mouse_over_area_->GetAbsoluteGeometry(); |
299 | 432 | int x = event.x - geo.x; | 382 | int x = event.x - geo.x; |
300 | 433 | int y = event.y - geo.y; | 383 | int y = event.y - geo.y; |
301 | 434 | 384 | ||
302 | 435 | mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState()); | 385 | mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState()); |
303 | 436 | } | 386 | } |
304 | 437 | // The area we found under the mouse pointer receives a "mouse enter signal". | 387 | // The area we found under the mouse pointer receives a "mouse enter signal". |
306 | 438 | SetMouseOverArea(hit_view); | 388 | SetMouseOverArea(hit_view.GetPointer()); |
307 | 439 | 389 | ||
310 | 440 | if (mouse_over_area_ != GetKeyFocusArea() && | 390 | if (mouse_over_area_.IsValid() && mouse_over_area_ != GetKeyFocusArea() && |
311 | 441 | mouse_over_area_ && mouse_over_area_->AcceptKeyNavFocusOnMouseEnter()) | 391 | mouse_over_area_->AcceptKeyNavFocusOnMouseEnter()) |
312 | 442 | { | 392 | { |
314 | 443 | SetKeyFocusArea(mouse_over_area_); | 393 | SetKeyFocusArea(mouse_over_area_.GetPointer()); |
315 | 444 | } | 394 | } |
316 | 445 | 395 | ||
317 | 446 | 396 | ||
318 | @@ -451,16 +401,16 @@ | |||
319 | 451 | // Send a "mouse mouse signal". | 401 | // Send a "mouse mouse signal". |
320 | 452 | mouse_over_area_->EmitMouseMoveSignal(hit_view_x, hit_view_y, emit_delta ? dx : 0, emit_delta ? dy : 0, event.GetMouseState(), event.GetKeyState()); | 402 | mouse_over_area_->EmitMouseMoveSignal(hit_view_x, hit_view_y, emit_delta ? dx : 0, emit_delta ? dy : 0, event.GetMouseState(), event.GetKeyState()); |
321 | 453 | } | 403 | } |
323 | 454 | else if (hit_view && ((event.type == NUX_MOUSE_PRESSED) || (event.type == NUX_MOUSE_DOUBLECLICK))) | 404 | else if (hit_view.IsValid() && (event.type == NUX_MOUSE_PRESSED || event.type == NUX_MOUSE_DOUBLECLICK)) |
324 | 455 | { | 405 | { |
326 | 456 | if ((event.type == NUX_MOUSE_DOUBLECLICK) && (!hit_view->DoubleClickEnabled())) | 406 | if (event.type == NUX_MOUSE_DOUBLECLICK && !hit_view->DoubleClickEnabled()) |
327 | 457 | { | 407 | { |
328 | 458 | // If the area does not accept double click events, transform the event into a mouse pressed. | 408 | // If the area does not accept double click events, transform the event into a mouse pressed. |
329 | 459 | event.type = NUX_MOUSE_PRESSED; | 409 | event.type = NUX_MOUSE_PRESSED; |
330 | 460 | } | 410 | } |
331 | 461 | 411 | ||
332 | 462 | bool emit_double_click_signal = false; | 412 | bool emit_double_click_signal = false; |
334 | 463 | if (mouse_over_area_ && (hit_view != mouse_over_area_)) | 413 | if (mouse_over_area_.IsValid() && hit_view != mouse_over_area_) |
335 | 464 | { | 414 | { |
336 | 465 | // The area where the mouse was in the previous cycle and the area returned by GetAreaUnderMouse are different. | 415 | // The area where the mouse was in the previous cycle and the area returned by GetAreaUnderMouse are different. |
337 | 466 | // The area from the previous cycle receive a "mouse leave signal". | 416 | // The area from the previous cycle receive a "mouse leave signal". |
338 | @@ -473,29 +423,29 @@ | |||
339 | 473 | 423 | ||
340 | 474 | mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState()); | 424 | mouse_over_area_->EmitMouseLeaveSignal(x, y, event.GetMouseState(), event.GetKeyState()); |
341 | 475 | } | 425 | } |
343 | 476 | else if (mouse_over_area_ && (hit_view == mouse_over_area_) && (event.type == NUX_MOUSE_DOUBLECLICK)) | 426 | else if (mouse_over_area_.IsValid() && hit_view == mouse_over_area_ && event.type == NUX_MOUSE_DOUBLECLICK) |
344 | 477 | { | 427 | { |
345 | 478 | // Double click is emitted, if the second click happened on the same area as the first click. | 428 | // Double click is emitted, if the second click happened on the same area as the first click. |
346 | 479 | // This means mouse_over_area_ is not null and is equal to hit_view. | 429 | // This means mouse_over_area_ is not null and is equal to hit_view. |
347 | 480 | emit_double_click_signal = true; | 430 | emit_double_click_signal = true; |
348 | 481 | } | 431 | } |
349 | 482 | 432 | ||
352 | 483 | SetMouseOverArea(hit_view); | 433 | SetMouseOverArea(hit_view.GetPointer()); |
353 | 484 | SetMouseOwnerArea(hit_view); | 434 | SetMouseOwnerArea(hit_view.GetPointer()); |
354 | 485 | _mouse_position_on_owner = Point(hit_view_x, hit_view_y); | 435 | _mouse_position_on_owner = Point(hit_view_x, hit_view_y); |
355 | 486 | 436 | ||
356 | 487 | // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different | 437 | // In the case of a mouse down event, if there is currently a keyboard event receiver and it is different |
357 | 488 | // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch | 438 | // from the area returned by GetAreaUnderMouse, then stop that receiver from receiving anymore keyboard events and switch |
358 | 489 | // make mouse_over_area_ the new receiver(if it accept keyboard events). | 439 | // make mouse_over_area_ the new receiver(if it accept keyboard events). |
361 | 490 | if (mouse_over_area_ != GetKeyFocusArea() && | 440 | if (mouse_over_area_.IsValid() && mouse_over_area_ != GetKeyFocusArea() && |
362 | 491 | mouse_over_area_ && mouse_over_area_->AcceptKeyNavFocusOnMouseDown()) | 441 | mouse_over_area_->AcceptKeyNavFocusOnMouseDown()) |
363 | 492 | { | 442 | { |
364 | 493 | InputArea* grab_area = GetKeyboardGrabArea(); | 443 | InputArea* grab_area = GetKeyboardGrabArea(); |
365 | 494 | if (grab_area) | 444 | if (grab_area) |
366 | 495 | { | 445 | { |
367 | 496 | if (mouse_over_area_->IsChildOf(grab_area) /*&& mouse_over_area_->AcceptKeyboardEvent()*/) | 446 | if (mouse_over_area_->IsChildOf(grab_area) /*&& mouse_over_area_->AcceptKeyboardEvent()*/) |
368 | 497 | { | 447 | { |
370 | 498 | SetKeyFocusArea(mouse_over_area_); | 448 | SetKeyFocusArea(mouse_over_area_.GetPointer()); |
371 | 499 | } | 449 | } |
372 | 500 | else | 450 | else |
373 | 501 | { | 451 | { |
374 | @@ -504,7 +454,7 @@ | |||
375 | 504 | } | 454 | } |
376 | 505 | else | 455 | else |
377 | 506 | { | 456 | { |
379 | 507 | SetKeyFocusArea(mouse_over_area_); | 457 | SetKeyFocusArea(mouse_over_area_.GetPointer()); |
380 | 508 | } | 458 | } |
381 | 509 | } | 459 | } |
382 | 510 | 460 | ||
383 | @@ -517,11 +467,11 @@ | |||
384 | 517 | mouse_over_area_->EmitMouseDownSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState()); | 467 | mouse_over_area_->EmitMouseDownSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState()); |
385 | 518 | } | 468 | } |
386 | 519 | } | 469 | } |
388 | 520 | else if (hit_view && (event.type == NUX_MOUSE_WHEEL)) | 470 | else if (hit_view.IsValid() && (event.type == NUX_MOUSE_WHEEL)) |
389 | 521 | { | 471 | { |
390 | 522 | hit_view->EmitMouseWheelSignal(hit_view_x, hit_view_y, event.wheel_delta, event.GetMouseState(), event.GetKeyState()); | 472 | hit_view->EmitMouseWheelSignal(hit_view_x, hit_view_y, event.wheel_delta, event.GetMouseState(), event.GetKeyState()); |
391 | 523 | } | 473 | } |
393 | 524 | else if (hit_view && (event.type == NUX_MOUSE_RELEASED)) | 474 | else if (hit_view.IsValid() && (event.type == NUX_MOUSE_RELEASED)) |
394 | 525 | { | 475 | { |
395 | 526 | // We only get a NUX_MOUSE_RELEASED event when the mouse was pressed | 476 | // We only get a NUX_MOUSE_RELEASED event when the mouse was pressed |
396 | 527 | // over another area and released here. There are a few situations that can cause | 477 | // over another area and released here. There are a few situations that can cause |
397 | @@ -533,11 +483,11 @@ | |||
398 | 533 | 483 | ||
399 | 534 | hit_view->EmitMouseUpSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState()); | 484 | hit_view->EmitMouseUpSignal(hit_view_x, hit_view_y, event.GetMouseState(), event.GetKeyState()); |
400 | 535 | } | 485 | } |
402 | 536 | else if (hit_view == NULL) | 486 | else if (!hit_view.IsValid()) |
403 | 537 | { | 487 | { |
405 | 538 | if (mouse_over_area_) | 488 | if (mouse_over_area_.IsValid()) |
406 | 539 | { | 489 | { |
408 | 540 | Geometry geo = mouse_over_area_->GetAbsoluteGeometry(); | 490 | Geometry const& geo = mouse_over_area_->GetAbsoluteGeometry(); |
409 | 541 | int x = event.x - geo.x; | 491 | int x = event.x - geo.x; |
410 | 542 | int y = event.y - geo.y; | 492 | int y = event.y - geo.y; |
411 | 543 | 493 | ||
412 | @@ -570,13 +520,12 @@ | |||
413 | 570 | { | 520 | { |
414 | 571 | // Context: The left mouse button down over an area. All events goes to that area. | 521 | // Context: The left mouse button down over an area. All events goes to that area. |
415 | 572 | // But we still need to know where the mouse is. | 522 | // But we still need to know where the mouse is. |
423 | 573 | 523 | ObjectWeakPtr<InputArea> hit_view; // The view under the mouse | |
424 | 574 | InputArea* hit_view = NULL; // The view under the mouse | 524 | ObjectWeakPtr<BaseWindow> hit_base_window; // The BaseWindow below the mouse pointer. |
425 | 575 | BaseWindow* hit_base_window = NULL; // The BaseWindow below the mouse pointer. | 525 | |
426 | 576 | 526 | GetAreaUnderMouse(Point(event.x, event.y), event.type, hit_view, hit_base_window); | |
427 | 577 | GetAreaUnderMouse(Point(event.x, event.y), event.type, &hit_view, &hit_base_window); | 527 | |
428 | 578 | 528 | Geometry const& mouse_owner_geo = mouse_owner_area_->GetAbsoluteGeometry(); | |
422 | 579 | Geometry mouse_owner_geo = mouse_owner_area_->GetAbsoluteGeometry(); | ||
429 | 580 | int mouse_owner_x = event.x - mouse_owner_geo.x; | 529 | int mouse_owner_x = event.x - mouse_owner_geo.x; |
430 | 581 | int mouse_owner_y = event.y - mouse_owner_geo.y; | 530 | int mouse_owner_y = event.y - mouse_owner_geo.y; |
431 | 582 | 531 | ||
432 | @@ -605,15 +554,15 @@ | |||
433 | 605 | mouse_owner_area_->EmitMouseDragSignal(mouse_owner_x, mouse_owner_y, dx, dy, event.GetMouseState(), event.GetKeyState()); | 554 | mouse_owner_area_->EmitMouseDragSignal(mouse_owner_x, mouse_owner_y, dx, dy, event.GetMouseState(), event.GetKeyState()); |
434 | 606 | } | 555 | } |
435 | 607 | 556 | ||
437 | 608 | if ((mouse_over_area_ == mouse_owner_area_) && (hit_view != mouse_owner_area_)) | 557 | if (mouse_over_area_ == mouse_owner_area_ && hit_view != mouse_owner_area_) |
438 | 609 | { | 558 | { |
439 | 610 | mouse_owner_area_->EmitMouseLeaveSignal(mouse_owner_x, mouse_owner_y, event.GetMouseState(), event.GetKeyState()); | 559 | mouse_owner_area_->EmitMouseLeaveSignal(mouse_owner_x, mouse_owner_y, event.GetMouseState(), event.GetKeyState()); |
441 | 611 | SetMouseOverArea(hit_view); | 560 | SetMouseOverArea(hit_view.GetPointer()); |
442 | 612 | } | 561 | } |
444 | 613 | else if ((mouse_over_area_ != mouse_owner_area_) && (hit_view == mouse_owner_area_)) | 562 | else if (mouse_over_area_ != mouse_owner_area_ && hit_view == mouse_owner_area_) |
445 | 614 | { | 563 | { |
446 | 615 | mouse_owner_area_->EmitMouseEnterSignal(mouse_owner_x, mouse_owner_y, event.GetMouseState(), event.GetKeyState()); | 564 | mouse_owner_area_->EmitMouseEnterSignal(mouse_owner_x, mouse_owner_y, event.GetMouseState(), event.GetKeyState()); |
448 | 616 | SetMouseOverArea(mouse_owner_area_); | 565 | SetMouseOverArea(mouse_owner_area_.GetPointer()); |
449 | 617 | } | 566 | } |
450 | 618 | 567 | ||
451 | 619 | _mouse_position_on_owner = Point(mouse_owner_x, mouse_owner_y); | 568 | _mouse_position_on_owner = Point(mouse_owner_x, mouse_owner_y); |
452 | @@ -625,11 +574,11 @@ | |||
453 | 625 | if (hit_view == mouse_owner_area_) | 574 | if (hit_view == mouse_owner_area_) |
454 | 626 | { | 575 | { |
455 | 627 | mouse_owner_area_->EmitMouseClickSignal(mouse_owner_x, mouse_owner_y, event.GetMouseState(), event.GetKeyState()); | 576 | mouse_owner_area_->EmitMouseClickSignal(mouse_owner_x, mouse_owner_y, event.GetMouseState(), event.GetKeyState()); |
457 | 628 | SetMouseOverArea(mouse_owner_area_); | 577 | SetMouseOverArea(mouse_owner_area_.GetPointer()); |
458 | 629 | } | 578 | } |
459 | 630 | else | 579 | else |
460 | 631 | { | 580 | { |
462 | 632 | SetMouseOverArea(hit_view); | 581 | SetMouseOverArea(hit_view.GetPointer()); |
463 | 633 | } | 582 | } |
464 | 634 | 583 | ||
465 | 635 | SetMouseOwnerArea(NULL); | 584 | SetMouseOwnerArea(NULL); |
466 | @@ -823,36 +772,36 @@ | |||
467 | 823 | void WindowCompositor::FindKeyFocusArea(NuxEventType event_type, | 772 | void WindowCompositor::FindKeyFocusArea(NuxEventType event_type, |
468 | 824 | unsigned int key_symbol, | 773 | unsigned int key_symbol, |
469 | 825 | unsigned int special_keys_state, | 774 | unsigned int special_keys_state, |
472 | 826 | InputArea** key_focus_area, | 775 | ObjectWeakPtr<InputArea>& key_focus_area, |
473 | 827 | BaseWindow** window) | 776 | ObjectWeakPtr<BaseWindow>& window) |
474 | 828 | { | 777 | { |
477 | 829 | *key_focus_area = NULL; | 778 | key_focus_area = NULL; |
478 | 830 | *window = NULL; | 779 | window = NULL; |
479 | 831 | 780 | ||
480 | 832 | // Go through the list of BaseWindos and find the first area over which the mouse pointer is. | 781 | // Go through the list of BaseWindos and find the first area over which the mouse pointer is. |
481 | 833 | WindowList::iterator window_it; | 782 | WindowList::iterator window_it; |
482 | 834 | window_it = _view_window_list.begin(); | 783 | window_it = _view_window_list.begin(); |
484 | 835 | while ((*key_focus_area == NULL) && (window_it != _view_window_list.end())) | 784 | while (!key_focus_area.IsValid() && window_it != _view_window_list.end()) |
485 | 836 | { | 785 | { |
486 | 837 | if ((*window_it).IsValid() && (*window_it)->IsVisible()) | 786 | if ((*window_it).IsValid() && (*window_it)->IsVisible()) |
487 | 838 | { | 787 | { |
490 | 839 | *key_focus_area = NUX_STATIC_CAST(InputArea*, (*window_it)->FindKeyFocusArea(event_type, key_symbol, special_keys_state)); | 788 | key_focus_area = NUX_STATIC_CAST(InputArea*, (*window_it)->FindKeyFocusArea(event_type, key_symbol, special_keys_state)); |
491 | 840 | if (key_focus_area) | 789 | if (key_focus_area.IsValid()) |
492 | 841 | { | 790 | { |
493 | 842 | // We have found an area. We are going to exit the while loop. | 791 | // We have found an area. We are going to exit the while loop. |
495 | 843 | *window = (*window_it).GetPointer(); | 792 | window = *window_it; |
496 | 844 | } | 793 | } |
497 | 845 | } | 794 | } |
498 | 846 | ++window_it; | 795 | ++window_it; |
499 | 847 | } | 796 | } |
500 | 848 | 797 | ||
501 | 849 | // If key_focus_area is NULL, then try the main window layout. | 798 | // If key_focus_area is NULL, then try the main window layout. |
503 | 850 | if (*key_focus_area == NULL) | 799 | if (!key_focus_area.IsValid()) |
504 | 851 | { | 800 | { |
505 | 852 | Layout* main_window_layout = window_thread_->GetLayout(); | 801 | Layout* main_window_layout = window_thread_->GetLayout(); |
506 | 853 | if (main_window_layout) | 802 | if (main_window_layout) |
507 | 854 | { | 803 | { |
509 | 855 | *key_focus_area = NUX_STATIC_CAST(InputArea*, main_window_layout->FindKeyFocusArea(event_type, key_symbol, special_keys_state)); | 804 | key_focus_area = NUX_STATIC_CAST(InputArea*, main_window_layout->FindKeyFocusArea(event_type, key_symbol, special_keys_state)); |
510 | 856 | } | 805 | } |
511 | 857 | } | 806 | } |
512 | 858 | } | 807 | } |
513 | @@ -861,21 +810,21 @@ | |||
514 | 861 | unsigned int key_symbol, | 810 | unsigned int key_symbol, |
515 | 862 | unsigned int special_keys_state, | 811 | unsigned int special_keys_state, |
516 | 863 | InputArea* root_search_area, | 812 | InputArea* root_search_area, |
519 | 864 | InputArea** key_focus_area, | 813 | ObjectWeakPtr<InputArea>& key_focus_area, |
520 | 865 | BaseWindow** window) | 814 | ObjectWeakPtr<BaseWindow>& window) |
521 | 866 | { | 815 | { |
524 | 867 | *key_focus_area = NULL; | 816 | key_focus_area = NULL; |
525 | 868 | *window = NULL; | 817 | window = NULL; |
526 | 869 | 818 | ||
527 | 870 | if (root_search_area == NULL) | 819 | if (root_search_area == NULL) |
528 | 871 | { | 820 | { |
529 | 872 | return; | 821 | return; |
530 | 873 | } | 822 | } |
531 | 874 | 823 | ||
534 | 875 | *key_focus_area = NUX_STATIC_CAST(InputArea*, root_search_area->FindKeyFocusArea(event_type, key_symbol, special_keys_state)); | 824 | key_focus_area = NUX_STATIC_CAST(InputArea*, root_search_area->FindKeyFocusArea(event_type, key_symbol, special_keys_state)); |
535 | 876 | if (key_focus_area) | 825 | if (key_focus_area.IsValid()) |
536 | 877 | { | 826 | { |
538 | 878 | *window = NUX_STATIC_CAST(BaseWindow*, root_search_area->GetTopLevelViewWindow()); | 827 | window = NUX_STATIC_CAST(BaseWindow*, root_search_area->GetTopLevelViewWindow()); |
539 | 879 | } | 828 | } |
540 | 880 | } | 829 | } |
541 | 881 | 830 | ||
542 | @@ -908,25 +857,21 @@ | |||
543 | 908 | { | 857 | { |
544 | 909 | InputArea* keyboard_event_grab_view = GetKeyboardGrabArea(); | 858 | InputArea* keyboard_event_grab_view = GetKeyboardGrabArea(); |
545 | 910 | 859 | ||
548 | 911 | InputArea* focus_area = NULL; // The view under the mouse | 860 | ObjectWeakPtr<InputArea> focus_area; // The view under the mouse |
549 | 912 | BaseWindow* base_window = NULL; // The BaseWindow below the mouse pointer. | 861 | ObjectWeakPtr<BaseWindow> base_window; // The BaseWindow below the mouse pointer. |
550 | 913 | 862 | ||
551 | 914 | if (keyboard_event_grab_view) | 863 | if (keyboard_event_grab_view) |
552 | 915 | { | 864 | { |
553 | 916 | // There is a keyboard grab. | 865 | // There is a keyboard grab. |
554 | 917 | // Find the key focus area, under the keyboard grab area. That is to say, the key focus area is in the widget tree | 866 | // Find the key focus area, under the keyboard grab area. That is to say, the key focus area is in the widget tree |
555 | 918 | // whose root is the keyboard grab area. This phase is known as the capture phase. | 867 | // whose root is the keyboard grab area. This phase is known as the capture phase. |
556 | 919 | |||
557 | 920 | FindKeyFocusAreaFrom(event.type, event.GetKeySym(), event.GetKeyState(), | 868 | FindKeyFocusAreaFrom(event.type, event.GetKeySym(), event.GetKeyState(), |
561 | 921 | keyboard_event_grab_view, | 869 | keyboard_event_grab_view, focus_area, base_window); |
559 | 922 | &focus_area, | ||
560 | 923 | &base_window); | ||
562 | 924 | } | 870 | } |
563 | 925 | else | 871 | else |
564 | 926 | { | 872 | { |
565 | 927 | FindKeyFocusArea(event.type, event.GetKeySym(), event.GetKeyState(), | 873 | FindKeyFocusArea(event.type, event.GetKeySym(), event.GetKeyState(), |
568 | 928 | &focus_area, | 874 | focus_area, base_window); |
567 | 929 | &base_window); | ||
569 | 930 | } | 875 | } |
570 | 931 | 876 | ||
571 | 932 | KeyNavDirection direction = KEY_NAV_NONE; | 877 | KeyNavDirection direction = KEY_NAV_NONE; |
572 | @@ -964,20 +909,20 @@ | |||
573 | 964 | } | 909 | } |
574 | 965 | } | 910 | } |
575 | 966 | 911 | ||
577 | 967 | if (focus_area) | 912 | if (focus_area.IsValid()) |
578 | 968 | { | 913 | { |
580 | 969 | SetKeyFocusArea(focus_area, direction); | 914 | SetKeyFocusArea(focus_area.GetPointer(), direction); |
581 | 970 | } | 915 | } |
582 | 971 | else | 916 | else |
583 | 972 | { | 917 | { |
584 | 973 | SetKeyFocusArea(NULL, KEY_NAV_NONE); | 918 | SetKeyFocusArea(NULL, KEY_NAV_NONE); |
585 | 974 | } | 919 | } |
586 | 975 | 920 | ||
588 | 976 | if (key_focus_area_) | 921 | if (key_focus_area_.IsValid()) |
589 | 977 | { | 922 | { |
590 | 978 | if (key_focus_area_->InspectKeyEvent(event.type, event.GetKeySym(), event.GetText())) | 923 | if (key_focus_area_->InspectKeyEvent(event.type, event.GetKeySym(), event.GetText())) |
591 | 979 | { | 924 | { |
593 | 980 | SendKeyEvent(key_focus_area_, | 925 | SendKeyEvent(key_focus_area_.GetPointer(), |
594 | 981 | event.type, | 926 | event.type, |
595 | 982 | event.GetKeySym(), | 927 | event.GetKeySym(), |
596 | 983 | #if defined(NUX_OS_WINDOWS) | 928 | #if defined(NUX_OS_WINDOWS) |
597 | @@ -1014,25 +959,25 @@ | |||
598 | 1014 | } | 959 | } |
599 | 1015 | } | 960 | } |
600 | 1016 | else if (event.type == NUX_KEYDOWN) | 961 | else if (event.type == NUX_KEYDOWN) |
602 | 1017 | { | 962 | { |
603 | 1018 | if (direction == KEY_NAV_ENTER) | 963 | if (direction == KEY_NAV_ENTER) |
604 | 1019 | { | 964 | { |
606 | 1020 | if (key_focus_area_ && key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) | 965 | if (key_focus_area_.IsValid() && key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) |
607 | 1021 | { | 966 | { |
608 | 1022 | // Signal emitted from the WindowCompositor. | 967 | // Signal emitted from the WindowCompositor. |
610 | 1023 | key_nav_focus_activate.emit(key_focus_area_); | 968 | key_nav_focus_activate.emit(key_focus_area_.GetPointer()); |
611 | 1024 | // Signal emitted from the area itsel. | 969 | // Signal emitted from the area itsel. |
613 | 1025 | static_cast<InputArea*>(key_focus_area_)->key_nav_focus_activate.emit(key_focus_area_); | 970 | key_focus_area_->key_nav_focus_activate.emit(key_focus_area_.GetPointer()); |
614 | 1026 | } | 971 | } |
615 | 1027 | } | 972 | } |
616 | 1028 | else | 973 | else |
617 | 1029 | { | 974 | { |
618 | 1030 | InputArea* key_nav_focus = NULL; | 975 | InputArea* key_nav_focus = NULL; |
619 | 1031 | Area* parent = key_focus_area_->GetParentObject(); | 976 | Area* parent = key_focus_area_->GetParentObject(); |
621 | 1032 | 977 | ||
622 | 1033 | if (parent) | 978 | if (parent) |
623 | 1034 | key_nav_focus = NUX_STATIC_CAST(InputArea*, parent->KeyNavIteration(direction)); | 979 | key_nav_focus = NUX_STATIC_CAST(InputArea*, parent->KeyNavIteration(direction)); |
625 | 1035 | 980 | ||
626 | 1036 | while (key_nav_focus == NULL && parent != NULL) | 981 | while (key_nav_focus == NULL && parent != NULL) |
627 | 1037 | { | 982 | { |
628 | 1038 | parent = parent->GetParentObject(); | 983 | parent = parent->GetParentObject(); |
629 | @@ -1589,10 +1534,10 @@ | |||
630 | 1589 | // End 2D Drawing | 1534 | // End 2D Drawing |
631 | 1590 | } | 1535 | } |
632 | 1591 | 1536 | ||
634 | 1592 | if (key_focus_area_) | 1537 | if (key_focus_area_.IsValid()) |
635 | 1593 | { | 1538 | { |
636 | 1594 | // key focus test | 1539 | // key focus test |
638 | 1595 | Geometry geo= key_focus_area_->GetRootGeometry(); | 1540 | Geometry const& geo = key_focus_area_->GetRootGeometry(); |
639 | 1596 | //GetGraphicsDisplay()->GetGraphicsEngine()->QRP_Color(geo.x, geo.y, geo.width, geo.height, color::Blue); | 1541 | //GetGraphicsDisplay()->GetGraphicsEngine()->QRP_Color(geo.x, geo.y, geo.width, geo.height, color::Blue); |
640 | 1597 | } | 1542 | } |
641 | 1598 | 1543 | ||
642 | @@ -1851,17 +1796,6 @@ | |||
643 | 1851 | return true; | 1796 | return true; |
644 | 1852 | } | 1797 | } |
645 | 1853 | 1798 | ||
646 | 1854 | void WindowCompositor::OnKeyNavFocusDestroyed(Object* area) | ||
647 | 1855 | { | ||
648 | 1856 | if (key_focus_area_ == area) | ||
649 | 1857 | { | ||
650 | 1858 | key_focus_area_->ResetDownwardPathToKeyFocusArea(); | ||
651 | 1859 | key_focus_area_->ResetUpwardPathToKeyFocusArea(); | ||
652 | 1860 | |||
653 | 1861 | key_focus_area_ = NULL; | ||
654 | 1862 | } | ||
655 | 1863 | } | ||
656 | 1864 | |||
657 | 1865 | bool WindowCompositor::SetKeyFocusArea(InputArea* area, KeyNavDirection direction) | 1799 | bool WindowCompositor::SetKeyFocusArea(InputArea* area, KeyNavDirection direction) |
658 | 1866 | { | 1800 | { |
659 | 1867 | InputArea* keyboard_grab_area = GetKeyboardGrabArea(); | 1801 | InputArea* keyboard_grab_area = GetKeyboardGrabArea(); |
660 | @@ -1886,7 +1820,7 @@ | |||
661 | 1886 | return false; | 1820 | return false; |
662 | 1887 | } | 1821 | } |
663 | 1888 | 1822 | ||
665 | 1889 | if (key_focus_area_) | 1823 | if (key_focus_area_.IsValid()) |
666 | 1890 | { | 1824 | { |
667 | 1891 | // This is the area that has the keyboard focus. Emit the signal 'end_key_focus'. | 1825 | // This is the area that has the keyboard focus. Emit the signal 'end_key_focus'. |
668 | 1892 | key_focus_area_->end_key_focus.emit(); | 1826 | key_focus_area_->end_key_focus.emit(); |
669 | @@ -1898,9 +1832,9 @@ | |||
670 | 1898 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) | 1832 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) |
671 | 1899 | { | 1833 | { |
672 | 1900 | // Signal emitted from the WindowCompositor. | 1834 | // Signal emitted from the WindowCompositor. |
674 | 1901 | key_nav_focus_change.emit(key_focus_area_, false, direction); | 1835 | key_nav_focus_change.emit(key_focus_area_.GetPointer(), false, direction); |
675 | 1902 | // Signal emitted from the area itself. | 1836 | // Signal emitted from the area itself. |
677 | 1903 | static_cast<InputArea*>(key_focus_area_)->key_nav_focus_change.emit(key_focus_area_, false, direction); | 1837 | key_focus_area_->key_nav_focus_change.emit(key_focus_area_.GetPointer(), false, direction); |
678 | 1904 | // nuxDebugMsg("[WindowCompositor::SetKeyFocusArea] Area type '%s' named '%s': Lost key nav focus.", | 1838 | // nuxDebugMsg("[WindowCompositor::SetKeyFocusArea] Area type '%s' named '%s': Lost key nav focus.", |
679 | 1905 | // key_focus_area_->Type().name, | 1839 | // key_focus_area_->Type().name, |
680 | 1906 | // key_focus_area_->GetBaseString().GetTCharPtr()); | 1840 | // key_focus_area_->GetBaseString().GetTCharPtr()); |
681 | @@ -1908,7 +1842,7 @@ | |||
682 | 1908 | 1842 | ||
683 | 1909 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) | 1843 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) |
684 | 1910 | { | 1844 | { |
686 | 1911 | static_cast<View*>(key_focus_area_)->QueueDraw(); | 1845 | static_cast<View*>(key_focus_area_.GetPointer())->QueueDraw(); |
687 | 1912 | } | 1846 | } |
688 | 1913 | } | 1847 | } |
689 | 1914 | 1848 | ||
690 | @@ -1926,9 +1860,9 @@ | |||
691 | 1926 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) | 1860 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) |
692 | 1927 | { | 1861 | { |
693 | 1928 | // Signal emitted from the WindowCompositor. | 1862 | // Signal emitted from the WindowCompositor. |
695 | 1929 | key_nav_focus_change.emit(key_focus_area_, true, direction); | 1863 | key_nav_focus_change.emit(key_focus_area_.GetPointer(), true, direction); |
696 | 1930 | // Signal emitted from the area itself. | 1864 | // Signal emitted from the area itself. |
698 | 1931 | static_cast<InputArea*>(key_focus_area_)->key_nav_focus_change.emit(key_focus_area_, true, direction); | 1865 | key_focus_area_->key_nav_focus_change.emit(key_focus_area_.GetPointer(), true, direction); |
699 | 1932 | // nuxDebugMsg("[WindowCompositor::SetKeyFocusArea] Area type '%s' named '%s': Has key nav focus.", | 1866 | // nuxDebugMsg("[WindowCompositor::SetKeyFocusArea] Area type '%s' named '%s': Has key nav focus.", |
700 | 1933 | // key_focus_area_->Type().name, | 1867 | // key_focus_area_->Type().name, |
701 | 1934 | // key_focus_area_->GetBaseString().GetTCharPtr()); | 1868 | // key_focus_area_->GetBaseString().GetTCharPtr()); |
702 | @@ -1936,10 +1870,10 @@ | |||
703 | 1936 | 1870 | ||
704 | 1937 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) | 1871 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) |
705 | 1938 | { | 1872 | { |
707 | 1939 | static_cast<View*>(key_focus_area_)->QueueDraw(); | 1873 | static_cast<View*>(key_focus_area_.GetPointer())->QueueDraw(); |
708 | 1940 | } | 1874 | } |
709 | 1941 | 1875 | ||
711 | 1942 | key_focus_area_->ChildFocusChanged.emit(key_focus_area_); | 1876 | key_focus_area_->ChildFocusChanged.emit(key_focus_area_.GetPointer()); |
712 | 1943 | 1877 | ||
713 | 1944 | } | 1878 | } |
714 | 1945 | else | 1879 | else |
715 | @@ -1947,24 +1881,12 @@ | |||
716 | 1947 | key_focus_area_ = NULL; | 1881 | key_focus_area_ = NULL; |
717 | 1948 | } | 1882 | } |
718 | 1949 | 1883 | ||
732 | 1950 | key_focus_area_connection_.disconnect(); | 1884 | return key_focus_area_.IsValid() ? true : false; |
720 | 1951 | |||
721 | 1952 | if (area) | ||
722 | 1953 | { | ||
723 | 1954 | key_focus_area_connection_ = area->object_destroyed.connect(sigc::mem_fun(this, &WindowCompositor::OnKeyNavFocusDestroyed)); | ||
724 | 1955 | } | ||
725 | 1956 | |||
726 | 1957 | if (key_focus_area_ == NULL) | ||
727 | 1958 | { | ||
728 | 1959 | return false; | ||
729 | 1960 | } | ||
730 | 1961 | |||
731 | 1962 | return true; | ||
733 | 1963 | } | 1885 | } |
734 | 1964 | 1886 | ||
735 | 1965 | InputArea* WindowCompositor::GetKeyFocusArea() | 1887 | InputArea* WindowCompositor::GetKeyFocusArea() |
736 | 1966 | { | 1888 | { |
738 | 1967 | return key_focus_area_; | 1889 | return key_focus_area_.GetPointer(); |
739 | 1968 | } | 1890 | } |
740 | 1969 | 1891 | ||
741 | 1970 | void WindowCompositor::SetBackgroundPaintLayer(AbstractPaintLayer* bkg) | 1892 | void WindowCompositor::SetBackgroundPaintLayer(AbstractPaintLayer* bkg) |
742 | @@ -2220,7 +2142,7 @@ | |||
743 | 2220 | keyboard_grab_stack_.push_front(area); | 2142 | keyboard_grab_stack_.push_front(area); |
744 | 2221 | 2143 | ||
745 | 2222 | // If there is any area with the key focus, cancel it. | 2144 | // If there is any area with the key focus, cancel it. |
747 | 2223 | if (key_focus_area_) | 2145 | if (key_focus_area_.IsValid()) |
748 | 2224 | { | 2146 | { |
749 | 2225 | key_focus_area_->end_key_focus.emit(); | 2147 | key_focus_area_->end_key_focus.emit(); |
750 | 2226 | key_focus_area_->ResetUpwardPathToKeyFocusArea(); | 2148 | key_focus_area_->ResetUpwardPathToKeyFocusArea(); |
751 | @@ -2228,9 +2150,9 @@ | |||
752 | 2228 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) | 2150 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) |
753 | 2229 | { | 2151 | { |
754 | 2230 | // Signal emitted from the WindowCompositor. | 2152 | // Signal emitted from the WindowCompositor. |
756 | 2231 | key_nav_focus_change.emit(key_focus_area_, false, KEY_NAV_NONE); | 2153 | key_nav_focus_change.emit(key_focus_area_.GetPointer(), false, KEY_NAV_NONE); |
757 | 2232 | // Signal emitted from the area itself. | 2154 | // Signal emitted from the area itself. |
759 | 2233 | static_cast<InputArea*>(key_focus_area_)->key_nav_focus_change.emit(key_focus_area_, false, KEY_NAV_NONE); | 2155 | key_focus_area_->key_nav_focus_change.emit(key_focus_area_.GetPointer(), false, KEY_NAV_NONE); |
760 | 2234 | // nuxDebugMsg("[WindowCompositor::GrabKeyboardAdd] Area type '%s' named '%s': Lost key nav focus.", | 2156 | // nuxDebugMsg("[WindowCompositor::GrabKeyboardAdd] Area type '%s' named '%s': Lost key nav focus.", |
761 | 2235 | // key_focus_area_->Type().name, | 2157 | // key_focus_area_->Type().name, |
762 | 2236 | // key_focus_area_->GetBaseString().GetTCharPtr()); | 2158 | // key_focus_area_->GetBaseString().GetTCharPtr()); |
763 | @@ -2239,7 +2161,7 @@ | |||
764 | 2239 | 2161 | ||
765 | 2240 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) | 2162 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) |
766 | 2241 | { | 2163 | { |
768 | 2242 | static_cast<View*>(key_focus_area_)->QueueDraw(); | 2164 | static_cast<View*>(key_focus_area_.GetPointer())->QueueDraw(); |
769 | 2243 | } | 2165 | } |
770 | 2244 | key_focus_area_ = NULL; | 2166 | key_focus_area_ = NULL; |
771 | 2245 | } | 2167 | } |
772 | @@ -2295,7 +2217,7 @@ | |||
773 | 2295 | else | 2217 | else |
774 | 2296 | { | 2218 | { |
775 | 2297 | // If there is any area with the key focus, cancel it. | 2219 | // If there is any area with the key focus, cancel it. |
777 | 2298 | if (key_focus_area_) | 2220 | if (key_focus_area_.IsValid()) |
778 | 2299 | { | 2221 | { |
779 | 2300 | key_focus_area_->end_key_focus.emit(); | 2222 | key_focus_area_->end_key_focus.emit(); |
780 | 2301 | key_focus_area_->ResetUpwardPathToKeyFocusArea(); | 2223 | key_focus_area_->ResetUpwardPathToKeyFocusArea(); |
781 | @@ -2303,9 +2225,9 @@ | |||
782 | 2303 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) | 2225 | if (key_focus_area_->Type().IsDerivedFromType(InputArea::StaticObjectType)) |
783 | 2304 | { | 2226 | { |
784 | 2305 | // Signal emitted from the WindowCompositor. | 2227 | // Signal emitted from the WindowCompositor. |
786 | 2306 | key_nav_focus_change.emit(key_focus_area_, false, KEY_NAV_NONE); | 2228 | key_nav_focus_change.emit(key_focus_area_.GetPointer(), false, KEY_NAV_NONE); |
787 | 2307 | // Signal emitted from the area itself. | 2229 | // Signal emitted from the area itself. |
789 | 2308 | static_cast<InputArea*>(key_focus_area_)->key_nav_focus_change.emit(key_focus_area_, false, KEY_NAV_NONE); | 2230 | key_focus_area_->key_nav_focus_change.emit(key_focus_area_.GetPointer(), false, KEY_NAV_NONE); |
790 | 2309 | // nuxDebugMsg("[WindowCompositor::GrabKeyboardRemove] Area type '%s' named '%s': Lost key nav focus.", | 2231 | // nuxDebugMsg("[WindowCompositor::GrabKeyboardRemove] Area type '%s' named '%s': Lost key nav focus.", |
791 | 2310 | // key_focus_area_->Type().name, | 2232 | // key_focus_area_->Type().name, |
792 | 2311 | // key_focus_area_->GetBaseString().GetTCharPtr()); | 2233 | // key_focus_area_->GetBaseString().GetTCharPtr()); |
793 | @@ -2313,7 +2235,7 @@ | |||
794 | 2313 | 2235 | ||
795 | 2314 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) | 2236 | if (key_focus_area_->Type().IsDerivedFromType(View::StaticObjectType)) |
796 | 2315 | { | 2237 | { |
798 | 2316 | static_cast<View*>(key_focus_area_)->QueueDraw(); | 2238 | static_cast<View*>(key_focus_area_.GetPointer())->QueueDraw(); |
799 | 2317 | } | 2239 | } |
800 | 2318 | key_focus_area_ = NULL; | 2240 | key_focus_area_ = NULL; |
801 | 2319 | } | 2241 | } |
802 | 2320 | 2242 | ||
803 | === modified file 'Nux/WindowCompositor.h' | |||
804 | --- Nux/WindowCompositor.h 2012-06-26 13:38:50 +0000 | |||
805 | +++ Nux/WindowCompositor.h 2012-09-18 18:30:40 +0000 | |||
806 | @@ -127,50 +127,38 @@ | |||
807 | 127 | //! Traverse the widget tree and found the area that is right below the mouse pointer. | 127 | //! Traverse the widget tree and found the area that is right below the mouse pointer. |
808 | 128 | void GetAreaUnderMouse(const Point& mouse_position, | 128 | void GetAreaUnderMouse(const Point& mouse_position, |
809 | 129 | NuxEventType event_type, | 129 | NuxEventType event_type, |
812 | 130 | InputArea** area_under_mouse_pointer, | 130 | ObjectWeakPtr<InputArea>& area_under_mouse_pointer, |
813 | 131 | BaseWindow** window); | 131 | ObjectWeakPtr<BaseWindow>& window); |
814 | 132 | 132 | ||
815 | 133 | //! Traverse the widget tree and found the area has the key focus. | 133 | //! Traverse the widget tree and found the area has the key focus. |
816 | 134 | void FindKeyFocusArea(NuxEventType event_type, | 134 | void FindKeyFocusArea(NuxEventType event_type, |
817 | 135 | unsigned int key_symbol, | 135 | unsigned int key_symbol, |
818 | 136 | unsigned int special_keys_state, | 136 | unsigned int special_keys_state, |
822 | 137 | InputArea** key_focus_area, | 137 | ObjectWeakPtr<InputArea>& key_focus_area, |
823 | 138 | BaseWindow** window); | 138 | ObjectWeakPtr<BaseWindow>& window); |
824 | 139 | 139 | ||
825 | 140 | //! Traverse the widget tree and found the area has the key focus, but start from a specified widget. | 140 | //! Traverse the widget tree and found the area has the key focus, but start from a specified widget. |
826 | 141 | void FindKeyFocusAreaFrom(NuxEventType event_type, | 141 | void FindKeyFocusAreaFrom(NuxEventType event_type, |
827 | 142 | unsigned int key_symbol, | 142 | unsigned int key_symbol, |
828 | 143 | unsigned int special_keys_state, | 143 | unsigned int special_keys_state, |
829 | 144 | InputArea* root_search_area, | 144 | InputArea* root_search_area, |
832 | 145 | InputArea** key_focus_area, | 145 | ObjectWeakPtr<InputArea>& key_focus_area, |
833 | 146 | BaseWindow** window); | 146 | ObjectWeakPtr<BaseWindow>& window); |
834 | 147 | 147 | ||
835 | 148 | void ResetMousePointerAreas(); | 148 | void ResetMousePointerAreas(); |
836 | 149 | 149 | ||
837 | 150 | //! Get the area upon which the mouse button is currently down. | 150 | //! Get the area upon which the mouse button is currently down. |
839 | 151 | Area* GetMouseOwnerArea(); | 151 | ObjectWeakPtr<InputArea> const& GetMouseOwnerArea() const; |
840 | 152 | 152 | ||
841 | 153 | //! Set the area upon which the mouse button is currently down. | 153 | //! Set the area upon which the mouse button is currently down. |
843 | 154 | void SetMouseOwnerArea(Area* area); | 154 | void SetMouseOwnerArea(InputArea* area); |
844 | 155 | 155 | ||
845 | 156 | //! Set the area that is right below the mouse pointer. | 156 | //! Set the area that is right below the mouse pointer. |
848 | 157 | void SetMouseOverArea(Area* area); | 157 | void SetMouseOverArea(InputArea* area); |
849 | 158 | 158 | ||
850 | 159 | //! Set The BaseWindow of the area that is the mouse owner. | 159 | //! Set The BaseWindow of the area that is the mouse owner. |
851 | 160 | void SetMouseOwnerBaseWindow(BaseWindow* base_window); | 160 | void SetMouseOwnerBaseWindow(BaseWindow* base_window); |
852 | 161 | 161 | ||
853 | 162 | //! Callback: called when mouse_over_area_ is destroyed. | ||
854 | 163 | void OnMouseOverViewDestroyed(Object* area); | ||
855 | 164 | |||
856 | 165 | //! Callback: called when mouse_owner_area_ is destroyed. | ||
857 | 166 | void OnMouseOwnerViewDestroyed(Object* area); | ||
858 | 167 | |||
859 | 168 | //! Callback: called when key_focus_area_ is destroyed. | ||
860 | 169 | void OnKeyNavFocusDestroyed(Object* area); | ||
861 | 170 | |||
862 | 171 | //! Callback: called when mouse_owner_basewindow_connection_ is destroyed. | ||
863 | 172 | void OnMouseOwnerBaseWindowDestroyed(Object* area); | ||
864 | 173 | |||
865 | 174 | void SendKeyEvent(InputArea* input_area, NuxEventType event_type, | 162 | void SendKeyEvent(InputArea* input_area, NuxEventType event_type, |
866 | 175 | unsigned int key_sym, | 163 | unsigned int key_sym, |
867 | 176 | unsigned long x11_key_code, | 164 | unsigned long x11_key_code, |
868 | @@ -184,19 +172,14 @@ | |||
869 | 184 | The InputArea that has the mouse focus also has the keyboard focus. That is if _mouse_focus_area is not Null | 172 | The InputArea that has the mouse focus also has the keyboard focus. That is if _mouse_focus_area is not Null |
870 | 185 | then _mouse_focus_area is equal to _mouse_focus_area; | 173 | then _mouse_focus_area is equal to _mouse_focus_area; |
871 | 186 | */ | 174 | */ |
876 | 187 | InputArea* key_focus_area_; | 175 | ObjectWeakPtr<InputArea> key_focus_area_; |
877 | 188 | InputArea* mouse_owner_area_; | 176 | ObjectWeakPtr<InputArea> mouse_owner_area_; |
878 | 189 | InputArea* mouse_over_area_; | 177 | ObjectWeakPtr<InputArea> mouse_over_area_; |
879 | 190 | BaseWindow* mouse_owner_base_window_; | 178 | ObjectWeakPtr<BaseWindow> mouse_owner_base_window_; |
880 | 191 | 179 | ||
881 | 192 | int dnd_safety_x_; | 180 | int dnd_safety_x_; |
882 | 193 | int dnd_safety_y_; | 181 | int dnd_safety_y_; |
883 | 194 | 182 | ||
884 | 195 | sigc::connection mouse_over_view_connection_; | ||
885 | 196 | sigc::connection mouse_owner_view_connection_; | ||
886 | 197 | sigc::connection mouse_owner_basewindow_connection_; | ||
887 | 198 | sigc::connection key_focus_area_connection_; | ||
888 | 199 | |||
889 | 200 | /*! | 183 | /*! |
890 | 201 | This signal is similar to Area::key_nav_focus_change. It is emitted from the WindowCompositor. | 184 | This signal is similar to Area::key_nav_focus_change. It is emitted from the WindowCompositor. |
891 | 202 | The user only needs to listen to this signal to find out the area that has received the keyboard focus.\n | 185 | The user only needs to listen to this signal to find out the area that has received the keyboard focus.\n |
892 | @@ -682,6 +665,7 @@ | |||
893 | 682 | friend class VSplitter; | 665 | friend class VSplitter; |
894 | 683 | friend class TableCtrl; | 666 | friend class TableCtrl; |
895 | 684 | friend class View; | 667 | friend class View; |
896 | 668 | friend class TestWindowCompositor; | ||
897 | 685 | }; | 669 | }; |
898 | 686 | 670 | ||
899 | 687 | #ifdef NUX_GESTURES_SUPPORT | 671 | #ifdef NUX_GESTURES_SUPPORT |
900 | 688 | 672 | ||
901 | === modified file 'configure.ac' | |||
902 | --- configure.ac 2012-08-30 10:57:51 +0000 | |||
903 | +++ configure.ac 2012-09-18 18:30:40 +0000 | |||
904 | @@ -22,7 +22,7 @@ | |||
905 | 22 | # The number format is : year/month/day | 22 | # The number format is : year/month/day |
906 | 23 | # e.g.: december 5th, 2011 is: 20111205 | 23 | # e.g.: december 5th, 2011 is: 20111205 |
907 | 24 | # To make more than one API change in a day, add a number to the date. Like 20111205.xx | 24 | # To make more than one API change in a day, add a number to the date. Like 20111205.xx |
909 | 25 | m4_define([nux_abi_version], [20120813.01]) | 25 | m4_define([nux_abi_version], [20120914.02]) |
910 | 26 | 26 | ||
911 | 27 | m4_define([nux_version], | 27 | m4_define([nux_version], |
912 | 28 | [nux_major_version.nux_minor_version.nux_micro_version]) | 28 | [nux_major_version.nux_minor_version.nux_micro_version]) |
913 | 29 | 29 | ||
914 | === modified file 'tests/gtest-nux-area.cpp' | |||
915 | --- tests/gtest-nux-area.cpp 2012-03-02 02:48:48 +0000 | |||
916 | +++ tests/gtest-nux-area.cpp 2012-09-18 18:30:40 +0000 | |||
917 | @@ -1,11 +1,26 @@ | |||
920 | 1 | #include <string> | 1 | /* |
921 | 2 | #include <fstream> | 2 | * Copyright 2010 Inalogic® Inc. |
922 | 3 | * | ||
923 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
924 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | ||
925 | 6 | * published by the Free Software Foundation. | ||
926 | 7 | * | ||
927 | 8 | * This program is distributed in the hope that it will be useful, but | ||
928 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
929 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
930 | 11 | * PURPOSE. See the applicable version of the GNU Lesser General Public | ||
931 | 12 | * License for more details. | ||
932 | 13 | * | ||
933 | 14 | * You should have received a copy of both the GNU Lesser General Public | ||
934 | 15 | * License version 3 along with this program. If not, see | ||
935 | 16 | * <http://www.gnu.org/licenses/> | ||
936 | 17 | * | ||
937 | 18 | * Authored by: Jay Taoko <jaytaoko@inalogic.com> | ||
938 | 19 | * Marco Trevisan <marco.trevisan@canonical.com> | ||
939 | 20 | */ | ||
940 | 3 | 21 | ||
941 | 4 | #include <iostream> | ||
942 | 5 | #include <gmock/gmock.h> | 22 | #include <gmock/gmock.h> |
946 | 6 | #include <boost/filesystem.hpp> | 23 | #include <boost/shared_ptr.hpp> |
944 | 7 | #include <glib.h> | ||
945 | 8 | |||
947 | 9 | #include "Nux/Nux.h" | 24 | #include "Nux/Nux.h" |
948 | 10 | #include "Nux/HLayout.h" | 25 | #include "Nux/HLayout.h" |
949 | 11 | #include "Nux/StaticText.h" | 26 | #include "Nux/StaticText.h" |
950 | @@ -16,14 +31,39 @@ | |||
951 | 16 | 31 | ||
952 | 17 | namespace { | 32 | namespace { |
953 | 18 | 33 | ||
962 | 19 | TEST(TestArea, TestAreaSize) | 34 | struct MockTestView : nux::TestView |
963 | 20 | { | 35 | { |
964 | 21 | nux::NuxInitialize(0); | 36 | MockTestView() |
965 | 22 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200, | 37 | : nux::TestView("MockTestView") |
966 | 23 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | 38 | {} |
967 | 24 | 39 | ||
968 | 25 | nux::TestView* test_view = new nux::TestView(""); | 40 | void SetNextObjectToKeyFocusArea(nux::Area* area) |
969 | 26 | 41 | { | |
970 | 42 | TestView::SetNextObjectToKeyFocusArea(area); | ||
971 | 43 | } | ||
972 | 44 | |||
973 | 45 | nux::Area* GetNextObjectToKeyFocusArea() | ||
974 | 46 | { | ||
975 | 47 | return TestView::GetNextObjectToKeyFocusArea(); | ||
976 | 48 | } | ||
977 | 49 | }; | ||
978 | 50 | |||
979 | 51 | struct TestArea : public testing::Test | ||
980 | 52 | { | ||
981 | 53 | void SetUp() | ||
982 | 54 | { | ||
983 | 55 | nux::NuxInitialize(0); | ||
984 | 56 | wnd_thread.reset(nux::CreateNuxWindow("Area Test", 300, 200, nux::WINDOWSTYLE_NORMAL, | ||
985 | 57 | NULL, false, NULL, NULL)); | ||
986 | 58 | test_view = new MockTestView(); | ||
987 | 59 | } | ||
988 | 60 | |||
989 | 61 | boost::shared_ptr<nux::WindowThread> wnd_thread; | ||
990 | 62 | nux::ObjectPtr<MockTestView> test_view; | ||
991 | 63 | }; | ||
992 | 64 | |||
993 | 65 | TEST_F(TestArea, TestAreaSize) | ||
994 | 66 | { | ||
995 | 27 | EXPECT_EQ(test_view->GetMinimumWidth(), nux::AREA_MIN_WIDTH); | 67 | EXPECT_EQ(test_view->GetMinimumWidth(), nux::AREA_MIN_WIDTH); |
996 | 28 | EXPECT_EQ(test_view->GetMaximumWidth(), nux::AREA_MAX_WIDTH); | 68 | EXPECT_EQ(test_view->GetMaximumWidth(), nux::AREA_MAX_WIDTH); |
997 | 29 | EXPECT_EQ(test_view->GetMinimumHeight(), nux::AREA_MIN_HEIGHT); | 69 | EXPECT_EQ(test_view->GetMinimumHeight(), nux::AREA_MIN_HEIGHT); |
998 | @@ -48,29 +88,16 @@ | |||
999 | 48 | EXPECT_EQ(test_view->GetMaximumWidth(), 4321); | 88 | EXPECT_EQ(test_view->GetMaximumWidth(), 4321); |
1000 | 49 | EXPECT_EQ(test_view->GetMinimumHeight(), 432); | 89 | EXPECT_EQ(test_view->GetMinimumHeight(), 432); |
1001 | 50 | EXPECT_EQ(test_view->GetMaximumHeight(), 1234); | 90 | EXPECT_EQ(test_view->GetMaximumHeight(), 1234); |
1002 | 51 | |||
1003 | 52 | test_view->UnReference(); | ||
1004 | 53 | delete wnd_thread; | ||
1005 | 54 | } | 91 | } |
1006 | 55 | 92 | ||
1008 | 56 | TEST(TestArea, TestAreaGeometry) | 93 | TEST_F(TestArea, TestAreaGeometry) |
1009 | 57 | { | 94 | { |
1017 | 58 | nux::NuxInitialize(0); | 95 | static_cast<nux::Area*>(test_view.GetPointer())->SetGeometry(0, 0, 100, 100); |
1011 | 59 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200, | ||
1012 | 60 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | ||
1013 | 61 | |||
1014 | 62 | nux::TestView* test_view = new nux::TestView(""); | ||
1015 | 63 | |||
1016 | 64 | static_cast<nux::Area*>(test_view)->SetGeometry(0, 0, 100, 100); | ||
1018 | 65 | 96 | ||
1019 | 66 | EXPECT_EQ(test_view->GetBaseX(), 0); | 97 | EXPECT_EQ(test_view->GetBaseX(), 0); |
1020 | 67 | EXPECT_EQ(test_view->GetBaseX(), 0); | 98 | EXPECT_EQ(test_view->GetBaseX(), 0); |
1021 | 68 | EXPECT_EQ(test_view->GetBaseWidth(), 100); | 99 | EXPECT_EQ(test_view->GetBaseWidth(), 100); |
1022 | 69 | EXPECT_EQ(test_view->GetBaseHeight(), 100); | 100 | EXPECT_EQ(test_view->GetBaseHeight(), 100); |
1023 | 70 | |||
1024 | 71 | |||
1025 | 72 | test_view->UnReference(); | ||
1026 | 73 | delete wnd_thread; | ||
1027 | 74 | } | 101 | } |
1028 | 75 | 102 | ||
1029 | 76 | static bool object_destroyed = false; | 103 | static bool object_destroyed = false; |
1030 | @@ -79,31 +106,53 @@ | |||
1031 | 79 | object_destroyed = true; | 106 | object_destroyed = true; |
1032 | 80 | } | 107 | } |
1033 | 81 | 108 | ||
1035 | 82 | TEST(TestArea, TestUnParentKeyFocus) | 109 | TEST_F(TestArea, TestUnParentKeyFocus) |
1036 | 83 | { | 110 | { |
1041 | 84 | nux::NuxInitialize(0); | 111 | nux::TestView* test_view1 = new nux::TestView(""); |
1038 | 85 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Area Test", 300, 200, | ||
1039 | 86 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | ||
1040 | 87 | |||
1042 | 88 | nux::HLayout* layout = new nux::HLayout(); | 112 | nux::HLayout* layout = new nux::HLayout(); |
1045 | 89 | nux::TestView* test_view = new nux::TestView(""); | 113 | test_view1->object_destroyed.connect(sigc::ptr_fun(&OnObjectDestroyed)); |
1044 | 90 | test_view->object_destroyed.connect(sigc::ptr_fun(&OnObjectDestroyed)); | ||
1046 | 91 | 114 | ||
1050 | 92 | test_view->Reference(); | 115 | test_view1->Reference(); |
1051 | 93 | 116 | layout->AddView(test_view1, 1); | |
1049 | 94 | layout->AddView(test_view, 1); | ||
1052 | 95 | 117 | ||
1053 | 96 | wnd_thread->SetLayout(layout); | 118 | wnd_thread->SetLayout(layout); |
1054 | 97 | 119 | ||
1061 | 98 | EXPECT_EQ(test_view->HasKeyFocus(), false); | 120 | EXPECT_EQ(test_view1->HasKeyFocus(), false); |
1062 | 99 | nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_view); | 121 | nux::GetWindowThread()->GetWindowCompositor().SetKeyFocusArea(test_view1); |
1063 | 100 | EXPECT_EQ(test_view->HasKeyFocus(), true); | 122 | EXPECT_EQ(test_view1->HasKeyFocus(), true); |
1064 | 101 | layout->RemoveChildObject(test_view); | 123 | layout->RemoveChildObject(test_view1); |
1065 | 102 | EXPECT_EQ(test_view->HasKeyFocus(), false); | 124 | EXPECT_EQ(test_view1->HasKeyFocus(), false); |
1066 | 103 | test_view->UnReference(); | 125 | test_view1->UnReference(); |
1067 | 104 | EXPECT_EQ(object_destroyed, true); | 126 | EXPECT_EQ(object_destroyed, true); |
1070 | 105 | 127 | } | |
1071 | 106 | delete wnd_thread; | 128 | |
1072 | 129 | TEST_F(TestArea, NextObjectToKeyFocusSetReset) | ||
1073 | 130 | { | ||
1074 | 131 | MockTestView* parent = new MockTestView(); | ||
1075 | 132 | MockTestView* brother = new MockTestView(); | ||
1076 | 133 | MockTestView* child1 = new MockTestView(); | ||
1077 | 134 | MockTestView* child2 = new MockTestView(); | ||
1078 | 135 | MockTestView* child3 = new MockTestView(); | ||
1079 | 136 | |||
1080 | 137 | parent->SetNextObjectToKeyFocusArea(brother); | ||
1081 | 138 | ASSERT_EQ(parent->GetNextObjectToKeyFocusArea(), brother); | ||
1082 | 139 | |||
1083 | 140 | child1->SetParentObject(parent); | ||
1084 | 141 | child1->SetNextObjectToKeyFocusArea(child2); | ||
1085 | 142 | ASSERT_EQ(child1->GetNextObjectToKeyFocusArea(), child2); | ||
1086 | 143 | |||
1087 | 144 | child2->SetParentObject(parent); | ||
1088 | 145 | child2->SetNextObjectToKeyFocusArea(child3); | ||
1089 | 146 | ASSERT_EQ(child2->GetNextObjectToKeyFocusArea(), child3); | ||
1090 | 147 | |||
1091 | 148 | child3->SetParentObject(parent); | ||
1092 | 149 | ASSERT_EQ(child3->GetNextObjectToKeyFocusArea(), nullptr); | ||
1093 | 150 | |||
1094 | 151 | child1->UnReference(); | ||
1095 | 152 | EXPECT_EQ(child2->GetNextObjectToKeyFocusArea(), nullptr); | ||
1096 | 153 | EXPECT_EQ(parent->GetNextObjectToKeyFocusArea(), nullptr); | ||
1097 | 154 | |||
1098 | 155 | parent->UnReference(); | ||
1099 | 107 | } | 156 | } |
1100 | 108 | 157 | ||
1101 | 109 | } | 158 | } |
1102 | 110 | 159 | ||
1103 | === modified file 'tests/gtest-nux-input-area.cpp' | |||
1104 | --- tests/gtest-nux-input-area.cpp 2012-09-18 18:30:40 +0000 | |||
1105 | +++ tests/gtest-nux-input-area.cpp 2012-09-18 18:30:40 +0000 | |||
1106 | @@ -1,5 +1,5 @@ | |||
1107 | 1 | /* | 1 | /* |
1109 | 2 | * Copyright 2012 Canonical Ltd. | 2 | * Copyright 2010 Inalogic® Inc. |
1110 | 3 | * | 3 | * |
1111 | 4 | * This program is free software: you can redistribute it and/or modify it | 4 | * This program is free software: you can redistribute it and/or modify it |
1112 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | 5 | * under the terms of the GNU Lesser General Public License version 3, as |
1113 | 6 | 6 | ||
1114 | === modified file 'tests/gtest-nux-windowcompositor.cpp' | |||
1115 | --- tests/gtest-nux-windowcompositor.cpp 2012-06-26 13:38:50 +0000 | |||
1116 | +++ tests/gtest-nux-windowcompositor.cpp 2012-09-18 18:30:40 +0000 | |||
1117 | @@ -47,17 +47,109 @@ | |||
1118 | 47 | }; | 47 | }; |
1119 | 48 | #endif | 48 | #endif |
1120 | 49 | 49 | ||
1127 | 50 | TEST(TestWindowCompositor, TestSetKeyFocusArea) | 50 | struct TestBaseWindow : public nux::BaseWindow |
1128 | 51 | { | 51 | { |
1129 | 52 | nux::NuxInitialize(0); | 52 | TestBaseWindow() : input_area(new nux::InputArea()) |
1130 | 53 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Nux Window", 300, 200, | 53 | { |
1131 | 54 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | 54 | ShowWindow(true); |
1132 | 55 | 55 | } | |
1133 | 56 | |||
1134 | 57 | nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) | ||
1135 | 58 | { | ||
1136 | 59 | return input_area.GetPointer(); | ||
1137 | 60 | } | ||
1138 | 61 | |||
1139 | 62 | Area* FindKeyFocusArea(unsigned int key_symbol, unsigned long x11_key_code, unsigned long special_keys_state) | ||
1140 | 63 | { | ||
1141 | 64 | return input_area.GetPointer(); | ||
1142 | 65 | } | ||
1143 | 66 | |||
1144 | 67 | nux::ObjectPtr<nux::InputArea> input_area; | ||
1145 | 68 | }; | ||
1146 | 69 | |||
1147 | 70 | struct TestHLayout : public nux::HLayout | ||
1148 | 71 | { | ||
1149 | 72 | TestHLayout() : input_area(new nux::InputArea()) {} | ||
1150 | 73 | |||
1151 | 74 | nux::Area* FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type) | ||
1152 | 75 | { | ||
1153 | 76 | return input_area.GetPointer(); | ||
1154 | 77 | } | ||
1155 | 78 | |||
1156 | 79 | Area* FindKeyFocusArea(unsigned int key_symbol, unsigned long x11_key_code, unsigned long special_keys_state) | ||
1157 | 80 | { | ||
1158 | 81 | return input_area.GetPointer(); | ||
1159 | 82 | } | ||
1160 | 83 | |||
1161 | 84 | nux::ObjectPtr<nux::InputArea> input_area; | ||
1162 | 85 | }; | ||
1163 | 86 | |||
1164 | 87 | } | ||
1165 | 88 | |||
1166 | 89 | namespace nux | ||
1167 | 90 | { | ||
1168 | 91 | struct TestWindowCompositor : public testing::Test | ||
1169 | 92 | { | ||
1170 | 93 | TestWindowCompositor() | ||
1171 | 94 | {} | ||
1172 | 95 | |||
1173 | 96 | void SetUp() | ||
1174 | 97 | { | ||
1175 | 98 | nux::NuxInitialize(0); | ||
1176 | 99 | wnd_thread.reset(nux::CreateNuxWindow("WindowCompositor Test", 300, 200, nux::WINDOWSTYLE_NORMAL, | ||
1177 | 100 | NULL, false, NULL, NULL)); | ||
1178 | 101 | } | ||
1179 | 102 | |||
1180 | 103 | void ForceSetKeyFocusArea(nux::InputArea* area) | ||
1181 | 104 | { | ||
1182 | 105 | nux::GetWindowCompositor().key_focus_area_ = area; | ||
1183 | 106 | } | ||
1184 | 107 | |||
1185 | 108 | ObjectWeakPtr<InputArea> const& GetMouseOwnerArea() const | ||
1186 | 109 | { | ||
1187 | 110 | return nux::GetWindowCompositor().GetMouseOwnerArea(); | ||
1188 | 111 | } | ||
1189 | 112 | |||
1190 | 113 | void SetMouseOwnerArea(InputArea* area) | ||
1191 | 114 | { | ||
1192 | 115 | nux::GetWindowCompositor().mouse_owner_area_ = area; | ||
1193 | 116 | } | ||
1194 | 117 | |||
1195 | 118 | InputArea* GetMouseOverArea() | ||
1196 | 119 | { | ||
1197 | 120 | return nux::GetWindowCompositor().mouse_over_area_.GetPointer(); | ||
1198 | 121 | } | ||
1199 | 122 | |||
1200 | 123 | void SetMouseOverArea(InputArea* area) | ||
1201 | 124 | { | ||
1202 | 125 | nux::GetWindowCompositor().mouse_over_area_ = area; | ||
1203 | 126 | } | ||
1204 | 127 | |||
1205 | 128 | void GetAreaUnderMouse(const Point& mouse_position, NuxEventType event_type, | ||
1206 | 129 | ObjectWeakPtr<InputArea>& area, | ||
1207 | 130 | ObjectWeakPtr<BaseWindow>& window) | ||
1208 | 131 | { | ||
1209 | 132 | return nux::GetWindowCompositor().GetAreaUnderMouse(mouse_position, event_type, area, window); | ||
1210 | 133 | } | ||
1211 | 134 | |||
1212 | 135 | void FindKeyFocusArea(NuxEventType event_type, unsigned int key_symbol, | ||
1213 | 136 | unsigned int state, | ||
1214 | 137 | ObjectWeakPtr<InputArea>& key_focus_area, | ||
1215 | 138 | ObjectWeakPtr<BaseWindow>& window) | ||
1216 | 139 | { | ||
1217 | 140 | return nux::GetWindowCompositor().FindKeyFocusArea(event_type, key_symbol, state, key_focus_area, window); | ||
1218 | 141 | } | ||
1219 | 142 | |||
1220 | 143 | boost::shared_ptr<nux::WindowThread> wnd_thread; | ||
1221 | 144 | }; | ||
1222 | 145 | |||
1223 | 146 | TEST_F(TestWindowCompositor, TestSetKeyFocusArea) | ||
1224 | 147 | { | ||
1225 | 56 | nux::TestView* test_view0 = new nux::TestView(); | 148 | nux::TestView* test_view0 = new nux::TestView(); |
1226 | 57 | nux::TestView* test_view1 = new nux::TestView(); | 149 | nux::TestView* test_view1 = new nux::TestView(); |
1227 | 58 | 150 | ||
1228 | 59 | nux::HLayout* layout = new nux::HLayout(); | 151 | nux::HLayout* layout = new nux::HLayout(); |
1230 | 60 | 152 | ||
1231 | 61 | layout->AddView(test_view0, 1); | 153 | layout->AddView(test_view0, 1); |
1232 | 62 | layout->AddView(test_view1, 1); | 154 | layout->AddView(test_view1, 1); |
1233 | 63 | 155 | ||
1234 | @@ -89,8 +181,6 @@ | |||
1235 | 89 | EXPECT_EQ(test_view1->registered_begin_keynav_focus_, true); | 181 | EXPECT_EQ(test_view1->registered_begin_keynav_focus_, true); |
1236 | 90 | EXPECT_EQ(test_view1->registered_end_keynav_focus_, false); | 182 | EXPECT_EQ(test_view1->registered_end_keynav_focus_, false); |
1237 | 91 | } | 183 | } |
1238 | 92 | |||
1239 | 93 | delete wnd_thread; | ||
1240 | 94 | } | 184 | } |
1241 | 95 | 185 | ||
1242 | 96 | #ifdef NUX_GESTURES_SUPPORT | 186 | #ifdef NUX_GESTURES_SUPPORT |
1243 | @@ -104,11 +194,8 @@ | |||
1244 | 104 | Check that the gesture got accepted, that window A got the gesture | 194 | Check that the gesture got accepted, that window A got the gesture |
1245 | 105 | events and that window B didn't get anything. | 195 | events and that window B didn't get anything. |
1246 | 106 | */ | 196 | */ |
1248 | 107 | TEST(TestWindowCompositor, GestureEventsDelivery_1) | 197 | TEST_F(TestWindowCompositor, GestureEventsDelivery_1) |
1249 | 108 | { | 198 | { |
1250 | 109 | nux::NuxInitialize(0); | ||
1251 | 110 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Nux Window", 500, 500, | ||
1252 | 111 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | ||
1253 | 112 | nux::WindowCompositor &wnd_compositor = wnd_thread->GetWindowCompositor(); | 199 | nux::WindowCompositor &wnd_compositor = wnd_thread->GetWindowCompositor(); |
1254 | 113 | nux::FakeGestureEvent fake_event; | 200 | nux::FakeGestureEvent fake_event; |
1255 | 114 | 201 | ||
1256 | @@ -159,7 +246,6 @@ | |||
1257 | 159 | 246 | ||
1258 | 160 | target_window->Dispose(); | 247 | target_window->Dispose(); |
1259 | 161 | innocent_window->Dispose(); | 248 | innocent_window->Dispose(); |
1260 | 162 | delete wnd_thread; | ||
1261 | 163 | } | 249 | } |
1262 | 164 | 250 | ||
1263 | 165 | /* | 251 | /* |
1264 | @@ -171,13 +257,10 @@ | |||
1265 | 171 | Check that the gesture got rejected and that no window got | 257 | Check that the gesture got rejected and that no window got |
1266 | 172 | any gesture event. | 258 | any gesture event. |
1267 | 173 | */ | 259 | */ |
1269 | 174 | TEST(TestWindowCompositor, GestureEventsDelivery_2) | 260 | TEST_F(TestWindowCompositor, GestureEventsDelivery_2) |
1270 | 175 | { | 261 | { |
1271 | 176 | nux::NuxInitialize(0); | ||
1272 | 177 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Nux Window", 500, 500, | ||
1273 | 178 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | ||
1274 | 179 | nux::WindowCompositor &wnd_compositor = wnd_thread->GetWindowCompositor(); | ||
1275 | 180 | nux::FakeGestureEvent fake_event; | 262 | nux::FakeGestureEvent fake_event; |
1276 | 263 | nux::WindowCompositor& wnd_compositor = nux::GetWindowCompositor(); | ||
1277 | 181 | 264 | ||
1278 | 182 | TestWindow *subscribed_window = new TestWindow; | 265 | TestWindow *subscribed_window = new TestWindow; |
1279 | 183 | subscribed_window->SetBaseXY(10, 10); | 266 | subscribed_window->SetBaseXY(10, 10); |
1280 | @@ -212,7 +295,6 @@ | |||
1281 | 212 | 295 | ||
1282 | 213 | subscribed_window->Dispose(); | 296 | subscribed_window->Dispose(); |
1283 | 214 | innocent_window->Dispose(); | 297 | innocent_window->Dispose(); |
1284 | 215 | delete wnd_thread; | ||
1285 | 216 | } | 298 | } |
1286 | 217 | 299 | ||
1287 | 218 | /* | 300 | /* |
1288 | @@ -225,13 +307,10 @@ | |||
1289 | 225 | Check that the gesture gets accepted and that only the input area behind that | 307 | Check that the gesture gets accepted and that only the input area behind that |
1290 | 226 | window gets the gesture events. | 308 | window gets the gesture events. |
1291 | 227 | */ | 309 | */ |
1293 | 228 | TEST(TestWindowCompositor, GestureEventsDelivery_3) | 310 | TEST_F(TestWindowCompositor, GestureEventsDelivery_3) |
1294 | 229 | { | 311 | { |
1295 | 230 | nux::NuxInitialize(0); | ||
1296 | 231 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Nux Window", 500, 500, | ||
1297 | 232 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | ||
1298 | 233 | nux::WindowCompositor &wnd_compositor = wnd_thread->GetWindowCompositor(); | ||
1299 | 234 | nux::FakeGestureEvent fake_event; | 312 | nux::FakeGestureEvent fake_event; |
1300 | 313 | nux::WindowCompositor& wnd_compositor = nux::GetWindowCompositor(); | ||
1301 | 235 | 314 | ||
1302 | 236 | TestWindow *window = new TestWindow; | 315 | TestWindow *window = new TestWindow; |
1303 | 237 | window->SetBaseXY(10, 10); | 316 | window->SetBaseXY(10, 10); |
1304 | @@ -287,20 +366,16 @@ | |||
1305 | 287 | ASSERT_EQ(0, other_input_area->gesture_events_received.size()); | 366 | ASSERT_EQ(0, other_input_area->gesture_events_received.size()); |
1306 | 288 | 367 | ||
1307 | 289 | window->Dispose(); | 368 | window->Dispose(); |
1308 | 290 | delete wnd_thread; | ||
1309 | 291 | } | 369 | } |
1310 | 292 | 370 | ||
1311 | 293 | /* | 371 | /* |
1312 | 294 | Check that if a gesture gets its construction finished only on its end event, | 372 | Check that if a gesture gets its construction finished only on its end event, |
1313 | 295 | it still gets accepted and delivered. | 373 | it still gets accepted and delivered. |
1314 | 296 | */ | 374 | */ |
1316 | 297 | TEST(TestWindowCompositor, GestureEventsDelivery_4) | 375 | TEST_F(TestWindowCompositor, GestureEventsDelivery_4) |
1317 | 298 | { | 376 | { |
1318 | 299 | nux::NuxInitialize(0); | ||
1319 | 300 | nux::WindowThread *wnd_thread = nux::CreateNuxWindow("Nux Window", 500, 500, | ||
1320 | 301 | nux::WINDOWSTYLE_NORMAL, NULL, false, NULL, NULL); | ||
1321 | 302 | nux::WindowCompositor &wnd_compositor = wnd_thread->GetWindowCompositor(); | ||
1322 | 303 | nux::FakeGestureEvent fake_event; | 377 | nux::FakeGestureEvent fake_event; |
1323 | 378 | nux::WindowCompositor& wnd_compositor = nux::GetWindowCompositor(); | ||
1324 | 304 | 379 | ||
1325 | 305 | TestWindow *window = new TestWindow; | 380 | TestWindow *window = new TestWindow; |
1326 | 306 | window->SetBaseXY(10, 10); | 381 | window->SetBaseXY(10, 10); |
1327 | @@ -356,7 +431,110 @@ | |||
1328 | 356 | ASSERT_EQ(0, other_input_area->gesture_events_received.size()); | 431 | ASSERT_EQ(0, other_input_area->gesture_events_received.size()); |
1329 | 357 | 432 | ||
1330 | 358 | window->Dispose(); | 433 | window->Dispose(); |
1332 | 359 | delete wnd_thread; | 434 | } |
1333 | 435 | |||
1334 | 436 | TEST_F(TestWindowCompositor, KeyFocusAreaAutomaticallyUnsets) | ||
1335 | 437 | { | ||
1336 | 438 | nux::WindowCompositor& wnd_compositor = nux::GetWindowCompositor(); | ||
1337 | 439 | nux::InputArea* test_area = new TestInputArea(); | ||
1338 | 440 | |||
1339 | 441 | ForceSetKeyFocusArea(test_area); | ||
1340 | 442 | ASSERT_EQ(wnd_compositor.GetKeyFocusArea(), test_area); | ||
1341 | 443 | |||
1342 | 444 | test_area->UnReference(); | ||
1343 | 445 | EXPECT_EQ(wnd_compositor.GetKeyFocusArea(), nullptr); | ||
1344 | 446 | } | ||
1345 | 447 | |||
1346 | 448 | TEST_F(TestWindowCompositor, MouseOverAreaAutomaticallyUnsets) | ||
1347 | 449 | { | ||
1348 | 450 | nux::InputArea* test_area = new TestInputArea(); | ||
1349 | 451 | |||
1350 | 452 | SetMouseOverArea(test_area); | ||
1351 | 453 | ASSERT_EQ(GetMouseOverArea(), test_area); | ||
1352 | 454 | |||
1353 | 455 | test_area->UnReference(); | ||
1354 | 456 | EXPECT_EQ(GetMouseOverArea(), nullptr); | ||
1355 | 457 | } | ||
1356 | 458 | |||
1357 | 459 | TEST_F(TestWindowCompositor, MouseOwnerAreaAutomaticallyUnsets) | ||
1358 | 460 | { | ||
1359 | 461 | nux::InputArea* test_area = new TestInputArea(); | ||
1360 | 462 | |||
1361 | 463 | SetMouseOwnerArea(test_area); | ||
1362 | 464 | ASSERT_EQ(GetMouseOwnerArea(), test_area); | ||
1363 | 465 | |||
1364 | 466 | test_area->UnReference(); | ||
1365 | 467 | EXPECT_EQ(GetMouseOwnerArea(), nullptr); | ||
1366 | 468 | } | ||
1367 | 469 | |||
1368 | 470 | TEST_F(TestWindowCompositor, GetAreaUnderMouse) | ||
1369 | 471 | { | ||
1370 | 472 | ObjectWeakPtr<InputArea> area; | ||
1371 | 473 | ObjectWeakPtr<BaseWindow> window; | ||
1372 | 474 | |||
1373 | 475 | TestBaseWindow* test_win = new TestBaseWindow(); | ||
1374 | 476 | |||
1375 | 477 | GetAreaUnderMouse(Point(1, 2), NUX_MOUSE_MOVE, area, window); | ||
1376 | 478 | |||
1377 | 479 | EXPECT_EQ(area.GetPointer(), test_win->input_area.GetPointer()); | ||
1378 | 480 | EXPECT_EQ(window.GetPointer(), test_win); | ||
1379 | 481 | |||
1380 | 482 | test_win->UnReference(); | ||
1381 | 483 | EXPECT_EQ(area.GetPointer(), nullptr); | ||
1382 | 484 | EXPECT_EQ(window.GetPointer(), nullptr); | ||
1383 | 485 | } | ||
1384 | 486 | |||
1385 | 487 | TEST_F(TestWindowCompositor, GetAreaUnderMouseFallback) | ||
1386 | 488 | { | ||
1387 | 489 | ObjectWeakPtr<InputArea> area; | ||
1388 | 490 | ObjectWeakPtr<BaseWindow> window; | ||
1389 | 491 | |||
1390 | 492 | TestHLayout* layout = new TestHLayout(); | ||
1391 | 493 | wnd_thread->SetLayout(layout); | ||
1392 | 494 | |||
1393 | 495 | GetAreaUnderMouse(Point(1, 2), NUX_MOUSE_MOVE, area, window); | ||
1394 | 496 | |||
1395 | 497 | EXPECT_EQ(area.GetPointer(), layout->input_area.GetPointer()); | ||
1396 | 498 | EXPECT_EQ(window.GetPointer(), nullptr); | ||
1397 | 499 | |||
1398 | 500 | wnd_thread->SetLayout(nullptr); | ||
1399 | 501 | layout->UnReference(); | ||
1400 | 502 | EXPECT_EQ(area.GetPointer(), nullptr); | ||
1401 | 503 | } | ||
1402 | 504 | |||
1403 | 505 | TEST_F(TestWindowCompositor, GetFocusedArea) | ||
1404 | 506 | { | ||
1405 | 507 | ObjectWeakPtr<InputArea> area; | ||
1406 | 508 | ObjectWeakPtr<BaseWindow> window; | ||
1407 | 509 | |||
1408 | 510 | TestBaseWindow* test_win = new TestBaseWindow(); | ||
1409 | 511 | |||
1410 | 512 | FindKeyFocusArea(NUX_KEYUP, 0, 0, area, window); | ||
1411 | 513 | |||
1412 | 514 | EXPECT_EQ(area.GetPointer(), test_win->input_area.GetPointer()); | ||
1413 | 515 | EXPECT_EQ(window.GetPointer(), test_win); | ||
1414 | 516 | |||
1415 | 517 | test_win->UnReference(); | ||
1416 | 518 | EXPECT_EQ(area.GetPointer(), nullptr); | ||
1417 | 519 | EXPECT_EQ(window.GetPointer(), nullptr); | ||
1418 | 520 | } | ||
1419 | 521 | |||
1420 | 522 | TEST_F(TestWindowCompositor, GetFocusedAreaFallback) | ||
1421 | 523 | { | ||
1422 | 524 | ObjectWeakPtr<InputArea> area; | ||
1423 | 525 | ObjectWeakPtr<BaseWindow> window; | ||
1424 | 526 | |||
1425 | 527 | TestHLayout* layout = new TestHLayout(); | ||
1426 | 528 | wnd_thread->SetLayout(layout); | ||
1427 | 529 | |||
1428 | 530 | FindKeyFocusArea(NUX_KEYUP, 0, 0, area, window); | ||
1429 | 531 | |||
1430 | 532 | EXPECT_EQ(area.GetPointer(), layout->input_area.GetPointer()); | ||
1431 | 533 | EXPECT_EQ(window.GetPointer(), nullptr); | ||
1432 | 534 | |||
1433 | 535 | wnd_thread->SetLayout(nullptr); | ||
1434 | 536 | layout->UnReference(); | ||
1435 | 537 | EXPECT_EQ(area.GetPointer(), nullptr); | ||
1436 | 360 | } | 538 | } |
1437 | 361 | 539 | ||
1438 | 362 | #endif // NUX_GESTURES_SUPPORT | 540 | #endif // NUX_GESTURES_SUPPORT |
Everything goes as expected ;)