OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "ui/gfx/native_widget_types.h" | 8 #include "ui/gfx/native_widget_types.h" |
9 #include "ui/views/test/widget_test.h" | 9 #include "ui/views/test/widget_test.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 View* container = new View; | 220 View* container = new View; |
221 toplevel->SetContentsView(container); | 221 toplevel->SetContentsView(container); |
222 | 222 |
223 EXPECT_FALSE(toplevel->HasCapture()); | 223 EXPECT_FALSE(toplevel->HasCapture()); |
224 toplevel->SetCapture(NULL); | 224 toplevel->SetCapture(NULL); |
225 EXPECT_TRUE(toplevel->HasCapture()); | 225 EXPECT_TRUE(toplevel->HasCapture()); |
226 | 226 |
227 // By default, mouse release removes capture. | 227 // By default, mouse release removes capture. |
228 gfx::Point click_location(45, 15); | 228 gfx::Point click_location(45, 15); |
229 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | 229 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, |
230 ui::EF_LEFT_MOUSE_BUTTON); | 230 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
231 toplevel->OnMouseEvent(&release); | 231 toplevel->OnMouseEvent(&release); |
232 EXPECT_FALSE(toplevel->HasCapture()); | 232 EXPECT_FALSE(toplevel->HasCapture()); |
233 | 233 |
234 // Now a mouse release shouldn't remove capture. | 234 // Now a mouse release shouldn't remove capture. |
235 toplevel->set_auto_release_capture(false); | 235 toplevel->set_auto_release_capture(false); |
236 toplevel->SetCapture(NULL); | 236 toplevel->SetCapture(NULL); |
237 EXPECT_TRUE(toplevel->HasCapture()); | 237 EXPECT_TRUE(toplevel->HasCapture()); |
238 toplevel->OnMouseEvent(&release); | 238 toplevel->OnMouseEvent(&release); |
239 EXPECT_TRUE(toplevel->HasCapture()); | 239 EXPECT_TRUE(toplevel->HasCapture()); |
240 toplevel->ReleaseCapture(); | 240 toplevel->ReleaseCapture(); |
(...skipping 26 matching lines...) Expand all Loading... |
267 ui::GestureEvent end(ui::ET_GESTURE_END, | 267 ui::GestureEvent end(ui::ET_GESTURE_END, |
268 15, 15, 0, base::TimeDelta(), | 268 15, 15, 0, base::TimeDelta(), |
269 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1); | 269 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1); |
270 toplevel->OnGestureEvent(&begin); | 270 toplevel->OnGestureEvent(&begin); |
271 | 271 |
272 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| | 272 // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| |
273 // will not receive the event. | 273 // will not receive the event. |
274 gfx::Point click_location(45, 15); | 274 gfx::Point click_location(45, 15); |
275 | 275 |
276 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 276 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, |
277 ui::EF_LEFT_MOUSE_BUTTON); | 277 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
278 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, | 278 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location, |
279 ui::EF_LEFT_MOUSE_BUTTON); | 279 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
280 | 280 |
281 EXPECT_TRUE(toplevel->HasCapture()); | 281 EXPECT_TRUE(toplevel->HasCapture()); |
282 | 282 |
283 toplevel->OnMouseEvent(&press); | 283 toplevel->OnMouseEvent(&press); |
284 toplevel->OnMouseEvent(&release); | 284 toplevel->OnMouseEvent(&release); |
285 EXPECT_EQ(0, mouse->pressed()); | 285 EXPECT_EQ(0, mouse->pressed()); |
286 | 286 |
287 EXPECT_FALSE(toplevel->HasCapture()); | 287 EXPECT_FALSE(toplevel->HasCapture()); |
288 | 288 |
289 // The end of the gesture should release the capture, and pressing on |mouse| | 289 // The end of the gesture should release the capture, and pressing on |mouse| |
(...skipping 30 matching lines...) Expand all Loading... |
320 first->SetSize(gfx::Size(100, 100)); | 320 first->SetSize(gfx::Size(100, 100)); |
321 first->Show(); | 321 first->Show(); |
322 | 322 |
323 gfx::Point location(20, 20); | 323 gfx::Point location(20, 20); |
324 base::MessageLoop::current()->PostTask(FROM_HERE, | 324 base::MessageLoop::current()->PostTask(FROM_HERE, |
325 base::Bind(&Widget::OnMouseEvent, | 325 base::Bind(&Widget::OnMouseEvent, |
326 base::Unretained(second), | 326 base::Unretained(second), |
327 base::Owned(new ui::MouseEvent(ui::ET_MOUSE_RELEASED, | 327 base::Owned(new ui::MouseEvent(ui::ET_MOUSE_RELEASED, |
328 location, | 328 location, |
329 location, | 329 location, |
| 330 ui::EF_LEFT_MOUSE_BUTTON, |
330 ui::EF_LEFT_MOUSE_BUTTON)))); | 331 ui::EF_LEFT_MOUSE_BUTTON)))); |
331 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location, | 332 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location, |
332 ui::EF_LEFT_MOUSE_BUTTON); | 333 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
333 first->OnMouseEvent(&press); | 334 first->OnMouseEvent(&press); |
334 EXPECT_FALSE(first->HasCapture()); | 335 EXPECT_FALSE(first->HasCapture()); |
335 first->Close(); | 336 first->Close(); |
336 RunPendingMessages(); | 337 RunPendingMessages(); |
337 } | 338 } |
338 | 339 |
339 // Tests some grab/ungrab events. | 340 // Tests some grab/ungrab events. |
340 // TODO(estade): can this be enabled now that this is an interactive ui test? | 341 // TODO(estade): can this be enabled now that this is an interactive ui test? |
341 TEST_F(WidgetTest, DISABLED_GrabUngrab) { | 342 TEST_F(WidgetTest, DISABLED_GrabUngrab) { |
342 Widget* toplevel = CreateTopLevelPlatformWidget(); | 343 Widget* toplevel = CreateTopLevelPlatformWidget(); |
(...skipping 11 matching lines...) Expand all Loading... |
354 view = new MouseView(); | 355 view = new MouseView(); |
355 view->SetBounds(0, 0, 200, 200); | 356 view->SetBounds(0, 0, 200, 200); |
356 child2->GetRootView()->AddChildView(view); | 357 child2->GetRootView()->AddChildView(view); |
357 | 358 |
358 toplevel->Show(); | 359 toplevel->Show(); |
359 RunPendingMessages(); | 360 RunPendingMessages(); |
360 | 361 |
361 // Click on child1 | 362 // Click on child1 |
362 gfx::Point p1(45, 45); | 363 gfx::Point p1(45, 45); |
363 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1, | 364 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1, |
364 ui::EF_LEFT_MOUSE_BUTTON); | 365 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
365 toplevel->OnMouseEvent(&pressed); | 366 toplevel->OnMouseEvent(&pressed); |
366 | 367 |
367 EXPECT_TRUE(toplevel->HasCapture()); | 368 EXPECT_TRUE(toplevel->HasCapture()); |
368 EXPECT_TRUE(child1->HasCapture()); | 369 EXPECT_TRUE(child1->HasCapture()); |
369 EXPECT_FALSE(child2->HasCapture()); | 370 EXPECT_FALSE(child2->HasCapture()); |
370 | 371 |
371 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, p1, p1, | 372 ui::MouseEvent released(ui::ET_MOUSE_RELEASED, p1, p1, |
372 ui::EF_LEFT_MOUSE_BUTTON); | 373 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
373 toplevel->OnMouseEvent(&released); | 374 toplevel->OnMouseEvent(&released); |
374 | 375 |
375 EXPECT_FALSE(toplevel->HasCapture()); | 376 EXPECT_FALSE(toplevel->HasCapture()); |
376 EXPECT_FALSE(child1->HasCapture()); | 377 EXPECT_FALSE(child1->HasCapture()); |
377 EXPECT_FALSE(child2->HasCapture()); | 378 EXPECT_FALSE(child2->HasCapture()); |
378 | 379 |
379 RunPendingMessages(); | 380 RunPendingMessages(); |
380 | 381 |
381 // Click on child2 | 382 // Click on child2 |
382 gfx::Point p2(315, 45); | 383 gfx::Point p2(315, 45); |
383 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, p2, p2, | 384 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, p2, p2, |
384 ui::EF_LEFT_MOUSE_BUTTON); | 385 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
385 toplevel->OnMouseEvent(&pressed2); | 386 toplevel->OnMouseEvent(&pressed2); |
386 EXPECT_TRUE(pressed2.handled()); | 387 EXPECT_TRUE(pressed2.handled()); |
387 EXPECT_TRUE(toplevel->HasCapture()); | 388 EXPECT_TRUE(toplevel->HasCapture()); |
388 EXPECT_TRUE(child2->HasCapture()); | 389 EXPECT_TRUE(child2->HasCapture()); |
389 EXPECT_FALSE(child1->HasCapture()); | 390 EXPECT_FALSE(child1->HasCapture()); |
390 | 391 |
391 ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2, | 392 ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2, |
392 ui::EF_LEFT_MOUSE_BUTTON); | 393 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
393 toplevel->OnMouseEvent(&released2); | 394 toplevel->OnMouseEvent(&released2); |
394 EXPECT_FALSE(toplevel->HasCapture()); | 395 EXPECT_FALSE(toplevel->HasCapture()); |
395 EXPECT_FALSE(child1->HasCapture()); | 396 EXPECT_FALSE(child1->HasCapture()); |
396 EXPECT_FALSE(child2->HasCapture()); | 397 EXPECT_FALSE(child2->HasCapture()); |
397 | 398 |
398 toplevel->CloseNow(); | 399 toplevel->CloseNow(); |
399 } | 400 } |
400 | 401 |
401 // Tests mouse move outside of the window into the "resize controller" and back | 402 // Tests mouse move outside of the window into the "resize controller" and back |
402 // will still generate an OnMouseEntered and OnMouseExited event.. | 403 // will still generate an OnMouseEntered and OnMouseExited event.. |
403 TEST_F(WidgetTest, CheckResizeControllerEvents) { | 404 TEST_F(WidgetTest, CheckResizeControllerEvents) { |
404 Widget* toplevel = CreateTopLevelPlatformWidget(); | 405 Widget* toplevel = CreateTopLevelPlatformWidget(); |
405 | 406 |
406 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); | 407 toplevel->SetBounds(gfx::Rect(0, 0, 100, 100)); |
407 | 408 |
408 MouseView* view = new MouseView(); | 409 MouseView* view = new MouseView(); |
409 view->SetBounds(90, 90, 10, 10); | 410 view->SetBounds(90, 90, 10, 10); |
410 toplevel->GetRootView()->AddChildView(view); | 411 toplevel->GetRootView()->AddChildView(view); |
411 | 412 |
412 toplevel->Show(); | 413 toplevel->Show(); |
413 RunPendingMessages(); | 414 RunPendingMessages(); |
414 | 415 |
415 // Move to an outside position. | 416 // Move to an outside position. |
416 gfx::Point p1(200, 200); | 417 gfx::Point p1(200, 200); |
417 ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EF_NONE); | 418 ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EF_NONE, |
| 419 ui::EF_NONE); |
418 toplevel->OnMouseEvent(&moved_out); | 420 toplevel->OnMouseEvent(&moved_out); |
419 EXPECT_EQ(0, view->EnteredCalls()); | 421 EXPECT_EQ(0, view->EnteredCalls()); |
420 EXPECT_EQ(0, view->ExitedCalls()); | 422 EXPECT_EQ(0, view->ExitedCalls()); |
421 | 423 |
422 // Move onto the active view. | 424 // Move onto the active view. |
423 gfx::Point p2(95, 95); | 425 gfx::Point p2(95, 95); |
424 ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EF_NONE); | 426 ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EF_NONE, |
| 427 ui::EF_NONE); |
425 toplevel->OnMouseEvent(&moved_over); | 428 toplevel->OnMouseEvent(&moved_over); |
426 EXPECT_EQ(1, view->EnteredCalls()); | 429 EXPECT_EQ(1, view->EnteredCalls()); |
427 EXPECT_EQ(0, view->ExitedCalls()); | 430 EXPECT_EQ(0, view->ExitedCalls()); |
428 | 431 |
429 // Move onto the outer resizing border. | 432 // Move onto the outer resizing border. |
430 gfx::Point p3(102, 95); | 433 gfx::Point p3(102, 95); |
431 ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, ui::EF_NONE); | 434 ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, ui::EF_NONE, |
| 435 ui::EF_NONE); |
432 toplevel->OnMouseEvent(&moved_resizer); | 436 toplevel->OnMouseEvent(&moved_resizer); |
433 EXPECT_EQ(0, view->EnteredCalls()); | 437 EXPECT_EQ(0, view->EnteredCalls()); |
434 EXPECT_EQ(1, view->ExitedCalls()); | 438 EXPECT_EQ(1, view->ExitedCalls()); |
435 | 439 |
436 // Move onto the view again. | 440 // Move onto the view again. |
437 toplevel->OnMouseEvent(&moved_over); | 441 toplevel->OnMouseEvent(&moved_over); |
438 EXPECT_EQ(1, view->EnteredCalls()); | 442 EXPECT_EQ(1, view->EnteredCalls()); |
439 EXPECT_EQ(0, view->ExitedCalls()); | 443 EXPECT_EQ(0, view->ExitedCalls()); |
440 | 444 |
441 RunPendingMessages(); | 445 RunPendingMessages(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 // Set capture to widget2 and verity it gets it. | 772 // Set capture to widget2 and verity it gets it. |
769 widget2.SetCapture(widget2.GetRootView()); | 773 widget2.SetCapture(widget2.GetRootView()); |
770 EXPECT_FALSE(widget1.HasCapture()); | 774 EXPECT_FALSE(widget1.HasCapture()); |
771 EXPECT_TRUE(widget2.HasCapture()); | 775 EXPECT_TRUE(widget2.HasCapture()); |
772 | 776 |
773 widget1.GetAndClearGotMouseEvent(); | 777 widget1.GetAndClearGotMouseEvent(); |
774 widget2.GetAndClearGotMouseEvent(); | 778 widget2.GetAndClearGotMouseEvent(); |
775 // Send a mouse event to the RootWindow associated with |widget1|. Even though | 779 // Send a mouse event to the RootWindow associated with |widget1|. Even though |
776 // |widget2| has capture, |widget1| should still get the event. | 780 // |widget2| has capture, |widget1| should still get the event. |
777 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 781 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
778 ui::EF_NONE); | 782 ui::EF_NONE, ui::EF_NONE); |
779 widget1.GetNativeWindow()->GetDispatcher()->AsRootWindowHostDelegate()-> | 783 widget1.GetNativeWindow()->GetDispatcher()->AsRootWindowHostDelegate()-> |
780 OnHostMouseEvent(&mouse_event); | 784 OnHostMouseEvent(&mouse_event); |
781 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 785 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
782 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 786 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
783 } | 787 } |
784 #endif | 788 #endif |
785 | 789 |
786 } // namespace test | 790 } // namespace test |
787 } // namespace views | 791 } // namespace views |
OLD | NEW |