OLD | NEW |
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/rect_path_utils.h" | 9 #import "chrome/browser/ui/cocoa/rect_path_utils.h" |
10 #import "chrome/browser/ui/cocoa/themed_window.h" | 10 #import "chrome/browser/ui/cocoa/themed_window.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 image_[state].image.reset([image retain]); | 125 image_[state].image.reset([image retain]); |
126 image_[state].imageId = 0; | 126 image_[state].imageId = 0; |
127 [[self controlView] setNeedsDisplay:YES]; | 127 [[self controlView] setNeedsDisplay:YES]; |
128 } | 128 } |
129 | 129 |
130 - (CGFloat)imageAlphaForWindowState:(NSWindow*)window { | 130 - (CGFloat)imageAlphaForWindowState:(NSWindow*)window { |
131 BOOL windowHasFocus = [window isMainWindow] || [window isKeyWindow]; | 131 BOOL windowHasFocus = [window isMainWindow] || [window isKeyWindow]; |
132 return windowHasFocus ? 1.0 : kImageNoFocusAlpha; | 132 return windowHasFocus ? 1.0 : kImageNoFocusAlpha; |
133 } | 133 } |
134 | 134 |
| 135 - (ui::ThemeProvider*)themeProviderForWindow:(NSWindow*)window { |
| 136 return [window themeProvider]; |
| 137 } |
| 138 |
135 - (void)drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 139 - (void)drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
136 if (![self showsFirstResponder]) | 140 if (![self showsFirstResponder]) |
137 return; | 141 return; |
138 gfx::ScopedNSGraphicsContextSaveGState scoped_state; | 142 gfx::ScopedNSGraphicsContextSaveGState scoped_state; |
139 const CGFloat lineWidth = [controlView cr_lineWidth]; | 143 const CGFloat lineWidth = [controlView cr_lineWidth]; |
140 rect_path_utils::FrameRectWithInset(rect_path_utils::RoundedCornerAll, | 144 rect_path_utils::FrameRectWithInset(rect_path_utils::RoundedCornerAll, |
141 NSInsetRect(cellFrame, 0, lineWidth), | 145 NSInsetRect(cellFrame, 0, lineWidth), |
142 0.0, // insetX | 146 0.0, // insetX |
143 0.0, // insetY | 147 0.0, // insetY |
144 3.0, // outerRadius | 148 3.0, // outerRadius |
(...skipping 14 matching lines...) Expand all Loading... |
159 if ([self isMouseInside] && has(image_button_cell::kHoverState)) | 163 if ([self isMouseInside] && has(image_button_cell::kHoverState)) |
160 return image_button_cell::kHoverState; | 164 return image_button_cell::kHoverState; |
161 return image_button_cell::kDefaultState; | 165 return image_button_cell::kDefaultState; |
162 } | 166 } |
163 | 167 |
164 - (NSImage*)imageForID:(NSInteger)imageID | 168 - (NSImage*)imageForID:(NSInteger)imageID |
165 controlView:(NSView*)controlView { | 169 controlView:(NSView*)controlView { |
166 if (!imageID) | 170 if (!imageID) |
167 return nil; | 171 return nil; |
168 | 172 |
169 ui::ThemeProvider* themeProvider = [[controlView window] themeProvider]; | 173 ui::ThemeProvider* themeProvider = |
| 174 [self themeProviderForWindow:[controlView window]]; |
170 if (!themeProvider) | 175 if (!themeProvider) |
171 return nil; | 176 return nil; |
172 | 177 |
173 return themeProvider->GetNSImageNamed(imageID); | 178 return themeProvider->GetNSImageNamed(imageID); |
174 } | 179 } |
175 | 180 |
176 - (void)setIsMouseInside:(BOOL)isMouseInside { | 181 - (void)setIsMouseInside:(BOOL)isMouseInside { |
177 if (isMouseInside_ != isMouseInside) { | 182 if (isMouseInside_ != isMouseInside) { |
178 isMouseInside_ = isMouseInside; | 183 isMouseInside_ = isMouseInside; |
179 NSView<ImageButton>* control = | 184 NSView<ImageButton>* control = |
(...skipping 17 matching lines...) Expand all Loading... |
197 | 202 |
198 - (void)mouseEntered:(NSEvent*)theEvent { | 203 - (void)mouseEntered:(NSEvent*)theEvent { |
199 [self setIsMouseInside:YES]; | 204 [self setIsMouseInside:YES]; |
200 } | 205 } |
201 | 206 |
202 - (void)mouseExited:(NSEvent*)theEvent { | 207 - (void)mouseExited:(NSEvent*)theEvent { |
203 [self setIsMouseInside:NO]; | 208 [self setIsMouseInside:NO]; |
204 } | 209 } |
205 | 210 |
206 @end | 211 @end |
OLD | NEW |