OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "cc/layers/scrollbar_layer_impl.h" |
6 | 6 |
7 #include "cc/animation/scrollbar_animation_controller.h" | 7 #include "cc/animation/scrollbar_animation_controller.h" |
8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
9 #include "cc/layers/quad_sink.h" | 9 #include "cc/layers/quad_sink.h" |
10 #include "cc/quads/solid_color_draw_quad.h" | 10 #include "cc/quads/solid_color_draw_quad.h" |
11 #include "cc/quads/texture_draw_quad.h" | 11 #include "cc/quads/texture_draw_quad.h" |
12 #include "cc/quads/tile_draw_quad.h" | |
12 #include "cc/trees/layer_tree_impl.h" | 13 #include "cc/trees/layer_tree_impl.h" |
13 #include "cc/trees/layer_tree_settings.h" | 14 #include "cc/trees/layer_tree_settings.h" |
14 #include "ui/gfx/rect_conversions.h" | 15 #include "ui/gfx/rect_conversions.h" |
15 | 16 |
16 namespace cc { | 17 namespace cc { |
17 | 18 |
18 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create( | 19 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create( |
19 LayerTreeImpl* tree_impl, | 20 LayerTreeImpl* tree_impl, |
20 int id, | 21 int id, |
21 ScrollbarOrientation orientation) { | 22 ScrollbarOrientation orientation) { |
22 return make_scoped_ptr(new ScrollbarLayerImpl(tree_impl, | 23 return make_scoped_ptr(new ScrollbarLayerImpl(tree_impl, |
23 id, | 24 id, |
24 orientation)); | 25 orientation)); |
25 } | 26 } |
26 | 27 |
27 ScrollbarLayerImpl::ScrollbarLayerImpl( | 28 ScrollbarLayerImpl::ScrollbarLayerImpl( |
28 LayerTreeImpl* tree_impl, | 29 LayerTreeImpl* tree_impl, |
29 int id, | 30 int id, |
30 ScrollbarOrientation orientation) | 31 ScrollbarOrientation orientation) |
31 : LayerImpl(tree_impl, id), | 32 : LayerImpl(tree_impl, id), |
32 track_resource_id_(0), | |
33 thumb_resource_id_(0), | |
34 current_pos_(0.f), | 33 current_pos_(0.f), |
35 maximum_(0), | 34 maximum_(0), |
36 thumb_thickness_(0), | 35 thumb_thickness_(0), |
37 thumb_length_(0), | 36 thumb_length_(0), |
38 track_start_(0), | 37 track_start_(0), |
39 track_length_(0), | 38 track_length_(0), |
40 orientation_(orientation), | 39 orientation_(orientation), |
41 vertical_adjust_(0.f), | 40 vertical_adjust_(0.f), |
42 visible_to_total_length_ratio_(1.f), | 41 visible_to_total_length_ratio_(1.f), |
43 scroll_layer_id_(Layer::INVALID_ID), | 42 scroll_layer_id_(Layer::INVALID_ID), |
43 track_ui_resource_id_(0), | |
44 thumb_ui_resource_id_(0), | |
44 is_scrollable_area_active_(false), | 45 is_scrollable_area_active_(false), |
45 is_scroll_view_scrollbar_(false), | 46 is_scroll_view_scrollbar_(false), |
46 enabled_(false), | 47 enabled_(false), |
47 is_custom_scrollbar_(false), | 48 is_custom_scrollbar_(false), |
48 is_overlay_scrollbar_(false) {} | 49 is_overlay_scrollbar_(false) {} |
49 | 50 |
50 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} | 51 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} |
51 | 52 |
52 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { | 53 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { |
53 return this; | 54 return this; |
54 } | 55 } |
55 | 56 |
56 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( | 57 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( |
57 LayerTreeImpl* tree_impl) { | 58 LayerTreeImpl* tree_impl) { |
58 return ScrollbarLayerImpl::Create(tree_impl, | 59 return ScrollbarLayerImpl::Create(tree_impl, |
59 id(), | 60 id(), |
60 orientation_).PassAs<LayerImpl>(); | 61 orientation_).PassAs<LayerImpl>(); |
61 } | 62 } |
62 | 63 |
63 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 64 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
64 LayerImpl::PushPropertiesTo(layer); | 65 LayerImpl::PushPropertiesTo(layer); |
65 | 66 |
66 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); | 67 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); |
67 | 68 |
68 scrollbar_layer->set_thumb_thickness(thumb_thickness_); | 69 scrollbar_layer->set_thumb_thickness(thumb_thickness_); |
69 scrollbar_layer->set_thumb_length(thumb_length_); | 70 scrollbar_layer->set_thumb_length(thumb_length_); |
70 scrollbar_layer->set_track_start(track_start_); | 71 scrollbar_layer->set_track_start(track_start_); |
71 scrollbar_layer->set_track_length(track_length_); | 72 scrollbar_layer->set_track_length(track_length_); |
72 | 73 |
73 scrollbar_layer->set_track_resource_id(track_resource_id_); | 74 if (scrollbar_layer->track_ui_resource_id_ != track_ui_resource_id_ || |
enne (OOO)
2013/07/22 23:09:15
No need for this to be conditional.
powei
2013/07/24 02:28:29
Done.
| |
74 scrollbar_layer->set_thumb_resource_id(thumb_resource_id_); | 75 scrollbar_layer->thumb_ui_resource_id_ != thumb_ui_resource_id_) { |
76 scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_); | |
77 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); | |
78 } | |
75 } | 79 } |
76 | 80 |
77 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode, | 81 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode, |
78 ResourceProvider* resource_provider) { | 82 ResourceProvider* resource_provider) { |
79 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE && | 83 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE && |
80 !layer_tree_impl()->settings().solid_color_scrollbars) | 84 !layer_tree_impl()->settings().solid_color_scrollbars) |
81 return false; | 85 return false; |
82 return LayerImpl::WillDraw(draw_mode, resource_provider); | 86 return LayerImpl::WillDraw(draw_mode, resource_provider); |
83 } | 87 } |
84 | 88 |
(...skipping 15 matching lines...) Expand all Loading... | |
100 if (layer_tree_impl()->settings().solid_color_scrollbars) { | 104 if (layer_tree_impl()->settings().solid_color_scrollbars) { |
101 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | 105 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
102 quad->SetNew(shared_quad_state, | 106 quad->SetNew(shared_quad_state, |
103 thumb_quad_rect, | 107 thumb_quad_rect, |
104 layer_tree_impl()->settings().solid_color_scrollbar_color, | 108 layer_tree_impl()->settings().solid_color_scrollbar_color, |
105 false); | 109 false); |
106 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 110 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
107 return; | 111 return; |
108 } | 112 } |
109 | 113 |
110 if (thumb_resource_id_ && !thumb_quad_rect.IsEmpty()) { | 114 gfx::Rect track_quad_rect = content_bounds_rect; |
115 | |
116 ResourceProvider::ResourceId thumb_resource_id = | |
117 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_); | |
118 ResourceProvider::ResourceId track_resource_id = | |
119 layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_); | |
120 | |
121 if (thumb_resource_id && !thumb_quad_rect.IsEmpty()) { | |
111 gfx::Rect opaque_rect; | 122 gfx::Rect opaque_rect; |
112 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 123 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
113 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 124 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
114 quad->SetNew(shared_quad_state, | 125 quad->SetNew(shared_quad_state, |
115 thumb_quad_rect, | 126 thumb_quad_rect, |
116 opaque_rect, | 127 opaque_rect, |
117 thumb_resource_id_, | 128 thumb_resource_id, |
118 premultipled_alpha, | 129 premultipled_alpha, |
119 uv_top_left, | 130 uv_top_left, |
120 uv_bottom_right, | 131 uv_bottom_right, |
121 opacity, | 132 opacity, |
122 flipped); | 133 flipped); |
123 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 134 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
124 } | 135 } |
125 | 136 |
126 if (!track_resource_id_) | 137 if (track_resource_id && !track_quad_rect.IsEmpty()) { |
127 return; | 138 gfx::Rect opaque_rect(contents_opaque() ? track_quad_rect : gfx::Rect()); |
128 | |
129 // Order matters here: since the back track texture is being drawn to the | |
130 // entire contents rect, we must append it after the thumb and fore track | |
131 // quads. The back track texture contains (and displays) the buttons. | |
132 if (!content_bounds_rect.IsEmpty()) { | |
133 gfx::Rect quad_rect(content_bounds_rect); | |
134 gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); | |
135 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 139 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
136 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 140 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
137 quad->SetNew(shared_quad_state, | 141 quad->SetNew(shared_quad_state, |
138 quad_rect, | 142 track_quad_rect, |
139 opaque_rect, | 143 opaque_rect, |
140 track_resource_id_, | 144 track_resource_id, |
141 premultipled_alpha, | 145 premultipled_alpha, |
142 uv_top_left, | 146 uv_top_left, |
143 uv_bottom_right, | 147 uv_bottom_right, |
144 opacity, | 148 opacity, |
145 flipped); | 149 flipped); |
146 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 150 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
147 } | 151 } |
148 } | 152 } |
149 | 153 |
150 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { | 154 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_, | 255 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_, |
252 thumb_length, thumb_thickness_); | 256 thumb_length, thumb_thickness_); |
253 } else { | 257 } else { |
254 thumb_rect = gfx::RectF(0.f, thumb_offset, | 258 thumb_rect = gfx::RectF(0.f, thumb_offset, |
255 thumb_thickness_, thumb_length); | 259 thumb_thickness_, thumb_length); |
256 } | 260 } |
257 | 261 |
258 return ScrollbarLayerRectToContentRect(thumb_rect); | 262 return ScrollbarLayerRectToContentRect(thumb_rect); |
259 } | 263 } |
260 | 264 |
261 void ScrollbarLayerImpl::DidLoseOutputSurface() { | 265 void ScrollbarLayerImpl::DidLoseOutputSurface() {} |
enne (OOO)
2013/07/22 23:09:15
This can be removed entirely.
powei
2013/07/24 02:28:29
Done.
| |
262 track_resource_id_ = 0; | |
263 thumb_resource_id_ = 0; | |
264 } | |
265 | 266 |
266 const char* ScrollbarLayerImpl::LayerTypeAsString() const { | 267 const char* ScrollbarLayerImpl::LayerTypeAsString() const { |
267 return "cc::ScrollbarLayerImpl"; | 268 return "cc::ScrollbarLayerImpl"; |
268 } | 269 } |
269 | 270 |
271 void ScrollbarLayerImpl::set_track_ui_resource_id(UIResourceId uid) { | |
272 track_ui_resource_id_ = uid; | |
273 } | |
274 | |
275 void ScrollbarLayerImpl::set_thumb_ui_resource_id(UIResourceId uid) { | |
276 thumb_ui_resource_id_ = uid; | |
277 } | |
278 | |
270 } // namespace cc | 279 } // namespace cc |
OLD | NEW |