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

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: Rebased and renamed. Created 3 years, 6 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;
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)
152 MenuController* menu_controller =
153 submenu_->GetMenuItem()->GetMenuController();
154 if (menu_controller) {
155 if (menu_controller->owner_needs_gesture_events()) {
xiyuan 2017/05/26 23:13:38 Combine this "if" with "if" on Line 154 and run th
minch1 2017/06/01 16:42:28 Done.
156 // TransferGesture when owner needs gesture events so that the incoming
157 // touch events after MenuHost is created are properly translated into
158 // gesture events instead of being dropped.
159 internal::TransferGesture(owner_, this);
160 } else {
161 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
162 }
163 }
164 #else // defined(OS_MACOSX)
144 // Cancel existing touches, so we don't miss some touch release/cancel 165 // Cancel existing touches, so we don't miss some touch release/cancel
145 // events due to the menu taking capture. 166 // events due to the menu taking capture.
146 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr); 167 ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
168 #endif // !defined(OS_MACOSX)
147 native_widget_private()->SetCapture(); 169 native_widget_private()->SetCapture();
148 } 170 }
149 } 171 }
150 172
151 void MenuHost::HideMenuHost() { 173 void MenuHost::HideMenuHost() {
174 #if !defined(OS_MACOSX)
175 MenuController* menu_controller =
176 submenu_->GetMenuItem()->GetMenuController();
177 if (owner_ && menu_controller &&
178 menu_controller->owner_needs_gesture_events()) {
179 internal::TransferGesture(this, owner_);
180 owner_ = nullptr;
181 }
182 #endif // !defined(OS_MACOSX)
152 ignore_capture_lost_ = true; 183 ignore_capture_lost_ = true;
153 ReleaseMenuHostCapture(); 184 ReleaseMenuHostCapture();
154 Hide(); 185 Hide();
155 ignore_capture_lost_ = false; 186 ignore_capture_lost_ = false;
156 } 187 }
157 188
158 void MenuHost::DestroyMenuHost() { 189 void MenuHost::DestroyMenuHost() {
159 HideMenuHost(); 190 HideMenuHost();
160 destroying_ = true; 191 destroying_ = true;
161 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu(); 192 static_cast<MenuHostRootView*>(GetRootView())->ClearSubmenu();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 270 }
240 menu_controller->OnDragComplete(should_close); 271 menu_controller->OnDragComplete(should_close);
241 272
242 // We may have lost capture in the drag and drop, but are remaining open. 273 // We may have lost capture in the drag and drop, but are remaining open.
243 // Return capture so we get MouseCaptureLost events. 274 // Return capture so we get MouseCaptureLost events.
244 if (!should_close) 275 if (!should_close)
245 native_widget_private()->SetCapture(); 276 native_widget_private()->SetCapture();
246 } 277 }
247 278
248 } // namespace views 279 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698