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

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

Issue 378333003: Allow menus to stay open during a child view's drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 2716ec8bb782c1a46288c0ab449d80a2a96e2caf..40d874927d132779960df84136f8ae3d1ac7be32 100644
--- a/ui/views/controls/menu/menu_host.cc
+++ b/ui/views/controls/menu/menu_host.cc
@@ -135,4 +135,34 @@ void MenuHost::OnOwnerClosing() {
menu_controller->CancelAll();
}
+void MenuHost::OnDragWillStart() {
+ MenuController* menu_controller =
+ submenu_->GetMenuItem()->GetMenuController();
+ if (menu_controller)
sky 2014/07/14 15:19:05 The if should be a DCHECK
Devlin 2014/07/16 16:00:45 Done. For my own edification, why should it be DC
sky 2014/07/16 19:19:00 MenuHost may outlive MenuController, hence the nec
+ menu_controller->OnDragWillStart();
+}
+
+void MenuHost::OnDragComplete(View* dragged_view) {
+ MenuController* menu_controller =
+ submenu_->GetMenuItem()->GetMenuController();
+ if (destroying_ || !menu_controller)
+ return;
+
+ bool should_close = true;
+ // If the view came from outside menu code (i.e., not a MenuItemView), we
+ // should consult the MenuDelegate to determine whether or not to close on
+ // exit.
+ if (dragged_view && dragged_view->id() != MenuItemView::kMenuItemViewID) {
Devlin 2014/07/11 20:28:15 I think this should work for ensuring the delegate
sky 2014/07/14 15:19:05 It would be safer to make MenuController know it i
Devlin 2014/07/16 16:00:45 Done.
+ MenuDelegate* menu_delegate = submenu_->GetMenuItem()->GetDelegate();
+ should_close =
+ menu_delegate ? menu_delegate->ShouldCloseOnDragComplete() : should_close;
+ }
+ menu_controller->OnDragComplete(should_close);
+
+ // We may have lost capture in the drag and drop, but are remaining open.
+ // Return capture so we get MouseCaptureLost events.
+ if (!should_close)
+ native_widget_private()->SetCapture();
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698