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

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

Issue 2116033002: Extend HoverHighlightView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add new HoverHighlightView APIs Created 4 years, 5 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
« no previous file with comments | « ash/common/system/tray/hover_highlight_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/system/tray/fixed_sized_image_view.h" 7 #include "ash/common/system/tray/fixed_sized_image_view.h"
8 #include "ash/common/system/tray/tray_constants.h" 8 #include "ash/common/system/tray/tray_constants.h"
9 #include "ash/common/system/tray/view_click_listener.h" 9 #include "ash/common/system/tray/view_click_listener.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
(...skipping 16 matching lines...) Expand all
27 const gfx::FontList& GetFontList(bool highlight) { 27 const gfx::FontList& GetFontList(bool highlight) {
28 return ui::ResourceBundle::GetSharedInstance().GetFontList( 28 return ui::ResourceBundle::GetSharedInstance().GetFontList(
29 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont); 29 highlight ? ui::ResourceBundle::BoldFont : ui::ResourceBundle::BaseFont);
30 } 30 }
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace ash { 34 namespace ash {
35 35
36 HoverHighlightView::HoverHighlightView(ViewClickListener* listener) 36 HoverHighlightView::HoverHighlightView(ViewClickListener* listener)
37 : listener_(listener), 37 : listener_(listener), highlight_color_(kHoverBackgroundColor) {
38 text_label_(NULL),
39 highlight_color_(kHoverBackgroundColor),
40 default_color_(0),
41 text_highlight_color_(0),
42 text_default_color_(0),
43 hover_(false),
44 expandable_(false),
45 checkable_(false),
46 checked_(false) {
47 set_notify_enter_exit_on_child(true); 38 set_notify_enter_exit_on_child(true);
48 } 39 }
49 40
50 HoverHighlightView::~HoverHighlightView() {} 41 HoverHighlightView::~HoverHighlightView() {}
51 42
52 bool HoverHighlightView::GetTooltipText(const gfx::Point& p, 43 bool HoverHighlightView::GetTooltipText(const gfx::Point& p,
53 base::string16* tooltip) const { 44 base::string16* tooltip) const {
54 if (tooltip_.empty()) 45 if (tooltip_.empty())
55 return false; 46 return false;
56 *tooltip = tooltip_; 47 *tooltip = tooltip_;
57 return true; 48 return true;
58 } 49 }
59 50
51 void HoverHighlightView::AddRightIcon(const gfx::ImageSkia& image) {
52 DCHECK(box_layout_);
stevenjb 2016/07/13 19:51:01 DCHECK(!right_icon_)
jdufault 2016/07/13 21:53:50 Done.
53
54 right_icon_ = new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
55 right_icon_->SetImage(image);
56 right_icon_->SetEnabled(enabled());
57 AddChildView(right_icon_);
58 }
59
60 void HoverHighlightView::SetRightIconVisible(bool visible) {
61 if (right_icon_) {
stevenjb 2016/07/13 19:51:01 nit: invert and early exit
jdufault 2016/07/13 21:53:50 Done.
62 right_icon_->SetVisible(visible);
63 Layout();
64 }
65 }
66
60 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image, 67 void HoverHighlightView::AddIconAndLabel(const gfx::ImageSkia& image,
61 const base::string16& text, 68 const base::string16& text,
62 bool highlight) { 69 bool highlight) {
63 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, 70 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3,
64 kTrayPopupPaddingBetweenItems)); 71 kTrayPopupPaddingBetweenItems);
72 SetLayoutManager(box_layout_);
65 DoAddIconAndLabel(image, text, highlight); 73 DoAddIconAndLabel(image, text, highlight);
66 } 74 }
67 75
68 void HoverHighlightView::AddIndentedIconAndLabel(const gfx::ImageSkia& image, 76 void HoverHighlightView::AddIndentedIconAndLabel(const gfx::ImageSkia& image,
69 const base::string16& text, 77 const base::string16& text,
70 bool highlight) { 78 bool highlight) {
71 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 79 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal,
72 kTrayPopupPaddingHorizontal, 0, 80 kTrayPopupPaddingHorizontal, 0,
73 kTrayPopupPaddingBetweenItems)); 81 kTrayPopupPaddingBetweenItems);
82 SetLayoutManager(box_layout_);
74 DoAddIconAndLabel(image, text, highlight); 83 DoAddIconAndLabel(image, text, highlight);
75 } 84 }
76 85
77 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, 86 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image,
78 const base::string16& text, 87 const base::string16& text,
79 bool highlight) { 88 bool highlight) {
89 DCHECK(box_layout_);
90
80 views::ImageView* image_view = 91 views::ImageView* image_view =
81 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); 92 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
82 image_view->SetImage(image); 93 image_view->SetImage(image);
83 image_view->SetEnabled(enabled()); 94 image_view->SetEnabled(enabled());
84 AddChildView(image_view); 95 AddChildView(image_view);
85 96
86 text_label_ = new views::Label(text); 97 text_label_ = new views::Label(text);
87 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 98 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
88 text_label_->SetFontList(GetFontList(highlight)); 99 text_label_->SetFontList(GetFontList(highlight));
89 if (text_default_color_) 100 if (text_default_color_)
90 text_label_->SetEnabledColor(text_default_color_); 101 text_label_->SetEnabledColor(text_default_color_);
91 text_label_->SetEnabled(enabled()); 102 text_label_->SetEnabled(enabled());
92 AddChildView(text_label_); 103 AddChildView(text_label_);
104 box_layout_->SetFlexForView(text_label_, 1);
93 105
94 SetAccessibleName(text); 106 SetAccessibleName(text);
95 } 107 }
96 108
97 views::Label* HoverHighlightView::AddLabel(const base::string16& text, 109 views::Label* HoverHighlightView::AddLabel(const base::string16& text,
98 gfx::HorizontalAlignment alignment, 110 gfx::HorizontalAlignment alignment,
99 bool highlight) { 111 bool highlight) {
100 SetLayoutManager(new views::FillLayout()); 112 box_layout_ = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
113 SetLayoutManager(box_layout_);
101 text_label_ = new views::Label(text); 114 text_label_ = new views::Label(text);
102 int left_margin = kTrayPopupPaddingHorizontal; 115 int left_margin = kTrayPopupPaddingHorizontal;
103 int right_margin = kTrayPopupPaddingHorizontal; 116 int right_margin = kTrayPopupPaddingHorizontal;
104 if (alignment != gfx::ALIGN_CENTER) { 117 if (alignment != gfx::ALIGN_CENTER) {
105 if (base::i18n::IsRTL()) 118 if (base::i18n::IsRTL())
106 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; 119 right_margin += kTrayPopupDetailsLabelExtraLeftMargin;
107 else 120 else
108 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; 121 left_margin += kTrayPopupDetailsLabelExtraLeftMargin;
109 } 122 }
110 text_label_->SetBorder( 123 text_label_->SetBorder(
111 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); 124 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
112 text_label_->SetHorizontalAlignment(alignment); 125 text_label_->SetHorizontalAlignment(alignment);
113 text_label_->SetFontList(GetFontList(highlight)); 126 text_label_->SetFontList(GetFontList(highlight));
114 // Do not set alpha value in disable color. It will have issue with elide 127 // Do not set alpha value in disable color. It will have issue with elide
115 // blending filter in disabled state for rendering label text color. 128 // blending filter in disabled state for rendering label text color.
116 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); 129 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
117 if (text_default_color_) 130 if (text_default_color_)
118 text_label_->SetEnabledColor(text_default_color_); 131 text_label_->SetEnabledColor(text_default_color_);
119 text_label_->SetEnabled(enabled()); 132 text_label_->SetEnabled(enabled());
120 AddChildView(text_label_); 133 AddChildView(text_label_);
134 box_layout_->SetFlexForView(text_label_, 1);
121 135
122 SetAccessibleName(text); 136 SetAccessibleName(text);
123 return text_label_; 137 return text_label_;
124 } 138 }
125 139
126 views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text, 140 views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text,
127 bool highlight, 141 bool highlight,
128 bool checked) { 142 bool checked) {
129 checkable_ = true; 143 checkable_ = true;
130 checked_ = checked; 144 checked_ = checked;
(...skipping 26 matching lines...) Expand all
157 return AddLabel(text, gfx::ALIGN_LEFT, highlight); 171 return AddLabel(text, gfx::ALIGN_LEFT, highlight);
158 } 172 }
159 173
160 void HoverHighlightView::SetExpandable(bool expandable) { 174 void HoverHighlightView::SetExpandable(bool expandable) {
161 if (expandable != expandable_) { 175 if (expandable != expandable_) {
162 expandable_ = expandable; 176 expandable_ = expandable;
163 InvalidateLayout(); 177 InvalidateLayout();
164 } 178 }
165 } 179 }
166 180
181 void HoverHighlightView::SetHighlight(bool highlight) {
182 DCHECK(text_label_);
183 text_label_->SetFontList(GetFontList(highlight));
184 text_label_->InvalidateLayout();
185 }
186
167 void HoverHighlightView::SetHoverHighlight(bool hover) { 187 void HoverHighlightView::SetHoverHighlight(bool hover) {
168 if (!enabled() && hover) 188 if (!enabled() && hover)
169 return; 189 return;
170 if (hover_ == hover) 190 if (hover_ == hover)
171 return; 191 return;
172 hover_ = hover; 192 hover_ = hover;
173 if (!text_label_) 193 if (!text_label_)
174 return; 194 return;
175 if (hover_ && text_highlight_color_) 195 if (hover_ && text_highlight_color_)
176 text_label_->SetEnabledColor(text_highlight_color_); 196 text_label_->SetEnabledColor(text_highlight_color_);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { 261 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) {
242 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); 262 canvas->DrawColor(hover_ ? highlight_color_ : default_color_);
243 } 263 }
244 264
245 void HoverHighlightView::OnFocus() { 265 void HoverHighlightView::OnFocus() {
246 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); 266 ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
247 ActionableView::OnFocus(); 267 ActionableView::OnFocus();
248 } 268 }
249 269
250 } // namespace ash 270 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/hover_highlight_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698