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

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

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

Powered by Google App Engine
This is Rietveld 408576698