Chromium Code Reviews| 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 "chrome/browser/ui/layout_constants.h" | 7 #include "chrome/browser/ui/layout_constants.h" |
| 8 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 8 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 10 #include "ui/accessibility/ax_node_data.h" | 10 #include "ui/accessibility/ax_node_data.h" |
| 11 #include "ui/compositor/layer_animator.h" | |
| 12 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 11 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_utils.h" | 14 #include "ui/gfx/color_utils.h" |
| 13 #include "ui/gfx/scoped_canvas.h" | 15 #include "ui/gfx/scoped_canvas.h" |
| 14 #include "ui/native_theme/native_theme.h" | 16 #include "ui/native_theme/native_theme.h" |
| 17 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
| 15 #include "ui/views/animation/ink_drop_highlight.h" | 18 #include "ui/views/animation/ink_drop_highlight.h" |
| 19 #include "ui/views/animation/ink_drop_impl.h" | |
| 20 #include "ui/views/animation/ink_drop_ripple.h" | |
| 16 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
| 17 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
| 18 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 19 | 24 |
| 20 namespace { | 25 namespace { |
| 21 | 26 |
| 22 // Amount of space on either side of the separator that appears after the label. | 27 // Amount of space on either side of the separator that appears after the label. |
| 23 constexpr int kSpaceBesideSeparator = 8; | 28 constexpr int kSpaceBesideSeparator = 8; |
| 24 | 29 |
| 30 // The length of the separator's fade animation. | |
| 31 constexpr int kFadeInDurationMs = 250; | |
| 32 constexpr int kFadeOutDurationMs = 175; | |
| 33 | |
| 25 } // namespace | 34 } // namespace |
| 26 | 35 |
| 36 ////////////////////////////////////////////////////////////////// | |
| 37 // SeparatorView class | |
| 38 | |
| 39 IconLabelBubbleView::SeparatorView::SeparatorView(IconLabelBubbleView* owner) { | |
| 40 DCHECK(owner); | |
| 41 owner_ = owner; | |
| 42 SetPaintToLayer(); | |
|
bruthig
2017/03/14 03:49:39
Can this use a LAYER_SOLID_COLOR LayerType instead
spqchan
2017/03/21 18:25:22
I can do that, but I'll have to set the width of t
bruthig
2017/03/22 17:20:16
I spoke with sadrul@ offline and he wasn't sure ho
| |
| 43 layer()->SetFillsBoundsOpaquely(false); | |
| 44 } | |
| 45 | |
| 46 void IconLabelBubbleView::SeparatorView::OnPaint(gfx::Canvas* canvas) { | |
| 47 if (!owner_->ShouldShowLabel()) | |
| 48 return; | |
| 49 | |
| 50 const SkColor plain_text_color = owner_->GetNativeTheme()->GetSystemColor( | |
| 51 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 52 const SkColor separator_color = SkColorSetA( | |
| 53 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); | |
| 54 | |
| 55 gfx::Rect bounds(owner_->label()->bounds()); | |
| 56 const int kSeparatorHeight = 16; | |
| 57 bounds.Inset(0, (bounds.height() - kSeparatorHeight) / 2); | |
| 58 | |
| 59 // Draw the 1 px separator. | |
| 60 gfx::ScopedCanvas scoped_canvas(canvas); | |
| 61 const float scale = canvas->UndoDeviceScaleFactor(); | |
| 62 // Keep the separator aligned on a pixel center. | |
| 63 const gfx::RectF pixel_aligned_bounds = | |
| 64 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); | |
| 65 canvas->DrawLine(pixel_aligned_bounds.top_right(), | |
| 66 pixel_aligned_bounds.bottom_right(), separator_color); | |
| 67 } | |
| 68 | |
| 69 bool IconLabelBubbleView::SeparatorView::CanProcessEventsWithinSubtree() const { | |
| 70 return false; | |
| 71 } | |
| 72 | |
| 73 void IconLabelBubbleView::SeparatorView::UpdateOpacity() { | |
| 74 views::InkDrop* ink_drop = owner_->GetInkDrop(); | |
| 75 DCHECK(ink_drop); | |
| 76 | |
| 77 // If an inkdrop highlight or ripple is animating in or visible, the | |
| 78 // separator should | |
|
bruthig
2017/03/14 03:49:41
Incomplete sentence?
spqchan
2017/03/21 18:25:23
Done.
| |
| 79 views::InkDropState state = ink_drop->GetTargetInkDropState(); | |
| 80 float opacity = 0.0f; | |
| 81 float duration = kFadeOutDurationMs; | |
| 82 if (!ink_drop->IsHighlightFadingInOrVisible() && | |
| 83 (state == views::InkDropState::HIDDEN || | |
| 84 state == views::InkDropState::DEACTIVATED)) { | |
| 85 opacity = 1.0f; | |
| 86 duration = kFadeInDurationMs; | |
| 87 } | |
| 88 | |
| 89 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | |
| 90 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(duration)); | |
| 91 animation.SetTweenType(gfx::Tween::Type::EASE_IN); | |
| 92 layer()->SetOpacity(opacity); | |
| 93 } | |
| 94 | |
| 95 ////////////////////////////////////////////////////////////////// | |
| 96 // IconLabelBubbleView class | |
| 97 | |
| 27 IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list, | 98 IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list, |
| 28 bool elide_in_middle) | 99 bool elide_in_middle) |
| 29 : image_(new views::ImageView()), | 100 : image_(new views::ImageView()), |
| 30 label_(new views::Label(base::string16(), font_list)) { | 101 label_(new views::Label(base::string16(), font_list)), |
| 102 ink_drop_container_(new views::InkDropContainerView()), | |
| 103 suppress_mouse_released_action_(false) { | |
| 31 // Disable separate hit testing for |image_|. This prevents views treating | 104 // Disable separate hit testing for |image_|. This prevents views treating |
| 32 // |image_| as a separate mouse hover region from |this|. | 105 // |image_| as a separate mouse hover region from |this|. |
| 33 image_->set_interactive(false); | 106 image_->set_interactive(false); |
| 34 image_->SetBorder(views::CreateEmptyBorder( | 107 image_->SetBorder(views::CreateEmptyBorder( |
| 35 gfx::Insets(LocationBarView::kIconInteriorPadding))); | 108 gfx::Insets(LocationBarView::kIconInteriorPadding))); |
| 36 AddChildView(image_); | 109 AddChildView(image_); |
| 37 | 110 |
| 38 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 111 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 39 | 112 |
| 40 if (elide_in_middle) | 113 if (elide_in_middle) |
| 41 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); | 114 label_->SetElideBehavior(gfx::ELIDE_MIDDLE); |
| 42 AddChildView(label_); | 115 AddChildView(label_); |
| 43 | 116 |
| 117 separator_view_.reset(new SeparatorView(this)); | |
| 118 AddChildView(separator_view_.get()); | |
| 119 | |
| 120 AddChildView(ink_drop_container_); | |
| 121 ink_drop_container_->SetVisible(false); | |
|
bruthig
2017/03/14 03:49:40
Is SetVisible(true) ever called on the |ink_drop_c
spqchan
2017/03/21 18:25:23
Yes: https://cs.chromium.org/chromium/src/ui/views
| |
| 122 | |
| 44 // Bubbles are given the full internal height of the location bar so that all | 123 // Bubbles are given the full internal height of the location bar so that all |
| 45 // child views in the location bar have the same height. The visible height of | 124 // child views in the location bar have the same height. The visible height of |
| 46 // the bubble should be smaller, so use an empty border to shrink down the | 125 // the bubble should be smaller, so use an empty border to shrink down the |
| 47 // content bounds so the background gets painted correctly. | 126 // content bounds so the background gets painted correctly. |
| 48 SetBorder(views::CreateEmptyBorder( | 127 SetBorder(views::CreateEmptyBorder( |
| 49 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0))); | 128 gfx::Insets(LocationBarView::kBubbleVerticalPadding, 0))); |
| 50 | 129 |
| 51 // Flip the canvas in RTL so the separator is drawn on the correct side. | 130 // Flip the canvas in RTL so the separator is drawn on the correct side. |
| 52 EnableCanvasFlippingForRTLUI(true); | 131 EnableCanvasFlippingForRTLUI(true); |
| 53 } | 132 } |
| 54 | 133 |
| 55 IconLabelBubbleView::~IconLabelBubbleView() { | 134 IconLabelBubbleView::~IconLabelBubbleView() { |
| 56 } | 135 } |
| 57 | 136 |
| 137 void IconLabelBubbleView::AnimationStarted() { | |
| 138 separator_view_->UpdateOpacity(); | |
| 139 } | |
| 140 | |
| 58 void IconLabelBubbleView::SetLabel(const base::string16& label) { | 141 void IconLabelBubbleView::SetLabel(const base::string16& label) { |
| 59 label_->SetText(label); | 142 label_->SetText(label); |
| 60 } | 143 } |
| 61 | 144 |
| 62 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { | 145 void IconLabelBubbleView::SetImage(const gfx::ImageSkia& image_skia) { |
| 63 image_->SetImage(image_skia); | 146 image_->SetImage(image_skia); |
| 64 } | 147 } |
| 65 | 148 |
| 66 bool IconLabelBubbleView::ShouldShowLabel() const { | 149 bool IconLabelBubbleView::ShouldShowLabel() const { |
| 67 return label_->visible() && !label_->text().empty(); | 150 return label_->visible() && !label_->text().empty(); |
| 68 } | 151 } |
| 69 | 152 |
| 70 double IconLabelBubbleView::WidthMultiplier() const { | 153 double IconLabelBubbleView::WidthMultiplier() const { |
| 71 return 1.0; | 154 return 1.0; |
| 72 } | 155 } |
| 73 | 156 |
| 74 bool IconLabelBubbleView::IsShrinking() const { | 157 bool IconLabelBubbleView::IsShrinking() const { |
| 75 return false; | 158 return false; |
| 76 } | 159 } |
| 77 | 160 |
| 78 bool IconLabelBubbleView::OnActivate(const ui::Event& event) { | 161 bool IconLabelBubbleView::OnActivate(const ui::Event& event) { |
| 79 return false; | 162 return false; |
| 80 } | 163 } |
| 81 | 164 |
| 165 bool IconLabelBubbleView::IsBubbleShown() const { | |
| 166 return false; | |
| 167 } | |
| 168 | |
| 169 bool IconLabelBubbleView::CanClick() const { | |
| 170 return false; | |
| 171 } | |
| 172 | |
| 82 gfx::Size IconLabelBubbleView::GetPreferredSize() const { | 173 gfx::Size IconLabelBubbleView::GetPreferredSize() const { |
| 83 // Height will be ignored by the LocationBarView. | 174 // Height will be ignored by the LocationBarView. |
| 84 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); | 175 return GetSizeForLabelWidth(label_->GetPreferredSize().width()); |
| 85 } | 176 } |
| 86 | 177 |
| 87 bool IconLabelBubbleView::OnKeyPressed(const ui::KeyEvent& event) { | 178 bool IconLabelBubbleView::OnKeyPressed(const ui::KeyEvent& event) { |
| 88 if (event.key_code() == ui::VKEY_RETURN) | 179 if (event.key_code() == ui::VKEY_RETURN) |
| 89 return OnActivate(event); | 180 return OnActivate(event); |
| 90 return false; | 181 return false; |
| 91 } | 182 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 113 image_->SetBounds(0, 0, image_width, height()); | 204 image_->SetBounds(0, 0, image_width, height()); |
| 114 | 205 |
| 115 // Compute the label bounds. The label gets whatever size is left over after | 206 // Compute the label bounds. The label gets whatever size is left over after |
| 116 // accounting for the preferred image width and padding amounts. Note that if | 207 // accounting for the preferred image width and padding amounts. Note that if |
| 117 // the label has zero size it doesn't actually matter what we compute its X | 208 // the label has zero size it doesn't actually matter what we compute its X |
| 118 // value to be, since it won't be visible. | 209 // value to be, since it won't be visible. |
| 119 const int label_x = image_->bounds().right() + GetInternalSpacing(); | 210 const int label_x = image_->bounds().right() + GetInternalSpacing(); |
| 120 const int label_width = | 211 const int label_width = |
| 121 std::max(0, width() - label_x - bubble_trailing_padding); | 212 std::max(0, width() - label_x - bubble_trailing_padding); |
| 122 label_->SetBounds(label_x, 0, label_width, height()); | 213 label_->SetBounds(label_x, 0, label_width, height()); |
| 214 separator_view_->SetBoundsRect(GetLocalBounds()); | |
| 215 ink_drop_container_->SetBoundsRect(GetLocalBounds()); | |
| 216 } | |
| 217 | |
| 218 bool IconLabelBubbleView::OnMousePressed(const ui::MouseEvent& event) { | |
| 219 suppress_mouse_released_action_ = IsBubbleShown() || !CanClick(); | |
| 220 if (!suppress_mouse_released_action_) | |
| 221 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event); | |
| 222 | |
| 223 return true; | |
| 224 } | |
| 225 | |
| 226 void IconLabelBubbleView::OnMouseReleased(const ui::MouseEvent& event) { | |
|
bruthig
2017/03/14 03:49:43
Does the InkDropHostView::InkDropGestureHandler wo
spqchan
2017/03/21 18:25:22
That's a good point. I made changes so that Custom
| |
| 227 if (suppress_mouse_released_action_) { | |
| 228 suppress_mouse_released_action_ = false; | |
| 229 return; | |
| 230 } | |
| 231 | |
| 232 if (HitTestPoint(event.location())) { | |
| 233 AnimateInkDrop(views::InkDropState::ACTIVATED, &event); | |
|
bruthig
2017/03/14 03:49:42
Should it really animate to ACTIVATED if OnActivat
spqchan
2017/03/21 18:25:22
This is now dealt by CustomButton
| |
| 234 OnActivate(event); | |
| 235 } else { | |
| 236 AnimateInkDrop(views::InkDropState::DEACTIVATED, &event); | |
|
bruthig
2017/03/14 03:49:38
I think you want the HIDDEN state here, this will
spqchan
2017/03/21 18:25:23
Done.
| |
| 237 } | |
| 123 } | 238 } |
| 124 | 239 |
| 125 void IconLabelBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 240 void IconLabelBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 126 label_->GetAccessibleNodeData(node_data); | 241 label_->GetAccessibleNodeData(node_data); |
| 127 } | 242 } |
| 128 | 243 |
| 129 void IconLabelBubbleView::OnNativeThemeChanged( | 244 void IconLabelBubbleView::OnNativeThemeChanged( |
| 130 const ui::NativeTheme* native_theme) { | 245 const ui::NativeTheme* native_theme) { |
| 131 label_->SetEnabledColor(GetTextColor()); | 246 label_->SetEnabledColor(GetTextColor()); |
| 132 label_->SetBackgroundColor(GetParentBackgroundColor()); | 247 label_->SetBackgroundColor(GetParentBackgroundColor()); |
| 133 SchedulePaint(); | 248 SchedulePaint(); |
| 134 } | 249 } |
| 135 | 250 |
| 136 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { | 251 void IconLabelBubbleView::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 137 image()->SetPaintToLayer(); | 252 ink_drop_container_->AddInkDropLayer(ink_drop_layer); |
| 138 image()->layer()->SetFillsBoundsOpaquely(false); | |
| 139 InkDropHostView::AddInkDropLayer(ink_drop_layer); | |
| 140 } | 253 } |
| 141 | 254 |
| 142 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { | 255 void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 143 InkDropHostView::RemoveInkDropLayer(ink_drop_layer); | 256 ink_drop_container_->RemoveInkDropLayer(ink_drop_layer); |
| 144 image()->DestroyLayer(); | 257 } |
| 258 | |
| 259 std::unique_ptr<views::InkDrop> IconLabelBubbleView::CreateInkDrop() { | |
| 260 std::unique_ptr<views::InkDropImpl> ink_drop = | |
| 261 CreateDefaultFloodFillInkDropImpl(); | |
| 262 ink_drop->SetShowHighlightOnFocus(true); | |
| 263 ink_drop->SetObserver(this); | |
| 264 return std::move(ink_drop); | |
| 145 } | 265 } |
| 146 | 266 |
| 147 std::unique_ptr<views::InkDropHighlight> | 267 std::unique_ptr<views::InkDropHighlight> |
| 148 IconLabelBubbleView::CreateInkDropHighlight() const { | 268 IconLabelBubbleView::CreateInkDropHighlight() const { |
| 149 // Only show a highlight effect when the label is empty/invisible. | 269 if (!CanClick()) |
|
bruthig
2017/03/14 03:49:43
I believe the button hierarchy prevents a highligh
spqchan
2017/03/21 18:25:22
Sounds good.
Question:
- I can try that although
| |
| 150 return label()->visible() ? nullptr | 270 return nullptr; |
| 151 : InkDropHostView::CreateInkDropHighlight(); | 271 |
| 272 gfx::PointF ink_drop_center = gfx::RectF(GetLocalBounds()).CenterPoint(); | |
| 273 gfx::Size ink_drop_size = size(); | |
|
bruthig
2017/03/14 03:49:38
When is it valid for size() to be empty?
spqchan
2017/03/21 18:25:22
It happens during tests. Now that you mentioned it
| |
| 274 if (ink_drop_size.IsEmpty()) | |
| 275 ink_drop_size = gfx::Size(kDefaultInkDropSize, kDefaultInkDropSize); | |
| 276 | |
| 277 if (ShouldShowLabel()) { | |
| 278 int padding_offset = -GetPostSeparatorPadding(); | |
| 279 ink_drop_center.Offset(padding_offset / 2, 0); | |
| 280 ink_drop_size.Enlarge(padding_offset, 0); | |
| 281 } | |
| 282 | |
| 283 return InkDropHostView::CreateDefaultInkDropHighlight(ink_drop_center, | |
| 284 ink_drop_size); | |
| 285 } | |
| 286 | |
| 287 std::unique_ptr<views::InkDropRipple> IconLabelBubbleView::CreateInkDropRipple() | |
| 288 const { | |
| 289 gfx::Point ink_drop_center = GetLocalBounds().CenterPoint(); | |
| 290 gfx::Size ink_drop_size = size(); | |
| 291 if (ink_drop_size.IsEmpty()) | |
| 292 return CreateDefaultInkDropRipple(ink_drop_center); | |
| 293 | |
| 294 if (ShouldShowLabel()) { | |
| 295 int padding_offset = -GetPostSeparatorPadding(); | |
| 296 ink_drop_center.Offset(padding_offset / 2, 0); | |
| 297 ink_drop_size.Enlarge(padding_offset, 0); | |
| 298 } | |
| 299 | |
| 300 return base::MakeUnique<views::FloodFillInkDropRipple>( | |
| 301 ink_drop_size, ink_drop_center, GetInkDropBaseColor(), | |
| 302 ink_drop_visible_opacity()); | |
| 152 } | 303 } |
| 153 | 304 |
| 154 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { | 305 SkColor IconLabelBubbleView::GetInkDropBaseColor() const { |
| 155 return color_utils::DeriveDefaultIconColor(GetTextColor()); | 306 return color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor( |
| 307 ui::NativeTheme::kColorId_TextfieldDefaultColor)); | |
| 308 } | |
| 309 | |
| 310 void IconLabelBubbleView::OnWidgetDestroying(views::Widget* widget) { | |
| 311 widget->RemoveObserver(this); | |
| 312 } | |
| 313 | |
| 314 void IconLabelBubbleView::OnWidgetVisibilityChanged(views::Widget* widget, | |
| 315 bool visible) { | |
| 316 // |widget| is a bubble that has just got shown / hidden. | |
| 317 if (!visible) | |
| 318 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | |
| 156 } | 319 } |
| 157 | 320 |
| 158 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { | 321 SkColor IconLabelBubbleView::GetParentBackgroundColor() const { |
| 159 return GetNativeTheme()->GetSystemColor( | 322 return GetNativeTheme()->GetSystemColor( |
| 160 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | 323 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 161 } | 324 } |
| 162 | 325 |
| 163 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { | 326 gfx::Size IconLabelBubbleView::GetSizeForLabelWidth(int label_width) const { |
| 164 gfx::Size size(image_->GetPreferredSize()); | 327 gfx::Size size(image_->GetPreferredSize()); |
| 165 const bool shrinking = IsShrinking(); | 328 const bool shrinking = IsShrinking(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 const views::Widget* widget = GetWidget(); | 372 const views::Widget* widget = GetWidget(); |
| 210 // There may be no widget in tests, and in ash there may be no compositor if | 373 // There may be no widget in tests, and in ash there may be no compositor if |
| 211 // the native view of the Widget doesn't have a parent. | 374 // the native view of the Widget doesn't have a parent. |
| 212 const ui::Compositor* compositor = widget ? widget->GetCompositor() : nullptr; | 375 const ui::Compositor* compositor = widget ? widget->GetCompositor() : nullptr; |
| 213 return compositor ? compositor->device_scale_factor() : 1.0f; | 376 return compositor ? compositor->device_scale_factor() : 1.0f; |
| 214 } | 377 } |
| 215 | 378 |
| 216 const char* IconLabelBubbleView::GetClassName() const { | 379 const char* IconLabelBubbleView::GetClassName() const { |
| 217 return "IconLabelBubbleView"; | 380 return "IconLabelBubbleView"; |
| 218 } | 381 } |
| 219 | |
| 220 void IconLabelBubbleView::OnPaint(gfx::Canvas* canvas) { | |
| 221 if (!ShouldShowLabel()) | |
| 222 return; | |
| 223 | |
| 224 const SkColor plain_text_color = GetNativeTheme()->GetSystemColor( | |
| 225 ui::NativeTheme::kColorId_TextfieldDefaultColor); | |
| 226 const SkColor separator_color = SkColorSetA( | |
| 227 plain_text_color, color_utils::IsDark(plain_text_color) ? 0x59 : 0xCC); | |
| 228 | |
| 229 gfx::Rect bounds(label_->bounds()); | |
| 230 const int kSeparatorHeight = 16; | |
| 231 bounds.Inset(0, (bounds.height() - kSeparatorHeight) / 2); | |
| 232 | |
| 233 // Draw the 1 px separator. | |
| 234 gfx::ScopedCanvas scoped_canvas(canvas); | |
| 235 const float scale = canvas->UndoDeviceScaleFactor(); | |
| 236 // Keep the separator aligned on a pixel center. | |
| 237 const gfx::RectF pixel_aligned_bounds = | |
| 238 gfx::ScaleRect(gfx::RectF(bounds), scale) - gfx::Vector2dF(0.5f, 0); | |
| 239 canvas->DrawLine(pixel_aligned_bounds.top_right(), | |
| 240 pixel_aligned_bounds.bottom_right(), separator_color); | |
| 241 } | |
| OLD | NEW |