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

Side by Side Diff: ui/views/controls/menu/menu_host.cc

Issue 2876203003: Make shelf item can be dragged when context menu is opened.
Patch Set: Fixed comments. Created 3 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
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/controls/menu/menu_host.h" 5 #include "ui/views/controls/menu/menu_host.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "ui/aura/window_observer.h" 11 #include "ui/aura/window_observer.h"
12 #include "ui/events/gestures/gesture_recognizer.h" 12 #include "ui/events/gestures/gesture_recognizer.h"
13 #include "ui/gfx/path.h" 13 #include "ui/gfx/path.h"
14 #include "ui/native_theme/native_theme.h" 14 #include "ui/native_theme/native_theme.h"
15 #include "ui/views/controls/menu/menu_controller.h"
16 #include "ui/views/controls/menu/menu_host_root_view.h" 15 #include "ui/views/controls/menu/menu_host_root_view.h"
17 #include "ui/views/controls/menu/menu_item_view.h" 16 #include "ui/views/controls/menu/menu_item_view.h"
18 #include "ui/views/controls/menu/menu_scroll_view_container.h" 17 #include "ui/views/controls/menu/menu_scroll_view_container.h"
19 #include "ui/views/controls/menu/submenu_view.h" 18 #include "ui/views/controls/menu/submenu_view.h"
20 #include "ui/views/round_rect_painter.h" 19 #include "ui/views/round_rect_painter.h"
21 #include "ui/views/widget/native_widget_private.h" 20 #include "ui/views/widget/native_widget_private.h"
22 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
23 22
24 #if !defined(OS_MACOSX) 23 #if !defined(OS_MACOSX)
25 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 MenuController* menu_controller_; 74 MenuController* menu_controller_;
76 SubmenuView* submenu_; 75 SubmenuView* submenu_;
77 aura::Window* window_; 76 aura::Window* window_;
78 77
79 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler); 78 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler);
80 }; 79 };
81 #endif // OS_MACOSX 80 #endif // OS_MACOSX
82 81
83 } // namespace internal 82 } // namespace internal
84 83
84 namespace {
85
86 #if defined(OS_CHROMEOS)
87 void TransferGesture(Widget* source, Widget* target) {
88 ui::GestureRecognizer::Get()->TransferEventsTo(
89 source->GetNativeView(), target->GetNativeView(),
90 ui::GestureRecognizer::ShouldCancelTouches::DontCancel);
91 }
92 #endif
93
94 } // namespace
xiyuan 2017/05/16 22:46:57 nit: We probably can put TransferGesture in the in
minch1 2017/05/17 16:55:38 Done.
95
85 //////////////////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////////////////
86 // MenuHost, public: 97 // MenuHost, public:
87 98
88 MenuHost::MenuHost(SubmenuView* submenu) 99 MenuHost::MenuHost(SubmenuView* submenu)
89 : submenu_(submenu), 100 : submenu_(submenu),
90 destroying_(false), 101 destroying_(false),
91 ignore_capture_lost_(false) { 102 ignore_capture_lost_(false) {
92 set_auto_release_capture(false); 103 set_auto_release_capture(false);
93 } 104 }
94 105
(...skipping 25 matching lines...) Expand all
120 // revert this change once http://crbug.com/125248 is fixed. 131 // revert this change once http://crbug.com/125248 is fixed.
121 params.force_software_compositing = true; 132 params.force_software_compositing = true;
122 #endif 133 #endif
123 Init(params); 134 Init(params);
124 135
125 #if !defined(OS_MACOSX) 136 #if !defined(OS_MACOSX)
126 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( 137 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler(
127 menu_controller, submenu_, GetNativeView())); 138 menu_controller, submenu_, GetNativeView()));
128 #endif 139 #endif
129 140
141 #if defined(OS_CHROMEOS)
xiyuan 2017/05/16 22:46:57 I wonder whether we should consider !defined(OS_MA
142 if (parent && controller && controller->owner_needs_gesture_events()) {
xiyuan 2017/05/16 22:46:57 Briefly document why we need to TransferGesture.
minch1 2017/05/17 16:55:37 Done.
143 owner_ = parent;
144 TransferGesture(owner_, this);
xiyuan 2017/05/16 22:46:57 Can we move this to ShowMenuHost so that it is sym
minch1 2017/05/17 16:55:37 Done.
145 }
146 #endif
147
130 SetContentsView(contents_view); 148 SetContentsView(contents_view);
131 ShowMenuHost(do_capture); 149 ShowMenuHost(do_capture);
132 } 150 }
133 151
134 bool MenuHost::IsMenuHostVisible() { 152 bool MenuHost::IsMenuHostVisible() {
135 return IsVisible(); 153 return IsVisible();
136 } 154 }
137 155
138 void MenuHost::ShowMenuHost(bool do_capture) { 156 void MenuHost::ShowMenuHost(bool do_capture) {
139 // Doing a capture may make us get capture lost. Ignore it while we're in the 157 // Doing a capture may make us get capture lost. Ignore it while we're in the
140 // process of showing. 158 // process of showing.
141 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); 159 base::AutoReset<bool> reseter(&ignore_capture_lost_, true);
142 ShowInactive(); 160 ShowInactive();
143 if (do_capture) { 161 if (do_capture) {
144 // Cancel existing touches, so we don't miss some touch release/cancel 162 // Cancel existing touches, so we don't miss some touch release/cancel
145 // events due to the menu taking capture. 163 // events due to the menu taking capture.
164 #if defined(OS_CHROMEOS)
165 if (controller && !controller->owner_needs_gesture_events())
166 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
167 #else
146 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); 168 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
169 #endif
147 native_widget_private()->SetCapture(); 170 native_widget_private()->SetCapture();
148 } 171 }
149 } 172 }
150 173
151 void MenuHost::HideMenuHost() { 174 void MenuHost::HideMenuHost() {
175 #if defined(OS_CHROMEOS)
176 if (owner_ && controller && controller->owner_needs_gesture_events()) {
177 TransferGesture(this, owner_);
178 owner_ = nullptr;
179 controller->set_owner_needs_gesture_events(false);
xiyuan 2017/05/16 22:46:57 Do we still need this after making the flag a memb
minch1 2017/05/17 16:55:38 Oh, yeap, we don't need to do this.
180 }
181 #endif
152 ignore_capture_lost_ = true; 182 ignore_capture_lost_ = true;
153 ReleaseMenuHostCapture(); 183 ReleaseMenuHostCapture();
154 Hide(); 184 Hide();
155 ignore_capture_lost_ = false; 185 ignore_capture_lost_ = false;
156 } 186 }
157 187
158 void MenuHost::DestroyMenuHost() { 188 void MenuHost::DestroyMenuHost() {
159 HideMenuHost(); 189 HideMenuHost();
160 destroying_ = true; 190 destroying_ = true;
161 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); 191 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 269 }
240 menu_controller->OnDragComplete(should_close); 270 menu_controller->OnDragComplete(should_close);
241 271
242 // We may have lost capture in the drag and drop, but are remaining open. 272 // We may have lost capture in the drag and drop, but are remaining open.
243 // Return capture so we get MouseCaptureLost events. 273 // Return capture so we get MouseCaptureLost events.
244 if (!should_close) 274 if (!should_close)
245 native_widget_private()->SetCapture(); 275 native_widget_private()->SetCapture();
246 } 276 }
247 277
248 } // namespace views 278 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698