OLD | NEW |
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/root_view.h" | 5 #include "ui/views/widget/root_view.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
10 #include "ui/views/context_menu_controller.h" | 10 #include "ui/views/context_menu_controller.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 bool got_key_event = false; | 48 bool got_key_event = false; |
49 | 49 |
50 View* content = new View; | 50 View* content = new View; |
51 widget.SetContentsView(content); | 51 widget.SetContentsView(content); |
52 | 52 |
53 View* child = new DeleteOnKeyEventView(&got_key_event); | 53 View* child = new DeleteOnKeyEventView(&got_key_event); |
54 content->AddChildView(child); | 54 content->AddChildView(child); |
55 | 55 |
56 // Give focus to |child| so that it will be the target of the key event. | 56 // Give focus to |child| so that it will be the target of the key event. |
57 child->SetFocusable(true); | 57 child->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
58 child->RequestFocus(); | 58 child->RequestFocus(); |
59 | 59 |
60 internal::RootView* root_view = | 60 internal::RootView* root_view = |
61 static_cast<internal::RootView*>(widget.GetRootView()); | 61 static_cast<internal::RootView*>(widget.GetRootView()); |
62 ViewTargeter* view_targeter = new ViewTargeter(root_view); | 62 ViewTargeter* view_targeter = new ViewTargeter(root_view); |
63 root_view->SetEventTargeter(base::WrapUnique(view_targeter)); | 63 root_view->SetEventTargeter(base::WrapUnique(view_targeter)); |
64 | 64 |
65 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE); | 65 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, ui::EF_NONE); |
66 ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event); | 66 ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event); |
67 EXPECT_TRUE(details.target_destroyed); | 67 EXPECT_TRUE(details.target_destroyed); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 CreateParams(Widget::InitParams::TYPE_POPUP); | 114 CreateParams(Widget::InitParams::TYPE_POPUP); |
115 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 115 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
116 widget.Init(init_params); | 116 widget.Init(init_params); |
117 internal::RootView* root_view = | 117 internal::RootView* root_view = |
118 static_cast<internal::RootView*>(widget.GetRootView()); | 118 static_cast<internal::RootView*>(widget.GetRootView()); |
119 | 119 |
120 TestContextMenuController controller; | 120 TestContextMenuController controller; |
121 View* focused_view = new View; | 121 View* focused_view = new View; |
122 focused_view->set_context_menu_controller(&controller); | 122 focused_view->set_context_menu_controller(&controller); |
123 widget.SetContentsView(focused_view); | 123 widget.SetContentsView(focused_view); |
124 focused_view->SetFocusable(true); | 124 focused_view->SetFocusBehavior(View::FocusBehavior::ALWAYS); |
125 focused_view->RequestFocus(); | 125 focused_view->RequestFocus(); |
126 | 126 |
127 // No context menu should be shown for a keypress of 'A'. | 127 // No context menu should be shown for a keypress of 'A'. |
128 ui::KeyEvent nomenu_key_event('a', ui::VKEY_A, ui::EF_NONE); | 128 ui::KeyEvent nomenu_key_event('a', ui::VKEY_A, ui::EF_NONE); |
129 ui::EventDispatchDetails details = | 129 ui::EventDispatchDetails details = |
130 root_view->OnEventFromSource(&nomenu_key_event); | 130 root_view->OnEventFromSource(&nomenu_key_event); |
131 EXPECT_FALSE(details.target_destroyed); | 131 EXPECT_FALSE(details.target_destroyed); |
132 EXPECT_FALSE(details.dispatcher_destroyed); | 132 EXPECT_FALSE(details.dispatcher_destroyed); |
133 EXPECT_EQ(0, controller.show_context_menu_calls()); | 133 EXPECT_EQ(0, controller.show_context_menu_calls()); |
134 EXPECT_EQ(NULL, controller.menu_source_view()); | 134 EXPECT_EQ(NULL, controller.menu_source_view()); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // mouse exit event to |subchild| and destroy the widget. This should not | 551 // mouse exit event to |subchild| and destroy the widget. This should not |
552 // crash when the mouse exit handler returns from |subchild|. | 552 // crash when the mouse exit handler returns from |subchild|. |
553 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), | 553 ui::MouseEvent move_event2(ui::ET_MOUSE_MOVED, gfx::Point(15, 15), |
554 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0); | 554 gfx::Point(15, 15), ui::EventTimeForNow(), 0, 0); |
555 root_view->OnMouseMoved(move_event2); | 555 root_view->OnMouseMoved(move_event2); |
556 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); | 556 EXPECT_FALSE(widget_deletion_observer.IsWidgetAlive()); |
557 } | 557 } |
558 | 558 |
559 } // namespace test | 559 } // namespace test |
560 } // namespace views | 560 } // namespace views |
OLD | NEW |