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

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: 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_);
64 DCHECK(tri_view_);
Evan Stade 2017/04/04 17:18:18 nit: chromium style suggests not DCHECKing in this
tdanderson 2017/04/04 18:45:06 Agreed, and done. However I don't see any explicit
Evan Stade 2017/04/05 13:56:43 I guess it doesn't say this directly. It just says
75 65
76 right_view_ = view; 66 right_view_ = view;
77 right_view_->SetEnabled(enabled()); 67 right_view_->SetEnabled(enabled());
78 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 68 tri_view_->AddView(TriView::Container::END, right_view_);
79 DCHECK(tri_view_); 69 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 } 70 }
87 71
88 // TODO(tdanderson): Ensure all checkable detailed view rows use this 72 // TODO(tdanderson): Ensure all checkable detailed view rows use this
89 // mechanism, and share the code that sets the accessible state for 73 // mechanism, and share the code that sets the accessible state for
90 // a checkbox. See crbug.com/652674. 74 // a checkbox. See crbug.com/652674.
91 void HoverHighlightView::SetRightViewVisible(bool visible) { 75 void HoverHighlightView::SetRightViewVisible(bool visible) {
92 if (!right_view_) 76 if (!right_view_)
93 return; 77 return;
94 78
95 right_view_->SetVisible(visible); 79 right_view_->SetVisible(visible);
96 Layout(); 80 Layout();
97 } 81 }
98 82
99 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, 83 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image,
100 const base::string16& text, 84 const base::string16& text) {
101 bool highlight) { 85 DoAddIconAndLabel(image, text,
102 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 86 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 } 87 }
113 88
114 void HoverHighlightView::AddIconAndLabels(const gfx::ImageSkia& image, 89 void HoverHighlightView::AddIconAndLabels(const gfx::ImageSkia& image,
115 const base::string16& text, 90 const base::string16& text,
116 const base::string16& sub_text) { 91 const base::string16& sub_text) {
117 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial()); 92 DoAddIconAndLabels(image, text,
118 DoAddIconAndLabelsMd(image, text, 93 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL,
119 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL, 94 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 } 95 }
140 96
141 void HoverHighlightView::AddIconAndLabelForDefaultView( 97 void HoverHighlightView::AddIconAndLabelForDefaultView(
142 const gfx::ImageSkia& image, 98 const gfx::ImageSkia& image,
143 const base::string16& text, 99 const base::string16& text) {
144 bool highlight) { 100 DoAddIconAndLabel(image, text,
145 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 101 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 } 102 }
155 103
156 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, 104 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, 105 const gfx::ImageSkia& image,
182 const base::string16& text, 106 const base::string16& text,
183 TrayPopupItemStyle::FontStyle font_style) { 107 TrayPopupItemStyle::FontStyle font_style) {
184 DoAddIconAndLabelsMd(image, text, font_style, base::string16()); 108 DoAddIconAndLabels(image, text, font_style, base::string16());
185 } 109 }
186 110
187 void HoverHighlightView::DoAddIconAndLabelsMd( 111 void HoverHighlightView::DoAddIconAndLabels(
188 const gfx::ImageSkia& image, 112 const gfx::ImageSkia& image,
189 const base::string16& text, 113 const base::string16& text,
190 TrayPopupItemStyle::FontStyle font_style, 114 TrayPopupItemStyle::FontStyle font_style,
191 const base::string16& sub_text) { 115 const base::string16& sub_text) {
192 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial());
193
194 SetLayoutManager(new views::FillLayout); 116 SetLayoutManager(new views::FillLayout);
195 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); 117 tri_view_ = TrayPopupUtils::CreateDefaultRowView();
196 AddChildView(tri_view_); 118 AddChildView(tri_view_);
197 119
198 left_icon_ = TrayPopupUtils::CreateMainImageView(); 120 left_icon_ = TrayPopupUtils::CreateMainImageView();
199 left_icon_->SetImage(image); 121 left_icon_->SetImage(image);
200 left_icon_->SetEnabled(enabled()); 122 left_icon_->SetEnabled(enabled());
201 tri_view_->AddView(TriView::Container::START, left_icon_); 123 tri_view_->AddView(TriView::Container::START, left_icon_);
202 124
203 text_label_ = TrayPopupUtils::CreateDefaultLabel(); 125 text_label_ = TrayPopupUtils::CreateDefaultLabel();
(...skipping 10 matching lines...) Expand all
214 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); 136 sub_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE);
215 sub_style.SetupLabel(sub_text_label_); 137 sub_style.SetupLabel(sub_text_label_);
216 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_); 138 tri_view_->AddView(TriView::Container::CENTER, sub_text_label_);
217 } 139 }
218 140
219 tri_view_->SetContainerVisible(TriView::Container::END, false); 141 tri_view_->SetContainerVisible(TriView::Container::END, false);
220 142
221 SetAccessibleName(text); 143 SetAccessibleName(text);
222 } 144 }
223 145
224 views::Label* HoverHighlightView::AddLabel(const base::string16& text, 146 views::Label* HoverHighlightView::AddLabelDeprecated(
225 gfx::HorizontalAlignment alignment, 147 const base::string16& text,
226 bool highlight) { 148 gfx::HorizontalAlignment alignment,
149 bool highlight) {
227 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 150 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
228 SetLayoutManager(box_layout_); 151 SetLayoutManager(box_layout_);
229 text_label_ = new views::Label(text); 152 text_label_ = new views::Label(text);
230 int left_margin = kTrayPopupPaddingHorizontal; 153 int left_margin = kTrayPopupPaddingHorizontal;
231 int right_margin = kTrayPopupPaddingHorizontal; 154 int right_margin = kTrayPopupPaddingHorizontal;
232 if (alignment != gfx::ALIGN_CENTER) { 155 if (alignment != gfx::ALIGN_CENTER) {
233 if (base::i18n::IsRTL()) 156 if (base::i18n::IsRTL())
234 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; 157 right_margin += kTrayPopupDetailsLabelExtraLeftMargin;
235 else 158 else
236 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; 159 left_margin += kTrayPopupDetailsLabelExtraLeftMargin;
237 } 160 }
238 text_label_->SetBorder( 161 text_label_->SetBorder(
239 views::CreateEmptyBorder(5, left_margin, 5, right_margin)); 162 views::CreateEmptyBorder(5, left_margin, 5, right_margin));
240 text_label_->SetHorizontalAlignment(alignment); 163 text_label_->SetHorizontalAlignment(alignment);
241 text_label_->SetFontList(GetFontList(highlight)); 164 text_label_->SetFontList(GetFontList(highlight));
242 // Do not set alpha value in disable color. It will have issue with elide 165 // 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. 166 // blending filter in disabled state for rendering label text color.
244 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); 167 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
245 if (text_default_color_) 168 if (text_default_color_)
246 text_label_->SetEnabledColor(text_default_color_); 169 text_label_->SetEnabledColor(text_default_color_);
247 text_label_->SetEnabled(enabled()); 170 text_label_->SetEnabled(enabled());
248 AddChildView(text_label_); 171 AddChildView(text_label_);
249 box_layout_->SetFlexForView(text_label_, 1); 172 box_layout_->SetFlexForView(text_label_, 1);
250 173
251 SetAccessibleName(text); 174 SetAccessibleName(text);
252 return text_label_; 175 return text_label_;
253 } 176 }
254 177
255 void HoverHighlightView::AddLabelRowMd(const base::string16& text) { 178 void HoverHighlightView::AddLabelRow(const base::string16& text) {
256 DCHECK(MaterialDesignController::IsSystemTrayMenuMaterial());
257
258 SetLayoutManager(new views::FillLayout); 179 SetLayoutManager(new views::FillLayout);
259 tri_view_ = TrayPopupUtils::CreateDefaultRowView(); 180 tri_view_ = TrayPopupUtils::CreateDefaultRowView();
260 AddChildView(tri_view_); 181 AddChildView(tri_view_);
261 182
262 text_label_ = TrayPopupUtils::CreateDefaultLabel(); 183 text_label_ = TrayPopupUtils::CreateDefaultLabel();
263 text_label_->SetText(text); 184 text_label_->SetText(text);
264 185
265 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); 186 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
266 style.SetupLabel(text_label_); 187 style.SetupLabel(text_label_);
267 tri_view_->AddView(TriView::Container::CENTER, text_label_); 188 tri_view_->AddView(TriView::Container::CENTER, text_label_);
268 189
269 SetAccessibleName(text); 190 SetAccessibleName(text);
270 } 191 }
271 192
272 void HoverHighlightView::SetExpandable(bool expandable) { 193 void HoverHighlightView::SetExpandable(bool expandable) {
273 if (expandable != expandable_) { 194 if (expandable != expandable_) {
274 expandable_ = expandable; 195 expandable_ = expandable;
275 InvalidateLayout(); 196 InvalidateLayout();
276 } 197 }
277 } 198 }
278 199
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( 200 void HoverHighlightView::SetAccessiblityState(
290 AccessibilityState accessibility_state) { 201 AccessibilityState accessibility_state) {
291 accessibility_state_ = accessibility_state; 202 accessibility_state_ = accessibility_state;
292 if (accessibility_state_ != AccessibilityState::DEFAULT) 203 if (accessibility_state_ != AccessibilityState::DEFAULT)
293 NotifyAccessibilityEvent(ui::AX_EVENT_CHECKED_STATE_CHANGED, true); 204 NotifyAccessibilityEvent(ui::AX_EVENT_CHECKED_STATE_CHANGED, true);
294 } 205 }
295 206
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) { 207 bool HoverHighlightView::PerformAction(const ui::Event& event) {
316 if (!listener_) 208 if (!listener_)
317 return false; 209 return false;
318 listener_->OnViewClicked(this); 210 listener_->OnViewClicked(this);
319 return true; 211 return true;
320 } 212 }
321 213
322 void HoverHighlightView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 214 void HoverHighlightView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
323 ActionableView::GetAccessibleNodeData(node_data); 215 ActionableView::GetAccessibleNodeData(node_data);
324 216
(...skipping 14 matching lines...) Expand all
339 else if (!expandable_ || size.height() < kTrayPopupItemMinHeight) 231 else if (!expandable_ || size.height() < kTrayPopupItemMinHeight)
340 size.set_height(kTrayPopupItemMinHeight); 232 size.set_height(kTrayPopupItemMinHeight);
341 233
342 return size; 234 return size;
343 } 235 }
344 236
345 int HoverHighlightView::GetHeightForWidth(int width) const { 237 int HoverHighlightView::GetHeightForWidth(int width) const {
346 return GetPreferredSize().height(); 238 return GetPreferredSize().height();
347 } 239 }
348 240
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() { 241 void HoverHighlightView::OnEnabledChanged() {
372 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { 242 if (left_icon_)
373 if (left_icon_) 243 left_icon_->SetEnabled(enabled());
374 left_icon_->SetEnabled(enabled()); 244 if (text_label_)
375 if (text_label_) 245 text_label_->SetEnabled(enabled());
376 text_label_->SetEnabled(enabled()); 246 if (right_view_)
377 if (right_view_) 247 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 } 248 }
390 249
391 void HoverHighlightView::OnFocus() { 250 void HoverHighlightView::OnFocus() {
392 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); 251 ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
393 ActionableView::OnFocus(); 252 ActionableView::OnFocus();
394 } 253 }
395 254
396 } // namespace ash 255 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698