| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/cocoa/new_tab_button.h" |
| 6 |
| 7 @implementation NewTabButton |
| 8 |
| 9 // Approximate the shape. It doesn't need to be perfect. This will need to be |
| 10 // updated if the size or shape of the icon ever changes. |
| 11 // TODO(pinkerton): use a click mask image instead of hard-coding points. |
| 12 - (NSBezierPath*)pathForButton { |
| 13 if (imagePath_.get()) |
| 14 return imagePath_.get(); |
| 15 |
| 16 // Cache the path as it doesn't change (the coordinates are local to this |
| 17 // view). There's not much point making constants for these, as they are |
| 18 // custom. |
| 19 imagePath_.reset([[NSBezierPath bezierPath] retain]); |
| 20 [imagePath_ moveToPoint:NSMakePoint(9, 7)]; |
| 21 [imagePath_ lineToPoint:NSMakePoint(26, 7)]; |
| 22 [imagePath_ lineToPoint:NSMakePoint(33, 23)]; |
| 23 [imagePath_ lineToPoint:NSMakePoint(14, 23)]; |
| 24 [imagePath_ lineToPoint:NSMakePoint(9, 7)]; |
| 25 return imagePath_; |
| 26 } |
| 27 |
| 28 // Override to only accept clicks within the bounds of the defined path, not |
| 29 // the entire bounding box. |aPoint| is in the superview's coordinate system. |
| 30 - (NSView*)hitTest:(NSPoint)aPoint { |
| 31 NSBezierPath* buttonPath = [self pathForButton]; |
| 32 NSPoint localPoint = [self convertPoint:aPoint fromView:[self superview]]; |
| 33 if ([buttonPath containsPoint:localPoint]) |
| 34 return [super hitTest:aPoint]; |
| 35 return nil; |
| 36 } |
| 37 |
| 38 @end |
| OLD | NEW |