Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3926)

Unified Diff: chrome/browser/cocoa/new_tab_button.mm

Issue 3046016: Restrict new tab button clicks to inside the image bounds, not anywhere in th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/new_tab_button.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/new_tab_button.mm
===================================================================
--- chrome/browser/cocoa/new_tab_button.mm (revision 0)
+++ chrome/browser/cocoa/new_tab_button.mm (revision 0)
@@ -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
Property changes on: chrome/browser/cocoa/new_tab_button.mm
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/cocoa/new_tab_button.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698