| 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 "ui/views/controls/scrollbar/base_scroll_bar.h" | 5 #include "ui/views/controls/scrollbar/base_scroll_bar.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 content_size = 0; | 406 content_size = 0; |
| 407 if (contents_scroll_offset < 0) | 407 if (contents_scroll_offset < 0) |
| 408 contents_scroll_offset = 0; | 408 contents_scroll_offset = 0; |
| 409 if (contents_scroll_offset > content_size) | 409 if (contents_scroll_offset > content_size) |
| 410 contents_scroll_offset = content_size; | 410 contents_scroll_offset = content_size; |
| 411 contents_scroll_offset_ = contents_scroll_offset; | 411 contents_scroll_offset_ = contents_scroll_offset; |
| 412 | 412 |
| 413 // Thumb Height and Thumb Pos. | 413 // Thumb Height and Thumb Pos. |
| 414 // The height of the thumb is the ratio of the Viewport height to the | 414 // The height of the thumb is the ratio of the Viewport height to the |
| 415 // content size multiplied by the height of the thumb track. | 415 // content size multiplied by the height of the thumb track. |
| 416 double ratio = static_cast<double>(viewport_size) / contents_size_; | 416 double ratio = |
| 417 std::min(1.0, static_cast<double>(viewport_size) / contents_size_); |
| 417 int thumb_size = static_cast<int>(ratio * GetTrackSize()); | 418 int thumb_size = static_cast<int>(ratio * GetTrackSize()); |
| 418 thumb_->SetSize(thumb_size); | 419 thumb_->SetSize(thumb_size); |
| 419 | 420 |
| 420 int thumb_position = CalculateThumbPosition(contents_scroll_offset); | 421 int thumb_position = CalculateThumbPosition(contents_scroll_offset); |
| 421 thumb_->SetPosition(thumb_position); | 422 thumb_->SetPosition(thumb_position); |
| 422 } | 423 } |
| 423 | 424 |
| 424 int BaseScrollBar::GetPosition() const { | 425 int BaseScrollBar::GetPosition() const { |
| 425 return thumb_->GetPosition(); | 426 return thumb_->GetPosition(); |
| 426 } | 427 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 int thumb_max = GetTrackSize() - thumb_->GetSize(); | 499 int thumb_max = GetTrackSize() - thumb_->GetSize(); |
| 499 if (contents_scroll_offset + viewport_size_ == contents_size_) | 500 if (contents_scroll_offset + viewport_size_ == contents_size_) |
| 500 return thumb_max; | 501 return thumb_max; |
| 501 return (contents_scroll_offset * thumb_max) / | 502 return (contents_scroll_offset * thumb_max) / |
| 502 (contents_size_ - viewport_size_); | 503 (contents_size_ - viewport_size_); |
| 503 } | 504 } |
| 504 | 505 |
| 505 int BaseScrollBar::CalculateContentsOffset(int thumb_position, | 506 int BaseScrollBar::CalculateContentsOffset(int thumb_position, |
| 506 bool scroll_to_middle) const { | 507 bool scroll_to_middle) const { |
| 507 int thumb_size = thumb_->GetSize(); | 508 int thumb_size = thumb_->GetSize(); |
| 509 int track_size = GetTrackSize(); |
| 510 if (track_size == thumb_size) |
| 511 return 0; |
| 508 if (scroll_to_middle) | 512 if (scroll_to_middle) |
| 509 thumb_position = thumb_position - (thumb_size / 2); | 513 thumb_position = thumb_position - (thumb_size / 2); |
| 510 return (thumb_position * (contents_size_ - viewport_size_)) / | 514 return (thumb_position * (contents_size_ - viewport_size_)) / |
| 511 (GetTrackSize() - thumb_size); | 515 (track_size - thumb_size); |
| 512 } | 516 } |
| 513 | 517 |
| 514 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { | 518 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { |
| 515 thumb_track_state_ = state; | 519 thumb_track_state_ = state; |
| 516 SchedulePaint(); | 520 SchedulePaint(); |
| 517 } | 521 } |
| 518 | 522 |
| 519 } // namespace views | 523 } // namespace views |
| OLD | NEW |