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

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

Issue 2668393003: Fix using theme colors for the download shelf's close button. (Closed)
Patch Set: Comment iconColor, move the default icon color into a constant. Created 3 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/hover_close_button.h" 5 #import "chrome/browser/ui/cocoa/hover_close_button.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/app/vector_icons/vector_icons.h" 9 #include "chrome/app/vector_icons/vector_icons.h"
10 #include "chrome/browser/themes/theme_properties.h"
11 #include "chrome/browser/themes/theme_service.h"
12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 10 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
13 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
14 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" 12 #import "chrome/browser/ui/cocoa/tabs/tab_view.h"
15 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
16 #include "chrome/grit/theme_resources.h"
17 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMKeyValueAnimation.h" 15 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMKeyValueAnimation.h"
19 #include "ui/base/cocoa/animation_utils.h" 16 #include "ui/base/cocoa/animation_utils.h"
20 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/material_design/material_design_controller.h" 18 #include "ui/base/material_design/material_design_controller.h"
22 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/color_palette.h" 20 #include "ui/gfx/color_palette.h"
24 #include "ui/gfx/image/image_skia_util_mac.h" 21 #include "ui/gfx/image/image_skia_util_mac.h"
25 #include "ui/gfx/paint_vector_icon.h" 22 #include "ui/gfx/paint_vector_icon.h"
26 #include "ui/resources/grit/ui_resources.h" 23 #include "ui/resources/grit/ui_resources.h"
27 24
28 namespace { 25 namespace {
29 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. 26 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good.
30 const CGFloat kCloseAnimationDuration = 0.1; 27 const CGFloat kCloseAnimationDuration = 0.1;
31 const int kTabCloseButtonSize = 16; 28 const int kTabCloseButtonSize = 16;
32 29
33 // Strings that are used for all close buttons. Set up in +initialize. 30 // Strings that are used for all close buttons. Set up in +initialize.
34 NSString* gBasicAccessibilityTitle = nil; 31 NSString* gBasicAccessibilityTitle = nil;
35 NSString* gTooltip = nil; 32 NSString* gTooltip = nil;
36 33
37 // If this string is changed, the setter (currently setFadeOutValue:) must 34 // If this string is changed, the setter (currently setFadeOutValue:) must
38 // be changed as well to match. 35 // be changed as well to match.
39 NSString* const kFadeOutValueKeyPath = @"fadeOutValue"; 36 NSString* const kFadeOutValueKeyPath = @"fadeOutValue";
37
38 const SkColor kDefaultIconColor = SkColorSetARGB(0xA0, 0x00, 0x00, 0x00);
40 } // namespace 39 } // namespace
41 40
42 @interface HoverCloseButton () 41 @interface HoverCloseButton ()
43 42
44 // Common initialization routine called from initWithFrame and awakeFromNib. 43 // Common initialization routine called from initWithFrame and awakeFromNib.
45 - (void)commonInit; 44 - (void)commonInit;
46 45
47 // Called by |fadeOutAnimation_| when animated value changes. 46 // Called by |fadeOutAnimation_| when animated value changes.
48 - (void)setFadeOutValue:(CGFloat)value; 47 - (void)setFadeOutValue:(CGFloat)value;
49 48
50 // Gets the image for the given hover state. 49 // Gets the image for the given hover state.
51 - (NSImage*)imageForHoverState:(HoverState)hoverState; 50 - (NSImage*)imageForHoverState:(HoverState)hoverState;
52 51
53 @end 52 @end
54 53
55 @implementation HoverCloseButton 54 @implementation HoverCloseButton
56 55
56 @synthesize iconColor = iconColor_;
57
57 + (void)initialize { 58 + (void)initialize {
58 // Grab some strings that are used by all close buttons. 59 // Grab some strings that are used by all close buttons.
59 if (!gBasicAccessibilityTitle) { 60 if (!gBasicAccessibilityTitle) {
60 gBasicAccessibilityTitle = [l10n_util::GetNSStringWithFixup( 61 gBasicAccessibilityTitle = [l10n_util::GetNSStringWithFixup(
61 IDS_ACCNAME_CLOSE) copy]; 62 IDS_ACCNAME_CLOSE) copy];
62 } 63 }
63 if (!gTooltip) 64 if (!gTooltip)
64 gTooltip = [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_CLOSE_TAB) copy]; 65 gTooltip = [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_CLOSE_TAB) copy];
65 } 66 }
66 67
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 - (void)drawFocusRingMask { 149 - (void)drawFocusRingMask {
149 // Match the hover image's shape. 150 // Match the hover image's shape.
150 NSRect circleRect = NSInsetRect([self bounds], 2, 2); 151 NSRect circleRect = NSInsetRect([self bounds], 2, 2);
151 [[NSBezierPath bezierPathWithOvalInRect:circleRect] fill]; 152 [[NSBezierPath bezierPathWithOvalInRect:circleRect] fill];
152 } 153 }
153 154
154 - (void)setFadeOutValue:(CGFloat)value { 155 - (void)setFadeOutValue:(CGFloat)value {
155 [self setNeedsDisplay]; 156 [self setNeedsDisplay];
156 } 157 }
157 158
158 - (TabView *)tabView {
159 return base::mac::ObjCCast<TabView>([self superview]);
160 }
161
162 - (NSImage*)imageForHoverState:(HoverState)hoverState { 159 - (NSImage*)imageForHoverState:(HoverState)hoverState {
163 const gfx::VectorIcon* vectorIcon = nullptr; 160 const gfx::VectorIcon* vectorIcon = nullptr;
164 SkColor vectorIconColor = gfx::kPlaceholderColor; 161 SkColor vectorIconColor = gfx::kPlaceholderColor;
165 TabView* tabView = [self tabView];
166 162
167 switch (hoverState) { 163 switch (hoverState) {
168 case kHoverStateNone: 164 case kHoverStateNone:
169 vectorIcon = &kTabCloseNormalIcon; 165 vectorIcon = &kTabCloseNormalIcon;
170 vectorIconColor = 166 vectorIconColor = iconColor_;
171 tabView ? [tabView iconColor] : tabs::kDefaultTabTextColor;
172 break; 167 break;
173 case kHoverStateMouseOver: 168 case kHoverStateMouseOver:
174 // For mouse over, the icon color is the fill color of the circle. 169 // For mouse over, the icon color is the fill color of the circle.
175 vectorIcon = &kTabCloseHoveredPressedIcon; 170 vectorIcon = &kTabCloseHoveredPressedIcon;
176 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); 171 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37);
177 break; 172 break;
178 case kHoverStateMouseDown: 173 case kHoverStateMouseDown:
179 // For mouse pressed, the icon color is the fill color of the circle. 174 // For mouse pressed, the icon color is the fill color of the circle.
180 vectorIcon = &kTabCloseHoveredPressedIcon; 175 vectorIcon = &kTabCloseHoveredPressedIcon;
181 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); 176 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A);
(...skipping 28 matching lines...) Expand all
210 } 205 }
211 206
212 - (void)commonInit { 207 - (void)commonInit {
213 [self setAccessibilityTitle:nil]; 208 [self setAccessibilityTitle:nil];
214 209
215 // Add a tooltip. Using 'owner:self' means that 210 // Add a tooltip. Using 'owner:self' means that
216 // -view:stringForToolTip:point:userData: will be called to provide the 211 // -view:stringForToolTip:point:userData: will be called to provide the
217 // tooltip contents immediately before showing it. 212 // tooltip contents immediately before showing it.
218 [self addToolTipRect:[self bounds] owner:self userData:NULL]; 213 [self addToolTipRect:[self bounds] owner:self userData:NULL];
219 214
220 // Initialize previousState.
221 previousState_ = kHoverStateNone; 215 previousState_ = kHoverStateNone;
216 iconColor_ = kDefaultIconColor;
222 } 217 }
223 218
224 // Called each time a tooltip is about to be shown. 219 // Called each time a tooltip is about to be shown.
225 - (NSString*)view:(NSView*)view 220 - (NSString*)view:(NSView*)view
226 stringForToolTip:(NSToolTipTag)tag 221 stringForToolTip:(NSToolTipTag)tag
227 point:(NSPoint)point 222 point:(NSPoint)point
228 userData:(void*)userData { 223 userData:(void*)userData {
229 if (self.hoverState == kHoverStateMouseOver) { 224 if (self.hoverState == kHoverStateMouseOver) {
230 // In some cases (e.g. the download tray), the button is still in the 225 // In some cases (e.g. the download tray), the button is still in the
231 // hover state, but is outside the bounds of its parent and not visible. 226 // hover state, but is outside the bounds of its parent and not visible.
(...skipping 12 matching lines...) Expand all
244 [super setAccessibilityTitle:gBasicAccessibilityTitle]; 239 [super setAccessibilityTitle:gBasicAccessibilityTitle];
245 return; 240 return;
246 } 241 }
247 242
248 NSString* extendedTitle = l10n_util::GetNSStringFWithFixup( 243 NSString* extendedTitle = l10n_util::GetNSStringFWithFixup(
249 IDS_ACCNAME_CLOSE_TAB, 244 IDS_ACCNAME_CLOSE_TAB,
250 base::SysNSStringToUTF16(accessibilityTitle)); 245 base::SysNSStringToUTF16(accessibilityTitle));
251 [super setAccessibilityTitle:extendedTitle]; 246 [super setAccessibilityTitle:extendedTitle];
252 } 247 }
253 248
249 - (void)setIconColor:(SkColor)iconColor {
250 if (iconColor != iconColor_) {
251 iconColor_ = iconColor;
252 [self setNeedsDisplay:YES];
253 }
254 }
255
254 @end 256 @end
255 257
256 @implementation WebUIHoverCloseButton 258 @implementation WebUIHoverCloseButton
257 259
258 - (NSImage*)imageForHoverState:(HoverState)hoverState { 260 - (NSImage*)imageForHoverState:(HoverState)hoverState {
259 int imageID = IDR_CLOSE_DIALOG; 261 int imageID = IDR_CLOSE_DIALOG;
260 switch (hoverState) { 262 switch (hoverState) {
261 case kHoverStateNone: 263 case kHoverStateNone:
262 imageID = IDR_CLOSE_DIALOG; 264 imageID = IDR_CLOSE_DIALOG;
263 break; 265 break;
264 case kHoverStateMouseOver: 266 case kHoverStateMouseOver:
265 imageID = IDR_CLOSE_DIALOG_H; 267 imageID = IDR_CLOSE_DIALOG_H;
266 break; 268 break;
267 case kHoverStateMouseDown: 269 case kHoverStateMouseDown:
268 imageID = IDR_CLOSE_DIALOG_P; 270 imageID = IDR_CLOSE_DIALOG_P;
269 break; 271 break;
270 } 272 }
271 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 273 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
272 return bundle.GetNativeImageNamed(imageID).ToNSImage(); 274 return bundle.GetNativeImageNamed(imageID).ToNSImage();
273 } 275 }
274 276
275 @end 277 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698