OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 6 |
| 7 #include "ash/common/system/tray/tray_popup_item_style_observer.h" |
| 8 #include "third_party/skia/include/core/SkColor.h" |
| 9 #include "ui/gfx/font.h" |
| 10 #include "ui/gfx/font_list.h" |
| 11 #include "ui/native_theme/native_theme.h" |
| 12 #include "ui/views/controls/label.h" |
| 13 |
| 14 namespace ash { |
| 15 namespace { |
| 16 |
| 17 // TODO(bruthig): Consider adding an 'inactive' color to the NativeTheme |
| 18 // and allow Label to use it directly. This would require changing the |
| 19 // View::enabled_ flag to a tri-state enum. |
| 20 const SkColor kInactiveTextColor = SkColorSetRGB(0x64, 0x64, 0x64); |
| 21 } // namespace |
| 22 |
| 23 TrayPopupItemStyle::TrayPopupItemStyle(const ui::NativeTheme* theme, |
| 24 FontStyle font_style) |
| 25 : theme_(theme), |
| 26 font_style_(font_style), |
| 27 color_style_(ColorStyle::ACTIVE) {} |
| 28 |
| 29 TrayPopupItemStyle::~TrayPopupItemStyle() {} |
| 30 |
| 31 void TrayPopupItemStyle::AddObserver(TrayPopupItemStyleObserver* observer) { |
| 32 if (!observers_.HasObserver(observer)) |
| 33 observers_.AddObserver(observer); |
| 34 } |
| 35 |
| 36 void TrayPopupItemStyle::RemoveObserver(TrayPopupItemStyleObserver* observer) { |
| 37 observers_.RemoveObserver(observer); |
| 38 } |
| 39 |
| 40 void TrayPopupItemStyle::SetTheme(const ui::NativeTheme* theme) { |
| 41 theme_ = theme; |
| 42 NotifyObserversStyleUpdated(); |
| 43 } |
| 44 |
| 45 void TrayPopupItemStyle::SetColorStyle(ColorStyle color_style) { |
| 46 color_style_ = color_style; |
| 47 NotifyObserversStyleUpdated(); |
| 48 } |
| 49 |
| 50 void TrayPopupItemStyle::SetFontStyle(FontStyle font_style) { |
| 51 font_style_ = font_style; |
| 52 NotifyObserversStyleUpdated(); |
| 53 } |
| 54 |
| 55 SkColor TrayPopupItemStyle::GetForegroundColor() const { |
| 56 switch (color_style_) { |
| 57 case ColorStyle::ACTIVE: |
| 58 return theme_->GetSystemColor( |
| 59 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 60 case ColorStyle::INACTIVE: |
| 61 return kInactiveTextColor; |
| 62 case ColorStyle::DISABLED: |
| 63 return theme_->GetSystemColor( |
| 64 ui::NativeTheme::kColorId_LabelDisabledColor); |
| 65 } |
| 66 NOTREACHED(); |
| 67 // Use a noticeable color to help notice unhandled cases. |
| 68 return SK_ColorMAGENTA; |
| 69 } |
| 70 |
| 71 void TrayPopupItemStyle::SetupLabel(views::Label* label) const { |
| 72 label->SetEnabledColor(GetForegroundColor()); |
| 73 |
| 74 const gfx::FontList& base_font_list = views::Label::GetDefaultFontList(); |
| 75 switch (font_style_) { |
| 76 case FontStyle::TITLE: |
| 77 label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL, |
| 78 gfx::Font::Weight::MEDIUM)); |
| 79 break; |
| 80 case FontStyle::DEFAULT_VIEW_LABEL: |
| 81 label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL, |
| 82 gfx::Font::Weight::NORMAL)); |
| 83 break; |
| 84 case FontStyle::DETAILED_VIEW_LABEL: |
| 85 case FontStyle::SYSTEM_INFO: |
| 86 label->SetFontList(base_font_list.Derive(1, gfx::Font::NORMAL, |
| 87 gfx::Font::Weight::NORMAL)); |
| 88 break; |
| 89 case FontStyle::CAPTION: |
| 90 label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, |
| 91 gfx::Font::Weight::NORMAL)); |
| 92 break; |
| 93 case FontStyle::BUTTON: |
| 94 label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, |
| 95 gfx::Font::Weight::MEDIUM)); |
| 96 break; |
| 97 } |
| 98 } |
| 99 |
| 100 void TrayPopupItemStyle::NotifyObserversStyleUpdated() { |
| 101 FOR_EACH_OBSERVER(TrayPopupItemStyleObserver, observers_, |
| 102 OnTrayPopupItemStyleUpdated()); |
| 103 } |
| 104 |
| 105 } // namespace ash |
OLD | NEW |