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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 break; | 381 break; |
382 case ScrollBarContextMenuCommand_ScrollNext: | 382 case ScrollBarContextMenuCommand_ScrollNext: |
383 ScrollByAmount(SCROLL_NEXT_LINE); | 383 ScrollByAmount(SCROLL_NEXT_LINE); |
384 break; | 384 break; |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 /////////////////////////////////////////////////////////////////////////////// | 388 /////////////////////////////////////////////////////////////////////////////// |
389 // BaseScrollBar, ScrollBar implementation: | 389 // BaseScrollBar, ScrollBar implementation: |
390 | 390 |
391 void BaseScrollBar::Update(int viewport_size, int content_size, | 391 void BaseScrollBar::Update(int viewport_size, |
| 392 int content_size, |
392 int contents_scroll_offset) { | 393 int contents_scroll_offset) { |
393 ScrollBar::Update(viewport_size, content_size, contents_scroll_offset); | 394 ScrollBar::Update(viewport_size, content_size, contents_scroll_offset); |
394 | 395 |
395 // Make sure contents_size is always > 0 to avoid divide by zero errors in | 396 // Make sure contents_size is always > 0 to avoid divide by zero errors in |
396 // calculations throughout this code. | 397 // calculations throughout this code. |
397 contents_size_ = std::max(1, content_size); | 398 contents_size_ = std::max(1, content_size); |
398 | 399 |
399 viewport_size_ = std::max(1, viewport_size); | 400 viewport_size_ = std::max(1, viewport_size); |
400 | 401 |
401 if (content_size < 0) | 402 if (content_size < 0) |
402 content_size = 0; | 403 content_size = 0; |
403 if (contents_scroll_offset < 0) | 404 if (contents_scroll_offset < 0) |
404 contents_scroll_offset = 0; | 405 contents_scroll_offset = 0; |
405 if (contents_scroll_offset > content_size) | 406 if (contents_scroll_offset > content_size) |
406 contents_scroll_offset = content_size; | 407 contents_scroll_offset = content_size; |
| 408 contents_scroll_offset_ = contents_scroll_offset; |
407 | 409 |
408 // Thumb Height and Thumb Pos. | 410 // Thumb Height and Thumb Pos. |
409 // The height of the thumb is the ratio of the Viewport height to the | 411 // The height of the thumb is the ratio of the Viewport height to the |
410 // content size multiplied by the height of the thumb track. | 412 // content size multiplied by the height of the thumb track. |
411 double ratio = static_cast<double>(viewport_size) / contents_size_; | 413 double ratio = static_cast<double>(viewport_size) / contents_size_; |
412 int thumb_size = static_cast<int>(ratio * GetTrackSize()); | 414 int thumb_size = static_cast<int>(ratio * GetTrackSize()); |
413 thumb_->SetSize(thumb_size); | 415 thumb_->SetSize(thumb_size); |
414 | 416 |
415 int thumb_position = CalculateThumbPosition(contents_scroll_offset); | 417 int thumb_position = CalculateThumbPosition(contents_scroll_offset); |
416 thumb_->SetPosition(thumb_position); | 418 thumb_->SetPosition(thumb_position); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // simple division can be rounded and there could be 1 pixel gap even when the | 493 // simple division can be rounded and there could be 1 pixel gap even when the |
492 // contents scroll down to the bottom. See crbug.com/244671 | 494 // contents scroll down to the bottom. See crbug.com/244671 |
493 if (contents_scroll_offset + viewport_size_ == contents_size_) { | 495 if (contents_scroll_offset + viewport_size_ == contents_size_) { |
494 int track_size = GetTrackSize(); | 496 int track_size = GetTrackSize(); |
495 return track_size - (viewport_size_ * GetTrackSize() / contents_size_); | 497 return track_size - (viewport_size_ * GetTrackSize() / contents_size_); |
496 } | 498 } |
497 return (contents_scroll_offset * GetTrackSize()) / contents_size_; | 499 return (contents_scroll_offset * GetTrackSize()) / contents_size_; |
498 } | 500 } |
499 | 501 |
500 int BaseScrollBar::CalculateContentsOffset(int thumb_position, | 502 int BaseScrollBar::CalculateContentsOffset(int thumb_position, |
501 bool scroll_to_middle) const { | 503 bool scroll_to_middle) const { |
502 if (scroll_to_middle) | 504 if (scroll_to_middle) |
503 thumb_position = thumb_position - (thumb_->GetSize() / 2); | 505 thumb_position = thumb_position - (thumb_->GetSize() / 2); |
504 return (thumb_position * contents_size_) / GetTrackSize(); | 506 return (thumb_position * contents_size_) / GetTrackSize(); |
505 } | 507 } |
506 | 508 |
507 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { | 509 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { |
508 thumb_track_state_ = state; | 510 thumb_track_state_ = state; |
509 SchedulePaint(); | 511 SchedulePaint(); |
510 } | 512 } |
511 | 513 |
512 } // namespace views | 514 } // namespace views |
OLD | NEW |