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

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

Issue 146713002: Revert of Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/scrollbar_layer_interface.h ('k') | cc/layers/solid_color_scrollbar_layer.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 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 "base/containers/hash_tables.h" 5 #include "base/containers/hash_tables.h"
6 #include "cc/animation/scrollbar_animation_controller.h" 6 #include "cc/animation/scrollbar_animation_controller.h"
7 #include "cc/layers/append_quads_data.h" 7 #include "cc/layers/append_quads_data.h"
8 #include "cc/layers/painted_scrollbar_layer.h" 8 #include "cc/layers/painted_scrollbar_layer.h"
9 #include "cc/layers/painted_scrollbar_layer_impl.h" 9 #include "cc/layers/painted_scrollbar_layer_impl.h"
10 #include "cc/layers/scrollbar_layer_interface.h" 10 #include "cc/layers/scrollbar_layer_interface.h"
(...skipping 27 matching lines...) Expand all
38 bool reverse_order, 38 bool reverse_order,
39 bool use_solid_color_scrollbar, 39 bool use_solid_color_scrollbar,
40 int thumb_thickness) { 40 int thumb_thickness) {
41 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 41 scoped_refptr<Layer> layer_tree_root = Layer::Create();
42 scoped_refptr<Layer> child1 = Layer::Create(); 42 scoped_refptr<Layer> child1 = Layer::Create();
43 scoped_refptr<Layer> child2; 43 scoped_refptr<Layer> child2;
44 if (use_solid_color_scrollbar) { 44 if (use_solid_color_scrollbar) {
45 const bool kIsLeftSideVerticalScrollbar = false; 45 const bool kIsLeftSideVerticalScrollbar = false;
46 child2 = SolidColorScrollbarLayer::Create( 46 child2 = SolidColorScrollbarLayer::Create(
47 scrollbar->Orientation(), thumb_thickness, 47 scrollbar->Orientation(), thumb_thickness,
48 kIsLeftSideVerticalScrollbar, child1.get()); 48 kIsLeftSideVerticalScrollbar, child1->id());
49 } else { 49 } else {
50 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1.get()); 50 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id());
51 } 51 }
52 layer_tree_root->AddChild(child1); 52 layer_tree_root->AddChild(child1);
53 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 53 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
54 host->SetRootLayer(layer_tree_root); 54 host->SetRootLayer(layer_tree_root);
55 return host->CommitAndCreateLayerImplTree(); 55 return host->CommitAndCreateLayerImplTree();
56 } 56 }
57 57
58 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { 58 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
59 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 59 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
60 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 60 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
61 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 61 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
62 host.get(), scrollbar.Pass(), false, false, 0); 62 host.get(), scrollbar.Pass(), false, false, 0);
63 63
64 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 64 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
65 PaintedScrollbarLayerImpl* cc_child2 = 65 PaintedScrollbarLayerImpl* cc_child2 =
66 static_cast<PaintedScrollbarLayerImpl*>( 66 static_cast<PaintedScrollbarLayerImpl*>(
67 layer_impl_tree_root->children()[1]); 67 layer_impl_tree_root->children()[1]);
68 68
69 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); 69 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2);
70 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2);
71 } 70 }
72 71
73 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { 72 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
74 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 73 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
75 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 74 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
76 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 75 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
77 host.get(), scrollbar.Pass(), true, false, 0); 76 host.get(), scrollbar.Pass(), true, false, 0);
78 77
79 PaintedScrollbarLayerImpl* cc_child1 = 78 PaintedScrollbarLayerImpl* cc_child1 =
80 static_cast<PaintedScrollbarLayerImpl*>( 79 static_cast<PaintedScrollbarLayerImpl*>(
81 layer_impl_tree_root->children()[0]); 80 layer_impl_tree_root->children()[0]);
82 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 81 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
83 82
84 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); 83 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1);
85 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1);
86 } 84 }
87 85
88 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 86 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
89 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 87 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
90 88
91 // Create and attach a non-overlay scrollbar. 89 // Create and attach a non-overlay scrollbar.
92 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 90 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
93 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 91 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
94 host.get(), scrollbar.Pass(), false, false, 0); 92 host.get(), scrollbar.Pass(), false, false, 0);
95 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 93 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
(...skipping 20 matching lines...) Expand all
116 EXPECT_EQ(InputHandler::ScrollIgnored, 114 EXPECT_EQ(InputHandler::ScrollIgnored,
117 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), 115 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0),
118 InputHandler::Gesture)); 116 InputHandler::Gesture));
119 } 117 }
120 118
121 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { 119 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) {
122 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 120 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
123 121
124 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 122 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
125 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 123 scoped_refptr<Layer> layer_tree_root = Layer::Create();
126 scoped_refptr<Layer> scroll_layer = Layer::Create();
127 scoped_refptr<Layer> content_layer = Layer::Create(); 124 scoped_refptr<Layer> content_layer = Layer::Create();
128 scoped_refptr<Layer> scrollbar_layer = 125 scoped_refptr<Layer> scrollbar_layer =
129 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root.get()); 126 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
130 127
131 // Choose bounds to give max_scroll_offset = (30, 50). 128 layer_tree_root->SetScrollable(true);
132 layer_tree_root->SetBounds(gfx::Size(70, 150)); 129 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
133 scroll_layer->SetScrollClipLayer(layer_tree_root.get()); 130 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50));
134 scroll_layer->SetScrollOffset(gfx::Vector2d(10, 20)); 131 layer_tree_root->SetBounds(gfx::Size(100, 200));
135 scroll_layer->SetBounds(gfx::Size(100, 200));
136 content_layer->SetBounds(gfx::Size(100, 200)); 132 content_layer->SetBounds(gfx::Size(100, 200));
137 133
138 host->SetRootLayer(layer_tree_root); 134 host->SetRootLayer(layer_tree_root);
139 layer_tree_root->AddChild(scroll_layer); 135 layer_tree_root->AddChild(content_layer);
140 scroll_layer->AddChild(content_layer);
141 layer_tree_root->AddChild(scrollbar_layer); 136 layer_tree_root->AddChild(scrollbar_layer);
142 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer);
143 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root);
144 137
145 layer_tree_root->SavePaintProperties(); 138 layer_tree_root->SavePaintProperties();
146 content_layer->SavePaintProperties(); 139 content_layer->SavePaintProperties();
147 140
148 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 141 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
149 142
150 ScrollbarLayerImplBase* cc_scrollbar_layer = 143 ScrollbarLayerImplBase* cc_scrollbar_layer =
151 static_cast<PaintedScrollbarLayerImpl*>( 144 static_cast<PaintedScrollbarLayerImpl*>(
152 layer_impl_tree_root->children()[1]); 145 layer_impl_tree_root->children()[1]);
153 146
154 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 147 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
155 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); 148 EXPECT_EQ(30, cc_scrollbar_layer->maximum());
156 149
157 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 150 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200));
151 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500));
152 layer_tree_root->SetBounds(gfx::Size(1000, 2000));
158 layer_tree_root->SavePaintProperties(); 153 layer_tree_root->SavePaintProperties();
159 scroll_layer->SetBounds(gfx::Size(1000, 2000));
160 scroll_layer->SetScrollOffset(gfx::Vector2d(100, 200));
161 scroll_layer->SavePaintProperties();
162 content_layer->SetBounds(gfx::Size(1000, 2000)); 154 content_layer->SetBounds(gfx::Size(1000, 2000));
163 content_layer->SavePaintProperties(); 155 content_layer->SavePaintProperties();
164 156
165 ScrollbarAnimationController* scrollbar_controller = 157 ScrollbarAnimationController* scrollbar_controller =
166 layer_impl_tree_root->scrollbar_animation_controller(); 158 layer_impl_tree_root->scrollbar_animation_controller();
167 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 159 layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
168 EXPECT_EQ(scrollbar_controller, 160 EXPECT_EQ(scrollbar_controller,
169 layer_impl_tree_root->scrollbar_animation_controller()); 161 layer_impl_tree_root->scrollbar_animation_controller());
170 162
171 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); 163 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
172 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); 164 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
173 165
174 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 166 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34));
175 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
176 167
177 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); 168 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
178 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); 169 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
179 } 170 }
180 171
181 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \
182 do { \
183 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
184 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \
185 root_layer_impl = root_clip_layer_impl->children()[0]; \
186 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
187 root_layer_impl->children()[1]); \
188 scrollbar_layer_impl->ScrollbarParametersDidChange(); \
189 } while (false)
190
191 TEST(ScrollbarLayerTest, ThumbRect) { 172 TEST(ScrollbarLayerTest, ThumbRect) {
192 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); 173 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
193 scoped_refptr<Layer> root_clip_layer = Layer::Create();
194 scoped_refptr<Layer> root_layer = Layer::Create(); 174 scoped_refptr<Layer> root_layer = Layer::Create();
195 scoped_refptr<Layer> content_layer = Layer::Create(); 175 scoped_refptr<Layer> content_layer = Layer::Create();
196 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 176 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
197 FakePaintedScrollbarLayer::Create(false, true, root_layer.get()); 177 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
198 178
199 root_layer->SetScrollClipLayer(root_clip_layer.get()); 179 root_layer->SetScrollable(true);
200 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 180 root_layer->SetMaxScrollOffset(gfx::Vector2d(80, 0));
201 root_clip_layer->SetBounds(gfx::Size(20, 50));
202 root_layer->SetBounds(gfx::Size(100, 50)); 181 root_layer->SetBounds(gfx::Size(100, 50));
203 content_layer->SetBounds(gfx::Size(100, 50)); 182 content_layer->SetBounds(gfx::Size(100, 50));
204 183
205 host->SetRootLayer(root_clip_layer); 184 host->SetRootLayer(root_layer);
206 root_clip_layer->AddChild(root_layer);
207 root_layer->AddChild(content_layer); 185 root_layer->AddChild(content_layer);
208 root_layer->AddChild(scrollbar_layer); 186 root_layer->AddChild(scrollbar_layer);
209 187
210 root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); 188 root_layer->SetScrollOffset(gfx::Vector2d(0, 0));
211 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 189 scrollbar_layer->SetBounds(gfx::Size(70, 10));
212 scrollbar_layer->SetScrollLayer(root_layer.get());
213 scrollbar_layer->SetClipLayer(root_clip_layer.get());
214 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 190 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
215 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 191 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
216 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 192 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
217 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 193 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
218 scrollbar_layer->UpdateThumbAndTrackGeometry(); 194 scrollbar_layer->UpdateThumbAndTrackGeometry();
219 LayerImpl* root_clip_layer_impl = NULL;
220 LayerImpl* root_layer_impl = NULL; 195 LayerImpl* root_layer_impl = NULL;
221 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; 196 PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL;
222 197
223 // Thumb is at the edge of the scrollbar (should be inset to 198 // Thumb is at the edge of the scrollbar (should be inset to
224 // the start of the track within the scrollbar layer's 199 // the start of the track within the scrollbar layer's
225 // position). 200 // position).
226 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 201 scrollbar_layer->UpdateThumbAndTrackGeometry();
202 root_layer_impl = host->CommitAndCreateLayerImplTree();
203 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
204 root_layer_impl->children()[1]);
227 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 205 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
228 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 206 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
229 207
230 // Under-scroll (thumb position should clamp and be unchanged). 208 // Under-scroll (thumb position should clamp and be unchanged).
231 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); 209 root_layer->SetScrollOffset(gfx::Vector2d(-5, 0));
232 210
233 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 211 scrollbar_layer->UpdateThumbAndTrackGeometry();
212 root_layer_impl = host->CommitAndCreateLayerImplTree();
213 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
214 root_layer_impl->children()[1]);
234 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 215 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
235 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 216 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
236 217
237 // Over-scroll (thumb position should clamp on the far side). 218 // Over-scroll (thumb position should clamp on the far side).
238 root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); 219 root_layer->SetScrollOffset(gfx::Vector2d(85, 0));
239 220
240 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 221 scrollbar_layer->UpdateThumbAndTrackGeometry();
222 root_layer_impl = host->CommitAndCreateLayerImplTree();
223 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
224 root_layer_impl->children()[1]);
241 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), 225 EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(),
242 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 226 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
243 227
244 // Change thumb thickness and length. 228 // Change thumb thickness and length.
245 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); 229 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4);
246 scrollbar_layer->fake_scrollbar()->set_thumb_length(6); 230 scrollbar_layer->fake_scrollbar()->set_thumb_length(6);
247 231
248 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 232 scrollbar_layer->UpdateThumbAndTrackGeometry();
233 root_layer_impl = host->CommitAndCreateLayerImplTree();
234 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
235 root_layer_impl->children()[1]);
249 EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(), 236 EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(),
250 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 237 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
251 238
252 // Shrink the scrollbar layer to cover only the track. 239 // Shrink the scrollbar layer to cover only the track.
253 scrollbar_layer->SetBounds(gfx::Size(50, 10)); 240 scrollbar_layer->SetBounds(gfx::Size(50, 10));
254 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10)); 241 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10));
255 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 242 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
256 243
257 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 244 scrollbar_layer->UpdateThumbAndTrackGeometry();
245 root_layer_impl = host->CommitAndCreateLayerImplTree();
246 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
247 root_layer_impl->children()[1]);
258 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), 248 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
259 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 249 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
260 250
261 // Shrink the track in the non-scrolling dimension so that it only covers the 251 // Shrink the track in the non-scrolling dimension so that it only covers the
262 // middle third of the scrollbar layer (this does not affect the thumb 252 // middle third of the scrollbar layer (this does not affect the thumb
263 // position). 253 // position).
264 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); 254 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6));
265 255
266 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 256 scrollbar_layer->UpdateThumbAndTrackGeometry();
257 root_layer_impl = host->CommitAndCreateLayerImplTree();
258 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
259 root_layer_impl->children()[1]);
267 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), 260 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
268 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 261 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
269 } 262 }
270 263
271 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { 264 TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
272 const int kThumbThickness = 3; 265 const int kThumbThickness = 3;
273 const int kTrackLength = 100; 266 const int kTrackLength = 100;
274 267
275 LayerTreeSettings layer_tree_settings; 268 LayerTreeSettings layer_tree_settings;
276 scoped_ptr<FakeLayerTreeHost> host = 269 scoped_ptr<FakeLayerTreeHost> host =
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 325
333 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 326 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
334 const int kThumbThickness = 3; 327 const int kThumbThickness = 3;
335 const int kTrackLength = 10; 328 const int kTrackLength = 10;
336 329
337 LayerTreeSettings layer_tree_settings; 330 LayerTreeSettings layer_tree_settings;
338 scoped_ptr<FakeLayerTreeHost> host = 331 scoped_ptr<FakeLayerTreeHost> host =
339 FakeLayerTreeHost::Create(layer_tree_settings); 332 FakeLayerTreeHost::Create(layer_tree_settings);
340 333
341 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 334 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
342 335 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
343 { 336 host.get(), scrollbar.Pass(), false, true, kThumbThickness);
344 scoped_refptr<Layer> layer_tree_root = Layer::Create();
345 scoped_refptr<Layer> scroll_layer = Layer::Create();
346 scroll_layer->SetScrollClipLayer(layer_tree_root);
347 scoped_refptr<Layer> child1 = Layer::Create();
348 scoped_refptr<Layer> child2;
349 const bool kIsLeftSideVerticalScrollbar = false;
350 child2 = SolidColorScrollbarLayer::Create(
351 scrollbar->Orientation(), kThumbThickness,
352 kIsLeftSideVerticalScrollbar, child1.get());
353 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer);
354 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root);
355 scroll_layer->AddChild(child1);
356 scroll_layer->InsertChild(child2, 1);
357 layer_tree_root->AddChild(scroll_layer);
358 host->SetRootLayer(layer_tree_root);
359 }
360 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
361 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
362
363 ScrollbarLayerImplBase* scrollbar_layer_impl = 337 ScrollbarLayerImplBase* scrollbar_layer_impl =
364 static_cast<PaintedScrollbarLayerImpl*>( 338 static_cast<PaintedScrollbarLayerImpl*>(
365 scroll_layer_impl->children()[1]); 339 layer_impl_tree_root->children()[1]);
366
367 // Choose layer bounds to give max_scroll_offset = (8, 8).
368 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
369 scroll_layer_impl->SetBounds(gfx::Size(10, 10));
370 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f));
371 340
372 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
373 scrollbar_layer_impl->SetCurrentPos(4.f); 342 scrollbar_layer_impl->SetCurrentPos(4.f);
374 scrollbar_layer_impl->SetMaximum(8); 343 scrollbar_layer_impl->SetMaximum(8);
375 344
345 layer_impl_tree_root->SetScrollable(true);
346 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl);
347 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8));
348 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
349 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f));
350
376 { 351 {
377 MockQuadCuller quad_culler; 352 MockQuadCuller quad_culler;
378 AppendQuadsData data; 353 AppendQuadsData data;
379 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); 354 scrollbar_layer_impl->AppendQuads(&quad_culler, &data);
380 355
381 const QuadList& quads = quad_culler.quad_list(); 356 const QuadList& quads = quad_culler.quad_list();
382 ASSERT_EQ(1u, quads.size()); 357 ASSERT_EQ(1u, quads.size());
383 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); 358 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material);
384 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); 359 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect);
385 } 360 }
386 } 361 }
387 362
388 class ScrollbarLayerSolidColorThumbTest : public testing::Test { 363 class ScrollbarLayerSolidColorThumbTest : public testing::Test {
389 public: 364 public:
390 ScrollbarLayerSolidColorThumbTest() { 365 ScrollbarLayerSolidColorThumbTest() {
391 LayerTreeSettings layer_tree_settings; 366 LayerTreeSettings layer_tree_settings;
392 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); 367 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_));
393 368
394 const int kThumbThickness = 3; 369 const int kThumbThickness = 3;
395 const bool kIsLeftSideVerticalScrollbar = false; 370 const bool kIsLeftSideVerticalScrollbar = false;
396 const bool kIsOverlayScrollbar = false;
397 371
398 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( 372 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
399 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness, 373 host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness,
400 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); 374 kIsLeftSideVerticalScrollbar);
401 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( 375 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
402 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness, 376 host_impl_->active_tree(), 2, VERTICAL, kThumbThickness,
403 kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); 377 kIsLeftSideVerticalScrollbar);
404 } 378 }
405 379
406 protected: 380 protected:
407 FakeImplProxy proxy_; 381 FakeImplProxy proxy_;
408 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; 382 scoped_ptr<FakeLayerTreeHostImpl> host_impl_;
409 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; 383 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_;
410 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; 384 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_;
411 }; 385 };
412 386
413 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { 387 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 vertical_scrollbar_layer_->ComputeThumbQuadRect()); 449 vertical_scrollbar_layer_->ComputeThumbQuadRect());
476 } 450 }
477 451
478 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest { 452 class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
479 public: 453 public:
480 ScrollbarLayerTestMaxTextureSize() {} 454 ScrollbarLayerTestMaxTextureSize() {}
481 455
482 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } 456 void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; }
483 457
484 virtual void BeginTest() OVERRIDE { 458 virtual void BeginTest() OVERRIDE {
485 scroll_layer_ = Layer::Create();
486 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
487
488 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 459 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
489 scrollbar_layer_ = 460 scrollbar_layer_ = PaintedScrollbarLayer::Create(scrollbar.Pass(), 1);
490 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_.get());
491 scrollbar_layer_->SetScrollLayer(scroll_layer_);
492 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 461 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
493 scrollbar_layer_->SetBounds(bounds_); 462 scrollbar_layer_->SetBounds(bounds_);
494 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 463 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
495 464
465 scroll_layer_ = Layer::Create();
466 scrollbar_layer_->SetScrollLayerId(scroll_layer_->id());
467 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
468
496 PostSetNeedsCommitToMainThread(); 469 PostSetNeedsCommitToMainThread();
497 } 470 }
498 471
499 virtual void DidCommitAndDrawFrame() OVERRIDE { 472 virtual void DidCommitAndDrawFrame() OVERRIDE {
500 const int kMaxTextureSize = 473 const int kMaxTextureSize =
501 layer_tree_host()->GetRendererCapabilities().max_texture_size; 474 layer_tree_host()->GetRendererCapabilities().max_texture_size;
502 475
503 // Check first that we're actually testing something. 476 // Check first that we're actually testing something.
504 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); 477 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize);
505 478
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 577 scoped_refptr<Layer> layer_tree_root = Layer::Create();
605 scoped_refptr<Layer> content_layer = Layer::Create(); 578 scoped_refptr<Layer> content_layer = Layer::Create();
606 scoped_refptr<Layer> scrollbar_layer; 579 scoped_refptr<Layer> scrollbar_layer;
607 if (use_solid_color_scrollbar) { 580 if (use_solid_color_scrollbar) {
608 const int kThumbThickness = 3; 581 const int kThumbThickness = 3;
609 const bool kIsLeftSideVerticalScrollbar = false; 582 const bool kIsLeftSideVerticalScrollbar = false;
610 scrollbar_layer = 583 scrollbar_layer =
611 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 584 SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
612 kThumbThickness, 585 kThumbThickness,
613 kIsLeftSideVerticalScrollbar, 586 kIsLeftSideVerticalScrollbar,
614 layer_tree_root.get()); 587 layer_tree_root->id());
615 } else { 588 } else {
616 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), 589 scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(),
617 layer_tree_root.get()); 590 layer_tree_root->id());
618 } 591 }
619 layer_tree_root->AddChild(content_layer); 592 layer_tree_root->AddChild(content_layer);
620 layer_tree_root->AddChild(scrollbar_layer); 593 layer_tree_root->AddChild(scrollbar_layer);
621 594
622 layer_tree_host_->SetRootLayer(layer_tree_root); 595 layer_tree_host_->SetRootLayer(layer_tree_root);
623 596
624 scrollbar_layer->SetIsDrawable(true); 597 scrollbar_layer->SetIsDrawable(true);
625 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 598 scrollbar_layer->SetBounds(gfx::Size(100, 100));
626 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); 599 layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20));
600 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50));
627 layer_tree_root->SetBounds(gfx::Size(100, 200)); 601 layer_tree_root->SetBounds(gfx::Size(100, 200));
628 content_layer->SetBounds(gfx::Size(100, 200)); 602 content_layer->SetBounds(gfx::Size(100, 200));
629 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); 603 scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200);
630 scrollbar_layer->draw_properties().visible_content_rect = 604 scrollbar_layer->draw_properties().visible_content_rect =
631 gfx::Rect(0, 0, 100, 200); 605 gfx::Rect(0, 0, 100, 200);
632 scrollbar_layer->CreateRenderSurface(); 606 scrollbar_layer->CreateRenderSurface();
633 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get(); 607 scrollbar_layer->draw_properties().render_target = scrollbar_layer.get();
634 608
635 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 609 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
636 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get()); 610 EXPECT_EQ(scrollbar_layer->layer_tree_host(), layer_tree_host_.get());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 657 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
684 658
685 void TestResourceUpload(const float test_scale) { 659 void TestResourceUpload(const float test_scale) {
686 layer_tree_host_.reset( 660 layer_tree_host_.reset(
687 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); 661 new MockLayerTreeHost(&fake_client_, layer_tree_settings_));
688 662
689 gfx::Point scrollbar_location(0, 185); 663 gfx::Point scrollbar_location(0, 185);
690 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 664 scoped_refptr<Layer> layer_tree_root = Layer::Create();
691 scoped_refptr<Layer> content_layer = Layer::Create(); 665 scoped_refptr<Layer> content_layer = Layer::Create();
692 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 666 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
693 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root.get()); 667 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
694 668
695 layer_tree_root->AddChild(content_layer); 669 layer_tree_root->AddChild(content_layer);
696 layer_tree_root->AddChild(scrollbar_layer); 670 layer_tree_root->AddChild(scrollbar_layer);
697 671
698 layer_tree_host_->SetRootLayer(layer_tree_root); 672 layer_tree_host_->SetRootLayer(layer_tree_root);
699 673
700 scrollbar_layer->SetIsDrawable(true); 674 scrollbar_layer->SetIsDrawable(true);
701 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 675 scrollbar_layer->SetBounds(gfx::Size(100, 15));
702 scrollbar_layer->SetPosition(scrollbar_location); 676 scrollbar_layer->SetPosition(scrollbar_location);
703 layer_tree_root->SetBounds(gfx::Size(100, 200)); 677 layer_tree_root->SetBounds(gfx::Size(100, 200));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 727 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
754 // Pick a test scale that moves the scrollbar's (non-zero) position to 728 // Pick a test scale that moves the scrollbar's (non-zero) position to
755 // a non-pixel-aligned location. 729 // a non-pixel-aligned location.
756 TestResourceUpload(.041f); 730 TestResourceUpload(.041f);
757 TestResourceUpload(1.41f); 731 TestResourceUpload(1.41f);
758 TestResourceUpload(4.1f); 732 TestResourceUpload(4.1f);
759 } 733 }
760 734
761 } // namespace 735 } // namespace
762 } // namespace cc 736 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/scrollbar_layer_interface.h ('k') | cc/layers/solid_color_scrollbar_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698