Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / new_tab_button.mm
blobdbdd56ef6328f51f3348b5e8e9a778362d4e9537
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 namespace {
13 NSImage* GetMaskImage() {
14   ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
15   return bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage();
20 // A simple override of the ImageButtonCell to disable handling of
21 // -mouseEntered.
22 @interface NewTabButtonCell : ImageButtonCell
24 - (void)mouseEntered:(NSEvent*)theEvent;
26 @end
28 @implementation NewTabButtonCell
30 - (void)mouseEntered:(NSEvent*)theEvent {
31   // Ignore this since the NTB enter is handled by the TabStripController.
34 - (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame inView:(NSView*)view {
35   // Match the button's shape.
36   [self drawImage:GetMaskImage() withFrame:cellFrame inView:view];
39 @end
42 @implementation NewTabButton
44 + (Class)cellClass {
45   return [NewTabButtonCell class];
48 - (BOOL)pointIsOverButton:(NSPoint)point {
49   NSPoint localPoint = [self convertPoint:point fromView:[self superview]];
50   NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1);
51   NSImage* buttonMask = GetMaskImage();
52   NSRect destinationRect = NSMakeRect(
53       (NSWidth(self.bounds) - [buttonMask size].width) / 2,
54       (NSHeight(self.bounds) - [buttonMask size].height) / 2,
55       [buttonMask size].width, [buttonMask size].height);
56   return [buttonMask hitTestRect:pointRect
57         withImageDestinationRect:destinationRect
58                          context:nil
59                            hints:nil
60                          flipped:YES];
63 // Override to only accept clicks within the bounds of the defined path, not
64 // the entire bounding box. |aPoint| is in the superview's coordinate system.
65 - (NSView*)hitTest:(NSPoint)aPoint {
66   if ([self pointIsOverButton:aPoint])
67     return [super hitTest:aPoint];
68   return nil;
71 // ThemedWindowDrawing implementation.
73 - (void)windowDidChangeTheme {
74   [self setNeedsDisplay:YES];
77 - (void)windowDidChangeActive {
78   [self setNeedsDisplay:YES];
81 @end