| 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 14 matching lines...) Expand all Loading... |
| 25 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 26 | 26 |
| 27 #undef min | 27 #undef min |
| 28 #undef max | 28 #undef max |
| 29 | 29 |
| 30 namespace views { | 30 namespace views { |
| 31 | 31 |
| 32 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
| 33 // BaseScrollBar, public: | 33 // BaseScrollBar, public: |
| 34 | 34 |
| 35 BaseScrollBar::BaseScrollBar(bool horizontal, BaseScrollBarThumb* thumb) | 35 BaseScrollBar::BaseScrollBar(bool horizontal) |
| 36 : ScrollBar(horizontal), | 36 : ScrollBar(horizontal), |
| 37 thumb_(thumb), | 37 thumb_(nullptr), |
| 38 contents_size_(0), | 38 contents_size_(0), |
| 39 contents_scroll_offset_(0), | 39 contents_scroll_offset_(0), |
| 40 viewport_size_(0), | 40 viewport_size_(0), |
| 41 last_scroll_amount_(SCROLL_NONE), | 41 last_scroll_amount_(SCROLL_NONE), |
| 42 repeater_(base::Bind(&BaseScrollBar::TrackClicked, | 42 repeater_(base::Bind(&BaseScrollBar::TrackClicked, |
| 43 base::Unretained(this))), | 43 base::Unretained(this))), |
| 44 context_menu_mouse_position_(0) { | 44 context_menu_mouse_position_(0) { |
| 45 AddChildView(thumb_); | 45 set_context_menu_controller(this); |
| 46 } |
| 46 | 47 |
| 47 set_context_menu_controller(this); | 48 BaseScrollBar::~BaseScrollBar() {} |
| 48 thumb_->set_context_menu_controller(this); | 49 |
| 50 void BaseScrollBar::SetThumb(BaseScrollBarThumb* thumb) { |
| 51 DCHECK(!thumb_); |
| 52 thumb_ = thumb; |
| 53 AddChildView(thumb); |
| 54 thumb->set_context_menu_controller(this); |
| 49 } | 55 } |
| 50 | 56 |
| 51 void BaseScrollBar::ScrollByAmount(ScrollAmount amount) { | 57 void BaseScrollBar::ScrollByAmount(ScrollAmount amount) { |
| 52 int offset = contents_scroll_offset_; | 58 int offset = contents_scroll_offset_; |
| 53 switch (amount) { | 59 switch (amount) { |
| 54 case SCROLL_START: | 60 case SCROLL_START: |
| 55 offset = GetMinPosition(); | 61 offset = GetMinPosition(); |
| 56 break; | 62 break; |
| 57 case SCROLL_END: | 63 case SCROLL_END: |
| 58 offset = GetMaxPosition(); | 64 offset = GetMaxPosition(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 offset += GetScrollIncrement(true, true); | 79 offset += GetScrollIncrement(true, true); |
| 74 offset = std::min(GetMaxPosition(), offset); | 80 offset = std::min(GetMaxPosition(), offset); |
| 75 break; | 81 break; |
| 76 default: | 82 default: |
| 77 break; | 83 break; |
| 78 } | 84 } |
| 79 contents_scroll_offset_ = offset; | 85 contents_scroll_offset_ = offset; |
| 80 ScrollContentsToOffset(); | 86 ScrollContentsToOffset(); |
| 81 } | 87 } |
| 82 | 88 |
| 83 BaseScrollBar::~BaseScrollBar() { | |
| 84 } | |
| 85 | |
| 86 void BaseScrollBar::ScrollToThumbPosition(int thumb_position, | 89 void BaseScrollBar::ScrollToThumbPosition(int thumb_position, |
| 87 bool scroll_to_middle) { | 90 bool scroll_to_middle) { |
| 88 contents_scroll_offset_ = | 91 contents_scroll_offset_ = |
| 89 CalculateContentsOffset(thumb_position, scroll_to_middle); | 92 CalculateContentsOffset(thumb_position, scroll_to_middle); |
| 90 if (contents_scroll_offset_ < GetMinPosition()) { | 93 if (contents_scroll_offset_ < GetMinPosition()) { |
| 91 contents_scroll_offset_ = GetMinPosition(); | 94 contents_scroll_offset_ = GetMinPosition(); |
| 92 } else if (contents_scroll_offset_ > GetMaxPosition()) { | 95 } else if (contents_scroll_offset_ > GetMaxPosition()) { |
| 93 contents_scroll_offset_ = GetMaxPosition(); | 96 contents_scroll_offset_ = GetMaxPosition(); |
| 94 } | 97 } |
| 95 ScrollContentsToOffset(); | 98 ScrollContentsToOffset(); |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 int track_size = GetTrackSize(); | 480 int track_size = GetTrackSize(); |
| 478 if (track_size == thumb_size) | 481 if (track_size == thumb_size) |
| 479 return 0; | 482 return 0; |
| 480 if (scroll_to_middle) | 483 if (scroll_to_middle) |
| 481 thumb_position = thumb_position - (thumb_size / 2); | 484 thumb_position = thumb_position - (thumb_size / 2); |
| 482 return (thumb_position * (contents_size_ - viewport_size_)) / | 485 return (thumb_position * (contents_size_ - viewport_size_)) / |
| 483 (track_size - thumb_size); | 486 (track_size - thumb_size); |
| 484 } | 487 } |
| 485 | 488 |
| 486 } // namespace views | 489 } // namespace views |
| OLD | NEW |