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