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