summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-23 17:56:40 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-23 17:56:40 +0000
commitf9c1f09a66f96929bd1d75d7aceaf3d8146cb9b6 (patch)
tree70973e9237a824603b734f2cb75374c834c50c30 /chrome/browser/cocoa
parent2f3bc65c0d7abb88bc3f9c88d32625eceaa7f5bc (diff)
downloadchromium_src-f9c1f09a66f96929bd1d75d7aceaf3d8146cb9b6.zip
chromium_src-f9c1f09a66f96929bd1d75d7aceaf3d8146cb9b6.tar.gz
chromium_src-f9c1f09a66f96929bd1d75d7aceaf3d8146cb9b6.tar.bz2
Restrict new tab button clicks to inside the image bounds, not anywhere in the bounds of the button in the nib.
Nib change: Make the new tab button a subclass of NewTabButton instead of NSButton BUG=45738 TEST=clicking new tab button still works as expected. Review URL: http://codereview.chromium.org/3046016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/new_tab_button.h23
-rw-r--r--chrome/browser/cocoa/new_tab_button.mm38
2 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/new_tab_button.h b/chrome/browser/cocoa/new_tab_button.h
new file mode 100644
index 0000000..dddcf4c
--- /dev/null
+++ b/chrome/browser/cocoa/new_tab_button.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2010 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_NEW_TAB_BUTTON
+#define CHROME_BROWSER_COCOA_NEW_TAB_BUTTON
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/scoped_nsobject.h"
+
+// Overrides hit-test behavior to only accept clicks inside the image of the
+// button, not just inside the bounding box. This could be abstracted to general
+// use, but no other buttons are so irregularly shaped with respect to their
+// bounding box.
+
+@interface NewTabButton : NSButton {
+ @private
+ scoped_nsobject<NSBezierPath> imagePath_;
+}
+@end
+
+#endif // CHROME_BROWSER_COCOA_NEW_TAB_BUTTON
diff --git a/chrome/browser/cocoa/new_tab_button.mm b/chrome/browser/cocoa/new_tab_button.mm
new file mode 100644
index 0000000..c5e41df
--- /dev/null
+++ b/chrome/browser/cocoa/new_tab_button.mm
@@ -0,0 +1,38 @@
+// Copyright (c) 2010 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/new_tab_button.h"
+
+@implementation NewTabButton
+
+// Approximate the shape. It doesn't need to be perfect. This will need to be
+// updated if the size or shape of the icon ever changes.
+// TODO(pinkerton): use a click mask image instead of hard-coding points.
+- (NSBezierPath*)pathForButton {
+ if (imagePath_.get())
+ return imagePath_.get();
+
+ // Cache the path as it doesn't change (the coordinates are local to this
+ // view). There's not much point making constants for these, as they are
+ // custom.
+ imagePath_.reset([[NSBezierPath bezierPath] retain]);
+ [imagePath_ moveToPoint:NSMakePoint(9, 7)];
+ [imagePath_ lineToPoint:NSMakePoint(26, 7)];
+ [imagePath_ lineToPoint:NSMakePoint(33, 23)];
+ [imagePath_ lineToPoint:NSMakePoint(14, 23)];
+ [imagePath_ lineToPoint:NSMakePoint(9, 7)];
+ return imagePath_;
+}
+
+// Override to only accept clicks within the bounds of the defined path, not
+// the entire bounding box. |aPoint| is in the superview's coordinate system.
+- (NSView*)hitTest:(NSPoint)aPoint {
+ NSBezierPath* buttonPath = [self pathForButton];
+ NSPoint localPoint = [self convertPoint:aPoint fromView:[self superview]];
+ if ([buttonPath containsPoint:localPoint])
+ return [super hitTest:aPoint];
+ return nil;
+}
+
+@end