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

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

Issue 1470783002: Fix two issues with HoverHighlightView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « no previous file | 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/system/tray/hover_highlight_view.h" 5 #include "ash/system/tray/hover_highlight_view.h"
6 6
7 #include "ash/system/tray/fixed_sized_image_view.h" 7 #include "ash/system/tray/fixed_sized_image_view.h"
8 #include "ash/system/tray/tray_constants.h" 8 #include "ash/system/tray/tray_constants.h"
9 #include "ash/system/tray/view_click_listener.h" 9 #include "ash/system/tray/view_click_listener.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 kTrayPopupPaddingBetweenItems)); 66 kTrayPopupPaddingBetweenItems));
67 DoAddIconAndLabel(image, text, highlight); 67 DoAddIconAndLabel(image, text, highlight);
68 } 68 }
69 69
70 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image, 70 void HoverHighlightView::DoAddIconAndLabel(const gfx::ImageSkia& image,
71 const base::string16& text, 71 const base::string16& text,
72 bool highlight) { 72 bool highlight) {
73 views::ImageView* image_view = 73 views::ImageView* image_view =
74 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0); 74 new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
75 image_view->SetImage(image); 75 image_view->SetImage(image);
76 image_view->SetEnabled(enabled());
76 AddChildView(image_view); 77 AddChildView(image_view);
77 78
78 text_label_ = new views::Label(text); 79 text_label_ = new views::Label(text);
79 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 80 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
80 text_label_->SetFontList(GetFontList(highlight)); 81 text_label_->SetFontList(GetFontList(highlight));
81 if (text_default_color_) 82 if (text_default_color_)
82 text_label_->SetEnabledColor(text_default_color_); 83 text_label_->SetEnabledColor(text_default_color_);
84 text_label_->SetEnabled(enabled());
83 AddChildView(text_label_); 85 AddChildView(text_label_);
84 86
85 SetAccessibleName(text); 87 SetAccessibleName(text);
86 } 88 }
87 89
88 views::Label* HoverHighlightView::AddLabel(const base::string16& text, 90 views::Label* HoverHighlightView::AddLabel(const base::string16& text,
89 gfx::HorizontalAlignment alignment, 91 gfx::HorizontalAlignment alignment,
90 bool highlight) { 92 bool highlight) {
91 SetLayoutManager(new views::FillLayout()); 93 SetLayoutManager(new views::FillLayout());
92 text_label_ = new views::Label(text); 94 text_label_ = new views::Label(text);
93 int left_margin = kTrayPopupPaddingHorizontal; 95 int left_margin = kTrayPopupPaddingHorizontal;
94 int right_margin = kTrayPopupPaddingHorizontal; 96 int right_margin = kTrayPopupPaddingHorizontal;
95 if (alignment != gfx::ALIGN_CENTER) { 97 if (alignment != gfx::ALIGN_CENTER) {
96 if (base::i18n::IsRTL()) 98 if (base::i18n::IsRTL())
97 right_margin += kTrayPopupDetailsLabelExtraLeftMargin; 99 right_margin += kTrayPopupDetailsLabelExtraLeftMargin;
98 else 100 else
99 left_margin += kTrayPopupDetailsLabelExtraLeftMargin; 101 left_margin += kTrayPopupDetailsLabelExtraLeftMargin;
100 } 102 }
101 text_label_->SetBorder( 103 text_label_->SetBorder(
102 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); 104 views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
103 text_label_->SetHorizontalAlignment(alignment); 105 text_label_->SetHorizontalAlignment(alignment);
104 text_label_->SetFontList(GetFontList(highlight)); 106 text_label_->SetFontList(GetFontList(highlight));
105 // Do not set alpha value in disable color. It will have issue with elide 107 // Do not set alpha value in disable color. It will have issue with elide
106 // blending filter in disabled state for rendering label text color. 108 // blending filter in disabled state for rendering label text color.
107 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127)); 109 text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
108 if (text_default_color_) 110 if (text_default_color_)
109 text_label_->SetEnabledColor(text_default_color_); 111 text_label_->SetEnabledColor(text_default_color_);
112 text_label_->SetEnabled(enabled());
110 AddChildView(text_label_); 113 AddChildView(text_label_);
111 114
112 SetAccessibleName(text); 115 SetAccessibleName(text);
113 return text_label_; 116 return text_label_;
114 } 117 }
115 118
116 views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text, 119 views::Label* HoverHighlightView::AddCheckableLabel(const base::string16& text,
117 bool highlight, 120 bool highlight,
118 bool checked) { 121 bool checked) {
119 checkable_ = true; 122 checkable_ = true;
120 checked_ = checked; 123 checked_ = checked;
121 if (checked) { 124 if (checked) {
122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
123 const gfx::ImageSkia* check = 126 const gfx::ImageSkia* check =
124 rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia(); 127 rb.GetImageNamed(IDR_MENU_CHECK).ToImageSkia();
125 int margin = kTrayPopupPaddingHorizontal + 128 int margin = kTrayPopupPaddingHorizontal +
126 kTrayPopupDetailsLabelExtraLeftMargin - kCheckLabelPadding; 129 kTrayPopupDetailsLabelExtraLeftMargin - kCheckLabelPadding;
127 SetLayoutManager(new views::BoxLayout( 130 SetLayoutManager(new views::BoxLayout(
128 views::BoxLayout::kHorizontal, 0, 3, kCheckLabelPadding)); 131 views::BoxLayout::kHorizontal, 0, 3, kCheckLabelPadding));
129 views::ImageView* image_view = new FixedSizedImageView(margin, 0); 132 views::ImageView* image_view = new FixedSizedImageView(margin, 0);
130 image_view->SetImage(check); 133 image_view->SetImage(check);
131 image_view->SetHorizontalAlignment(views::ImageView::TRAILING); 134 image_view->SetHorizontalAlignment(views::ImageView::TRAILING);
135 image_view->SetEnabled(enabled());
132 AddChildView(image_view); 136 AddChildView(image_view);
133 137
134 text_label_ = new views::Label(text); 138 text_label_ = new views::Label(text);
135 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 139 text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
136 text_label_->SetFontList(GetFontList(highlight)); 140 text_label_->SetFontList(GetFontList(highlight));
137 text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); 141 text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0));
138 if (text_default_color_) 142 if (text_default_color_)
139 text_label_->SetEnabledColor(text_default_color_); 143 text_label_->SetEnabledColor(text_default_color_);
144 text_label_->SetEnabled(enabled());
140 AddChildView(text_label_); 145 AddChildView(text_label_);
141 146
142 SetAccessibleName(text); 147 SetAccessibleName(text);
143 return text_label_; 148 return text_label_;
144 } 149 }
145 return AddLabel(text, gfx::ALIGN_LEFT, highlight); 150 return AddLabel(text, gfx::ALIGN_LEFT, highlight);
146 } 151 }
147 152
148 void HoverHighlightView::SetExpandable(bool expandable) { 153 void HoverHighlightView::SetExpandable(bool expandable) {
149 if (expandable != expandable_) { 154 if (expandable != expandable_) {
150 expandable_ = expandable; 155 expandable_ = expandable;
151 InvalidateLayout(); 156 InvalidateLayout();
152 } 157 }
153 } 158 }
154 159
155 void HoverHighlightView::SetHoverHighlight(bool hover) { 160 void HoverHighlightView::SetHoverHighlight(bool hover) {
161 if (!enabled() && hover)
162 return;
156 if (hover_ == hover) 163 if (hover_ == hover)
157 return; 164 return;
158 hover_ = hover; 165 hover_ = hover;
159 if (!text_label_) 166 if (!text_label_)
160 return; 167 return;
161 if (hover_ && text_highlight_color_) 168 if (hover_ && text_highlight_color_)
162 text_label_->SetEnabledColor(text_highlight_color_); 169 text_label_->SetEnabledColor(text_highlight_color_);
163 if (!hover_ && text_default_color_) 170 if (!hover_ && text_default_color_)
164 text_label_->SetEnabledColor(text_default_color_); 171 text_label_->SetEnabledColor(text_default_color_);
165 SchedulePaint(); 172 SchedulePaint();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 218 }
212 } 219 }
213 ActionableView::OnGestureEvent(event); 220 ActionableView::OnGestureEvent(event);
214 } 221 }
215 222
216 void HoverHighlightView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 223 void HoverHighlightView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
217 SetHoverHighlight(IsMouseHovered()); 224 SetHoverHighlight(IsMouseHovered());
218 } 225 }
219 226
220 void HoverHighlightView::OnEnabledChanged() { 227 void HoverHighlightView::OnEnabledChanged() {
228 if (!enabled())
229 SetHoverHighlight(false);
221 for (int i = 0; i < child_count(); ++i) 230 for (int i = 0; i < child_count(); ++i)
222 child_at(i)->SetEnabled(enabled()); 231 child_at(i)->SetEnabled(enabled());
223 } 232 }
224 233
225 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { 234 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) {
226 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); 235 canvas->DrawColor(hover_ ? highlight_color_ : default_color_);
227 } 236 }
228 237
229 void HoverHighlightView::OnFocus() { 238 void HoverHighlightView::OnFocus() {
230 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); 239 ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
231 ActionableView::OnFocus(); 240 ActionableView::OnFocus();
232 } 241 }
233 242
234 } // namespace ash 243 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698