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

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

Issue 12529012: Context menu on views must show on mouse down for non-WIN. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 7 years, 8 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_controller.cc
diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc
index 9b8db7d1eeaf232ac804ec3e8974bcc1733f4c1f..c035f6fab3462acf82f7083d5f50e9784a939779 100644
--- a/ui/views/controls/menu/menu_controller.cc
+++ b/ui/views/controls/menu/menu_controller.cc
@@ -57,6 +57,11 @@ namespace views {
namespace {
+// When showing context menu on mouse down, the user might accidentally select
+// the menu item on the subsequent mouse up. To prevent this, we add the
+// following delay before the user is able to select an item.
+static int g_context_menu_selection_hold_time_ms = 200;
sky 2013/04/05 19:41:36 This isn't global. I think you want context_menu_s
varunjain 2013/04/05 21:58:42 Done.
+
// The spacing offset for the bubble tip.
const int kBubbleTipSizeLeftRight = 12;
const int kBubbleTipSizeTopBottom = 11;
@@ -286,6 +291,13 @@ MenuItemView* MenuController::Run(Widget* parent,
possible_drag_ = false;
drag_in_progress_ = false;
closing_event_time_ = base::TimeDelta();
+ menu_start_time_ = base::TimeTicks::Now();
+
+ // If we are shown on mouse press, we will eat the subsequent mouse down and
+ // the parent widget will not be able to reset its state (it might have mouse
+ // capture from the mouse down). So we clear its state here.
+ if (parent && parent->GetRootView())
+ parent->GetRootView()->SetMouseHandler(NULL);
bool nested_menu = showing_;
if (showing_) {
@@ -496,7 +508,11 @@ void MenuController::OnMouseReleased(SubmenuView* source,
}
if (!part.menu->NonIconChildViewsCount() &&
part.menu->GetDelegate()->IsTriggerableEvent(part.menu, event)) {
- Accept(part.menu, event.flags());
+ int64 time_since_menu_start =
+ (base::TimeTicks::Now() - menu_start_time_).InMilliseconds();
+ if (!state_.context_menu || !View::ShouldShowContextMenuOnMousePress() ||
+ time_since_menu_start > g_context_menu_selection_hold_time_ms)
+ Accept(part.menu, event.flags());
return;
}
} else if (part.type == MenuPart::MENU_ITEM) {
@@ -732,6 +748,11 @@ void MenuController::OnWidgetDestroying(Widget* widget) {
owner_ = NULL;
}
+// static
+void MenuController::TurnOffContextMenuSelectionHoldForTest() {
+ g_context_menu_selection_hold_time_ms = -1;
+}
+
void MenuController::SetSelection(MenuItemView* menu_item,
int selection_types) {
size_t paths_differ_at = 0;
@@ -1093,7 +1114,8 @@ MenuController::MenuController(ui::NativeTheme* theme,
delegate_(delegate),
message_loop_depth_(0),
menu_config_(theme),
- closing_event_time_(base::TimeDelta()) {
+ closing_event_time_(base::TimeDelta()),
+ menu_start_time_(base::TimeTicks()) {
active_instance_ = this;
}

Powered by Google App Engine
This is Rietveld 408576698