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

Side by Side Diff: ui/views/widget/root_view_unittest.cc

Issue 291273007: Prevent the context menu from showing when long pressing the window controls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include "ui/events/event_targeter.h" 7 #include "ui/events/event_targeter.h"
8 #include "ui/views/context_menu_controller.h" 8 #include "ui/views/context_menu_controller.h"
9 #include "ui/views/test/views_test_base.h" 9 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/view_targeter.h" 10 #include "ui/views/view_targeter.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 static_cast<internal::RootView*>(widget.GetRootView()); 59 static_cast<internal::RootView*>(widget.GetRootView());
60 root_view->SetEventTargeter(make_scoped_ptr(targeter)); 60 root_view->SetEventTargeter(make_scoped_ptr(targeter));
61 61
62 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0, false); 62 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_ESCAPE, 0, false);
63 ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event); 63 ui::EventDispatchDetails details = root_view->OnEventFromSource(&key_event);
64 EXPECT_TRUE(details.target_destroyed); 64 EXPECT_TRUE(details.target_destroyed);
65 EXPECT_FALSE(details.dispatcher_destroyed); 65 EXPECT_FALSE(details.dispatcher_destroyed);
66 EXPECT_TRUE(got_key_event); 66 EXPECT_TRUE(got_key_event);
67 } 67 }
68 68
69 // Used to determine whether or not a context menu is shown as a result of 69 // Tracks whether a context menu is shown.
70 // a keypress.
71 class TestContextMenuController : public ContextMenuController { 70 class TestContextMenuController : public ContextMenuController {
72 public: 71 public:
73 TestContextMenuController() 72 TestContextMenuController()
74 : show_context_menu_calls_(0), 73 : show_context_menu_calls_(0),
75 menu_source_view_(NULL), 74 menu_source_view_(NULL),
76 menu_source_type_(ui::MENU_SOURCE_NONE) { 75 menu_source_type_(ui::MENU_SOURCE_NONE) {
77 } 76 }
78 virtual ~TestContextMenuController() {} 77 virtual ~TestContextMenuController() {}
79 78
80 int show_context_menu_calls() const { return show_context_menu_calls_; } 79 int show_context_menu_calls() const { return show_context_menu_calls_; }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, 0, false); 148 ui::KeyEvent menu_key_event2(ui::ET_KEY_PRESSED, ui::VKEY_APPS, 0, false);
150 details = root_view->OnEventFromSource(&menu_key_event2); 149 details = root_view->OnEventFromSource(&menu_key_event2);
151 EXPECT_FALSE(details.target_destroyed); 150 EXPECT_FALSE(details.target_destroyed);
152 EXPECT_FALSE(details.dispatcher_destroyed); 151 EXPECT_FALSE(details.dispatcher_destroyed);
153 EXPECT_EQ(1, controller.show_context_menu_calls()); 152 EXPECT_EQ(1, controller.show_context_menu_calls());
154 EXPECT_EQ(focused_view, controller.menu_source_view()); 153 EXPECT_EQ(focused_view, controller.menu_source_view());
155 EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type()); 154 EXPECT_EQ(ui::MENU_SOURCE_KEYBOARD, controller.menu_source_type());
156 controller.Reset(); 155 controller.Reset();
157 } 156 }
158 157
158 // View which handles all gesture events.
159 class GestureHandlingView : public View {
160 public:
161 GestureHandlingView() {
162 }
163
164 virtual ~GestureHandlingView() {
165 }
166
167 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
168 event->SetHandled();
169 }
170
171 private:
172 DISALLOW_COPY_AND_ASSIGN(GestureHandlingView);
173 };
174
175 // Tests that context menus are shown for long press by the post-target handler
176 // installed on the RootView only if the event is targetted at a view which can
177 // show a context menu.
178 TEST_F(RootViewTest, ContextMenuFromLongPress) {
179 Widget widget;
180 Widget::InitParams init_params =
181 CreateParams(Widget::InitParams::TYPE_POPUP);
182 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
183 init_params.bounds = gfx::Rect(100,100);
184 widget.Init(init_params);
185 internal::RootView* root_view =
186 static_cast<internal::RootView*>(widget.GetRootView());
187
188 // Create a view capable of showing the context menu with two children one of
189 // which handles all gesture events (e.g. a button).
190 TestContextMenuController controller;
191 View* parent_view = new View;
192 parent_view->set_context_menu_controller(&controller);
193 widget.SetContentsView(parent_view);
194
195 View* gesture_handling_child_view = new GestureHandlingView;
196 gesture_handling_child_view->SetBoundsRect(gfx::Rect(10,10));
197 parent_view->AddChildView(gesture_handling_child_view);
198
199 View* other_child_view = new View;
200 other_child_view->SetBoundsRect(gfx::Rect(20, 0, 10,10));
201 parent_view->AddChildView(other_child_view);
202
203 // |parent_view| should not show a context menu as a result of a long press on
204 // |gesture_handling_child_view|.
205 ui::GestureEvent begin1(ui::ET_GESTURE_BEGIN, 5, 5, 0, base::TimeDelta(),
206 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
207 ui::EventDispatchDetails details = root_view->OnEventFromSource(&begin1);
208
209 ui::GestureEvent long_press1(ui::ET_GESTURE_LONG_PRESS, 5, 5, 0,
210 base::TimeDelta(),
211 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0), 1);
212 details = root_view->OnEventFromSource(&long_press1);
213
214 ui::GestureEvent end1(ui::ET_GESTURE_END, 5, 5, 0, base::TimeDelta(),
215 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
216 details = root_view->OnEventFromSource(&end1);
217
218 EXPECT_FALSE(details.target_destroyed);
219 EXPECT_FALSE(details.dispatcher_destroyed);
220 EXPECT_EQ(0, controller.show_context_menu_calls());
221
222 // |parent_view| should show a context menu as a result of a long press on
223 // |other_child_view|.
224 ui::GestureEvent begin2(ui::ET_GESTURE_BEGIN, 25, 5, 0, base::TimeDelta(),
225 ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
226 details = root_view->OnEventFromSource(&begin2);
227
228 ui::GestureEvent long_press2(ui::ET_GESTURE_LONG_PRESS, 25, 5, 0,
229 base::TimeDelta(),
230 ui::GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0), 1);
231 details = root_view->OnEventFromSource(&long_press2);
232
233 ui::GestureEvent end2(ui::ET_GESTURE_END, 25, 5, 0, base::TimeDelta(),
234 ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
235 details = root_view->OnEventFromSource(&end2);
236
237 EXPECT_FALSE(details.target_destroyed);
238 EXPECT_FALSE(details.dispatcher_destroyed);
239 EXPECT_EQ(1, controller.show_context_menu_calls());
240 }
241
159 } // namespace test 242 } // namespace test
160 } // namespace views 243 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698