Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: cc/layers/painted_scrollbar_layer_impl.cc

Issue 18341009: Refactor cc scrollbar layers to separate solid-color vs desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows compile. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl.h ('k') | cc/layers/scrollbar_layer_impl_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/painted_scrollbar_layer_impl.h" 5 #include "cc/layers/painted_scrollbar_layer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "cc/animation/scrollbar_animation_controller.h" 9 #include "cc/animation/scrollbar_animation_controller.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
(...skipping 11 matching lines...) Expand all
22 int id, 22 int id,
23 ScrollbarOrientation orientation) { 23 ScrollbarOrientation orientation) {
24 return make_scoped_ptr( 24 return make_scoped_ptr(
25 new PaintedScrollbarLayerImpl(tree_impl, id, orientation)); 25 new PaintedScrollbarLayerImpl(tree_impl, id, orientation));
26 } 26 }
27 27
28 PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl( 28 PaintedScrollbarLayerImpl::PaintedScrollbarLayerImpl(
29 LayerTreeImpl* tree_impl, 29 LayerTreeImpl* tree_impl,
30 int id, 30 int id,
31 ScrollbarOrientation orientation) 31 ScrollbarOrientation orientation)
32 : LayerImpl(tree_impl, id), 32 : ScrollbarLayerImplBase(tree_impl, id, orientation),
33 track_ui_resource_id_(0), 33 track_ui_resource_id_(0),
34 thumb_ui_resource_id_(0), 34 thumb_ui_resource_id_(0),
35 current_pos_(0.f),
36 maximum_(0),
37 thumb_thickness_(0), 35 thumb_thickness_(0),
38 thumb_length_(0), 36 thumb_length_(0),
39 track_start_(0), 37 track_start_(0),
40 track_length_(0), 38 track_length_(0),
41 orientation_(orientation),
42 vertical_adjust_(0.f), 39 vertical_adjust_(0.f),
43 visible_to_total_length_ratio_(1.f), 40 scroll_layer_id_(Layer::INVALID_ID) {}
44 scroll_layer_id_(Layer::INVALID_ID),
45 is_overlay_scrollbar_(false) {}
46 41
47 PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {} 42 PaintedScrollbarLayerImpl::~PaintedScrollbarLayerImpl() {}
48 43
49 PaintedScrollbarLayerImpl* PaintedScrollbarLayerImpl::ToScrollbarLayer() {
50 return this;
51 }
52
53 scoped_ptr<LayerImpl> PaintedScrollbarLayerImpl::CreateLayerImpl( 44 scoped_ptr<LayerImpl> PaintedScrollbarLayerImpl::CreateLayerImpl(
54 LayerTreeImpl* tree_impl) { 45 LayerTreeImpl* tree_impl) {
55 return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation_) 46 return PaintedScrollbarLayerImpl::Create(tree_impl, id(), orientation())
56 .PassAs<LayerImpl>(); 47 .PassAs<LayerImpl>();
57 } 48 }
58 49
59 void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) { 50 void PaintedScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
60 LayerImpl::PushPropertiesTo(layer); 51 ScrollbarLayerImplBase::PushPropertiesTo(layer);
61 52
62 PaintedScrollbarLayerImpl* scrollbar_layer = 53 PaintedScrollbarLayerImpl* scrollbar_layer =
63 static_cast<PaintedScrollbarLayerImpl*>(layer); 54 static_cast<PaintedScrollbarLayerImpl*>(layer);
64 55
65 scrollbar_layer->SetThumbThickness(thumb_thickness_); 56 scrollbar_layer->SetThumbThickness(thumb_thickness_);
66 scrollbar_layer->SetThumbLength(thumb_length_); 57 scrollbar_layer->SetThumbLength(thumb_length_);
67 scrollbar_layer->SetTrackStart(track_start_); 58 scrollbar_layer->SetTrackStart(track_start_);
68 scrollbar_layer->SetTrackLength(track_length_); 59 scrollbar_layer->SetTrackLength(track_length_);
69 scrollbar_layer->set_is_overlay_scrollbar(is_overlay_scrollbar_);
70 60
71 scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_); 61 scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_);
72 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_); 62 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_);
73 } 63 }
74 64
75 bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode, 65 bool PaintedScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
76 ResourceProvider* resource_provider) { 66 ResourceProvider* resource_provider) {
77 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE && 67 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE);
78 !layer_tree_impl()->settings().solid_color_scrollbars)
79 return false;
80 return LayerImpl::WillDraw(draw_mode, resource_provider); 68 return LayerImpl::WillDraw(draw_mode, resource_provider);
81 } 69 }
82 70
83 void PaintedScrollbarLayerImpl::AppendQuads( 71 void PaintedScrollbarLayerImpl::AppendQuads(
84 QuadSink* quad_sink, 72 QuadSink* quad_sink,
85 AppendQuadsData* append_quads_data) { 73 AppendQuadsData* append_quads_data) {
86 bool premultipled_alpha = true; 74 bool premultipled_alpha = true;
87 bool flipped = false; 75 bool flipped = false;
88 gfx::PointF uv_top_left(0.f, 0.f); 76 gfx::PointF uv_top_left(0.f, 0.f);
89 gfx::PointF uv_bottom_right(1.f, 1.f); 77 gfx::PointF uv_bottom_right(1.f, 1.f);
90 gfx::Rect bounds_rect(bounds()); 78 gfx::Rect bounds_rect(bounds());
91 gfx::Rect content_bounds_rect(content_bounds()); 79 gfx::Rect content_bounds_rect(content_bounds());
92 80
93 SharedQuadState* shared_quad_state = 81 SharedQuadState* shared_quad_state =
94 quad_sink->UseSharedQuadState(CreateSharedQuadState()); 82 quad_sink->UseSharedQuadState(CreateSharedQuadState());
95 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); 83 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
96 84
97 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); 85 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect();
98 86
99 if (layer_tree_impl()->settings().solid_color_scrollbars) {
100 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
101 quad->SetNew(shared_quad_state,
102 thumb_quad_rect,
103 layer_tree_impl()->settings().solid_color_scrollbar_color,
104 false);
105 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
106 return;
107 }
108
109 ResourceProvider::ResourceId thumb_resource_id = 87 ResourceProvider::ResourceId thumb_resource_id =
110 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_); 88 layer_tree_impl()->ResourceIdForUIResource(thumb_ui_resource_id_);
111 ResourceProvider::ResourceId track_resource_id = 89 ResourceProvider::ResourceId track_resource_id =
112 layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_); 90 layer_tree_impl()->ResourceIdForUIResource(track_ui_resource_id_);
113 91
114 if (thumb_resource_id && !thumb_quad_rect.IsEmpty()) { 92 if (thumb_resource_id && !thumb_quad_rect.IsEmpty()) {
115 gfx::Rect opaque_rect; 93 gfx::Rect opaque_rect;
116 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; 94 const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
117 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); 95 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
118 quad->SetNew(shared_quad_state, 96 quad->SetNew(shared_quad_state,
(...skipping 21 matching lines...) Expand all
140 premultipled_alpha, 118 premultipled_alpha,
141 uv_top_left, 119 uv_top_left,
142 uv_bottom_right, 120 uv_bottom_right,
143 SK_ColorTRANSPARENT, 121 SK_ColorTRANSPARENT,
144 opacity, 122 opacity,
145 flipped); 123 flipped);
146 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); 124 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
147 } 125 }
148 } 126 }
149 127
150 ScrollbarOrientation PaintedScrollbarLayerImpl::Orientation() const { 128 void PaintedScrollbarLayerImpl::DidLoseOutputSurface() {
151 return orientation_; 129 track_ui_resource_id_ = 0;
152 } 130 thumb_ui_resource_id_ = 0;
153
154 float PaintedScrollbarLayerImpl::CurrentPos() const {
155 return current_pos_;
156 }
157
158 int PaintedScrollbarLayerImpl::Maximum() const {
159 return maximum_;
160 }
161
162 gfx::Rect PaintedScrollbarLayerImpl::ScrollbarLayerRectToContentRect(
163 gfx::RectF layer_rect) const {
164 // Don't intersect with the bounds as in layerRectToContentRect() because
165 // layer_rect here might be in coordinates of the containing layer.
166 gfx::RectF content_rect = gfx::ScaleRect(layer_rect,
167 contents_scale_x(),
168 contents_scale_y());
169 return gfx::ToEnclosingRect(content_rect);
170 } 131 }
171 132
172 void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) { 133 void PaintedScrollbarLayerImpl::SetThumbThickness(int thumb_thickness) {
173 if (thumb_thickness_ == thumb_thickness) 134 if (thumb_thickness_ == thumb_thickness)
174 return; 135 return;
175 thumb_thickness_ = thumb_thickness; 136 thumb_thickness_ = thumb_thickness;
176 NoteLayerPropertyChanged(); 137 NoteLayerPropertyChanged();
177 } 138 }
178 139
140 int PaintedScrollbarLayerImpl::ThumbThickness() const {
141 return thumb_thickness_;
142 }
143
179 void PaintedScrollbarLayerImpl::SetThumbLength(int thumb_length) { 144 void PaintedScrollbarLayerImpl::SetThumbLength(int thumb_length) {
180 if (thumb_length_ == thumb_length) 145 if (thumb_length_ == thumb_length)
181 return; 146 return;
182 thumb_length_ = thumb_length; 147 thumb_length_ = thumb_length;
183 NoteLayerPropertyChanged(); 148 NoteLayerPropertyChanged();
184 } 149 }
150
151 int PaintedScrollbarLayerImpl::ThumbLength() const {
152 return thumb_length_;
153 }
154
185 void PaintedScrollbarLayerImpl::SetTrackStart(int track_start) { 155 void PaintedScrollbarLayerImpl::SetTrackStart(int track_start) {
186 if (track_start_ == track_start) 156 if (track_start_ == track_start)
187 return; 157 return;
188 track_start_ = track_start; 158 track_start_ = track_start;
189 NoteLayerPropertyChanged(); 159 NoteLayerPropertyChanged();
190 } 160 }
191 161
162 int PaintedScrollbarLayerImpl::TrackStart() const {
163 return track_start_;
164 }
165
192 void PaintedScrollbarLayerImpl::SetTrackLength(int track_length) { 166 void PaintedScrollbarLayerImpl::SetTrackLength(int track_length) {
193 if (track_length_ == track_length) 167 if (track_length_ == track_length)
194 return; 168 return;
195 track_length_ = track_length; 169 track_length_ = track_length;
196 NoteLayerPropertyChanged(); 170 NoteLayerPropertyChanged();
197 } 171 }
198 172
199 void PaintedScrollbarLayerImpl::SetVerticalAdjust(float vertical_adjust) { 173 float PaintedScrollbarLayerImpl::TrackLength() const {
200 if (vertical_adjust_ == vertical_adjust) 174 return track_length_ + (orientation() == VERTICAL ? vertical_adjust() : 0);
201 return;
202 vertical_adjust_ = vertical_adjust;
203 NoteLayerPropertyChanged();
204 }
205
206 void PaintedScrollbarLayerImpl::SetVisibleToTotalLengthRatio(float ratio) {
207 if (visible_to_total_length_ratio_ == ratio)
208 return;
209 visible_to_total_length_ratio_ = ratio;
210 NoteLayerPropertyChanged();
211 }
212
213 void PaintedScrollbarLayerImpl::SetCurrentPos(float current_pos) {
214 if (current_pos_ == current_pos)
215 return;
216 current_pos_ = current_pos;
217 NoteLayerPropertyChanged();
218 }
219
220 void PaintedScrollbarLayerImpl::SetMaximum(int maximum) {
221 if (maximum_ == maximum)
222 return;
223 maximum_ = maximum;
224 NoteLayerPropertyChanged();
225 }
226
227 gfx::Rect PaintedScrollbarLayerImpl::ComputeThumbQuadRect() const {
228 // Thumb extent is the length of the thumb in the scrolling direction, thumb
229 // thickness is in the perpendicular direction. Here's an example of a
230 // horizontal scrollbar - inputs are above the scrollbar, computed values
231 // below:
232 //
233 // |<------------------- track_length_ ------------------->|
234 //
235 // |--| <-- start_offset
236 //
237 // +--+----------------------------+------------------+-------+--+
238 // |<|| |##################| ||>|
239 // +--+----------------------------+------------------+-------+--+
240 //
241 // |<- thumb_length ->|
242 //
243 // |<------- thumb_offset -------->|
244 //
245 // For painted, scrollbars, the length is fixed. For solid color scrollbars we
246 // have to compute it. The ratio of the thumb's length to the track's length
247 // is the same as that of the visible viewport to the total viewport, unless
248 // that would make the thumb's length less than its thickness.
249 //
250 // vertical_adjust_ is used when the layer geometry from the main thread is
251 // not in sync with what the user sees. For instance on Android scrolling the
252 // top bar controls out of view reveals more of the page content. We want the
253 // root layer scrollbars to reflect what the user sees even if we haven't
254 // received new layer geometry from the main thread. If the user has scrolled
255 // down by 50px and the initial viewport size was 950px the geometry would
256 // look something like this:
257 //
258 // vertical_adjust_ = 50, scroll position 0, visible ratios 99%
259 // Layer geometry: Desired thumb positions:
260 // +--------------------+-+ +----------------------+ <-- 0px
261 // | |v| | #|
262 // | |e| | #|
263 // | |r| | #|
264 // | |t| | #|
265 // | |i| | #|
266 // | |c| | #|
267 // | |a| | #|
268 // | |l| | #|
269 // | | | | #|
270 // | |l| | #|
271 // | |a| | #|
272 // | |y| | #|
273 // | |e| | #|
274 // | |r| | #|
275 // +--------------------+-+ | #|
276 // | horizontal layer | | | #|
277 // +--------------------+-+ | #| <-- 950px
278 // | | | #|
279 // | | |##################### |
280 // +----------------------+ +----------------------+ <-- 1000px
281 //
282 // The layer geometry is set up for a 950px tall viewport, but the user can
283 // actually see down to 1000px. Thus we have to move the quad for the
284 // horizontal scrollbar down by the vertical_adjust_ factor and lay the
285 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This
286 // means the quads may extend outside the layer's bounds.
287
288 int thumb_length = thumb_length_;
289 float track_length = track_length_;
290 if (orientation_ == VERTICAL)
291 track_length += vertical_adjust_;
292
293 if (layer_tree_impl()->settings().solid_color_scrollbars) {
294 thumb_length = std::max(
295 static_cast<int>(visible_to_total_length_ratio_ * track_length),
296 thumb_thickness_);
297 }
298
299 // With the length known, we can compute the thumb's position.
300 float clamped_current_pos =
301 std::min(std::max(current_pos_, 0.f), static_cast<float>(maximum_));
302 float ratio = clamped_current_pos / maximum_;
303 float max_offset = track_length - thumb_length;
304 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_;
305
306 gfx::RectF thumb_rect;
307 if (orientation_ == HORIZONTAL) {
308 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_,
309 thumb_length, thumb_thickness_);
310 } else {
311 thumb_rect = gfx::RectF(0.f, thumb_offset,
312 thumb_thickness_, thumb_length);
313 }
314
315 return ScrollbarLayerRectToContentRect(thumb_rect);
316 } 175 }
317 176
318 const char* PaintedScrollbarLayerImpl::LayerTypeAsString() const { 177 const char* PaintedScrollbarLayerImpl::LayerTypeAsString() const {
319 return "cc::PaintedScrollbarLayerImpl"; 178 return "cc::PaintedScrollbarLayerImpl";
320 } 179 }
321 180
322 } // namespace cc 181 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/painted_scrollbar_layer_impl.h ('k') | cc/layers/scrollbar_layer_impl_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698