| 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/browser/themes/theme_properties.h" | 9 #include "chrome/browser/themes/theme_properties.h" |
| 10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
| 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 13 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "grit/components_strings.h" | 15 #include "grit/components_strings.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMKeyValueAnimation.h" | 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMKeyValueAnimation.h" |
| 17 #include "ui/base/cocoa/animation_utils.h" | 18 #include "ui/base/cocoa/animation_utils.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/material_design/material_design_controller.h" | 20 #include "ui/base/material_design/material_design_controller.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/color_palette.h" |
| 21 #include "ui/gfx/image/image_skia_util_mac.h" | 23 #include "ui/gfx/image/image_skia_util_mac.h" |
| 22 #include "ui/gfx/paint_vector_icon.h" | 24 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/vector_icons_public.h" | 25 #include "ui/gfx/vector_icons_public.h" |
| 24 #include "ui/resources/grit/ui_resources.h" | 26 #include "ui/resources/grit/ui_resources.h" |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. | 29 const CGFloat kFramesPerSecond = 16; // Determined experimentally to look good. |
| 28 const CGFloat kCloseAnimationDuration = 0.1; | 30 const CGFloat kCloseAnimationDuration = 0.1; |
| 29 const int kTabCloseButtonSize = 16; | 31 const int kTabCloseButtonSize = 16; |
| 30 | 32 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 } | 152 } |
| 151 | 153 |
| 152 - (void)setFadeOutValue:(CGFloat)value { | 154 - (void)setFadeOutValue:(CGFloat)value { |
| 153 [self setNeedsDisplay]; | 155 [self setNeedsDisplay]; |
| 154 } | 156 } |
| 155 | 157 |
| 156 - (TabView *)tabView { | 158 - (TabView *)tabView { |
| 157 return base::mac::ObjCCast<TabView>([self superview]); | 159 return base::mac::ObjCCast<TabView>([self superview]); |
| 158 } | 160 } |
| 159 | 161 |
| 162 - (SkColor)iconColor { |
| 163 if ([[self window] hasDarkTheme]) { |
| 164 return SkColorSetARGB(0xFF, 0xC4, 0xC4, 0xC4); |
| 165 } |
| 166 |
| 167 const ui::ThemeProvider* themeProvider = [[self window] themeProvider]; |
| 168 if (themeProvider) { |
| 169 TabView* tabView = [self tabView]; |
| 170 bool use_active_tab_text_color = !tabView || [tabView isActiveTab]; |
| 171 |
| 172 const SkColor titleColor = use_active_tab_text_color ? |
| 173 themeProvider->GetColor(ThemeProperties::COLOR_TAB_TEXT) : |
| 174 themeProvider->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB_TEXT); |
| 175 return SkColorSetA(titleColor, 0xA0); |
| 176 } |
| 177 |
| 178 // Return the default COLOR_TAB_TEXT color. |
| 179 return SkColorSetARGB(0xA0, 0x00, 0x00, 0x00); |
| 180 } |
| 181 |
| 160 - (NSImage*)imageForHoverState:(HoverState)hoverState { | 182 - (NSImage*)imageForHoverState:(HoverState)hoverState { |
| 161 int imageID = IDR_CLOSE_1; | 183 int imageID = IDR_CLOSE_1; |
| 162 | 184 |
| 163 if (!ui::MaterialDesignController::IsModeMaterial()) { | 185 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 164 switch (hoverState) { | 186 switch (hoverState) { |
| 165 case kHoverStateNone: | 187 case kHoverStateNone: |
| 166 imageID = IDR_CLOSE_1; | 188 imageID = IDR_CLOSE_1; |
| 167 break; | 189 break; |
| 168 case kHoverStateMouseOver: | 190 case kHoverStateMouseOver: |
| 169 imageID = IDR_CLOSE_1_H; | 191 imageID = IDR_CLOSE_1_H; |
| 170 break; | 192 break; |
| 171 case kHoverStateMouseDown: | 193 case kHoverStateMouseDown: |
| 172 imageID = IDR_CLOSE_1_P; | 194 imageID = IDR_CLOSE_1_P; |
| 173 break; | 195 break; |
| 174 } | 196 } |
| 175 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 197 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 176 return bundle.GetNativeImageNamed(imageID).ToNSImage(); | 198 return bundle.GetNativeImageNamed(imageID).ToNSImage(); |
| 177 } | 199 } |
| 178 | 200 |
| 179 gfx::VectorIconId vectorIconID; | 201 gfx::VectorIconId vectorIconID; |
| 180 SkColor vectorIconColor; | 202 SkColor vectorIconColor = gfx::kPlaceholderColor; |
| 181 const ui::ThemeProvider* themeProvider = nullptr; | |
| 182 TabView* tabView; | |
| 183 | 203 |
| 184 switch (hoverState) { | 204 switch (hoverState) { |
| 185 case kHoverStateNone: | 205 case kHoverStateNone: |
| 186 vectorIconID = gfx::VectorIconId::TAB_CLOSE_NORMAL; | 206 vectorIconID = gfx::VectorIconId::TAB_CLOSE_NORMAL; |
| 187 // Determine the vector icon color, which for this icon is the color | 207 vectorIconColor = [self iconColor]; |
| 188 // of the "x". | |
| 189 themeProvider = [[self window] themeProvider]; | |
| 190 if (themeProvider) { | |
| 191 if (themeProvider->InIncognitoMode()) { | |
| 192 vectorIconColor = SkColorSetARGB(0xFF, 0xC4, 0xC4, 0xC4); | |
| 193 } else { | |
| 194 tabView = [self tabView]; | |
| 195 bool use_active_tab_text_color = !tabView || [tabView isActiveTab]; | |
| 196 | |
| 197 const SkColor titleColor = use_active_tab_text_color ? | |
| 198 themeProvider->GetColor(ThemeProperties::COLOR_TAB_TEXT) : | |
| 199 themeProvider->GetColor( | |
| 200 ThemeProperties::COLOR_BACKGROUND_TAB_TEXT); | |
| 201 vectorIconColor = SkColorSetA(titleColor, 0xA0); | |
| 202 } | |
| 203 } else { | |
| 204 // 0x000000 is the default COLOR_TAB_TEXT color. | |
| 205 vectorIconColor = SkColorSetARGB(0xA0, 0x00, 0x00, 0x00); | |
| 206 } | |
| 207 break; | 208 break; |
| 208 case kHoverStateMouseOver: | 209 case kHoverStateMouseOver: |
| 209 // For mouse over, the icon color is the fill color of the circle. | 210 // For mouse over, the icon color is the fill color of the circle. |
| 210 vectorIconID = gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED; | 211 vectorIconID = gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED; |
| 211 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); | 212 vectorIconColor = SkColorSetARGB(0xFF, 0xDB, 0x44, 0x37); |
| 212 break; | 213 break; |
| 213 case kHoverStateMouseDown: | 214 case kHoverStateMouseDown: |
| 214 // For mouse pressed, the icon color is the fill color of the circle. | 215 // For mouse pressed, the icon color is the fill color of the circle. |
| 215 vectorIconID = gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED; | 216 vectorIconID = gfx::VectorIconId::TAB_CLOSE_HOVERED_PRESSED; |
| 216 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); | 217 vectorIconColor = SkColorSetARGB(0xFF, 0xA8, 0x35, 0x2A); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 break; | 303 break; |
| 303 case kHoverStateMouseDown: | 304 case kHoverStateMouseDown: |
| 304 imageID = IDR_CLOSE_DIALOG_P; | 305 imageID = IDR_CLOSE_DIALOG_P; |
| 305 break; | 306 break; |
| 306 } | 307 } |
| 307 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 308 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 308 return bundle.GetNativeImageNamed(imageID).ToNSImage(); | 309 return bundle.GetNativeImageNamed(imageID).ToNSImage(); |
| 309 } | 310 } |
| 310 | 311 |
| 311 @end | 312 @end |
| OLD | NEW |