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

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 nit. Created 3 years, 4 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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 window_->RemoveObserver(this); 71 window_->RemoveObserver(this);
72 window_ = nullptr; 72 window_ = nullptr;
73 } 73 }
74 74
75 MenuController* menu_controller_; 75 MenuController* menu_controller_;
76 SubmenuView* submenu_; 76 SubmenuView* submenu_;
77 aura::Window* window_; 77 aura::Window* window_;
78 78
79 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler); 79 DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler);
80 }; 80 };
81
82 void TransferGesture(Widget* source, Widget* target) {
83 ui::GestureRecognizer::Get()->TransferEventsTo(
84 source->GetNativeView(), target->GetNativeView(),
85 ui::GestureRecognizer::ShouldCancelTouches::DontCancel);
86 }
81 #endif // OS_MACOSX 87 #endif // OS_MACOSX
82 88
83 } // namespace internal 89 } // namespace internal
84 90
85 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
86 // MenuHost, public: 92 // MenuHost, public:
87 93
88 MenuHost::MenuHost(SubmenuView* submenu) 94 MenuHost::MenuHost(SubmenuView* submenu)
89 : submenu_(submenu), 95 : submenu_(submenu),
90 destroying_(false), 96 destroying_(false),
(...skipping 27 matching lines...) Expand all
118 // On Windows use the software compositor to ensure that we don't block 124 // On Windows use the software compositor to ensure that we don't block
119 // the UI thread blocking issue during command buffer creation. We can 125 // the UI thread blocking issue during command buffer creation. We can
120 // revert this change once http://crbug.com/125248 is fixed. 126 // revert this change once http://crbug.com/125248 is fixed.
121 params.force_software_compositing = true; 127 params.force_software_compositing = true;
122 #endif 128 #endif
123 Init(params); 129 Init(params);
124 130
125 #if !defined(OS_MACOSX) 131 #if !defined(OS_MACOSX)
126 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler( 132 pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler(
127 menu_controller, submenu_, GetNativeView())); 133 menu_controller, submenu_, GetNativeView()));
134 owner_ = parent;
sadrul 2017/08/30 20:31:39 What if |owner_| is destroyed after the menu comes
minch1 2017/08/31 23:21:02 Added DCHECK(owner()) when we need to send events
sadrul 2017/09/07 19:58:28 If |owner_| is destroyed, the DCHECK() won't hit t
minch1 2017/09/07 20:54:55 Do you mean that |parent| is destroyed after assig
128 #endif 135 #endif
129 136
130 SetContentsView(contents_view); 137 SetContentsView(contents_view);
131 ShowMenuHost(do_capture); 138 ShowMenuHost(do_capture);
132 } 139 }
133 140
134 bool MenuHost::IsMenuHostVisible() { 141 bool MenuHost::IsMenuHostVisible() {
135 return IsVisible(); 142 return IsVisible();
136 } 143 }
137 144
138 void MenuHost::ShowMenuHost(bool do_capture) { 145 void MenuHost::ShowMenuHost(bool do_capture) {
139 // Doing a capture may make us get capture lost. Ignore it while we're in the 146 // Doing a capture may make us get capture lost. Ignore it while we're in the
140 // process of showing. 147 // process of showing.
141 base::AutoReset<bool> reseter(&ignore_capture_lost_, true); 148 base::AutoReset<bool> reseter(&ignore_capture_lost_, true);
142 ShowInactive(); 149 ShowInactive();
143 if (do_capture) { 150 if (do_capture) {
151 #if !defined(OS_MACOSX)
sadrul 2017/08/30 20:31:39 Do we need the OS_MACOSX checks?
minch1 2017/08/31 23:21:02 I think so. Since GestureRecognizerImplMac current
152 MenuController* menu_controller =
153 submenu_->GetMenuItem()->GetMenuController();
154 if (menu_controller && menu_controller->send_gesture_events_to_owner()) {
155 // TransferGesture when owner needs gesture events so that the incoming
156 // touch events after MenuHost is created are properly translated into
157 // gesture events instead of being dropped.
158 internal::TransferGesture(owner_, this);
159 } else {
160 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
161 }
162 #else // defined(OS_MACOSX)
144 // Cancel existing touches, so we don't miss some touch release/cancel 163 // Cancel existing touches, so we don't miss some touch release/cancel
145 // events due to the menu taking capture. 164 // events due to the menu taking capture.
146 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); 165 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
166 #endif // !defined(OS_MACOSX)
147 native_widget_private()->SetCapture(); 167 native_widget_private()->SetCapture();
148 } 168 }
149 } 169 }
sadrul 2017/08/30 20:31:39 An alternate approach, although probably hackier t
minch1 2017/08/31 23:21:02 Do you mean to do all of these in ShowMenuHost? Tr
150 170
151 void MenuHost::HideMenuHost() { 171 void MenuHost::HideMenuHost() {
172 #if !defined(OS_MACOSX)
173 MenuController* menu_controller =
174 submenu_->GetMenuItem()->GetMenuController();
175 if (owner_ && menu_controller &&
176 menu_controller->send_gesture_events_to_owner()) {
177 internal::TransferGesture(this, owner_);
178 owner_ = nullptr;
179 }
180 #endif // !defined(OS_MACOSX)
152 ignore_capture_lost_ = true; 181 ignore_capture_lost_ = true;
153 ReleaseMenuHostCapture(); 182 ReleaseMenuHostCapture();
154 Hide(); 183 Hide();
155 ignore_capture_lost_ = false; 184 ignore_capture_lost_ = false;
156 } 185 }
157 186
158 void MenuHost::DestroyMenuHost() { 187 void MenuHost::DestroyMenuHost() {
159 HideMenuHost(); 188 HideMenuHost();
160 destroying_ = true; 189 destroying_ = true;
161 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); 190 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 268 }
240 menu_controller->OnDragComplete(should_close); 269 menu_controller->OnDragComplete(should_close);
241 270
242 // We may have lost capture in the drag and drop, but are remaining open. 271 // We may have lost capture in the drag and drop, but are remaining open.
243 // Return capture so we get MouseCaptureLost events. 272 // Return capture so we get MouseCaptureLost events.
244 if (!should_close) 273 if (!should_close)
245 native_widget_private()->SetCapture(); 274 native_widget_private()->SetCapture();
246 } 275 }
247 276
248 } // namespace views 277 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698