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

Side by Side Diff: ui/views/widget/root_view.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.h ('k') | ui/views/widget/root_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "ui/accessibility/ax_view_state.h" 11 #include "ui/accessibility/ax_view_state.h"
12 #include "ui/base/cursor/cursor.h" 12 #include "ui/base/cursor/cursor.h"
13 #include "ui/base/dragdrop/drag_drop_types.h" 13 #include "ui/base/dragdrop/drag_drop_types.h"
14 #include "ui/base/ui_base_switches_util.h"
14 #include "ui/compositor/layer.h" 15 #include "ui/compositor/layer.h"
15 #include "ui/events/event.h" 16 #include "ui/events/event.h"
16 #include "ui/events/keycodes/keyboard_codes.h" 17 #include "ui/events/keycodes/keyboard_codes.h"
17 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/views/drag_controller.h"
18 #include "ui/views/focus/view_storage.h" 20 #include "ui/views/focus/view_storage.h"
19 #include "ui/views/layout/fill_layout.h" 21 #include "ui/views/layout/fill_layout.h"
20 #include "ui/views/view_targeter.h" 22 #include "ui/views/view_targeter.h"
21 #include "ui/views/views_switches.h" 23 #include "ui/views/views_switches.h"
22 #include "ui/views/widget/widget.h" 24 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h" 25 #include "ui/views/widget/widget_delegate.h"
24 26
25 typedef ui::EventDispatchDetails DispatchDetails; 27 typedef ui::EventDispatchDetails DispatchDetails;
26 28
27 namespace views { 29 namespace views {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 v->ShowContextMenu(location, ui::MENU_SOURCE_KEYBOARD); 87 v->ShowContextMenu(location, ui::MENU_SOURCE_KEYBOARD);
86 event->StopPropagation(); 88 event->StopPropagation();
87 } 89 }
88 } 90 }
89 91
90 View* owner_; 92 View* owner_;
91 93
92 DISALLOW_COPY_AND_ASSIGN(PreEventDispatchHandler); 94 DISALLOW_COPY_AND_ASSIGN(PreEventDispatchHandler);
93 }; 95 };
94 96
97 // This event handler receives events in the post-target phase and takes care of
98 // the following:
99 // - Generates context menu, or initiates drag-and-drop, from gesture events.
100 class PostEventDispatchHandler : public ui::EventHandler {
101 public:
102 PostEventDispatchHandler()
103 : touch_dnd_enabled_(::switches::IsTouchDragDropEnabled()) {
104 }
105 virtual ~PostEventDispatchHandler() {}
106
107 private:
108 // Overridden from ui::EventHandler:
109 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
110 DCHECK_EQ(ui::EP_POSTTARGET, event->phase());
111 if (event->handled())
112 return;
113
114 View* target = static_cast<View*>(event->target());
115 gfx::Point location = event->location();
116 if (touch_dnd_enabled_ &&
117 event->type() == ui::ET_GESTURE_LONG_PRESS &&
118 (!target->drag_controller() ||
119 target->drag_controller()->CanStartDragForView(
120 target, location, location))) {
121 if (target->DoDrag(*event, location,
122 ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH)) {
123 event->StopPropagation();
124 return;
125 }
126 }
127
128 if (target->context_menu_controller() &&
129 (event->type() == ui::ET_GESTURE_LONG_PRESS ||
130 event->type() == ui::ET_GESTURE_LONG_TAP ||
131 event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) {
132 gfx::Point screen_location(location);
133 View::ConvertPointToScreen(target, &screen_location);
134 target->ShowContextMenu(screen_location, ui::MENU_SOURCE_TOUCH);
135 event->StopPropagation();
136 }
137 }
138
139 bool touch_dnd_enabled_;
140
141 DISALLOW_COPY_AND_ASSIGN(PostEventDispatchHandler);
142 };
143
95 // static 144 // static
96 const char RootView::kViewClassName[] = "RootView"; 145 const char RootView::kViewClassName[] = "RootView";
97 146
98 //////////////////////////////////////////////////////////////////////////////// 147 ////////////////////////////////////////////////////////////////////////////////
99 // RootView, public: 148 // RootView, public:
100 149
101 // Creation and lifetime ------------------------------------------------------- 150 // Creation and lifetime -------------------------------------------------------
102 151
103 RootView::RootView(Widget* widget) 152 RootView::RootView(Widget* widget)
104 : widget_(widget), 153 : widget_(widget),
105 mouse_pressed_handler_(NULL), 154 mouse_pressed_handler_(NULL),
106 mouse_move_handler_(NULL), 155 mouse_move_handler_(NULL),
107 last_click_handler_(NULL), 156 last_click_handler_(NULL),
108 explicit_mouse_handler_(false), 157 explicit_mouse_handler_(false),
109 last_mouse_event_flags_(0), 158 last_mouse_event_flags_(0),
110 last_mouse_event_x_(-1), 159 last_mouse_event_x_(-1),
111 last_mouse_event_y_(-1), 160 last_mouse_event_y_(-1),
112 gesture_handler_(NULL), 161 gesture_handler_(NULL),
113 scroll_gesture_handler_(NULL), 162 scroll_gesture_handler_(NULL),
114 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)), 163 pre_dispatch_handler_(new internal::PreEventDispatchHandler(this)),
164 post_dispatch_handler_(new internal::PostEventDispatchHandler),
115 focus_search_(this, false, false), 165 focus_search_(this, false, false),
116 focus_traversable_parent_(NULL), 166 focus_traversable_parent_(NULL),
117 focus_traversable_parent_view_(NULL), 167 focus_traversable_parent_view_(NULL),
118 event_dispatch_target_(NULL), 168 event_dispatch_target_(NULL),
119 old_dispatch_target_(NULL) { 169 old_dispatch_target_(NULL) {
120 AddPreTargetHandler(pre_dispatch_handler_.get()); 170 AddPreTargetHandler(pre_dispatch_handler_.get());
171 AddPostTargetHandler(post_dispatch_handler_.get());
121 SetEventTargeter(scoped_ptr<ui::EventTargeter>(new ViewTargeter())); 172 SetEventTargeter(scoped_ptr<ui::EventTargeter>(new ViewTargeter()));
122 } 173 }
123 174
124 RootView::~RootView() { 175 RootView::~RootView() {
125 // If we have children remove them explicitly so to make sure a remove 176 // If we have children remove them explicitly so to make sure a remove
126 // notification is sent for each one of them. 177 // notification is sent for each one of them.
127 if (has_children()) 178 if (has_children())
128 RemoveAllChildViews(true); 179 RemoveAllChildViews(true);
129 } 180 }
130 181
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 808
758 #ifndef NDEBUG 809 #ifndef NDEBUG
759 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); 810 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_));
760 #endif 811 #endif
761 812
762 return details; 813 return details;
763 } 814 }
764 815
765 } // namespace internal 816 } // namespace internal
766 } // namespace views 817 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.h ('k') | ui/views/widget/root_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698