[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / new_tab_button.mm
blob7c4d70de198d53a263f24fdf1ba61693d0cfe7db
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
11 // -mouseEntered.
12 @interface NewTabButtonCell : ImageButtonCell
14 - (void)mouseEntered:(NSEvent*)theEvent;
16 @end
18 @implementation NewTabButtonCell
20 - (void)mouseEntered:(NSEvent*)theEvent {
21   // Ignore this since the NTB enter is handled by the TabStripController.
24 @end
27 @implementation NewTabButton
29 + (Class)cellClass {
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();
37   NSImage* buttonMask =
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
45                          context:nil
46                            hints:nil
47                          flipped:YES];
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];
55   return nil;
58 @end