| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/svg/LayoutSVGRoot.h" | 5 #include "core/layout/svg/LayoutSVGRoot.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
| 8 #include "core/layout/svg/LayoutSVGShape.h" | 8 #include "core/layout/svg/LayoutSVGShape.h" |
| 9 #include "core/layout/svg/SVGLayoutSupport.h" | 9 #include "core/layout/svg/SVGLayoutSupport.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 using LayoutSVGRootTest = RenderingTest; | 14 using LayoutSVGRootTest = RenderingTest; |
| 15 | 15 |
| 16 TEST_F(LayoutSVGRootTest, OverflowRectMappingWithoutViewportClipWithBorder) { | 16 TEST_F(LayoutSVGRootTest, VisualRectMappingWithoutViewportClipWithBorder) { |
| 17 setBodyInnerHTML( | 17 setBodyInnerHTML( |
| 18 "<svg id='root' style='border: 10px solid red; width: 200px; height: " | 18 "<svg id='root' style='border: 10px solid red; width: 200px; height: " |
| 19 "100px; overflow: visible' viewBox='0 0 200 100'>" | 19 "100px; overflow: visible' viewBox='0 0 200 100'>" |
| 20 " <rect id='rect' x='80' y='80' width='100' height='100'/>" | 20 " <rect id='rect' x='80' y='80' width='100' height='100'/>" |
| 21 "</svg>"); | 21 "</svg>"); |
| 22 | 22 |
| 23 const LayoutSVGRoot* root = | 23 const LayoutSVGRoot& root = |
| 24 toLayoutSVGRoot(getLayoutObjectByElementId("root")); | 24 *toLayoutSVGRoot(getLayoutObjectByElementId("root")); |
| 25 const LayoutSVGShape* svgRect = | 25 const LayoutSVGShape& svgRect = |
| 26 toLayoutSVGShape(getLayoutObjectByElementId("rect")); | 26 *toLayoutSVGShape(getLayoutObjectByElementId("rect")); |
| 27 | 27 |
| 28 LayoutRect rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation( | 28 LayoutRect rect = SVGLayoutSupport::visualRectInAncestorSpace(svgRect, root); |
| 29 *svgRect, *root); | |
| 30 // (80, 80, 100, 100) added by root's content rect offset from border rect, | 29 // (80, 80, 100, 100) added by root's content rect offset from border rect, |
| 31 // not clipped. | 30 // not clipped. |
| 32 EXPECT_EQ(LayoutRect(90, 90, 100, 100), rect); | 31 EXPECT_EQ(LayoutRect(90, 90, 100, 100), rect); |
| 33 | 32 |
| 34 LayoutRect rootOverflowRect = static_cast<const LayoutObject*>(root) | 33 LayoutRect rootVisualRect = |
| 35 ->localOverflowRectForPaintInvalidation(); | 34 static_cast<const LayoutObject&>(root).localVisualRect(); |
| 36 // SVG root's overflow includes overflow from descendants. | 35 // SVG root's overflow includes overflow from descendants. |
| 37 EXPECT_EQ(LayoutRect(0, 0, 220, 190), rootOverflowRect); | 36 EXPECT_EQ(LayoutRect(0, 0, 220, 190), rootVisualRect); |
| 38 | 37 |
| 39 rect = rootOverflowRect; | 38 rect = rootVisualRect; |
| 40 EXPECT_TRUE(root->mapToVisualRectInAncestorSpace(root, rect)); | 39 EXPECT_TRUE(root.mapToVisualRectInAncestorSpace(&root, rect)); |
| 41 EXPECT_EQ(LayoutRect(0, 0, 220, 190), rect); | 40 EXPECT_EQ(LayoutRect(0, 0, 220, 190), rect); |
| 42 } | 41 } |
| 43 | 42 |
| 44 TEST_F(LayoutSVGRootTest, OverflowRectMappingWithViewportClipAndBorder) { | 43 TEST_F(LayoutSVGRootTest, VisualRectMappingWithViewportClipAndBorder) { |
| 45 setBodyInnerHTML( | 44 setBodyInnerHTML( |
| 46 "<svg id='root' style='border: 10px solid red; width: 200px; height: " | 45 "<svg id='root' style='border: 10px solid red; width: 200px; height: " |
| 47 "100px; overflow: hidden' viewBox='0 0 200 100'>" | 46 "100px; overflow: hidden' viewBox='0 0 200 100'>" |
| 48 " <rect id='rect' x='80' y='80' width='100' height='100'/>" | 47 " <rect id='rect' x='80' y='80' width='100' height='100'/>" |
| 49 "</svg>"); | 48 "</svg>"); |
| 50 | 49 |
| 51 const LayoutSVGRoot* root = | 50 const LayoutSVGRoot& root = |
| 52 toLayoutSVGRoot(getLayoutObjectByElementId("root")); | 51 *toLayoutSVGRoot(getLayoutObjectByElementId("root")); |
| 53 const LayoutSVGShape* svgRect = | 52 const LayoutSVGShape& svgRect = |
| 54 toLayoutSVGShape(getLayoutObjectByElementId("rect")); | 53 *toLayoutSVGShape(getLayoutObjectByElementId("rect")); |
| 55 | 54 |
| 56 LayoutRect rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation( | 55 LayoutRect rect = SVGLayoutSupport::visualRectInAncestorSpace(svgRect, root); |
| 57 *svgRect, *root); | |
| 58 // (80, 80, 100, 100) added by root's content rect offset from border rect, | 56 // (80, 80, 100, 100) added by root's content rect offset from border rect, |
| 59 // clipped by (10, 10, 200, 100). | 57 // clipped by (10, 10, 200, 100). |
| 60 EXPECT_EQ(LayoutRect(90, 90, 100, 20), rect); | 58 EXPECT_EQ(LayoutRect(90, 90, 100, 20), rect); |
| 61 | 59 |
| 62 LayoutRect rootOverflowRect = static_cast<const LayoutObject*>(root) | 60 LayoutRect rootVisualRect = |
| 63 ->localOverflowRectForPaintInvalidation(); | 61 static_cast<const LayoutObject&>(root).localVisualRect(); |
| 64 // SVG root with overflow:hidden doesn't include overflow from children, just | 62 // SVG root with overflow:hidden doesn't include overflow from children, just |
| 65 // border box rect. | 63 // border box rect. |
| 66 EXPECT_EQ(LayoutRect(0, 0, 220, 120), rootOverflowRect); | 64 EXPECT_EQ(LayoutRect(0, 0, 220, 120), rootVisualRect); |
| 67 | 65 |
| 68 rect = rootOverflowRect; | 66 rect = rootVisualRect; |
| 69 EXPECT_TRUE(root->mapToVisualRectInAncestorSpace(root, rect)); | 67 EXPECT_TRUE(root.mapToVisualRectInAncestorSpace(&root, rect)); |
| 70 // LayoutSVGRoot should not apply overflow clip on its own rect. | 68 // LayoutSVGRoot should not apply overflow clip on its own rect. |
| 71 EXPECT_EQ(LayoutRect(0, 0, 220, 120), rect); | 69 EXPECT_EQ(LayoutRect(0, 0, 220, 120), rect); |
| 72 } | 70 } |
| 73 | 71 |
| 74 TEST_F(LayoutSVGRootTest, OverflowRectMappingWithViewportClipWithoutBorder) { | 72 TEST_F(LayoutSVGRootTest, VisualRectMappingWithViewportClipWithoutBorder) { |
| 75 setBodyInnerHTML( | 73 setBodyInnerHTML( |
| 76 "<svg id='root' style='width: 200px; height: 100px; overflow: hidden' " | 74 "<svg id='root' style='width: 200px; height: 100px; overflow: hidden' " |
| 77 "viewBox='0 0 200 100'>" | 75 "viewBox='0 0 200 100'>" |
| 78 " <rect id='rect' x='80' y='80' width='100' height='100'/>" | 76 " <rect id='rect' x='80' y='80' width='100' height='100'/>" |
| 79 "</svg>"); | 77 "</svg>"); |
| 80 | 78 |
| 81 const LayoutSVGRoot* root = | 79 const LayoutSVGRoot& root = |
| 82 toLayoutSVGRoot(getLayoutObjectByElementId("root")); | 80 *toLayoutSVGRoot(getLayoutObjectByElementId("root")); |
| 83 const LayoutSVGShape* svgRect = | 81 const LayoutSVGShape& svgRect = |
| 84 toLayoutSVGShape(getLayoutObjectByElementId("rect")); | 82 *toLayoutSVGShape(getLayoutObjectByElementId("rect")); |
| 85 | 83 |
| 86 LayoutRect rect = SVGLayoutSupport::clippedOverflowRectForPaintInvalidation( | 84 LayoutRect rect = SVGLayoutSupport::visualRectInAncestorSpace(svgRect, root); |
| 87 *svgRect, *root); | |
| 88 // (80, 80, 100, 100) clipped by (0, 0, 200, 100). | 85 // (80, 80, 100, 100) clipped by (0, 0, 200, 100). |
| 89 EXPECT_EQ(LayoutRect(80, 80, 100, 20), rect); | 86 EXPECT_EQ(LayoutRect(80, 80, 100, 20), rect); |
| 90 | 87 |
| 91 LayoutRect rootOverflowRect = static_cast<const LayoutObject*>(root) | 88 LayoutRect rootVisualRect = |
| 92 ->localOverflowRectForPaintInvalidation(); | 89 static_cast<const LayoutObject&>(root).localVisualRect(); |
| 93 // SVG root doesn't have box decoration background, so just use clipped | 90 // SVG root doesn't have box decoration background, so just use clipped |
| 94 // overflow of children. | 91 // overflow of children. |
| 95 EXPECT_EQ(LayoutRect(80, 80, 100, 20), rootOverflowRect); | 92 EXPECT_EQ(LayoutRect(80, 80, 100, 20), rootVisualRect); |
| 96 | 93 |
| 97 rect = rootOverflowRect; | 94 rect = rootVisualRect; |
| 98 EXPECT_TRUE(root->mapToVisualRectInAncestorSpace(root, rect)); | 95 EXPECT_TRUE(root.mapToVisualRectInAncestorSpace(&root, rect)); |
| 99 EXPECT_EQ(LayoutRect(80, 80, 100, 20), rect); | 96 EXPECT_EQ(LayoutRect(80, 80, 100, 20), rect); |
| 100 } | 97 } |
| 101 | 98 |
| 102 } // namespace blink | 99 } // namespace blink |
| OLD | NEW |