| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 RenderingTest::SetUp(); | 68 RenderingTest::SetUp(); |
| 69 enableCompositing(); | 69 enableCompositing(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void PaintPropertyTreeBuilderTest::TearDown() { | 72 void PaintPropertyTreeBuilderTest::TearDown() { |
| 73 RenderingTest::TearDown(); | 73 RenderingTest::TearDown(); |
| 74 | 74 |
| 75 Settings::setMockScrollbarsEnabled(false); | 75 Settings::setMockScrollbarsEnabled(false); |
| 76 } | 76 } |
| 77 | 77 |
| 78 #define CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, \ | 78 #define CHECK_VISUAL_RECT(expected, sourceObject, ancestorObject, slopFactor) \ |
| 79 slopFactor) \ | 79 do { \ |
| 80 do { \ | 80 if ((sourceObject)->hasLayer() && (ancestorObject)->hasLayer()) { \ |
| 81 std::unique_ptr<GeometryMapper> geometryMapper = GeometryMapper::create(); \ | 81 auto geometryMapper = GeometryMapper::create(); \ |
| 82 LayoutRect source((sourceLayoutObject)->localVisualRect()); \ | 82 LayoutRect source((sourceObject)->localVisualRect()); \ |
| 83 source.moveBy((sourceLayoutObject)->paintOffset()); \ | 83 source.moveBy((sourceObject)->paintOffset()); \ |
| 84 const auto& contentsProperties = \ | 84 const auto& contentsProperties = \ |
| 85 *(ancestorLayoutObject)->paintProperties()->contentsProperties(); \ | 85 *(ancestorObject)->paintProperties()->contentsProperties(); \ |
| 86 FloatRect actualFloatRect(source); \ | 86 FloatRect actualFloatRect(source); \ |
| 87 geometryMapper->sourceToDestinationVisualRect( \ | 87 geometryMapper->sourceToDestinationVisualRect( \ |
| 88 *(sourceLayoutObject)->paintProperties()->localBorderBoxProperties(), \ | 88 *(sourceObject)->paintProperties()->localBorderBoxProperties(), \ |
| 89 contentsProperties, actualFloatRect); \ | 89 contentsProperties, actualFloatRect); \ |
| 90 LayoutRect actual(actualFloatRect); \ | 90 LayoutRect actual(actualFloatRect); \ |
| 91 actual.moveBy(-(ancestorLayoutObject)->paintOffset()); \ | 91 actual.moveBy(-(ancestorObject)->paintOffset()); \ |
| 92 EXPECT_EQ(expected, actual) \ | 92 SCOPED_TRACE("GeometryMapper: "); \ |
| 93 << "GeometryMapper: expected: " << expected.toString() \ | 93 EXPECT_EQ(expected, actual); \ |
| 94 << ", actual: " << actual.toString(); \ | 94 } \ |
| 95 \ | 95 \ |
| 96 if (slopFactor == LayoutUnit::max()) \ | 96 if (slopFactor == LayoutUnit::max()) \ |
| 97 break; \ | 97 break; \ |
| 98 LayoutRect slowPathRect = (sourceLayoutObject)->localVisualRect(); \ | 98 LayoutRect slowPathRect = (sourceObject)->localVisualRect(); \ |
| 99 (sourceLayoutObject) \ | 99 (sourceObject) \ |
| 100 ->mapToVisualRectInAncestorSpace(ancestorLayoutObject, slowPathRect); \ | 100 ->mapToVisualRectInAncestorSpace(ancestorObject, slowPathRect); \ |
| 101 if (slopFactor) { \ | 101 if (slopFactor) { \ |
| 102 LayoutRect inflatedActual = LayoutRect(actual); \ | 102 LayoutRect inflatedExpected = LayoutRect(expected); \ |
| 103 inflatedActual.inflate(slopFactor); \ | 103 inflatedExpected.inflate(slopFactor); \ |
| 104 SCOPED_TRACE( \ | 104 SCOPED_TRACE(String::format( \ |
| 105 String::format("Old path rect: %s, Actual: %s, Inflated actual: %s", \ | 105 "Old path rect: %s, Expected: %s, Inflated expected: %s", \ |
| 106 slowPathRect.toString().ascii().data(), \ | 106 slowPathRect.toString().ascii().data(), \ |
| 107 actual.toString().ascii().data(), \ | 107 expected.toString().ascii().data(), \ |
| 108 inflatedActual.toString().ascii().data())); \ | 108 inflatedExpected.toString().ascii().data())); \ |
| 109 EXPECT_TRUE(slowPathRect.contains(LayoutRect(actual))); \ | 109 EXPECT_TRUE(slowPathRect.contains(LayoutRect(expected))); \ |
| 110 EXPECT_TRUE(inflatedActual.contains(slowPathRect)); \ | 110 EXPECT_TRUE(inflatedExpected.contains(slowPathRect)); \ |
| 111 } else { \ | 111 } else { \ |
| 112 EXPECT_EQ(expected, slowPathRect) \ | 112 SCOPED_TRACE("Slow path: "); \ |
| 113 << "Slow path: expected: " << slowPathRect.toString() \ | 113 EXPECT_EQ(expected, slowPathRect); \ |
| 114 << ", actual: " << actual.toString().ascii().data(); \ | 114 } \ |
| 115 } \ | |
| 116 } while (0) | 115 } while (0) |
| 117 | 116 |
| 118 #define CHECK_EXACT_VISUAL_RECT(expected, sourceLayoutObject, \ | 117 #define CHECK_EXACT_VISUAL_RECT(expected, sourceObject, ancestorObject) \ |
| 119 ancestorLayoutObject) \ | 118 CHECK_VISUAL_RECT(expected, sourceObject, ancestorObject, 0) |
| 120 CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, 0) | |
| 121 | 119 |
| 122 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool()); | 120 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool()); |
| 123 | 121 |
| 124 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition) { | 122 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition) { |
| 125 loadTestData("fixed-position.html"); | 123 loadTestData("fixed-position.html"); |
| 126 | 124 |
| 127 Element* positionedScroll = document().getElementById("positionedScroll"); | 125 Element* positionedScroll = document().getElementById("positionedScroll"); |
| 128 positionedScroll->setScrollTop(3); | 126 positionedScroll->setScrollTop(3); |
| 129 Element* transformedScroll = document().getElementById("transformedScroll"); | 127 Element* transformedScroll = document().getElementById("transformedScroll"); |
| 130 transformedScroll->setScrollTop(5); | 128 transformedScroll->setScrollTop(5); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 " <div id='greatGrandChildWithOpacity'" | 525 " <div id='greatGrandChildWithOpacity'" |
| 528 " style='opacity: 0.2; width: 10px; height: 15px'></div>" | 526 " style='opacity: 0.2; width: 10px; height: 15px'></div>" |
| 529 " </div>" | 527 " </div>" |
| 530 " </div>" | 528 " </div>" |
| 531 "</div>"); | 529 "</div>"); |
| 532 | 530 |
| 533 LayoutObject* nodeWithoutOpacity = | 531 LayoutObject* nodeWithoutOpacity = |
| 534 document().getElementById("nodeWithoutOpacity")->layoutObject(); | 532 document().getElementById("nodeWithoutOpacity")->layoutObject(); |
| 535 const ObjectPaintProperties* nodeWithoutOpacityProperties = | 533 const ObjectPaintProperties* nodeWithoutOpacityProperties = |
| 536 nodeWithoutOpacity->paintProperties(); | 534 nodeWithoutOpacity->paintProperties(); |
| 537 EXPECT_NE(nullptr, nodeWithoutOpacityProperties); | 535 EXPECT_EQ(nullptr, nodeWithoutOpacityProperties); |
| 538 CHECK_EXACT_VISUAL_RECT(LayoutRect(8, 8, 100, 200), nodeWithoutOpacity, | 536 CHECK_EXACT_VISUAL_RECT(LayoutRect(8, 8, 100, 200), nodeWithoutOpacity, |
| 539 document().view()->layoutView()); | 537 document().view()->layoutView()); |
| 540 | 538 |
| 541 LayoutObject* childWithOpacity = | 539 LayoutObject* childWithOpacity = |
| 542 document().getElementById("childWithOpacity")->layoutObject(); | 540 document().getElementById("childWithOpacity")->layoutObject(); |
| 543 const ObjectPaintProperties* childWithOpacityProperties = | 541 const ObjectPaintProperties* childWithOpacityProperties = |
| 544 childWithOpacity->paintProperties(); | 542 childWithOpacity->paintProperties(); |
| 545 EXPECT_EQ(0.5f, childWithOpacityProperties->effect()->opacity()); | 543 EXPECT_EQ(0.5f, childWithOpacityProperties->effect()->opacity()); |
| 546 // childWithOpacity is the root effect node. | 544 // childWithOpacity is the root effect node. |
| 547 EXPECT_NE(nullptr, childWithOpacityProperties->effect()->parent()); | 545 EXPECT_NE(nullptr, childWithOpacityProperties->effect()->parent()); |
| 548 CHECK_EXACT_VISUAL_RECT(LayoutRect(8, 8, 50, 60), childWithOpacity, | 546 CHECK_EXACT_VISUAL_RECT(LayoutRect(8, 8, 50, 60), childWithOpacity, |
| 549 document().view()->layoutView()); | 547 document().view()->layoutView()); |
| 550 | 548 |
| 551 LayoutObject* grandChildWithoutOpacity = | 549 LayoutObject* grandChildWithoutOpacity = |
| 552 document().getElementById("grandChildWithoutOpacity")->layoutObject(); | 550 document().getElementById("grandChildWithoutOpacity")->layoutObject(); |
| 553 EXPECT_NE(nullptr, grandChildWithoutOpacity->paintProperties()); | 551 EXPECT_EQ(nullptr, grandChildWithoutOpacity->paintProperties()); |
| 554 CHECK_EXACT_VISUAL_RECT(LayoutRect(8, 8, 20, 30), grandChildWithoutOpacity, | 552 CHECK_EXACT_VISUAL_RECT(LayoutRect(8, 8, 20, 30), grandChildWithoutOpacity, |
| 555 document().view()->layoutView()); | 553 document().view()->layoutView()); |
| 556 | 554 |
| 557 LayoutObject* greatGrandChildWithOpacity = | 555 LayoutObject* greatGrandChildWithOpacity = |
| 558 document().getElementById("greatGrandChildWithOpacity")->layoutObject(); | 556 document().getElementById("greatGrandChildWithOpacity")->layoutObject(); |
| 559 const ObjectPaintProperties* greatGrandChildWithOpacityProperties = | 557 const ObjectPaintProperties* greatGrandChildWithOpacityProperties = |
| 560 greatGrandChildWithOpacity->paintProperties(); | 558 greatGrandChildWithOpacity->paintProperties(); |
| 561 EXPECT_EQ(0.2f, greatGrandChildWithOpacityProperties->effect()->opacity()); | 559 EXPECT_EQ(0.2f, greatGrandChildWithOpacityProperties->effect()->opacity()); |
| 562 EXPECT_EQ(childWithOpacityProperties->effect(), | 560 EXPECT_EQ(childWithOpacityProperties->effect(), |
| 563 greatGrandChildWithOpacityProperties->effect()->parent()); | 561 greatGrandChildWithOpacityProperties->effect()->parent()); |
| (...skipping 878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 setBodyInnerHTML( | 1440 setBodyInnerHTML( |
| 1443 "<style>" | 1441 "<style>" |
| 1444 " #clip {" | 1442 " #clip {" |
| 1445 " position: absolute;" | 1443 " position: absolute;" |
| 1446 " left: 123px;" | 1444 " left: 123px;" |
| 1447 " top: 456px;" | 1445 " top: 456px;" |
| 1448 " clip: rect(10px, 80px, 70px, 40px);" | 1446 " clip: rect(10px, 80px, 70px, 40px);" |
| 1449 " width: 100px;" | 1447 " width: 100px;" |
| 1450 " height: 100px;" | 1448 " height: 100px;" |
| 1451 " }" | 1449 " }" |
| 1452 " #abs {" | 1450 " #absolute {" |
| 1453 " position: absolute;" | 1451 " position: absolute;" |
| 1454 " left: 654px;" | 1452 " left: 654px;" |
| 1455 " top: 321px;" | 1453 " top: 321px;" |
| 1456 " width: 10px;" | 1454 " width: 10px;" |
| 1457 " heght: 20px" | 1455 " heght: 20px" |
| 1458 " }" | 1456 " }" |
| 1459 "</style>" | 1457 "</style>" |
| 1460 "<div id='clip'><div id='absolute'></div></div>"); | 1458 "<div id='clip'><div id='absolute'></div></div>"); |
| 1461 | 1459 |
| 1462 LayoutRect localClipRect(40, 10, 40, 60); | 1460 LayoutRect localClipRect(40, 10, 40, 60); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1477 // TODO(crbug.com/599939): mapToVisualRectInAncestorSpace() | 1475 // TODO(crbug.com/599939): mapToVisualRectInAncestorSpace() |
| 1478 // doesn't apply css clip on the object itself. | 1476 // doesn't apply css clip on the object itself. |
| 1479 LayoutUnit::max()); | 1477 LayoutUnit::max()); |
| 1480 | 1478 |
| 1481 auto* absolute = document().getElementById("absolute")->layoutObject(); | 1479 auto* absolute = document().getElementById("absolute")->layoutObject(); |
| 1482 const ObjectPaintProperties* absPosProperties = absolute->paintProperties(); | 1480 const ObjectPaintProperties* absPosProperties = absolute->paintProperties(); |
| 1483 EXPECT_EQ(clipProperties->cssClip(), | 1481 EXPECT_EQ(clipProperties->cssClip(), |
| 1484 absPosProperties->localBorderBoxProperties()->clip()); | 1482 absPosProperties->localBorderBoxProperties()->clip()); |
| 1485 EXPECT_EQ(framePreTranslation(), | 1483 EXPECT_EQ(framePreTranslation(), |
| 1486 absPosProperties->localBorderBoxProperties()->transform()); | 1484 absPosProperties->localBorderBoxProperties()->transform()); |
| 1487 EXPECT_EQ(LayoutPoint(123, 456), absolute->paintOffset()); | 1485 EXPECT_EQ(LayoutPoint(777, 777), absolute->paintOffset()); |
| 1488 CHECK_VISUAL_RECT(LayoutRect(), absolute, document().view()->layoutView(), | 1486 CHECK_VISUAL_RECT(LayoutRect(), absolute, document().view()->layoutView(), |
| 1489 // TODO(crbug.com/599939): CSS clip of fixed-position | 1487 // TODO(crbug.com/599939): CSS clip of fixed-position |
| 1490 // descendants is broken in | 1488 // descendants is broken in |
| 1491 // mapToVisualRectInAncestorSpace(). | 1489 // mapToVisualRectInAncestorSpace(). |
| 1492 LayoutUnit::max()); | 1490 LayoutUnit::max()); |
| 1493 } | 1491 } |
| 1494 | 1492 |
| 1495 TEST_P(PaintPropertyTreeBuilderTest, CSSClipFixedPositionDescendantNonShared) { | 1493 TEST_P(PaintPropertyTreeBuilderTest, CSSClipFixedPositionDescendantNonShared) { |
| 1496 // This test is similar to CSSClipFixedPositionDescendant above, except that | 1494 // This test is similar to CSSClipFixedPositionDescendant above, except that |
| 1497 // now we have a parent overflow clip that should be escaped by the fixed | 1495 // now we have a parent overflow clip that should be escaped by the fixed |
| (...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3135 EXPECT_TRUE(properties->effect()); | 3133 EXPECT_TRUE(properties->effect()); |
| 3136 EXPECT_NE(CompositorElementId(), properties->effect()->compositorElementId()); | 3134 EXPECT_NE(CompositorElementId(), properties->effect()->compositorElementId()); |
| 3137 EXPECT_TRUE(properties->effect()->requiresCompositingForAnimation()); | 3135 EXPECT_TRUE(properties->effect()->requiresCompositingForAnimation()); |
| 3138 } | 3136 } |
| 3139 | 3137 |
| 3140 TEST_P(PaintPropertyTreeBuilderTest, FloatUnderInline) { | 3138 TEST_P(PaintPropertyTreeBuilderTest, FloatUnderInline) { |
| 3141 setBodyInnerHTML( | 3139 setBodyInnerHTML( |
| 3142 "<div style='position: absolute; top: 55px; left: 66px'>" | 3140 "<div style='position: absolute; top: 55px; left: 66px'>" |
| 3143 " <span id='span'" | 3141 " <span id='span'" |
| 3144 " style='position: relative; top: 100px; left: 200px; opacity: 0.5'>" | 3142 " style='position: relative; top: 100px; left: 200px; opacity: 0.5'>" |
| 3145 " <div id='target' style='float: left; width: 33px; height: 44px'>" | 3143 " <div id='target'" |
| 3144 " style='overflow: hidden; float: left; width: 3px; height: 4px'>" |
| 3146 " </div>" | 3145 " </div>" |
| 3147 " </span" | 3146 " </span>" |
| 3148 "</div>"); | 3147 "</div>"); |
| 3149 | 3148 |
| 3150 LayoutObject* span = getLayoutObjectByElementId("span"); | 3149 LayoutObject* span = getLayoutObjectByElementId("span"); |
| 3151 const auto* effect = span->paintProperties()->effect(); | 3150 const auto* effect = span->paintProperties()->effect(); |
| 3152 ASSERT_TRUE(effect); | 3151 ASSERT_TRUE(effect); |
| 3153 EXPECT_EQ(0.5f, effect->opacity()); | 3152 EXPECT_EQ(0.5f, effect->opacity()); |
| 3154 | 3153 |
| 3155 LayoutObject* target = getLayoutObjectByElementId("target"); | 3154 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 3156 const auto* localBorderBoxProperties = | 3155 const auto* localBorderBoxProperties = |
| 3157 target->paintProperties()->localBorderBoxProperties(); | 3156 target->paintProperties()->localBorderBoxProperties(); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3324 Element* mask = document().getElementById("mask"); | 3323 Element* mask = document().getElementById("mask"); |
| 3325 mask->setAttribute(HTMLNames::styleAttr, "height: 200px"); | 3324 mask->setAttribute(HTMLNames::styleAttr, "height: 200px"); |
| 3326 document().view()->updateAllLifecyclePhases(); | 3325 document().view()->updateAllLifecyclePhases(); |
| 3327 | 3326 |
| 3328 ASSERT_EQ(properties, paintPropertiesForElement("mask")); | 3327 ASSERT_EQ(properties, paintPropertiesForElement("mask")); |
| 3329 ASSERT_EQ(maskClip, properties->maskClip()); | 3328 ASSERT_EQ(maskClip, properties->maskClip()); |
| 3330 EXPECT_EQ(FloatRoundedRect(8, 8, 100, 200), maskClip->clipRect()); | 3329 EXPECT_EQ(FloatRoundedRect(8, 8, 100, 200), maskClip->clipRect()); |
| 3331 } | 3330 } |
| 3332 | 3331 |
| 3333 } // namespace blink | 3332 } // namespace blink |
| OLD | NEW |