OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/layers/layer_position_constraint.h" | |
6 | |
7 #include "cc/layers/layer_impl.h" | |
8 #include "cc/test/fake_impl_proxy.h" | |
9 #include "cc/test/fake_layer_tree_host_impl.h" | |
10 #include "cc/test/geometry_test_utils.h" | |
11 #include "cc/trees/layer_tree_host_common.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace cc { | |
15 namespace { | |
16 | |
17 template <typename LayerType> | |
18 void SetLayerPropertiesForTestingInternal( | |
shawnsingh
2013/04/04 10:15:14
Since this is only used by LayerImpl side, let's g
trchen
2013/04/04 11:18:05
Done.
| |
19 LayerType* layer, | |
20 const gfx::Transform& transform, | |
21 const gfx::Transform& sublayer_transform, | |
22 gfx::PointF anchor, | |
23 gfx::PointF position, | |
24 gfx::Size bounds, | |
25 bool preserves3d) { | |
26 layer->SetTransform(transform); | |
27 layer->SetSublayerTransform(sublayer_transform); | |
28 layer->SetAnchorPoint(anchor); | |
29 layer->SetPosition(position); | |
30 layer->SetBounds(bounds); | |
31 layer->SetPreserves3d(preserves3d); | |
32 } | |
33 | |
34 void SetLayerPropertiesForTesting(LayerImpl* layer, | |
35 const gfx::Transform& transform, | |
36 const gfx::Transform& sublayer_transform, | |
37 gfx::PointF anchor, | |
38 gfx::PointF position, | |
39 gfx::Size bounds, | |
40 bool preserves3d) { | |
41 SetLayerPropertiesForTestingInternal<LayerImpl>(layer, | |
42 transform, | |
43 sublayer_transform, | |
44 anchor, | |
45 position, | |
46 bounds, | |
47 preserves3d); | |
48 layer->SetContentBounds(bounds); | |
49 } | |
50 | |
51 void ExecuteCalculateDrawProperties(LayerImpl* root_layer, | |
52 float device_scale_factor, | |
53 float page_scale_factor, | |
54 bool can_use_lcd_text) { | |
55 gfx::Transform identity_matrix; | |
56 std::vector<LayerImpl*> dummy_render_surface_layer_list; | |
57 int dummy_max_texture_size = 512; | |
58 gfx::Size device_viewport_size = | |
59 gfx::Size(root_layer->bounds().width() * device_scale_factor, | |
60 root_layer->bounds().height() * device_scale_factor); | |
61 | |
62 // We are probably not testing what is intended if the root_layer bounds are | |
63 // empty. | |
64 DCHECK(!root_layer->bounds().IsEmpty()); | |
65 LayerTreeHostCommon::CalculateDrawProperties(root_layer, | |
66 device_viewport_size, | |
67 device_scale_factor, | |
68 page_scale_factor, | |
69 dummy_max_texture_size, | |
70 can_use_lcd_text, | |
71 &dummy_render_surface_layer_list, | |
72 false); | |
73 } | |
74 | |
75 template <class LayerType> | |
76 void ExecuteCalculateDrawProperties(LayerType* root_layer) { | |
shawnsingh
2013/04/04 10:15:14
And this probably doesn't need to be templated her
trchen
2013/04/04 11:18:05
Done.
| |
77 ExecuteCalculateDrawProperties(root_layer, 1.f, 1.f, false); | |
78 } | |
79 | |
80 class LayerPositionConstraintTest : public testing::Test { | |
81 public: | |
82 LayerPositionConstraintTest() | |
83 : host_impl_(&proxy_) { | |
84 root_ = CreateTreeForTest(); | |
85 fixed_to_top_left_.set_is_fixed_position(true); | |
86 fixed_to_bottom_right_.set_is_fixed_position(true); | |
87 fixed_to_bottom_right_.set_is_fixed_to_right_edge(true); | |
88 fixed_to_bottom_right_.set_is_fixed_to_bottom_edge(true); | |
89 } | |
90 | |
91 scoped_ptr<LayerImpl> CreateTreeForTest() { | |
92 scoped_ptr<LayerImpl> root = | |
93 LayerImpl::Create(host_impl_.active_tree(), 1); | |
94 scoped_ptr<LayerImpl> child = | |
95 LayerImpl::Create(host_impl_.active_tree(), 2); | |
96 scoped_ptr<LayerImpl> grand_child = | |
97 LayerImpl::Create(host_impl_.active_tree(), 3); | |
98 scoped_ptr<LayerImpl> great_grand_child = | |
99 LayerImpl::Create(host_impl_.active_tree(), 4); | |
100 | |
101 gfx::Transform IdentityMatrix; | |
102 gfx::PointF anchor; | |
103 gfx::PointF position; | |
104 gfx::Size bounds(100, 100); | |
105 SetLayerPropertiesForTesting(root.get(), | |
106 IdentityMatrix, | |
107 IdentityMatrix, | |
108 anchor, | |
109 position, | |
110 bounds, | |
111 false); | |
112 SetLayerPropertiesForTesting(child.get(), | |
113 IdentityMatrix, | |
114 IdentityMatrix, | |
115 anchor, | |
116 position, | |
117 bounds, | |
118 false); | |
119 SetLayerPropertiesForTesting(grand_child.get(), | |
120 IdentityMatrix, | |
121 IdentityMatrix, | |
122 anchor, | |
123 position, | |
124 bounds, | |
125 false); | |
126 SetLayerPropertiesForTesting(great_grand_child.get(), | |
127 IdentityMatrix, | |
128 IdentityMatrix, | |
129 anchor, | |
130 position, | |
131 bounds, | |
132 false); | |
133 | |
134 grand_child->AddChild(great_grand_child.Pass()); | |
135 child->AddChild(grand_child.Pass()); | |
136 root->AddChild(child.Pass()); | |
137 | |
138 return root.Pass(); | |
139 } | |
140 protected: | |
141 FakeImplProxy proxy_; | |
142 FakeLayerTreeHostImpl host_impl_; | |
143 scoped_ptr<LayerImpl> root_; | |
144 | |
145 LayerPositionConstraint fixed_to_top_left_; | |
146 LayerPositionConstraint fixed_to_bottom_right_; | |
147 }; | |
148 | |
149 TEST_F(LayerPositionConstraintTest, | |
150 ScrollCompensationForFixedPositionLayerWithDirectContainer) { | |
151 // This test checks for correct scroll compensation when the fixed-position | |
152 // container is the direct parent of the fixed-position layer. | |
153 LayerImpl* child = root_->children()[0]; | |
154 LayerImpl* grand_child = child->children()[0]; | |
155 | |
156 child->SetIsContainerForFixedPositionLayers(true); | |
157 grand_child->SetPositionConstraint(fixed_to_top_left_); | |
158 | |
159 // Case 1: scroll delta of 0, 0 | |
160 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
161 ExecuteCalculateDrawProperties(root_.get()); | |
162 | |
163 gfx::Transform expected_child_transform; | |
164 gfx::Transform expected_grand_child_transform = expected_child_transform; | |
165 | |
166 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
167 child->draw_transform()); | |
168 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
169 grand_child->draw_transform()); | |
170 | |
171 // Case 2: scroll delta of 10, 10 | |
172 child->SetScrollDelta(gfx::Vector2d(10, 10)); | |
173 ExecuteCalculateDrawProperties(root_.get()); | |
174 | |
175 // Here the child is affected by scroll delta, but the fixed position | |
176 // grand_child should not be affected. | |
177 expected_child_transform.MakeIdentity(); | |
178 expected_child_transform.Translate(-10.0, -10.0); | |
179 | |
180 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
181 child->draw_transform()); | |
182 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
183 grand_child->draw_transform()); | |
184 | |
185 // Case 3: fixed-container size delta of 20, 20 | |
186 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
187 ExecuteCalculateDrawProperties(root_.get()); | |
188 | |
189 // Top-left fixed-position layer should not be affected by container size. | |
190 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
191 child->draw_transform()); | |
192 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
193 grand_child->draw_transform()); | |
194 | |
195 // Case 4: Bottom-right fixed-position layer. | |
196 grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
197 ExecuteCalculateDrawProperties(root_.get()); | |
198 | |
199 // Bottom-right fixed-position layer moves as container resizes. | |
200 expected_grand_child_transform.Translate(20.0, 20.0); | |
201 | |
202 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
203 child->draw_transform()); | |
204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
205 grand_child->draw_transform()); | |
206 } | |
207 | |
208 TEST_F(LayerPositionConstraintTest, | |
209 ScrollCompensationForFixedPositionLayerWithTransformedDirectContainer) { | |
210 // This test checks for correct scroll compensation when the fixed-position | |
211 // container is the direct parent of the fixed-position layer, but that | |
212 // container is transformed. In this case, the fixed position element | |
213 // inherits the container's transform, but the scroll delta that has to be | |
214 // undone should not be affected by that transform. | |
215 // | |
216 // gfx::Transforms are in general non-commutative; using something like a | |
shawnsingh
2013/04/04 10:15:14
gfx::Transforms --> transforms. I think this was
trchen
2013/04/04 11:18:05
Done.
| |
217 // non-uniform scale helps to verify that translations and non-uniform scales | |
218 // are applied in the correct order. | |
219 LayerImpl* child = root_->children()[0]; | |
220 LayerImpl* grand_child = child->children()[0]; | |
221 | |
222 // This scale will cause child and grand_child to be effectively 200 x 800 | |
223 // with respect to the render target. | |
224 gfx::Transform non_uniform_scale; | |
225 non_uniform_scale.Scale(2.0, 8.0); | |
226 child->SetTransform(non_uniform_scale); | |
227 | |
228 child->SetIsContainerForFixedPositionLayers(true); | |
229 grand_child->SetPositionConstraint(fixed_to_top_left_); | |
230 | |
231 // Case 1: scroll delta of 0, 0 | |
232 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
233 ExecuteCalculateDrawProperties(root_.get()); | |
234 | |
235 gfx::Transform expected_child_transform; | |
236 expected_child_transform.PreconcatTransform(non_uniform_scale); | |
237 | |
238 gfx::Transform expected_grand_child_transform = expected_child_transform; | |
239 | |
240 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
241 child->draw_transform()); | |
242 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
243 grand_child->draw_transform()); | |
244 | |
245 // Case 2: scroll delta of 10, 20 | |
246 child->SetScrollDelta(gfx::Vector2d(10, 20)); | |
247 ExecuteCalculateDrawProperties(root_.get()); | |
248 | |
249 // The child should be affected by scroll delta, but the fixed position | |
250 // grand_child should not be affected. | |
251 expected_child_transform.MakeIdentity(); | |
252 expected_child_transform.Translate(-10.0, -20.0); // scroll delta | |
253 expected_child_transform.PreconcatTransform(non_uniform_scale); | |
254 | |
255 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
256 child->draw_transform()); | |
257 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
258 grand_child->draw_transform()); | |
259 | |
260 // Case 3: fixed-container size delta of 20, 20 | |
261 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
262 ExecuteCalculateDrawProperties(root_.get()); | |
263 | |
264 // Top-left fixed-position layer should not be affected by container size. | |
265 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
266 child->draw_transform()); | |
267 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
268 grand_child->draw_transform()); | |
269 | |
270 // Case 4: Bottom-right fixed-position layer. | |
271 grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
272 ExecuteCalculateDrawProperties(root_.get()); | |
273 | |
274 // Bottom-right fixed-position layer moves as container resizes. | |
275 expected_grand_child_transform.Translate(20.0, 20.0); | |
shawnsingh
2013/04/04 10:15:14
Something isn't right here, but I can't explain wh
trchen
2013/04/04 11:18:05
There is no sizeDeltaCompensation in the tests at
| |
276 | |
277 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
278 child->draw_transform()); | |
279 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
280 grand_child->draw_transform()); | |
281 } | |
282 | |
283 TEST_F(LayerPositionConstraintTest, | |
284 ScrollCompensationForFixedPositionLayerWithDistantContainer) { | |
285 // This test checks for correct scroll compensation when the fixed-position | |
286 // container is NOT the direct parent of the fixed-position layer. | |
287 LayerImpl* child = root_->children()[0]; | |
288 LayerImpl* grand_child = child->children()[0]; | |
289 LayerImpl* great_grand_child = grand_child->children()[0]; | |
290 | |
291 child->SetIsContainerForFixedPositionLayers(true); | |
292 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); | |
293 great_grand_child->SetPositionConstraint(fixed_to_top_left_); | |
294 | |
295 // Case 1: scroll delta of 0, 0 | |
296 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
297 ExecuteCalculateDrawProperties(root_.get()); | |
298 | |
299 gfx::Transform expected_child_transform; | |
300 gfx::Transform expected_grand_child_transform; | |
301 expected_grand_child_transform.Translate(8.0, 6.0); | |
302 | |
303 gfx::Transform expected_great_grand_child_transform = | |
304 expected_grand_child_transform; | |
305 | |
306 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
307 child->draw_transform()); | |
308 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
309 grand_child->draw_transform()); | |
310 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
311 great_grand_child->draw_transform()); | |
312 | |
313 // Case 2: scroll delta of 10, 10 | |
314 child->SetScrollDelta(gfx::Vector2d(10, 10)); | |
315 ExecuteCalculateDrawProperties(root_.get()); | |
316 | |
317 // Here the child and grand_child are affected by scroll delta, but the fixed | |
318 // position great_grand_child should not be affected. | |
319 expected_child_transform.MakeIdentity(); | |
320 expected_child_transform.Translate(-10.0, -10.0); | |
321 expected_grand_child_transform.MakeIdentity(); | |
322 expected_grand_child_transform.Translate(-2.0, -4.0); | |
323 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
324 child->draw_transform()); | |
325 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
326 grand_child->draw_transform()); | |
327 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
328 great_grand_child->draw_transform()); | |
329 | |
330 // Case 3: fixed-container size delta of 20, 20 | |
331 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
332 ExecuteCalculateDrawProperties(root_.get()); | |
333 | |
334 // Top-left fixed-position layer should not be affected by container size. | |
335 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
336 child->draw_transform()); | |
337 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
338 grand_child->draw_transform()); | |
339 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
340 great_grand_child->draw_transform()); | |
341 | |
342 // Case 4: Bottom-right fixed-position layer. | |
343 great_grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
344 ExecuteCalculateDrawProperties(root_.get()); | |
345 | |
346 // Bottom-right fixed-position layer moves as container resizes. | |
347 expected_great_grand_child_transform.Translate(20.0, 20.0); | |
348 | |
349 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
350 child->draw_transform()); | |
351 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
352 grand_child->draw_transform()); | |
353 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
354 great_grand_child->draw_transform()); | |
355 } | |
356 | |
357 TEST_F(LayerPositionConstraintTest, | |
358 ScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms) { | |
359 // This test checks for correct scroll compensation when the fixed-position | |
360 // container is NOT the direct parent of the fixed-position layer, and the | |
361 // hierarchy has various transforms that have to be processed in the correct | |
362 // order. | |
363 LayerImpl* child = root_->children()[0]; | |
364 LayerImpl* grand_child = child->children()[0]; | |
365 LayerImpl* great_grand_child = grand_child->children()[0]; | |
366 | |
367 gfx::Transform rotation_about_z; | |
368 rotation_about_z.RotateAboutZAxis(90.0); | |
369 | |
370 child->SetIsContainerForFixedPositionLayers(true); | |
371 child->SetTransform(rotation_about_z); | |
372 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); | |
373 grand_child->SetTransform(rotation_about_z); | |
374 // great_grand_child is positioned upside-down with respect to the render | |
375 // target. | |
376 great_grand_child->SetPositionConstraint(fixed_to_top_left_); | |
377 | |
378 // Case 1: scroll delta of 0, 0 | |
379 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
380 ExecuteCalculateDrawProperties(root_.get()); | |
381 | |
382 gfx::Transform expected_child_transform; | |
383 expected_child_transform.PreconcatTransform(rotation_about_z); | |
384 | |
385 gfx::Transform expected_grand_child_transform; | |
386 expected_grand_child_transform.PreconcatTransform( | |
387 rotation_about_z); // child's local transform is inherited | |
388 // translation because of position occurs before layer's local transform. | |
389 expected_grand_child_transform.Translate(8.0, 6.0); | |
390 expected_grand_child_transform.PreconcatTransform( | |
391 rotation_about_z); // grand_child's local transform | |
392 | |
393 gfx::Transform expected_great_grand_child_transform = | |
394 expected_grand_child_transform; | |
395 | |
396 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
397 child->draw_transform()); | |
398 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
399 grand_child->draw_transform()); | |
400 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
401 great_grand_child->draw_transform()); | |
402 | |
403 // Case 2: scroll delta of 10, 20 | |
404 child->SetScrollDelta(gfx::Vector2d(10, 20)); | |
405 ExecuteCalculateDrawProperties(root_.get()); | |
406 | |
407 // Here the child and grand_child are affected by scroll delta, but the fixed | |
408 // position great_grand_child should not be affected. | |
409 expected_child_transform.MakeIdentity(); | |
410 expected_child_transform.Translate(-10.0, -20.0); // scroll delta | |
411 expected_child_transform.PreconcatTransform(rotation_about_z); | |
412 | |
413 expected_grand_child_transform.MakeIdentity(); | |
414 expected_grand_child_transform.Translate( | |
415 -10.0, -20.0); // child's scroll delta is inherited | |
416 expected_grand_child_transform.PreconcatTransform( | |
417 rotation_about_z); // child's local transform is inherited | |
418 // translation because of position occurs before layer's local transform. | |
419 expected_grand_child_transform.Translate(8.0, 6.0); | |
420 expected_grand_child_transform.PreconcatTransform( | |
421 rotation_about_z); // grand_child's local transform | |
422 | |
423 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
424 child->draw_transform()); | |
425 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
426 grand_child->draw_transform()); | |
427 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
428 great_grand_child->draw_transform()); | |
429 | |
430 // Case 3: fixed-container size delta of 20, 20 | |
431 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
432 ExecuteCalculateDrawProperties(root_.get()); | |
433 | |
434 // Top-left fixed-position layer should not be affected by container size. | |
435 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
436 child->draw_transform()); | |
437 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
438 grand_child->draw_transform()); | |
439 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
440 great_grand_child->draw_transform()); | |
441 | |
442 // Case 4: Bottom-right fixed-position layer. | |
443 great_grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
444 ExecuteCalculateDrawProperties(root_.get()); | |
445 | |
446 // Bottom-right fixed-position layer moves as container resizes. | |
447 expected_great_grand_child_transform.Translate(20.0, -20.0); | |
shawnsingh
2013/04/04 10:15:14
this comment also applies to all tests, but this i
| |
448 | |
449 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
450 child->draw_transform()); | |
451 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
452 grand_child->draw_transform()); | |
453 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
454 great_grand_child->draw_transform()); | |
455 } | |
456 | |
457 TEST_F(LayerPositionConstraintTest, | |
458 ScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas) { | |
459 // This test checks for correct scroll compensation when the fixed-position | |
460 // container has multiple ancestors that have nonzero scroll delta before | |
461 // reaching the space where the layer is fixed. In this test, each scroll | |
462 // delta occurs in a different space because of each layer's local transform. | |
463 // This test checks for correct scroll compensation when the fixed-position | |
464 // container is NOT the direct parent of the fixed-position layer, and the | |
465 // hierarchy has various transforms that have to be processed in the correct | |
466 // order. | |
467 LayerImpl* child = root_->children()[0]; | |
468 LayerImpl* grand_child = child->children()[0]; | |
469 LayerImpl* great_grand_child = grand_child->children()[0]; | |
470 | |
471 gfx::Transform rotation_about_z; | |
472 rotation_about_z.RotateAboutZAxis(90.0); | |
473 | |
474 child->SetIsContainerForFixedPositionLayers(true); | |
475 child->SetTransform(rotation_about_z); | |
476 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); | |
477 grand_child->SetTransform(rotation_about_z); | |
478 // great_grand_child is positioned upside-down with respect to the render | |
479 // target. | |
480 great_grand_child->SetPositionConstraint(fixed_to_top_left_); | |
481 | |
482 // Case 1: scroll delta of 0, 0 | |
483 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
484 ExecuteCalculateDrawProperties(root_.get()); | |
485 | |
486 gfx::Transform expected_child_transform; | |
487 expected_child_transform.PreconcatTransform(rotation_about_z); | |
488 | |
489 gfx::Transform expected_grand_child_transform; | |
490 expected_grand_child_transform.PreconcatTransform( | |
491 rotation_about_z); // child's local transform is inherited | |
492 // translation because of position occurs before layer's local transform. | |
493 expected_grand_child_transform.Translate(8.0, 6.0); | |
494 expected_grand_child_transform.PreconcatTransform( | |
495 rotation_about_z); // grand_child's local transform | |
496 | |
497 gfx::Transform expected_great_grand_child_transform = | |
498 expected_grand_child_transform; | |
499 | |
500 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
501 child->draw_transform()); | |
502 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
503 grand_child->draw_transform()); | |
504 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
505 great_grand_child->draw_transform()); | |
506 | |
507 // Case 2: scroll delta of 10, 20 | |
508 child->SetScrollDelta(gfx::Vector2d(10, 0)); | |
509 grand_child->SetScrollDelta(gfx::Vector2d(5, 0)); | |
510 ExecuteCalculateDrawProperties(root_.get()); | |
511 | |
512 // Here the child and grand_child are affected by scroll delta, but the fixed | |
513 // position great_grand_child should not be affected. | |
514 expected_child_transform.MakeIdentity(); | |
515 expected_child_transform.Translate(-10.0, 0.0); // scroll delta | |
516 expected_child_transform.PreconcatTransform(rotation_about_z); | |
517 | |
518 expected_grand_child_transform.MakeIdentity(); | |
519 expected_grand_child_transform.Translate( | |
520 -10.0, 0.0); // child's scroll delta is inherited | |
521 expected_grand_child_transform.PreconcatTransform( | |
522 rotation_about_z); // child's local transform is inherited | |
523 expected_grand_child_transform.Translate(-5.0, | |
524 0.0); // grand_child's scroll delta | |
525 // translation because of position occurs before layer's local transform. | |
526 expected_grand_child_transform.Translate(8.0, 6.0); | |
527 expected_grand_child_transform.PreconcatTransform( | |
528 rotation_about_z); // grand_child's local transform | |
529 | |
530 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
531 child->draw_transform()); | |
532 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
533 grand_child->draw_transform()); | |
534 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
535 great_grand_child->draw_transform()); | |
536 | |
537 // Case 3: fixed-container size delta of 20, 20 | |
538 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
539 ExecuteCalculateDrawProperties(root_.get()); | |
540 | |
541 // Top-left fixed-position layer should not be affected by container size. | |
542 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
543 child->draw_transform()); | |
544 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
545 grand_child->draw_transform()); | |
546 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
547 great_grand_child->draw_transform()); | |
548 | |
549 // Case 4: Bottom-right fixed-position layer. | |
shawnsingh
2013/04/04 10:15:14
I feel like the case 3 and case 4 here are actuall
| |
550 great_grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
551 ExecuteCalculateDrawProperties(root_.get()); | |
552 | |
553 // Bottom-right fixed-position layer moves as container resizes. | |
554 expected_great_grand_child_transform.Translate(20.0, -20.0); | |
555 | |
556 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
557 child->draw_transform()); | |
558 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
559 grand_child->draw_transform()); | |
560 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
561 great_grand_child->draw_transform()); | |
562 } | |
563 | |
564 TEST_F(LayerPositionConstraintTest, | |
565 ScrollCompensationForFixedPositionWithIntermediateSurfaceAndTransforms) { | |
566 // This test checks for correct scroll compensation when the fixed-position | |
567 // container contributes to a different render surface than the fixed-position | |
568 // layer. In this case, the surface draw transforms also have to be accounted | |
569 // for when checking the scroll delta. | |
570 LayerImpl* child = root_->children()[0]; | |
571 LayerImpl* grand_child = child->children()[0]; | |
572 LayerImpl* great_grand_child = grand_child->children()[0]; | |
573 | |
574 child->SetIsContainerForFixedPositionLayers(true); | |
575 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); | |
576 grand_child->SetForceRenderSurface(true); | |
577 great_grand_child->SetPositionConstraint(fixed_to_top_left_); | |
578 great_grand_child->SetDrawsContent(true); | |
579 | |
580 gfx::Transform rotation_about_z; | |
581 rotation_about_z.RotateAboutZAxis(90.0); | |
582 grand_child->SetTransform(rotation_about_z); | |
583 | |
584 // Case 1: scroll delta of 0, 0 | |
585 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
586 ExecuteCalculateDrawProperties(root_.get()); | |
587 | |
588 gfx::Transform expected_child_transform; | |
589 gfx::Transform expected_surface_draw_transform; | |
590 expected_surface_draw_transform.Translate(8.0, 6.0); | |
591 expected_surface_draw_transform.PreconcatTransform(rotation_about_z); | |
592 gfx::Transform expected_grand_child_transform; | |
593 gfx::Transform expected_great_grand_child_transform; | |
594 ASSERT_TRUE(grand_child->render_surface()); | |
595 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
596 child->draw_transform()); | |
597 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
598 expected_surface_draw_transform, | |
599 grand_child->render_surface()->draw_transform()); | |
600 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
601 grand_child->draw_transform()); | |
602 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
603 great_grand_child->draw_transform()); | |
604 | |
605 // Case 2: scroll delta of 10, 30 | |
606 child->SetScrollDelta(gfx::Vector2d(10, 30)); | |
607 ExecuteCalculateDrawProperties(root_.get()); | |
608 | |
609 // Here the grand_child remains unchanged, because it scrolls along with the | |
610 // render surface, and the translation is actually in the render surface. But, | |
611 // the fixed position great_grand_child is more awkward: its actually being | |
612 // drawn with respect to the render surface, but it needs to remain fixed with | |
613 // resepct to a container beyond that surface. So, the net result is that, | |
614 // unlike previous tests where the fixed position layer's transform remains | |
615 // unchanged, here the fixed position layer's transform explicitly contains | |
616 // the translation that cancels out the scroll. | |
617 expected_child_transform.MakeIdentity(); | |
618 expected_child_transform.Translate(-10.0, -30.0); // scroll delta | |
619 | |
620 expected_surface_draw_transform.MakeIdentity(); | |
621 expected_surface_draw_transform.Translate(-10.0, -30.0); // scroll delta | |
622 expected_surface_draw_transform.Translate(8.0, 6.0); | |
623 expected_surface_draw_transform.PreconcatTransform(rotation_about_z); | |
624 | |
625 // The rotation and its inverse are needed to place the scroll delta | |
626 // compensation in the correct space. This test will fail if the | |
627 // rotation/inverse are backwards, too, so it requires perfect order of | |
628 // operations. | |
629 expected_great_grand_child_transform.MakeIdentity(); | |
630 expected_great_grand_child_transform.PreconcatTransform( | |
631 Inverse(rotation_about_z)); | |
632 // explicit canceling out the scroll delta that gets embedded in the fixed | |
633 // position layer's surface. | |
634 expected_great_grand_child_transform.Translate(10.0, 30.0); | |
635 expected_great_grand_child_transform.PreconcatTransform(rotation_about_z); | |
636 | |
637 ASSERT_TRUE(grand_child->render_surface()); | |
638 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
639 child->draw_transform()); | |
640 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
641 expected_surface_draw_transform, | |
642 grand_child->render_surface()->draw_transform()); | |
643 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
644 grand_child->draw_transform()); | |
645 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
646 great_grand_child->draw_transform()); | |
647 | |
648 // Case 3: fixed-container size delta of 20, 20 | |
649 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
650 ExecuteCalculateDrawProperties(root_.get()); | |
651 | |
652 // Top-left fixed-position layer should not be affected by container size. | |
653 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
654 child->draw_transform()); | |
655 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
656 grand_child->draw_transform()); | |
657 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
658 great_grand_child->draw_transform()); | |
659 | |
660 // Case 4: Bottom-right fixed-position layer. | |
661 great_grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
662 ExecuteCalculateDrawProperties(root_.get()); | |
663 | |
664 // Bottom-right fixed-position layer moves as container resizes. | |
665 expected_great_grand_child_transform.Translate(20.0, -20.0); | |
shawnsingh
2013/04/04 10:15:14
same issue here, we need to see the spelled-out ex
| |
666 | |
667 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
668 child->draw_transform()); | |
669 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
670 grand_child->draw_transform()); | |
671 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
672 great_grand_child->draw_transform()); | |
673 } | |
674 | |
675 TEST_F(LayerPositionConstraintTest, | |
676 ScrollCompensationForFixedPositionLayerWithMultipleIntermediateSurfaces) { | |
677 // This test checks for correct scroll compensation when the fixed-position | |
678 // container contributes to a different render surface than the fixed-position | |
679 // layer, with additional render surfaces in-between. This checks that the | |
680 // conversion to ancestor surfaces is accumulated properly in the final matrix | |
681 // transform. | |
682 LayerImpl* child = root_->children()[0]; | |
683 LayerImpl* grand_child = child->children()[0]; | |
684 LayerImpl* great_grand_child = grand_child->children()[0]; | |
685 | |
686 // Add one more layer to the test tree for this scenario. | |
687 { | |
688 gfx::Transform identity; | |
689 scoped_ptr<LayerImpl> fixed_position_child = | |
690 LayerImpl::Create(host_impl_.active_tree(), 5); | |
691 SetLayerPropertiesForTesting(fixed_position_child.get(), | |
692 identity, | |
693 identity, | |
694 gfx::PointF(), | |
695 gfx::PointF(), | |
696 gfx::Size(100, 100), | |
697 false); | |
698 great_grand_child->AddChild(fixed_position_child.Pass()); | |
699 } | |
700 LayerImpl* fixed_position_child = great_grand_child->children()[0]; | |
701 | |
702 // Actually set up the scenario here. | |
703 child->SetIsContainerForFixedPositionLayers(true); | |
704 grand_child->SetPosition(gfx::PointF(8.f, 6.f)); | |
705 grand_child->SetForceRenderSurface(true); | |
706 great_grand_child->SetPosition(gfx::PointF(40.f, 60.f)); | |
707 great_grand_child->SetForceRenderSurface(true); | |
708 fixed_position_child->SetPositionConstraint(fixed_to_top_left_); | |
709 fixed_position_child->SetDrawsContent(true); | |
710 | |
711 // The additional rotations, which are non-commutative with translations, help | |
712 // to verify that we have correct order-of-operations in the final scroll | |
713 // compensation. Note that rotating about the center of the layer ensures we | |
714 // do not accidentally clip away layers that we want to test. | |
715 gfx::Transform rotation_about_z; | |
716 rotation_about_z.Translate(50.0, 50.0); | |
717 rotation_about_z.RotateAboutZAxis(90.0); | |
718 rotation_about_z.Translate(-50.0, -50.0); | |
719 grand_child->SetTransform(rotation_about_z); | |
720 great_grand_child->SetTransform(rotation_about_z); | |
721 | |
722 // Case 1: scroll delta of 0, 0 | |
723 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
724 ExecuteCalculateDrawProperties(root_.get()); | |
725 | |
726 gfx::Transform expected_child_transform; | |
727 | |
728 gfx::Transform expected_grand_child_surface_draw_transform; | |
729 expected_grand_child_surface_draw_transform.Translate(8.0, 6.0); | |
730 expected_grand_child_surface_draw_transform.PreconcatTransform( | |
731 rotation_about_z); | |
732 | |
733 gfx::Transform expected_grand_child_transform; | |
734 | |
735 gfx::Transform expected_great_grand_child_surface_draw_transform; | |
736 expected_great_grand_child_surface_draw_transform.Translate(40.0, 60.0); | |
737 expected_great_grand_child_surface_draw_transform.PreconcatTransform( | |
738 rotation_about_z); | |
739 | |
740 gfx::Transform expected_great_grand_child_transform; | |
741 | |
742 gfx::Transform expected_fixed_position_child_transform; | |
743 | |
744 ASSERT_TRUE(grand_child->render_surface()); | |
745 ASSERT_TRUE(great_grand_child->render_surface()); | |
746 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
747 child->draw_transform()); | |
748 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
749 expected_grand_child_surface_draw_transform, | |
750 grand_child->render_surface()->draw_transform()); | |
751 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
752 grand_child->draw_transform()); | |
753 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
754 expected_great_grand_child_surface_draw_transform, | |
755 great_grand_child->render_surface()->draw_transform()); | |
756 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
757 great_grand_child->draw_transform()); | |
758 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, | |
759 fixed_position_child->draw_transform()); | |
760 | |
761 // Case 2: scroll delta of 10, 30 | |
762 child->SetScrollDelta(gfx::Vector2d(10, 30)); | |
763 ExecuteCalculateDrawProperties(root_.get()); | |
764 | |
765 expected_child_transform.MakeIdentity(); | |
766 expected_child_transform.Translate(-10.0, -30.0); // scroll delta | |
767 | |
768 expected_grand_child_surface_draw_transform.MakeIdentity(); | |
769 expected_grand_child_surface_draw_transform.Translate(-10.0, | |
770 -30.0); // scroll delta | |
771 expected_grand_child_surface_draw_transform.Translate(8.0, 6.0); | |
772 expected_grand_child_surface_draw_transform.PreconcatTransform( | |
773 rotation_about_z); | |
774 | |
775 // grand_child, great_grand_child, and great_grand_child's surface are not | |
776 // expected to change, since they are all not fixed, and they are all drawn | |
777 // with respect to grand_child's surface that already has the scroll delta | |
778 // accounted for. | |
779 | |
780 // But the great-great grandchild, "fixed_position_child", should have a | |
781 // transform that explicitly cancels out the scroll delta. The expected | |
782 // transform is: compound_draw_transform.Inverse() * translate(positive scroll | |
783 // delta) * compound_origin_transform from great_grand_childSurface's origin | |
784 // to the root surface. | |
785 gfx::Transform compound_draw_transform; | |
786 compound_draw_transform.Translate(8.0, | |
787 6.0); // origin translation of grand_child | |
788 compound_draw_transform.PreconcatTransform( | |
789 rotation_about_z); // rotation of grand_child | |
790 compound_draw_transform.Translate( | |
791 40.0, 60.0); // origin translation of great_grand_child | |
792 compound_draw_transform.PreconcatTransform( | |
793 rotation_about_z); // rotation of great_grand_child | |
794 | |
795 expected_fixed_position_child_transform.MakeIdentity(); | |
796 expected_fixed_position_child_transform.PreconcatTransform( | |
797 Inverse(compound_draw_transform)); | |
798 // explicit canceling out the scroll delta that gets embedded in the fixed | |
799 // position layer's surface. | |
800 expected_fixed_position_child_transform.Translate(10.0, 30.0); | |
801 expected_fixed_position_child_transform.PreconcatTransform( | |
802 compound_draw_transform); | |
803 | |
804 ASSERT_TRUE(grand_child->render_surface()); | |
805 ASSERT_TRUE(great_grand_child->render_surface()); | |
806 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
807 child->draw_transform()); | |
808 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
809 expected_grand_child_surface_draw_transform, | |
810 grand_child->render_surface()->draw_transform()); | |
811 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
812 grand_child->draw_transform()); | |
813 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
814 expected_great_grand_child_surface_draw_transform, | |
815 great_grand_child->render_surface()->draw_transform()); | |
816 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
817 great_grand_child->draw_transform()); | |
818 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, | |
819 fixed_position_child->draw_transform()); | |
820 | |
821 | |
822 // Case 3: fixed-container size delta of 20, 20 | |
823 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
824 ExecuteCalculateDrawProperties(root_.get()); | |
825 | |
826 // Top-left fixed-position layer should not be affected by container size. | |
827 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
828 child->draw_transform()); | |
829 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
830 grand_child->draw_transform()); | |
831 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
832 great_grand_child->draw_transform()); | |
833 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, | |
834 fixed_position_child->draw_transform()); | |
835 | |
836 // Case 4: Bottom-right fixed-position layer. | |
837 fixed_position_child->SetPositionConstraint(fixed_to_bottom_right_); | |
838 ExecuteCalculateDrawProperties(root_.get()); | |
839 | |
840 // Bottom-right fixed-position layer moves as container resizes. | |
841 expected_fixed_position_child_transform.Translate(-20.0, -20.0); | |
shawnsingh
2013/04/04 10:15:14
and again here, same issue as above =)
| |
842 | |
843 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
844 child->draw_transform()); | |
845 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
846 grand_child->draw_transform()); | |
847 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_great_grand_child_transform, | |
848 great_grand_child->draw_transform()); | |
849 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_fixed_position_child_transform, | |
850 fixed_position_child->draw_transform()); | |
851 } | |
852 | |
853 TEST_F(LayerPositionConstraintTest, | |
854 ScrollCompensationForFixedPositionLayerWithContainerLayerThatHasSurface) { | |
855 // This test checks for correct scroll compensation when the fixed-position | |
856 // container itself has a render surface. In this case, the container layer | |
857 // should be treated like a layer that contributes to a render target, and | |
858 // that render target is completely irrelevant; it should not affect the | |
859 // scroll compensation. | |
860 LayerImpl* child = root_->children()[0]; | |
861 LayerImpl* grand_child = child->children()[0]; | |
862 | |
863 child->SetIsContainerForFixedPositionLayers(true); | |
864 child->SetForceRenderSurface(true); | |
865 grand_child->SetPositionConstraint(fixed_to_top_left_); | |
866 grand_child->SetDrawsContent(true); | |
867 | |
868 // Case 1: scroll delta of 0, 0 | |
869 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
870 ExecuteCalculateDrawProperties(root_.get()); | |
871 | |
872 gfx::Transform expected_surface_draw_transform; | |
873 expected_surface_draw_transform.Translate(0.0, 0.0); | |
874 gfx::Transform expected_child_transform; | |
875 gfx::Transform expected_grand_child_transform; | |
876 ASSERT_TRUE(child->render_surface()); | |
877 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, | |
878 child->render_surface()->draw_transform()); | |
879 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
880 child->draw_transform()); | |
881 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
882 grand_child->draw_transform()); | |
883 | |
884 // Case 2: scroll delta of 10, 10 | |
885 child->SetScrollDelta(gfx::Vector2d(10, 10)); | |
886 ExecuteCalculateDrawProperties(root_.get()); | |
887 | |
888 // The surface is translated by scroll delta, the child transform doesn't | |
889 // change because it scrolls along with the surface, but the fixed position | |
890 // grand_child needs to compensate for the scroll translation. | |
891 expected_surface_draw_transform.MakeIdentity(); | |
892 expected_surface_draw_transform.Translate(-10.0, -10.0); | |
893 expected_grand_child_transform.MakeIdentity(); | |
894 expected_grand_child_transform.Translate(10.0, 10.0); | |
895 | |
896 ASSERT_TRUE(child->render_surface()); | |
897 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_surface_draw_transform, | |
898 child->render_surface()->draw_transform()); | |
899 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
900 child->draw_transform()); | |
901 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
902 grand_child->draw_transform()); | |
903 | |
904 // Case 3: fixed-container size delta of 20, 20 | |
905 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
906 ExecuteCalculateDrawProperties(root_.get()); | |
907 | |
908 // Top-left fixed-position layer should not be affected by container size. | |
909 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
910 child->draw_transform()); | |
911 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
912 grand_child->draw_transform()); | |
913 | |
914 // Case 4: Bottom-right fixed-position layer. | |
915 grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
916 ExecuteCalculateDrawProperties(root_.get()); | |
917 | |
918 // Bottom-right fixed-position layer moves as container resizes. | |
919 expected_grand_child_transform.Translate(20.0, 20.0); | |
920 | |
921 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
922 child->draw_transform()); | |
923 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
924 grand_child->draw_transform()); | |
925 } | |
926 | |
927 TEST_F(LayerPositionConstraintTest, | |
928 ScrollCompensationForFixedPositionLayerThatIsAlsoFixedPositionContainer) { | |
929 // This test checks the scenario where a fixed-position layer also happens to | |
930 // be a container itself for a descendant fixed position layer. In particular, | |
931 // the layer should not accidentally be fixed to itself. | |
932 LayerImpl* child = root_->children()[0]; | |
933 LayerImpl* grand_child = child->children()[0]; | |
934 | |
935 child->SetIsContainerForFixedPositionLayers(true); | |
936 grand_child->SetPositionConstraint(fixed_to_top_left_); | |
937 | |
938 // This should not confuse the grand_child. If correct, the grand_child would | |
939 // still be considered fixed to its container (i.e. "child"). | |
940 grand_child->SetIsContainerForFixedPositionLayers(true); | |
941 | |
942 // Case 1: scroll delta of 0, 0 | |
943 child->SetScrollDelta(gfx::Vector2d(0, 0)); | |
944 ExecuteCalculateDrawProperties(root_.get()); | |
945 | |
946 gfx::Transform expected_child_transform; | |
947 gfx::Transform expected_grand_child_transform; | |
948 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
949 child->draw_transform()); | |
950 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
951 grand_child->draw_transform()); | |
952 | |
953 // Case 2: scroll delta of 10, 10 | |
954 child->SetScrollDelta(gfx::Vector2d(10, 10)); | |
955 ExecuteCalculateDrawProperties(root_.get()); | |
956 | |
957 // Here the child is affected by scroll delta, but the fixed position | |
958 // grand_child should not be affected. | |
959 expected_child_transform.MakeIdentity(); | |
960 expected_child_transform.Translate(-10.0, -10.0); | |
961 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
962 child->draw_transform()); | |
963 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
964 grand_child->draw_transform()); | |
965 | |
966 // Case 3: fixed-container size delta of 20, 20 | |
967 child->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
968 ExecuteCalculateDrawProperties(root_.get()); | |
969 | |
970 // Top-left fixed-position layer should not be affected by container size. | |
971 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
972 child->draw_transform()); | |
973 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
974 grand_child->draw_transform()); | |
975 | |
976 // Case 4: Bottom-right fixed-position layer. | |
977 grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
978 ExecuteCalculateDrawProperties(root_.get()); | |
979 | |
980 // Bottom-right fixed-position layer moves as container resizes. | |
981 expected_grand_child_transform.Translate(20.0, 20.0); | |
982 | |
983 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_child_transform, | |
984 child->draw_transform()); | |
985 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
986 grand_child->draw_transform()); | |
987 } | |
988 | |
989 TEST_F(LayerPositionConstraintTest, | |
990 ScrollCompensationForFixedPositionLayerThatHasNoContainer) { | |
991 // This test checks scroll compensation when a fixed-position layer does not | |
992 // find any ancestor that is a "containerForFixedPositionLayers". In this | |
993 // situation, the layer should be fixed to the viewport -- not the root_layer, | |
994 // which may have transforms of its own. | |
995 LayerImpl* child = root_->children()[0]; | |
996 LayerImpl* grand_child = child->children()[0]; | |
997 | |
998 gfx::Transform rotation_by_z; | |
999 rotation_by_z.RotateAboutZAxis(90.0); | |
1000 | |
1001 root_->SetTransform(rotation_by_z); | |
1002 grand_child->SetPositionConstraint(fixed_to_top_left_); | |
1003 | |
1004 // Case 1: root scroll delta of 0, 0 | |
1005 root_->SetScrollDelta(gfx::Vector2d(0, 0)); | |
1006 ExecuteCalculateDrawProperties(root_.get()); | |
1007 | |
1008 gfx::Transform identity_matrix; | |
1009 | |
1010 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
1011 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, | |
1012 grand_child->draw_transform()); | |
1013 | |
1014 // Case 2: root scroll delta of 10, 10 | |
1015 root_->SetScrollDelta(gfx::Vector2d(10, 20)); | |
1016 ExecuteCalculateDrawProperties(root_.get()); | |
1017 | |
1018 // The child is affected by scroll delta, but it is already implcitly | |
1019 // accounted for by the child's target surface (i.e. the root render surface). | |
1020 // The grand_child is not affected by the scroll delta, so its draw transform | |
1021 // needs to explicitly inverse-compensate for the scroll that's embedded in | |
1022 // the target surface. | |
1023 gfx::Transform expected_grand_child_transform; | |
1024 expected_grand_child_transform.PreconcatTransform(Inverse(rotation_by_z)); | |
1025 // explicit cancelling out the scroll delta that gets embedded in the fixed | |
1026 // position layer's surface. | |
1027 expected_grand_child_transform.Translate(10.0, 20.0); | |
1028 expected_grand_child_transform.PreconcatTransform(rotation_by_z); | |
1029 | |
1030 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
1031 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
1032 grand_child->draw_transform()); | |
1033 | |
1034 | |
1035 // Case 3: fixed-container size delta of 20, 20 | |
1036 root_->SetFixedContainerSizeDelta(gfx::Vector2d(20, 20)); | |
1037 ExecuteCalculateDrawProperties(root_.get()); | |
1038 | |
1039 // Top-left fixed-position layer should not be affected by container size. | |
1040 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
1041 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
1042 grand_child->draw_transform()); | |
1043 | |
1044 // Case 4: Bottom-right fixed-position layer. | |
1045 grand_child->SetPositionConstraint(fixed_to_bottom_right_); | |
1046 ExecuteCalculateDrawProperties(root_.get()); | |
1047 | |
1048 // Root layer is not the fixed-container anyway. | |
1049 EXPECT_TRANSFORMATION_MATRIX_EQ(identity_matrix, child->draw_transform()); | |
1050 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_grand_child_transform, | |
1051 grand_child->draw_transform()); | |
1052 } | |
1053 | |
1054 } // namespace | |
1055 } // namespace cc | |
OLD | NEW |