OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <set> | 6 #include <set> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 const ui::EventType event_type_; | 1298 const ui::EventType event_type_; |
1299 | 1299 |
1300 DISALLOW_COPY_AND_ASSIGN(CloseWidgetView); | 1300 DISALLOW_COPY_AND_ASSIGN(CloseWidgetView); |
1301 }; | 1301 }; |
1302 | 1302 |
1303 // Generates two moves (first generates enter, second real move), a press, drag | 1303 // Generates two moves (first generates enter, second real move), a press, drag |
1304 // and release stopping at |last_event_type|. | 1304 // and release stopping at |last_event_type|. |
1305 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { | 1305 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { |
1306 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); | 1306 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); |
1307 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), | 1307 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), |
1308 screen_bounds.CenterPoint(), 0); | 1308 screen_bounds.CenterPoint(), 0, 0); |
1309 aura::RootWindowHostDelegate* rwhd = | 1309 aura::RootWindowHostDelegate* rwhd = |
1310 widget->GetNativeWindow()->GetDispatcher()->AsRootWindowHostDelegate(); | 1310 widget->GetNativeWindow()->GetDispatcher()->AsRootWindowHostDelegate(); |
1311 rwhd->OnHostMouseEvent(&move_event); | 1311 rwhd->OnHostMouseEvent(&move_event); |
1312 if (last_event_type == ui::ET_MOUSE_ENTERED) | 1312 if (last_event_type == ui::ET_MOUSE_ENTERED) |
1313 return; | 1313 return; |
1314 rwhd->OnHostMouseEvent(&move_event); | 1314 rwhd->OnHostMouseEvent(&move_event); |
1315 if (last_event_type == ui::ET_MOUSE_MOVED) | 1315 if (last_event_type == ui::ET_MOUSE_MOVED) |
1316 return; | 1316 return; |
1317 | 1317 |
1318 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), | 1318 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), |
1319 screen_bounds.CenterPoint(), 0); | 1319 screen_bounds.CenterPoint(), 0, 0); |
1320 rwhd->OnHostMouseEvent(&press_event); | 1320 rwhd->OnHostMouseEvent(&press_event); |
1321 if (last_event_type == ui::ET_MOUSE_PRESSED) | 1321 if (last_event_type == ui::ET_MOUSE_PRESSED) |
1322 return; | 1322 return; |
1323 | 1323 |
1324 gfx::Point end_point(screen_bounds.CenterPoint()); | 1324 gfx::Point end_point(screen_bounds.CenterPoint()); |
1325 end_point.Offset(1, 1); | 1325 end_point.Offset(1, 1); |
1326 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 0); | 1326 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, end_point, end_point, 0, 0); |
1327 rwhd->OnHostMouseEvent(&drag_event); | 1327 rwhd->OnHostMouseEvent(&drag_event); |
1328 if (last_event_type == ui::ET_MOUSE_DRAGGED) | 1328 if (last_event_type == ui::ET_MOUSE_DRAGGED) |
1329 return; | 1329 return; |
1330 | 1330 |
1331 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 0); | 1331 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, end_point, end_point, 0, |
| 1332 0); |
1332 rwhd->OnHostMouseEvent(&release_event); | 1333 rwhd->OnHostMouseEvent(&release_event); |
1333 } | 1334 } |
1334 | 1335 |
1335 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. | 1336 // Creates a widget and invokes GenerateMouseEvents() with |last_event_type|. |
1336 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, | 1337 void RunCloseWidgetDuringDispatchTest(WidgetTest* test, |
1337 ui::EventType last_event_type) { | 1338 ui::EventType last_event_type) { |
1338 // |widget| is deleted by CloseWidgetView. | 1339 // |widget| is deleted by CloseWidgetView. |
1339 Widget* widget = new Widget; | 1340 Widget* widget = new Widget; |
1340 Widget::InitParams params = | 1341 Widget::InitParams params = |
1341 test->CreateParams(Widget::InitParams::TYPE_POPUP); | 1342 test->CreateParams(Widget::InitParams::TYPE_POPUP); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 | 1536 |
1536 EventCountView* v1 = new EventCountView(); | 1537 EventCountView* v1 = new EventCountView(); |
1537 v1->SetBounds(0, 0, 10, 10); | 1538 v1->SetBounds(0, 0, 10, 10); |
1538 root_view->AddChildView(v1); | 1539 root_view->AddChildView(v1); |
1539 EventCountView* v2 = new EventCountView(); | 1540 EventCountView* v2 = new EventCountView(); |
1540 v2->SetBounds(0, 10, 10, 10); | 1541 v2->SetBounds(0, 10, 10, 10); |
1541 root_view->AddChildView(v2); | 1542 root_view->AddChildView(v2); |
1542 | 1543 |
1543 gfx::Point cursor_location(5, 5); | 1544 gfx::Point cursor_location(5, 5); |
1544 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, | 1545 ui::MouseEvent move(ui::ET_MOUSE_MOVED, cursor_location, cursor_location, |
1545 ui::EF_NONE); | 1546 ui::EF_NONE, ui::EF_NONE); |
1546 widget->OnMouseEvent(&move); | 1547 widget->OnMouseEvent(&move); |
1547 | 1548 |
1548 EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_ENTERED)); | 1549 EXPECT_EQ(1, v1->GetEventCount(ui::ET_MOUSE_ENTERED)); |
1549 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_ENTERED)); | 1550 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_ENTERED)); |
1550 | 1551 |
1551 delete v1; | 1552 delete v1; |
1552 v2->SetBounds(0, 0, 10, 10); | 1553 v2->SetBounds(0, 0, 10, 10); |
1553 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_ENTERED)); | 1554 EXPECT_EQ(0, v2->GetEventCount(ui::ET_MOUSE_ENTERED)); |
1554 | 1555 |
1555 widget->SynthesizeMouseMoveEvent(); | 1556 widget->SynthesizeMouseMoveEvent(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1717 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1718 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
1718 widget->Init(params); | 1719 widget->Init(params); |
1719 | 1720 |
1720 widget->SetContentsView(new WidgetDeleterView); | 1721 widget->SetContentsView(new WidgetDeleterView); |
1721 | 1722 |
1722 widget->SetSize(gfx::Size(100, 100)); | 1723 widget->SetSize(gfx::Size(100, 100)); |
1723 widget->Show(); | 1724 widget->Show(); |
1724 | 1725 |
1725 gfx::Point click_location(45, 15); | 1726 gfx::Point click_location(45, 15); |
1726 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 1727 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, |
1727 ui::EF_LEFT_MOUSE_BUTTON); | 1728 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1728 widget->OnMouseEvent(&press); | 1729 widget->OnMouseEvent(&press); |
1729 | 1730 |
1730 // Yay we did not crash! | 1731 // Yay we did not crash! |
1731 } | 1732 } |
1732 | 1733 |
1733 // See description of RunGetNativeThemeFromDestructor() for details. | 1734 // See description of RunGetNativeThemeFromDestructor() for details. |
1734 class GetNativeThemeFromDestructorView : public WidgetDelegateView { | 1735 class GetNativeThemeFromDestructorView : public WidgetDelegateView { |
1735 public: | 1736 public: |
1736 GetNativeThemeFromDestructorView() {} | 1737 GetNativeThemeFromDestructorView() {} |
1737 virtual ~GetNativeThemeFromDestructorView() { | 1738 virtual ~GetNativeThemeFromDestructorView() { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 view->SetBounds(0, 0, 300, 300); | 1861 view->SetBounds(0, 0, 300, 300); |
1861 internal::RootView* root_view = | 1862 internal::RootView* root_view = |
1862 static_cast<internal::RootView*>(widget->GetRootView()); | 1863 static_cast<internal::RootView*>(widget->GetRootView()); |
1863 root_view->AddChildView(view); | 1864 root_view->AddChildView(view); |
1864 | 1865 |
1865 // Check RootView::mouse_pressed_handler_. | 1866 // Check RootView::mouse_pressed_handler_. |
1866 widget->Show(); | 1867 widget->Show(); |
1867 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); | 1868 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); |
1868 gfx::Point click_location(45, 15); | 1869 gfx::Point click_location(45, 15); |
1869 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, | 1870 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location, |
1870 ui::EF_LEFT_MOUSE_BUTTON); | 1871 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
1871 widget->OnMouseEvent(&press); | 1872 widget->OnMouseEvent(&press); |
1872 EXPECT_EQ(view, GetMousePressedHandler(root_view)); | 1873 EXPECT_EQ(view, GetMousePressedHandler(root_view)); |
1873 widget->Hide(); | 1874 widget->Hide(); |
1874 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); | 1875 EXPECT_EQ(NULL, GetMousePressedHandler(root_view)); |
1875 | 1876 |
1876 // Check RootView::mouse_move_handler_. | 1877 // Check RootView::mouse_move_handler_. |
1877 widget->Show(); | 1878 widget->Show(); |
1878 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); | 1879 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); |
1879 gfx::Point move_location(45, 15); | 1880 gfx::Point move_location(45, 15); |
1880 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, 0); | 1881 ui::MouseEvent move(ui::ET_MOUSE_MOVED, move_location, move_location, 0, 0); |
1881 widget->OnMouseEvent(&move); | 1882 widget->OnMouseEvent(&move); |
1882 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); | 1883 EXPECT_EQ(view, GetMouseMoveHandler(root_view)); |
1883 widget->Hide(); | 1884 widget->Hide(); |
1884 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); | 1885 EXPECT_EQ(NULL, GetMouseMoveHandler(root_view)); |
1885 | 1886 |
1886 // Check RootView::gesture_handler_. | 1887 // Check RootView::gesture_handler_. |
1887 widget->Show(); | 1888 widget->Show(); |
1888 EXPECT_EQ(NULL, GetGestureHandler(root_view)); | 1889 EXPECT_EQ(NULL, GetGestureHandler(root_view)); |
1889 ui::GestureEvent tap_down( | 1890 ui::GestureEvent tap_down( |
1890 ui::ET_GESTURE_TAP_DOWN, | 1891 ui::ET_GESTURE_TAP_DOWN, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 | 2060 |
2060 // Create a view and validate that a mouse moves makes it to the view. | 2061 // Create a view and validate that a mouse moves makes it to the view. |
2061 EventCountView* widget_view = new EventCountView(); | 2062 EventCountView* widget_view = new EventCountView(); |
2062 widget_view->SetBounds(0, 0, 10, 10); | 2063 widget_view->SetBounds(0, 0, 10, 10); |
2063 top_level_widget.GetRootView()->AddChildView(widget_view); | 2064 top_level_widget.GetRootView()->AddChildView(widget_view); |
2064 | 2065 |
2065 gfx::Point cursor_location_main(5, 5); | 2066 gfx::Point cursor_location_main(5, 5); |
2066 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, | 2067 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, |
2067 cursor_location_main, | 2068 cursor_location_main, |
2068 cursor_location_main, | 2069 cursor_location_main, |
| 2070 ui::EF_NONE, |
2069 ui::EF_NONE); | 2071 ui::EF_NONE); |
2070 top_level_widget.GetNativeView()->GetDispatcher()-> | 2072 top_level_widget.GetNativeView()->GetDispatcher()-> |
2071 AsRootWindowHostDelegate()->OnHostMouseEvent(&move_main); | 2073 AsRootWindowHostDelegate()->OnHostMouseEvent(&move_main); |
2072 | 2074 |
2073 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); | 2075 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); |
2074 widget_view->ResetCounts(); | 2076 widget_view->ResetCounts(); |
2075 | 2077 |
2076 // Create a modal dialog and validate that a mouse down message makes it to | 2078 // Create a modal dialog and validate that a mouse down message makes it to |
2077 // the main view within the dialog. | 2079 // the main view within the dialog. |
2078 | 2080 |
2079 // This instance will be destroyed when the dialog is destroyed. | 2081 // This instance will be destroyed when the dialog is destroyed. |
2080 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; | 2082 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; |
2081 | 2083 |
2082 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( | 2084 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( |
2083 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); | 2085 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); |
2084 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); | 2086 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); |
2085 EventCountView* dialog_widget_view = new EventCountView(); | 2087 EventCountView* dialog_widget_view = new EventCountView(); |
2086 dialog_widget_view->SetBounds(0, 0, 50, 50); | 2088 dialog_widget_view->SetBounds(0, 0, 50, 50); |
2087 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); | 2089 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); |
2088 modal_dialog_widget->Show(); | 2090 modal_dialog_widget->Show(); |
2089 EXPECT_TRUE(modal_dialog_widget->IsVisible()); | 2091 EXPECT_TRUE(modal_dialog_widget->IsVisible()); |
2090 | 2092 |
2091 gfx::Point cursor_location_dialog(100, 100); | 2093 gfx::Point cursor_location_dialog(100, 100); |
2092 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED, | 2094 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED, |
2093 cursor_location_dialog, | 2095 cursor_location_dialog, |
2094 cursor_location_dialog, | 2096 cursor_location_dialog, |
| 2097 ui::EF_NONE, |
2095 ui::EF_NONE); | 2098 ui::EF_NONE); |
2096 top_level_widget.GetNativeView()->GetDispatcher()-> | 2099 top_level_widget.GetNativeView()->GetDispatcher()-> |
2097 AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_down_dialog); | 2100 AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_down_dialog); |
2098 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 2101 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
2099 | 2102 |
2100 // Send a mouse move message to the main window. It should not be received by | 2103 // Send a mouse move message to the main window. It should not be received by |
2101 // the main window as the modal dialog is still active. | 2104 // the main window as the modal dialog is still active. |
2102 gfx::Point cursor_location_main2(6, 6); | 2105 gfx::Point cursor_location_main2(6, 6); |
2103 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, | 2106 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, |
2104 cursor_location_main2, | 2107 cursor_location_main2, |
2105 cursor_location_main2, | 2108 cursor_location_main2, |
| 2109 ui::EF_NONE, |
2106 ui::EF_NONE); | 2110 ui::EF_NONE); |
2107 top_level_widget.GetNativeView()->GetDispatcher()-> | 2111 top_level_widget.GetNativeView()->GetDispatcher()-> |
2108 AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_down_main); | 2112 AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse_down_main); |
2109 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); | 2113 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
2110 | 2114 |
2111 modal_dialog_widget->CloseNow(); | 2115 modal_dialog_widget->CloseNow(); |
2112 top_level_widget.CloseNow(); | 2116 top_level_widget.CloseNow(); |
2113 } | 2117 } |
2114 | 2118 |
2115 #if defined(USE_AURA) | 2119 #if defined(USE_AURA) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2234 EXPECT_EQ(activate_result, MA_ACTIVATE); | 2238 EXPECT_EQ(activate_result, MA_ACTIVATE); |
2235 | 2239 |
2236 modal_dialog_widget->CloseNow(); | 2240 modal_dialog_widget->CloseNow(); |
2237 top_level_widget.CloseNow(); | 2241 top_level_widget.CloseNow(); |
2238 } | 2242 } |
2239 #endif | 2243 #endif |
2240 #endif | 2244 #endif |
2241 | 2245 |
2242 } // namespace test | 2246 } // namespace test |
2243 } // namespace views | 2247 } // namespace views |
OLD | NEW |