| 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/browser/themes/theme_properties.h" | 10 #include "chrome/browser/themes/theme_properties.h" |
| 10 #include "chrome/browser/themes/theme_service.h" | 11 #include "chrome/browser/themes/theme_service.h" |
| 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 12 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 14 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 15 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
| 16 #include "components/strings/grit/components_strings.h" | 17 #include "components/strings/grit/components_strings.h" |
| 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMKeyValueAnimation.h" | 18 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMKeyValueAnimation.h" |
| 18 #include "ui/base/cocoa/animation_utils.h" | 19 #include "ui/base/cocoa/animation_utils.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/material_design/material_design_controller.h" | 21 #include "ui/base/material_design/material_design_controller.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
| 23 #include "ui/gfx/image/image_skia_util_mac.h" | 24 #include "ui/gfx/image/image_skia_util_mac.h" |
| 24 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
| 25 #include "ui/gfx/vector_icons_public.h" | |
| 26 #include "ui/resources/grit/ui_resources.h" | 26 #include "ui/resources/grit/ui_resources.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. | 29 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. |
| 30 const CGFloat kCloseAnimationDuration = 0.1; | 30 const CGFloat kCloseAnimationDuration = 0.1; |
| 31 const int kTabCloseButtonSize = 16; | 31 const int kTabCloseButtonSize = 16; |
| 32 | 32 |
| 33 // Strings that are used for all close buttons. Set up in +initialize. | 33 // Strings that are used for all close buttons. Set up in +initialize. |
| 34 NSString* gBasicAccessibilityTitle = nil; | 34 NSString* gBasicAccessibilityTitle = nil; |
| 35 NSString* gTooltip = nil; | 35 NSString* gTooltip = nil; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 - (void)setFadeOutValue:(CGFloat)value { | 154 - (void)setFadeOutValue:(CGFloat)value { |
| 155 [self setNeedsDisplay]; | 155 [self setNeedsDisplay]; |
| 156 } | 156 } |
| 157 | 157 |
| 158 - (TabView *)tabView { | 158 - (TabView *)tabView { |
| 159 return base::mac::ObjCCast<TabView>([self superview]); | 159 return base::mac::ObjCCast<TabView>([self superview]); |
| 160 } | 160 } |
| 161 | 161 |
| 162 - (NSImage*)imageForHoverState:(HoverState)hoverState { | 162 - (NSImage*)imageForHoverState:(HoverState)hoverState { |
| 163 gfx::VectorIconId vectorIconID; | 163 const gfx::VectorIcon* vectorIcon = nullptr; |
| 164 SkColor vectorIconColor = gfx::kPlaceholderColor; | 164 SkColor vectorIconColor = gfx::kPlaceholderColor; |
| 165 TabView* tabView = [self tabView]; | 165 TabView* tabView = [self tabView]; |
| 166 | 166 |
| 167 switch (hoverState) { | 167 switch (hoverState) { |
| 168 case kHoverStateNone: | 168 case kHoverStateNone: |
| 169 vectorIconID = gfx::VectorIconId::TAB_CLOSE_NORMAL; | 169 vectorIcon = &kTabCloseNormalIcon; |
| 170 vectorIconColor = | 170 vectorIconColor = |
| 171 tabView ? [tabView iconColor] : tabs::kDefaultTabTextColor; | 171 tabView ? [tabView iconColor] : tabs::kDefaultTabTextColor; |
| 172 break; | 172 break; |
| 173 case kHoverStateMouseOver: | 173 case kHoverStateMouseOver: |
| 174 // For mouse over, the icon color is the fill color of the circle. | 174 // For mouse over, the icon color is the fill color of the circle. |
| 175 vectorIconID = gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED; | 175 vectorIcon = &kTabCloseHoveredPressedIcon; |
| 176 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); | 176 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); |
| 177 break; | 177 break; |
| 178 case kHoverStateMouseDown: | 178 case kHoverStateMouseDown: |
| 179 // For mouse pressed, the icon color is the fill color of the circle. | 179 // For mouse pressed, the icon color is the fill color of the circle. |
| 180 vectorIconID = gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED; | 180 vectorIcon = &kTabCloseHoveredPressedIcon; |
| 181 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); | 181 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); |
| 182 break; | 182 break; |
| 183 } | 183 } |
| 184 | 184 |
| 185 return NSImageFromImageSkia( | 185 return NSImageFromImageSkia( |
| 186 gfx::CreateVectorIcon(vectorIconID, kTabCloseButtonSize, | 186 gfx::CreateVectorIcon(*vectorIcon, kTabCloseButtonSize, vectorIconColor)); |
| 187 vectorIconColor)); | |
| 188 } | 187 } |
| 189 | 188 |
| 190 - (void)setHoverState:(HoverState)state { | 189 - (void)setHoverState:(HoverState)state { |
| 191 if (state != self.hoverState) { | 190 if (state != self.hoverState) { |
| 192 previousState_ = self.hoverState; | 191 previousState_ = self.hoverState; |
| 193 [super setHoverState:state]; | 192 [super setHoverState:state]; |
| 194 // Only animate the HoverStateNone case and only if this is still in the | 193 // Only animate the HoverStateNone case and only if this is still in the |
| 195 // view hierarchy. | 194 // view hierarchy. |
| 196 if (state == kHoverStateNone && [self superview] != nil) { | 195 if (state == kHoverStateNone && [self superview] != nil) { |
| 197 DCHECK(fadeOutAnimation_ == nil); | 196 DCHECK(fadeOutAnimation_ == nil); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 break; | 266 break; |
| 268 case kHoverStateMouseDown: | 267 case kHoverStateMouseDown: |
| 269 imageID = IDR_CLOSE_DIALOG_P; | 268 imageID = IDR_CLOSE_DIALOG_P; |
| 270 break; | 269 break; |
| 271 } | 270 } |
| 272 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 271 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 273 return bundle.GetNativeImageNamed(imageID).ToNSImage(); | 272 return bundle.GetNativeImageNamed(imageID).ToNSImage(); |
| 274 } | 273 } |
| 275 | 274 |
| 276 @end | 275 @end |
| OLD | NEW |