Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Unified Diff: ui/views/controls/scrollbar/base_scroll_bar_thumb.cc

Issue 2496643002: Implement Sebastien's overlay scrollbars for native UI (Views). (Closed)
Patch Set: fix test failure Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2cf40e66d18ec3dcad412ed16a84148fbfcaf569 100644
--- a/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc
+++ b/ui/views/controls/scrollbar/base_scroll_bar_thumb.cc
@@ -26,23 +26,17 @@ 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();
+ size.SetToMax(
+ gfx::Size(IsHorizontal() ? length : 0, IsHorizontal() ? 0 : length));
+ SetSize(size);
}
int BaseScrollBarThumb::GetSize() const {
- if (scroll_bar_->IsHorizontal())
+ if (IsHorizontal())
return width();
return height();
}
@@ -50,7 +44,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 +54,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 +68,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 +78,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 +91,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;
@@ -126,10 +120,16 @@ void BaseScrollBarThumb::SetState(CustomButton::ButtonState state) {
if (state_ == state)
return;
- CustomButton::ButtonState old_state = state_;
state_ = state;
- scroll_bar_->OnThumbStateChanged(old_state, state);
+ OnStateChanged();
+}
+
+void BaseScrollBarThumb::OnStateChanged() {
SchedulePaint();
}
+bool BaseScrollBarThumb::IsHorizontal() const {
+ return scroll_bar_->IsHorizontal();
+}
+
} // namespace views
« no previous file with comments | « ui/views/controls/scrollbar/base_scroll_bar_thumb.h ('k') | ui/views/controls/scrollbar/overlay_scroll_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698