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

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

Issue 140353002: [rAC, OSX] Fix focus ring drawing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/image_button_cell.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/image_button_cell.h" 5 #import "chrome/browser/ui/cocoa/image_button_cell.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "chrome/browser/themes/theme_service.h" 8 #import "chrome/browser/themes/theme_service.h"
9 #import "chrome/browser/ui/cocoa/nsview_additions.h" 9 #import "chrome/browser/ui/cocoa/nsview_additions.h"
10 #import "chrome/browser/ui/cocoa/rect_path_utils.h" 10 #import "chrome/browser/ui/cocoa/rect_path_utils.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 [self setShowsBorderOnlyWhileMouseInside:YES]; 52 [self setShowsBorderOnlyWhileMouseInside:YES];
53 } 53 }
54 54
55 - (NSImage*)imageForState:(image_button_cell::ButtonState)state 55 - (NSImage*)imageForState:(image_button_cell::ButtonState)state
56 view:(NSView*)controlView{ 56 view:(NSView*)controlView{
57 if (image_[state].imageId) 57 if (image_[state].imageId)
58 return [self imageForID:image_[state].imageId controlView:controlView]; 58 return [self imageForID:image_[state].imageId controlView:controlView];
59 return image_[state].image; 59 return image_[state].image;
60 } 60 }
61 61
62 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 62 - (void)drawImageWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
63 image_button_cell::ButtonState state = [self currentButtonState]; 63 image_button_cell::ButtonState state = [self currentButtonState];
64 BOOL windowHasFocus = [[controlView window] isMainWindow] || 64 BOOL windowHasFocus = [[controlView window] isMainWindow] ||
65 [[controlView window] isKeyWindow]; 65 [[controlView window] isKeyWindow];
66 CGFloat alpha = [self imageAlphaForWindowState:[controlView window]]; 66 CGFloat alpha = [self imageAlphaForWindowState:[controlView window]];
67 NSImage* image = [self imageForState:state view:controlView]; 67 NSImage* image = [self imageForState:state view:controlView];
68 68
69 if (!windowHasFocus) { 69 if (!windowHasFocus) {
70 NSImage* defaultImage = [self 70 NSImage* defaultImage = [self
71 imageForState:image_button_cell::kDefaultStateBackground 71 imageForState:image_button_cell::kDefaultStateBackground
72 view:controlView]; 72 view:controlView];
(...skipping 17 matching lines...) Expand all
90 roundf((NSWidth(cellFrame) - NSWidth(imageRect)) / 2.0); 90 roundf((NSWidth(cellFrame) - NSWidth(imageRect)) / 2.0);
91 imageRect.origin.y = cellFrame.origin.y + 91 imageRect.origin.y = cellFrame.origin.y +
92 roundf((NSHeight(cellFrame) - NSHeight(imageRect)) / 2.0); 92 roundf((NSHeight(cellFrame) - NSHeight(imageRect)) / 2.0);
93 93
94 [image drawInRect:imageRect 94 [image drawInRect:imageRect
95 fromRect:NSZeroRect 95 fromRect:NSZeroRect
96 operation:NSCompositeSourceOver 96 operation:NSCompositeSourceOver
97 fraction:alpha 97 fraction:alpha
98 respectFlipped:YES 98 respectFlipped:YES
99 hints:nil]; 99 hints:nil];
100 }
100 101
101 [self drawFocusRingWithFrame:cellFrame inView:controlView]; 102 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
103 [self drawImageWithFrame:cellFrame inView:controlView];
104 // Only draw custom focus ring if the 10.7 focus ring APIs are not available.
Nico 2014/01/16 00:53:09 Why? Who calls this on 10.7+?
groby-ooo-7-16 2014/01/16 01:05:51 10.7+ automatically draws a focus ring using drawF
105 // TODO(groby): Remove once we build against the 10.7 SDK.
106 if (![self respondsToSelector:@selector(drawFocusRingMaskWithFrame:inView:)])
107 [self drawFocusRingWithFrame:cellFrame inView:controlView];
102 } 108 }
103 109
104 - (void)setImageID:(NSInteger)imageID 110 - (void)setImageID:(NSInteger)imageID
105 forButtonState:(image_button_cell::ButtonState)state { 111 forButtonState:(image_button_cell::ButtonState)state {
106 DCHECK_GE(state, 0); 112 DCHECK_GE(state, 0);
107 DCHECK_LT(state, image_button_cell::kButtonStateCount); 113 DCHECK_LT(state, image_button_cell::kButtonStateCount);
108 114
109 image_[state].image.reset(); 115 image_[state].image.reset();
110 image_[state].imageId = imageID; 116 image_[state].imageId = imageID;
111 [[self controlView] setNeedsDisplay:YES]; 117 [[self controlView] setNeedsDisplay:YES];
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 198
193 - (void)mouseEntered:(NSEvent*)theEvent { 199 - (void)mouseEntered:(NSEvent*)theEvent {
194 [self setIsMouseInside:YES]; 200 [self setIsMouseInside:YES];
195 } 201 }
196 202
197 - (void)mouseExited:(NSEvent*)theEvent { 203 - (void)mouseExited:(NSEvent*)theEvent {
198 [self setIsMouseInside:NO]; 204 [self setIsMouseInside:NO];
199 } 205 }
200 206
201 @end 207 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/image_button_cell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698