blob: 02fd53d2467b72876c998ebaf44211aedcc4e8b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "chrome/browser/ui/cocoa/new_tab_button.h"
#import "chrome/browser/ui/cocoa/image_button_cell.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
// A simple override of the ImageButtonCell to disable handling of
// -mouseEntered.
@interface NewTabButtonCell : ImageButtonCell
- (void)mouseEntered:(NSEvent*)theEvent;
@end
@implementation NewTabButtonCell
- (void)mouseEntered:(NSEvent*)theEvent {
// Ignore this since the NTB enter is handled by the TabStripController.
}
@end
@implementation NewTabButton
+ (Class)cellClass {
return [NewTabButtonCell class];
}
- (BOOL)pointIsOverButton:(NSPoint)point {
NSPoint localPoint = [self convertPoint:point fromView:[self superview]];
NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1);
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
NSImage* buttonMask =
bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage();
NSRect destinationRect = NSMakeRect(
(NSWidth(self.bounds) - [buttonMask size].width) / 2,
(NSHeight(self.bounds) - [buttonMask size].height) / 2,
[buttonMask size].width, [buttonMask size].height);
return [buttonMask hitTestRect:pointRect
withImageDestinationRect:destinationRect
context:nil
hints:nil
flipped:YES];
}
// Override to only accept clicks within the bounds of the defined path, not
// the entire bounding box. |aPoint| is in the superview's coordinate system.
- (NSView*)hitTest:(NSPoint)aPoint {
if ([self pointIsOverButton:aPoint])
return [super hitTest:aPoint];
return nil;
}
- (NSRect)focusRingMaskBounds {
// This override won't be needed once we link with 10.8+ SDK.
return [self bounds];
}
- (void)drawFocusRingMask {
// Match the button's shape.
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
NSImage* image =
bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage();
[ImageButtonCell drawImage:image inRect:[self bounds] alpha:1.0];
}
// ThemedWindowDrawing implementation.
- (void)windowDidChangeTheme {
[self setNeedsDisplay:YES];
}
- (void)windowDidChangeActive {
[self setNeedsDisplay:YES];
}
@end
|