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

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

Issue 2795143005: [Ash] Remove pre-MD code paths from HoverHighlightView (Closed)
Patch Set: estade comments Created 3 years, 8 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 #include "ash/common/system/tray/hover_highlight_view.h" 5 #include "ash/common/system/tray/hover_highlight_view.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/system/tray/fixed_sized_image_view.h"
9 #include "ash/common/system/tray/tray_constants.h" 7 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/tray_popup_utils.h" 8 #include "ash/common/system/tray/tray_popup_utils.h"
11 #include "ash/common/system/tray/tri_view.h" 9 #include "ash/common/system/tray/tri_view.h"
12 #include "ash/common/system/tray/view_click_listener.h" 10 #include "ash/common/system/tray/view_click_listener.h"
13 #include "ash/resources/vector_icons/vector_icons.h" 11 #include "ash/resources/vector_icons/vector_icons.h"
14 #include "ui/accessibility/ax_node_data.h" 12 #include "ui/accessibility/ax_node_data.h"
15 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/font_list.h" 15 #include "ui/gfx/font_list.h"
18 #include "ui/gfx/paint_vector_icon.h" 16 #include "ui/gfx/paint_vector_icon.h"
(...skipping 11 matching lines...) Expand all
30 return ui::ResourceBundle::GetSharedInstance().GetFontList( 28 return ui::ResourceBundle::GetSharedInstance().GetFontList(
31 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont); 29 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont);
32 } 30 }
33 31
34 } // namespace 32 } // namespace
35 33
36 namespace ash { 34 namespace ash {
37 35
38 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) 36 HoverHighlightView::HoverHighlightView(ViewClickListener* listener)
39 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS), 37 : ActionableView(nullptr, TrayPopupInkDropStyle::FILL_BOUNDS),
40 listener_(listener), 38 listener_(listener) {
41 highlight_color_(kHoverBackgroundColor) {
42 set_notify_enter_exit_on_child(true); 39 set_notify_enter_exit_on_child(true);
43 if (MaterialDesignController::IsSystemTrayMenuMaterial()) 40 SetInkDropMode(InkDropHostView::InkDropMode::ON);
44 SetInkDropMode(InkDropHostView::InkDropMode::ON);
45 } 41 }
46 42
47 HoverHighlightView::~HoverHighlightView() {} 43 HoverHighlightView::~HoverHighlightView() {}
48 44
49 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, 45 bool HoverHighlightView::GetTooltipText(const gfx::Point& p,
50 base::string16* tooltip) const { 46 base::string16* tooltip) const {
51 if (tooltip_.empty()) 47 if (tooltip_.empty())
52 return false; 48 return false;
53 *tooltip = tooltip_; 49 *tooltip = tooltip_;
54 return true; 50 return true;
55 } 51 }
56 52
57 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image, 53 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image,
58 int icon_size) { 54 int icon_size) {
59 DCHECK(!right_view_); 55 DCHECK(!right_view_);
60 56
61 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 57 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView();
62 views::ImageView* right_icon = TrayPopupUtils::CreateMainImageView();
63 right_icon->SetImage(image);
64 AddRightView(right_icon);
65 return;
66 }
67
68 views::ImageView* right_icon = new FixedSizedImageView(icon_size, icon_size);
69 right_icon->SetImage(image); 58 right_icon->SetImage(image);
70 AddRightView(right_icon); 59 AddRightView(right_icon);
71 } 60 }
72 61
73 void HoverHighlightView::AddRightView(views::View* view) { 62 void HoverHighlightView::AddRightView(views::View* view) {
74 DCHECK(!right_view_); 63 DCHECK(!right_view_);
75 64
76 right_view_ = view; 65 right_view_ = view;
77 right_view_->SetEnabled(enabled()); 66 right_view_->SetEnabled(enabled());
78 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 67 tri_view_->AddView(TriView::Container::END, right_view_);
79 DCHECK(tri_view_); 68 tri_view_->SetContainerVisible(TriView::Container::END, true);
80 tri_view_->AddView(TriView::Container::END, right_view_);
81 tri_view_->SetContainerVisible(TriView::Container::END, true);
82 return;
83 }
84 DCHECK(box_layout_);
85 AddChildView(right_view_);
86 } 69 }
87 70
88 // TODO(tdanderson): Ensure all checkable detailed view rows use this 71 // TODO(tdanderson): Ensure all checkable detailed view rows use this
89 // mechanism, and share the code that sets the accessible state for 72 // mechanism, and share the code that sets the accessible state for
90 // a checkbox. See crbug.com/652674. 73 // a checkbox. See crbug.com/652674.
91 void HoverHighlightView::SetRightViewVisible(bool visible) { 74 void HoverHighlightView::SetRightViewVisible(bool visible) {
92 if (!right_view_) 75 if (!right_view_)
93 return; 76 return;
94 77
95 right_view_->SetVisible(visible); 78 right_view_->SetVisible(visible);
96 Layout(); 79 Layout();
97 } 80 }
98 81
99 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, 82 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image,
100 const base::string16& text, 83 const base::string16& text) {
101 bool highlight) { 84 DoAddIconAndLabel(image, text,
102 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 85 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
103 DoAddIconAndLabelMd(image, text,
104 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
105 return;
106 }
107
108 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3,
109 kTrayPopupPaddingBetweenItems);
110 SetLayoutManager(box_layout_);
111 DoAddIconAndLabel(image, kTrayPopupDetailsIconWidth, text, highlight);
112 } 86 }
113 87
114 void HoverHighlightView::AddIconAndLabels(const gfx::ImageSkia& image, 88 void HoverHighlightView::AddIconAndLabels(const gfx::ImageSkia& image,
115 const base::string16& text, 89 const base::string16& text,
116 const base::string16& sub_text) { 90 const base::string16& sub_text) {
117 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial()); 91 DoAddIconAndLabels(image, text,
118 DoAddIconAndLabelsMd(image, text, 92 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL,
119 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL, 93 sub_text);
120 sub_text);
121 }
122
123 void HoverHighlightView::AddIconAndLabelCustomSize(const gfx::ImageSkia& image,
124 const base::string16& text,
125 bool highlight,
126 int icon_size,
127 int indent,
128 int space_between_items) {
129 if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
130 DoAddIconAndLabelMd(image, text,
131 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
132 return;
133 }
134
135 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, indent, 0,
136 space_between_items);
137 SetLayoutManager(box_layout_);
138 DoAddIconAndLabel(image, icon_size, text, highlight);
139 } 94 }
140 95
141 void HoverHighlightView::AddIconAndLabelForDefaultView( 96 void HoverHighlightView::AddIconAndLabelForDefaultView(
142 const gfx::ImageSkia& image, 97 const gfx::ImageSkia& image,
143 const base::string16& text, 98 const base::string16& text) {
144 bool highlight) { 99 DoAddIconAndLabel(image, text,
145 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 100 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
146 DoAddIconAndLabelMd(image, text,
147 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
148 return;
149 }
150
151 // For non-MD, call AddIconAndLabel() so that |box_layout_| is instantiated
152 // and installed as the layout manager.
153 AddIconAndLabel(image, text, highlight);
154 } 101 }
155 102
156 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, 103 void HoverHighlightView::DoAddIconAndLabel(
157 int icon_size,
158 const base::string16& text,
159 bool highlight) {
160 DCHECK(!MaterialDesignController::IsSystemTrayMenuMaterial());
161 DCHECK(box_layout_);
162
163 views::ImageView* image_view = new FixedSizedImageView(icon_size, 0);
164 image_view->SetImage(image);
165 image_view->SetEnabled(enabled());
166 AddChildView(image_view);
167
168 text_label_ = new views::Label(text);
169 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
170 text_label_->SetFontList(GetFontList(highlight));
171 if (text_default_color_)
172 text_label_->SetEnabledColor(text_default_color_);
173 text_label_->SetEnabled(enabled());
174 AddChildView(text_label_);
175 box_layout_->SetFlexForView(text_label_, 1);
176
177 SetAccessibleName(text);
178 }
179
180 void HoverHighlightView::DoAddIconAndLabelMd(
181 const gfx::ImageSkia& image, 104 const gfx::ImageSkia& image,
182 const base::string16& text, 105 const base::string16& text,
183 TrayPopupItemStyle::FontStyle font_style) { 106 TrayPopupItemStyle::FontStyle font_style) {
184 DoAddIconAndLabelsMd(image, text, font_style, base::string16()); 107 DoAddIconAndLabels(image, text, font_style, base::string16());
185 } 108 }
186 109
187 void HoverHighlightView::DoAddIconAndLabelsMd( 110 void HoverHighlightView::DoAddIconAndLabels(
188 const gfx::ImageSkia& image, 111 const gfx::ImageSkia& image,
189 const base::string16& text, 112 const base::string16& text,
190 TrayPopupItemStyle::FontStyle font_style, 113 TrayPopupItemStyle::FontStyle font_style,
191 const base::string16& sub_text) { 114 const base::string16& sub_text) {
192 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial());
193
194 SetLayoutManager(new views::FillLayout); 115 SetLayoutManager(new views::FillLayout);
195 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); 116 tri_view_ = TrayPopupUtils::CreateDefaultRowView();
196 AddChildView(tri_view_); 117 AddChildView(tri_view_);
197 118
198 left_icon_ = TrayPopupUtils::CreateMainImageView(); 119 left_icon_ = TrayPopupUtils::CreateMainImageView();
199 left_icon_->SetImage(image); 120 left_icon_->SetImage(image);
200 left_icon_->SetEnabled(enabled()); 121 left_icon_->SetEnabled(enabled());
201 tri_view_->AddView(TriView::Container::START, left_icon_); 122 tri_view_->AddView(TriView::Container::START, left_icon_);
202 123
203 text_label_ = TrayPopupUtils::CreateDefaultLabel(); 124 text_label_ = TrayPopupUtils::CreateDefaultLabel();
(...skipping 10 matching lines...) Expand all
214 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); 135 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE);
215 sub_style.SetupLabel(sub_text_label_); 136 sub_style.SetupLabel(sub_text_label_);
216 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_); 137 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_);
217 } 138 }
218 139
219 tri_view_->SetContainerVisible(TriView::Container::END, false); 140 tri_view_->SetContainerVisible(TriView::Container::END, false);
220 141
221 SetAccessibleName(text); 142 SetAccessibleName(text);
222 } 143 }
223 144
224 views::Label* HoverHighlightView::AddLabel(const base::string16& text, 145 views::Label* HoverHighlightView::AddLabelDeprecated(
225 gfx::HorizontalAlignment alignment, 146 const base::string16& text,
226 bool highlight) { 147 gfx::HorizontalAlignment alignment,
148 bool highlight) {
227 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 149 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
228 SetLayoutManager(box_layout_); 150 SetLayoutManager(box_layout_);
229 text_label_ = new views::Label(text); 151 text_label_ = new views::Label(text);
230 int left_margin = kTrayPopupPaddingHorizontal; 152 int left_margin = kTrayPopupPaddingHorizontal;
231 int right_margin = kTrayPopupPaddingHorizontal; 153 int right_margin = kTrayPopupPaddingHorizontal;
232 if (alignment != gfx::ALIGN_CENTER) { 154 if (alignment != gfx::ALIGN_CENTER) {
233 if (base::i18n::IsRTL()) 155 if (base::i18n::IsRTL())
234 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; 156 right_margin += kTrayPopupDetailsLabelExtraLeftMargin;
235 else 157 else
236 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; 158 left_margin += kTrayPopupDetailsLabelExtraLeftMargin;
237 } 159 }
238 text_label_->SetBorder( 160 text_label_->SetBorder(
239 views::CreateEmptyBorder(5, left_margin, 5, right_margin)); 161 views::CreateEmptyBorder(5, left_margin, 5, right_margin));
240 text_label_->SetHorizontalAlignment(alignment); 162 text_label_->SetHorizontalAlignment(alignment);
241 text_label_->SetFontList(GetFontList(highlight)); 163 text_label_->SetFontList(GetFontList(highlight));
242 // Do not set alpha value in disable color. It will have issue with elide 164 // Do not set alpha value in disable color. It will have issue with elide
243 // blending filter in disabled state for rendering label text color. 165 // blending filter in disabled state for rendering label text color.
244 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); 166 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
245 if (text_default_color_) 167 if (text_default_color_)
246 text_label_->SetEnabledColor(text_default_color_); 168 text_label_->SetEnabledColor(text_default_color_);
247 text_label_->SetEnabled(enabled()); 169 text_label_->SetEnabled(enabled());
248 AddChildView(text_label_); 170 AddChildView(text_label_);
249 box_layout_->SetFlexForView(text_label_, 1); 171 box_layout_->SetFlexForView(text_label_, 1);
250 172
251 SetAccessibleName(text); 173 SetAccessibleName(text);
252 return text_label_; 174 return text_label_;
253 } 175 }
254 176
255 void HoverHighlightView::AddLabelRowMd(const base::string16& text) { 177 void HoverHighlightView::AddLabelRow(const base::string16& text) {
256 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial());
257
258 SetLayoutManager(new views::FillLayout); 178 SetLayoutManager(new views::FillLayout);
259 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); 179 tri_view_ = TrayPopupUtils::CreateDefaultRowView();
260 AddChildView(tri_view_); 180 AddChildView(tri_view_);
261 181
262 text_label_ = TrayPopupUtils::CreateDefaultLabel(); 182 text_label_ = TrayPopupUtils::CreateDefaultLabel();
263 text_label_->SetText(text); 183 text_label_->SetText(text);
264 184
265 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); 185 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
266 style.SetupLabel(text_label_); 186 style.SetupLabel(text_label_);
267 tri_view_->AddView(TriView::Container::CENTER, text_label_); 187 tri_view_->AddView(TriView::Container::CENTER, text_label_);
268 188
269 SetAccessibleName(text); 189 SetAccessibleName(text);
270 } 190 }
271 191
272 void HoverHighlightView::SetExpandable(bool expandable) { 192 void HoverHighlightView::SetExpandable(bool expandable) {
273 if (expandable != expandable_) { 193 if (expandable != expandable_) {
274 expandable_ = expandable; 194 expandable_ = expandable;
275 InvalidateLayout(); 195 InvalidateLayout();
276 } 196 }
277 } 197 }
278 198
279 void HoverHighlightView::SetHighlight(bool highlight) {
280 // Do not change the font styling for a highlighted row in material design.
281 if (MaterialDesignController::IsSystemTrayMenuMaterial())
282 return;
283
284 DCHECK(text_label_);
285 text_label_->SetFontList(GetFontList(highlight));
286 text_label_->InvalidateLayout();
287 }
288
289 void HoverHighlightView::SetAccessiblityState( 199 void HoverHighlightView::SetAccessiblityState(
290 AccessibilityState accessibility_state) { 200 AccessibilityState accessibility_state) {
291 accessibility_state_ = accessibility_state; 201 accessibility_state_ = accessibility_state;
292 if (accessibility_state_ != AccessibilityState::DEFAULT) 202 if (accessibility_state_ != AccessibilityState::DEFAULT)
293 NotifyAccessibilityEvent(ui::AX_EVENT_CHECKED_STATE_CHANGED, true); 203 NotifyAccessibilityEvent(ui::AX_EVENT_CHECKED_STATE_CHANGED, true);
294 } 204 }
295 205
296 void HoverHighlightView::SetHoverHighlight(bool hover) {
297 // We do not show any hover effects for material design.
298 if (MaterialDesignController::IsSystemTrayMenuMaterial())
299 return;
300
301 if (!enabled() && hover)
302 return;
303 if (hover_ == hover)
304 return;
305 hover_ = hover;
306 if (!text_label_)
307 return;
308 if (hover_ && text_highlight_color_)
309 text_label_->SetEnabledColor(text_highlight_color_);
310 if (!hover_ && text_default_color_)
311 text_label_->SetEnabledColor(text_default_color_);
312 SchedulePaint();
313 }
314
315 bool HoverHighlightView::PerformAction(const ui::Event& event) { 206 bool HoverHighlightView::PerformAction(const ui::Event& event) {
316 if (!listener_) 207 if (!listener_)
317 return false; 208 return false;
318 listener_->OnViewClicked(this); 209 listener_->OnViewClicked(this);
319 return true; 210 return true;
320 } 211 }
321 212
322 void HoverHighlightView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 213 void HoverHighlightView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
323 ActionableView::GetAccessibleNodeData(node_data); 214 ActionableView::GetAccessibleNodeData(node_data);
324 215
(...skipping 14 matching lines...) Expand all
339 else if (!expandable_ || size.height() < kTrayPopupItemMinHeight) 230 else if (!expandable_ || size.height() < kTrayPopupItemMinHeight)
340 size.set_height(kTrayPopupItemMinHeight); 231 size.set_height(kTrayPopupItemMinHeight);
341 232
342 return size; 233 return size;
343 } 234 }
344 235
345 int HoverHighlightView::GetHeightForWidth(int width) const { 236 int HoverHighlightView::GetHeightForWidth(int width) const {
346 return GetPreferredSize().height(); 237 return GetPreferredSize().height();
347 } 238 }
348 239
349 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) {
350 SetHoverHighlight(true);
351 }
352
353 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) {
354 SetHoverHighlight(false);
355 }
356
357 void HoverHighlightView::OnGestureEvent(ui::GestureEvent* event) {
358 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
359 SetHoverHighlight(true);
360 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL ||
361 event->type() == ui::ET_GESTURE_TAP) {
362 SetHoverHighlight(false);
363 }
364 ActionableView::OnGestureEvent(event);
365 }
366
367 void HoverHighlightView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
368 SetHoverHighlight(IsMouseHovered());
369 }
370
371 void HoverHighlightView::OnEnabledChanged() { 240 void HoverHighlightView::OnEnabledChanged() {
372 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 241 if (left_icon_)
373 if (left_icon_) 242 left_icon_->SetEnabled(enabled());
374 left_icon_->SetEnabled(enabled()); 243 if (text_label_)
375 if (text_label_) 244 text_label_->SetEnabled(enabled());
376 text_label_->SetEnabled(enabled()); 245 if (right_view_)
377 if (right_view_) 246 right_view_->SetEnabled(enabled());
378 right_view_->SetEnabled(enabled());
379 } else {
380 if (!enabled())
381 SetHoverHighlight(false);
382 for (int i = 0; i < child_count(); ++i)
383 child_at(i)->SetEnabled(enabled());
384 }
385 }
386
387 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) {
388 canvas->DrawColor(hover_ ? highlight_color_ : default_color_);
389 } 247 }
390 248
391 void HoverHighlightView::OnFocus() { 249 void HoverHighlightView::OnFocus() {
392 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); 250 ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
393 ActionableView::OnFocus(); 251 ActionableView::OnFocus();
394 } 252 }
395 253
396 } // namespace ash 254 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698