Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura_unittest.cc

Issue 2786693002: Add PointerDetails to ui::MouseEvent's constructors (Closed)
Patch Set: mouse event constructor Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 459
460 // The following code verifies we can correctly destroy a Widget from a mouse 460 // The following code verifies we can correctly destroy a Widget from a mouse
461 // enter/exit. We could test move/drag/enter/exit but in general we don't run 461 // enter/exit. We could test move/drag/enter/exit but in general we don't run
462 // nested message loops from such events, nor has the code ever really dealt 462 // nested message loops from such events, nor has the code ever really dealt
463 // with this situation. 463 // with this situation.
464 464
465 // Generates two moves (first generates enter, second real move), a press, drag 465 // Generates two moves (first generates enter, second real move), a press, drag
466 // and release stopping at |last_event_type|. 466 // and release stopping at |last_event_type|.
467 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { 467 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) {
468 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); 468 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen());
469 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), 469 ui::MouseEvent move_event(
470 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 470 ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(),
471 0, 0); 471 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 0, 0,
472 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
472 ui::EventSink* sink = WidgetTest::GetEventSink(widget); 473 ui::EventSink* sink = WidgetTest::GetEventSink(widget);
473 ui::EventDispatchDetails details = sink->OnEventFromSource(&move_event); 474 ui::EventDispatchDetails details = sink->OnEventFromSource(&move_event);
474 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) 475 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed)
475 return; 476 return;
476 details = sink->OnEventFromSource(&move_event); 477 details = sink->OnEventFromSource(&move_event);
477 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) 478 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed)
478 return; 479 return;
479 480
480 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), 481 ui::MouseEvent press_event(
481 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 482 ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(),
482 0, 0); 483 screen_bounds.CenterPoint(), ui::EventTimeForNow(), 0, 0,
484 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
483 details = sink->OnEventFromSource(&press_event); 485 details = sink->OnEventFromSource(&press_event);
484 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed) 486 if (last_event_type == ui::ET_MOUSE_PRESSED || details.dispatcher_destroyed)
485 return; 487 return;
486 488
487 gfx::Point end_point(screen_bounds.CenterPoint()); 489 gfx::Point end_point(screen_bounds.CenterPoint());
488 end_point.Offset(1, 1); 490 end_point.Offset(1, 1);
489 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 491 ui::MouseEvent drag_event(
490 ui::EventTimeForNow(), 0, 0); 492 ui::ET_MOUSE_DRAGGED, end_point, end_point, ui::EventTimeForNow(), 0, 0,
493 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
491 details = sink->OnEventFromSource(&drag_event); 494 details = sink->OnEventFromSource(&drag_event);
492 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed) 495 if (last_event_type == ui::ET_MOUSE_DRAGGED || details.dispatcher_destroyed)
493 return; 496 return;
494 497
495 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 498 ui::MouseEvent release_event(
496 ui::EventTimeForNow(), 0, 0); 499 ui::ET_MOUSE_RELEASED, end_point, end_point, ui::EventTimeForNow(), 0, 0,
500 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
497 details = sink->OnEventFromSource(&release_event); 501 details = sink->OnEventFromSource(&release_event);
498 if (details.dispatcher_destroyed) 502 if (details.dispatcher_destroyed)
499 return; 503 return;
500 } 504 }
501 505
502 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. 506 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|.
503 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, 507 void RunCloseWidgetDuringDispatchTest(WidgetTest* test,
504 ui::EventType last_event_type) { 508 ui::EventType last_event_type) {
505 // |widget| is deleted by CloseWidgetView. 509 // |widget| is deleted by CloseWidgetView.
506 Widget* widget = new Widget; 510 Widget* widget = new Widget;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 top_level_widget.Init(init_params); 562 top_level_widget.Init(init_params);
559 top_level_widget.Show(); 563 top_level_widget.Show();
560 EXPECT_TRUE(top_level_widget.IsVisible()); 564 EXPECT_TRUE(top_level_widget.IsVisible());
561 565
562 // Create a view and validate that a mouse moves makes it to the view. 566 // Create a view and validate that a mouse moves makes it to the view.
563 EventCountView* widget_view = new EventCountView(); 567 EventCountView* widget_view = new EventCountView();
564 widget_view->SetBounds(0, 0, 10, 10); 568 widget_view->SetBounds(0, 0, 10, 10);
565 top_level_widget.GetRootView()->AddChildView(widget_view); 569 top_level_widget.GetRootView()->AddChildView(widget_view);
566 570
567 gfx::Point cursor_location_main(5, 5); 571 gfx::Point cursor_location_main(5, 5);
568 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, cursor_location_main, 572 ui::MouseEvent move_main(
569 cursor_location_main, ui::EventTimeForNow(), 573 ui::ET_MOUSE_MOVED, cursor_location_main, cursor_location_main,
570 ui::EF_NONE, ui::EF_NONE); 574 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE,
575 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
571 ui::EventDispatchDetails details = 576 ui::EventDispatchDetails details =
572 GetEventSink(&top_level_widget)->OnEventFromSource(&move_main); 577 GetEventSink(&top_level_widget)->OnEventFromSource(&move_main);
573 ASSERT_FALSE(details.dispatcher_destroyed); 578 ASSERT_FALSE(details.dispatcher_destroyed);
574 579
575 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); 580 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED));
576 widget_view->ResetCounts(); 581 widget_view->ResetCounts();
577 582
578 // Create a modal dialog and validate that a mouse down message makes it to 583 // Create a modal dialog and validate that a mouse down message makes it to
579 // the main view within the dialog. 584 // the main view within the dialog.
580 585
581 // This instance will be destroyed when the dialog is destroyed. 586 // This instance will be destroyed when the dialog is destroyed.
582 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; 587 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate;
583 588
584 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( 589 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
585 dialog_delegate, NULL, top_level_widget.GetNativeView()); 590 dialog_delegate, NULL, top_level_widget.GetNativeView());
586 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); 591 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
587 EventCountView* dialog_widget_view = new EventCountView(); 592 EventCountView* dialog_widget_view = new EventCountView();
588 dialog_widget_view->SetBounds(0, 0, 50, 50); 593 dialog_widget_view->SetBounds(0, 0, 50, 50);
589 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); 594 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view);
590 modal_dialog_widget->Show(); 595 modal_dialog_widget->Show();
591 EXPECT_TRUE(modal_dialog_widget->IsVisible()); 596 EXPECT_TRUE(modal_dialog_widget->IsVisible());
592 597
593 gfx::Point cursor_location_dialog(100, 100); 598 gfx::Point cursor_location_dialog(100, 100);
594 ui::MouseEvent mouse_down_dialog( 599 ui::MouseEvent mouse_down_dialog(
595 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog, 600 ui::ET_MOUSE_PRESSED, cursor_location_dialog, cursor_location_dialog,
596 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); 601 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE,
602 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
597 details = 603 details =
598 GetEventSink(&top_level_widget)->OnEventFromSource(&mouse_down_dialog); 604 GetEventSink(&top_level_widget)->OnEventFromSource(&mouse_down_dialog);
599 ASSERT_FALSE(details.dispatcher_destroyed); 605 ASSERT_FALSE(details.dispatcher_destroyed);
600 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); 606 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED));
601 607
602 // Send a mouse move message to the main window. It should not be received by 608 // Send a mouse move message to the main window. It should not be received by
603 // the main window as the modal dialog is still active. 609 // the main window as the modal dialog is still active.
604 gfx::Point cursor_location_main2(6, 6); 610 gfx::Point cursor_location_main2(6, 6);
605 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, cursor_location_main2, 611 ui::MouseEvent mouse_down_main(
606 cursor_location_main2, ui::EventTimeForNow(), 612 ui::ET_MOUSE_MOVED, cursor_location_main2, cursor_location_main2,
607 ui::EF_NONE, ui::EF_NONE); 613 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE,
614 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
608 details = 615 details =
609 GetEventSink(&top_level_widget)->OnEventFromSource(&mouse_down_main); 616 GetEventSink(&top_level_widget)->OnEventFromSource(&mouse_down_main);
610 ASSERT_FALSE(details.dispatcher_destroyed); 617 ASSERT_FALSE(details.dispatcher_destroyed);
611 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); 618 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED));
612 619
613 modal_dialog_widget->CloseNow(); 620 modal_dialog_widget->CloseNow();
614 top_level_widget.CloseNow(); 621 top_level_widget.CloseNow();
615 } 622 }
616 623
617 #if defined(OS_WIN) 624 #if defined(OS_WIN)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 target->HandleKeyboardMessage(WM_CHAR, 0, 0, &handled); 681 target->HandleKeyboardMessage(WM_CHAR, 0, 0, &handled);
675 target->HandleKeyboardMessage(WM_SYSCHAR, 0, 0, &handled); 682 target->HandleKeyboardMessage(WM_SYSCHAR, 0, 0, &handled);
676 target->HandleKeyboardMessage(WM_SYSDEADCHAR, 0, 0, &handled); 683 target->HandleKeyboardMessage(WM_SYSDEADCHAR, 0, 0, &handled);
677 widget.CloseNow(); 684 widget.CloseNow();
678 } 685 }
679 686
680 #endif // defined(OS_WIN) 687 #endif // defined(OS_WIN)
681 688
682 } // namespace test 689 } // namespace test
683 } // namespace views 690 } // namespace views
OLDNEW
« ui/events/event.h ('K') | « ui/views/view_unittest.cc ('k') | ui/views/widget/root_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698