| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | 5 #ifndef ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ |
| 6 #define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | 6 #define ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ |
| 7 | 7 |
| 8 #include "ash/system/tray/actionable_view.h" | 8 #include "ash/system/tray/actionable_view.h" |
| 9 #include "ash/system/tray/tray_popup_item_style.h" | 9 #include "ash/system/tray/tray_popup_item_style.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/gfx/font.h" | 11 #include "ui/gfx/font.h" |
| 12 #include "ui/gfx/text_constants.h" | 12 #include "ui/gfx/text_constants.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 class ImageView; | 15 class ImageView; |
| 16 class Label; | 16 class Label; |
| 17 class BoxLayout; | |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| 21 class TriView; | 20 class TriView; |
| 22 class ViewClickListener; | 21 class ViewClickListener; |
| 23 | 22 |
| 24 // A view that changes background color on hover, and triggers a callback in the | 23 // A view that changes background color on hover, and triggers a callback in the |
| 25 // associated ViewClickListener on click. The view can also be forced to | 24 // associated ViewClickListener on click. The view can also be forced to |
| 26 // maintain a fixed height. | 25 // maintain a fixed height. |
| 27 class HoverHighlightView : public ActionableView { | 26 class HoverHighlightView : public ActionableView { |
| 28 public: | 27 public: |
| 29 enum class AccessibilityState { | 28 enum class AccessibilityState { |
| 30 // The default accessibility view. | 29 // The default accessibility view. |
| 31 DEFAULT, | 30 DEFAULT, |
| 32 // This view is a checked checkbox. | 31 // This view is a checked checkbox. |
| 33 CHECKED_CHECKBOX, | 32 CHECKED_CHECKBOX, |
| 34 // This view is an unchecked checkbox. | 33 // This view is an unchecked checkbox. |
| 35 UNCHECKED_CHECKBOX | 34 UNCHECKED_CHECKBOX |
| 36 }; | 35 }; |
| 37 | 36 |
| 38 explicit HoverHighlightView(ViewClickListener* listener); | 37 explicit HoverHighlightView(ViewClickListener* listener); |
| 39 ~HoverHighlightView() override; | 38 ~HoverHighlightView() override; |
| 40 | 39 |
| 41 // views::View: | |
| 42 bool GetTooltipText(const gfx::Point& p, | |
| 43 base::string16* tooltip) const override; | |
| 44 | |
| 45 // Convenience function for adding an icon and a label. This also sets the | 40 // Convenience function for adding an icon and a label. This also sets the |
| 46 // accessible name. Primarily used for scrollable rows in detailed views. | 41 // accessible name. Primarily used for scrollable rows in detailed views. |
| 47 void AddIconAndLabel(const gfx::ImageSkia& image, const base::string16& text); | 42 void AddIconAndLabel(const gfx::ImageSkia& image, const base::string16& text); |
| 48 | 43 |
| 49 // Convenience function for adding an icon, a main label, and a sub label. | 44 // Convenience function for adding an icon, a main label, and a sub label. |
| 50 // This also sets the accessible name besed on the main label. Used for | 45 // This also sets the accessible name besed on the main label. Used for |
| 51 // scrollable rows in detailed views. | 46 // scrollable rows in detailed views. |
| 52 void AddIconAndLabels(const gfx::ImageSkia& image, | 47 void AddIconAndLabels(const gfx::ImageSkia& image, |
| 53 const base::string16& text, | 48 const base::string16& text, |
| 54 const base::string16& sub_text); | 49 const base::string16& sub_text); |
| 55 | 50 |
| 56 // A convenience function for adding an icon and label for a system menu | 51 // A convenience function for adding an icon and label for a system menu |
| 57 // default view row. | 52 // default view row. |
| 58 void AddIconAndLabelForDefaultView(const gfx::ImageSkia& image, | 53 void AddIconAndLabelForDefaultView(const gfx::ImageSkia& image, |
| 59 const base::string16& text); | 54 const base::string16& text); |
| 60 | 55 |
| 61 // Convenience function for adding a label with padding on the left for a | |
| 62 // blank icon. This also sets the accessible name. Returns label after | |
| 63 // parenting it. | |
| 64 // TODO(tdanderson): Remove this function and use AddLabelRow() instead. | |
| 65 // See crbug.com/708190. | |
| 66 views::Label* AddLabelDeprecated(const base::string16& text, | |
| 67 gfx::HorizontalAlignment alignment, | |
| 68 bool highlight); | |
| 69 | |
| 70 // Adds a row containing only a text label, inset on the left by the | 56 // Adds a row containing only a text label, inset on the left by the |
| 71 // horizontal space that would normally be occupied by an icon. | 57 // horizontal space that would normally be occupied by an icon. |
| 72 void AddLabelRow(const base::string16& text); | 58 void AddLabelRow(const base::string16& text); |
| 73 | 59 |
| 74 // Add an optional right icon to an already established view (call one of | 60 // Add an optional right icon to an already established view (call one of |
| 75 // the other Add* functions first). |icon_size| is the size of the icon in DP. | 61 // the other Add* functions first). |icon_size| is the size of the icon in DP. |
| 76 void AddRightIcon(const gfx::ImageSkia& image, int icon_size); | 62 void AddRightIcon(const gfx::ImageSkia& image, int icon_size); |
| 77 | 63 |
| 78 // Add an optional right view to an already established view (call one of | 64 // Add an optional right view to an already established view (call one of |
| 79 // the other Add* functions first). | 65 // the other Add* functions first). |
| 80 void AddRightView(views::View* view); | 66 void AddRightView(views::View* view); |
| 81 | 67 |
| 82 // Hide or show the right view. | 68 // Hide or show the right view. |
| 83 void SetRightViewVisible(bool visible); | 69 void SetRightViewVisible(bool visible); |
| 84 | 70 |
| 85 // Allows view to expand its height. Size of unexapandable view is fixed and | 71 // Allows view to expand its height. Size of unexapandable view is fixed and |
| 86 // equals to kTrayPopupItemHeight. | 72 // equals to kTrayPopupItemHeight. |
| 87 void SetExpandable(bool expandable); | 73 void SetExpandable(bool expandable); |
| 88 | 74 |
| 89 // Set a custom height for the view. A value of 0 means that no custom height | |
| 90 // is set. | |
| 91 void set_custom_height(int custom_height) { custom_height_ = custom_height; } | |
| 92 | |
| 93 // Changes the view's current accessibility state. This will fire an | 75 // Changes the view's current accessibility state. This will fire an |
| 94 // accessibility event if needed. | 76 // accessibility event if needed. |
| 95 void SetAccessiblityState(AccessibilityState accessibility_state); | 77 void SetAccessiblityState(AccessibilityState accessibility_state); |
| 96 | 78 |
| 97 views::Label* text_label() { return text_label_; } | 79 views::Label* text_label() { return text_label_; } |
| 98 views::Label* sub_text_label() { return sub_text_label_; } | 80 views::Label* sub_text_label() { return sub_text_label_; } |
| 99 | 81 |
| 100 void set_tooltip(const base::string16& tooltip) { tooltip_ = tooltip; } | |
| 101 | |
| 102 protected: | 82 protected: |
| 103 // views::View: | 83 // views::View: |
| 104 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 84 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 105 | 85 |
| 106 TriView* tri_view() { return tri_view_; } | 86 TriView* tri_view() { return tri_view_; } |
| 107 | 87 |
| 108 private: | 88 private: |
| 109 // Adds the image and label to the row with the label being styled using | 89 // Adds the image and label to the row with the label being styled using |
| 110 // |font_style|. | 90 // |font_style|. |
| 111 void DoAddIconAndLabel(const gfx::ImageSkia& image, | 91 void DoAddIconAndLabel(const gfx::ImageSkia& image, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 125 | 105 |
| 126 // views::View: | 106 // views::View: |
| 127 gfx::Size GetPreferredSize() const override; | 107 gfx::Size GetPreferredSize() const override; |
| 128 int GetHeightForWidth(int width) const override; | 108 int GetHeightForWidth(int width) const override; |
| 129 void OnEnabledChanged() override; | 109 void OnEnabledChanged() override; |
| 130 void OnFocus() override; | 110 void OnFocus() override; |
| 131 | 111 |
| 132 ViewClickListener* listener_ = nullptr; | 112 ViewClickListener* listener_ = nullptr; |
| 133 views::Label* text_label_ = nullptr; | 113 views::Label* text_label_ = nullptr; |
| 134 views::Label* sub_text_label_ = nullptr; | 114 views::Label* sub_text_label_ = nullptr; |
| 135 views::BoxLayout* box_layout_ = nullptr; | |
| 136 views::ImageView* left_icon_ = nullptr; | 115 views::ImageView* left_icon_ = nullptr; |
| 137 views::View* right_view_ = nullptr; | 116 views::View* right_view_ = nullptr; |
| 138 TriView* tri_view_ = nullptr; | 117 TriView* tri_view_ = nullptr; |
| 139 SkColor text_default_color_ = 0; | |
| 140 bool expandable_ = false; | 118 bool expandable_ = false; |
| 141 int custom_height_ = 0; | |
| 142 AccessibilityState accessibility_state_ = AccessibilityState::DEFAULT; | 119 AccessibilityState accessibility_state_ = AccessibilityState::DEFAULT; |
| 143 base::string16 tooltip_; | |
| 144 | 120 |
| 145 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); | 121 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView); |
| 146 }; | 122 }; |
| 147 | 123 |
| 148 } // namespace ash | 124 } // namespace ash |
| 149 | 125 |
| 150 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ | 126 #endif // ASH_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_ |
| OLD | NEW |