| 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/solid_color_scrollbar_layer.h" | 5 #include "cc/layers/solid_color_scrollbar_layer.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "cc/layers/layer_impl.h" | 9 #include "cc/layers/layer_impl.h" |
| 10 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 10 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 11 #include "cc/proto/cc_conversions.h" | 11 #include "cc/proto/cc_conversions.h" |
| 12 #include "cc/proto/layer.pb.h" | 12 #include "cc/proto/layer.pb.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 std::unique_ptr<LayerImpl> SolidColorScrollbarLayer::CreateLayerImpl( | 16 std::unique_ptr<LayerImpl> SolidColorScrollbarLayer::CreateLayerImpl( |
| 17 LayerTreeImpl* tree_impl) { | 17 LayerTreeImpl* tree_impl) { |
| 18 const bool kIsOverlayScrollbar = true; | 18 const bool kIsOverlayScrollbar = true; |
| 19 return SolidColorScrollbarLayerImpl::Create(tree_impl, | 19 return SolidColorScrollbarLayerImpl::Create( |
| 20 id(), | 20 tree_impl, id(), orientation(), |
| 21 orientation(), | 21 solid_color_scrollbar_layer_inputs_.thumb_thickness, |
| 22 thumb_thickness_, | 22 solid_color_scrollbar_layer_inputs_.track_start, |
| 23 track_start_, | 23 solid_color_scrollbar_layer_inputs_.is_left_side_vertical_scrollbar, |
| 24 is_left_side_vertical_scrollbar_, | 24 kIsOverlayScrollbar); |
| 25 kIsOverlayScrollbar); | |
| 26 } | 25 } |
| 27 | 26 |
| 28 scoped_refptr<SolidColorScrollbarLayer> SolidColorScrollbarLayer::Create( | 27 scoped_refptr<SolidColorScrollbarLayer> SolidColorScrollbarLayer::Create( |
| 29 ScrollbarOrientation orientation, | 28 ScrollbarOrientation orientation, |
| 30 int thumb_thickness, | 29 int thumb_thickness, |
| 31 int track_start, | 30 int track_start, |
| 32 bool is_left_side_vertical_scrollbar, | 31 bool is_left_side_vertical_scrollbar, |
| 33 int scroll_layer_id) { | 32 int scroll_layer_id) { |
| 34 return make_scoped_refptr(new SolidColorScrollbarLayer( | 33 return make_scoped_refptr(new SolidColorScrollbarLayer( |
| 35 orientation, thumb_thickness, track_start, | 34 orientation, thumb_thickness, track_start, |
| 36 is_left_side_vertical_scrollbar, scroll_layer_id)); | 35 is_left_side_vertical_scrollbar, scroll_layer_id)); |
| 37 } | 36 } |
| 38 | 37 |
| 38 SolidColorScrollbarLayer::SolidColorScrollbarLayerInputs:: |
| 39 SolidColorScrollbarLayerInputs(ScrollbarOrientation orientation, |
| 40 int thumb_thickness, |
| 41 int track_start, |
| 42 bool is_left_side_vertical_scrollbar, |
| 43 int scroll_layer_id) |
| 44 : scroll_layer_id(Layer::INVALID_ID), |
| 45 orientation(orientation), |
| 46 thumb_thickness(thumb_thickness), |
| 47 track_start(track_start), |
| 48 is_left_side_vertical_scrollbar(is_left_side_vertical_scrollbar) {} |
| 49 |
| 50 SolidColorScrollbarLayer::SolidColorScrollbarLayerInputs:: |
| 51 ~SolidColorScrollbarLayerInputs() = default; |
| 52 |
| 39 SolidColorScrollbarLayer::SolidColorScrollbarLayer( | 53 SolidColorScrollbarLayer::SolidColorScrollbarLayer( |
| 40 ScrollbarOrientation orientation, | 54 ScrollbarOrientation orientation, |
| 41 int thumb_thickness, | 55 int thumb_thickness, |
| 42 int track_start, | 56 int track_start, |
| 43 bool is_left_side_vertical_scrollbar, | 57 bool is_left_side_vertical_scrollbar, |
| 44 int scroll_layer_id) | 58 int scroll_layer_id) |
| 45 : scroll_layer_id_(Layer::INVALID_ID), | 59 : solid_color_scrollbar_layer_inputs_(orientation, |
| 46 orientation_(orientation), | 60 thumb_thickness, |
| 47 thumb_thickness_(thumb_thickness), | 61 track_start, |
| 48 track_start_(track_start), | 62 is_left_side_vertical_scrollbar, |
| 49 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar) { | 63 scroll_layer_id) { |
| 50 Layer::SetOpacity(0.f); | 64 Layer::SetOpacity(0.f); |
| 51 } | 65 } |
| 52 | 66 |
| 53 SolidColorScrollbarLayer::~SolidColorScrollbarLayer() {} | 67 SolidColorScrollbarLayer::~SolidColorScrollbarLayer() {} |
| 54 | 68 |
| 55 ScrollbarLayerInterface* SolidColorScrollbarLayer::ToScrollbarLayer() { | 69 ScrollbarLayerInterface* SolidColorScrollbarLayer::ToScrollbarLayer() { |
| 56 return this; | 70 return this; |
| 57 } | 71 } |
| 58 | 72 |
| 59 void SolidColorScrollbarLayer::SetOpacity(float opacity) { | 73 void SolidColorScrollbarLayer::SetOpacity(float opacity) { |
| 60 // The opacity of a solid color scrollbar layer is always 0 on main thread. | 74 // The opacity of a solid color scrollbar layer is always 0 on main thread. |
| 61 DCHECK_EQ(opacity, 0.f); | 75 DCHECK_EQ(opacity, 0.f); |
| 62 Layer::SetOpacity(opacity); | 76 Layer::SetOpacity(opacity); |
| 63 } | 77 } |
| 64 | 78 |
| 65 void SolidColorScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { | 79 void SolidColorScrollbarLayer::PushPropertiesTo(LayerImpl* layer) { |
| 66 Layer::PushPropertiesTo(layer); | 80 Layer::PushPropertiesTo(layer); |
| 67 SolidColorScrollbarLayerImpl* scrollbar_layer = | 81 SolidColorScrollbarLayerImpl* scrollbar_layer = |
| 68 static_cast<SolidColorScrollbarLayerImpl*>(layer); | 82 static_cast<SolidColorScrollbarLayerImpl*>(layer); |
| 69 | 83 |
| 70 scrollbar_layer->SetScrollLayerId(scroll_layer_id_); | 84 scrollbar_layer->SetScrollLayerId( |
| 85 solid_color_scrollbar_layer_inputs_.scroll_layer_id); |
| 71 } | 86 } |
| 72 | 87 |
| 73 void SolidColorScrollbarLayer::SetNeedsDisplayRect(const gfx::Rect& rect) { | 88 void SolidColorScrollbarLayer::SetNeedsDisplayRect(const gfx::Rect& rect) { |
| 74 // Never needs repaint. | 89 // Never needs repaint. |
| 75 } | 90 } |
| 76 | 91 |
| 77 bool SolidColorScrollbarLayer::OpacityCanAnimateOnImplThread() const { | 92 bool SolidColorScrollbarLayer::OpacityCanAnimateOnImplThread() const { |
| 78 return true; | 93 return true; |
| 79 } | 94 } |
| 80 | 95 |
| 81 bool SolidColorScrollbarLayer::AlwaysUseActiveTreeOpacity() const { | 96 bool SolidColorScrollbarLayer::AlwaysUseActiveTreeOpacity() const { |
| 82 return true; | 97 return true; |
| 83 } | 98 } |
| 84 | 99 |
| 85 int SolidColorScrollbarLayer::ScrollLayerId() const { | 100 int SolidColorScrollbarLayer::ScrollLayerId() const { |
| 86 return scroll_layer_id_; | 101 return solid_color_scrollbar_layer_inputs_.scroll_layer_id; |
| 87 } | 102 } |
| 88 | 103 |
| 89 void SolidColorScrollbarLayer::SetScrollLayer(int layer_id) { | 104 void SolidColorScrollbarLayer::SetScrollLayer(int layer_id) { |
| 90 if (layer_id == scroll_layer_id_) | 105 if (layer_id == solid_color_scrollbar_layer_inputs_.scroll_layer_id) |
| 91 return; | 106 return; |
| 92 | 107 |
| 93 scroll_layer_id_ = layer_id; | 108 solid_color_scrollbar_layer_inputs_.scroll_layer_id = layer_id; |
| 94 SetNeedsFullTreeSync(); | 109 SetNeedsFullTreeSync(); |
| 95 } | 110 } |
| 96 | 111 |
| 97 ScrollbarOrientation SolidColorScrollbarLayer::orientation() const { | 112 ScrollbarOrientation SolidColorScrollbarLayer::orientation() const { |
| 98 return orientation_; | 113 return solid_color_scrollbar_layer_inputs_.orientation; |
| 99 } | 114 } |
| 100 | 115 |
| 101 void SolidColorScrollbarLayer::SetTypeForProtoSerialization( | 116 void SolidColorScrollbarLayer::SetTypeForProtoSerialization( |
| 102 proto::LayerNode* proto) const { | 117 proto::LayerNode* proto) const { |
| 103 proto->set_type(proto::LayerNode::SOLID_COLOR_SCROLLBAR_LAYER); | 118 proto->set_type(proto::LayerNode::SOLID_COLOR_SCROLLBAR_LAYER); |
| 104 } | 119 } |
| 105 | 120 |
| 106 void SolidColorScrollbarLayer::LayerSpecificPropertiesToProto( | 121 void SolidColorScrollbarLayer::LayerSpecificPropertiesToProto( |
| 107 proto::LayerProperties* proto) { | 122 proto::LayerProperties* proto) { |
| 108 Layer::LayerSpecificPropertiesToProto(proto); | 123 Layer::LayerSpecificPropertiesToProto(proto); |
| 109 | 124 |
| 110 proto::SolidColorScrollbarLayerProperties* scrollbar = | 125 proto::SolidColorScrollbarLayerProperties* scrollbar = |
| 111 proto->mutable_solid_scrollbar(); | 126 proto->mutable_solid_scrollbar(); |
| 112 scrollbar->set_scroll_layer_id(scroll_layer_id_); | 127 scrollbar->set_scroll_layer_id( |
| 113 scrollbar->set_thumb_thickness(thumb_thickness_); | 128 solid_color_scrollbar_layer_inputs_.scroll_layer_id); |
| 114 scrollbar->set_track_start(track_start_); | 129 scrollbar->set_thumb_thickness( |
| 130 solid_color_scrollbar_layer_inputs_.thumb_thickness); |
| 131 scrollbar->set_track_start(solid_color_scrollbar_layer_inputs_.track_start); |
| 115 scrollbar->set_is_left_side_vertical_scrollbar( | 132 scrollbar->set_is_left_side_vertical_scrollbar( |
| 116 is_left_side_vertical_scrollbar_); | 133 solid_color_scrollbar_layer_inputs_.is_left_side_vertical_scrollbar); |
| 117 scrollbar->set_orientation(ScrollbarOrientationToProto(orientation_)); | 134 scrollbar->set_orientation(ScrollbarOrientationToProto( |
| 135 solid_color_scrollbar_layer_inputs_.orientation)); |
| 118 } | 136 } |
| 119 | 137 |
| 120 void SolidColorScrollbarLayer::FromLayerSpecificPropertiesProto( | 138 void SolidColorScrollbarLayer::FromLayerSpecificPropertiesProto( |
| 121 const proto::LayerProperties& proto) { | 139 const proto::LayerProperties& proto) { |
| 122 Layer::FromLayerSpecificPropertiesProto(proto); | 140 Layer::FromLayerSpecificPropertiesProto(proto); |
| 123 | 141 |
| 124 const proto::SolidColorScrollbarLayerProperties& scrollbar = | 142 const proto::SolidColorScrollbarLayerProperties& scrollbar = |
| 125 proto.solid_scrollbar(); | 143 proto.solid_scrollbar(); |
| 126 scroll_layer_id_ = scrollbar.scroll_layer_id(); | 144 solid_color_scrollbar_layer_inputs_.scroll_layer_id = |
| 127 thumb_thickness_ = scrollbar.thumb_thickness(); | 145 scrollbar.scroll_layer_id(); |
| 128 track_start_ = scrollbar.track_start(); | 146 solid_color_scrollbar_layer_inputs_.thumb_thickness = |
| 129 is_left_side_vertical_scrollbar_ = | 147 scrollbar.thumb_thickness(); |
| 148 solid_color_scrollbar_layer_inputs_.track_start = scrollbar.track_start(); |
| 149 solid_color_scrollbar_layer_inputs_.is_left_side_vertical_scrollbar = |
| 130 scrollbar.is_left_side_vertical_scrollbar(); | 150 scrollbar.is_left_side_vertical_scrollbar(); |
| 131 orientation_ = ScrollbarOrientationFromProto(scrollbar.orientation()); | 151 solid_color_scrollbar_layer_inputs_.orientation = |
| 152 ScrollbarOrientationFromProto(scrollbar.orientation()); |
| 132 } | 153 } |
| 133 | 154 |
| 134 } // namespace cc | 155 } // namespace cc |
| OLD | NEW |