Commit 0fe34285 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

MacViews: don't trigger a context menu from right command key

The right command key shares a key code with the windows context menu
key. For key event purposes, we don't want to collapse it together
with the left command key in case users have remapped it.

Instead, disable the entire keyboard context menu code path, since
neither of those shortcuts should work on Mac.

Bug: 827618
Change-Id: I05123bde9cd43cf5ba01aaf33d406d8300cbe27b
Reviewed-on: https://chromium-review.googlesource.com/988392
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547818}
parent 9da33553
......@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "build/build_config.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/dragdrop/drag_drop_types.h"
......@@ -73,7 +74,8 @@ class PreEventDispatchHandler : public ui::EventHandler {
View* v = NULL;
if (owner_->GetFocusManager()) // Can be NULL in unittests.
v = owner_->GetFocusManager()->GetFocusedView();
// macOS doesn't have keyboard-triggered context menus.
#if !defined(OS_MACOSX)
// Special case to handle keyboard-triggered context menus.
if (v && v->enabled() && ((event->key_code() == ui::VKEY_APPS) ||
(event->key_code() == ui::VKEY_F10 && event->IsShiftDown()))) {
......@@ -88,6 +90,7 @@ class PreEventDispatchHandler : public ui::EventHandler {
v->ShowContextMenu(location, ui::MENU_SOURCE_KEYBOARD);
event->StopPropagation();
}
#endif
}
View* owner_;
......
......@@ -6,6 +6,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "build/build_config.h"
#include "ui/events/event_utils.h"
#include "ui/views/context_menu_controller.h"
#include "ui/views/test/views_test_base.h"
......@@ -111,6 +112,10 @@ class TestContextMenuController : public ContextMenuController {
// Tests that context menus are shown for certain key events (Shift+F10
// and VKEY_APPS) by the pre-target handler installed on RootView.
TEST_F(RootViewTest, ContextMenuFromKeyEvent) {
#if defined(OS_MACOSX)
// This behavior is intentionally unsupported on macOS.
return;
#endif
Widget widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_POPUP);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment