Chromium Code Reviews| 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() { | |
|
aelias_OOO_until_Jul13
2014/01/16 03:44:04
This should make sure to call RemoveScrollbar() to
wjmaclean
2014/01/16 15:07:32
Done.
| |
| 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); | |
|
aelias_OOO_until_Jul13
2014/01/16 03:44:04
It's weird that the clip layer is getting called A
wjmaclean
2014/01/16 15:07:32
The scrollbar should not have to rely on polling t
| |
| 73 } | |
| 74 | |
| 37 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( | 75 gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( |
| 38 const gfx::RectF& layer_rect) const { | 76 const 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 ? bounds().width() - thumb_thickness | 208 ? bounds().width() - thumb_thickness |
| 171 : thumb_thickness_adjustment, | 209 : thumb_thickness_adjustment, |
| 172 thumb_offset, | 210 thumb_offset, |
| 173 thumb_thickness - thumb_thickness_adjustment, | 211 thumb_thickness - thumb_thickness_adjustment, |
| 174 thumb_length); | 212 thumb_length); |
| 175 } | 213 } |
| 176 | 214 |
| 177 return ScrollbarLayerRectToContentRect(thumb_rect); | 215 return ScrollbarLayerRectToContentRect(thumb_rect); |
| 178 } | 216 } |
| 179 | 217 |
| 218 void ScrollbarLayerImplBase::ScrollbarParametersDidChange() { | |
| 219 if (!clip_layer_ || !scroll_layer_) | |
| 220 return; | |
| 221 | |
| 222 scroll_layer_->SetScrollbarPosition(this, clip_layer_); | |
| 223 } | |
| 224 | |
| 180 } // namespace cc | 225 } // namespace cc |
| OLD | NEW |