| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "ash/common/system/tray/tray_popup_item_style.h" | 5 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 6 | 6 |
| 7 #include "third_party/skia/include/core/SkColor.h" | 7 #include "third_party/skia/include/core/SkColor.h" |
| 8 #include "ui/gfx/color_palette.h" | 8 #include "ui/gfx/color_palette.h" |
| 9 #include "ui/gfx/font.h" | 9 #include "ui/gfx/font.h" |
| 10 #include "ui/gfx/font_list.h" | 10 #include "ui/gfx/font_list.h" |
| 11 #include "ui/native_theme/native_theme.h" | |
| 12 #include "ui/views/controls/label.h" | 11 #include "ui/views/controls/label.h" |
| 13 | 12 |
| 14 namespace ash { | 13 namespace ash { |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 // The base color used to compute the effective text colors. | 16 const int kInactiveAlpha = 0x8A; |
| 18 const SkColor kBaseTextColor = SK_ColorBLACK; | 17 const int kDisabledAlpha = 0x61; |
| 19 | |
| 20 // The color used for sub-section header row text and icons. | |
| 21 const SkColor kProminentButtonColor = gfx::kGoogleBlue500; | |
| 22 | |
| 23 // The color for "Connected" status text. | |
| 24 const SkColor kConnectedTextColor = gfx::kGoogleGreen700; | |
| 25 | |
| 26 const int kActiveTextAlpha = 0xDE; | |
| 27 const int kInactiveTextAlpha = 0x8A; | |
| 28 const int kDisabledTextAlpha = 0x61; | |
| 29 | |
| 30 // The base color used to compute the effective icon colors. | |
| 31 const SkColor kBaseIconColor = SkColorSetRGB(0x5a, 0x5a, 0x5a); | |
| 32 | |
| 33 const int kActiveIconAlpha = 0xFF; | |
| 34 const int kInactiveIconAlpha = 0x8A; | |
| 35 const int kDisabledIconAlpha = 0x61; | |
| 36 | 18 |
| 37 } // namespace | 19 } // namespace |
| 38 | 20 |
| 39 // static | 21 // static |
| 40 SkColor TrayPopupItemStyle::GetIconColor(const ui::NativeTheme* theme, | 22 SkColor TrayPopupItemStyle::GetIconColor(ColorStyle color_style) { |
| 41 ColorStyle color_style) { | |
| 42 // TODO(bruthig|tdanderson): Determine if TrayPopupItemStyle should depend on | |
| 43 // a NativeTheme and if so use it here. See http://crbug.com/665891. | |
| 44 switch (color_style) { | 23 switch (color_style) { |
| 45 case ColorStyle::ACTIVE: | 24 case ColorStyle::ACTIVE: |
| 46 return SkColorSetA(kBaseIconColor, kActiveIconAlpha); | 25 return gfx::kChromeIconGrey; |
| 47 case ColorStyle::INACTIVE: | 26 case ColorStyle::INACTIVE: |
| 48 return SkColorSetA(kBaseIconColor, kInactiveIconAlpha); | 27 return SkColorSetA(gfx::kChromeIconGrey, kInactiveAlpha); |
| 49 case ColorStyle::DISABLED: | 28 case ColorStyle::DISABLED: |
| 50 return SkColorSetA(kBaseIconColor, kDisabledIconAlpha); | 29 return SkColorSetA(gfx::kChromeIconGrey, kDisabledAlpha); |
| 51 case ColorStyle::CONNECTED: | 30 case ColorStyle::CONNECTED: |
| 52 // Use a noticeable color to help notice undefined color styles for icons. | 31 return gfx::kPlaceholderColor; |
| 53 return SK_ColorMAGENTA; | |
| 54 case ColorStyle::SUB_HEADER: | |
| 55 return kProminentButtonColor; | |
| 56 } | 32 } |
| 57 NOTREACHED(); | 33 NOTREACHED(); |
| 58 // Use a noticeable color to help notice unhandled cases. | 34 return gfx::kPlaceholderColor; |
| 59 return SK_ColorMAGENTA; | |
| 60 } | 35 } |
| 61 | 36 |
| 62 // static | 37 TrayPopupItemStyle::TrayPopupItemStyle(FontStyle font_style) |
| 63 SkColor TrayPopupItemStyle::GetIconColor(ColorStyle color_style) { | 38 : font_style_(font_style), color_style_(ColorStyle::ACTIVE) { |
| 64 return GetIconColor(nullptr, color_style); | 39 if (font_style_ == FontStyle::SYSTEM_INFO) |
| 40 color_style_ = ColorStyle::INACTIVE; |
| 65 } | 41 } |
| 66 | 42 |
| 67 TrayPopupItemStyle::TrayPopupItemStyle(const ui::NativeTheme* theme, | |
| 68 FontStyle font_style) | |
| 69 : theme_(theme), | |
| 70 font_style_(font_style), | |
| 71 color_style_(font_style_ == FontStyle::SUB_HEADER ? ColorStyle::SUB_HEADER | |
| 72 : ColorStyle::ACTIVE) {} | |
| 73 | |
| 74 TrayPopupItemStyle::TrayPopupItemStyle(FontStyle font_style) | |
| 75 : TrayPopupItemStyle(nullptr, font_style) {} | |
| 76 | |
| 77 TrayPopupItemStyle::~TrayPopupItemStyle() {} | 43 TrayPopupItemStyle::~TrayPopupItemStyle() {} |
| 78 | 44 |
| 79 SkColor TrayPopupItemStyle::GetTextColor() const { | 45 SkColor TrayPopupItemStyle::GetTextColor() const { |
| 80 if (font_style_ == FontStyle::SYSTEM_INFO) | 46 const SkColor kBaseTextColor = SkColorSetA(SK_ColorBLACK, 0xDE); |
| 81 return SkColorSetA(kBaseTextColor, kInactiveTextAlpha); | |
| 82 | 47 |
| 83 switch (color_style_) { | 48 switch (color_style_) { |
| 84 case ColorStyle::ACTIVE: | 49 case ColorStyle::ACTIVE: |
| 85 return SkColorSetA(kBaseTextColor, kActiveTextAlpha); | 50 return kBaseTextColor; |
| 86 case ColorStyle::INACTIVE: | 51 case ColorStyle::INACTIVE: |
| 87 return SkColorSetA(kBaseTextColor, kInactiveTextAlpha); | 52 return SkColorSetA(kBaseTextColor, kInactiveAlpha); |
| 88 case ColorStyle::DISABLED: | 53 case ColorStyle::DISABLED: |
| 89 return SkColorSetA(kBaseTextColor, kDisabledTextAlpha); | 54 return SkColorSetA(kBaseTextColor, kDisabledAlpha); |
| 90 case ColorStyle::CONNECTED: | 55 case ColorStyle::CONNECTED: |
| 91 return kConnectedTextColor; | 56 return gfx::kGoogleGreen700; |
| 92 case ColorStyle::SUB_HEADER: | |
| 93 return kProminentButtonColor; | |
| 94 } | 57 } |
| 95 NOTREACHED(); | 58 NOTREACHED(); |
| 96 // Use a noticeable color to help notice unhandled cases. | 59 return gfx::kPlaceholderColor; |
| 97 return SK_ColorMAGENTA; | |
| 98 } | 60 } |
| 99 | 61 |
| 100 SkColor TrayPopupItemStyle::GetIconColor() const { | 62 SkColor TrayPopupItemStyle::GetIconColor() const { |
| 101 return GetIconColor(theme_, color_style_); | 63 return GetIconColor(color_style_); |
| 102 } | 64 } |
| 103 | 65 |
| 104 void TrayPopupItemStyle::SetupLabel(views::Label* label) const { | 66 void TrayPopupItemStyle::SetupLabel(views::Label* label) const { |
| 105 label->SetEnabledColor(GetTextColor()); | 67 label->SetEnabledColor(GetTextColor()); |
| 106 | 68 |
| 107 const gfx::FontList& base_font_list = views::Label::GetDefaultFontList(); | 69 const gfx::FontList& base_font_list = views::Label::GetDefaultFontList(); |
| 108 switch (font_style_) { | 70 switch (font_style_) { |
| 109 case FontStyle::TITLE: | 71 case FontStyle::TITLE: |
| 110 label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL, | 72 label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL, |
| 111 gfx::Font::Weight::MEDIUM)); | 73 gfx::Font::Weight::MEDIUM)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 129 gfx::Font::Weight::MEDIUM)); | 91 gfx::Font::Weight::MEDIUM)); |
| 130 break; | 92 break; |
| 131 case FontStyle::CAPTION: | 93 case FontStyle::CAPTION: |
| 132 label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, | 94 label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, |
| 133 gfx::Font::Weight::NORMAL)); | 95 gfx::Font::Weight::NORMAL)); |
| 134 break; | 96 break; |
| 135 } | 97 } |
| 136 } | 98 } |
| 137 | 99 |
| 138 } // namespace ash | 100 } // namespace ash |
| OLD | NEW |