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 bool is_overlay) |
18 : LayerImpl(tree_impl, id), | 19 : LayerImpl(tree_impl, id), |
19 scroll_layer_id_(Layer::INVALID_ID), | 20 scroll_layer_(NULL), |
20 is_overlay_scrollbar_(false), | 21 clip_layer_(NULL), |
| 22 is_overlay_scrollbar_(is_overlay), |
21 thumb_thickness_scale_factor_(1.f), | 23 thumb_thickness_scale_factor_(1.f), |
22 current_pos_(0.f), | 24 current_pos_(0.f), |
23 maximum_(0), | 25 maximum_(0), |
24 orientation_(orientation), | 26 orientation_(orientation), |
25 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), | 27 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar), |
26 vertical_adjust_(0.f), | 28 vertical_adjust_(0.f), |
27 visible_to_total_length_ratio_(1.f) {} | 29 visible_to_total_length_ratio_(1.f) {} |
28 | 30 |
| 31 ScrollbarLayerImplBase::~ScrollbarLayerImplBase() {} |
| 32 |
29 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { | 33 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { |
30 LayerImpl::PushPropertiesTo(layer); | 34 LayerImpl::PushPropertiesTo(layer); |
| 35 DCHECK(layer->ToScrollbarLayer()); |
| 36 layer->ToScrollbarLayer()->set_is_overlay_scrollbar(is_overlay_scrollbar_); |
| 37 PushScrollClipPropertiesTo(layer); |
| 38 } |
| 39 |
| 40 void ScrollbarLayerImplBase::PushScrollClipPropertiesTo(LayerImpl* layer) { |
| 41 DCHECK(layer->ToScrollbarLayer()); |
| 42 layer->ToScrollbarLayer()->SetScrollLayerById(ScrollLayerId()); |
| 43 layer->ToScrollbarLayer()->SetClipLayerById(ClipLayerId()); |
31 } | 44 } |
32 | 45 |
33 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { | 46 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { |
34 return this; | 47 return this; |
35 } | 48 } |
36 | 49 |
| 50 void ScrollbarLayerImplBase::SetScrollLayerById(int id) { |
| 51 LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id); |
| 52 if (scroll_layer_ == scroll_layer) |
| 53 return; |
| 54 |
| 55 if (scroll_layer_) |
| 56 scroll_layer_->RemoveScrollbar(this); |
| 57 scroll_layer_ = scroll_layer; |
| 58 if (scroll_layer_) |
| 59 scroll_layer_->AddScrollbar(this); |
| 60 } |
| 61 |
| 62 void ScrollbarLayerImplBase::SetClipLayerById(int id) { |
| 63 LayerImpl* clip_layer = layer_tree_impl()->LayerById(id); |
| 64 if (clip_layer_ == clip_layer) |
| 65 return; |
| 66 |
| 67 if (clip_layer_) |
| 68 clip_layer_->RemoveScrollbar(this); |
| 69 clip_layer_ = clip_layer; |
| 70 if (clip_layer_) |
| 71 clip_layer_->AddScrollbar(this); |
| 72 } |
| 73 |
37 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( | 74 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( |
38 const gfx::RectF& layer_rect) const { | 75 const gfx::RectF& layer_rect) const { |
39 // Don't intersect with the bounds as in LayerRectToContentRect() because | 76 // Don't intersect with the bounds as in LayerRectToContentRect() because |
40 // layer_rect here might be in coordinates of the containing layer. | 77 // layer_rect here might be in coordinates of the containing layer. |
41 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, | 78 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, |
42 contents_scale_x(), | 79 contents_scale_x(), |
43 contents_scale_y()); | 80 contents_scale_y()); |
44 return gfx::ToEnclosingRect(content_rect); | 81 return gfx::ToEnclosingRect(content_rect); |
45 } | 82 } |
46 | 83 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 ? bounds().width() - thumb_thickness | 207 ? bounds().width() - thumb_thickness |
171 : thumb_thickness_adjustment, | 208 : thumb_thickness_adjustment, |
172 thumb_offset, | 209 thumb_offset, |
173 thumb_thickness - thumb_thickness_adjustment, | 210 thumb_thickness - thumb_thickness_adjustment, |
174 thumb_length); | 211 thumb_length); |
175 } | 212 } |
176 | 213 |
177 return ScrollbarLayerRectToContentRect(thumb_rect); | 214 return ScrollbarLayerRectToContentRect(thumb_rect); |
178 } | 215 } |
179 | 216 |
| 217 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { |
| 218 if (!clip_layer_ || !scroll_layer_) |
| 219 return; |
| 220 |
| 221 scroll_layer_->SetScrollbarPosition(this, clip_layer_); |
| 222 } |
| 223 |
180 } // namespace cc | 224 } // namespace cc |
OLD | NEW |