Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: ash/common/system/tray/tray_popup_item_style.cc

Issue 2244003002: Materialized font style for TrayItemMore type system tray rows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated TrayPopupItemStyle to use the default FontList. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 }
27
28 void TrayPopupItemStyle::RemoveObserver(TrayPopupItemStyleObserver* observer) {
29 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.
30 }
31
32 void TrayPopupItemStyle::SetTheme(const ui::NativeTheme* theme) {
33 theme_ = theme;
34 NotifyObserversStyleUpdated();
35 }
36
37 void TrayPopupItemStyle::SetColorStyle(ColorStyle color_style) {
38 color_style_ = color_style;
39 NotifyObserversStyleUpdated();
40 }
41
42 void TrayPopupItemStyle::SetFontStyle(FontStyle font_style) {
43 font_style_ = font_style;
44 NotifyObserversStyleUpdated();
45 }
46
47 SkColor TrayPopupItemStyle::GetForegroundColor() const {
48 switch (color_style_) {
49 case ColorStyle::ACTIVE:
50 return theme_->GetSystemColor(
51 ui::NativeTheme::kColorId_LabelEnabledColor);
52 case ColorStyle::INACTIVE:
53 // TODO(bruthig): Consider adding an 'inactive' color to the NativeTheme
54 // and allow Label to use it directly. This would require changing the
55 // View::enabled_ flag to a tri-state enum.
56 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.
57 case ColorStyle::DISABLED:
58 return theme_->GetSystemColor(
59 ui::NativeTheme::kColorId_LabelDisabledColor);
60 }
61 NOTREACHED();
62 // Use a noticeable color to help notice unhandled cases.
63 return SK_ColorMAGENTA;
64 }
65
66 void TrayPopupItemStyle::SetupLabel(views::Label* label) const {
67 label->SetEnabledColor(GetForegroundColor());
68
69 const gfx::FontList& base_font_list = views::Label::GetDefaultFontList();
70 switch (font_style_) {
71 case FontStyle::TITLE:
72 label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL,
73 gfx::Font::Weight::MEDIUM));
74 break;
75 case FontStyle::MAIN_PANEL_SECTION_ROW:
76 label->SetFontList(base_font_list.Derive(2, gfx::Font::NORMAL,
77 gfx::Font::Weight::NORMAL));
78 break;
79 case FontStyle::SUB_PANEL_SECTION_ROW:
80 case FontStyle::SYSTEM_INFO:
81 label->SetFontList(base_font_list.Derive(1, gfx::Font::NORMAL,
82 gfx::Font::Weight::NORMAL));
83 break;
84 case FontStyle::CAPTION:
85 label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL,
86 gfx::Font::Weight::NORMAL));
87 break;
88 case FontStyle::BUTTON:
89 label->SetFontList(base_font_list.Derive(0, gfx::Font::NORMAL,
90 gfx::Font::Weight::MEDIUM));
91 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
92 }
93 }
94
95 void TrayPopupItemStyle::NotifyObserversStyleUpdated() {
96 FOR_EACH_OBSERVER(TrayPopupItemStyleObserver, observers_,
97 OnTrayPopupItemStyleUpdated());
98 }
99
100 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698