Chromium Code Reviews| Index: ui/views/controls/scrollbar/base_scroll_bar_thumb.cc |
| diff --git a/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc b/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc |
| index 8256c4a149324e5d8efbf4f3dd6c3720ee99df05..0bb7d0acb627f36191ac7dd3c29e2f9d210d1b6c 100644 |
| --- a/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc |
| +++ b/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc |
| @@ -26,23 +26,19 @@ BaseScrollBarThumb::BaseScrollBarThumb(BaseScrollBar* scroll_bar) |
| BaseScrollBarThumb::~BaseScrollBarThumb() { |
| } |
| -void BaseScrollBarThumb::SetSize(int size) { |
| +void BaseScrollBarThumb::SetLength(int length) { |
| // Make sure the thumb is never sized smaller than its minimum possible |
| // display size. |
| - gfx::Size prefsize = GetPreferredSize(); |
| - size = std::max(size, scroll_bar_->IsHorizontal() ? prefsize.width() : |
| - prefsize.height()); |
| - gfx::Rect thumb_bounds = bounds(); |
| - if (scroll_bar_->IsHorizontal()) { |
| - thumb_bounds.set_width(size); |
| - } else { |
| - thumb_bounds.set_height(size); |
| - } |
| - SetBoundsRect(thumb_bounds); |
| + gfx::Size size = GetPreferredSize(); |
| + if (IsHorizontal()) |
| + size.set_width(length); |
| + else |
| + size.set_height(length); |
| + SetSize(size); |
|
Evan Stade
2016/11/10 19:31:40
the changes here are functionally idempotent; it's
|
| } |
| int BaseScrollBarThumb::GetSize() const { |
| - if (scroll_bar_->IsHorizontal()) |
| + if (IsHorizontal()) |
| return width(); |
| return height(); |
| } |
| @@ -50,7 +46,7 @@ int BaseScrollBarThumb::GetSize() const { |
| void BaseScrollBarThumb::SetPosition(int position) { |
| gfx::Rect thumb_bounds = bounds(); |
| gfx::Rect track_bounds = scroll_bar_->GetTrackBounds(); |
| - if (scroll_bar_->IsHorizontal()) { |
| + if (IsHorizontal()) { |
| thumb_bounds.set_x(track_bounds.x() + position); |
| } else { |
| thumb_bounds.set_y(track_bounds.y() + position); |
| @@ -60,7 +56,7 @@ void BaseScrollBarThumb::SetPosition(int position) { |
| int BaseScrollBarThumb::GetPosition() const { |
| gfx::Rect track_bounds = scroll_bar_->GetTrackBounds(); |
| - if (scroll_bar_->IsHorizontal()) |
| + if (IsHorizontal()) |
| return x() - track_bounds.x(); |
| return y() - track_bounds.y(); |
| } |
| @@ -74,7 +70,7 @@ void BaseScrollBarThumb::OnMouseExited(const ui::MouseEvent& event) { |
| } |
| bool BaseScrollBarThumb::OnMousePressed(const ui::MouseEvent& event) { |
| - mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y(); |
| + mouse_offset_ = IsHorizontal() ? event.x() : event.y(); |
| drag_start_position_ = GetPosition(); |
| SetState(CustomButton::STATE_PRESSED); |
| return true; |
| @@ -84,7 +80,7 @@ bool BaseScrollBarThumb::OnMouseDragged(const ui::MouseEvent& event) { |
| // If the user moves the mouse more than |kScrollThumbDragOutSnap| outside |
| // the bounds of the thumb, the scrollbar will snap the scroll back to the |
| // point it was at before the drag began. |
| - if (scroll_bar_->IsHorizontal()) { |
| + if (IsHorizontal()) { |
| if ((event.y() < y() - kScrollThumbDragOutSnap) || |
| (event.y() > (y() + height() + kScrollThumbDragOutSnap))) { |
| scroll_bar_->ScrollToThumbPosition(drag_start_position_, false); |
| @@ -97,7 +93,7 @@ bool BaseScrollBarThumb::OnMouseDragged(const ui::MouseEvent& event) { |
| return true; |
| } |
| } |
| - if (scroll_bar_->IsHorizontal()) { |
| + if (IsHorizontal()) { |
| int thumb_x = event.x() - mouse_offset_; |
| if (base::i18n::IsRTL()) |
| thumb_x *= -1; |
| @@ -132,4 +128,8 @@ void BaseScrollBarThumb::SetState(CustomButton::ButtonState state) { |
| SchedulePaint(); |
| } |
| +bool BaseScrollBarThumb::IsHorizontal() const { |
| + return scroll_bar_->IsHorizontal(); |
| +} |
| + |
| } // namespace views |