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