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/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
13 #include "cc/trees/layer_tree_settings.h" | 13 #include "cc/trees/layer_tree_settings.h" |
14 #include "ui/gfx/rect_conversions.h" | 14 #include "ui/gfx/rect_conversions.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create( | 18 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create( |
19 LayerTreeImpl* tree_impl, | 19 LayerTreeImpl* tree_impl, |
20 int id, | 20 int id, |
21 ScrollbarOrientation orientation) { | 21 ScrollbarOrientation orientation, |
22 bool is_solid_color) { | |
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, |
26 is_solid_color)); | |
25 } | 27 } |
26 | 28 |
27 ScrollbarLayerImpl::ScrollbarLayerImpl( | 29 ScrollbarLayerImpl::ScrollbarLayerImpl( |
28 LayerTreeImpl* tree_impl, | 30 LayerTreeImpl* tree_impl, |
29 int id, | 31 int id, |
30 ScrollbarOrientation orientation) | 32 ScrollbarOrientation orientation, |
33 bool is_solid_color) | |
31 : LayerImpl(tree_impl, id), | 34 : LayerImpl(tree_impl, id), |
32 track_resource_id_(0), | 35 track_resource_id_(0), |
33 thumb_resource_id_(0), | 36 thumb_resource_id_(0), |
34 current_pos_(0.f), | 37 current_pos_(0.f), |
35 maximum_(0), | 38 maximum_(0), |
36 thumb_thickness_(0), | 39 thumb_thickness_(0), |
37 thumb_length_(0), | 40 thumb_length_(0), |
38 track_start_(0), | 41 track_start_(0), |
39 track_length_(0), | 42 track_length_(0), |
40 orientation_(orientation), | 43 orientation_(orientation), |
41 vertical_adjust_(0.f), | 44 vertical_adjust_(0.f), |
42 visible_to_total_length_ratio_(1.f), | 45 visible_to_total_length_ratio_(1.f), |
43 scroll_layer_id_(Layer::INVALID_ID), | 46 scroll_layer_id_(Layer::INVALID_ID), |
44 is_scrollable_area_active_(false), | 47 is_scrollable_area_active_(false), |
45 is_scroll_view_scrollbar_(false), | 48 is_scroll_view_scrollbar_(false), |
46 enabled_(false), | 49 enabled_(false), |
47 is_custom_scrollbar_(false), | 50 is_custom_scrollbar_(false), |
48 is_overlay_scrollbar_(false) {} | 51 is_overlay_scrollbar_(false), |
52 is_solid_color_(is_solid_color) { | |
53 } | |
49 | 54 |
50 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} | 55 ScrollbarLayerImpl::~ScrollbarLayerImpl() {} |
51 | 56 |
52 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { | 57 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() { |
53 return this; | 58 return this; |
54 } | 59 } |
55 | 60 |
56 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( | 61 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl( |
57 LayerTreeImpl* tree_impl) { | 62 LayerTreeImpl* tree_impl) { |
58 return ScrollbarLayerImpl::Create(tree_impl, | 63 return ScrollbarLayerImpl::Create( |
59 id(), | 64 tree_impl, id(), orientation_, is_solid_color_).PassAs<LayerImpl>(); |
60 orientation_).PassAs<LayerImpl>(); | |
61 } | 65 } |
62 | 66 |
63 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 67 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
64 LayerImpl::PushPropertiesTo(layer); | 68 LayerImpl::PushPropertiesTo(layer); |
65 | 69 |
66 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); | 70 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer); |
67 | 71 |
72 scrollbar_layer->set_is_solid_color(is_solid_color_); | |
73 | |
68 scrollbar_layer->set_thumb_thickness(thumb_thickness_); | 74 scrollbar_layer->set_thumb_thickness(thumb_thickness_); |
69 scrollbar_layer->set_thumb_length(thumb_length_); | 75 scrollbar_layer->set_thumb_length(thumb_length_); |
70 scrollbar_layer->set_track_start(track_start_); | 76 scrollbar_layer->set_track_start(track_start_); |
71 scrollbar_layer->set_track_length(track_length_); | 77 scrollbar_layer->set_track_length(track_length_); |
72 | 78 |
73 scrollbar_layer->set_track_resource_id(track_resource_id_); | 79 scrollbar_layer->set_track_resource_id(track_resource_id_); |
74 scrollbar_layer->set_thumb_resource_id(thumb_resource_id_); | 80 scrollbar_layer->set_thumb_resource_id(thumb_resource_id_); |
75 } | 81 } |
76 | 82 |
77 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode, | 83 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode, |
78 ResourceProvider* resource_provider) { | 84 ResourceProvider* resource_provider) { |
79 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE && | 85 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE && |
80 !layer_tree_impl()->settings().solid_color_scrollbars) | 86 !is_solid_color()) |
jamesr
2013/07/03 21:26:24
no need to use a getter here, just access the bool
| |
81 return false; | 87 return false; |
82 return LayerImpl::WillDraw(draw_mode, resource_provider); | 88 return LayerImpl::WillDraw(draw_mode, resource_provider); |
83 } | 89 } |
84 | 90 |
85 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink, | 91 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink, |
86 AppendQuadsData* append_quads_data) { | 92 AppendQuadsData* append_quads_data) { |
87 bool premultipled_alpha = true; | 93 bool premultipled_alpha = true; |
88 bool flipped = false; | 94 bool flipped = false; |
89 gfx::PointF uv_top_left(0.f, 0.f); | 95 gfx::PointF uv_top_left(0.f, 0.f); |
90 gfx::PointF uv_bottom_right(1.f, 1.f); | 96 gfx::PointF uv_bottom_right(1.f, 1.f); |
91 gfx::Rect bounds_rect(bounds()); | 97 gfx::Rect bounds_rect(bounds()); |
92 gfx::Rect content_bounds_rect(content_bounds()); | 98 gfx::Rect content_bounds_rect(content_bounds()); |
93 | 99 |
94 SharedQuadState* shared_quad_state = | 100 SharedQuadState* shared_quad_state = |
95 quad_sink->UseSharedQuadState(CreateSharedQuadState()); | 101 quad_sink->UseSharedQuadState(CreateSharedQuadState()); |
96 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); | 102 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); |
97 | 103 |
98 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); | 104 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); |
99 | 105 |
100 if (layer_tree_impl()->settings().solid_color_scrollbars) { | 106 if (is_solid_color()) { |
jamesr
2013/07/03 21:26:24
ditto
| |
101 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); | 107 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); |
102 quad->SetNew(shared_quad_state, | 108 quad->SetNew(shared_quad_state, |
103 thumb_quad_rect, | 109 thumb_quad_rect, |
104 layer_tree_impl()->settings().solid_color_scrollbar_color, | 110 layer_tree_impl()->settings().solid_color_scrollbar_color, |
105 false); | 111 false); |
106 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 112 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
107 return; | 113 return; |
108 } | 114 } |
109 | 115 |
110 if (thumb_resource_id_ && !thumb_quad_rect.IsEmpty()) { | 116 if (thumb_resource_id_ && !thumb_quad_rect.IsEmpty()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 opacity, | 150 opacity, |
145 flipped); | 151 flipped); |
146 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); | 152 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); |
147 } | 153 } |
148 } | 154 } |
149 | 155 |
150 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { | 156 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { |
151 return orientation_; | 157 return orientation_; |
152 } | 158 } |
153 | 159 |
160 bool ScrollbarLayerImpl::is_solid_color() const { | |
161 return is_solid_color_; | |
162 } | |
163 | |
164 void ScrollbarLayerImpl::set_is_solid_color(bool is_solid_color) { | |
165 is_solid_color_ = is_solid_color; | |
166 } | |
167 | |
154 float ScrollbarLayerImpl::CurrentPos() const { | 168 float ScrollbarLayerImpl::CurrentPos() const { |
155 return current_pos_; | 169 return current_pos_; |
156 } | 170 } |
157 | 171 |
158 int ScrollbarLayerImpl::Maximum() const { | 172 int ScrollbarLayerImpl::Maximum() const { |
159 return maximum_; | 173 return maximum_; |
160 } | 174 } |
161 | 175 |
162 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect( | 176 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect( |
163 gfx::RectF layer_rect) const { | 177 gfx::RectF layer_rect) const { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 // actually see down to 1000px. Thus we have to move the quad for the | 242 // actually see down to 1000px. Thus we have to move the quad for the |
229 // horizontal scrollbar down by the vertical_adjust_ factor and lay the | 243 // horizontal scrollbar down by the vertical_adjust_ factor and lay the |
230 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This | 244 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This |
231 // means the quads may extend outside the layer's bounds. | 245 // means the quads may extend outside the layer's bounds. |
232 | 246 |
233 int thumb_length = thumb_length_; | 247 int thumb_length = thumb_length_; |
234 float track_length = track_length_; | 248 float track_length = track_length_; |
235 if (orientation_ == VERTICAL) | 249 if (orientation_ == VERTICAL) |
236 track_length += vertical_adjust_; | 250 track_length += vertical_adjust_; |
237 | 251 |
238 if (layer_tree_impl()->settings().solid_color_scrollbars) { | 252 if (is_solid_color()) { |
jamesr
2013/07/03 21:26:24
ditto
| |
239 thumb_length = std::max( | 253 thumb_length = std::max( |
240 static_cast<int>(visible_to_total_length_ratio_ * track_length), | 254 static_cast<int>(visible_to_total_length_ratio_ * track_length), |
241 thumb_thickness_); | 255 thumb_thickness_); |
242 } | 256 } |
243 | 257 |
244 // With the length known, we can compute the thumb's position. | 258 // With the length known, we can compute the thumb's position. |
245 float ratio = current_pos_ / maximum_; | 259 float ratio = current_pos_ / maximum_; |
246 float max_offset = track_length - thumb_length; | 260 float max_offset = track_length - thumb_length; |
247 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_; | 261 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_; |
248 | 262 |
(...skipping 12 matching lines...) Expand all Loading... | |
261 void ScrollbarLayerImpl::DidLoseOutputSurface() { | 275 void ScrollbarLayerImpl::DidLoseOutputSurface() { |
262 track_resource_id_ = 0; | 276 track_resource_id_ = 0; |
263 thumb_resource_id_ = 0; | 277 thumb_resource_id_ = 0; |
264 } | 278 } |
265 | 279 |
266 const char* ScrollbarLayerImpl::LayerTypeAsString() const { | 280 const char* ScrollbarLayerImpl::LayerTypeAsString() const { |
267 return "cc::ScrollbarLayerImpl"; | 281 return "cc::ScrollbarLayerImpl"; |
268 } | 282 } |
269 | 283 |
270 } // namespace cc | 284 } // namespace cc |
OLD | NEW |