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

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp

Issue 2831683003: Refactor to centralize code which decides whether ObjectPaintProperties are needed. (Closed)
Patch Set: none Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/PaintPropertyTreeBuilderTest.h" 5 #include "core/paint/PaintPropertyTreeBuilderTest.h"
6 6
7 #include "core/html/HTMLIFrameElement.h" 7 #include "core/html/HTMLIFrameElement.h"
8 #include "core/layout/LayoutTreeAsText.h" 8 #include "core/layout/LayoutTreeAsText.h"
9 #include "core/paint/ObjectPaintProperties.h" 9 #include "core/paint/ObjectPaintProperties.h"
10 #include "core/paint/PaintPropertyTreePrinter.h" 10 #include "core/paint/PaintPropertyTreePrinter.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 EXPECT_FALSE(FrameScrollTranslation()->HasDirectCompositingReasons()); 371 EXPECT_FALSE(FrameScrollTranslation()->HasDirectCompositingReasons());
372 372
373 CHECK_EXACT_VISUAL_RECT(LayoutRect(173, 556, 400, 300), 373 CHECK_EXACT_VISUAL_RECT(LayoutRect(173, 556, 400, 300),
374 transform->GetLayoutObject(), 374 transform->GetLayoutObject(),
375 GetDocument().View()->GetLayoutView()); 375 GetDocument().View()->GetLayoutView());
376 376
377 transform->setAttribute( 377 transform->setAttribute(
378 HTMLNames::styleAttr, 378 HTMLNames::styleAttr,
379 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px;"); 379 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px;");
380 GetDocument().View()->UpdateAllLifecyclePhases(); 380 GetDocument().View()->UpdateAllLifecyclePhases();
381 EXPECT_EQ(nullptr, 381 EXPECT_EQ(nullptr, transform->GetLayoutObject()->PaintProperties());
382 transform->GetLayoutObject()->PaintProperties()->Transform());
383 382
384 transform->setAttribute( 383 transform->setAttribute(
385 HTMLNames::styleAttr, 384 HTMLNames::styleAttr,
386 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px; " 385 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px; "
387 "transform: translate3d(123px, 456px, 789px)"); 386 "transform: translate3d(123px, 456px, 789px)");
388 GetDocument().View()->UpdateAllLifecyclePhases(); 387 GetDocument().View()->UpdateAllLifecyclePhases();
389 EXPECT_EQ( 388 EXPECT_EQ(
390 TransformationMatrix().Translate3d(123, 456, 789), 389 TransformationMatrix().Translate3d(123, 456, 789),
391 transform->GetLayoutObject()->PaintProperties()->Transform()->Matrix()); 390 transform->GetLayoutObject()->PaintProperties()->Transform()->Matrix());
392 } 391 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 EXPECT_TRUE(transform_properties->Transform()->HasDirectCompositingReasons()); 471 EXPECT_TRUE(transform_properties->Transform()->HasDirectCompositingReasons());
473 472
474 CHECK_EXACT_VISUAL_RECT(LayoutRect(50, 100, 400, 300), 473 CHECK_EXACT_VISUAL_RECT(LayoutRect(50, 100, 400, 300),
475 transform->GetLayoutObject(), 474 transform->GetLayoutObject(),
476 GetDocument().View()->GetLayoutView()); 475 GetDocument().View()->GetLayoutView());
477 476
478 transform->setAttribute( 477 transform->setAttribute(
479 HTMLNames::styleAttr, 478 HTMLNames::styleAttr,
480 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px;"); 479 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px;");
481 GetDocument().View()->UpdateAllLifecyclePhases(); 480 GetDocument().View()->UpdateAllLifecyclePhases();
482 EXPECT_EQ(nullptr, 481 EXPECT_EQ(nullptr, transform->GetLayoutObject()->PaintProperties());
483 transform->GetLayoutObject()->PaintProperties()->Transform());
484 482
485 transform->setAttribute( 483 transform->setAttribute(
486 HTMLNames::styleAttr, 484 HTMLNames::styleAttr,
487 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px; " 485 "margin-left: 50px; margin-top: 100px; width: 400px; height: 300px; "
488 "will-change: transform"); 486 "will-change: transform");
489 GetDocument().View()->UpdateAllLifecyclePhases(); 487 GetDocument().View()->UpdateAllLifecyclePhases();
490 EXPECT_EQ( 488 EXPECT_EQ(
491 TransformationMatrix(), 489 TransformationMatrix(),
492 transform->GetLayoutObject()->PaintProperties()->Transform()->Matrix()); 490 transform->GetLayoutObject()->PaintProperties()->Transform()->Matrix());
493 } 491 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 EXPECT_EQ(TransformationMatrix().Translate3d(1, 2, 3), 1013 EXPECT_EQ(TransformationMatrix().Translate3d(1, 2, 3),
1016 svg_with_transform_properties->Transform()->Matrix()); 1014 svg_with_transform_properties->Transform()->Matrix());
1017 1015
1018 LayoutObject& div_with_transform = 1016 LayoutObject& div_with_transform =
1019 *GetDocument().GetElementById("divWithTransform")->GetLayoutObject(); 1017 *GetDocument().GetElementById("divWithTransform")->GetLayoutObject();
1020 const ObjectPaintProperties* div_with_transform_properties = 1018 const ObjectPaintProperties* div_with_transform_properties =
1021 div_with_transform.PaintProperties(); 1019 div_with_transform.PaintProperties();
1022 EXPECT_EQ(TransformationMatrix().Translate3d(3, 4, 5), 1020 EXPECT_EQ(TransformationMatrix().Translate3d(3, 4, 5),
1023 div_with_transform_properties->Transform()->Matrix()); 1021 div_with_transform_properties->Transform()->Matrix());
1024 // Ensure the div's transform node is a child of the svg's transform node. 1022 // Ensure the div's transform node is a child of the svg's transform node.
1023 // (The first parent is the SVG to local border box transform.)
1025 EXPECT_EQ(svg_with_transform_properties->Transform(), 1024 EXPECT_EQ(svg_with_transform_properties->Transform(),
1026 div_with_transform_properties->Transform()->Parent()); 1025 div_with_transform_properties->Transform()->Parent()->Parent());
1027 } 1026 }
1028 1027
1029 TEST_P(PaintPropertyTreeBuilderTest, 1028 TEST_P(PaintPropertyTreeBuilderTest,
1030 FixedTransformAncestorAcrossSVGHTMLBoundary) { 1029 FixedTransformAncestorAcrossSVGHTMLBoundary) {
1031 SetBodyInnerHTML( 1030 SetBodyInnerHTML(
1032 "<style> body { margin: 0px; } </style>" 1031 "<style> body { margin: 0px; } </style>"
1033 "<svg id='svg' style='transform: translate3d(1px, 2px, 3px);'>" 1032 "<svg id='svg' style='transform: translate3d(1px, 2px, 3px);'>"
1034 " <g id='container' transform='translate(20 30)'>" 1033 " <g id='container' transform='translate(20 30)'>"
1035 " <foreignObject>" 1034 " <foreignObject>"
1036 " <body>" 1035 " <body>"
1037 " <div id='fixed'" 1036 " <div id='fixed'"
1038 " style='position: fixed; left: 200px; top: 150px;'></div>" 1037 " style='position: fixed; left: 200px; top: 150px;'></div>"
1039 " </body>" 1038 " </body>"
1040 " </foreignObject>" 1039 " </foreignObject>"
1041 " </g>" 1040 " </g>"
1042 "</svg>"); 1041 "</svg>");
1043 1042
1044 LayoutObject& svg = *GetDocument().GetElementById("svg")->GetLayoutObject(); 1043 LayoutObject& svg = *GetDocument().GetElementById("svg")->GetLayoutObject();
1045 const ObjectPaintProperties* svg_properties = svg.PaintProperties(); 1044 const ObjectPaintProperties* svg_properties = svg.PaintProperties();
1046 EXPECT_EQ(TransformationMatrix().Translate3d(1, 2, 3), 1045 EXPECT_EQ(TransformationMatrix().Translate3d(1, 2, 3),
1047 svg_properties->Transform()->Matrix()); 1046 svg_properties->Transform()->Matrix());
1048 1047
1049 LayoutObject& container = 1048 LayoutObject& container =
1050 *GetDocument().GetElementById("container")->GetLayoutObject(); 1049 *GetDocument().GetElementById("container")->GetLayoutObject();
1051 const ObjectPaintProperties* container_properties = 1050 const ObjectPaintProperties* container_properties =
1052 container.PaintProperties(); 1051 container.PaintProperties();
1053 EXPECT_EQ(TransformationMatrix().Translate(20, 30), 1052 EXPECT_EQ(TransformationMatrix().Translate(20, 30),
1054 container_properties->Transform()->Matrix()); 1053 container_properties->Transform()->Matrix());
1054 // (The first parent is the SVG to local border box transform.)
1055 EXPECT_EQ(svg_properties->Transform(), 1055 EXPECT_EQ(svg_properties->Transform(),
1056 container_properties->Transform()->Parent()); 1056 container_properties->Transform()->Parent()->Parent());
1057 1057
1058 Element* fixed = GetDocument().GetElementById("fixed"); 1058 Element* fixed = GetDocument().GetElementById("fixed");
1059 // Ensure the fixed position element is rooted at the nearest transform 1059 // Ensure the fixed position element is rooted at the nearest transform
1060 // container. 1060 // container.
1061 EXPECT_EQ(container_properties->Transform(), 1061 EXPECT_EQ(container_properties->Transform(),
1062 fixed->GetLayoutObject()->LocalBorderBoxProperties()->Transform()); 1062 fixed->GetLayoutObject()->LocalBorderBoxProperties()->Transform());
1063 } 1063 }
1064 1064
1065 TEST_P(PaintPropertyTreeBuilderTest, ControlClip) { 1065 TEST_P(PaintPropertyTreeBuilderTest, ControlClip) {
1066 SetBodyInnerHTML( 1066 SetBodyInnerHTML(
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 " <rect id='rect' transform='translate(1, 1)'/>" 1936 " <rect id='rect' transform='translate(1, 1)'/>"
1937 "</svg>"); 1937 "</svg>");
1938 1938
1939 LayoutObject& svg_with_transform = 1939 LayoutObject& svg_with_transform =
1940 *GetDocument().GetElementById("svg")->GetLayoutObject(); 1940 *GetDocument().GetElementById("svg")->GetLayoutObject();
1941 const ObjectPaintProperties* svg_with_transform_properties = 1941 const ObjectPaintProperties* svg_with_transform_properties =
1942 svg_with_transform.PaintProperties(); 1942 svg_with_transform.PaintProperties();
1943 EXPECT_EQ(TransformationMatrix(), 1943 EXPECT_EQ(TransformationMatrix(),
1944 svg_with_transform_properties->Transform()->Matrix()); 1944 svg_with_transform_properties->Transform()->Matrix());
1945 EXPECT_EQ(LayoutPoint(FloatPoint(0.1, 0)), svg_with_transform.PaintOffset()); 1945 EXPECT_EQ(LayoutPoint(FloatPoint(0.1, 0)), svg_with_transform.PaintOffset());
1946 EXPECT_EQ(nullptr, 1946 EXPECT_FALSE(svg_with_transform_properties->SvgLocalToBorderBoxTransform() ==
1947 svg_with_transform_properties->SvgLocalToBorderBoxTransform()); 1947 nullptr);
1948 1948
1949 LayoutObject& rect_with_transform = 1949 LayoutObject& rect_with_transform =
1950 *GetDocument().GetElementById("rect")->GetLayoutObject(); 1950 *GetDocument().GetElementById("rect")->GetLayoutObject();
1951 const ObjectPaintProperties* rect_with_transform_properties = 1951 const ObjectPaintProperties* rect_with_transform_properties =
1952 rect_with_transform.PaintProperties(); 1952 rect_with_transform.PaintProperties();
1953 EXPECT_EQ(TransformationMatrix().Translate(1, 1), 1953 EXPECT_EQ(TransformationMatrix().Translate(1, 1),
1954 rect_with_transform_properties->Transform()->Matrix()); 1954 rect_with_transform_properties->Transform()->Matrix());
1955 1955
1956 // Ensure there is no PaintOffset transform between the rect and the svg's 1956 // Ensure there is no PaintOffset transform between the rect and the svg's
1957 // transform. 1957 // transform.
1958 // (The first parent is the SVG to border box transform.)
1958 EXPECT_EQ(svg_with_transform_properties->Transform(), 1959 EXPECT_EQ(svg_with_transform_properties->Transform(),
1959 rect_with_transform_properties->Transform()->Parent()); 1960 rect_with_transform_properties->Transform()->Parent()->Parent());
1960 } 1961 }
1961 1962
1962 TEST_P(PaintPropertyTreeBuilderTest, SvgRootAndForeignObjectPixelSnapping) { 1963 TEST_P(PaintPropertyTreeBuilderTest, SvgRootAndForeignObjectPixelSnapping) {
1963 SetBodyInnerHTML( 1964 SetBodyInnerHTML(
1964 "<svg id=svg style='position: relative; left: 0.6px; top: 0.3px'>" 1965 "<svg id=svg style='position: relative; left: 0.6px; top: 0.3px'>"
1965 " <foreignObject id=foreign x='3.5' y='5.4' transform='translate(1, 1)'>" 1966 " <foreignObject id=foreign x='3.5' y='5.4' transform='translate(1, 1)'>"
1966 " <div id=div style='position: absolute; left: 5.6px; top: 7.3px'>" 1967 " <div id=div style='position: absolute; left: 5.6px; top: 7.3px'>"
1967 " </div>" 1968 " </div>"
1968 " </foreignObject>" 1969 " </foreignObject>"
1969 "</svg>"); 1970 "</svg>");
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 2329
2329 // Remove transform from b. B's transform node should be removed from the 2330 // Remove transform from b. B's transform node should be removed from the
2330 // tree, and a and c's transform nodes should be unchanged (with c's parent 2331 // tree, and a and c's transform nodes should be unchanged (with c's parent
2331 // adjusted). 2332 // adjusted).
2332 b->setAttribute(HTMLNames::styleAttr, ""); 2333 b->setAttribute(HTMLNames::styleAttr, "");
2333 GetDocument().View()->UpdateAllLifecyclePhases(); 2334 GetDocument().View()->UpdateAllLifecyclePhases();
2334 2335
2335 EXPECT_EQ(a_properties, a->GetLayoutObject()->PaintProperties()); 2336 EXPECT_EQ(a_properties, a->GetLayoutObject()->PaintProperties());
2336 EXPECT_EQ(a_transform_node, a_properties->Transform()); 2337 EXPECT_EQ(a_transform_node, a_properties->Transform());
2337 2338
2338 EXPECT_EQ(b_properties, b->GetLayoutObject()->PaintProperties()); 2339 EXPECT_EQ(nullptr, b->GetLayoutObject()->PaintProperties());
2339 EXPECT_EQ(nullptr, b_properties->Transform());
2340 2340
2341 EXPECT_EQ(c_properties, c->GetLayoutObject()->PaintProperties()); 2341 EXPECT_EQ(c_properties, c->GetLayoutObject()->PaintProperties());
2342 EXPECT_EQ(c_transform_node, c_properties->Transform()); 2342 EXPECT_EQ(c_transform_node, c_properties->Transform());
2343 EXPECT_EQ(a_transform_node, c_transform_node->Parent()); 2343 EXPECT_EQ(a_transform_node, c_transform_node->Parent());
2344 2344
2345 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->GetLayoutObject(), 2345 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->GetLayoutObject(),
2346 frame_view->GetLayoutView()); 2346 frame_view->GetLayoutView());
2347 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 20), b->GetLayoutObject(), 2347 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 20), b->GetLayoutObject(),
2348 frame_view->GetLayoutView()); 2348 frame_view->GetLayoutView());
2349 CHECK_EXACT_VISUAL_RECT(LayoutRect(110, 132, 10, 20), c->GetLayoutObject(), 2349 CHECK_EXACT_VISUAL_RECT(LayoutRect(110, 132, 10, 20), c->GetLayoutObject(),
2350 frame_view->GetLayoutView()); 2350 frame_view->GetLayoutView());
2351 2351
2352 // Re-add transform to b. B's transform node should be inserted into the tree, 2352 // Re-add transform to b. B's transform node should be inserted into the tree,
2353 // and a and c's transform nodes should be unchanged (with c's parent 2353 // and a and c's transform nodes should be unchanged (with c's parent
2354 // adjusted). 2354 // adjusted).
2355 b->setAttribute(HTMLNames::styleAttr, "transform: translate(4px, 5px)"); 2355 b->setAttribute(HTMLNames::styleAttr, "transform: translate(4px, 5px)");
2356 GetDocument().View()->UpdateAllLifecyclePhases(); 2356 GetDocument().View()->UpdateAllLifecyclePhases();
2357 2357
2358 EXPECT_EQ(a_properties, a->GetLayoutObject()->PaintProperties()); 2358 EXPECT_EQ(a_properties, a->GetLayoutObject()->PaintProperties());
2359 EXPECT_EQ(a_transform_node, a_properties->Transform()); 2359 EXPECT_EQ(a_transform_node, a_properties->Transform());
2360 2360
2361 b_properties = b->GetLayoutObject()->PaintProperties();
2361 EXPECT_EQ(b_properties, b->GetLayoutObject()->PaintProperties()); 2362 EXPECT_EQ(b_properties, b->GetLayoutObject()->PaintProperties());
2362 b_transform_node = b_properties->Transform(); 2363 b_transform_node = b_properties->Transform();
2363 EXPECT_EQ(TransformationMatrix().Translate(4, 5), b_transform_node->Matrix()); 2364 EXPECT_EQ(TransformationMatrix().Translate(4, 5), b_transform_node->Matrix());
2364 EXPECT_EQ(a_transform_node, b_transform_node->Parent()); 2365 EXPECT_EQ(a_transform_node, b_transform_node->Parent());
2365 2366
2366 EXPECT_EQ(c_properties, c->GetLayoutObject()->PaintProperties()); 2367 EXPECT_EQ(c_properties, c->GetLayoutObject()->PaintProperties());
2367 EXPECT_EQ(c_transform_node, c_properties->Transform()); 2368 EXPECT_EQ(c_transform_node, c_properties->Transform());
2368 EXPECT_EQ(b_transform_node, c_transform_node->Parent()); 2369 EXPECT_EQ(b_transform_node, c_transform_node->Parent());
2369 2370
2370 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->GetLayoutObject(), 2371 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->GetLayoutObject(),
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
3460 3461
3461 LayoutObject& svg_root = 3462 LayoutObject& svg_root =
3462 *GetDocument().GetElementById("svgroot")->GetLayoutObject(); 3463 *GetDocument().GetElementById("svgroot")->GetLayoutObject();
3463 const ObjectPaintProperties* svg_root_properties = svg_root.PaintProperties(); 3464 const ObjectPaintProperties* svg_root_properties = svg_root.PaintProperties();
3464 EXPECT_TRUE(svg_root_properties->Effect()); 3465 EXPECT_TRUE(svg_root_properties->Effect());
3465 EXPECT_EQ(EffectPaintPropertyNode::Root(), 3466 EXPECT_EQ(EffectPaintPropertyNode::Root(),
3466 svg_root_properties->Effect()->Parent()); 3467 svg_root_properties->Effect()->Parent());
3467 } 3468 }
3468 3469
3469 } // namespace blink 3470 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698