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 } |
| 33 |
29 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { | 34 void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { |
30 LayerImpl::PushPropertiesTo(layer); | 35 LayerImpl::PushPropertiesTo(layer); |
| 36 DCHECK(layer->ToScrollbarLayer()); |
| 37 layer->ToScrollbarLayer()->set_is_overlay_scrollbar(is_overlay_scrollbar_); |
| 38 PushScrollClipPropertiesTo(layer); |
| 39 } |
| 40 |
| 41 void ScrollbarLayerImplBase::PushScrollClipPropertiesTo(LayerImpl* layer) { |
| 42 DCHECK(layer->ToScrollbarLayer()); |
| 43 layer->ToScrollbarLayer()->SetScrollLayerById(ScrollLayerId()); |
| 44 layer->ToScrollbarLayer()->SetClipLayerById(ClipLayerId()); |
31 } | 45 } |
32 | 46 |
33 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { | 47 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { |
34 return this; | 48 return this; |
35 } | 49 } |
36 | 50 |
| 51 void ScrollbarLayerImplBase::SetScrollLayerById(int id) { |
| 52 LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id); |
| 53 if (scroll_layer_ == scroll_layer) |
| 54 return; |
| 55 |
| 56 if (scroll_layer_) |
| 57 scroll_layer_->RemoveScrollbar(this); |
| 58 scroll_layer_ = scroll_layer; |
| 59 if (scroll_layer_) |
| 60 scroll_layer_->AddScrollbar(this); |
| 61 } |
| 62 |
| 63 void ScrollbarLayerImplBase::SetClipLayerById(int id) { |
| 64 LayerImpl* clip_layer = layer_tree_impl()->LayerById(id); |
| 65 if (clip_layer_ == clip_layer) |
| 66 return; |
| 67 |
| 68 if (clip_layer_) |
| 69 clip_layer_->RemoveScrollbar(this); |
| 70 clip_layer_ = clip_layer; |
| 71 if (clip_layer_) |
| 72 clip_layer_->AddScrollbar(this); |
| 73 } |
| 74 |
37 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( | 75 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( |
38 gfx::RectF layer_rect) const { | 76 gfx::RectF layer_rect) const { |
39 // Don't intersect with the bounds as in LayerRectToContentRect() because | 77 // Don't intersect with the bounds as in LayerRectToContentRect() because |
40 // layer_rect here might be in coordinates of the containing layer. | 78 // layer_rect here might be in coordinates of the containing layer. |
41 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, | 79 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, |
42 contents_scale_x(), | 80 contents_scale_x(), |
43 contents_scale_y()); | 81 contents_scale_y()); |
44 return gfx::ToEnclosingRect(content_rect); | 82 return gfx::ToEnclosingRect(content_rect); |
45 } | 83 } |
46 | 84 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ? bounds().width() - thumb_thickness | 205 ? bounds().width() - thumb_thickness |
168 : thumb_thickness_adjustment, | 206 : thumb_thickness_adjustment, |
169 thumb_offset, | 207 thumb_offset, |
170 thumb_thickness - thumb_thickness_adjustment, | 208 thumb_thickness - thumb_thickness_adjustment, |
171 thumb_length); | 209 thumb_length); |
172 } | 210 } |
173 | 211 |
174 return ScrollbarLayerRectToContentRect(thumb_rect); | 212 return ScrollbarLayerRectToContentRect(thumb_rect); |
175 } | 213 } |
176 | 214 |
| 215 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { |
| 216 if (!clip_layer_ || !scroll_layer_) |
| 217 return; |
| 218 |
| 219 scroll_layer_->SetScrollbarPosition(this, clip_layer_); |
| 220 } |
| 221 |
177 } // namespace cc | 222 } // namespace cc |
OLD | NEW |