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..0d92362c883976ef5114415cbc4faf5116b3237e 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; |
| @@ -37,7 +37,12 @@ OverlayScrollBar::Thumb::Thumb(OverlayScrollBar* scroll_bar) |
| 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); |
|
sadrul
2016/11/19 01:43:04
This would affect layout (and thus painting) too,
|
| } |
| void OverlayScrollBar::Thumb::OnPaint(gfx::Canvas* canvas) { |
| @@ -45,6 +50,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 +89,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); |
| @@ -107,7 +114,11 @@ 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 { |