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

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

Issue 18191020: UI Resource Manager (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 5 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/layers/picture_scrollbar_layer_impl.h"
6
7 #if !USE_REGULAR_SCROLLBAR
8
9 #include "cc/animation/scrollbar_animation_controller.h"
10 #include "cc/layers/layer.h"
11 #include "cc/layers/quad_sink.h"
12 #include "cc/quads/solid_color_draw_quad.h"
13 #include "cc/quads/texture_draw_quad.h"
14 #include "cc/quads/tile_draw_quad.h"
15 #include "cc/trees/layer_tree_impl.h"
16 #include "cc/trees/layer_tree_settings.h"
17 #include "ui/gfx/rect_conversions.h"
18
19 namespace cc {
20
21 scoped_ptr<ScrollbarLayerImpl> ScrollbarLayerImpl::Create(
22 LayerTreeImpl* tree_impl,
23 int id,
24 ScrollbarOrientation orientation) {
25 return make_scoped_ptr(new ScrollbarLayerImpl(tree_impl,
26 id,
27 orientation));
28 }
29
30 ScrollbarLayerImpl::ScrollbarLayerImpl(
31 LayerTreeImpl* tree_impl,
32 int id,
33 ScrollbarOrientation orientation)
34 : LayerImpl(tree_impl, id),
35 current_pos_(0.f),
36 maximum_(0),
37 thumb_thickness_(0),
38 thumb_length_(0),
39 track_start_(0),
40 track_length_(0),
41 orientation_(orientation),
42 vertical_adjust_(0.f),
43 visible_to_total_length_ratio_(1.f),
44 scroll_layer_id_(Layer::INVALID_ID),
45 track_ui_resource_id_(0),
46 thumb_ui_resource_id_(0),
47 is_scrollable_area_active_(false),
48 is_scroll_view_scrollbar_(false),
49 enabled_(false),
50 is_custom_scrollbar_(false),
51 is_overlay_scrollbar_(false) {}
52
53 ScrollbarLayerImpl::~ScrollbarLayerImpl() {}
54
55 ScrollbarLayerImpl* ScrollbarLayerImpl::ToScrollbarLayer() {
56 return this;
57 }
58
59 scoped_ptr<LayerImpl> ScrollbarLayerImpl::CreateLayerImpl(
60 LayerTreeImpl* tree_impl) {
61 return ScrollbarLayerImpl::Create(tree_impl,
62 id(),
63 orientation_).PassAs<LayerImpl>();
64 }
65
66 void ScrollbarLayerImpl::PushPropertiesTo(LayerImpl* layer) {
67 LayerImpl::PushPropertiesTo(layer);
68
69 ScrollbarLayerImpl* scrollbar_layer = static_cast<ScrollbarLayerImpl*>(layer);
70
71 scrollbar_layer->set_thumb_thickness(thumb_thickness_);
72 scrollbar_layer->set_thumb_length(thumb_length_);
73 scrollbar_layer->set_track_start(track_start_);
74 scrollbar_layer->set_track_length(track_length_);
75
76 if (scrollbar_layer->track_ui_resource_id_ != track_ui_resource_id_ ||
77 scrollbar_layer->thumb_ui_resource_id_ != thumb_ui_resource_id_) {
78 scrollbar_layer->set_track_ui_resource_id(track_ui_resource_id_);
79 scrollbar_layer->set_thumb_ui_resource_id(thumb_ui_resource_id_);
80
81 NoteLayerPropertyChanged();
82 scrollbar_layer->NoteLayerPropertyChanged();
83 }
84 }
85
86 bool ScrollbarLayerImpl::WillDraw(DrawMode draw_mode,
87 ResourceProvider* resource_provider) {
88 LayerImpl::WillDraw(draw_mode, resource_provider);
89 return draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE ||
90 layer_tree_impl()->settings().solid_color_scrollbars;
91 }
92
93 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink,
94 AppendQuadsData* append_quads_data) {
95 gfx::Rect bounds_rect(bounds());
96 gfx::Rect content_bounds_rect(content_bounds());
97
98 SharedQuadState* shared_quad_state =
99 quad_sink->UseSharedQuadState(CreateSharedQuadState());
100 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
101
102 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect();
103
104 if (layer_tree_impl()->settings().solid_color_scrollbars) {
105 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
106 quad->SetNew(shared_quad_state,
107 thumb_quad_rect,
108 layer_tree_impl()->settings().solid_color_scrollbar_color,
109 false);
110 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
111 return;
112 }
113
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) {
122 scoped_ptr<TileDrawQuad> thumb_quad = TileDrawQuad::Create();
123 thumb_quad->SetNew(shared_quad_state,
124 thumb_quad_rect,
125 thumb_quad_rect,
126 thumb_resource_id,
127 gfx::RectF(0, 0, 1, 1),
128 gfx::Size(1, 1),
129 false);
130 quad_sink->Append(thumb_quad.PassAs<DrawQuad>(), append_quads_data);
131 }
132
133 if (!track_quad_rect.IsEmpty() && track_resource_id) {
134 scoped_ptr<TileDrawQuad> track_quad = TileDrawQuad::Create();
135 track_quad->SetNew(shared_quad_state,
136 track_quad_rect,
137 track_quad_rect,
138 track_resource_id,
139 gfx::RectF(0, 0, 1, 1),
140 gfx::Size(1, 1),
141 false);
142 quad_sink->Append(track_quad.PassAs<DrawQuad>(), append_quads_data);
143 }
144 }
145
146 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const {
147 return orientation_;
148 }
149
150 float ScrollbarLayerImpl::CurrentPos() const {
151 return current_pos_;
152 }
153
154 int ScrollbarLayerImpl::Maximum() const {
155 return maximum_;
156 }
157
158 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect(
159 gfx::RectF layer_rect) const {
160 // Don't intersect with the bounds as in layerRectToContentRect() because
161 // layer_rect here might be in coordinates of the containing layer.
162 gfx::RectF content_rect = gfx::ScaleRect(layer_rect,
163 contents_scale_x(),
164 contents_scale_y());
165 return gfx::ToEnclosingRect(content_rect);
166 }
167
168 gfx::Rect ScrollbarLayerImpl::ComputeThumbQuadRect() const {
169 // Thumb extent is the length of the thumb in the scrolling direction, thumb
170 // thickness is in the perpendicular direction. Here's an example of a
171 // horizontal scrollbar - inputs are above the scrollbar, computed values
172 // below:
173 //
174 // |<------------------- track_length_ ------------------->|
175 //
176 // |--| <-- start_offset
177 //
178 // +--+----------------------------+------------------+-------+--+
179 // |<|| |##################| ||>|
180 // +--+----------------------------+------------------+-------+--+
181 //
182 // |<- thumb_length ->|
183 //
184 // |<------- thumb_offset -------->|
185 //
186 // For painted, scrollbars, the length is fixed. For solid color scrollbars we
187 // have to compute it. The ratio of the thumb's length to the track's length
188 // is the same as that of the visible viewport to the total viewport, unless
189 // that would make the thumb's length less than its thickness.
190 //
191 // vertical_adjust_ is used when the layer geometry from the main thread is
192 // not in sync with what the user sees. For instance on Android scrolling the
193 // top bar controls out of view reveals more of the page content. We want the
194 // root layer scrollbars to reflect what the user sees even if we haven't
195 // received new layer geometry from the main thread. If the user has scrolled
196 // down by 50px and the initial viewport size was 950px the geometry would
197 // look something like this:
198 //
199 // vertical_adjust_ = 50, scroll position 0, visible ratios 99%
200 // Layer geometry: Desired thumb positions:
201 // +--------------------+-+ +----------------------+ <-- 0px
202 // | |v| | #|
203 // | |e| | #|
204 // | |r| | #|
205 // | |t| | #|
206 // | |i| | #|
207 // | |c| | #|
208 // | |a| | #|
209 // | |l| | #|
210 // | | | | #|
211 // | |l| | #|
212 // | |a| | #|
213 // | |y| | #|
214 // | |e| | #|
215 // | |r| | #|
216 // +--------------------+-+ | #|
217 // | horizontal layer | | | #|
218 // +--------------------+-+ | #| <-- 950px
219 // | | | #|
220 // | | |##################### |
221 // +----------------------+ +----------------------+ <-- 1000px
222 //
223 // The layer geometry is set up for a 950px tall viewport, but the user can
224 // actually see down to 1000px. Thus we have to move the quad for the
225 // horizontal scrollbar down by the vertical_adjust_ factor and lay the
226 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This
227 // means the quads may extend outside the layer's bounds.
228
229 int thumb_length = thumb_length_;
230 float track_length = track_length_;
231 if (orientation_ == VERTICAL)
232 track_length += vertical_adjust_;
233
234 if (layer_tree_impl()->settings().solid_color_scrollbars) {
235 thumb_length = std::max(
236 static_cast<int>(visible_to_total_length_ratio_ * track_length),
237 thumb_thickness_);
238 }
239
240 // With the length known, we can compute the thumb's position.
241 float ratio = current_pos_ / maximum_;
242 float max_offset = track_length - thumb_length;
243 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_;
244
245 gfx::RectF thumb_rect;
246 if (orientation_ == HORIZONTAL) {
247 thumb_rect = gfx::RectF(thumb_offset, vertical_adjust_,
248 thumb_length, thumb_thickness_);
249 } else {
250 thumb_rect = gfx::RectF(0.f, thumb_offset,
251 thumb_thickness_, thumb_length);
252 }
253
254 return ScrollbarLayerRectToContentRect(thumb_rect);
255 }
256
257 void ScrollbarLayerImpl::DidLoseOutputSurface() {
258 }
259
260 const char* ScrollbarLayerImpl::LayerTypeAsString() const {
261 return "cc::ScrollbarLayerImpl";
262 }
263
264 void ScrollbarLayerImpl::set_track_ui_resource_id(UIResourceId uid) {
265 track_ui_resource_id_ = uid;
266 }
267
268 void ScrollbarLayerImpl::set_thumb_ui_resource_id(UIResourceId uid) {
269 thumb_ui_resource_id_ = uid;
270 }
271
272 } // namespace cc
273
274 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698