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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/menu/menu_host.cc
diff --git a/ui/views/controls/menu/menu_host.cc b/ui/views/controls/menu/menu_host.cc
index c6750a6e0cd51be18d9470a45969bed6b27c0e4c..b16cfe223a7c8d50c1274e1350d65a4d1bddbc72 100644
--- a/ui/views/controls/menu/menu_host.cc
+++ b/ui/views/controls/menu/menu_host.cc
@@ -80,6 +80,14 @@ class PreMenuEventDispatchHandler : public ui::EventHandler,
};
#endif // OS_MACOSX
+#if !defined(OS_MACOSX)
+void TransferGesture(Widget* source, Widget* target) {
msw 2017/05/17 23:03:30 nit: comment, maybe seek menu review from sky@?
+ ui::GestureRecognizer::Get()->TransferEventsTo(
+ source->GetNativeView(), target->GetNativeView(),
+ ui::GestureRecognizer::ShouldCancelTouches::DontCancel);
+}
+#endif
+
} // namespace internal
////////////////////////////////////////////////////////////////////////////////
@@ -125,6 +133,7 @@ void MenuHost::InitMenuHost(Widget* parent,
#if !defined(OS_MACOSX)
pre_dispatch_handler_.reset(new internal::PreMenuEventDispatchHandler(
menu_controller, submenu_, GetNativeView()));
+ owner_ = parent;
#endif
SetContentsView(contents_view);
@@ -143,12 +152,36 @@ void MenuHost::ShowMenuHost(bool do_capture) {
if (do_capture) {
// Cancel existing touches, so we don't miss some touch release/cancel
msw 2017/05/17 23:03:30 nit: move comment into else?
minch1 2017/05/26 23:01:12 Done.
// events due to the menu taking capture.
+#if !defined(OS_MACOSX)
+ MenuController* menu_controller =
+ submenu_->GetMenuItem()->GetMenuController();
+ if (menu_controller) {
+ if (menu_controller->owner_needs_gesture_events()) {
+ // TransferGesture when owner needs gesture events so that the incoming
+ // touch events after MenuHost is created are properly translated into
+ // gesture events instead of being dropped.
+ internal::TransferGesture(owner_, this);
+ } else {
+ ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
+ }
+ }
+#else
ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
+#endif
native_widget_private()->SetCapture();
}
}
void MenuHost::HideMenuHost() {
+#if !defined(OS_MACOSX)
+ MenuController* menu_controller =
+ submenu_->GetMenuItem()->GetMenuController();
+ if (owner_ && menu_controller &&
+ menu_controller->owner_needs_gesture_events()) {
+ internal::TransferGesture(this, owner_);
+ owner_ = nullptr;
+ }
+#endif
ignore_capture_lost_ = true;
ReleaseMenuHostCapture();
Hide();

Powered by Google App Engine
This is Rietveld 408576698