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
3 // found in the LICENSE file.
4
5 #include "cc/layers/solid_color_scrollbar_layer.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "cc/layers/layer_impl.h"
9 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
10
11 namespace cc {
12
CreateLayerImpl(LayerTreeImpl * tree_impl)13 scoped_ptr<LayerImpl> SolidColorScrollbarLayer::CreateLayerImpl(
14 LayerTreeImpl* tree_impl) {
15 const bool kIsOverlayScrollbar = true;
16 return SolidColorScrollbarLayerImpl::Create(tree_impl,
17 id(),
18 orientation(),
19 thumb_thickness_,
20 track_start_,
21 is_left_side_vertical_scrollbar_,
22 kIsOverlayScrollbar)
23 .PassAs<LayerImpl>();
24 }
25
Create(ScrollbarOrientation orientation,int thumb_thickness,int track_start,bool is_left_side_vertical_scrollbar,int scroll_layer_id)26 scoped_refptr<SolidColorScrollbarLayer> SolidColorScrollbarLayer::Create(
27 ScrollbarOrientation orientation,
28 int thumb_thickness,
29 int track_start,
30 bool is_left_side_vertical_scrollbar,
31 int scroll_layer_id) {
32 return make_scoped_refptr(
33 new SolidColorScrollbarLayer(orientation,
34 thumb_thickness,
35 track_start,
36 is_left_side_vertical_scrollbar,
37 scroll_layer_id));
38 }
39
SolidColorScrollbarLayer(ScrollbarOrientation orientation,int thumb_thickness,int track_start,bool is_left_side_vertical_scrollbar,int scroll_layer_id)40 SolidColorScrollbarLayer::SolidColorScrollbarLayer(
41 ScrollbarOrientation orientation,
42 int thumb_thickness,
43 int track_start,
44 bool is_left_side_vertical_scrollbar,
45 int scroll_layer_id)
46 : scroll_layer_id_(Layer::INVALID_ID),
47 clip_layer_id_(scroll_layer_id),
48 orientation_(orientation),
49 thumb_thickness_(thumb_thickness),
50 track_start_(track_start),
51 is_left_side_vertical_scrollbar_(is_left_side_vertical_scrollbar) {}
52
~SolidColorScrollbarLayer()53 SolidColorScrollbarLayer::~SolidColorScrollbarLayer() {}
54
ToScrollbarLayer()55 ScrollbarLayerInterface* SolidColorScrollbarLayer::ToScrollbarLayer() {
56 return this;
57 }
58
PushPropertiesTo(LayerImpl * layer)59 void SolidColorScrollbarLayer::PushPropertiesTo(LayerImpl* layer) {
60 Layer::PushPropertiesTo(layer);
61 PushScrollClipPropertiesTo(layer);
62 }
63
PushScrollClipPropertiesTo(LayerImpl * layer)64 void SolidColorScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) {
65 SolidColorScrollbarLayerImpl* scrollbar_layer =
66 static_cast<SolidColorScrollbarLayerImpl*>(layer);
67
68 scrollbar_layer->SetScrollLayerById(scroll_layer_id_);
69 scrollbar_layer->SetClipLayerById(clip_layer_id_);
70 }
71
SetNeedsDisplayRect(const gfx::RectF &)72 void SolidColorScrollbarLayer::SetNeedsDisplayRect(const gfx::RectF&) {
73 // Never needs repaint.
74 }
75
OpacityCanAnimateOnImplThread() const76 bool SolidColorScrollbarLayer::OpacityCanAnimateOnImplThread() const {
77 return true;
78 }
79
ScrollLayerId() const80 int SolidColorScrollbarLayer::ScrollLayerId() const {
81 return scroll_layer_id_;
82 }
83
SetScrollLayer(int layer_id)84 void SolidColorScrollbarLayer::SetScrollLayer(int layer_id) {
85 if (layer_id == scroll_layer_id_)
86 return;
87
88 scroll_layer_id_ = layer_id;
89 SetNeedsFullTreeSync();
90 }
91
SetClipLayer(int layer_id)92 void SolidColorScrollbarLayer::SetClipLayer(int layer_id) {
93 if (layer_id == clip_layer_id_)
94 return;
95
96 clip_layer_id_ = layer_id;
97 SetNeedsFullTreeSync();
98 }
99
orientation() const100 ScrollbarOrientation SolidColorScrollbarLayer::orientation() const {
101 return orientation_;
102 }
103
104 } // namespace cc
105