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

Side by Side Diff: ui/views/controls/menu/menu_controller.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: Test Fix 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_controller.h" 5 #include "ui/views/controls/menu/menu_controller.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 MenuItemView* MenuController::Run(Widget* parent, 287 MenuItemView* MenuController::Run(Widget* parent,
288 MenuButton* button, 288 MenuButton* button,
289 MenuItemView* root, 289 MenuItemView* root,
290 const gfx::Rect& bounds, 290 const gfx::Rect& bounds,
291 MenuAnchorPosition position, 291 MenuAnchorPosition position,
292 bool context_menu, 292 bool context_menu,
293 int* result_event_flags) { 293 int* result_event_flags) {
294 exit_type_ = EXIT_NONE; 294 exit_type_ = EXIT_NONE;
295 possible_drag_ = false; 295 possible_drag_ = false;
296 drag_in_progress_ = false; 296 drag_in_progress_ = false;
297 did_initiate_drag_ = false;
297 closing_event_time_ = base::TimeDelta(); 298 closing_event_time_ = base::TimeDelta();
298 menu_start_time_ = base::TimeTicks::Now(); 299 menu_start_time_ = base::TimeTicks::Now();
299 menu_start_mouse_press_loc_ = gfx::Point(); 300 menu_start_mouse_press_loc_ = gfx::Point();
300 301
301 // If we are shown on mouse press, we will eat the subsequent mouse down and 302 // If we are shown on mouse press, we will eat the subsequent mouse down and
302 // the parent widget will not be able to reset its state (it might have mouse 303 // the parent widget will not be able to reset its state (it might have mouse
303 // capture from the mouse down). So we clear its state here. 304 // capture from the mouse down). So we clear its state here.
304 if (parent) { 305 if (parent) {
305 View* root_view = parent->GetRootView(); 306 View* root_view = parent->GetRootView();
306 if (root_view) { 307 if (root_view) {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 776
776 StopCancelAllTimer(); 777 StopCancelAllTimer();
777 } 778 }
778 779
779 void MenuController::OnDragExitedScrollButton(SubmenuView* source) { 780 void MenuController::OnDragExitedScrollButton(SubmenuView* source) {
780 StartCancelAllTimer(); 781 StartCancelAllTimer();
781 SetDropMenuItem(NULL, MenuDelegate::DROP_NONE); 782 SetDropMenuItem(NULL, MenuDelegate::DROP_NONE);
782 StopScrolling(); 783 StopScrolling();
783 } 784 }
784 785
786 void MenuController::OnDragWillStart() {
787 DCHECK(!drag_in_progress_);
788 drag_in_progress_ = true;
789 }
790
791 void MenuController::OnDragComplete(bool should_close) {
792 DCHECK(drag_in_progress_);
793 drag_in_progress_ = false;
794 if (showing_ && should_close && GetActiveInstance() == this) {
795 CloseAllNestedMenus();
796 Cancel(EXIT_ALL);
797 }
798 }
799
785 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) { 800 void MenuController::UpdateSubmenuSelection(SubmenuView* submenu) {
786 if (submenu->IsShowing()) { 801 if (submenu->IsShowing()) {
787 gfx::Point point = GetScreen()->GetCursorScreenPoint(); 802 gfx::Point point = GetScreen()->GetCursorScreenPoint();
788 const SubmenuView* root_submenu = 803 const SubmenuView* root_submenu =
789 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu(); 804 submenu->GetMenuItem()->GetRootMenuItem()->GetSubmenu();
790 View::ConvertPointFromScreen( 805 View::ConvertPointFromScreen(
791 root_submenu->GetWidget()->GetRootView(), &point); 806 root_submenu->GetWidget()->GetRootView(), &point);
792 HandleMouseLocation(submenu, point); 807 HandleMouseLocation(submenu, point);
793 } 808 }
794 } 809 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 source->GetWidget(), gfx::Size(item->width(), item->height()))); 978 source->GetWidget(), gfx::Size(item->width(), item->height())));
964 item->PaintButton(canvas.get(), MenuItemView::PB_FOR_DRAG); 979 item->PaintButton(canvas.get(), MenuItemView::PB_FOR_DRAG);
965 980
966 OSExchangeData data; 981 OSExchangeData data;
967 item->GetDelegate()->WriteDragData(item, &data); 982 item->GetDelegate()->WriteDragData(item, &data);
968 drag_utils::SetDragImageOnDataObject(*canvas, 983 drag_utils::SetDragImageOnDataObject(*canvas,
969 press_loc.OffsetFromOrigin(), 984 press_loc.OffsetFromOrigin(),
970 &data); 985 &data);
971 StopScrolling(); 986 StopScrolling();
972 int drag_ops = item->GetDelegate()->GetDragOperations(item); 987 int drag_ops = item->GetDelegate()->GetDragOperations(item);
973 drag_in_progress_ = true; 988 did_initiate_drag_ = true;
974 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below. 989 // TODO(varunjain): Properly determine and send DRAG_EVENT_SOURCE below.
975 item->GetWidget()->RunShellDrag(NULL, data, widget_loc, drag_ops, 990 item->GetWidget()->RunShellDrag(NULL, data, widget_loc, drag_ops,
976 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE); 991 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE);
977 drag_in_progress_ = false; 992 did_initiate_drag_ = false;
978
979 if (GetActiveInstance() == this) {
980 if (showing_) {
981 // We're still showing, close all menus.
982 CloseAllNestedMenus();
983 Cancel(EXIT_ALL);
984 } // else case, drop was on us.
985 } // else case, someone canceled us, don't do anything
986 } 993 }
987 994
988 bool MenuController::OnKeyDown(ui::KeyboardCode key_code) { 995 bool MenuController::OnKeyDown(ui::KeyboardCode key_code) {
989 DCHECK(blocking_run_); 996 DCHECK(blocking_run_);
990 997
991 switch (key_code) { 998 switch (key_code) {
992 case ui::VKEY_UP: 999 case ui::VKEY_UP:
993 IncrementSelection(-1); 1000 IncrementSelection(-1);
994 break; 1001 break;
995 1002
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 showing_(false), 1071 showing_(false),
1065 exit_type_(EXIT_NONE), 1072 exit_type_(EXIT_NONE),
1066 did_capture_(false), 1073 did_capture_(false),
1067 result_(NULL), 1074 result_(NULL),
1068 accept_event_flags_(0), 1075 accept_event_flags_(0),
1069 drop_target_(NULL), 1076 drop_target_(NULL),
1070 drop_position_(MenuDelegate::DROP_UNKNOWN), 1077 drop_position_(MenuDelegate::DROP_UNKNOWN),
1071 owner_(NULL), 1078 owner_(NULL),
1072 possible_drag_(false), 1079 possible_drag_(false),
1073 drag_in_progress_(false), 1080 drag_in_progress_(false),
1081 did_initiate_drag_(false),
1074 valid_drop_coordinates_(false), 1082 valid_drop_coordinates_(false),
1075 last_drop_operation_(MenuDelegate::DROP_UNKNOWN), 1083 last_drop_operation_(MenuDelegate::DROP_UNKNOWN),
1076 showing_submenu_(false), 1084 showing_submenu_(false),
1077 menu_button_(NULL), 1085 menu_button_(NULL),
1078 active_mouse_view_id_(ViewStorage::GetInstance()->CreateStorageID()), 1086 active_mouse_view_id_(ViewStorage::GetInstance()->CreateStorageID()),
1079 delegate_(delegate), 1087 delegate_(delegate),
1080 message_loop_depth_(0), 1088 message_loop_depth_(0),
1081 menu_config_(theme), 1089 menu_config_(theme),
1082 closing_event_time_(base::TimeDelta()), 1090 closing_event_time_(base::TimeDelta()),
1083 menu_start_time_(base::TimeTicks()), 1091 menu_start_time_(base::TimeTicks()),
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 } 2299 }
2292 } 2300 }
2293 2301
2294 gfx::Screen* MenuController::GetScreen() { 2302 gfx::Screen* MenuController::GetScreen() {
2295 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL; 2303 Widget* root = owner_ ? owner_->GetTopLevelWidget() : NULL;
2296 return root ? gfx::Screen::GetScreenFor(root->GetNativeView()) 2304 return root ? gfx::Screen::GetScreenFor(root->GetNativeView())
2297 : gfx::Screen::GetNativeScreen(); 2305 : gfx::Screen::GetNativeScreen();
2298 } 2306 }
2299 2307
2300 } // namespace views 2308 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_controller.h ('k') | ui/views/controls/menu/menu_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698