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 |
(...skipping 29 matching lines...) Expand all Loading... |
40 void ScrollbarLayerImplBase::PushScrollClipPropertiesTo(LayerImpl* layer) { | 40 void ScrollbarLayerImplBase::PushScrollClipPropertiesTo(LayerImpl* layer) { |
41 DCHECK(layer->ToScrollbarLayer()); | 41 DCHECK(layer->ToScrollbarLayer()); |
42 layer->ToScrollbarLayer()->SetScrollLayerById(ScrollLayerId()); | 42 layer->ToScrollbarLayer()->SetScrollLayerById(ScrollLayerId()); |
43 layer->ToScrollbarLayer()->SetClipLayerById(ClipLayerId()); | 43 layer->ToScrollbarLayer()->SetClipLayerById(ClipLayerId()); |
44 } | 44 } |
45 | 45 |
46 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { | 46 ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { |
47 return this; | 47 return this; |
48 } | 48 } |
49 | 49 |
| 50 namespace { |
| 51 |
| 52 typedef void (LayerImpl::*ScrollbarRegistrationOperation)( |
| 53 ScrollbarLayerImplBase*); |
| 54 |
| 55 void RegisterScrollbarWithLayers(ScrollbarLayerImplBase* scrollbar, |
| 56 LayerImpl* container_layer, |
| 57 LayerImpl* scroll_layer, |
| 58 ScrollbarRegistrationOperation operation) { |
| 59 if (!container_layer || !scroll_layer) |
| 60 return; |
| 61 |
| 62 DCHECK(scrollbar); |
| 63 |
| 64 // Scrollbars must be notifed of changes to their scroll and container layers |
| 65 // and all scrollable layers in between. |
| 66 for (LayerImpl* current_layer = scroll_layer; |
| 67 current_layer && current_layer != container_layer->parent(); |
| 68 current_layer = current_layer->parent()) { |
| 69 // TODO(wjmaclean) We shouldn't need to exempt the scroll_layer from the |
| 70 // scrollable() test below. https://crbug.com/367858. |
| 71 if (current_layer->scrollable() || current_layer == container_layer || |
| 72 current_layer == scroll_layer) |
| 73 (current_layer->*operation)(scrollbar); |
| 74 } |
| 75 } |
| 76 } // namespace |
| 77 |
50 void ScrollbarLayerImplBase::SetScrollLayerById(int id) { | 78 void ScrollbarLayerImplBase::SetScrollLayerById(int id) { |
51 LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id); | 79 LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id); |
52 if (scroll_layer_ == scroll_layer) | 80 if (scroll_layer_ == scroll_layer) |
53 return; | 81 return; |
54 | 82 |
55 if (scroll_layer_) | 83 RegisterScrollbarWithLayers( |
56 scroll_layer_->RemoveScrollbar(this); | 84 this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar); |
57 scroll_layer_ = scroll_layer; | 85 scroll_layer_ = scroll_layer; |
58 if (scroll_layer_) | 86 RegisterScrollbarWithLayers( |
59 scroll_layer_->AddScrollbar(this); | 87 this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar); |
60 } | 88 } |
61 | 89 |
62 void ScrollbarLayerImplBase::SetClipLayerById(int id) { | 90 void ScrollbarLayerImplBase::SetClipLayerById(int id) { |
63 LayerImpl* clip_layer = layer_tree_impl()->LayerById(id); | 91 LayerImpl* clip_layer = layer_tree_impl()->LayerById(id); |
64 if (clip_layer_ == clip_layer) | 92 if (clip_layer_ == clip_layer) |
65 return; | 93 return; |
66 | 94 |
67 if (clip_layer_) | 95 RegisterScrollbarWithLayers( |
68 clip_layer_->RemoveScrollbar(this); | 96 this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar); |
69 clip_layer_ = clip_layer; | 97 clip_layer_ = clip_layer; |
70 if (clip_layer_) | 98 RegisterScrollbarWithLayers( |
71 clip_layer_->AddScrollbar(this); | 99 this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar); |
72 } | 100 } |
73 | 101 |
74 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( | 102 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( |
75 const gfx::RectF& layer_rect) const { | 103 const gfx::RectF& layer_rect) const { |
76 // Don't intersect with the bounds as in LayerRectToContentRect() because | 104 // Don't intersect with the bounds as in LayerRectToContentRect() because |
77 // layer_rect here might be in coordinates of the containing layer. | 105 // layer_rect here might be in coordinates of the containing layer. |
78 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, | 106 gfx::RectF content_rect = gfx::ScaleRect(layer_rect, |
79 contents_scale_x(), | 107 contents_scale_x(), |
80 contents_scale_y()); | 108 contents_scale_y()); |
81 return gfx::ToEnclosingRect(content_rect); | 109 return gfx::ToEnclosingRect(content_rect); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } | 243 } |
216 | 244 |
217 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { | 245 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { |
218 if (!clip_layer_ || !scroll_layer_) | 246 if (!clip_layer_ || !scroll_layer_) |
219 return; | 247 return; |
220 | 248 |
221 scroll_layer_->SetScrollbarPosition(this, clip_layer_); | 249 scroll_layer_->SetScrollbarPosition(this, clip_layer_); |
222 } | 250 } |
223 | 251 |
224 } // namespace cc | 252 } // namespace cc |
OLD | NEW |