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

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

Issue 17550008: Make IsSolidColor() a property on CC scrollbar layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use DCHECK(layer_tree_host()) instead. 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 | Annotate | Revision Log
OLDNEW
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 LayerImpl::WillDraw(draw_mode, resource_provider); 85 LayerImpl::WillDraw(draw_mode, resource_provider);
80 return draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE || 86 return draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE ||
81 layer_tree_impl()->settings().solid_color_scrollbars; 87 is_solid_color();
82 } 88 }
83 89
84 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink, 90 void ScrollbarLayerImpl::AppendQuads(QuadSink* quad_sink,
85 AppendQuadsData* append_quads_data) { 91 AppendQuadsData* append_quads_data) {
86 bool premultipled_alpha = true; 92 bool premultipled_alpha = true;
87 bool flipped = false; 93 bool flipped = false;
88 gfx::PointF uv_top_left(0.f, 0.f); 94 gfx::PointF uv_top_left(0.f, 0.f);
89 gfx::PointF uv_bottom_right(1.f, 1.f); 95 gfx::PointF uv_bottom_right(1.f, 1.f);
90 gfx::Rect bounds_rect(bounds()); 96 gfx::Rect bounds_rect(bounds());
91 gfx::Rect content_bounds_rect(content_bounds()); 97 gfx::Rect content_bounds_rect(content_bounds());
92 98
93 SharedQuadState* shared_quad_state = 99 SharedQuadState* shared_quad_state =
94 quad_sink->UseSharedQuadState(CreateSharedQuadState()); 100 quad_sink->UseSharedQuadState(CreateSharedQuadState());
95 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); 101 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
96 102
97 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect(); 103 gfx::Rect thumb_quad_rect = ComputeThumbQuadRect();
98 104
99 if (layer_tree_impl()->settings().solid_color_scrollbars) { 105 if (is_solid_color()) {
100 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create(); 106 scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
101 quad->SetNew(shared_quad_state, 107 quad->SetNew(shared_quad_state,
102 thumb_quad_rect, 108 thumb_quad_rect,
103 layer_tree_impl()->settings().solid_color_scrollbar_color, 109 layer_tree_impl()->settings().solid_color_scrollbar_color,
104 false); 110 false);
105 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); 111 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
106 return; 112 return;
107 } 113 }
108 114
109 if (thumb_resource_id_ && !thumb_quad_rect.IsEmpty()) { 115 if (thumb_resource_id_ && !thumb_quad_rect.IsEmpty()) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 opacity, 149 opacity,
144 flipped); 150 flipped);
145 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data); 151 quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
146 } 152 }
147 } 153 }
148 154
149 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const { 155 ScrollbarOrientation ScrollbarLayerImpl::Orientation() const {
150 return orientation_; 156 return orientation_;
151 } 157 }
152 158
159 bool ScrollbarLayerImpl::is_solid_color() const {
160 return is_solid_color_;
161 }
162
163 void ScrollbarLayerImpl::set_is_solid_color(bool is_solid_color) {
164 is_solid_color_ = is_solid_color;
165 }
166
153 float ScrollbarLayerImpl::CurrentPos() const { 167 float ScrollbarLayerImpl::CurrentPos() const {
154 return current_pos_; 168 return current_pos_;
155 } 169 }
156 170
157 int ScrollbarLayerImpl::Maximum() const { 171 int ScrollbarLayerImpl::Maximum() const {
158 return maximum_; 172 return maximum_;
159 } 173 }
160 174
161 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect( 175 gfx::Rect ScrollbarLayerImpl::ScrollbarLayerRectToContentRect(
162 gfx::RectF layer_rect) const { 176 gfx::RectF layer_rect) const {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // actually see down to 1000px. Thus we have to move the quad for the 241 // actually see down to 1000px. Thus we have to move the quad for the
228 // horizontal scrollbar down by the vertical_adjust_ factor and lay the 242 // horizontal scrollbar down by the vertical_adjust_ factor and lay the
229 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This 243 // vertical thumb out on a track lengthed by the vertical_adjust_ factor. This
230 // means the quads may extend outside the layer's bounds. 244 // means the quads may extend outside the layer's bounds.
231 245
232 int thumb_length = thumb_length_; 246 int thumb_length = thumb_length_;
233 float track_length = track_length_; 247 float track_length = track_length_;
234 if (orientation_ == VERTICAL) 248 if (orientation_ == VERTICAL)
235 track_length += vertical_adjust_; 249 track_length += vertical_adjust_;
236 250
237 if (layer_tree_impl()->settings().solid_color_scrollbars) { 251 if (is_solid_color()) {
238 thumb_length = std::max( 252 thumb_length = std::max(
239 static_cast<int>(visible_to_total_length_ratio_ * track_length), 253 static_cast<int>(visible_to_total_length_ratio_ * track_length),
240 thumb_thickness_); 254 thumb_thickness_);
241 } 255 }
242 256
243 // With the length known, we can compute the thumb's position. 257 // With the length known, we can compute the thumb's position.
244 float ratio = current_pos_ / maximum_; 258 float ratio = current_pos_ / maximum_;
245 float max_offset = track_length - thumb_length; 259 float max_offset = track_length - thumb_length;
246 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_; 260 int thumb_offset = static_cast<int>(ratio * max_offset) + track_start_;
247 261
(...skipping 12 matching lines...) Expand all
260 void ScrollbarLayerImpl::DidLoseOutputSurface() { 274 void ScrollbarLayerImpl::DidLoseOutputSurface() {
261 track_resource_id_ = 0; 275 track_resource_id_ = 0;
262 thumb_resource_id_ = 0; 276 thumb_resource_id_ = 0;
263 } 277 }
264 278
265 const char* ScrollbarLayerImpl::LayerTypeAsString() const { 279 const char* ScrollbarLayerImpl::LayerTypeAsString() const {
266 return "cc::ScrollbarLayerImpl"; 280 return "cc::ScrollbarLayerImpl";
267 } 281 }
268 282
269 } // namespace cc 283 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698