summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjackhou <jackhou@chromium.org>2015-07-29 20:11:18 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-30 03:11:48 +0000
commit06c25a9881b76f7e0b0ab27050d8c470fe9bdc2d (patch)
treeb8156b9a571eb68c33ab42f9a185292f8263a504 /chrome
parent1eb12db3dbd38d63376994a1d684bdbc858dcf2c (diff)
downloadchromium_src-06c25a9881b76f7e0b0ab27050d8c470fe9bdc2d.zip
chromium_src-06c25a9881b76f7e0b0ab27050d8c470fe9bdc2d.tar.gz
chromium_src-06c25a9881b76f7e0b0ab27050d8c470fe9bdc2d.tar.bz2
[Mac] Remove BrowserCommandExecutor protocol.
Only BrowserWindowController implements this. Other implementors just turn it into a no-op. ChromeEventProcessingWindow (CEPW) now simply checks whether it's a Browser window and executes the command. This is the first step to factor out keyboard shortcut handling in CEPW into a component that can be reused in Views as it removes one (of two) dependencies on -[NSWindow windowController], which cannot be used to implement browser-side behavior under Views. Added new browser_test for shortcuts in global_keyboard_shortcuts_mac. Some history: BrowserCommandExecutor was added in r30619 (6 years ago) to allow a non-browser window to execute browser commands, but became obsolete a month later in r32445 when HtmlDialogWindowController (now WebDialogWindowController) decided to ignore those commands instead. BUG=508438 Review URL: https://codereview.chromium.org/1250533003 Cr-Commit-Position: refs/heads/master@{#341062}
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/global_keyboard_shortcuts_mac.h4
-rw-r--r--chrome/browser/global_keyboard_shortcuts_mac.mm5
-rw-r--r--chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm45
-rw-r--r--chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h5
-rw-r--r--chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm4
-rw-r--r--chrome/browser/ui/cocoa/browser_command_executor.h15
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.h7
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller.mm6
-rw-r--r--chrome/browser/ui/cocoa/browser_window_utils.mm8
-rw-r--r--chrome/browser/ui/cocoa/chrome_event_processing_window.h17
-rw-r--r--chrome/browser/ui/cocoa/chrome_event_processing_window.mm168
-rw-r--r--chrome/browser/ui/cocoa/chrome_event_processing_window_unittest.mm103
-rw-r--r--chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm18
-rw-r--r--chrome/browser/ui/cocoa/web_dialog_window_controller.mm18
-rw-r--r--chrome/chrome_browser_ui.gypi1
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/chrome_tests_unit.gypi1
17 files changed, 146 insertions, 280 deletions
diff --git a/chrome/browser/global_keyboard_shortcuts_mac.h b/chrome/browser/global_keyboard_shortcuts_mac.h
index ab87ef9..b478005 100644
--- a/chrome/browser/global_keyboard_shortcuts_mac.h
+++ b/chrome/browser/global_keyboard_shortcuts_mac.h
@@ -5,8 +5,12 @@
#ifndef CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
#define CHROME_BROWSER_GLOBAL_KEYBOARD_SHORTCUTS_MAC_H_
+#include <Carbon/Carbon.h> // For unichar.
+
#include "base/basictypes.h"
+@class NSEvent;
+
struct KeyboardShortcutData {
bool command_key;
bool shift_key;
diff --git a/chrome/browser/global_keyboard_shortcuts_mac.mm b/chrome/browser/global_keyboard_shortcuts_mac.mm
index 9327213..d9bd18d 100644
--- a/chrome/browser/global_keyboard_shortcuts_mac.mm
+++ b/chrome/browser/global_keyboard_shortcuts_mac.mm
@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import <AppKit/AppKit.h>
-#include <Carbon/Carbon.h>
-
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
+#import <AppKit/AppKit.h>
+
#include "base/basictypes.h"
#include "base/logging.h"
#include "chrome/app/chrome_command_ids.h"
diff --git a/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm b/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm
new file mode 100644
index 0000000..3e6b7f2d
--- /dev/null
+++ b/chrome/browser/global_keyboard_shortcuts_mac_browsertest.mm
@@ -0,0 +1,45 @@
+// Copyright 2015 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.
+
+#import "chrome/browser/global_keyboard_shortcuts_mac.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/run_loop.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#import "ui/events/test/cocoa_test_event_utils.h"
+
+using cocoa_test_event_utils::SynthesizeKeyEvent;
+
+using GlobalKeyboardShortcutsTest = ExtensionBrowserTest;
+
+// Test that global keyboard shortcuts are handled by the native window.
+IN_PROC_BROWSER_TEST_F(GlobalKeyboardShortcutsTest, SwitchTabsMac) {
+ NSWindow* ns_window = browser()->window()->GetNativeWindow();
+ TabStripModel* tab_strip = browser()->tab_strip_model();
+
+ // Set up window with 2 tabs.
+ chrome::NewTab(browser());
+ EXPECT_EQ(2, tab_strip->count());
+ EXPECT_TRUE(tab_strip->IsTabSelected(1));
+
+ // Ctrl+Tab goes to the next tab, which loops back to the first tab.
+ [ns_window performKeyEquivalent:SynthesizeKeyEvent(
+ ns_window, true, ui::VKEY_TAB, NSControlKeyMask)];
+ EXPECT_TRUE(tab_strip->IsTabSelected(0));
+
+ // Cmd+2 goes to the second tab.
+ [ns_window performKeyEquivalent:SynthesizeKeyEvent(
+ ns_window, true, ui::VKEY_2, NSCommandKeyMask)];
+ EXPECT_TRUE(tab_strip->IsTabSelected(1));
+
+ // Cmd+{ goes to the previous tab.
+ [ns_window performKeyEquivalent:SynthesizeKeyEvent(
+ ns_window, true, ui::VKEY_OEM_4, NSShiftKeyMask | NSCommandKeyMask)];
+ EXPECT_TRUE(tab_strip->IsTabSelected(0));
+}
diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h
index 38b02c5..580ae0a 100644
--- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h
+++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.h
@@ -10,7 +10,6 @@
#include "base/mac/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
-#import "chrome/browser/ui/cocoa/browser_command_executor.h"
#include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/native_app_window.h"
@@ -26,9 +25,7 @@ class SkRegion;
// A window controller for a minimal window to host a web app view. Passes
// Objective-C notifications to the C++ bridge.
-@interface NativeAppWindowController : NSWindowController
- <NSWindowDelegate,
- BrowserCommandExecutor> {
+@interface NativeAppWindowController : NSWindowController<NSWindowDelegate> {
@private
NativeAppWindowCocoa* appWindow_; // Weak; owns self.
base::scoped_nsobject<NSView> titlebar_background_view_;
diff --git a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
index b9524d8..c7df9af 100644
--- a/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/apps/native_app_window_cocoa.mm
@@ -175,10 +175,6 @@ std::vector<gfx::Rect> CalculateNonDraggableRegions(
return proposedSize;
}
-- (void)executeCommand:(int)command {
- // No-op, swallow the event.
-}
-
- (BOOL)handledByExtensionCommand:(NSEvent*)event
priority:(ui::AcceleratorManager::HandlerPriority)priority {
if (appWindow_)
diff --git a/chrome/browser/ui/cocoa/browser_command_executor.h b/chrome/browser/ui/cocoa/browser_command_executor.h
deleted file mode 100644
index 4a76ff1..0000000
--- a/chrome/browser/ui/cocoa/browser_command_executor.h
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright (c) 2009 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.
-
-#ifndef CHROME_BROWSER_BROWSER_COMMAND_EXECUTOR_H_
-#define CHROME_BROWSER_BROWSER_COMMAND_EXECUTOR_H_
-
-// Defines a protocol for any object that can execute commands in the
-// context of some underlying browser object.
-@protocol BrowserCommandExecutor
-- (void)executeCommand:(int)command;
-@end
-
-#endif // CHROME_BROWSER_BROWSER_COMMAND_EXECUTOR_H_
-
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.h b/chrome/browser/ui/cocoa/browser_window_controller.h
index 93070f5..97a4bd0 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.h
+++ b/chrome/browser/ui/cocoa/browser_window_controller.h
@@ -17,7 +17,6 @@
#include "chrome/browser/translate/chrome_translate_client.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bubble_controller.h"
-#import "chrome/browser/ui/cocoa/browser_command_executor.h"
#import "chrome/browser/ui/cocoa/exclusive_access_bubble_window_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
@@ -61,7 +60,6 @@ class Command;
@interface BrowserWindowController :
TabWindowController<NSUserInterfaceValidations,
BookmarkBarControllerDelegate,
- BrowserCommandExecutor,
ViewResizer,
TabStripControllerDelegate> {
@private
@@ -315,11 +313,6 @@ class Command;
// The user changed the theme.
- (void)userChangedTheme;
-// Executes the command in the context of the current browser.
-// |command| is an integer value containing one of the constants defined in the
-// "chrome/app/chrome_command_ids.h" file.
-- (void)executeCommand:(int)command;
-
// Consults the Command Registry to see if this |event| needs to be handled as
// an extension command and returns YES if so (NO otherwise).
// Only extensions with the given |priority| are considered.
diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm
index 3f79c03..4be4668 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller.mm
@@ -1263,12 +1263,6 @@ using content::WebContents;
[NSApp currentEvent], modifierFlags));
}
-// Called when another part of the internal codebase needs to execute a
-// command.
-- (void)executeCommand:(int)command {
- chrome::ExecuteCommand(browser_.get(), command);
-}
-
- (BOOL)handledByExtensionCommand:(NSEvent*)event
priority:(ui::AcceleratorManager::HandlerPriority)priority {
return extension_keybinding_registry_->ProcessKeyEvent(
diff --git a/chrome/browser/ui/cocoa/browser_window_utils.mm b/chrome/browser/ui/cocoa/browser_window_utils.mm
index 60dd4d1..2a63941 100644
--- a/chrome/browser/ui/cocoa/browser_window_utils.mm
+++ b/chrome/browser/ui/cocoa/browser_window_utils.mm
@@ -45,13 +45,7 @@ using content::NativeWebKeyboardEvent;
if ([[NSApp mainMenu] performKeyEquivalent:event])
return true;
- if ([event_window handleExtraBrowserKeyboardShortcut:event])
- return true;
-
- if ([event_window handleExtraWindowKeyboardShortcut:event])
- return true;
-
- if ([event_window handleDelayedWindowKeyboardShortcut:event])
+ if ([event_window handleExtraKeyboardShortcut:event])
return true;
}
diff --git a/chrome/browser/ui/cocoa/chrome_event_processing_window.h b/chrome/browser/ui/cocoa/chrome_event_processing_window.h
index b9a20e9..0f6dfb1 100644
--- a/chrome/browser/ui/cocoa/chrome_event_processing_window.h
+++ b/chrome/browser/ui/cocoa/chrome_event_processing_window.h
@@ -26,19 +26,10 @@
// Returns |YES| if |event| has been handled.
- (BOOL)redispatchKeyEvent:(NSEvent*)event;
-// See global_keyboard_shortcuts_mac.h for details on the next two functions.
-
-// Checks if |event| is a window keyboard shortcut. If so, dispatches it to the
-// window controller's |executeCommand:| and returns |YES|.
-- (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event;
-
-// Checks if |event| is a delayed window keyboard shortcut. If so, dispatches
-// it to the window controller's |executeCommand:| and returns |YES|.
-- (BOOL)handleDelayedWindowKeyboardShortcut:(NSEvent*)event;
-
-// Checks if |event| is a browser keyboard shortcut. If so, dispatches it to the
-// window controller's |executeCommand:| and returns |YES|.
-- (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event;
+// Checks if |event| is a window, delayed window, or browser keyboard shortcut.
+// (See global_keyboard_shortcuts_mac.h for details). If so, execute the
+// associated command. Returns YES if the event was handled.
+- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event;
// Override, so we can handle global keyboard events.
- (BOOL)performKeyEquivalent:(NSEvent*)theEvent;
diff --git a/chrome/browser/ui/cocoa/chrome_event_processing_window.mm b/chrome/browser/ui/cocoa/chrome_event_processing_window.mm
index a493d84..4dd2c64 100644
--- a/chrome/browser/ui/cocoa/chrome_event_processing_window.mm
+++ b/chrome/browser/ui/cocoa/chrome_event_processing_window.mm
@@ -6,58 +6,105 @@
#include "base/logging.h"
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
-#import "chrome/browser/ui/cocoa/browser_command_executor.h"
+#include "chrome/browser/ui/browser_commands.h"
+#include "chrome/browser/ui/browser_finder.h"
#import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#import "content/public/browser/render_widget_host_view_mac_base.h"
-typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int, unichar);
-
-@interface ChromeEventProcessingWindow ()
-// Duplicate the given key event, but changing the associated window.
-- (NSEvent*)keyEventForWindow:(NSWindow*)window fromKeyEvent:(NSEvent*)event;
-@end
+namespace {
-@implementation ChromeEventProcessingWindow
+// Type of functions listed in global_keyboard_shortcuts_mac.h.
+typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int, unichar);
-- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event fromTable:
- (KeyToCommandMapper)commandForKeyboardShortcut {
+// If the event is for a Browser window, and the key combination has an
+// associated command, execute the command.
+bool HandleExtraKeyboardShortcut(
+ NSEvent* event,
+ NSWindow* window,
+ KeyToCommandMapper command_for_keyboard_shortcut) {
// Extract info from |event|.
NSUInteger modifers = [event modifierFlags];
- const bool cmdKey = modifers & NSCommandKeyMask;
- const bool shiftKey = modifers & NSShiftKeyMask;
- const bool cntrlKey = modifers & NSControlKeyMask;
- const bool optKey = modifers & NSAlternateKeyMask;
- const unichar keyCode = [event keyCode];
- const unichar keyChar = KeyCharacterForEvent(event);
-
- int cmdNum = commandForKeyboardShortcut(cmdKey, shiftKey, cntrlKey, optKey,
- keyCode, keyChar);
-
- if (cmdNum != -1) {
- id executor = [self delegate];
- // A bit of sanity.
- DCHECK([executor conformsToProtocol:@protocol(BrowserCommandExecutor)]);
- DCHECK([executor respondsToSelector:@selector(executeCommand:)]);
- [executor executeCommand:cmdNum];
- return YES;
- }
- return NO;
+ const bool command = modifers & NSCommandKeyMask;
+ const bool shift = modifers & NSShiftKeyMask;
+ const bool control = modifers & NSControlKeyMask;
+ const bool option = modifers & NSAlternateKeyMask;
+ const int key_code = [event keyCode];
+ const unichar key_char = KeyCharacterForEvent(event);
+
+ int cmd = command_for_keyboard_shortcut(command, shift, control, option,
+ key_code, key_char);
+
+ if (cmd == -1)
+ return false;
+
+ // Only handle event if this is a browser window.
+ Browser* browser = chrome::FindBrowserWithWindow(window);
+ if (!browser)
+ return false;
+
+ chrome::ExecuteCommand(browser, cmd);
+ return true;
}
-- (BOOL)handleExtraWindowKeyboardShortcut:(NSEvent*)event {
- return [self handleExtraKeyboardShortcut:event
- fromTable:CommandForWindowKeyboardShortcut];
+bool HandleExtraWindowKeyboardShortcut(NSEvent* event, NSWindow* window) {
+ return HandleExtraKeyboardShortcut(event, window,
+ CommandForWindowKeyboardShortcut);
}
-- (BOOL)handleDelayedWindowKeyboardShortcut:(NSEvent*)event {
- return [self handleExtraKeyboardShortcut:event
- fromTable:CommandForDelayedWindowKeyboardShortcut];
+bool HandleDelayedWindowKeyboardShortcut(NSEvent* event, NSWindow* window) {
+ return HandleExtraKeyboardShortcut(event, window,
+ CommandForDelayedWindowKeyboardShortcut);
}
-- (BOOL)handleExtraBrowserKeyboardShortcut:(NSEvent*)event {
- return [self handleExtraKeyboardShortcut:event
- fromTable:CommandForBrowserKeyboardShortcut];
+bool HandleExtraBrowserKeyboardShortcut(NSEvent* event, NSWindow* window) {
+ return HandleExtraKeyboardShortcut(event, window,
+ CommandForBrowserKeyboardShortcut);
+}
+
+// Duplicate the given key event, but changing the associated window.
+NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) {
+ NSEventType event_type = [event type];
+
+ // Convert the event's location from the original window's coordinates into
+ // our own.
+ NSPoint location = [event locationInWindow];
+ location = [[event window] convertBaseToScreen:location];
+ location = [window convertScreenToBase:location];
+
+ // Various things *only* apply to key down/up.
+ bool is_a_repeat = false;
+ NSString* characters = nil;
+ NSString* charactors_ignoring_modifiers = nil;
+ if (event_type == NSKeyDown || event_type == NSKeyUp) {
+ is_a_repeat = [event isARepeat];
+ characters = [event characters];
+ charactors_ignoring_modifiers = [event charactersIgnoringModifiers];
+ }
+
+ // This synthesis may be slightly imperfect: we provide nil for the context,
+ // since I (viettrungluu) am sceptical that putting in the original context
+ // (if one is given) is valid.
+ return [NSEvent keyEventWithType:event_type
+ location:location
+ modifierFlags:[event modifierFlags]
+ timestamp:[event timestamp]
+ windowNumber:[window windowNumber]
+ context:nil
+ characters:characters
+ charactersIgnoringModifiers:charactors_ignoring_modifiers
+ isARepeat:is_a_repeat
+ keyCode:[event keyCode]];
+}
+
+} // namespace
+
+@implementation ChromeEventProcessingWindow
+
+- (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event {
+ return HandleExtraBrowserKeyboardShortcut(event, self) ||
+ HandleExtraWindowKeyboardShortcut(event, self) ||
+ HandleDelayedWindowKeyboardShortcut(event, self);
}
- (BOOL)performKeyEquivalent:(NSEvent*)event {
@@ -86,15 +133,10 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int, unichar);
if ([r conformsToProtocol:@protocol(RenderWidgetHostViewMacBase)])
return [r performKeyEquivalent:event];
- // If the delegate does not implement the BrowserCommandExecutor protocol,
- // then we don't need to handle browser specific shortcut keys.
- if (![[self delegate] conformsToProtocol:@protocol(BrowserCommandExecutor)])
- return [super performKeyEquivalent:event];
-
// Handle per-window shortcuts like cmd-1, but do not handle browser-level
// shortcuts like cmd-left (else, cmd-left would do history navigation even
// if e.g. the Omnibox has focus).
- if ([self handleExtraWindowKeyboardShortcut:event])
+ if (HandleExtraWindowKeyboardShortcut(event, self))
return YES;
if ([super performKeyEquivalent:event])
@@ -102,7 +144,7 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int, unichar);
// Handle per-window shortcuts like Esc after giving everybody else a chance
// to handle them
- return [self handleDelayedWindowKeyboardShortcut:event];
+ return HandleDelayedWindowKeyboardShortcut(event, self);
}
- (BOOL)redispatchKeyEvent:(NSEvent*)event {
@@ -122,7 +164,7 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int, unichar);
// rare case, we synthesize a new key event so that its associate window
// (number) is our own.
if ([event window] != self)
- event = [self keyEventForWindow:self fromKeyEvent:event];
+ event = KeyEventForWindow(self, event);
// Redispatch the event.
eventHandled_ = YES;
@@ -143,38 +185,4 @@ typedef int (*KeyToCommandMapper)(bool, bool, bool, bool, int, unichar);
eventHandled_ = NO;
}
-- (NSEvent*)keyEventForWindow:(NSWindow*)window fromKeyEvent:(NSEvent*)event {
- NSEventType eventType = [event type];
-
- // Convert the event's location from the original window's coordinates into
- // our own.
- NSPoint eventLoc = [event locationInWindow];
- eventLoc = [[event window] convertBaseToScreen:eventLoc];
- eventLoc = [self convertScreenToBase:eventLoc];
-
- // Various things *only* apply to key down/up.
- BOOL eventIsARepeat = NO;
- NSString* eventCharacters = nil;
- NSString* eventUnmodCharacters = nil;
- if (eventType == NSKeyDown || eventType == NSKeyUp) {
- eventIsARepeat = [event isARepeat];
- eventCharacters = [event characters];
- eventUnmodCharacters = [event charactersIgnoringModifiers];
- }
-
- // This synthesis may be slightly imperfect: we provide nil for the context,
- // since I (viettrungluu) am sceptical that putting in the original context
- // (if one is given) is valid.
- return [NSEvent keyEventWithType:eventType
- location:eventLoc
- modifierFlags:[event modifierFlags]
- timestamp:[event timestamp]
- windowNumber:[window windowNumber]
- context:nil
- characters:eventCharacters
- charactersIgnoringModifiers:eventUnmodCharacters
- isARepeat:eventIsARepeat
- keyCode:[event keyCode]];
-}
-
@end // ChromeEventProcessingWindow
diff --git a/chrome/browser/ui/cocoa/chrome_event_processing_window_unittest.mm b/chrome/browser/ui/cocoa/chrome_event_processing_window_unittest.mm
deleted file mode 100644
index 00b4df1..0000000
--- a/chrome/browser/ui/cocoa/chrome_event_processing_window_unittest.mm
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2012 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 <Carbon/Carbon.h>
-
-#include "base/debug/debugger.h"
-#include "chrome/app/chrome_command_ids.h"
-#import "chrome/browser/ui/cocoa/browser_window_controller.h"
-#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
-#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
-#import "third_party/ocmock/OCMock/OCMock.h"
-#include "third_party/ocmock/gtest_support.h"
-#import "third_party/ocmock/ocmock_extensions.h"
-
-namespace {
-
-NSEvent* KeyEvent(const NSUInteger flags, const NSUInteger keyCode) {
- return [NSEvent keyEventWithType:NSKeyDown
- location:NSZeroPoint
- modifierFlags:flags
- timestamp:0.0
- windowNumber:0
- context:nil
- characters:@""
- charactersIgnoringModifiers:@""
- isARepeat:NO
- keyCode:keyCode];
-}
-
-class ChromeEventProcessingWindowTest : public CocoaTest {
- public:
- void SetUp() override {
- CocoaTest::SetUp();
- // Create a window.
- const NSUInteger mask = NSTitledWindowMask | NSClosableWindowMask |
- NSMiniaturizableWindowMask | NSResizableWindowMask;
- window_ = [[ChromeEventProcessingWindow alloc]
- initWithContentRect:NSMakeRect(0, 0, 800, 600)
- styleMask:mask
- backing:NSBackingStoreBuffered
- defer:NO];
- if (base::debug::BeingDebugged()) {
- [window_ orderFront:nil];
- } else {
- [window_ orderBack:nil];
- }
- }
-
- void TearDown() override {
- [window_ close];
- CocoaTest::TearDown();
- }
-
- ChromeEventProcessingWindow* window_;
-};
-
-id CreateBrowserWindowControllerMock() {
- id delegate = [OCMockObject mockForClass:[BrowserWindowController class]];
- // Make conformsToProtocol return YES for @protocol(BrowserCommandExecutor)
- // to satisfy the DCHECK() in handleExtraKeyboardShortcut.
- [[[delegate stub] andReturnBool:YES]
- conformsToProtocol:[OCMArg conformsToProtocol:
- @protocol(BrowserCommandExecutor)]];
- return delegate;
-}
-
-// Verify that the window intercepts a particular key event and
-// forwards it to [delegate executeCommand:]. Assume that other
-// CommandForKeyboardShortcut() will work the same for the rest.
-TEST_F(ChromeEventProcessingWindowTest,
- PerformKeyEquivalentForwardToExecuteCommand) {
- NSEvent* event = KeyEvent(NSCommandKeyMask, kVK_ANSI_1);
-
- id delegate = CreateBrowserWindowControllerMock();
- [[delegate expect] executeCommand:IDC_SELECT_TAB_0];
-
- [window_ setDelegate:delegate];
- [window_ performKeyEquivalent:event];
-
- // Don't wish to mock all the way down...
- [window_ setDelegate:nil];
- EXPECT_OCMOCK_VERIFY(delegate);
-}
-
-// Verify that an unhandled shortcut does not get forwarded via
-// -executeCommand:.
-// TODO(shess) Think of a way to test that it is sent to the
-// superclass.
-TEST_F(ChromeEventProcessingWindowTest, PerformKeyEquivalentNoForward) {
- NSEvent* event = KeyEvent(0, 0);
-
- id delegate = CreateBrowserWindowControllerMock();
-
- [window_ setDelegate:delegate];
- [window_ performKeyEquivalent:event];
-
- // Don't wish to mock all the way down...
- [window_ setDelegate:nil];
- EXPECT_OCMOCK_VERIFY(delegate);
-}
-
-} // namespace
diff --git a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
index 7815bdc..de94948 100644
--- a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
+++ b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
@@ -16,7 +16,6 @@
#include "chrome/app/chrome_command_ids.h" // IDC_*
#include "chrome/browser/chrome_browser_application_mac.h"
#include "chrome/browser/profiles/profile.h"
-#import "chrome/browser/ui/cocoa/browser_command_executor.h"
#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#import "chrome/browser/ui/cocoa/panels/mouse_drag_controller.h"
#import "chrome/browser/ui/cocoa/panels/panel_cocoa.h"
@@ -149,23 +148,6 @@ const double kWidthOfMouseResizeArea = 15.0;
}
@end
-// ChromeEventProcessingWindow expects its controller to implement the
-// BrowserCommandExecutor protocol.
-@interface PanelWindowControllerCocoa (InternalAPI) <BrowserCommandExecutor>
-
-// BrowserCommandExecutor methods.
-- (void)executeCommand:(int)command;
-
-@end
-
-@implementation PanelWindowControllerCocoa (InternalAPI)
-
-// This gets called whenever a browser-specific keyboard shortcut is performed
-// in the Panel window. We simply swallow all those events.
-- (void)executeCommand:(int)command {}
-
-@end
-
@implementation PanelWindowControllerCocoa
- (id)initWithPanel:(PanelCocoa*)window {
diff --git a/chrome/browser/ui/cocoa/web_dialog_window_controller.mm b/chrome/browser/ui/cocoa/web_dialog_window_controller.mm
index 6e3e2a9..1180f95 100644
--- a/chrome/browser/ui/cocoa/web_dialog_window_controller.mm
+++ b/chrome/browser/ui/cocoa/web_dialog_window_controller.mm
@@ -8,7 +8,6 @@
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#import "chrome/browser/ui/browser_dialogs.h"
-#import "chrome/browser/ui/cocoa/browser_command_executor.h"
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
#include "content/public/browser/native_web_keyboard_event.h"
@@ -85,15 +84,6 @@ private:
DISALLOW_COPY_AND_ASSIGN(WebDialogWindowDelegateBridge);
};
-// ChromeEventProcessingWindow expects its controller to implement the
-// BrowserCommandExecutor protocol.
-@interface WebDialogWindowController (InternalAPI) <BrowserCommandExecutor>
-
-// BrowserCommandExecutor methods.
-- (void)executeCommand:(int)command;
-
-@end
-
namespace chrome {
gfx::NativeWindow ShowWebDialog(gfx::NativeView parent,
@@ -281,14 +271,6 @@ void WebDialogWindowDelegateBridge::HandleKeyboardEvent(
[event_window redispatchKeyEvent:event.os_event];
}
-@implementation WebDialogWindowController (InternalAPI)
-
-// This gets called whenever a chrome-specific keyboard shortcut is performed
-// in the Web dialog window. We simply swallow all those events.
-- (void)executeCommand:(int)command {}
-
-@end
-
@implementation WebDialogWindowController
// NOTE(akalin): We'll probably have to add the parentWindow parameter back
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 8d5580c..7bd9e4b 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -881,7 +881,6 @@
'browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.mm',
'browser/ui/cocoa/browser/zoom_bubble_controller.h',
'browser/ui/cocoa/browser/zoom_bubble_controller.mm',
- 'browser/ui/cocoa/browser_command_executor.h',
'browser/ui/cocoa/browser_window_cocoa.h',
'browser/ui/cocoa/browser_window_cocoa.mm',
'browser/ui/cocoa/browser_window_controller.h',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 943e5b3..e263909 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -294,6 +294,7 @@
'browser/first_run/try_chrome_dialog_view_browsertest.cc',
'browser/geolocation/access_token_store_browsertest.cc',
'browser/geolocation/geolocation_browsertest.cc',
+ 'browser/global_keyboard_shortcuts_mac_browsertest.mm',
'browser/history/history_browsertest.cc',
'browser/history/redirect_browsertest.cc',
'browser/iframe_browsertest.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index d0a6e33..e019c5b 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -367,7 +367,6 @@
'browser/ui/cocoa/browser_window_layout_unittest.mm',
'browser/ui/cocoa/bubble_view_unittest.mm',
'browser/ui/cocoa/chrome_browser_window_unittest.mm',
- 'browser/ui/cocoa/chrome_event_processing_window_unittest.mm',
'browser/ui/cocoa/clickhold_button_cell_unittest.mm',
'browser/ui/cocoa/cocoa_profile_test.h',
'browser/ui/cocoa/cocoa_profile_test.mm',