| 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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/client/window_tree_client.h" | 16 #include "ui/aura/client/window_tree_client.h" |
| 17 #include "ui/aura/test/event_generator.h" | 17 #include "ui/aura/test/event_generator.h" |
| 18 #include "ui/aura/test/test_window_delegate.h" | 18 #include "ui/aura/test/test_window_delegate.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_tree_host.h" |
| 21 #include "ui/base/hit_test.h" | 21 #include "ui/base/hit_test.h" |
| 22 #include "ui/events/event_processor.h" |
| 22 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
| 23 #include "ui/gfx/native_widget_types.h" | 24 #include "ui/gfx/native_widget_types.h" |
| 24 #include "ui/gfx/point.h" | 25 #include "ui/gfx/point.h" |
| 25 #include "ui/views/bubble/bubble_delegate.h" | 26 #include "ui/views/bubble/bubble_delegate.h" |
| 26 #include "ui/views/controls/textfield/textfield.h" | 27 #include "ui/views/controls/textfield/textfield.h" |
| 27 #include "ui/views/test/test_views_delegate.h" | 28 #include "ui/views/test/test_views_delegate.h" |
| 28 #include "ui/views/test/widget_test.h" | 29 #include "ui/views/test/widget_test.h" |
| 29 #include "ui/views/views_delegate.h" | 30 #include "ui/views/views_delegate.h" |
| 30 #include "ui/views/widget/native_widget_aura.h" | 31 #include "ui/views/widget/native_widget_aura.h" |
| 31 #include "ui/views/widget/native_widget_delegate.h" | 32 #include "ui/views/widget/native_widget_delegate.h" |
| (...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 // enter/exit. We could test move/drag/enter/exit but in general we don't run | 1283 // enter/exit. We could test move/drag/enter/exit but in general we don't run |
| 1283 // nested message loops from such events, nor has the code ever really dealt | 1284 // nested message loops from such events, nor has the code ever really dealt |
| 1284 // with this situation. | 1285 // with this situation. |
| 1285 | 1286 |
| 1286 // Generates two moves (first generates enter, second real move), a press, drag | 1287 // Generates two moves (first generates enter, second real move), a press, drag |
| 1287 // and release stopping at |last_event_type|. | 1288 // and release stopping at |last_event_type|. |
| 1288 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { | 1289 void GenerateMouseEvents(Widget* widget, ui::EventType last_event_type) { |
| 1289 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); | 1290 const gfx::Rect screen_bounds(widget->GetWindowBoundsInScreen()); |
| 1290 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), | 1291 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, screen_bounds.CenterPoint(), |
| 1291 screen_bounds.CenterPoint(), 0, 0); | 1292 screen_bounds.CenterPoint(), 0, 0); |
| 1292 aura::WindowEventDispatcher* dispatcher = | 1293 ui::EventProcessor* dispatcher = |
| 1293 widget->GetNativeWindow()->GetHost()->dispatcher(); | 1294 widget->GetNativeWindow()->GetHost()->event_processor(); |
| 1294 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); | 1295 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move_event); |
| 1295 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) | 1296 if (last_event_type == ui::ET_MOUSE_ENTERED || details.dispatcher_destroyed) |
| 1296 return; | 1297 return; |
| 1297 details = dispatcher->OnEventFromSource(&move_event); | 1298 details = dispatcher->OnEventFromSource(&move_event); |
| 1298 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) | 1299 if (last_event_type == ui::ET_MOUSE_MOVED || details.dispatcher_destroyed) |
| 1299 return; | 1300 return; |
| 1300 | 1301 |
| 1301 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), | 1302 ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED, screen_bounds.CenterPoint(), |
| 1302 screen_bounds.CenterPoint(), 0, 0); | 1303 screen_bounds.CenterPoint(), 0, 0); |
| 1303 details = dispatcher->OnEventFromSource(&press_event); | 1304 details = dispatcher->OnEventFromSource(&press_event); |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2051 widget_view->SetBounds(0, 0, 10, 10); | 2052 widget_view->SetBounds(0, 0, 10, 10); |
| 2052 top_level_widget.GetRootView()->AddChildView(widget_view); | 2053 top_level_widget.GetRootView()->AddChildView(widget_view); |
| 2053 | 2054 |
| 2054 gfx::Point cursor_location_main(5, 5); | 2055 gfx::Point cursor_location_main(5, 5); |
| 2055 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, | 2056 ui::MouseEvent move_main(ui::ET_MOUSE_MOVED, |
| 2056 cursor_location_main, | 2057 cursor_location_main, |
| 2057 cursor_location_main, | 2058 cursor_location_main, |
| 2058 ui::EF_NONE, | 2059 ui::EF_NONE, |
| 2059 ui::EF_NONE); | 2060 ui::EF_NONE); |
| 2060 ui::EventDispatchDetails details = top_level_widget.GetNativeView()-> | 2061 ui::EventDispatchDetails details = top_level_widget.GetNativeView()-> |
| 2061 GetHost()->dispatcher()->OnEventFromSource(&move_main); | 2062 GetHost()->event_processor()->OnEventFromSource(&move_main); |
| 2062 ASSERT_FALSE(details.dispatcher_destroyed); | 2063 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2063 | 2064 |
| 2064 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); | 2065 EXPECT_EQ(1, widget_view->GetEventCount(ui::ET_MOUSE_ENTERED)); |
| 2065 widget_view->ResetCounts(); | 2066 widget_view->ResetCounts(); |
| 2066 | 2067 |
| 2067 // Create a modal dialog and validate that a mouse down message makes it to | 2068 // Create a modal dialog and validate that a mouse down message makes it to |
| 2068 // the main view within the dialog. | 2069 // the main view within the dialog. |
| 2069 | 2070 |
| 2070 // This instance will be destroyed when the dialog is destroyed. | 2071 // This instance will be destroyed when the dialog is destroyed. |
| 2071 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; | 2072 ModalDialogDelegate* dialog_delegate = new ModalDialogDelegate; |
| 2072 | 2073 |
| 2073 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( | 2074 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( |
| 2074 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); | 2075 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); |
| 2075 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); | 2076 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 2076 EventCountView* dialog_widget_view = new EventCountView(); | 2077 EventCountView* dialog_widget_view = new EventCountView(); |
| 2077 dialog_widget_view->SetBounds(0, 0, 50, 50); | 2078 dialog_widget_view->SetBounds(0, 0, 50, 50); |
| 2078 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); | 2079 modal_dialog_widget->GetRootView()->AddChildView(dialog_widget_view); |
| 2079 modal_dialog_widget->Show(); | 2080 modal_dialog_widget->Show(); |
| 2080 EXPECT_TRUE(modal_dialog_widget->IsVisible()); | 2081 EXPECT_TRUE(modal_dialog_widget->IsVisible()); |
| 2081 | 2082 |
| 2082 gfx::Point cursor_location_dialog(100, 100); | 2083 gfx::Point cursor_location_dialog(100, 100); |
| 2083 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED, | 2084 ui::MouseEvent mouse_down_dialog(ui::ET_MOUSE_PRESSED, |
| 2084 cursor_location_dialog, | 2085 cursor_location_dialog, |
| 2085 cursor_location_dialog, | 2086 cursor_location_dialog, |
| 2086 ui::EF_NONE, | 2087 ui::EF_NONE, |
| 2087 ui::EF_NONE); | 2088 ui::EF_NONE); |
| 2088 details = top_level_widget.GetNativeView()->GetHost()->dispatcher()-> | 2089 details = top_level_widget.GetNativeView()->GetHost()->event_processor()-> |
| 2089 OnEventFromSource(&mouse_down_dialog); | 2090 OnEventFromSource(&mouse_down_dialog); |
| 2090 ASSERT_FALSE(details.dispatcher_destroyed); | 2091 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2091 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); | 2092 EXPECT_EQ(1, dialog_widget_view->GetEventCount(ui::ET_MOUSE_PRESSED)); |
| 2092 | 2093 |
| 2093 // Send a mouse move message to the main window. It should not be received by | 2094 // Send a mouse move message to the main window. It should not be received by |
| 2094 // the main window as the modal dialog is still active. | 2095 // the main window as the modal dialog is still active. |
| 2095 gfx::Point cursor_location_main2(6, 6); | 2096 gfx::Point cursor_location_main2(6, 6); |
| 2096 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, | 2097 ui::MouseEvent mouse_down_main(ui::ET_MOUSE_MOVED, |
| 2097 cursor_location_main2, | 2098 cursor_location_main2, |
| 2098 cursor_location_main2, | 2099 cursor_location_main2, |
| 2099 ui::EF_NONE, | 2100 ui::EF_NONE, |
| 2100 ui::EF_NONE); | 2101 ui::EF_NONE); |
| 2101 details = top_level_widget.GetNativeView()->GetHost()->dispatcher()-> | 2102 details = top_level_widget.GetNativeView()->GetHost()->event_processor()-> |
| 2102 OnEventFromSource(&mouse_down_main); | 2103 OnEventFromSource(&mouse_down_main); |
| 2103 ASSERT_FALSE(details.dispatcher_destroyed); | 2104 ASSERT_FALSE(details.dispatcher_destroyed); |
| 2104 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); | 2105 EXPECT_EQ(0, widget_view->GetEventCount(ui::ET_MOUSE_MOVED)); |
| 2105 | 2106 |
| 2106 modal_dialog_widget->CloseNow(); | 2107 modal_dialog_widget->CloseNow(); |
| 2107 top_level_widget.CloseNow(); | 2108 top_level_widget.CloseNow(); |
| 2108 } | 2109 } |
| 2109 | 2110 |
| 2110 // Verifies nativeview visbility matches that of Widget visibility when | 2111 // Verifies nativeview visbility matches that of Widget visibility when |
| 2111 // SetFullscreen is invoked. | 2112 // SetFullscreen is invoked. |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2393 child_widget.Init(child_params); | 2394 child_widget.Init(child_params); |
| 2394 child_widget.AddObserver(&observer); | 2395 child_widget.AddObserver(&observer); |
| 2395 child_widget.Show(); | 2396 child_widget.Show(); |
| 2396 | 2397 |
| 2397 parent_widget.CloseNow(); | 2398 parent_widget.CloseNow(); |
| 2398 } | 2399 } |
| 2399 #endif | 2400 #endif |
| 2400 | 2401 |
| 2401 } // namespace test | 2402 } // namespace test |
| 2402 } // namespace views | 2403 } // namespace views |
| OLD | NEW |