Chromium Code Reviews| Index: ash/common/system/tray/tray_popup_item_style.cc |
| diff --git a/ash/common/system/tray/tray_popup_item_style.cc b/ash/common/system/tray/tray_popup_item_style.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e5ba8f1d337bace4a1511c7f8e61498553181051 |
| --- /dev/null |
| +++ b/ash/common/system/tray/tray_popup_item_style.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/common/system/tray/tray_popup_item_style.h" |
| + |
| +#include "ash/common/system/tray/tray_popup_item_style_observer.h" |
| +#include "ui/gfx/font.h" |
| +#include "ui/gfx/font_list.h" |
| +#include "ui/native_theme/native_theme.h" |
| +#include "ui/views/controls/label.h" |
| + |
| +namespace ash { |
| + |
| +TrayPopupItemStyle::TrayPopupItemStyle(const ui::NativeTheme* theme, |
| + FontStyle font_style) |
| + : theme_(theme), |
| + font_style_(font_style), |
| + color_style_(ColorStyle::ACTIVE) {} |
| + |
| +TrayPopupItemStyle::~TrayPopupItemStyle() {} |
| + |
| +void TrayPopupItemStyle::AddObserver(TrayPopupItemStyleObserver* observer) { |
| + if (!observers_.HasObserver(observer)) |
| + observers_.AddObserver(observer); |
| +} |
|
tdanderson
2016/09/08 16:11:02
nit: newline
bruthig
2016/09/12 13:45:34
Done.
|
| +void TrayPopupItemStyle::RemoveObserver(TrayPopupItemStyleObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void TrayPopupItemStyle::SetTheme(const ui::NativeTheme* theme) { |
| + theme_ = theme; |
| + NotifyObserversStyleChanged(); |
| +} |
| + |
| +void TrayPopupItemStyle::SetColorStyle(ColorStyle color_style) { |
| + if (color_style_ != color_style) { |
| + color_style_ = color_style; |
| + NotifyObserversStyleChanged(); |
| + } |
| +} |
| + |
| +void TrayPopupItemStyle::SetFontStyle(FontStyle font_style) { |
| + if (font_style_ != font_style) { |
| + font_style_ = font_style; |
| + NotifyObserversStyleChanged(); |
| + } |
| +} |
| + |
| +SkColor TrayPopupItemStyle::GetForegroundColor() const { |
| + switch (color_style_) { |
| + case ColorStyle::ACTIVE: |
| + return theme_->GetSystemColor( |
| + ui::NativeTheme::kColorId_LabelEnabledColor); |
| + case ColorStyle::INACTIVE: |
| + // TODO(bruthig): Consider adding an 'inactive' color to the NativeTheme |
| + // and allow Label to use it directly. This would require changing the |
| + // View::enabled_ flag to a tri-state enum. |
| + return SkColorSetRGB(0x64, 0x64, 0x64); |
| + case ColorStyle::DISABLED: |
| + return theme_->GetSystemColor( |
| + ui::NativeTheme::kColorId_LabelDisabledColor); |
| + } |
| + NOTREACHED(); |
| + // Use a noticeable color to help notice unhandled cases. |
| + return SK_ColorMAGENTA; |
| +} |
| + |
| +void TrayPopupItemStyle::SetupLabel(views::Label* label) const { |
| + if (!label) |
| + return; |
| + label->SetEnabledColor(GetForegroundColor()); |
| + |
| + switch (font_style_) { |
| + case FontStyle::TITLE: |
| + label->SetFontList(label->font_list().Derive(2, gfx::Font::NORMAL, |
| + gfx::Font::Weight::MEDIUM)); |
| + break; |
| + case FontStyle::MAIN_PANEL_SECTION_ROW: |
| + label->SetFontList(label->font_list().Derive(2, gfx::Font::NORMAL, |
| + gfx::Font::Weight::NORMAL)); |
| + break; |
| + case FontStyle::SUB_PANEL_SECTION_ROW: |
| + case FontStyle::SYSTEM_INFO: |
| + label->SetFontList(label->font_list().Derive(1, gfx::Font::NORMAL, |
| + gfx::Font::Weight::NORMAL)); |
| + break; |
| + case FontStyle::CAPTION: |
| + label->SetFontList(label->font_list().Derive(0, gfx::Font::NORMAL, |
| + gfx::Font::Weight::NORMAL)); |
| + break; |
| + case FontStyle::BUTTON: |
| + label->SetFontList(label->font_list().Derive(0, gfx::Font::NORMAL, |
| + gfx::Font::Weight::MEDIUM)); |
| + break; |
| + } |
| +} |
| + |
| +void TrayPopupItemStyle::NotifyObserversStyleChanged() { |
| + FOR_EACH_OBSERVER(TrayPopupItemStyleObserver, observers_, |
| + OnTrayPopupItemStyleChanged()); |
| +} |
| + |
| +} // namespace ash |