| 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 "base/observer_list.h" | |
| 10 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 11 | 10 |
| 12 namespace ui { | 11 namespace ui { |
| 13 class NativeTheme; | 12 class NativeTheme; |
| 14 } // namespace ui | 13 } // namespace ui |
| 15 | 14 |
| 16 namespace views { | 15 namespace views { |
| 17 class Label; | 16 class Label; |
| 18 } // namespace views | 17 } // namespace views |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| 21 class TrayPopupItemStyleObserver; | |
| 22 | 20 |
| 23 // Central style provider for the system tray menu. Makes it easier to ensure | 21 // Central style provider for the system tray menu. Makes it easier to ensure |
| 24 // all visuals are consistent and easily updated in one spot instead of being | 22 // all visuals are consistent and easily updated in one spot instead of being |
| 25 // defined in multiple places throughout the code. | 23 // 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 // } |
| 26 class TrayPopupItemStyle { | 43 class TrayPopupItemStyle { |
| 27 public: | 44 public: |
| 28 // The different visual styles that a row can have. | 45 // The different visual styles that a row can have. |
| 29 enum class ColorStyle { | 46 enum class ColorStyle { |
| 30 // Active and clickable. | 47 // Active and clickable. |
| 31 ACTIVE, | 48 ACTIVE, |
| 32 // Inactive but clickable. | 49 // Inactive but clickable. |
| 33 INACTIVE, | 50 INACTIVE, |
| 34 // Disabled and not clickable. | 51 // Disabled and not clickable. |
| 35 DISABLED, | 52 DISABLED, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 // Sub text within a row (e.g. user name in user row). | 65 // Sub text within a row (e.g. user name in user row). |
| 49 CAPTION, | 66 CAPTION, |
| 50 // Child buttons within rows that have a visible border (e.g. Cast's | 67 // Child buttons within rows that have a visible border (e.g. Cast's |
| 51 // "Stop", etc). | 68 // "Stop", etc). |
| 52 BUTTON, | 69 BUTTON, |
| 53 }; | 70 }; |
| 54 | 71 |
| 55 TrayPopupItemStyle(const ui::NativeTheme* theme, FontStyle font_style); | 72 TrayPopupItemStyle(const ui::NativeTheme* theme, FontStyle font_style); |
| 56 ~TrayPopupItemStyle(); | 73 ~TrayPopupItemStyle(); |
| 57 | 74 |
| 58 void AddObserver(TrayPopupItemStyleObserver* observer); | |
| 59 void RemoveObserver(TrayPopupItemStyleObserver* observer); | |
| 60 | |
| 61 const ui::NativeTheme* theme() const { return theme_; } | 75 const ui::NativeTheme* theme() const { return theme_; } |
| 62 | 76 |
| 63 // Sets the |theme_| and notifies observers. | 77 void set_theme(const ui::NativeTheme* theme) { theme_ = theme; } |
| 64 void SetTheme(const ui::NativeTheme* theme); | |
| 65 | 78 |
| 66 ColorStyle color_style() const { return color_style_; } | 79 ColorStyle color_style() const { return color_style_; } |
| 67 | 80 |
| 68 // Sets the |color_style_| and notifies observers if |color_style_| changed. | 81 void set_color_style(ColorStyle color_style) { color_style_ = color_style; } |
| 69 void SetColorStyle(ColorStyle color_style); | |
| 70 | 82 |
| 71 FontStyle font_style() const { return font_style_; } | 83 FontStyle font_style() const { return font_style_; } |
| 72 | 84 |
| 73 // Sets the |font_style_| notifies observers if |font_style_| changed. | 85 void set_font_style(FontStyle font_style) { font_style_ = font_style; } |
| 74 void SetFontStyle(FontStyle font_style); | |
| 75 | 86 |
| 76 SkColor GetForegroundColor() const; | 87 SkColor GetForegroundColor() const; |
| 77 | 88 |
| 78 // Configures a Label as per the style (e.g. color, font). | 89 // Configures a Label as per the style (e.g. color, font). |
| 79 void SetupLabel(views::Label* label) const; | 90 void SetupLabel(views::Label* label) const; |
| 80 | 91 |
| 81 private: | 92 private: |
| 82 void NotifyObserversStyleUpdated(); | |
| 83 | |
| 84 // The theme that the styles are dervied from. | 93 // The theme that the styles are dervied from. |
| 85 const ui::NativeTheme* theme_; | 94 const ui::NativeTheme* theme_; |
| 86 | 95 |
| 87 FontStyle font_style_; | 96 FontStyle font_style_; |
| 88 | 97 |
| 89 ColorStyle color_style_; | 98 ColorStyle color_style_; |
| 90 | 99 |
| 91 base::ObserverList<TrayPopupItemStyleObserver> observers_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemStyle); | 100 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemStyle); |
| 94 }; | 101 }; |
| 95 | 102 |
| 96 } // namespace ash | 103 } // namespace ash |
| 97 | 104 |
| 98 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ | 105 #endif // ASH_COMMON_SYSTEM_TRAY_TRAY_POPUP_ITEM_STYLE_H_ |
| OLD | NEW |