| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ | 5 #ifndef ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ |
| 6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ | 6 #define ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 | 10 |
| 11 namespace ui { | |
| 12 class NativeTheme; | |
| 13 } // namespace ui | |
| 14 | |
| 15 namespace views { | 11 namespace views { |
| 16 class Label; | 12 class Label; |
| 17 } // namespace views | 13 } // namespace views |
| 18 | 14 |
| 19 namespace ash { | 15 namespace ash { |
| 20 | 16 |
| 21 // Central style provider for the system tray menu. Makes it easier to ensure | 17 // Central style provider for the system tray menu. Makes it easier to ensure |
| 22 // all visuals are consistent and easily updated in one spot instead of being | 18 // all visuals are consistent and easily updated in one spot instead of being |
| 23 // defined in multiple places throughout the code. | 19 // defined in multiple places throughout the code. |
| 24 // | |
| 25 // Since the TrayPopupItemStyle is based on a NativeTheme you should ensure that | |
| 26 // when a View's theme changes that a style is re-applied using the new theme. | |
| 27 // Typically this is done by overriding View::OnNativeThemeChanged() as shown | |
| 28 // below. | |
| 29 // | |
| 30 // It is also important to note that Views call through the virtual function | |
| 31 // View::GetWidget() when obtaining the NativeTheme. Therefore, Views should not | |
| 32 // be getting the theme in their own constructors. See https://crbug.com/647376. | |
| 33 // | |
| 34 // Example: | |
| 35 // void OnNativeThemeChanged(const ui::NativeTheme* theme) override { | |
| 36 // UpdateStyle(); | |
| 37 // } | |
| 38 // | |
| 39 // void UpdateStyle() { | |
| 40 // TrayPopupItemStyle style(GetNativeTheme()); | |
| 41 // style.SetupLabel(label_); | |
| 42 // } | |
| 43 class TrayPopupItemStyle { | 20 class TrayPopupItemStyle { |
| 44 public: | 21 public: |
| 45 // The different visual styles that a row can have. | 22 // The different visual styles that a row can have. |
| 46 enum class ColorStyle { | 23 enum class ColorStyle { |
| 47 // Active and clickable. | 24 // Active and clickable. |
| 48 ACTIVE, | 25 ACTIVE, |
| 49 // Inactive but clickable. | 26 // Inactive but clickable. |
| 50 INACTIVE, | 27 INACTIVE, |
| 51 // Disabled and not clickable. | 28 // Disabled and not clickable. |
| 52 DISABLED, | 29 DISABLED, |
| 53 // Color for "Connected" labels. | 30 // Color for "Connected" labels. |
| 54 CONNECTED, | 31 CONNECTED, |
| 55 // Color for sub-section header rows in detailed views. | |
| 56 SUB_HEADER, | |
| 57 }; | 32 }; |
| 58 | 33 |
| 59 // The different font styles that row text can have. | 34 // The different font styles that row text can have. |
| 60 enum class FontStyle { | 35 enum class FontStyle { |
| 61 // Topmost header rows for default view and detailed view. | 36 // Topmost header rows for default view and detailed view. |
| 62 TITLE, | 37 TITLE, |
| 63 // Main text used by default view rows. | 38 // Main text used by default view rows. |
| 64 DEFAULT_VIEW_LABEL, | 39 DEFAULT_VIEW_LABEL, |
| 65 // Text in sub-section header rows in detailed views. | 40 // Text in sub-section header rows in detailed views. |
| 66 SUB_HEADER, | 41 SUB_HEADER, |
| 67 // Main text used by detailed view rows. | 42 // Main text used by detailed view rows. |
| 68 DETAILED_VIEW_LABEL, | 43 DETAILED_VIEW_LABEL, |
| 69 // System information text (e.g. date/time, battery status, etc). | 44 // System information text (e.g. date/time, battery status, etc). |
| 70 SYSTEM_INFO, | 45 SYSTEM_INFO, |
| 71 // Child buttons within rows that have a visible border (e.g. Cast's | 46 // Child buttons within rows that have a visible border (e.g. Cast's |
| 72 // "Stop", etc). | 47 // "Stop", etc). |
| 73 BUTTON, | 48 BUTTON, |
| 74 // Sub text within a row (e.g. user name in user row). | 49 // Sub text within a row (e.g. user name in user row). |
| 75 CAPTION, | 50 CAPTION, |
| 76 }; | 51 }; |
| 77 | 52 |
| 78 static SkColor GetIconColor(const ui::NativeTheme* theme, | |
| 79 ColorStyle color_style); | |
| 80 static SkColor GetIconColor(ColorStyle color_style); | 53 static SkColor GetIconColor(ColorStyle color_style); |
| 81 | 54 |
| 82 TrayPopupItemStyle(const ui::NativeTheme* theme, FontStyle font_style); | |
| 83 explicit TrayPopupItemStyle(FontStyle font_style); | 55 explicit TrayPopupItemStyle(FontStyle font_style); |
| 84 ~TrayPopupItemStyle(); | 56 ~TrayPopupItemStyle(); |
| 85 | 57 |
| 86 const ui::NativeTheme* theme() const { return theme_; } | |
| 87 | |
| 88 void set_theme(const ui::NativeTheme* theme) { theme_ = theme; } | |
| 89 | |
| 90 ColorStyle color_style() const { return color_style_; } | 58 ColorStyle color_style() const { return color_style_; } |
| 91 | 59 |
| 92 void set_color_style(ColorStyle color_style) { color_style_ = color_style; } | 60 void set_color_style(ColorStyle color_style) { color_style_ = color_style; } |
| 93 | 61 |
| 94 FontStyle font_style() const { return font_style_; } | 62 FontStyle font_style() const { return font_style_; } |
| 95 | 63 |
| 96 void set_font_style(FontStyle font_style) { font_style_ = font_style; } | 64 void set_font_style(FontStyle font_style) { font_style_ = font_style; } |
| 97 | 65 |
| 98 SkColor GetTextColor() const; | 66 SkColor GetTextColor() const; |
| 99 | 67 |
| 100 SkColor GetIconColor() const; | 68 SkColor GetIconColor() const; |
| 101 | 69 |
| 102 // Configures a Label as per the style (e.g. color, font). | 70 // Configures a Label as per the style (e.g. color, font). |
| 103 void SetupLabel(views::Label* label) const; | 71 void SetupLabel(views::Label* label) const; |
| 104 | 72 |
| 105 private: | 73 private: |
| 106 // The theme that the styles are dervied from. | |
| 107 // NOTE the styles are not currently derived from |theme_| but see TODO below. | |
| 108 // TODO(bruthig|tdanderson): Determine if TrayPopupItemStyle should depend on | |
| 109 // a NativeTheme. See http://crbug.com/665891. | |
| 110 const ui::NativeTheme* theme_; | |
| 111 | |
| 112 FontStyle font_style_; | 74 FontStyle font_style_; |
| 113 | 75 |
| 114 ColorStyle color_style_; | 76 ColorStyle color_style_; |
| 115 | 77 |
| 116 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemStyle); | 78 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemStyle); |
| 117 }; | 79 }; |
| 118 | 80 |
| 119 } // namespace ash | 81 } // namespace ash |
| 120 | 82 |
| 121 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ | 83 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ |
| OLD | NEW |