summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/nibs/Panel.xib12
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.h2
-rw-r--r--chrome/browser/ui/cocoa/browser_window_cocoa.mm123
-rw-r--r--chrome/browser/ui/cocoa/browser_window_utils.h28
-rw-r--r--chrome/browser/ui/cocoa/browser_window_utils.mm121
-rw-r--r--chrome/browser/ui/panels/panel_browser_window_cocoa.mm21
-rw-r--r--chrome/chrome_browser.gypi2
7 files changed, 119 insertions, 190 deletions
diff --git a/chrome/app/nibs/Panel.xib b/chrome/app/nibs/Panel.xib
index f2a2561..b84b375 100644
--- a/chrome/app/nibs/Panel.xib
+++ b/chrome/app/nibs/Panel.xib
@@ -12,8 +12,8 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="1"/>
<integer value="6"/>
+ <integer value="1"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -45,7 +45,7 @@
<string key="NSWindowRect">{{196, 240}, {480, 270}}</string>
<int key="NSWTFlags">544736256</int>
<string key="NSWindowTitle">Window</string>
- <string key="NSWindowClass">ChromeEventProcessingWindow</string>
+ <string key="NSWindowClass">NSWindow</string>
<nil key="NSViewClass"/>
<string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
<object class="NSView" key="NSWindowView" id="1006">
@@ -205,14 +205,6 @@
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
- <string key="className">ChromeEventProcessingWindow</string>
- <string key="superclassName">NSWindow</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBUserSource</string>
- <string key="minorKey"/>
- </object>
- </object>
- <object class="IBPartialClassDescription">
<string key="className">FirstResponder</string>
<string key="superclassName">NSObject</string>
<object class="NSMutableDictionary" key="actions">
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h
index 255b1cf..327f409 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h
@@ -132,6 +132,8 @@ class BrowserWindowCocoa : public BrowserWindow,
virtual void DestroyBrowser();
private:
+ int GetCommandId(const NativeWebKeyboardEvent& event);
+ bool HandleKeyboardEventInternal(NSEvent* event);
NSWindow* window() const; // Accessor for the (current) |NSWindow|.
void UpdateSidebarForContents(TabContents* tab_contents);
diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
index 9ad67b9..c87c61a 100644
--- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm
@@ -11,6 +11,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/download/download_shelf.h"
+#include "chrome/browser/global_keyboard_shortcuts_mac.h"
#include "chrome/browser/page_info_window.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -20,7 +21,6 @@
#include "chrome/browser/ui/browser_list.h"
#import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
-#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
#import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
@@ -449,27 +449,130 @@ void BrowserWindowCocoa::ShowAppMenu() {
bool BrowserWindowCocoa::PreHandleKeyboardEvent(
const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
- if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
+ if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
return false;
- int id = [BrowserWindowUtils getCommandId:event];
+ DCHECK(event.os_event != NULL);
+ int id = GetCommandId(event);
if (id == -1)
return false;
- if (browser_->IsReservedCommandOrKey(id, event)) {
- return [BrowserWindowUtils handleKeyboardEvent:event.os_event
- inWindow:window()];
- }
+ if (browser_->IsReservedCommandOrKey(id, event))
+ return HandleKeyboardEventInternal(event.os_event);
- DCHECK(is_keyboard_shortcut);
+ DCHECK(is_keyboard_shortcut != NULL);
*is_keyboard_shortcut = true;
+
return false;
}
void BrowserWindowCocoa::HandleKeyboardEvent(
const NativeWebKeyboardEvent& event) {
- if ([BrowserWindowUtils shouldHandleKeyboardEvent:event])
- [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()];
+ if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
+ return;
+
+ DCHECK(event.os_event != NULL);
+ HandleKeyboardEventInternal(event.os_event);
+}
+
+@interface MenuWalker : NSObject
++ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
+ menu:(NSMenu*)menu;
+@end
+
+@implementation MenuWalker
++ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
+ menu:(NSMenu*)menu {
+ NSMenuItem* result = nil;
+
+ for (NSMenuItem *item in [menu itemArray]) {
+ NSMenu* submenu = [item submenu];
+ if (submenu) {
+ if (submenu != [NSApp servicesMenu])
+ result = [self itemForKeyEquivalent:key
+ menu:submenu];
+ } else if ([item cr_firesForKeyEventIfEnabled:key]) {
+ result = item;
+ }
+
+ if (result)
+ break;
+ }
+
+ return result;
+}
+@end
+
+int BrowserWindowCocoa::GetCommandId(const NativeWebKeyboardEvent& event) {
+ if ([event.os_event type] != NSKeyDown)
+ return -1;
+
+ // Look in menu.
+ NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event
+ menu:[NSApp mainMenu]];
+
+ if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0)
+ return [item tag];
+
+ // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items
+ // that do not correspond to IDC_ constants need no special treatment however,
+ // as they can't be blacklisted in |Browser::IsReservedCommandOrKey()| anyhow.
+ if (item && [item action] == @selector(performClose:))
+ return IDC_CLOSE_WINDOW;
+
+ // "Exit" doesn't use the |commandDispatch:| mechanism either.
+ if (item && [item action] == @selector(terminate:))
+ return IDC_EXIT;
+
+ // Look in secondary keyboard shortcuts.
+ NSUInteger modifiers = [event.os_event modifierFlags];
+ const bool cmdKey = (modifiers & NSCommandKeyMask) != 0;
+ const bool shiftKey = (modifiers & NSShiftKeyMask) != 0;
+ const bool cntrlKey = (modifiers & NSControlKeyMask) != 0;
+ const bool optKey = (modifiers & NSAlternateKeyMask) != 0;
+ const int keyCode = [event.os_event keyCode];
+ const unichar keyChar = KeyCharacterForEvent(event.os_event);
+
+ int cmdNum = CommandForWindowKeyboardShortcut(
+ cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
+ if (cmdNum != -1)
+ return cmdNum;
+
+ cmdNum = CommandForBrowserKeyboardShortcut(
+ cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
+ if (cmdNum != -1)
+ return cmdNum;
+
+ return -1;
+}
+
+bool BrowserWindowCocoa::HandleKeyboardEventInternal(NSEvent* event) {
+ ChromeEventProcessingWindow* event_window =
+ static_cast<ChromeEventProcessingWindow*>(window());
+ DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
+
+ // Do not fire shortcuts on key up.
+ if ([event type] == NSKeyDown) {
+ // Send the event to the menu before sending it to the browser/window
+ // shortcut handling, so that if a user configures cmd-left to mean
+ // "previous tab", it takes precedence over the built-in "history back"
+ // binding. Other than that, the |-redispatchKeyEvent:| call would take care
+ // of invoking the original menu item shortcut as well.
+
+ 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])
+ return true;
+ }
+
+ return [event_window redispatchKeyEvent:event];
}
void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
diff --git a/chrome/browser/ui/cocoa/browser_window_utils.h b/chrome/browser/ui/cocoa/browser_window_utils.h
deleted file mode 100644
index 97d454f..0000000
--- a/chrome/browser/ui/cocoa/browser_window_utils.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2011 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_UI_COCOA_BROWSER_WINDOW_UTILS_H_
-#define CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_UTILS_H_
-#pragma once
-
-#import <Cocoa/Cocoa.h>
-
-class Browser;
-struct NativeWebKeyboardEvent;
-
-@interface BrowserWindowUtils : NSObject
-
-// Returns YES if keyboard event should be handled.
-+ (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event;
-
-// Determines the command associated with the keyboard event.
-// Returns -1 if no command found.
-+ (int)getCommandId:(const NativeWebKeyboardEvent&)event;
-
-// NSWindow must be a ChromeEventProcessingWindow.
-+ (BOOL)handleKeyboardEvent:(NSEvent*)event
- inWindow:(NSWindow*)window;
-@end
-
-#endif // CHROME_BROWSER_UI_COCOA_BROWSER_WINDOW_UTILS_H_
diff --git a/chrome/browser/ui/cocoa/browser_window_utils.mm b/chrome/browser/ui/cocoa/browser_window_utils.mm
deleted file mode 100644
index 6396a30..0000000
--- a/chrome/browser/ui/cocoa/browser_window_utils.mm
+++ /dev/null
@@ -1,121 +0,0 @@
-// Copyright (c) 2011 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/ui/cocoa/browser_window_utils.h"
-
-#include "base/logging.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/global_keyboard_shortcuts_mac.h"
-#include "chrome/browser/ui/browser.h"
-#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
-#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
-#include "content/common/native_web_keyboard_event.h"
-
-@interface MenuWalker : NSObject
-+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
- menu:(NSMenu*)menu;
-@end
-
-@implementation MenuWalker
-+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
- menu:(NSMenu*)menu {
- NSMenuItem* result = nil;
-
- for (NSMenuItem* item in [menu itemArray]) {
- NSMenu* submenu = [item submenu];
- if (submenu) {
- if (submenu != [NSApp servicesMenu])
- result = [self itemForKeyEquivalent:key
- menu:submenu];
- } else if ([item cr_firesForKeyEventIfEnabled:key]) {
- result = item;
- }
-
- if (result)
- break;
- }
-
- return result;
-}
-@end
-
-@implementation BrowserWindowUtils
-+ (BOOL)shouldHandleKeyboardEvent:(const NativeWebKeyboardEvent&)event {
- if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
- return NO;
- DCHECK(event.os_event != NULL);
- return YES;
-}
-
-+ (int)getCommandId:(const NativeWebKeyboardEvent&)event {
- if ([event.os_event type] != NSKeyDown)
- return -1;
-
- // Look in menu.
- NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event
- menu:[NSApp mainMenu]];
-
- // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items
- // that do not correspond to IDC_ constants need no special treatment however,
- // as they can't be blacklisted in |Browser::IsReservedCommandOrKey()| anyhow.
- if (item && [item action] == @selector(performClose:))
- return IDC_CLOSE_WINDOW;
-
- // "Exit" doesn't use the |commandDispatch:| mechanism either.
- if (item && [item action] == @selector(terminate:))
- return IDC_EXIT;
-
- // Look in secondary keyboard shortcuts.
- NSUInteger modifiers = [event.os_event modifierFlags];
- const bool cmdKey = (modifiers & NSCommandKeyMask) != 0;
- const bool shiftKey = (modifiers & NSShiftKeyMask) != 0;
- const bool cntrlKey = (modifiers & NSControlKeyMask) != 0;
- const bool optKey = (modifiers & NSAlternateKeyMask) != 0;
- const int keyCode = [event.os_event keyCode];
- const unichar keyChar = KeyCharacterForEvent(event.os_event);
-
- int cmdNum = CommandForWindowKeyboardShortcut(
- cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
- if (cmdNum != -1)
- return cmdNum;
-
- cmdNum = CommandForBrowserKeyboardShortcut(
- cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
- if (cmdNum != -1)
- return cmdNum;
-
- return -1;
-}
-
-+ (BOOL)handleKeyboardEvent:(NSEvent*)event
- inWindow:(NSWindow*)window {
- ChromeEventProcessingWindow* event_window =
- static_cast<ChromeEventProcessingWindow*>(window);
- DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
-
- // Do not fire shortcuts on key up.
- if ([event type] == NSKeyDown) {
- // Send the event to the menu before sending it to the browser/window
- // shortcut handling, so that if a user configures cmd-left to mean
- // "previous tab", it takes precedence over the built-in "history back"
- // binding. Other than that, the |-redispatchKeyEvent:| call would take care
- // of invoking the original menu item shortcut as well.
-
- 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])
- return true;
- }
-
- return [event_window redispatchKeyEvent:event];
-}
-
-@end
diff --git a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
index d3fba0d..3e7521f 100644
--- a/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
+++ b/chrome/browser/ui/panels/panel_browser_window_cocoa.mm
@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
-#import "chrome/browser/ui/cocoa/browser_window_utils.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/panel_manager.h"
#import "chrome/browser/ui/panels/panel_window_controller_cocoa.h"
@@ -157,29 +156,13 @@ bool PanelBrowserWindowCocoa::IsDrawingAttention() const {
bool PanelBrowserWindowCocoa::PreHandlePanelKeyboardEvent(
const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
- if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
- return false;
-
- int id = [BrowserWindowUtils getCommandId:event];
- if (id == -1)
- return false;
-
- if (browser()->IsReservedCommandOrKey(id, event)) {
- return [BrowserWindowUtils handleKeyboardEvent:event.os_event
- inWindow:GetNativePanelHandle()];
- }
-
- DCHECK(is_keyboard_shortcut);
- *is_keyboard_shortcut = true;
+ NOTIMPLEMENTED();
return false;
}
void PanelBrowserWindowCocoa::HandlePanelKeyboardEvent(
const NativeWebKeyboardEvent& event) {
- if ([BrowserWindowUtils shouldHandleKeyboardEvent:event]) {
- [BrowserWindowUtils handleKeyboardEvent:event.os_event
- inWindow:GetNativePanelHandle()];
- }
+ NOTIMPLEMENTED();
}
Browser* PanelBrowserWindowCocoa::GetPanelBrowser() const {
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 5e8829d..6a0d72f 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2361,8 +2361,6 @@
'browser/ui/cocoa/browser_window_controller_private.h',
'browser/ui/cocoa/browser_window_controller_private.mm',
'browser/ui/cocoa/browser_window_factory.mm',
- 'browser/ui/cocoa/browser_window_utils.h',
- 'browser/ui/cocoa/browser_window_utils.mm',
'browser/ui/cocoa/bubble_view.h',
'browser/ui/cocoa/bubble_view.mm',
'browser/ui/cocoa/bug_report_window_controller.h',