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

Unified Diff: ui/views/controls/menu/menu_host.cc

Issue 2876203003: Make shelf item can be dragged when context menu is opened.
Patch Set: Add widget observer for |owner_| in MenuHost. Created 3 years, 3 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
« no previous file with comments | « ui/views/controls/menu/menu_host.h ('k') | ui/views/controls/menu/menu_runner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2eaa627dc9daf168ba109574caf6610e33cb3765 100644
--- a/ui/views/controls/menu/menu_host.cc
+++ b/ui/views/controls/menu/menu_host.cc
@@ -78,6 +78,12 @@ class PreMenuEventDispatchHandler : public ui::EventHandler,
DISALLOW_COPY_AND_ASSIGN(PreMenuEventDispatchHandler);
};
+
+void TransferGesture(Widget* source, Widget* target) {
+ ui::GestureRecognizer::Get()->TransferEventsTo(
+ source->GetNativeView(), target->GetNativeView(),
+ ui::GestureRecognizer::ShouldCancelTouches::DontCancel);
+}
#endif // OS_MACOSX
} // namespace internal
@@ -93,6 +99,8 @@ MenuHost::MenuHost(SubmenuView* submenu)
}
MenuHost::~MenuHost() {
+ if (owner_)
+ owner_->RemoveObserver(this);
}
void MenuHost::InitMenuHost(Widget* parent,
@@ -127,6 +135,12 @@ void MenuHost::InitMenuHost(Widget* parent,
menu_controller, submenu_, GetNativeView()));
#endif
+ if (owner_)
+ owner_->RemoveObserver(this);
+ owner_ = parent;
+ if (owner_)
+ owner_->AddObserver(this);
+
SetContentsView(contents_view);
ShowMenuHost(do_capture);
}
@@ -141,14 +155,35 @@ void MenuHost::ShowMenuHost(bool do_capture) {
base::AutoReset<bool> reseter(&ignore_capture_lost_, true);
ShowInactive();
if (do_capture) {
+#if !defined(OS_MACOSX)
+ MenuController* menu_controller =
+ submenu_->GetMenuItem()->GetMenuController();
+ if (menu_controller && menu_controller->send_gesture_events_to_owner()) {
+ // 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 // defined(OS_MACOSX)
// Cancel existing touches, so we don't miss some touch release/cancel
// events due to the menu taking capture.
ui::GestureRecognizer::Get()->CancelActiveTouchesExcept(nullptr);
+#endif // !defined(OS_MACOSX)
native_widget_private()->SetCapture();
}
}
void MenuHost::HideMenuHost() {
+#if !defined(OS_MACOSX)
+ MenuController* menu_controller =
+ submenu_->GetMenuItem()->GetMenuController();
+ if (owner_ && menu_controller &&
+ menu_controller->send_gesture_events_to_owner()) {
+ internal::TransferGesture(this, owner_);
+ }
+#endif // !defined(OS_MACOSX)
ignore_capture_lost_ = true;
ReleaseMenuHostCapture();
Hide();
@@ -175,7 +210,7 @@ void MenuHost::ReleaseMenuHostCapture() {
}
////////////////////////////////////////////////////////////////////////////////
-// MenuHost, Widget overrides:
+// MenuHost, private:
internal::RootView* MenuHost::CreateRootView() {
return new MenuHostRootView(this, submenu_);
@@ -245,4 +280,10 @@ void MenuHost::OnDragComplete() {
native_widget_private()->SetCapture();
}
+void MenuHost::OnWidgetDestroying(Widget* widget) {
+ DCHECK_EQ(owner_, widget);
+ owner_->RemoveObserver(this);
+ owner_ = nullptr;
+}
+
} // namespace views
« no previous file with comments | « ui/views/controls/menu/menu_host.h ('k') | ui/views/controls/menu/menu_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698