summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 21:14:44 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 21:14:44 +0000
commit992edd121c5c1ccb7e4fe94cccd35a9500079637 (patch)
tree619d934cacda11c0d196d0391a541c4eb54d81c2 /chrome/browser
parent494656dcbf45201c79d1a9387f3e1ecfe0b6d2ad (diff)
downloadchromium_src-992edd121c5c1ccb7e4fe94cccd35a9500079637.zip
chromium_src-992edd121c5c1ccb7e4fe94cccd35a9500079637.tar.gz
chromium_src-992edd121c5c1ccb7e4fe94cccd35a9500079637.tar.bz2
Hung Renderer dialog should dismiss with "Wait" for Enter or Esc
HungRendererDialog.xib: made the "Wait" button's use Return as its normal key equivalent; changed the "Wait" button's class to MultiKeyEquivalentButton. BUG=21074 TEST=about:hang. Return, Enter, Esc, and Command-. (period) should all dismiss the Hung Renderer dialog with "Wait". Review URL: http://codereview.chromium.org/266026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28454 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/hung_renderer_controller.h7
-rw-r--r--chrome/browser/cocoa/hung_renderer_controller.mm12
-rw-r--r--chrome/browser/cocoa/multi_key_equivalent_button.h35
-rw-r--r--chrome/browser/cocoa/multi_key_equivalent_button.mm33
4 files changed, 83 insertions, 4 deletions
diff --git a/chrome/browser/cocoa/hung_renderer_controller.h b/chrome/browser/cocoa/hung_renderer_controller.h
index 593cf25..9b890c7 100644
--- a/chrome/browser/cocoa/hung_renderer_controller.h
+++ b/chrome/browser/cocoa/hung_renderer_controller.h
@@ -23,9 +23,12 @@
#import "base/cocoa_protocols_mac.h"
+@class MultiKeyEquivalentButton;
+class TabContents;
+
@interface HungRendererController : NSWindowController<NSTableViewDataSource> {
@private
- IBOutlet NSButton* waitButton_;
+ IBOutlet MultiKeyEquivalentButton* waitButton_;
IBOutlet NSButton* killButton_;
IBOutlet NSTableView* tableView_;
IBOutlet NSImageView* imageView_;
@@ -63,7 +66,7 @@
@interface HungRendererController (JustForTesting)
- (NSButton*)killButton;
-- (NSButton*)waitButton;
+- (MultiKeyEquivalentButton*)waitButton;
@end
#endif // CHROME_BROWSER_COCOA_HUNG_RENDERER_CONTROLLER_H_
diff --git a/chrome/browser/cocoa/hung_renderer_controller.mm b/chrome/browser/cocoa/hung_renderer_controller.mm
index 54c4c9d..8967389 100644
--- a/chrome/browser/cocoa/hung_renderer_controller.mm
+++ b/chrome/browser/cocoa/hung_renderer_controller.mm
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#import "chrome/browser/cocoa/hung_renderer_controller.h"
+
#import <Cocoa/Cocoa.h>
#include "app/resource_bundle.h"
@@ -11,7 +13,7 @@
#include "base/sys_string_conversions.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/hung_renderer_dialog.h"
-#import "chrome/browser/cocoa/hung_renderer_controller.h"
+#import "chrome/browser/cocoa/multi_key_equivalent_button.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/result_codes.h"
@@ -63,6 +65,12 @@ HungRendererController* g_instance = NULL;
[GTMUILocalizerAndLayoutTweaker
resizeWindowWithoutAutoResizingSubViews:[self window]
delta:windowDelta];
+
+ // Make the "wait" button respond to additional keys. By setting this to
+ // @"\e", it will respond to both Esc and Command-. (period).
+ KeyEquivalentAndModifierMask key;
+ key.charCode = @"\e";
+ [waitButton_ addKeyEquivalent:key];
}
- (IBAction)kill:(id)sender {
@@ -135,7 +143,7 @@ HungRendererController* g_instance = NULL;
return killButton_;
}
-- (NSButton*)waitButton {
+- (MultiKeyEquivalentButton*)waitButton {
return waitButton_;
}
@end
diff --git a/chrome/browser/cocoa/multi_key_equivalent_button.h b/chrome/browser/cocoa/multi_key_equivalent_button.h
new file mode 100644
index 0000000..4d2c3b6
--- /dev/null
+++ b/chrome/browser/cocoa/multi_key_equivalent_button.h
@@ -0,0 +1,35 @@
+// 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_COCOA_MULTI_KEY_EQUIVALENT_BUTTON_H_
+#define CHROME_BROWSER_COCOA_MULTI_KEY_EQUIVALENT_BUTTON_H_
+
+#import <AppKit/AppKit.h>
+
+#include <vector>
+
+struct KeyEquivalentAndModifierMask {
+ public:
+ KeyEquivalentAndModifierMask() : charCode(nil), mask(0) {}
+ NSString* charCode;
+ NSUInteger mask;
+};
+
+// MultiKeyEquivalentButton is an NSButton subclass that is capable of
+// responding to additional key equivalents. It will respond to the ordinary
+// NSButton key equivalent set by -setKeyEquivalent: and
+// -setKeyEquivalentModifierMask:, and it will also respond to any additional
+// equivalents provided to it in a KeyEquivalentAndModifierMask structure
+// passed to -addKeyEquivalent:.
+
+@interface MultiKeyEquivalentButton : NSButton {
+ @private
+ std::vector<KeyEquivalentAndModifierMask> extraKeys_;
+}
+
+- (void)addKeyEquivalent:(KeyEquivalentAndModifierMask)key;
+
+@end
+
+#endif // CHROME_BROWSER_COCOA_MULTI_KEY_EQUIVALENT_BUTTON_H_
diff --git a/chrome/browser/cocoa/multi_key_equivalent_button.mm b/chrome/browser/cocoa/multi_key_equivalent_button.mm
new file mode 100644
index 0000000..fc10160
--- /dev/null
+++ b/chrome/browser/cocoa/multi_key_equivalent_button.mm
@@ -0,0 +1,33 @@
+// 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.
+
+#import "chrome/browser/cocoa/multi_key_equivalent_button.h"
+
+@implementation MultiKeyEquivalentButton
+
+- (void)addKeyEquivalent:(KeyEquivalentAndModifierMask)key {
+ extraKeys_.push_back(key);
+}
+
+- (BOOL)performKeyEquivalent:(NSEvent*)event {
+ NSWindow* modalWindow = [NSApp modalWindow];
+ NSWindow* window = [self window];
+
+ if ([self isEnabled] &&
+ (!modalWindow || modalWindow == window || [window worksWhenModal])) {
+ for (size_t index = 0; index < extraKeys_.size(); ++index) {
+ KeyEquivalentAndModifierMask key = extraKeys_[index];
+ if (key.charCode &&
+ [key.charCode isEqualToString:[event charactersIgnoringModifiers]] &&
+ ([event modifierFlags] & key.mask) == key.mask) {
+ [self performClick:self];
+ return YES;
+ }
+ }
+ }
+
+ return [super performKeyEquivalent:event];
+}
+
+@end