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/ui/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 - (BOOL)pointIsOverButton:(NSPoint)point { 29 NSPoint localPoint = [self convertPoint:point fromView:[self superview]]; 30 NSBezierPath* buttonPath = [self pathForButton]; 31 return [buttonPath containsPoint:localPoint]; 32 } 33 34 // Override to only accept clicks within the bounds of the defined path, not 35 // the entire bounding box. |aPoint| is in the superview's coordinate system. 36 - (NSView*)hitTest:(NSPoint)aPoint { 37 if ([self pointIsOverButton:aPoint]) 38 return [super hitTest:aPoint]; 39 return nil; 40 } 41 42 @end 43