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..054984cb6f891fde74bcf0db6291a80cd03e94ca |
--- /dev/null |
+++ b/ash/common/system/tray/tray_popup_item_style.cc |
@@ -0,0 +1,100 @@ |
+// 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); |
+} |
+ |
+void TrayPopupItemStyle::RemoveObserver(TrayPopupItemStyleObserver* observer) { |
+ observers_.RemoveObserver(observer); |
tdanderson
2016/09/12 18:51:47
should you check HasObserver() before calling Remo
bruthig
2016/09/15 18:56:29
It would be unnecessary. ObserverListBase::Remove
tdanderson
2016/09/15 19:49:33
Acknowledged.
|
+} |
+ |
+void TrayPopupItemStyle::SetTheme(const ui::NativeTheme* theme) { |
+ theme_ = theme; |
+ NotifyObserversStyleUpdated(); |
+} |
+ |
+void TrayPopupItemStyle::SetColorStyle(ColorStyle color_style) { |
+ color_style_ = color_style; |
+ NotifyObserversStyleUpdated(); |
+} |
+ |
+void TrayPopupItemStyle::SetFontStyle(FontStyle font_style) { |
+ font_style_ = font_style; |
+ NotifyObserversStyleUpdated(); |
+} |
+ |
+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); |
tdanderson
2016/09/12 18:51:47
Consider moving this to tray_constants (or at the
bruthig
2016/09/15 18:56:29
Made it a constant in this file and kept TODO.
|
+ 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 { |
+ label->SetEnabledColor(GetForegroundColor()); |
+ |
+ const gfx::FontList& base_font_list = views::Label::GetDefaultFontList(); |
+ switch (font_style_) { |
+ case FontStyle::TITLE: |
+ label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL, |
+ gfx::Font::Weight::MEDIUM)); |
+ break; |
+ case FontStyle::MAIN_PANEL_SECTION_ROW: |
+ label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL, |
+ gfx::Font::Weight::NORMAL)); |
+ break; |
+ case FontStyle::SUB_PANEL_SECTION_ROW: |
+ case FontStyle::SYSTEM_INFO: |
+ label->SetFontList(base_font_list.Derive(1, gfx::Font::NORMAL, |
+ gfx::Font::Weight::NORMAL)); |
+ break; |
+ case FontStyle::CAPTION: |
+ label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, |
+ gfx::Font::Weight::NORMAL)); |
+ break; |
+ case FontStyle::BUTTON: |
+ label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL, |
+ gfx::Font::Weight::MEDIUM)); |
+ break; |
tdanderson
2016/09/12 18:51:47
can you add a NOTREACHED() somewhere in here?
bruthig
2016/09/15 18:56:29
I'm not exactly sure what you are asking. FTR the
tdanderson
2016/09/15 19:49:33
I thought the style guide required a default: NOTR
|
+ } |
+} |
+ |
+void TrayPopupItemStyle::NotifyObserversStyleUpdated() { |
+ FOR_EACH_OBSERVER(TrayPopupItemStyleObserver, observers_, |
+ OnTrayPopupItemStyleUpdated()); |
+} |
+ |
+} // namespace ash |