Commit 58ccd174 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

polychrome: merge GetWindowKeyboardShortcutTable and friends

This change merges the separate Cocoa and Views implementations of these
functions into a single implementation that chooses the correct table at
runtime. This fixes GlobalKeyboardShortcutsTest.* in polychrome-cocoa, and
all but one of GlobalKeyboardShortcutsTest.* in polychrome-views.

Bug: 817408
Change-Id: I57e333ee2fcec2ac21fb2920a7d5794b774de204
Reviewed-on: https://chromium-review.googlesource.com/975583Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545136}
parent 97d35fae
...@@ -2993,12 +2993,6 @@ jumbo_split_static_library("browser") { ...@@ -2993,12 +2993,6 @@ jumbo_split_static_library("browser") {
"QuartzCore.framework", "QuartzCore.framework",
"SecurityInterface.framework", "SecurityInterface.framework",
] ]
if (mac_views_browser) {
sources += [ "global_keyboard_shortcuts_views_mac.mm" ]
} else {
sources += [ "global_keyboard_shortcuts_cocoa_mac.mm" ]
}
} }
if (is_linux) { if (is_linux) {
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
// Basically, there are two kinds of keyboard shortcuts: Ones that should work
// only if the tab contents is focused (BrowserKeyboardShortcut), and ones that
// should work in all other cases (WindowKeyboardShortcut). In the latter case,
// we differentiate between shortcuts that are checked before any other view
// gets the chance to handle them (WindowKeyboardShortcut) or after all views
// had a chance but did not handle the keypress event
// (DelayedWindowKeyboardShortcut).
const std::vector<KeyboardShortcutData>& GetWindowKeyboardShortcutTable() {
// clang-format off
CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
// '{' / '}' characters should be matched earlier than virtual key codes
// (so we can match alt-8 as '{' on German keyboards).
{true, false, false, false, 0, '}', IDC_SELECT_NEXT_TAB},
{true, false, false, false, 0, '{', IDC_SELECT_PREVIOUS_TAB},
{true, true, false, false, kVK_ANSI_RightBracket, 0, IDC_SELECT_NEXT_TAB},
{true, true, false, false, kVK_ANSI_LeftBracket, 0, IDC_SELECT_PREVIOUS_TAB},
{false, false, true, false, kVK_PageDown, 0, IDC_SELECT_NEXT_TAB},
{false, false, true, false, kVK_Tab, 0, IDC_SELECT_NEXT_TAB},
{false, false, true, false, kVK_PageUp, 0, IDC_SELECT_PREVIOUS_TAB},
{false, true, true, false, kVK_Tab, 0, IDC_SELECT_PREVIOUS_TAB},
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
// Cmd-0..8 select the nth tab, with cmd-9 being "last tab".
{true, false, false, false, kVK_ANSI_1, 0, IDC_SELECT_TAB_0},
{true, false, false, false, kVK_ANSI_Keypad1, 0, IDC_SELECT_TAB_0},
{true, false, false, false, kVK_ANSI_2, 0, IDC_SELECT_TAB_1},
{true, false, false, false, kVK_ANSI_Keypad2, 0, IDC_SELECT_TAB_1},
{true, false, false, false, kVK_ANSI_3, 0, IDC_SELECT_TAB_2},
{true, false, false, false, kVK_ANSI_Keypad3, 0, IDC_SELECT_TAB_2},
{true, false, false, false, kVK_ANSI_4, 0, IDC_SELECT_TAB_3},
{true, false, false, false, kVK_ANSI_Keypad4, 0, IDC_SELECT_TAB_3},
{true, false, false, false, kVK_ANSI_5, 0, IDC_SELECT_TAB_4},
{true, false, false, false, kVK_ANSI_Keypad5, 0, IDC_SELECT_TAB_4},
{true, false, false, false, kVK_ANSI_6, 0, IDC_SELECT_TAB_5},
{true, false, false, false, kVK_ANSI_Keypad6, 0, IDC_SELECT_TAB_5},
{true, false, false, false, kVK_ANSI_7, 0, IDC_SELECT_TAB_6},
{true, false, false, false, kVK_ANSI_Keypad7, 0, IDC_SELECT_TAB_6},
{true, false, false, false, kVK_ANSI_8, 0, IDC_SELECT_TAB_7},
{true, false, false, false, kVK_ANSI_Keypad8, 0, IDC_SELECT_TAB_7},
{true, false, false, false, kVK_ANSI_9, 0, IDC_SELECT_LAST_TAB},
{true, false, false, false, kVK_ANSI_Keypad9, 0, IDC_SELECT_LAST_TAB},
{true, true, false, false, kVK_ANSI_M, 0, IDC_SHOW_AVATAR_MENU},
{true, false, false, true, kVK_ANSI_L, 0, IDC_SHOW_DOWNLOADS},
}));
// clang-format on
return result;
}
const std::vector<KeyboardShortcutData>&
GetDelayedWindowKeyboardShortcutTable() {
// clang-format off
CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
{false, false, false, false, kVK_Escape, 0, IDC_STOP},
}));
// clang-format on
return result;
}
const std::vector<KeyboardShortcutData>& GetBrowserKeyboardShortcutTable() {
// clang-format off
CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
{true, false, false, false, kVK_LeftArrow, 0, IDC_BACK},
{true, false, false, false, kVK_RightArrow, 0, IDC_FORWARD},
{true, true, false, false, 0, 'c', IDC_DEV_TOOLS_INSPECT},
}));
// clang-format on
return result;
}
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
#import <AppKit/AppKit.h> #import <AppKit/AppKit.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/no_destructor.h"
#include "build/buildflag.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
#include "chrome/browser/ui/views_mode_controller.h"
namespace { namespace {
...@@ -91,8 +93,112 @@ int CommandForKeyboardShortcut(const std::vector<KeyboardShortcutData>& table, ...@@ -91,8 +93,112 @@ int CommandForKeyboardShortcut(const std::vector<KeyboardShortcutData>& table,
return -1; return -1;
} }
// Given a set of Views keyboard shortcuts and a set of Cocoa keyboard
// shortcuts, returns the appropriate set depending on which browser window is
// in use.
const std::vector<KeyboardShortcutData>& ViewsOrCocoaKeys(
const std::vector<KeyboardShortcutData>& views_keys,
const std::vector<KeyboardShortcutData>& cocoa_keys) {
#if BUILDFLAG(MAC_VIEWS_BROWSER)
if (!views_mode_controller::IsViewsBrowserCocoa())
return views_keys;
#endif
return cocoa_keys;
}
} // namespace } // namespace
// Basically, there are two kinds of keyboard shortcuts: Ones that should work
// only if the tab contents is focused (BrowserKeyboardShortcut), and ones that
// should work in all other cases (WindowKeyboardShortcut). In the latter case,
// we differentiate between shortcuts that are checked before any other view
// gets the chance to handle them (WindowKeyboardShortcut) or after all views
// had a chance but did not handle the keypress event
// (DelayedWindowKeyboardShortcut).
const std::vector<KeyboardShortcutData>& GetWindowKeyboardShortcutTable() {
// clang-format off
// Lists shortcuts that are impossible to migrate to accelerator_table.cc
// (https://crbug.com/25946). Most of the entries in cocoa_keys are already
// present in accelerator_table.cc, so for Views browser windows, those
// definitions are used.
static base::NoDestructor<std::vector<KeyboardShortcutData>> views_keys({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
// '{' / '}' characters should be matched earlier than virtual key codes
// (so we can match alt-8 as '{' on German keyboards).
{true, false, false, false, 0, '}', IDC_SELECT_NEXT_TAB},
{true, false, false, false, 0, '{', IDC_SELECT_PREVIOUS_TAB},
});
static base::NoDestructor<std::vector<KeyboardShortcutData>> cocoa_keys({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
// '{' / '}' characters should be matched earlier than virtual key codes
// (so we can match alt-8 as '{' on German keyboards).
{true, false, false, false, 0, '}', IDC_SELECT_NEXT_TAB},
{true, false, false, false, 0, '{', IDC_SELECT_PREVIOUS_TAB},
{true, true, false, false, kVK_ANSI_RightBracket, 0, IDC_SELECT_NEXT_TAB},
{true, true, false, false, kVK_ANSI_LeftBracket, 0, IDC_SELECT_PREVIOUS_TAB},
{false, false, true, false, kVK_PageDown, 0, IDC_SELECT_NEXT_TAB},
{false, false, true, false, kVK_Tab, 0, IDC_SELECT_NEXT_TAB},
{false, false, true, false, kVK_PageUp, 0, IDC_SELECT_PREVIOUS_TAB},
{false, true, true, false, kVK_Tab, 0, IDC_SELECT_PREVIOUS_TAB},
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
// Cmd-0..8 select the nth tab, with cmd-9 being "last tab".
{true, false, false, false, kVK_ANSI_1, 0, IDC_SELECT_TAB_0},
{true, false, false, false, kVK_ANSI_Keypad1, 0, IDC_SELECT_TAB_0},
{true, false, false, false, kVK_ANSI_2, 0, IDC_SELECT_TAB_1},
{true, false, false, false, kVK_ANSI_Keypad2, 0, IDC_SELECT_TAB_1},
{true, false, false, false, kVK_ANSI_3, 0, IDC_SELECT_TAB_2},
{true, false, false, false, kVK_ANSI_Keypad3, 0, IDC_SELECT_TAB_2},
{true, false, false, false, kVK_ANSI_4, 0, IDC_SELECT_TAB_3},
{true, false, false, false, kVK_ANSI_Keypad4, 0, IDC_SELECT_TAB_3},
{true, false, false, false, kVK_ANSI_5, 0, IDC_SELECT_TAB_4},
{true, false, false, false, kVK_ANSI_Keypad5, 0, IDC_SELECT_TAB_4},
{true, false, false, false, kVK_ANSI_6, 0, IDC_SELECT_TAB_5},
{true, false, false, false, kVK_ANSI_Keypad6, 0, IDC_SELECT_TAB_5},
{true, false, false, false, kVK_ANSI_7, 0, IDC_SELECT_TAB_6},
{true, false, false, false, kVK_ANSI_Keypad7, 0, IDC_SELECT_TAB_6},
{true, false, false, false, kVK_ANSI_8, 0, IDC_SELECT_TAB_7},
{true, false, false, false, kVK_ANSI_Keypad8, 0, IDC_SELECT_TAB_7},
{true, false, false, false, kVK_ANSI_9, 0, IDC_SELECT_LAST_TAB},
{true, false, false, false, kVK_ANSI_Keypad9, 0, IDC_SELECT_LAST_TAB},
{true, true, false, false, kVK_ANSI_M, 0, IDC_SHOW_AVATAR_MENU},
{true, false, false, true, kVK_ANSI_L, 0, IDC_SHOW_DOWNLOADS},
});
// clang-format on
return ViewsOrCocoaKeys(*views_keys, *cocoa_keys);
}
const std::vector<KeyboardShortcutData>&
GetDelayedWindowKeyboardShortcutTable() {
// clang-format off
static base::NoDestructor<std::vector<KeyboardShortcutData>> views_keys({});
static base::NoDestructor<std::vector<KeyboardShortcutData>> cocoa_keys({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
{false, false, false, false, kVK_Escape, 0, IDC_STOP},
});
// clang-format on
return ViewsOrCocoaKeys(*views_keys, *cocoa_keys);
}
const std::vector<KeyboardShortcutData>& GetBrowserKeyboardShortcutTable() {
// clang-format off
static base::NoDestructor<std::vector<KeyboardShortcutData>> views_keys({});
static base::NoDestructor<std::vector<KeyboardShortcutData>> cocoa_keys({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
{true, false, false, false, kVK_LeftArrow, 0, IDC_BACK},
{true, false, false, false, kVK_RightArrow, 0, IDC_FORWARD},
{true, true, false, false, 0, 'c', IDC_DEV_TOOLS_INSPECT},
});
// clang-format on
return ViewsOrCocoaKeys(*views_keys, *cocoa_keys);
}
int CommandForWindowKeyboardShortcut( int CommandForWindowKeyboardShortcut(
bool command_key, bool shift_key, bool cntrl_key, bool opt_key, bool command_key, bool shift_key, bool cntrl_key, bool opt_key,
int vkey_code, unichar key_char) { int vkey_code, unichar key_char) {
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/macros.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
// Lists shortcuts that are impossible to migrate to accelerator_table.cc
// (crbug.com/25946).
const std::vector<KeyboardShortcutData>& GetWindowKeyboardShortcutTable() {
// clang-format off
CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({
//cmd shift cntrl option vkeycode char command
//--- ----- ----- ------ -------- ---- -------
// '{' / '}' characters should be matched earlier than virtual key codes
// (so we can match alt-8 as '{' on German keyboards).
{true, false, false, false, 0, '}', IDC_SELECT_NEXT_TAB},
{true, false, false, false, 0, '{', IDC_SELECT_PREVIOUS_TAB},
}));
// clang-format on
return result;
}
const std::vector<KeyboardShortcutData>&
GetDelayedWindowKeyboardShortcutTable() {
CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({}));
return result;
}
const std::vector<KeyboardShortcutData>& GetBrowserKeyboardShortcutTable() {
CR_DEFINE_STATIC_LOCAL(std::vector<KeyboardShortcutData>, result, ({}));
return result;
}
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