| 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/painted_scrollbar_layer.h" | 5 #include "cc/layers/painted_scrollbar_layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl( | 28 std::unique_ptr<LayerImpl> PaintedScrollbarLayer::CreateLayerImpl( |
| 29 LayerTreeImpl* tree_impl) { | 29 LayerTreeImpl* tree_impl) { |
| 30 return PaintedScrollbarLayerImpl::Create( | 30 return PaintedScrollbarLayerImpl::Create( |
| 31 tree_impl, id(), scrollbar_->Orientation(), | 31 tree_impl, id(), scrollbar_->Orientation(), |
| 32 scrollbar_->IsLeftSideVerticalScrollbar(), scrollbar_->IsOverlay()); | 32 scrollbar_->IsLeftSideVerticalScrollbar(), scrollbar_->IsOverlay()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( | 35 scoped_refptr<PaintedScrollbarLayer> PaintedScrollbarLayer::Create( |
| 36 std::unique_ptr<Scrollbar> scrollbar, | 36 std::unique_ptr<Scrollbar> scrollbar, |
| 37 int scroll_layer_id, | |
| 38 ElementId scroll_element_id) { | 37 ElementId scroll_element_id) { |
| 39 return make_scoped_refptr(new PaintedScrollbarLayer( | 38 return make_scoped_refptr( |
| 40 std::move(scrollbar), scroll_layer_id, scroll_element_id)); | 39 new PaintedScrollbarLayer(std::move(scrollbar), scroll_element_id)); |
| 41 } | 40 } |
| 42 | 41 |
| 43 PaintedScrollbarLayer::PaintedScrollbarLayer( | 42 PaintedScrollbarLayer::PaintedScrollbarLayer( |
| 44 std::unique_ptr<Scrollbar> scrollbar, | 43 std::unique_ptr<Scrollbar> scrollbar, |
| 45 int scroll_layer_id, | |
| 46 ElementId scroll_element_id) | 44 ElementId scroll_element_id) |
| 47 : scrollbar_(std::move(scrollbar)), | 45 : scrollbar_(std::move(scrollbar)), |
| 48 scroll_layer_id_(scroll_layer_id), | |
| 49 scroll_element_id_(scroll_element_id), | 46 scroll_element_id_(scroll_element_id), |
| 50 internal_contents_scale_(1.f), | 47 internal_contents_scale_(1.f), |
| 51 thumb_thickness_(scrollbar_->ThumbThickness()), | 48 thumb_thickness_(scrollbar_->ThumbThickness()), |
| 52 thumb_length_(scrollbar_->ThumbLength()), | 49 thumb_length_(scrollbar_->ThumbLength()), |
| 53 is_overlay_(scrollbar_->IsOverlay()), | 50 is_overlay_(scrollbar_->IsOverlay()), |
| 54 has_thumb_(scrollbar_->HasThumb()), | 51 has_thumb_(scrollbar_->HasThumb()), |
| 55 thumb_opacity_(scrollbar_->ThumbOpacity()) { | 52 thumb_opacity_(scrollbar_->ThumbOpacity()) { |
| 56 if (!scrollbar_->IsOverlay()) | 53 if (!scrollbar_->IsOverlay()) |
| 57 AddMainThreadScrollingReasons( | 54 AddMainThreadScrollingReasons( |
| 58 MainThreadScrollingReason::kScrollbarScrolling); | 55 MainThreadScrollingReason::kScrollbarScrolling); |
| 59 } | 56 } |
| 60 | 57 |
| 61 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} | 58 PaintedScrollbarLayer::~PaintedScrollbarLayer() {} |
| 62 | 59 |
| 63 ElementId PaintedScrollbarLayer::scroll_element_id() const { | 60 ElementId PaintedScrollbarLayer::scroll_element_id() const { |
| 64 return scroll_element_id_; | 61 return scroll_element_id_; |
| 65 } | 62 } |
| 66 | 63 |
| 67 void PaintedScrollbarLayer::SetScrollInfo(int layer_id, ElementId element_id) { | 64 void PaintedScrollbarLayer::SetScrollElementId(ElementId element_id) { |
| 68 if (layer_id == scroll_layer_id_ && element_id == scroll_element_id_) | 65 if (element_id == scroll_element_id_) |
| 69 return; | 66 return; |
| 70 | 67 |
| 71 scroll_layer_id_ = layer_id; | |
| 72 scroll_element_id_ = element_id; | 68 scroll_element_id_ = element_id; |
| 73 SetNeedsFullTreeSync(); | 69 SetNeedsFullTreeSync(); |
| 74 } | 70 } |
| 75 | 71 |
| 76 bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const { | 72 bool PaintedScrollbarLayer::OpacityCanAnimateOnImplThread() const { |
| 77 return scrollbar_->IsOverlay(); | 73 return scrollbar_->IsOverlay(); |
| 78 } | 74 } |
| 79 | 75 |
| 80 bool PaintedScrollbarLayer::AlwaysUseActiveTreeOpacity() const { | 76 bool PaintedScrollbarLayer::AlwaysUseActiveTreeOpacity() const { |
| 81 return true; | 77 return true; |
| 82 } | 78 } |
| 83 | 79 |
| 84 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { | 80 ScrollbarOrientation PaintedScrollbarLayer::orientation() const { |
| 85 return scrollbar_->Orientation(); | 81 return scrollbar_->Orientation(); |
| 86 } | 82 } |
| 87 | 83 |
| 88 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 84 void PaintedScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
| 89 Layer::PushPropertiesTo(layer); | 85 Layer::PushPropertiesTo(layer); |
| 90 | 86 |
| 91 PaintedScrollbarLayerImpl* scrollbar_layer = | 87 PaintedScrollbarLayerImpl* scrollbar_layer = |
| 92 static_cast<PaintedScrollbarLayerImpl*>(layer); | 88 static_cast<PaintedScrollbarLayerImpl*>(layer); |
| 93 | 89 |
| 94 scrollbar_layer->SetScrollInfo(scroll_layer_id_, scroll_element_id_); | 90 scrollbar_layer->SetScrollElementId(scroll_element_id_); |
| 95 scrollbar_layer->set_internal_contents_scale_and_bounds( | 91 scrollbar_layer->set_internal_contents_scale_and_bounds( |
| 96 internal_contents_scale_, internal_content_bounds_); | 92 internal_contents_scale_, internal_content_bounds_); |
| 97 | 93 |
| 98 scrollbar_layer->SetThumbThickness(thumb_thickness_); | 94 scrollbar_layer->SetThumbThickness(thumb_thickness_); |
| 99 scrollbar_layer->SetThumbLength(thumb_length_); | 95 scrollbar_layer->SetThumbLength(thumb_length_); |
| 100 if (orientation() == HORIZONTAL) { | 96 if (orientation() == HORIZONTAL) { |
| 101 scrollbar_layer->SetTrackStart( | 97 scrollbar_layer->SetTrackStart( |
| 102 track_rect_.x() - location_.x()); | 98 track_rect_.x() - location_.x()); |
| 103 scrollbar_layer->SetTrackLength(track_rect_.width()); | 99 scrollbar_layer->SetTrackLength(track_rect_.width()); |
| 104 } else { | 100 } else { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 285 |
| 290 scrollbar_->PaintPart(&canvas, part, layer_rect); | 286 scrollbar_->PaintPart(&canvas, part, layer_rect); |
| 291 // Make sure that the pixels are no longer mutable to unavoid unnecessary | 287 // Make sure that the pixels are no longer mutable to unavoid unnecessary |
| 292 // allocation and copying. | 288 // allocation and copying. |
| 293 skbitmap.setImmutable(); | 289 skbitmap.setImmutable(); |
| 294 | 290 |
| 295 return UIResourceBitmap(skbitmap); | 291 return UIResourceBitmap(skbitmap); |
| 296 } | 292 } |
| 297 | 293 |
| 298 } // namespace cc | 294 } // namespace cc |
| OLD | NEW |