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

Side by Side Diff: ash/common/system/tray/hover_highlight_view.h

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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 2013 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 #ifndef ASH_COMMON_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
6 #define ASH_COMMON_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
7
8 #include "ash/common/system/tray/actionable_view.h"
9 #include "ash/common/system/tray/tray_popup_item_style.h"
10 #include "base/macros.h"
11 #include "ui/gfx/font.h"
12 #include "ui/gfx/text_constants.h"
13
14 namespace views {
15 class ImageView;
16 class Label;
17 class BoxLayout;
18 }
19
20 namespace ash {
21 class TriView;
22 class ViewClickListener;
23
24 // 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
26 // maintain a fixed height.
27 class HoverHighlightView : public ActionableView {
28 public:
29 enum class AccessibilityState {
30 // The default accessibility view.
31 DEFAULT,
32 // This view is a checked checkbox.
33 CHECKED_CHECKBOX,
34 // This view is an unchecked checkbox.
35 UNCHECKED_CHECKBOX
36 };
37
38 explicit HoverHighlightView(ViewClickListener* listener);
39 ~HoverHighlightView() override;
40
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
46 // accessible name. Primarily used for scrollable rows in detailed views.
47 void AddIconAndLabel(const gfx::ImageSkia& image,
48 const base::string16& text,
49 bool highlight);
50
51 // Convenience function for adding an icon, a main label, and a sub label.
52 // This also sets the accessible name besed on the main label. Used for
53 // scrollable rows in detailed views in material design.
54 void AddIconAndLabels(const gfx::ImageSkia& image,
55 const base::string16& text,
56 const base::string16& sub_text);
57
58 // Convenience function for adding an icon and a label. This also sets the
59 // accessible name. This method allows the indent and spacing between elements
60 // to be set by the caller. |icon_size| is the size of the icon. |indent| is
61 // the distance between the edges of the view and the icons, and
62 // |space_between_items| is the minimum distance between any two child views.
63 // All distances are in DP. Primarily used for scrollable rows in detailed
64 // views.
65 void AddIconAndLabelCustomSize(const gfx::ImageSkia& image,
66 const base::string16& text,
67 bool highlight,
68 int icon_size,
69 int indent,
70 int space_between_items);
71
72 // A convenience function for adding an icon and label for a system menu
73 // default view row.
74 void AddIconAndLabelForDefaultView(const gfx::ImageSkia& image,
75 const base::string16& text,
76 bool highlight);
77
78 // Convenience function for adding a label with padding on the left for a
79 // blank icon. This also sets the accessible name. Returns label after
80 // parenting it.
81 views::Label* AddLabel(const base::string16& text,
82 gfx::HorizontalAlignment alignment,
83 bool highlight);
84
85 // Adds a row containing only a text label, inset on the left by the
86 // horizontal space that would normally be occupied by an icon.
87 void AddLabelRowMd(const base::string16& text);
88
89 // Add an optional right icon to an already established view (call one of
90 // the other Add* functions first). |icon_size| is the size of the icon in DP.
91 void AddRightIcon(const gfx::ImageSkia& image, int icon_size);
92
93 // Add an optional right view to an already established view (call one of
94 // the other Add* functions first).
95 void AddRightView(views::View* view);
96
97 // Hide or show the right view.
98 void SetRightViewVisible(bool visible);
99
100 // Allows view to expand its height.
101 // Size of unexapandable view is fixed and equals to kTrayPopupItemHeight.
102 void SetExpandable(bool expandable);
103
104 // Enables or disable highlighting on the label, where a highlighted label
105 // just uses a bold font.
106 void SetHighlight(bool hightlight);
107
108 // Set a custom height for the view. A value of 0 means that no custom height
109 // is set.
110 void set_custom_height(int custom_height) { custom_height_ = custom_height; }
111
112 // Changes the view's current accessibility state. This will fire an
113 // accessibility event if needed.
114 void SetAccessiblityState(AccessibilityState accessibility_state);
115
116 void set_highlight_color(SkColor color) { highlight_color_ = color; }
117 void set_default_color(SkColor color) { default_color_ = color; }
118 void set_text_highlight_color(SkColor c) { text_highlight_color_ = c; }
119 void set_text_default_color(SkColor color) { text_default_color_ = color; }
120
121 views::Label* text_label() { return text_label_; }
122 views::Label* sub_text_label() { return sub_text_label_; }
123
124 bool hover() const { return hover_; }
125
126 void set_tooltip(const base::string16& tooltip) { tooltip_ = tooltip; }
127
128 protected:
129 // Overridden from views::View.
130 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
131
132 // Sets the highlighted color on a text label if |hover| is set.
133 void SetHoverHighlight(bool hover);
134
135 TriView* tri_view() { return tri_view_; }
136
137 private:
138 // Actually adds the icon and label but does not set the layout manager.
139 // Not used in material design.
140 void DoAddIconAndLabel(const gfx::ImageSkia& image,
141 int icon_size,
142 const base::string16& text,
143 bool highlight);
144
145 // Adds the image and label to the row with the label being styled using
146 // |font_style|. Only used in material design.
147 void DoAddIconAndLabelMd(const gfx::ImageSkia& image,
148 const base::string16& text,
149 TrayPopupItemStyle::FontStyle font_style);
150
151 // Adds the image, main label and sub label to the row with the main label
152 // being styled using |font_style| and the sub label being styled using
153 // FontStyle::CAPTION and ColorStyle::INACTIVE. Only used in material design.
154 void DoAddIconAndLabelsMd(const gfx::ImageSkia& image,
155 const base::string16& text,
156 TrayPopupItemStyle::FontStyle font_style,
157 const base::string16& sub_text);
158
159 // Overridden from ActionableView:
160 bool PerformAction(const ui::Event& event) override;
161
162 // Overridden from views::View.
163 gfx::Size GetPreferredSize() const override;
164 int GetHeightForWidth(int width) const override;
165 void OnMouseEntered(const ui::MouseEvent& event) override;
166 void OnMouseExited(const ui::MouseEvent& event) override;
167 void OnGestureEvent(ui::GestureEvent* event) override;
168 void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
169 void OnEnabledChanged() override;
170 void OnPaintBackground(gfx::Canvas* canvas) override;
171 void OnFocus() override;
172
173 ViewClickListener* listener_ = nullptr;
174 views::Label* text_label_ = nullptr;
175 views::Label* sub_text_label_ = nullptr;
176 views::BoxLayout* box_layout_ = nullptr; // Not used in material design.
177 views::ImageView* left_icon_ = nullptr;
178 views::View* right_view_ = nullptr;
179 TriView* tri_view_ = nullptr; // Only used in material design.
180 SkColor highlight_color_ = 0; // Not used in material design.
181 SkColor default_color_ = 0;
182 SkColor text_highlight_color_ = 0; // Not used in material design.
183 SkColor text_default_color_ = 0; // Not used in material design.
184 bool hover_ = false; // Not used in material design.
185 bool expandable_ = false;
186 int custom_height_ = 0; // Not used in material design.
187 AccessibilityState accessibility_state_ = AccessibilityState::DEFAULT;
188 base::string16 tooltip_;
189
190 DISALLOW_COPY_AND_ASSIGN(HoverHighlightView);
191 };
192
193 } // namespace ash
194
195 #endif // ASH_COMMON_SYSTEM_TRAY_HOVER_HIGHLIGHT_VIEW_H_
OLDNEW
« no previous file with comments | « ash/common/system/tray/fixed_sized_image_view.cc ('k') | ash/common/system/tray/hover_highlight_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698