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

Side by Side Diff: chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc

Issue 2348853004: Remove non-md code in location bar (Views). (Closed)
Patch Set: images Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" 5 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/layout_constants.h" 8 #include "chrome/browser/ui/layout_constants.h"
9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" 9 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
10 #include "ui/base/material_design/material_design_controller.h"
11 #include "ui/base/resource/resource_bundle.h" 10 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/color_utils.h" 12 #include "ui/gfx/color_utils.h"
14 #include "ui/gfx/image/image_util.h" 13 #include "ui/gfx/image/image_util.h"
15 #include "ui/gfx/scoped_canvas.h" 14 #include "ui/gfx/scoped_canvas.h"
16 #include "ui/native_theme/native_theme.h" 15 #include "ui/native_theme/native_theme.h"
17 #include "ui/views/animation/ink_drop_highlight.h" 16 #include "ui/views/animation/ink_drop_highlight.h"
18 #include "ui/views/border.h" 17 #include "ui/views/border.h"
19 #include "ui/views/controls/image_view.h" 18 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/textfield/textfield.h" 19 #include "ui/views/controls/textfield/textfield.h"
21 #include "ui/views/painter.h" 20 #include "ui/views/painter.h"
Peter Kasting 2016/09/19 23:46:45 Nit: Maybe don't need this #include
Evan Stade 2016/09/20 17:37:03 Done.
22 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
23 22
24 namespace { 23 namespace {
25 24
26 // Amount of space on either side of the separator that appears after the label. 25 // Amount of space on either side of the separator that appears after the label.
27 constexpr int kSpaceBesideSeparator = 8; 26 constexpr int kSpaceBesideSeparator = 8;
28 27
29 SkColor CalculateImageColor(gfx::ImageSkia* image) { 28 SkColor CalculateImageColor(gfx::ImageSkia* image) {
30 // We grab the color of the middle pixel of the image, which we treat as 29 // We grab the color of the middle pixel of the image, which we treat as
31 // the representative color of the entire image (reasonable, given the current 30 // the representative color of the entire image (reasonable, given the current
32 // appearance of these assets). 31 // appearance of these assets).
33 const SkBitmap& bitmap(image->GetRepresentation(1.0f).sk_bitmap()); 32 const SkBitmap& bitmap(image->GetRepresentation(1.0f).sk_bitmap());
34 SkAutoLockPixels pixel_lock(bitmap); 33 SkAutoLockPixels pixel_lock(bitmap);
35 return bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); 34 return bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2);
36 } 35 }
37 36
38 } // namespace 37 } // namespace
39 38
40 IconLabelBubbleView::IconLabelBubbleView(int contained_image, 39 IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list,
41 const gfx::FontList& font_list,
42 SkColor parent_background_color,
43 bool elide_in_middle) 40 bool elide_in_middle)
44 : background_painter_(nullptr), 41 : image_(new views::ImageView()),
45 image_(new views::ImageView()), 42 label_(new views::Label(base::string16(), font_list)) {
46 label_(new views::Label(base::string16(), font_list)),
47 is_extension_icon_(false),
48 parent_background_color_(parent_background_color) {
49 if (contained_image) {
50 image_->SetImage(
51 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
52 contained_image));
53 }
54
55 // Disable separate hit testing for |image_|. This prevents views treating 43 // Disable separate hit testing for |image_|. This prevents views treating
56 // |image_| as a separate mouse hover region from |this|. 44 // |image_| as a separate mouse hover region from |this|.
57 image_->set_interactive(false); 45 image_->set_interactive(false);
58 AddChildView(image_); 46 AddChildView(image_);
59 47
60 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 48 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
61 49
62 if (elide_in_middle) 50 if (elide_in_middle)
63 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); 51 label_->SetElideBehavior(gfx::ELIDE_MIDDLE);
64 AddChildView(label_); 52 AddChildView(label_);
65 53
66 // Bubbles are given the full internal height of the location bar so that all 54 // Bubbles are given the full internal height of the location bar so that all
67 // child views in the location bar have the same height. The visible height of 55 // child views in the location bar have the same height. The visible height of
68 // the bubble should be smaller, so use an empty border to shrink down the 56 // the bubble should be smaller, so use an empty border to shrink down the
69 // content bounds so the background gets painted correctly. 57 // content bounds so the background gets painted correctly.
70 SetBorder(views::Border::CreateEmptyBorder( 58 SetBorder(views::Border::CreateEmptyBorder(
71 gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0))); 59 gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0)));
72 60
73 // Flip the canvas in MD RTL so the separator is drawn on the correct side. 61 // Flip the canvas in RTL so the separator is drawn on the correct side.
74 EnableCanvasFlippingForRTLUI(ui::MaterialDesignController::IsModeMaterial()); 62 EnableCanvasFlippingForRTLUI(true);
75 } 63 }
76 64
77 IconLabelBubbleView::~IconLabelBubbleView() { 65 IconLabelBubbleView::~IconLabelBubbleView() {
78 } 66 }
79 67
80 void IconLabelBubbleView::SetBackgroundImageGrid(
81 const int background_images[]) {
82 should_show_background_ = true;
83 if (!ui::MaterialDesignController::IsModeMaterial()) {
84 background_painter_.reset(
85 views::Painter::CreateImageGridPainter(background_images));
86 // Use the middle image of the background to represent the color of the
87 // entire background.
88 gfx::ImageSkia* background_image =
89 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
90 background_images[4]);
91 SetLabelBackgroundColor(CalculateImageColor(background_image));
92 }
93 OnNativeThemeChanged(GetNativeTheme());
94 }
95
96 void IconLabelBubbleView::UnsetBackgroundImageGrid() {
97 should_show_background_ = false;
98 SetLabelBackgroundColor(SK_ColorTRANSPARENT);
99 }
100
101 void IconLabelBubbleView::SetLabel(const base::string16& label) { 68 void IconLabelBubbleView::SetLabel(const base::string16& label) {
102 label_->SetText(label); 69 label_->SetText(label);
103 } 70 }
104 71
105 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { 72 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) {
106 image_->SetImage(image_skia); 73 image_->SetImage(image_skia);
107 } 74 }
108 75
109 bool IconLabelBubbleView::ShouldShowBackground() const { 76 bool IconLabelBubbleView::ShouldShowLabel() const {
110 return should_show_background_; 77 return label_->visible() && !label_->text().empty();
Peter Kasting 2016/09/19 23:46:45 Is this logic synthesized from the cases when we c
Evan Stade 2016/09/20 17:37:03 In LocationBarView, it's only called on LocationIc
111 } 78 }
112 79
113 double IconLabelBubbleView::WidthMultiplier() const { 80 double IconLabelBubbleView::WidthMultiplier() const {
114 return 1.0; 81 return 1.0;
115 } 82 }
116 83
117 bool IconLabelBubbleView::IsShrinking() const { 84 bool IconLabelBubbleView::IsShrinking() const {
118 return false; 85 return false;
119 } 86 }
120 87
(...skipping 15 matching lines...) Expand all
136 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) { 103 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) {
137 if (event.key_code() == ui::VKEY_SPACE) 104 if (event.key_code() == ui::VKEY_SPACE)
138 return OnActivate(event); 105 return OnActivate(event);
139 return false; 106 return false;
140 } 107 }
141 108
142 void IconLabelBubbleView::Layout() { 109 void IconLabelBubbleView::Layout() {
143 // Compute the image bounds. In non-MD, the leading padding depends on 110 // Compute the image bounds. In non-MD, the leading padding depends on
144 // whether this is an extension icon, since extension icons and 111 // whether this is an extension icon, since extension icons and
145 // Chrome-provided icons are different sizes. In MD, these sizes are the 112 // Chrome-provided icons are different sizes. In MD, these sizes are the
146 // same, so it's not necessary to handle the two types differently. 113 // same, so it's not necessary to handle the two types differently.
Peter Kasting 2016/09/19 23:46:45 Nit: This comment needs updating
Evan Stade 2016/09/20 17:37:04 Done.
147 const bool icon_has_enough_padding = 114 int image_x = GetOuterPadding();
148 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); 115 int bubble_trailing_padding = GetOuterPadding();
Peter Kasting 2016/09/19 23:46:45 Nit: I'd just do "bubble_trailing_padding = image_
Evan Stade 2016/09/20 17:37:04 Done.
149 int image_x = GetOuterPadding(icon_has_enough_padding);
150 int bubble_trailing_padding = GetOuterPadding(false);
151 116
152 // If ShouldShowBackground() is true, then either we show a background in the 117 // If ShouldShowLabel() is true, then either we show a label in the
153 // steady state, or we're not yet in the last portion of the animation. In 118 // steady state, or we're not yet in the last portion of the animation. In
154 // these cases, we leave the leading and trailing padding alone; we don't want 119 // these cases, we leave the leading and trailing padding alone; we don't want
155 // to let the image overlap the edge of the background, as this looks glitchy. 120 // to let the image overlap the edge of the background, as this looks glitchy.
156 // If this is false, however, then we're only showing the image, and either 121 // If this is false, however, then we're only showing the image, and either
157 // the view width is the image width, or it's animating downwards and getting 122 // the view width is the image width, or it's animating downwards and getting
158 // close to it. In these cases, we want to shrink the trailing padding first, 123 // close to it. In these cases, we want to shrink the trailing padding first,
159 // so the image slides all the way to the trailing edge before slowing or 124 // so the image slides all the way to the trailing edge before slowing or
160 // stopping; then we want to shrink the leading padding down to zero. 125 // stopping; then we want to shrink the leading padding down to zero.
161 const int image_preferred_width = image_->GetPreferredSize().width(); 126 const int image_preferred_width = image_->GetPreferredSize().width();
162 if (!ShouldShowBackground()) { 127 if (!ShouldShowLabel()) {
163 image_x = std::min(image_x, width() - image_preferred_width); 128 image_x = std::min(image_x, width() - image_preferred_width);
164 bubble_trailing_padding = std::min( 129 bubble_trailing_padding = std::min(
165 bubble_trailing_padding, width() - image_preferred_width - image_x); 130 bubble_trailing_padding, width() - image_preferred_width - image_x);
166 } 131 }
167 132
168 // Now that we've computed the padding values, give the image all the 133 // Now that we've computed the padding values, give the image all the
169 // remaining width. This will be less than the image's preferred width during 134 // remaining width. This will be less than the image's preferred width during
170 // the first portion of the animation; during the very beginning there may not 135 // the first portion of the animation; during the very beginning there may not
171 // be enough room to show the image at all. 136 // be enough room to show the image at all.
172 const int image_width = 137 const int image_width =
173 std::min(image_preferred_width, 138 std::min(image_preferred_width,
174 std::max(0, width() - image_x - bubble_trailing_padding)); 139 std::max(0, width() - image_x - bubble_trailing_padding));
175 image_->SetBounds(image_x, 0, image_width, height()); 140 image_->SetBounds(image_x, 0, image_width, height());
176 141
177 // Compute the label bounds. The label gets whatever size is left over after 142 // Compute the label bounds. The label gets whatever size is left over after
178 // accounting for the preferred image width and padding amounts. Note that if 143 // accounting for the preferred image width and padding amounts. Note that if
179 // the label has zero size it doesn't actually matter what we compute its X 144 // the label has zero size it doesn't actually matter what we compute its X
180 // value to be, since it won't be visible. 145 // value to be, since it won't be visible.
181 const int label_x = image_x + image_width + GetInternalSpacing(); 146 const int label_x = image_x + image_width + GetInternalSpacing();
182 const int label_width = 147 const int label_width =
183 std::max(0, width() - label_x - bubble_trailing_padding); 148 std::max(0, width() - label_x - bubble_trailing_padding);
184 label_->SetBounds(label_x, 0, label_width, height()); 149 label_->SetBounds(label_x, 0, label_width, height());
185 } 150 }
186 151
187 void IconLabelBubbleView::OnNativeThemeChanged( 152 void IconLabelBubbleView::OnNativeThemeChanged(
188 const ui::NativeTheme* native_theme) { 153 const ui::NativeTheme* native_theme) {
189 label_->SetEnabledColor(GetTextColor()); 154 label_->SetEnabledColor(GetTextColor());
190 155 label_->SetBackgroundColor(GetParentBackgroundColor());
191 if (ui::MaterialDesignController::IsModeMaterial()) { 156 SchedulePaint();
192 label_->SetBackgroundColor(GetParentBackgroundColor());
193 SchedulePaint();
194 }
195 } 157 }
196 158
197 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 159 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
198 image()->SetPaintToLayer(true); 160 image()->SetPaintToLayer(true);
199 image()->layer()->SetFillsBoundsOpaquely(false); 161 image()->layer()->SetFillsBoundsOpaquely(false);
200 InkDropHostView::AddInkDropLayer(ink_drop_layer); 162 InkDropHostView::AddInkDropLayer(ink_drop_layer);
201 } 163 }
202 164
203 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 165 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
204 InkDropHostView::RemoveInkDropLayer(ink_drop_layer); 166 InkDropHostView::RemoveInkDropLayer(ink_drop_layer);
205 image()->SetPaintToLayer(false); 167 image()->SetPaintToLayer(false);
206 } 168 }
207 169
208 std::unique_ptr<views::InkDropHighlight> 170 std::unique_ptr<views::InkDropHighlight>
209 IconLabelBubbleView::CreateInkDropHighlight() const { 171 IconLabelBubbleView::CreateInkDropHighlight() const {
210 // Only show a highlight effect when the label is empty/invisible. 172 // Only show a highlight effect when the label is empty/invisible.
211 return label()->visible() ? nullptr 173 return label()->visible() ? nullptr
212 : InkDropHostView::CreateInkDropHighlight(); 174 : InkDropHostView::CreateInkDropHighlight();
213 } 175 }
214 176
215 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { 177 SkColor IconLabelBubbleView::GetInkDropBaseColor() const {
216 return color_utils::DeriveDefaultIconColor(GetTextColor()); 178 return color_utils::DeriveDefaultIconColor(GetTextColor());
217 } 179 }
218 180
219 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { 181 SkColor IconLabelBubbleView::GetParentBackgroundColor() const {
220 return ui::MaterialDesignController::IsModeMaterial() 182 return GetNativeTheme()->GetSystemColor(
221 ? GetNativeTheme()->GetSystemColor( 183 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
222 ui::NativeTheme::kColorId_TextfieldDefaultBackground)
223 : parent_background_color_;
224 } 184 }
225 185
226 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { 186 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const {
227 gfx::Size size(image_->GetPreferredSize()); 187 gfx::Size size(image_->GetPreferredSize());
228 const bool shrinking = IsShrinking(); 188 const bool shrinking = IsShrinking();
229 // Animation continues for the last few pixels even after the label is not 189 // Animation continues for the last few pixels even after the label is not
230 // visible in order to slide the icon into its final position. Therefore it 190 // visible in order to slide the icon into its final position. Therefore it
231 // is necessary to animate |total_width| even when the background is hidden 191 // is necessary to animate |total_width| even when the background is hidden
232 // as long as the animation is still shrinking. 192 // as long as the animation is still shrinking.
233 if (ShouldShowBackground() || shrinking) { 193 if (ShouldShowLabel() || shrinking) {
234 // On scale factors < 2, we reserve 1 DIP for the 1 px separator. For 194 // On scale factors < 2, we reserve 1 DIP for the 1 px separator. For
235 // higher scale factors, we simply take the separator px out of the 195 // higher scale factors, we simply take the separator px out of the
236 // kSpaceBesideSeparator region before the separator, as that results in a 196 // kSpaceBesideSeparator region before the separator, as that results in a
237 // width closer to the desired gap than if we added a whole DIP for the 197 // width closer to the desired gap than if we added a whole DIP for the
238 // separator px. (For scale 2, the two methods have equal error: 1 px.) 198 // separator px. (For scale 2, the two methods have equal error: 1 px.)
239 const views::Widget* widget = GetWidget(); 199 const views::Widget* widget = GetWidget();
240 // There may be no widget in tests. 200 // There may be no widget in tests.
241 const int separator_width = 201 const int separator_width =
242 (widget && widget->GetCompositor()->device_scale_factor() >= 2) ? 0 : 1; 202 (widget && widget->GetCompositor()->device_scale_factor() >= 2) ? 0 : 1;
243 const int post_label_width = ui::MaterialDesignController::IsModeMaterial() 203 const int post_label_width =
244 ? (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()) 204 (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding());
245 : GetOuterPadding(false);
246 205
247 // |multiplier| grows from zero to one, stays equal to one and then shrinks 206 // |multiplier| grows from zero to one, stays equal to one and then shrinks
248 // to zero again. The view width should correspondingly grow from zero to 207 // to zero again. The view width should correspondingly grow from zero to
249 // fully showing both label and icon, stay there, then shrink to just large 208 // fully showing both label and icon, stay there, then shrink to just large
250 // enough to show the icon. We don't want to shrink all the way back to 209 // enough to show the icon. We don't want to shrink all the way back to
251 // zero, since this would mean the view would completely disappear and then 210 // zero, since this would mean the view would completely disappear and then
252 // pop back to an icon after the animation finishes. 211 // pop back to an icon after the animation finishes.
253 const int max_width = GetImageTrailingEdge() + GetInternalSpacing() + 212 const int max_width = GetImageTrailingEdge() + GetInternalSpacing() +
254 label_width + post_label_width; 213 label_width + post_label_width;
255 const int current_width = WidthMultiplier() * max_width; 214 const int current_width = WidthMultiplier() * max_width;
256 size.set_width(shrinking ? std::max(current_width, size.width()) 215 size.set_width(shrinking ? std::max(current_width, size.width())
257 : current_width); 216 : current_width);
258 } 217 }
259 return size; 218 return size;
260 } 219 }
261 220
262 int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const { 221 int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const {
263 return GetImageTrailingEdge() + GetOuterPadding(false); 222 return GetImageTrailingEdge() + GetOuterPadding();
264 } 223 }
265 224
266 void IconLabelBubbleView::SetLabelBackgroundColor( 225 int IconLabelBubbleView::GetOuterPadding() const {
267 SkColor chip_background_color) { 226 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
Peter Kasting 2016/09/19 23:46:45 Nit: Seems like we could just make this call direc
Evan Stade 2016/09/20 17:37:04 Done.
268 // The background images are painted atop |parent_background_color_|.
269 // Alpha-blend |chip_background_color| with |parent_background_color_| to
270 // determine the actual color the label text will sit atop.
271 // Tricky bit: We alpha blend an opaque version of |chip_background_color|
272 // against |parent_background_color_| using the original image grid color's
273 // alpha. This is because AlphaBlend(a, b, 255) always returns |a| unchanged
274 // even if |a| is a color with non-255 alpha.
275 label_->SetBackgroundColor(color_utils::AlphaBlend(
276 SkColorSetA(chip_background_color, 255), GetParentBackgroundColor(),
277 SkColorGetA(chip_background_color)));
278 }
279
280 int IconLabelBubbleView::GetOuterPadding(bool leading) const {
281 if (ui::MaterialDesignController::IsModeMaterial())
282 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
283
284 return GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) -
285 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING) +
286 (leading ? 0 : kTrailingPaddingPreMd);
287 } 227 }
288 228
289 int IconLabelBubbleView::GetImageTrailingEdge() const { 229 int IconLabelBubbleView::GetImageTrailingEdge() const {
290 return GetOuterPadding(true) + image_->GetPreferredSize().width(); 230 return GetOuterPadding() + image_->GetPreferredSize().width();
291 } 231 }
292 232
293 int IconLabelBubbleView::GetInternalSpacing() const { 233 int IconLabelBubbleView::GetInternalSpacing() const {
294 return image_->GetPreferredSize().IsEmpty() 234 return image_->GetPreferredSize().IsEmpty()
295 ? 0 235 ? 0
296 : GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 236 : GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
297 } 237 }
298 238
299 int IconLabelBubbleView::GetPostSeparatorPadding() const { 239 int IconLabelBubbleView::GetPostSeparatorPadding() const {
300 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us. 240 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us.
301 return kSpaceBesideSeparator - 241 return kSpaceBesideSeparator -
302 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 242 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
303 } 243 }
304 244
305 const char* IconLabelBubbleView::GetClassName() const { 245 const char* IconLabelBubbleView::GetClassName() const {
306 return "IconLabelBubbleView"; 246 return "IconLabelBubbleView";
307 } 247 }
308 248
309 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { 249 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) {
310 if (!ShouldShowBackground()) 250 if (!ShouldShowLabel())
311 return; 251 return;
312 if (background_painter_) {
313 views::Painter::PaintPainterAt(canvas, background_painter_.get(),
314 GetContentsBounds());
315 }
316 252
317 // In MD, draw a separator and not a background. 253 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor(
318 if (ui::MaterialDesignController::IsModeMaterial()) { 254 ui::NativeTheme::kColorId_TextfieldDefaultColor);
319 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( 255 const SkColor separator_color = SkColorSetA(
320 ui::NativeTheme::kColorId_TextfieldDefaultColor); 256 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC);
321 const SkColor separator_color = SkColorSetA(
322 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC);
323 257
324 gfx::Rect bounds(GetLocalBounds()); 258 gfx::Rect bounds(GetLocalBounds());
325 const int kSeparatorHeight = 16; 259 const int kSeparatorHeight = 16;
326 bounds.Inset(GetPostSeparatorPadding(), 260 bounds.Inset(GetPostSeparatorPadding(),
327 (bounds.height() - kSeparatorHeight) / 2); 261 (bounds.height() - kSeparatorHeight) / 2);
328 262
329 // Draw the 1 px separator. 263 // Draw the 1 px separator.
330 gfx::ScopedCanvas scoped_canvas(canvas); 264 gfx::ScopedCanvas scoped_canvas(canvas);
331 const float scale = canvas->UndoDeviceScaleFactor(); 265 const float scale = canvas->UndoDeviceScaleFactor();
332 // Keep the separator aligned on a pixel center. 266 // Keep the separator aligned on a pixel center.
333 const gfx::RectF pixel_aligned_bounds = 267 const gfx::RectF pixel_aligned_bounds =
334 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); 268 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0);
335 canvas->DrawLine(pixel_aligned_bounds.top_right(), 269 canvas->DrawLine(pixel_aligned_bounds.top_right(),
336 pixel_aligned_bounds.bottom_right(), separator_color); 270 pixel_aligned_bounds.bottom_right(), separator_color);
337 }
338 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698