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

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

Issue 2045253005: Re-implement SVG transform paint property nodes [spv2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/layout/LayoutTestHelper.h" 5 #include "core/layout/LayoutTestHelper.h"
6 #include "core/layout/LayoutTreeAsText.h" 6 #include "core/layout/LayoutTreeAsText.h"
7 #include "core/layout/LayoutView.h" 7 #include "core/layout/LayoutView.h"
8 #include "core/paint/ObjectPaintProperties.h" 8 #include "core/paint/ObjectPaintProperties.h"
9 #include "platform/graphics/paint/TransformPaintPropertyNode.h" 9 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
10 #include "platform/testing/UnitTestHelpers.h" 10 #include "platform/testing/UnitTestHelpers.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 EXPECT_EQ(TransformationMatrix().translate(70, 25), svgRootWith3dTransformPr operties->paintOffsetTranslation()->matrix()); 410 EXPECT_EQ(TransformationMatrix().translate(70, 25), svgRootWith3dTransformPr operties->paintOffsetTranslation()->matrix());
411 EXPECT_EQ(document().view()->scrollTranslation(), svgRootWith3dTransformProp erties->paintOffsetTranslation()->parent()); 411 EXPECT_EQ(document().view()->scrollTranslation(), svgRootWith3dTransformProp erties->paintOffsetTranslation()->parent());
412 412
413 LayoutObject& rectWith2dTransform = *document().getElementById("rectWith2dTr ansform")->layoutObject(); 413 LayoutObject& rectWith2dTransform = *document().getElementById("rectWith2dTr ansform")->layoutObject();
414 ObjectPaintProperties* rectWith2dTransformProperties = rectWith2dTransform.o bjectPaintProperties(); 414 ObjectPaintProperties* rectWith2dTransformProperties = rectWith2dTransform.o bjectPaintProperties();
415 TransformationMatrix matrix; 415 TransformationMatrix matrix;
416 matrix.translate(100, 100); 416 matrix.translate(100, 100);
417 matrix.rotate(45); 417 matrix.rotate(45);
418 // SVG's transform origin is baked into the transform. 418 // SVG's transform origin is baked into the transform.
419 matrix.applyTransformOrigin(50, 25, 0); 419 matrix.applyTransformOrigin(50, 25, 0);
420 EXPECT_EQ(matrix, rectWith2dTransformProperties->svgLocalTransform()->matrix ()); 420 EXPECT_EQ(matrix, rectWith2dTransformProperties->transform()->matrix());
421 EXPECT_EQ(FloatPoint3D(0, 0, 0), rectWith2dTransformProperties->svgLocalTran sform()->origin()); 421 EXPECT_EQ(FloatPoint3D(0, 0, 0), rectWith2dTransformProperties->transform()- >origin());
422 // SVG does not use paint offset. 422 // SVG does not use paint offset.
423 EXPECT_EQ(nullptr, rectWith2dTransformProperties->paintOffsetTranslation()); 423 EXPECT_EQ(nullptr, rectWith2dTransformProperties->paintOffsetTranslation());
424 } 424 }
425 425
426 TEST_F(PaintPropertyTreeBuilderTest, SVGViewBoxTransform) 426 TEST_F(PaintPropertyTreeBuilderTest, SVGViewBoxTransform)
427 { 427 {
428 setBodyInnerHTML( 428 setBodyInnerHTML(
429 "<style>" 429 "<style>"
430 " body {" 430 " body {"
431 " margin: 0px;" 431 " margin: 0px;"
432 " }" 432 " }"
433 " svg {" 433 " svg {"
434 " transform: translate3d(1px, 2px, 3px);" 434 " transform: translate3d(1px, 2px, 3px);"
435 " position: absolute;" 435 " position: absolute;"
436 " }" 436 " }"
437 " rect {" 437 " rect {"
438 " transform: translate(100px, 100px);" 438 " transform: translate(100px, 100px);"
439 " }" 439 " }"
440 "</style>" 440 "</style>"
441 "<svg id='svgWithViewBox' width='100px' height='100px' viewBox='50 50 10 0 100'>" 441 "<svg id='svgWithViewBox' width='100px' height='100px' viewBox='50 50 10 0 100'>"
442 " <rect id='rect' width='100px' height='100px' />" 442 " <rect id='rect' width='100px' height='100px' />"
443 "</svg>"); 443 "</svg>");
444 444
445 LayoutObject& svgWithViewBox = *document().getElementById("svgWithViewBox")- >layoutObject(); 445 LayoutObject& svgWithViewBox = *document().getElementById("svgWithViewBox")- >layoutObject();
446 ObjectPaintProperties* svgWithViewBoxProperties = svgWithViewBox.objectPaint Properties(); 446 ObjectPaintProperties* svgWithViewBoxProperties = svgWithViewBox.objectPaint Properties();
447 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgWithViewBoxPropert ies->transform()->matrix()); 447 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgWithViewBoxPropert ies->transform()->matrix());
448 EXPECT_EQ(TransformationMatrix().translate(-50, -50), svgWithViewBoxProperti es->svgLocalTransform()->matrix()); 448 EXPECT_EQ(TransformationMatrix().translate(-50, -50), svgWithViewBoxProperti es->svgLocalToBorderBoxTransform()->matrix());
449 EXPECT_EQ(svgWithViewBoxProperties->svgLocalTransform()->parent(), svgWithVi ewBoxProperties->transform()); 449 EXPECT_EQ(svgWithViewBoxProperties->svgLocalToBorderBoxTransform()->parent() , svgWithViewBoxProperties->transform());
450 450
451 LayoutObject& rect = *document().getElementById("rect")->layoutObject(); 451 LayoutObject& rect = *document().getElementById("rect")->layoutObject();
452 ObjectPaintProperties* rectProperties = rect.objectPaintProperties(); 452 ObjectPaintProperties* rectProperties = rect.objectPaintProperties();
453 EXPECT_EQ(TransformationMatrix().translate(100, 100), rectProperties->svgLoc alTransform()->matrix()); 453 EXPECT_EQ(TransformationMatrix().translate(100, 100), rectProperties->transf orm()->matrix());
454 EXPECT_EQ(svgWithViewBoxProperties->svgLocalTransform(), rectProperties->svg LocalTransform()->parent()); 454 EXPECT_EQ(svgWithViewBoxProperties->svgLocalToBorderBoxTransform(), rectProp erties->transform()->parent());
455 } 455 }
456 456
457 TEST_F(PaintPropertyTreeBuilderTest, SVGRootPaintOffsetTransformNode) 457 TEST_F(PaintPropertyTreeBuilderTest, SVGRootPaintOffsetTransformNode)
458 { 458 {
459 setBodyInnerHTML( 459 setBodyInnerHTML(
460 "<style>body { margin: 0px; } </style>" 460 "<style>body { margin: 0px; } </style>"
461 "<svg id='svg' style='margin-left: 50px; margin-top: 25px; width: 100px; height: 100px;' />"); 461 "<svg id='svg' style='margin-left: 50px; margin-top: 25px; width: 100px; height: 100px;' />");
462 462
463 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); 463 LayoutObject& svg = *document().getElementById("svg")->layoutObject();
464 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); 464 ObjectPaintProperties* svgProperties = svg.objectPaintProperties();
465 // Ensure that a paint offset transform is emitted for SVG, even without a C SS transform. 465 // Ensure that a paint offset transform is not unnecessarily emitted.
466 EXPECT_EQ(nullptr, svgProperties->transform()); 466 EXPECT_EQ(nullptr, svgProperties->paintOffsetTranslation());
467 EXPECT_EQ(TransformationMatrix().translate(50, 25), svgProperties->paintOffs etTranslation()->matrix()); 467 EXPECT_EQ(TransformationMatrix().translate(50, 25), svgProperties->svgLocalT oBorderBoxTransform()->matrix());
468 EXPECT_EQ(document().view()->scrollTranslation(), svgProperties->paintOffset Translation()->parent()); 468 EXPECT_EQ(document().view()->scrollTranslation(), svgProperties->svgLocalToB orderBoxTransform()->parent());
469 }
470
471 TEST_F(PaintPropertyTreeBuilderTest, SVGRootLocalToBorderBoxTransformNode)
472 {
473 setBodyInnerHTML(
474 "<style>body { margin: 0px; } </style>"
475 "<svg id='svg' style='transform: translate(2px, 3px); margin: 5px; borde r: 7px solid green; width: 100px; height: 100px;'/>");
476
477 LayoutObject& svg = *document().getElementById("svg")->layoutObject();
478 ObjectPaintProperties* svgProperties = svg.objectPaintProperties();
479 EXPECT_EQ(TransformationMatrix().translate(5, 5), svgProperties->paintOffset Translation()->matrix());
480 EXPECT_EQ(TransformationMatrix().translate(2, 3), svgProperties->transform() ->matrix());
481 EXPECT_EQ(TransformationMatrix().translate(7, 7), svgProperties->svgLocalToB orderBoxTransform()->matrix());
482
483 EXPECT_EQ(svgProperties->paintOffsetTranslation(), svgProperties->transform( )->parent());
484 EXPECT_EQ(svgProperties->transform(), svgProperties->svgLocalToBorderBoxTran sform()->parent());
469 } 485 }
470 486
471 TEST_F(PaintPropertyTreeBuilderTest, TransformNodesAcrossSVGHTMLBoundary) 487 TEST_F(PaintPropertyTreeBuilderTest, TransformNodesAcrossSVGHTMLBoundary)
472 { 488 {
473 setBodyInnerHTML( 489 setBodyInnerHTML(
474 "<style> body { margin: 0px; } </style>" 490 "<style> body { margin: 0px; } </style>"
475 "<svg id='svgWithTransform' style='transform: translate3d(1px, 2px, 3px) ;'>" 491 "<svg id='svgWithTransform' style='transform: translate3d(1px, 2px, 3px) ;'>"
476 " <foreignObject>" 492 " <foreignObject>"
477 " <body>" 493 " <body>"
478 " <div id='divWithTransform' style='transform: translate3d(3px, 4px , 5px);'></div>" 494 " <div id='divWithTransform' style='transform: translate3d(3px, 4px , 5px);'></div>"
(...skipping 25 matching lines...) Expand all
504 " </foreignObject>" 520 " </foreignObject>"
505 " </g>" 521 " </g>"
506 "</svg>"); 522 "</svg>");
507 523
508 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); 524 LayoutObject& svg = *document().getElementById("svg")->layoutObject();
509 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); 525 ObjectPaintProperties* svgProperties = svg.objectPaintProperties();
510 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgProperties->transf orm()->matrix()); 526 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgProperties->transf orm()->matrix());
511 527
512 LayoutObject& container = *document().getElementById("container")->layoutObj ect(); 528 LayoutObject& container = *document().getElementById("container")->layoutObj ect();
513 ObjectPaintProperties* containerProperties = container.objectPaintProperties (); 529 ObjectPaintProperties* containerProperties = container.objectPaintProperties ();
514 EXPECT_EQ(TransformationMatrix().translate(20, 30), containerProperties->svg LocalTransform()->matrix()); 530 EXPECT_EQ(TransformationMatrix().translate(20, 30), containerProperties->tra nsform()->matrix());
515 EXPECT_EQ(svgProperties->transform(), containerProperties->svgLocalTransform ()->parent()); 531 EXPECT_EQ(svgProperties->transform(), containerProperties->transform()->pare nt());
516 532
517 Element* fixed = document().getElementById("fixed"); 533 Element* fixed = document().getElementById("fixed");
518 ObjectPaintProperties* fixedProperties = fixed->layoutObject()->objectPaintP roperties(); 534 ObjectPaintProperties* fixedProperties = fixed->layoutObject()->objectPaintP roperties();
519 EXPECT_EQ(TransformationMatrix().translate(200, 150), fixedProperties->paint OffsetTranslation()->matrix()); 535 EXPECT_EQ(TransformationMatrix().translate(200, 150), fixedProperties->paint OffsetTranslation()->matrix());
520 // Ensure the fixed position element is rooted at the nearest transform cont ainer. 536 // Ensure the fixed position element is rooted at the nearest transform cont ainer.
521 EXPECT_EQ(containerProperties->svgLocalTransform(), fixedProperties->paintOf fsetTranslation()->parent()); 537 EXPECT_EQ(containerProperties->transform(), fixedProperties->paintOffsetTran slation()->parent());
522 } 538 }
523 539
524 TEST_F(PaintPropertyTreeBuilderTest, ControlClip) 540 TEST_F(PaintPropertyTreeBuilderTest, ControlClip)
525 { 541 {
526 setBodyInnerHTML( 542 setBodyInnerHTML(
527 "<style>" 543 "<style>"
528 " body {" 544 " body {"
529 " margin: 0;" 545 " margin: 0;"
530 " }" 546 " }"
531 " input {" 547 " input {"
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 " <div id='spanner' style='column-span: all; opacity: 0.5; width: 100 px; height: 100px;'></div>" 875 " <div id='spanner' style='column-span: all; opacity: 0.5; width: 100 px; height: 100px;'></div>"
860 " </div>" 876 " </div>"
861 "</div>" 877 "</div>"
862 ); 878 );
863 879
864 LayoutObject& spanner = *getLayoutObjectByElementId("spanner"); 880 LayoutObject& spanner = *getLayoutObjectByElementId("spanner");
865 EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderB oxProperties()->paintOffset); 881 EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderB oxProperties()->paintOffset);
866 } 882 }
867 883
868 } // namespace blink 884 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698