1 // Copyright (c) 2011 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.
5 #import "chrome/browser/ui/cocoa/new_tab_button.h"
7 #import "chrome/browser/ui/cocoa/image_button_cell.h"
8 #include "grit/theme_resources.h"
9 #include "ui/base/resource/resource_bundle.h"
11 // A simple override of the ImageButtonCell to disable handling of
13 @interface NewTabButtonCell : ImageButtonCell
15 - (void)mouseEntered:(NSEvent*)theEvent;
19 @implementation NewTabButtonCell
21 - (void)mouseEntered:(NSEvent*)theEvent {
22 // Ignore this since the NTB enter is handled by the TabStripController.
28 @implementation NewTabButton
31 return [NewTabButtonCell class];
34 - (BOOL)pointIsOverButton:(NSPoint)point {
35 NSPoint localPoint = [self convertPoint:point fromView:[self superview]];
36 NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1);
37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
39 bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage();
40 NSRect destinationRect = NSMakeRect(
41 (NSWidth(self.bounds) - [buttonMask size].width) / 2,
42 (NSHeight(self.bounds) - [buttonMask size].height) / 2,
43 [buttonMask size].width, [buttonMask size].height);
44 return [buttonMask hitTestRect:pointRect
45 withImageDestinationRect:destinationRect
51 // Override to only accept clicks within the bounds of the defined path, not
52 // the entire bounding box. |aPoint| is in the superview's coordinate system.
53 - (NSView*)hitTest:(NSPoint)aPoint {
54 if ([self pointIsOverButton:aPoint])
55 return [super hitTest:aPoint];
59 // ThemedWindowDrawing implementation.
61 - (void)windowDidChangeTheme {
62 [self setNeedsDisplay:YES];
65 - (void)windowDidChangeActive {
66 [self setNeedsDisplay:YES];