| OLD | NEW |
| 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" | |
| 8 #include "chrome/browser/ui/layout_constants.h" | 7 #include "chrome/browser/ui/layout_constants.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" | |
| 12 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/color_utils.h" | 9 #include "ui/gfx/color_utils.h" |
| 14 #include "ui/gfx/image/image_util.h" | |
| 15 #include "ui/gfx/scoped_canvas.h" | 10 #include "ui/gfx/scoped_canvas.h" |
| 16 #include "ui/native_theme/native_theme.h" | 11 #include "ui/native_theme/native_theme.h" |
| 17 #include "ui/views/animation/ink_drop_highlight.h" | 12 #include "ui/views/animation/ink_drop_highlight.h" |
| 18 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
| 19 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/controls/textfield/textfield.h" | |
| 21 #include "ui/views/painter.h" | |
| 22 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 23 | 16 |
| 24 namespace { | 17 namespace { |
| 25 | 18 |
| 26 // Amount of space on either side of the separator that appears after the label. | 19 // Amount of space on either side of the separator that appears after the label. |
| 27 constexpr int kSpaceBesideSeparator = 8; | 20 constexpr int kSpaceBesideSeparator = 8; |
| 28 | 21 |
| 29 SkColor CalculateImageColor(gfx::ImageSkia* image) { | |
| 30 // 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 | |
| 32 // appearance of these assets). | |
| 33 const SkBitmap& bitmap(image->GetRepresentation(1.0f).sk_bitmap()); | |
| 34 SkAutoLockPixels pixel_lock(bitmap); | |
| 35 return bitmap.getColor(bitmap.width() / 2, bitmap.height() / 2); | |
| 36 } | |
| 37 | |
| 38 } // namespace | 22 } // namespace |
| 39 | 23 |
| 40 IconLabelBubbleView::IconLabelBubbleView(int contained_image, | 24 IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list, |
| 41 const gfx::FontList& font_list, | |
| 42 SkColor parent_background_color, | |
| 43 bool elide_in_middle) | 25 bool elide_in_middle) |
| 44 : background_painter_(nullptr), | 26 : image_(new views::ImageView()), |
| 45 image_(new views::ImageView()), | 27 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 | 28 // Disable separate hit testing for |image_|. This prevents views treating |
| 56 // |image_| as a separate mouse hover region from |this|. | 29 // |image_| as a separate mouse hover region from |this|. |
| 57 image_->set_interactive(false); | 30 image_->set_interactive(false); |
| 58 AddChildView(image_); | 31 AddChildView(image_); |
| 59 | 32 |
| 60 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 33 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 61 | 34 |
| 62 if (elide_in_middle) | 35 if (elide_in_middle) |
| 63 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); | 36 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); |
| 64 AddChildView(label_); | 37 AddChildView(label_); |
| 65 | 38 |
| 66 // Bubbles are given the full internal height of the location bar so that all | 39 // 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 | 40 // 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 | 41 // the bubble should be smaller, so use an empty border to shrink down the |
| 69 // content bounds so the background gets painted correctly. | 42 // content bounds so the background gets painted correctly. |
| 70 SetBorder(views::Border::CreateEmptyBorder( | 43 SetBorder(views::Border::CreateEmptyBorder( |
| 71 gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0))); | 44 gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0))); |
| 72 | 45 |
| 73 // Flip the canvas in MD RTL so the separator is drawn on the correct side. | 46 // Flip the canvas in RTL so the separator is drawn on the correct side. |
| 74 EnableCanvasFlippingForRTLUI(ui::MaterialDesignController::IsModeMaterial()); | 47 EnableCanvasFlippingForRTLUI(true); |
| 75 } | 48 } |
| 76 | 49 |
| 77 IconLabelBubbleView::~IconLabelBubbleView() { | 50 IconLabelBubbleView::~IconLabelBubbleView() { |
| 78 } | 51 } |
| 79 | 52 |
| 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) { | 53 void IconLabelBubbleView::SetLabel(const base::string16& label) { |
| 102 label_->SetText(label); | 54 label_->SetText(label); |
| 103 } | 55 } |
| 104 | 56 |
| 105 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { | 57 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { |
| 106 image_->SetImage(image_skia); | 58 image_->SetImage(image_skia); |
| 107 } | 59 } |
| 108 | 60 |
| 109 bool IconLabelBubbleView::ShouldShowBackground() const { | 61 bool IconLabelBubbleView::ShouldShowLabel() const { |
| 110 return should_show_background_; | 62 return label_->visible() && !label_->text().empty(); |
| 111 } | 63 } |
| 112 | 64 |
| 113 double IconLabelBubbleView::WidthMultiplier() const { | 65 double IconLabelBubbleView::WidthMultiplier() const { |
| 114 return 1.0; | 66 return 1.0; |
| 115 } | 67 } |
| 116 | 68 |
| 117 bool IconLabelBubbleView::IsShrinking() const { | 69 bool IconLabelBubbleView::IsShrinking() const { |
| 118 return false; | 70 return false; |
| 119 } | 71 } |
| 120 | 72 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 return false; | 85 return false; |
| 134 } | 86 } |
| 135 | 87 |
| 136 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) { | 88 bool IconLabelBubbleView::OnKeyReleased(const ui::KeyEvent& event) { |
| 137 if (event.key_code() == ui::VKEY_SPACE) | 89 if (event.key_code() == ui::VKEY_SPACE) |
| 138 return OnActivate(event); | 90 return OnActivate(event); |
| 139 return false; | 91 return false; |
| 140 } | 92 } |
| 141 | 93 |
| 142 void IconLabelBubbleView::Layout() { | 94 void IconLabelBubbleView::Layout() { |
| 143 // Compute the image bounds. In non-MD, the leading padding depends on | 95 // Compute the image bounds. Leading and trailing padding are the same. |
| 144 // whether this is an extension icon, since extension icons and | 96 int image_x = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 145 // Chrome-provided icons are different sizes. In MD, these sizes are the | 97 int bubble_trailing_padding = image_x; |
| 146 // same, so it's not necessary to handle the two types differently. | |
| 147 const bool icon_has_enough_padding = | |
| 148 !is_extension_icon_ || ui::MaterialDesignController::IsModeMaterial(); | |
| 149 int image_x = GetOuterPadding(icon_has_enough_padding); | |
| 150 int bubble_trailing_padding = GetOuterPadding(false); | |
| 151 | 98 |
| 152 // If ShouldShowBackground() is true, then either we show a background in the | 99 // 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 | 100 // 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 | 101 // these cases, we leave the leading and trailing padding alone. If this is |
| 155 // to let the image overlap the edge of the background, as this looks glitchy. | 102 // false, however, then we're only showing the image, and either the view |
| 156 // If this is false, however, then we're only showing the image, and either | 103 // width is the image width, or it's animating downwards and getting close to |
| 157 // the view width is the image width, or it's animating downwards and getting | 104 // it. In these cases, we want to shrink the trailing padding first, so the |
| 158 // close to it. In these cases, we want to shrink the trailing padding first, | 105 // image slides all the way to the trailing edge before slowing or stopping; |
| 159 // so the image slides all the way to the trailing edge before slowing or | 106 // then we want to shrink the leading padding down to zero. |
| 160 // stopping; then we want to shrink the leading padding down to zero. | |
| 161 const int image_preferred_width = image_->GetPreferredSize().width(); | 107 const int image_preferred_width = image_->GetPreferredSize().width(); |
| 162 if (!ShouldShowBackground()) { | 108 if (!ShouldShowLabel()) { |
| 163 image_x = std::min(image_x, width() - image_preferred_width); | 109 image_x = std::min(image_x, width() - image_preferred_width); |
| 164 bubble_trailing_padding = std::min( | 110 bubble_trailing_padding = std::min( |
| 165 bubble_trailing_padding, width() - image_preferred_width - image_x); | 111 bubble_trailing_padding, width() - image_preferred_width - image_x); |
| 166 } | 112 } |
| 167 | 113 |
| 168 // Now that we've computed the padding values, give the image all the | 114 // 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 | 115 // 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 | 116 // the first portion of the animation; during the very beginning there may not |
| 171 // be enough room to show the image at all. | 117 // be enough room to show the image at all. |
| 172 const int image_width = | 118 const int image_width = |
| 173 std::min(image_preferred_width, | 119 std::min(image_preferred_width, |
| 174 std::max(0, width() - image_x - bubble_trailing_padding)); | 120 std::max(0, width() - image_x - bubble_trailing_padding)); |
| 175 image_->SetBounds(image_x, 0, image_width, height()); | 121 image_->SetBounds(image_x, 0, image_width, height()); |
| 176 | 122 |
| 177 // Compute the label bounds. The label gets whatever size is left over after | 123 // 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 | 124 // 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 | 125 // 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. | 126 // value to be, since it won't be visible. |
| 181 const int label_x = image_x + image_width + GetInternalSpacing(); | 127 const int label_x = image_x + image_width + GetInternalSpacing(); |
| 182 const int label_width = | 128 const int label_width = |
| 183 std::max(0, width() - label_x - bubble_trailing_padding); | 129 std::max(0, width() - label_x - bubble_trailing_padding); |
| 184 label_->SetBounds(label_x, 0, label_width, height()); | 130 label_->SetBounds(label_x, 0, label_width, height()); |
| 185 } | 131 } |
| 186 | 132 |
| 187 void IconLabelBubbleView::OnNativeThemeChanged( | 133 void IconLabelBubbleView::OnNativeThemeChanged( |
| 188 const ui::NativeTheme* native_theme) { | 134 const ui::NativeTheme* native_theme) { |
| 189 label_->SetEnabledColor(GetTextColor()); | 135 label_->SetEnabledColor(GetTextColor()); |
| 190 | 136 label_->SetBackgroundColor(GetParentBackgroundColor()); |
| 191 if (ui::MaterialDesignController::IsModeMaterial()) { | 137 SchedulePaint(); |
| 192 label_->SetBackgroundColor(GetParentBackgroundColor()); | |
| 193 SchedulePaint(); | |
| 194 } | |
| 195 } | 138 } |
| 196 | 139 |
| 197 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 140 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 198 image()->SetPaintToLayer(true); | 141 image()->SetPaintToLayer(true); |
| 199 image()->layer()->SetFillsBoundsOpaquely(false); | 142 image()->layer()->SetFillsBoundsOpaquely(false); |
| 200 InkDropHostView::AddInkDropLayer(ink_drop_layer); | 143 InkDropHostView::AddInkDropLayer(ink_drop_layer); |
| 201 } | 144 } |
| 202 | 145 |
| 203 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 146 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 204 InkDropHostView::RemoveInkDropLayer(ink_drop_layer); | 147 InkDropHostView::RemoveInkDropLayer(ink_drop_layer); |
| 205 image()->SetPaintToLayer(false); | 148 image()->SetPaintToLayer(false); |
| 206 } | 149 } |
| 207 | 150 |
| 208 std::unique_ptr<views::InkDropHighlight> | 151 std::unique_ptr<views::InkDropHighlight> |
| 209 IconLabelBubbleView::CreateInkDropHighlight() const { | 152 IconLabelBubbleView::CreateInkDropHighlight() const { |
| 210 // Only show a highlight effect when the label is empty/invisible. | 153 // Only show a highlight effect when the label is empty/invisible. |
| 211 return label()->visible() ? nullptr | 154 return label()->visible() ? nullptr |
| 212 : InkDropHostView::CreateInkDropHighlight(); | 155 : InkDropHostView::CreateInkDropHighlight(); |
| 213 } | 156 } |
| 214 | 157 |
| 215 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { | 158 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { |
| 216 return color_utils::DeriveDefaultIconColor(GetTextColor()); | 159 return color_utils::DeriveDefaultIconColor(GetTextColor()); |
| 217 } | 160 } |
| 218 | 161 |
| 219 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { | 162 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { |
| 220 return ui::MaterialDesignController::IsModeMaterial() | 163 return GetNativeTheme()->GetSystemColor( |
| 221 ? GetNativeTheme()->GetSystemColor( | 164 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 222 ui::NativeTheme::kColorId_TextfieldDefaultBackground) | |
| 223 : parent_background_color_; | |
| 224 } | 165 } |
| 225 | 166 |
| 226 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { | 167 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| 227 gfx::Size size(image_->GetPreferredSize()); | 168 gfx::Size size(image_->GetPreferredSize()); |
| 228 const bool shrinking = IsShrinking(); | 169 const bool shrinking = IsShrinking(); |
| 229 // Animation continues for the last few pixels even after the label is not | 170 // 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 | 171 // 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 | 172 // is necessary to animate |total_width| even when the background is hidden |
| 232 // as long as the animation is still shrinking. | 173 // as long as the animation is still shrinking. |
| 233 if (ShouldShowBackground() || shrinking) { | 174 if (ShouldShowLabel() || shrinking) { |
| 234 // On scale factors < 2, we reserve 1 DIP for the 1 px separator. For | 175 // 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 | 176 // higher scale factors, we simply take the separator px out of the |
| 236 // kSpaceBesideSeparator region before the separator, as that results in a | 177 // 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 | 178 // 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.) | 179 // separator px. (For scale 2, the two methods have equal error: 1 px.) |
| 239 const views::Widget* widget = GetWidget(); | 180 const views::Widget* widget = GetWidget(); |
| 240 // There may be no widget in tests. | 181 // There may be no widget in tests. |
| 241 const int separator_width = | 182 const int separator_width = |
| 242 (widget && widget->GetCompositor()->device_scale_factor() >= 2) ? 0 : 1; | 183 (widget && widget->GetCompositor()->device_scale_factor() >= 2) ? 0 : 1; |
| 243 const int post_label_width = ui::MaterialDesignController::IsModeMaterial() | 184 const int post_label_width = |
| 244 ? (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()) | 185 (kSpaceBesideSeparator + separator_width + GetPostSeparatorPadding()); |
| 245 : GetOuterPadding(false); | |
| 246 | 186 |
| 247 // |multiplier| grows from zero to one, stays equal to one and then shrinks | 187 // |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 | 188 // 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 | 189 // 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 | 190 // 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 | 191 // zero, since this would mean the view would completely disappear and then |
| 252 // pop back to an icon after the animation finishes. | 192 // pop back to an icon after the animation finishes. |
| 253 const int max_width = GetImageTrailingEdge() + GetInternalSpacing() + | 193 const int max_width = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING) + |
| 254 label_width + post_label_width; | 194 image_->GetPreferredSize().width() + |
| 195 GetInternalSpacing() + label_width + post_label_width; |
| 255 const int current_width = WidthMultiplier() * max_width; | 196 const int current_width = WidthMultiplier() * max_width; |
| 256 size.set_width(shrinking ? std::max(current_width, size.width()) | 197 size.set_width(shrinking ? std::max(current_width, size.width()) |
| 257 : current_width); | 198 : current_width); |
| 258 } | 199 } |
| 259 return size; | 200 return size; |
| 260 } | 201 } |
| 261 | 202 |
| 262 int IconLabelBubbleView::MinimumWidthForImageWithBackgroundShown() const { | |
| 263 return GetImageTrailingEdge() + GetOuterPadding(false); | |
| 264 } | |
| 265 | |
| 266 void IconLabelBubbleView::SetLabelBackgroundColor( | |
| 267 SkColor chip_background_color) { | |
| 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 } | |
| 288 | |
| 289 int IconLabelBubbleView::GetImageTrailingEdge() const { | |
| 290 return GetOuterPadding(true) + image_->GetPreferredSize().width(); | |
| 291 } | |
| 292 | |
| 293 int IconLabelBubbleView::GetInternalSpacing() const { | 203 int IconLabelBubbleView::GetInternalSpacing() const { |
| 294 return image_->GetPreferredSize().IsEmpty() | 204 return image_->GetPreferredSize().IsEmpty() |
| 295 ? 0 | 205 ? 0 |
| 296 : GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 206 : GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 297 } | 207 } |
| 298 | 208 |
| 299 int IconLabelBubbleView::GetPostSeparatorPadding() const { | 209 int IconLabelBubbleView::GetPostSeparatorPadding() const { |
| 300 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us. | 210 // The location bar will add LOCATION_BAR_HORIZONTAL_PADDING after us. |
| 301 return kSpaceBesideSeparator - | 211 return kSpaceBesideSeparator - |
| 302 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); | 212 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); |
| 303 } | 213 } |
| 304 | 214 |
| 305 const char* IconLabelBubbleView::GetClassName() const { | 215 const char* IconLabelBubbleView::GetClassName() const { |
| 306 return "IconLabelBubbleView"; | 216 return "IconLabelBubbleView"; |
| 307 } | 217 } |
| 308 | 218 |
| 309 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | 219 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { |
| 310 if (!ShouldShowBackground()) | 220 if (!ShouldShowLabel()) |
| 311 return; | 221 return; |
| 312 if (background_painter_) { | |
| 313 views::Painter::PaintPainterAt(canvas, background_painter_.get(), | |
| 314 GetContentsBounds()); | |
| 315 } | |
| 316 | 222 |
| 317 // In MD, draw a separator and not a background. | 223 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( |
| 318 if (ui::MaterialDesignController::IsModeMaterial()) { | 224 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 319 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( | 225 const SkColor separator_color = SkColorSetA( |
| 320 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 226 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 | 227 |
| 324 gfx::Rect bounds(GetLocalBounds()); | 228 gfx::Rect bounds(GetLocalBounds()); |
| 325 const int kSeparatorHeight = 16; | 229 const int kSeparatorHeight = 16; |
| 326 bounds.Inset(GetPostSeparatorPadding(), | 230 bounds.Inset(GetPostSeparatorPadding(), |
| 327 (bounds.height() - kSeparatorHeight) / 2); | 231 (bounds.height() - kSeparatorHeight) / 2); |
| 328 | 232 |
| 329 // Draw the 1 px separator. | 233 // Draw the 1 px separator. |
| 330 gfx::ScopedCanvas scoped_canvas(canvas); | 234 gfx::ScopedCanvas scoped_canvas(canvas); |
| 331 const float scale = canvas->UndoDeviceScaleFactor(); | 235 const float scale = canvas->UndoDeviceScaleFactor(); |
| 332 // Keep the separator aligned on a pixel center. | 236 // Keep the separator aligned on a pixel center. |
| 333 const gfx::RectF pixel_aligned_bounds = | 237 const gfx::RectF pixel_aligned_bounds = |
| 334 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); | 238 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); |
| 335 canvas->DrawLine(pixel_aligned_bounds.top_right(), | 239 canvas->DrawLine(pixel_aligned_bounds.top_right(), |
| 336 pixel_aligned_bounds.bottom_right(), separator_color); | 240 pixel_aligned_bounds.bottom_right(), separator_color); |
| 337 } | |
| 338 } | 241 } |
| OLD | NEW |