Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 47 // Called by |fadeOutAnimation_| when animated value changes. | 44 // Called by |fadeOutAnimation_| when animated value changes. |
| 48 - (void)setFadeOutValue:(CGFloat)value; | 45 - (void)setFadeOutValue:(CGFloat)value; |
| 49 | 46 |
| 50 // Gets the image for the given hover state. | 47 // Gets the image for the given hover state. |
| 51 - (NSImage*)imageForHoverState:(HoverState)hoverState; | 48 - (NSImage*)imageForHoverState:(HoverState)hoverState; |
| 52 | 49 |
| 53 @end | 50 @end |
| 54 | 51 |
| 55 @implementation HoverCloseButton | 52 @implementation HoverCloseButton |
| 56 | 53 |
| 54 @synthesize iconColor = iconColor_; | |
| 55 | |
| 57 + (void)initialize { | 56 + (void)initialize { |
| 58 // Grab some strings that are used by all close buttons. | 57 // Grab some strings that are used by all close buttons. |
| 59 if (!gBasicAccessibilityTitle) { | 58 if (!gBasicAccessibilityTitle) { |
| 60 gBasicAccessibilityTitle = [l10n_util::GetNSStringWithFixup( | 59 gBasicAccessibilityTitle = [l10n_util::GetNSStringWithFixup( |
| 61 IDS_ACCNAME_CLOSE) copy]; | 60 IDS_ACCNAME_CLOSE) copy]; |
| 62 } | 61 } |
| 63 if (!gTooltip) | 62 if (!gTooltip) |
| 64 gTooltip = [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_CLOSE_TAB) copy]; | 63 gTooltip = [l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_CLOSE_TAB) copy]; |
| 65 } | 64 } |
| 66 | 65 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 - (void)drawFocusRingMask { | 147 - (void)drawFocusRingMask { |
| 149 // Match the hover image's shape. | 148 // Match the hover image's shape. |
| 150 NSRect circleRect = NSInsetRect([self bounds], 2, 2); | 149 NSRect circleRect = NSInsetRect([self bounds], 2, 2); |
| 151 [[NSBezierPath bezierPathWithOvalInRect:circleRect] fill]; | 150 [[NSBezierPath bezierPathWithOvalInRect:circleRect] fill]; |
| 152 } | 151 } |
| 153 | 152 |
| 154 - (void)setFadeOutValue:(CGFloat)value { | 153 - (void)setFadeOutValue:(CGFloat)value { |
| 155 [self setNeedsDisplay]; | 154 [self setNeedsDisplay]; |
| 156 } | 155 } |
| 157 | 156 |
| 158 - (TabView *)tabView { | |
| 159 return base::mac::ObjCCast<TabView>([self superview]); | |
| 160 } | |
| 161 | |
| 162 - (NSImage*)imageForHoverState:(HoverState)hoverState { | 157 - (NSImage*)imageForHoverState:(HoverState)hoverState { |
| 163 const gfx::VectorIcon* vectorIcon = nullptr; | 158 const gfx::VectorIcon* vectorIcon = nullptr; |
| 164 SkColor vectorIconColor = gfx::kPlaceholderColor; | 159 SkColor vectorIconColor = gfx::kPlaceholderColor; |
| 165 TabView* tabView = [self tabView]; | |
| 166 | 160 |
| 167 switch (hoverState) { | 161 switch (hoverState) { |
| 168 case kHoverStateNone: | 162 case kHoverStateNone: |
| 169 vectorIcon = &kTabCloseNormalIcon; | 163 vectorIcon = &kTabCloseNormalIcon; |
| 170 vectorIconColor = | 164 vectorIconColor = iconColor_; |
| 171 tabView ? [tabView iconColor] : tabs::kDefaultTabTextColor; | |
| 172 break; | 165 break; |
| 173 case kHoverStateMouseOver: | 166 case kHoverStateMouseOver: |
| 174 // For mouse over, the icon color is the fill color of the circle. | 167 // For mouse over, the icon color is the fill color of the circle. |
| 175 vectorIcon = &kTabCloseHoveredPressedIcon; | 168 vectorIcon = &kTabCloseHoveredPressedIcon; |
| 176 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); | 169 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); |
| 177 break; | 170 break; |
| 178 case kHoverStateMouseDown: | 171 case kHoverStateMouseDown: |
| 179 // For mouse pressed, the icon color is the fill color of the circle. | 172 // For mouse pressed, the icon color is the fill color of the circle. |
| 180 vectorIcon = &kTabCloseHoveredPressedIcon; | 173 vectorIcon = &kTabCloseHoveredPressedIcon; |
| 181 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); | 174 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 210 } | 203 } |
| 211 | 204 |
| 212 - (void)commonInit { | 205 - (void)commonInit { |
| 213 [self setAccessibilityTitle:nil]; | 206 [self setAccessibilityTitle:nil]; |
| 214 | 207 |
| 215 // Add a tooltip. Using 'owner:self' means that | 208 // Add a tooltip. Using 'owner:self' means that |
| 216 // -view:stringForToolTip:point:userData: will be called to provide the | 209 // -view:stringForToolTip:point:userData: will be called to provide the |
| 217 // tooltip contents immediately before showing it. | 210 // tooltip contents immediately before showing it. |
| 218 [self addToolTipRect:[self bounds] owner:self userData:NULL]; | 211 [self addToolTipRect:[self bounds] owner:self userData:NULL]; |
| 219 | 212 |
| 220 // Initialize previousState. | |
| 221 previousState_ = kHoverStateNone; | 213 previousState_ = kHoverStateNone; |
| 214 iconColor_ = SkColorSetARGB(0xA0, 0x00, 0x00, 0x00); | |
|
spqchan
2017/02/02 17:36:44
nit: Hardcoded values should go into the namespace
Sidney San Martín
2017/02/02 18:58:14
Done.
| |
| 222 } | 215 } |
| 223 | 216 |
| 224 // Called each time a tooltip is about to be shown. | 217 // Called each time a tooltip is about to be shown. |
| 225 - (NSString*)view:(NSView*)view | 218 - (NSString*)view:(NSView*)view |
| 226 stringForToolTip:(NSToolTipTag)tag | 219 stringForToolTip:(NSToolTipTag)tag |
| 227 point:(NSPoint)point | 220 point:(NSPoint)point |
| 228 userData:(void*)userData { | 221 userData:(void*)userData { |
| 229 if (self.hoverState == kHoverStateMouseOver) { | 222 if (self.hoverState == kHoverStateMouseOver) { |
| 230 // In some cases (e.g. the download tray), the button is still in the | 223 // 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. | 224 // hover state, but is outside the bounds of its parent and not visible. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 244 [super setAccessibilityTitle:gBasicAccessibilityTitle]; | 237 [super setAccessibilityTitle:gBasicAccessibilityTitle]; |
| 245 return; | 238 return; |
| 246 } | 239 } |
| 247 | 240 |
| 248 NSString* extendedTitle = l10n_util::GetNSStringFWithFixup( | 241 NSString* extendedTitle = l10n_util::GetNSStringFWithFixup( |
| 249 IDS_ACCNAME_CLOSE_TAB, | 242 IDS_ACCNAME_CLOSE_TAB, |
| 250 base::SysNSStringToUTF16(accessibilityTitle)); | 243 base::SysNSStringToUTF16(accessibilityTitle)); |
| 251 [super setAccessibilityTitle:extendedTitle]; | 244 [super setAccessibilityTitle:extendedTitle]; |
| 252 } | 245 } |
| 253 | 246 |
| 247 - (void)setIconColor:(SkColor)iconColor { | |
| 248 if (iconColor != iconColor_) { | |
| 249 iconColor_ = iconColor; | |
| 250 [self setNeedsDisplay:YES]; | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 @end | 254 @end |
| 255 | 255 |
| 256 @implementation WebUIHoverCloseButton | 256 @implementation WebUIHoverCloseButton |
| 257 | 257 |
| 258 - (NSImage*)imageForHoverState:(HoverState)hoverState { | 258 - (NSImage*)imageForHoverState:(HoverState)hoverState { |
| 259 int imageID = IDR_CLOSE_DIALOG; | 259 int imageID = IDR_CLOSE_DIALOG; |
| 260 switch (hoverState) { | 260 switch (hoverState) { |
| 261 case kHoverStateNone: | 261 case kHoverStateNone: |
| 262 imageID = IDR_CLOSE_DIALOG; | 262 imageID = IDR_CLOSE_DIALOG; |
| 263 break; | 263 break; |
| 264 case kHoverStateMouseOver: | 264 case kHoverStateMouseOver: |
| 265 imageID = IDR_CLOSE_DIALOG_H; | 265 imageID = IDR_CLOSE_DIALOG_H; |
| 266 break; | 266 break; |
| 267 case kHoverStateMouseDown: | 267 case kHoverStateMouseDown: |
| 268 imageID = IDR_CLOSE_DIALOG_P; | 268 imageID = IDR_CLOSE_DIALOG_P; |
| 269 break; | 269 break; |
| 270 } | 270 } |
| 271 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 271 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 272 return bundle.GetNativeImageNamed(imageID).ToNSImage(); | 272 return bundle.GetNativeImageNamed(imageID).ToNSImage(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 @end | 275 @end |
| OLD | NEW |