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/layers/layer.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 : LayerImpl(tree_impl, id), | 18 : LayerImpl(tree_impl, id), |
19 scroll_layer_id_(Layer::INVALID_ID), | 19 scroll_layer_(NULL), |
| 20 clip_layer_(NULL), |
20 is_overlay_scrollbar_(false), | 21 is_overlay_scrollbar_(false), |
21 thumb_thickness_scale_factor_(1.f), | 22 thumb_thickness_scale_factor_(1.f), |
22 current_pos_(0.f), | 23 current_pos_(0.f), |
23 maximum_(0), | 24 maximum_(0), |
24 orientation_(orientation), | 25 orientation_(orientation), |
25 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), | 26 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), |
26 vertical_adjust_(0.f), | 27 vertical_adjust_(0.f), |
27 visible_to_total_length_ratio_(1.f) {} | 28 visible_to_total_length_ratio_(1.f), |
| 29 opacity_can_animate_(false) {} |
| 30 |
| 31 ScrollbarLayerImplBase::~ScrollbarLayerImplBase() { |
| 32 } |
28 | 33 |
29 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { | 34 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { |
30 LayerImpl::PushPropertiesTo(layer); | 35 LayerImpl::PushPropertiesTo(layer); |
| 36 |
| 37 DCHECK(layer->ToScrollbarLayer()); |
| 38 layer->ToScrollbarLayer()->SetScrollLayerById(ScrollLayerId()); |
| 39 layer->ToScrollbarLayer()->SetClipLayerById(ClipLayerId()); |
31 } | 40 } |
32 | 41 |
33 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { | 42 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { |
34 return this; | 43 return this; |
35 } | 44 } |
36 | 45 |
| 46 void ScrollbarLayerImplBase::SetScrollLayerById(int id) { |
| 47 LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id); |
| 48 if (scroll_layer_ == scroll_layer) |
| 49 return; |
| 50 |
| 51 if (scroll_layer_) |
| 52 scroll_layer_->RemoveScrollbar(this); |
| 53 scroll_layer_ = scroll_layer; |
| 54 if (scroll_layer_) |
| 55 scroll_layer_->AddScrollbar(this); |
| 56 } |
| 57 |
| 58 void ScrollbarLayerImplBase::SetClipLayerById(int id) { |
| 59 LayerImpl* clip_layer = layer_tree_impl()->LayerById(id); |
| 60 if (clip_layer_ == clip_layer) |
| 61 return; |
| 62 |
| 63 if (clip_layer_) |
| 64 clip_layer_->RemoveScrollbar(this); |
| 65 clip_layer_ = clip_layer; |
| 66 if (clip_layer_) |
| 67 clip_layer_->AddScrollbar(this); |
| 68 } |
| 69 |
37 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( | 70 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( |
38 gfx::RectF layer_rect) const { | 71 gfx::RectF layer_rect) const { |
39 // Don't intersect with the bounds as in LayerRectToContentRect() because | 72 // Don't intersect with the bounds as in LayerRectToContentRect() because |
40 // layer_rect here might be in coordinates of the containing layer. | 73 // layer_rect here might be in coordinates of the containing layer. |
41 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, | 74 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, |
42 contents_scale_x(), | 75 contents_scale_x(), |
43 contents_scale_y()); | 76 contents_scale_y()); |
44 return gfx::ToEnclosingRect(content_rect); | 77 return gfx::ToEnclosingRect(content_rect); |
45 } | 78 } |
46 | 79 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ? bounds().width() - thumb_thickness | 193 ? bounds().width() - thumb_thickness |
161 : thumb_thickness_adjustment, | 194 : thumb_thickness_adjustment, |
162 thumb_offset, | 195 thumb_offset, |
163 thumb_thickness - thumb_thickness_adjustment, | 196 thumb_thickness - thumb_thickness_adjustment, |
164 thumb_length); | 197 thumb_length); |
165 } | 198 } |
166 | 199 |
167 return ScrollbarLayerRectToContentRect(thumb_rect); | 200 return ScrollbarLayerRectToContentRect(thumb_rect); |
168 } | 201 } |
169 | 202 |
| 203 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { |
| 204 if (!clip_layer_ || !scroll_layer_) |
| 205 return; |
| 206 |
| 207 scroll_layer_->SetScrollbarPosition(this, clip_layer_); |
| 208 } |
| 209 |
170 } // namespace cc | 210 } // namespace cc |
OLD | NEW |