OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/layers/scrollbar_layer_impl_base.h" | 5 #include "cc/layers/scrollbar_layer_impl_base.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "cc/trees/layer_tree_impl.h" | 8 #include "cc/trees/layer_tree_impl.h" |
9 #include "ui/gfx/rect_conversions.h" | 9 #include "ui/gfx/rect_conversions.h" |
10 | 10 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // means the quads may extend outside the layer's bounds. | 205 // means the quads may extend outside the layer's bounds. |
206 | 206 |
207 // With the length known, we can compute the thumb's position. | 207 // With the length known, we can compute the thumb's position. |
208 float track_length = TrackLength(); | 208 float track_length = TrackLength(); |
209 int thumb_length = ThumbLength(); | 209 int thumb_length = ThumbLength(); |
210 int thumb_thickness = ThumbThickness(); | 210 int thumb_thickness = ThumbThickness(); |
211 | 211 |
212 // With the length known, we can compute the thumb's position. | 212 // With the length known, we can compute the thumb's position. |
213 float clamped_current_pos = | 213 float clamped_current_pos = |
214 std::min(std::max(current_pos_, 0.f), static_cast<float>(maximum_)); | 214 std::min(std::max(current_pos_, 0.f), static_cast<float>(maximum_)); |
215 float ratio = clamped_current_pos / maximum_; | 215 |
216 float max_offset = track_length - thumb_length; | 216 int thumb_offset = TrackStart(); |
217 int thumb_offset = static_cast<int>(ratio * max_offset) + TrackStart(); | 217 if (maximum_ > 0) { |
| 218 float ratio = clamped_current_pos / maximum_; |
| 219 float max_offset = track_length - thumb_length; |
| 220 thumb_offset += static_cast<int>(ratio * max_offset); |
| 221 } |
218 | 222 |
219 float thumb_thickness_adjustment = | 223 float thumb_thickness_adjustment = |
220 thumb_thickness * (1.f - thumb_thickness_scale_factor_); | 224 thumb_thickness * (1.f - thumb_thickness_scale_factor_); |
221 | 225 |
222 gfx::RectF thumb_rect; | 226 gfx::RectF thumb_rect; |
223 if (orientation_ == HORIZONTAL) { | 227 if (orientation_ == HORIZONTAL) { |
224 thumb_rect = gfx::RectF(thumb_offset, | 228 thumb_rect = gfx::RectF(thumb_offset, |
225 vertical_adjust_ + thumb_thickness_adjustment, | 229 vertical_adjust_ + thumb_thickness_adjustment, |
226 thumb_length, | 230 thumb_length, |
227 thumb_thickness - thumb_thickness_adjustment); | 231 thumb_thickness - thumb_thickness_adjustment); |
(...skipping 11 matching lines...) Expand all Loading... |
239 } | 243 } |
240 | 244 |
241 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { | 245 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { |
242 if (!clip_layer_ || !scroll_layer_) | 246 if (!clip_layer_ || !scroll_layer_) |
243 return; | 247 return; |
244 | 248 |
245 scroll_layer_->SetScrollbarPosition(this, clip_layer_); | 249 scroll_layer_->SetScrollbarPosition(this, clip_layer_); |
246 } | 250 } |
247 | 251 |
248 } // namespace cc | 252 } // namespace cc |
OLD | NEW |