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.
5 #include "cc/layers/painted_scrollbar_layer_impl.h"
9 #include "cc/animation/scrollbar_animation_controller.h"
10 #include "cc/layers/layer.h"
11 #include "cc/quads/solid_color_draw_quad.h"
12 #include "cc/quads/texture_draw_quad.h"
13 #include "cc/trees/layer_tree_impl.h"
14 #include "cc/trees/layer_tree_settings.h"
15 #include "cc/trees/occlusion.h"
16 #include "ui/gfx/geometry/rect_conversions.h"
20 scoped_ptr
<PaintedScrollbarLayerImpl
> PaintedScrollbarLayerImpl::Create(
21 LayerTreeImpl
* tree_impl
,
23 ScrollbarOrientation orientation
) {
24 return make_scoped_ptr(
25 new PaintedScrollbarLayerImpl(tree_impl
, id
, orientation
));
28 PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl(
29 LayerTreeImpl
* tree_impl
,
31 ScrollbarOrientation orientation
)
32 : ScrollbarLayerImplBase(tree_impl
, id
, orientation
, false, false),
33 track_ui_resource_id_(0),
34 thumb_ui_resource_id_(0),
39 vertical_adjust_(0.f
),
40 scroll_layer_id_(Layer::INVALID_ID
) {}
42 PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {}
44 scoped_ptr
<LayerImpl
> PaintedScrollbarLayerImpl::CreateLayerImpl(
45 LayerTreeImpl
* tree_impl
) {
46 return PaintedScrollbarLayerImpl::Create(tree_impl
, id(), orientation());
49 void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl
* layer
) {
50 ScrollbarLayerImplBase::PushPropertiesTo(layer
);
52 PaintedScrollbarLayerImpl
* scrollbar_layer
=
53 static_cast<PaintedScrollbarLayerImpl
*>(layer
);
55 scrollbar_layer
->SetThumbThickness(thumb_thickness_
);
56 scrollbar_layer
->SetThumbLength(thumb_length_
);
57 scrollbar_layer
->SetTrackStart(track_start_
);
58 scrollbar_layer
->SetTrackLength(track_length_
);
60 scrollbar_layer
->set_track_ui_resource_id(track_ui_resource_id_
);
61 scrollbar_layer
->set_thumb_ui_resource_id(thumb_ui_resource_id_
);
64 bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode
,
65 ResourceProvider
* resource_provider
) {
66 DCHECK(draw_mode
!= DRAW_MODE_RESOURCELESS_SOFTWARE
);
67 return LayerImpl::WillDraw(draw_mode
, resource_provider
);
70 void PaintedScrollbarLayerImpl::AppendQuads(
71 RenderPass
* render_pass
,
72 const Occlusion
& occlusion_in_content_space
,
73 AppendQuadsData
* append_quads_data
) {
74 bool premultipled_alpha
= true;
76 gfx::PointF
uv_top_left(0.f
, 0.f
);
77 gfx::PointF
uv_bottom_right(1.f
, 1.f
);
78 gfx::Rect
bounds_rect(bounds());
79 gfx::Rect
content_bounds_rect(content_bounds());
81 SharedQuadState
* shared_quad_state
=
82 render_pass
->CreateAndAppendSharedQuadState();
83 PopulateSharedQuadState(shared_quad_state
);
85 AppendDebugBorderQuad(
86 render_pass
, content_bounds(), shared_quad_state
, append_quads_data
);
88 gfx::Rect thumb_quad_rect
= ComputeThumbQuadRect();
89 gfx::Rect visible_thumb_quad_rect
=
90 occlusion_in_content_space
.GetUnoccludedContentRect(thumb_quad_rect
);
92 ResourceProvider::ResourceId thumb_resource_id
=
93 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_
);
94 ResourceProvider::ResourceId track_resource_id
=
95 layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_
);
97 if (thumb_resource_id
&& !visible_thumb_quad_rect
.IsEmpty()) {
98 gfx::Rect opaque_rect
;
99 const float opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
100 TextureDrawQuad
* quad
=
101 render_pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
102 quad
->SetNew(shared_quad_state
,
105 visible_thumb_quad_rect
,
115 gfx::Rect track_quad_rect
= content_bounds_rect
;
116 gfx::Rect visible_track_quad_rect
=
117 occlusion_in_content_space
.GetUnoccludedContentRect(track_quad_rect
);
118 if (track_resource_id
&& !visible_track_quad_rect
.IsEmpty()) {
119 gfx::Rect
opaque_rect(contents_opaque() ? track_quad_rect
: gfx::Rect());
120 const float opacity
[] = {1.0f
, 1.0f
, 1.0f
, 1.0f
};
121 TextureDrawQuad
* quad
=
122 render_pass
->CreateAndAppendDrawQuad
<TextureDrawQuad
>();
123 quad
->SetNew(shared_quad_state
,
126 visible_track_quad_rect
,
137 void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness
) {
138 if (thumb_thickness_
== thumb_thickness
)
140 thumb_thickness_
= thumb_thickness
;
141 NoteLayerPropertyChanged();
144 int PaintedScrollbarLayerImpl::ThumbThickness() const {
145 return thumb_thickness_
;
148 void PaintedScrollbarLayerImpl::SetThumbLength(int thumb_length
) {
149 if (thumb_length_
== thumb_length
)
151 thumb_length_
= thumb_length
;
152 NoteLayerPropertyChanged();
155 int PaintedScrollbarLayerImpl::ThumbLength() const {
156 return thumb_length_
;
159 void PaintedScrollbarLayerImpl::SetTrackStart(int track_start
) {
160 if (track_start_
== track_start
)
162 track_start_
= track_start
;
163 NoteLayerPropertyChanged();
166 int PaintedScrollbarLayerImpl::TrackStart() const {
170 void PaintedScrollbarLayerImpl::SetTrackLength(int track_length
) {
171 if (track_length_
== track_length
)
173 track_length_
= track_length
;
174 NoteLayerPropertyChanged();
177 float PaintedScrollbarLayerImpl::TrackLength() const {
178 return track_length_
+ (orientation() == VERTICAL
? vertical_adjust() : 0);
181 bool PaintedScrollbarLayerImpl::IsThumbResizable() const {
185 const char* PaintedScrollbarLayerImpl::LayerTypeAsString() const {
186 return "cc::PaintedScrollbarLayerImpl";