Chromium Code Reviews| Index: ui/views/controls/scrollbar/overlay_scroll_bar.cc |
| diff --git a/ui/views/controls/scrollbar/overlay_scroll_bar.cc b/ui/views/controls/scrollbar/overlay_scroll_bar.cc |
| index de3b193e1760171e3f277a681fa73b7017d0657c..54ed80a5d4d498e105d62afbd22a841b4f776722 100644 |
| --- a/ui/views/controls/scrollbar/overlay_scroll_bar.cc |
| +++ b/ui/views/controls/scrollbar/overlay_scroll_bar.cc |
| @@ -19,7 +19,7 @@ namespace { |
| const int kThumbThickness = 11; |
| // When hovered, the thumb takes up the full width. Otherwise, it's a bit |
| // slimmer. |
| -const int kThumbUnhoveredDifference = 4; |
| +const int kThumbHoverOffset = 4; |
| const int kThumbStroke = 1; |
| const float kThumbHoverAlpha = 0.5f; |
| const float kThumbDefaultAlpha = 0.3f; |
| @@ -28,16 +28,27 @@ const float kThumbDefaultAlpha = 0.3f; |
| OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar) |
| : BaseScrollBarThumb(scroll_bar), scroll_bar_(scroll_bar) { |
| + // |scroll_bar| isn't done being constructed; it's not safe to do anything |
|
Evan Stade
2016/11/19 02:23:34
different bug here --- don't do work in constructo
varkha
2016/11/19 02:58:00
Is this responsible for the first Thumb's paint be
Evan Stade
2016/11/21 15:26:20
yes
|
| + // that might reference it yet. |
| +} |
| + |
| +OverlayScrollBar::Thumb::~Thumb() {} |
| + |
| +void OverlayScrollBar::Thumb::Init() { |
| SetPaintToLayer(true); |
| + layer()->SetFillsBoundsOpaquely(false); |
|
Evan Stade
2016/11/19 02:23:34
this is the fix for the graphical glitch Valery po
varkha
2016/11/19 02:58:00
Yay! Glad you caught it.
|
| // Animate all changes to the layer except the first one. |
| OnStateChanged(); |
| layer()->SetAnimator(ui::LayerAnimator::CreateImplicitAnimator()); |
| } |
| -OverlayScrollBar::Thumb::~Thumb() {} |
| - |
| gfx::Size OverlayScrollBar::Thumb::GetPreferredSize() const { |
| - return gfx::Size(kThumbThickness, kThumbThickness); |
| + // The visual size of the thumb is kThumbThickness, but it slides back and |
| + // forth by kThumbHoverOffset. To make event targetting work well, expand the |
| + // width of the thumb such that it's always taking up the full width of the |
| + // track regardless of the offset. |
| + return gfx::Size(kThumbThickness + kThumbHoverOffset, |
| + kThumbThickness + kThumbHoverOffset); |
| } |
| void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) { |
| @@ -45,6 +56,8 @@ void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) { |
| fill_paint.setStyle(SkPaint::kFill_Style); |
| fill_paint.setColor(SK_ColorBLACK); |
| gfx::RectF fill_bounds(GetLocalBounds()); |
| + fill_bounds.Inset(gfx::InsetsF(IsHorizontal() ? kThumbHoverOffset : 0, |
| + IsHorizontal() ? 0 : kThumbHoverOffset, 0, 0)); |
| fill_bounds.Inset(gfx::InsetsF(kThumbStroke, kThumbStroke, |
| IsHorizontal() ? 0 : kThumbStroke, |
| IsHorizontal() ? kThumbStroke : 0)); |
| @@ -82,8 +95,8 @@ void OverlayScrollBar::Thumb::OnStateChanged() { |
| if (GetState() == CustomButton::STATE_NORMAL) { |
| gfx::Transform translation; |
| translation.Translate( |
| - gfx::Vector2d(IsHorizontal() ? 0 : kThumbUnhoveredDifference, |
| - IsHorizontal() ? kThumbUnhoveredDifference : 0)); |
| + gfx::Vector2d(IsHorizontal() ? 0 : kThumbHoverOffset, |
| + IsHorizontal() ? kThumbHoverOffset: 0)); |
| layer()->SetTransform(translation); |
| layer()->SetOpacity(kThumbDefaultAlpha); |
| @@ -97,17 +110,21 @@ void OverlayScrollBar::Thumb::OnStateChanged() { |
| OverlayScrollBar::OverlayScrollBar(bool horizontal) |
| : BaseScrollBar(horizontal, new Thumb(this)), hide_timer_(false, false) { |
| + static_cast<Thumb*>(GetThumb())->Init(); |
|
varkha
2016/11/19 02:58:00
Is it possible to make a virtual BaseScrollBarThum
Evan Stade
2016/11/21 15:26:20
"Avoid virtual method calls in constructors"
http
varkha
2016/11/21 17:16:46
Fair enough, although I thought this was about cal
|
| set_notify_enter_exit_on_child(true); |
| SetPaintToLayer(true); |
| layer()->SetMasksToBounds(true); |
| layer()->SetFillsBoundsOpaquely(false); |
| } |
| -OverlayScrollBar::~OverlayScrollBar() { |
| -} |
| +OverlayScrollBar::~OverlayScrollBar() {} |
| gfx::Rect OverlayScrollBar::GetTrackBounds() const { |
| - return GetLocalBounds(); |
| + gfx::Rect local = GetLocalBounds(); |
| + // The track has to be wide enough for the thumb. |
| + local.Inset(gfx::Insets(IsHorizontal() ? -kThumbHoverOffset : 0, |
| + IsHorizontal() ? 0 : -kThumbHoverOffset, 0, 0)); |
| + return local; |
| } |
| int OverlayScrollBar::GetLayoutSize() const { |