| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/layers/scrollbar_layer_impl.h" | 5 #include "cc/layers/scrollbar_layer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 7 #include "cc/animation/scrollbar_animation_controller.h" | 9 #include "cc/animation/scrollbar_animation_controller.h" |
| 8 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
| 9 #include "cc/layers/quad_sink.h" | 11 #include "cc/layers/quad_sink.h" |
| 10 #include "cc/quads/solid_color_draw_quad.h" | 12 #include "cc/quads/solid_color_draw_quad.h" |
| 11 #include "cc/quads/texture_draw_quad.h" | 13 #include "cc/quads/texture_draw_quad.h" |
| 12 #include "cc/trees/layer_tree_impl.h" | 14 #include "cc/trees/layer_tree_impl.h" |
| 13 #include "cc/trees/layer_tree_settings.h" | 15 #include "cc/trees/layer_tree_settings.h" |
| 14 #include "ui/gfx/rect_conversions.h" | 16 #include "ui/gfx/rect_conversions.h" |
| 15 | 17 |
| 16 namespace cc { | 18 namespace cc { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (orientation_ == VERTICAL) | 236 if (orientation_ == VERTICAL) |
| 235 track_length += vertical_adjust_; | 237 track_length += vertical_adjust_; |
| 236 | 238 |
| 237 if (layer_tree_impl()->settings().solid_color_scrollbars) { | 239 if (layer_tree_impl()->settings().solid_color_scrollbars) { |
| 238 thumb_length = std::max( | 240 thumb_length = std::max( |
| 239 static_cast<int>(visible_to_total_length_ratio_ * track_length), | 241 static_cast<int>(visible_to_total_length_ratio_ * track_length), |
| 240 thumb_thickness_); | 242 thumb_thickness_); |
| 241 } | 243 } |
| 242 | 244 |
| 243 // With the length known, we can compute the thumb's position. | 245 // With the length known, we can compute the thumb's position. |
| 244 float ratio = current_pos_ / maximum_; | 246 float clamped_current_pos = |
| 247 std::min(std::max(current_pos_, 0.f), static_cast<float>(maximum_)); |
| 248 float ratio = clamped_current_pos / maximum_; |
| 245 float max_offset = track_length - thumb_length; | 249 float max_offset = track_length - thumb_length; |
| 246 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_; | 250 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_; |
| 247 | 251 |
| 248 gfx::RectF thumb_rect; | 252 gfx::RectF thumb_rect; |
| 249 if (orientation_ == HORIZONTAL) { | 253 if (orientation_ == HORIZONTAL) { |
| 250 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_, | 254 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_, |
| 251 thumb_length, thumb_thickness_); | 255 thumb_length, thumb_thickness_); |
| 252 } else { | 256 } else { |
| 253 thumb_rect = gfx::RectF(0.f, thumb_offset, | 257 thumb_rect = gfx::RectF(0.f, thumb_offset, |
| 254 thumb_thickness_, thumb_length); | 258 thumb_thickness_, thumb_length); |
| 255 } | 259 } |
| 256 | 260 |
| 257 return ScrollbarLayerRectToContentRect(thumb_rect); | 261 return ScrollbarLayerRectToContentRect(thumb_rect); |
| 258 } | 262 } |
| 259 | 263 |
| 260 void ScrollbarLayerImpl::DidLoseOutputSurface() { | 264 void ScrollbarLayerImpl::DidLoseOutputSurface() { |
| 261 track_resource_id_ = 0; | 265 track_resource_id_ = 0; |
| 262 thumb_resource_id_ = 0; | 266 thumb_resource_id_ = 0; |
| 263 } | 267 } |
| 264 | 268 |
| 265 const char* ScrollbarLayerImpl::LayerTypeAsString() const { | 269 const char* ScrollbarLayerImpl::LayerTypeAsString() const { |
| 266 return "cc::ScrollbarLayerImpl"; | 270 return "cc::ScrollbarLayerImpl"; |
| 267 } | 271 } |
| 268 | 272 |
| 269 } // namespace cc | 273 } // namespace cc |
| OLD | NEW |