| 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 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 ScrollbarLayerImplBase::ScrollbarLayerImplBase( | 13 ScrollbarLayerImplBase::ScrollbarLayerImplBase( |
| 14 LayerTreeImpl* tree_impl, | 14 LayerTreeImpl* tree_impl, |
| 15 int id, | 15 int id, |
| 16 ScrollbarOrientation orientation, | 16 ScrollbarOrientation orientation, |
| 17 bool is_left_side_vertical_scrollbar, | 17 bool is_left_side_vertical_scrollbar, |
| 18 bool is_overlay) | 18 bool is_overlay) |
| 19 : LayerImpl(tree_impl, id), | 19 : LayerImpl(tree_impl, id), |
| 20 scroll_layer_(NULL), | 20 scroll_layer_(NULL), |
| 21 clip_layer_(NULL), | 21 clip_layer_(NULL), |
| 22 is_overlay_scrollbar_(is_overlay), | 22 is_overlay_scrollbar_(is_overlay), |
| 23 thumb_thickness_scale_factor_(1.f), | 23 thumb_thickness_scale_factor_(1.f), |
| 24 current_pos_(0.f), | 24 current_pos_(0.f), |
| 25 maximum_(0), | 25 maximum_(0), |
| 26 orientation_(orientation), | 26 orientation_(orientation), |
| 27 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), | 27 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), |
| 28 vertical_adjust_(0.f), | 28 vertical_adjust_(0.f), |
| 29 visible_to_total_length_ratio_(1.f) {} | 29 visible_to_total_length_ratio_(1.f), |
| 30 scrollbar_needs_animation_(false) { |
| 31 } |
| 30 | 32 |
| 31 ScrollbarLayerImplBase::~ScrollbarLayerImplBase() {} | 33 ScrollbarLayerImplBase::~ScrollbarLayerImplBase() {} |
| 32 | 34 |
| 33 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { | 35 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { |
| 34 float active_opacity = layer->opacity(); | 36 float active_opacity = layer->opacity(); |
| 35 LayerImpl::PushPropertiesTo(layer); | 37 LayerImpl::PushPropertiesTo(layer); |
| 36 layer->SetOpacity(active_opacity); | 38 layer->SetOpacity(active_opacity); |
| 37 DCHECK(layer->ToScrollbarLayer()); | 39 DCHECK(layer->ToScrollbarLayer()); |
| 38 layer->ToScrollbarLayer()->set_is_overlay_scrollbar(is_overlay_scrollbar_); | 40 layer->ToScrollbarLayer()->set_is_overlay_scrollbar(is_overlay_scrollbar_); |
| 39 PushScrollClipPropertiesTo(layer); | 41 PushScrollClipPropertiesTo(layer); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, | 104 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, |
| 103 contents_scale_x(), | 105 contents_scale_x(), |
| 104 contents_scale_y()); | 106 contents_scale_y()); |
| 105 return gfx::ToEnclosingRect(content_rect); | 107 return gfx::ToEnclosingRect(content_rect); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void ScrollbarLayerImplBase::SetCurrentPos(float current_pos) { | 110 void ScrollbarLayerImplBase::SetCurrentPos(float current_pos) { |
| 109 if (current_pos_ == current_pos) | 111 if (current_pos_ == current_pos) |
| 110 return; | 112 return; |
| 111 current_pos_ = current_pos; | 113 current_pos_ = current_pos; |
| 114 scrollbar_needs_animation_ = true; |
| 112 NoteLayerPropertyChanged(); | 115 NoteLayerPropertyChanged(); |
| 113 } | 116 } |
| 114 | 117 |
| 115 void ScrollbarLayerImplBase::SetMaximum(int maximum) { | 118 void ScrollbarLayerImplBase::SetMaximum(int maximum) { |
| 116 if (maximum_ == maximum) | 119 if (maximum_ == maximum) |
| 117 return; | 120 return; |
| 118 maximum_ = maximum; | 121 maximum_ = maximum; |
| 122 scrollbar_needs_animation_ = true; |
| 119 NoteLayerPropertyChanged(); | 123 NoteLayerPropertyChanged(); |
| 120 } | 124 } |
| 121 | 125 |
| 122 void ScrollbarLayerImplBase::SetVerticalAdjust(float vertical_adjust) { | 126 void ScrollbarLayerImplBase::SetVerticalAdjust(float vertical_adjust) { |
| 123 if (vertical_adjust_ == vertical_adjust) | 127 if (vertical_adjust_ == vertical_adjust) |
| 124 return; | 128 return; |
| 125 vertical_adjust_ = vertical_adjust; | 129 vertical_adjust_ = vertical_adjust; |
| 130 scrollbar_needs_animation_ = true; |
| 126 NoteLayerPropertyChanged(); | 131 NoteLayerPropertyChanged(); |
| 127 } | 132 } |
| 128 | 133 |
| 129 void ScrollbarLayerImplBase::SetVisibleToTotalLengthRatio(float ratio) { | 134 void ScrollbarLayerImplBase::SetVisibleToTotalLengthRatio(float ratio) { |
| 130 if (!IsThumbResizable()) | 135 if (!IsThumbResizable()) |
| 131 return; | 136 return; |
| 132 | 137 |
| 133 if (visible_to_total_length_ratio_ == ratio) | 138 if (visible_to_total_length_ratio_ == ratio) |
| 134 return; | 139 return; |
| 135 visible_to_total_length_ratio_ = ratio; | 140 visible_to_total_length_ratio_ = ratio; |
| 141 scrollbar_needs_animation_ = true; |
| 136 NoteLayerPropertyChanged(); | 142 NoteLayerPropertyChanged(); |
| 137 } | 143 } |
| 138 | 144 |
| 139 void ScrollbarLayerImplBase::SetThumbThicknessScaleFactor(float factor) { | 145 void ScrollbarLayerImplBase::SetThumbThicknessScaleFactor(float factor) { |
| 140 if (thumb_thickness_scale_factor_ == factor) | 146 if (thumb_thickness_scale_factor_ == factor) |
| 141 return; | 147 return; |
| 142 thumb_thickness_scale_factor_ = factor; | 148 thumb_thickness_scale_factor_ = factor; |
| 149 scrollbar_needs_animation_ = true; |
| 143 NoteLayerPropertyChanged(); | 150 NoteLayerPropertyChanged(); |
| 144 } | 151 } |
| 145 | 152 |
| 146 gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const { | 153 gfx::Rect ScrollbarLayerImplBase::ComputeThumbQuadRect() const { |
| 147 // Thumb extent is the length of the thumb in the scrolling direction, thumb | 154 // Thumb extent is the length of the thumb in the scrolling direction, thumb |
| 148 // thickness is in the perpendicular direction. Here's an example of a | 155 // thickness is in the perpendicular direction. Here's an example of a |
| 149 // horizontal scrollbar - inputs are above the scrollbar, computed values | 156 // horizontal scrollbar - inputs are above the scrollbar, computed values |
| 150 // below: | 157 // below: |
| 151 // | 158 // |
| 152 // |<------------------- track_length_ ------------------->| | 159 // |<------------------- track_length_ ------------------->| |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 250 } |
| 244 | 251 |
| 245 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { | 252 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { |
| 246 if (!clip_layer_ || !scroll_layer_) | 253 if (!clip_layer_ || !scroll_layer_) |
| 247 return; | 254 return; |
| 248 | 255 |
| 249 scroll_layer_->SetScrollbarPosition(this, clip_layer_); | 256 scroll_layer_->SetScrollbarPosition(this, clip_layer_); |
| 250 } | 257 } |
| 251 | 258 |
| 252 } // namespace cc | 259 } // namespace cc |
| OLD | NEW |