Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome/browser/ui/cocoa/new_tab_button.mm

Issue 1327203003: Mac: Fix missing focus rings on toolbar, profile, and tab buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2490
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/new_tab_button.h" 5 #import "chrome/browser/ui/cocoa/new_tab_button.h"
6 6
7 #import "chrome/browser/ui/cocoa/image_button_cell.h" 7 #import "chrome/browser/ui/cocoa/image_button_cell.h"
8 #include "grit/theme_resources.h" 8 #include "grit/theme_resources.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 10
11 namespace {
12
13 NSImage* GetMaskImage() {
14 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
15 return bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage();
16 }
17
18 }
19
11 // A simple override of the ImageButtonCell to disable handling of 20 // A simple override of the ImageButtonCell to disable handling of
12 // -mouseEntered. 21 // -mouseEntered.
13 @interface NewTabButtonCell : ImageButtonCell 22 @interface NewTabButtonCell : ImageButtonCell
14 23
15 - (void)mouseEntered:(NSEvent*)theEvent; 24 - (void)mouseEntered:(NSEvent*)theEvent;
16 25
17 @end 26 @end
18 27
19 @implementation NewTabButtonCell 28 @implementation NewTabButtonCell
20 29
21 - (void)mouseEntered:(NSEvent*)theEvent { 30 - (void)mouseEntered:(NSEvent*)theEvent {
22 // Ignore this since the NTB enter is handled by the TabStripController. 31 // Ignore this since the NTB enter is handled by the TabStripController.
23 } 32 }
24 33
34 - (void)drawFocusRingMaskWithFrame:(NSRect)cellFrame inView:(NSView*)view {
35 // Match the button's shape.
36 [self drawImage:GetMaskImage() withFrame:cellFrame inView:view];
37 }
38
25 @end 39 @end
26 40
27 41
28 @implementation NewTabButton 42 @implementation NewTabButton
29 43
30 + (Class)cellClass { 44 + (Class)cellClass {
31 return [NewTabButtonCell class]; 45 return [NewTabButtonCell class];
32 } 46 }
33 47
34 - (BOOL)pointIsOverButton:(NSPoint)point { 48 - (BOOL)pointIsOverButton:(NSPoint)point {
35 NSPoint localPoint = [self convertPoint:point fromView:[self superview]]; 49 NSPoint localPoint = [self convertPoint:point fromView:[self superview]];
36 NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1); 50 NSRect pointRect = NSMakeRect(localPoint.x, localPoint.y, 1, 1);
37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 51 NSImage* buttonMask = GetMaskImage();
38 NSImage* buttonMask =
39 bundle.GetNativeImageNamed(IDR_NEWTAB_BUTTON_MASK).ToNSImage();
40 NSRect destinationRect = NSMakeRect( 52 NSRect destinationRect = NSMakeRect(
41 (NSWidth(self.bounds) - [buttonMask size].width) / 2, 53 (NSWidth(self.bounds) - [buttonMask size].width) / 2,
42 (NSHeight(self.bounds) - [buttonMask size].height) / 2, 54 (NSHeight(self.bounds) - [buttonMask size].height) / 2,
43 [buttonMask size].width, [buttonMask size].height); 55 [buttonMask size].width, [buttonMask size].height);
44 return [buttonMask hitTestRect:pointRect 56 return [buttonMask hitTestRect:pointRect
45 withImageDestinationRect:destinationRect 57 withImageDestinationRect:destinationRect
46 context:nil 58 context:nil
47 hints:nil 59 hints:nil
48 flipped:YES]; 60 flipped:YES];
49 } 61 }
(...skipping 10 matching lines...) Expand all
60 72
61 - (void)windowDidChangeTheme { 73 - (void)windowDidChangeTheme {
62 [self setNeedsDisplay:YES]; 74 [self setNeedsDisplay:YES];
63 } 75 }
64 76
65 - (void)windowDidChangeActive { 77 - (void)windowDidChangeActive {
66 [self setNeedsDisplay:YES]; 78 [self setNeedsDisplay:YES];
67 } 79 }
68 80
69 @end 81 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/image_button_cell.mm ('k') | chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698