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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGForeignObjectTest.cpp

Issue 2778873002: Reland "Let SVGForeignObject's local SVG coordinates mean what it should" (Closed)
Patch Set: Fix 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
(Empty)
1 // Copyright 2017 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 "core/layout/LayoutGeometryMap.h"
6 #include "core/layout/LayoutTestHelper.h"
7
8 namespace blink {
9
10 class LayoutSVGForeignObjectTest : public RenderingTest {
11 public:
12 LayoutSVGForeignObjectTest()
13 : RenderingTest(SingleChildLocalFrameClient::create()) {}
14
15 const Node* hitTest(int x, int y) {
16 HitTestResult result(
17 HitTestRequest(HitTestRequest::ReadOnly | HitTestRequest::Active |
18 HitTestRequest::AllowChildFrameContent),
19 IntPoint(x, y));
20 layoutView().hitTest(result);
21 return result.innerNode();
22 }
23 };
24
25 TEST_F(LayoutSVGForeignObjectTest, DivInForeignObject) {
26 setBodyInnerHTML(
27 "<style>body { margin: 0 }</style>"
28 "<svg id='svg' style='width: 500px; height: 400px'>"
29 " <foreignObject id='foreign' x='100' y='100' width='300' height='200'>"
30 " <div id='div' style='margin: 50px; width: 200px; height: 100px'>"
31 " </div>"
32 " </foreignObject>"
33 "</svg>");
34
35 const auto& svg = *document().getElementById("svg");
36 const auto& foreignObject = *getLayoutObjectByElementId("foreign");
37 const auto& div = *getLayoutObjectByElementId("div");
38
39 EXPECT_EQ(FloatRect(100, 100, 300, 200), foreignObject.objectBoundingBox());
40 EXPECT_EQ(AffineTransform(), foreignObject.localSVGTransform());
41 EXPECT_EQ(AffineTransform(), foreignObject.localToSVGParentTransform());
42
43 // mapToVisualRectInAncestorSpace
44 LayoutRect divRect(0, 0, 100, 50);
45 EXPECT_TRUE(div.mapToVisualRectInAncestorSpace(&layoutView(), divRect));
46 EXPECT_EQ(LayoutRect(150, 150, 100, 50), divRect);
47
48 // mapLocalToAncestor
49 TransformState transformState(TransformState::ApplyTransformDirection,
50 FloatPoint());
51 div.mapLocalToAncestor(&layoutView(), transformState,
52 TraverseDocumentBoundaries);
53 transformState.flatten();
54 EXPECT_EQ(FloatPoint(150, 150), transformState.lastPlanarPoint());
55
56 // mapAncestorToLocal
57 TransformState transformState1(
58 TransformState::UnapplyInverseTransformDirection, FloatPoint());
59 div.mapAncestorToLocal(&layoutView(), transformState1,
60 TraverseDocumentBoundaries);
61 transformState1.flatten();
62 EXPECT_EQ(FloatPoint(-150, -150), transformState1.lastPlanarPoint());
63
64 // pushMappingToContainer
65 LayoutGeometryMap rgm(TraverseDocumentBoundaries);
66 rgm.pushMappingsToAncestor(&div, nullptr);
67 EXPECT_EQ(FloatQuad(FloatRect(150, 150, 1, 2)),
68 rgm.mapToAncestor(FloatRect(0, 0, 1, 2), nullptr));
69
70 // Hit testing
71 EXPECT_EQ(svg, hitTest(149, 149));
72 EXPECT_EQ(div.node(), hitTest(150, 150));
73 EXPECT_EQ(div.node(), hitTest(349, 249));
74 EXPECT_EQ(svg, hitTest(350, 250));
75 }
76
77 TEST_F(LayoutSVGForeignObjectTest, IframeInForeignObject) {
78 setBodyInnerHTML(
79 "<style>body { margin: 0 }</style>"
80 "<svg id='svg' style='width: 500px; height: 450px'>"
81 " <foreignObject id='foreign' x='100' y='100' width='300' height='250'>"
82 " <iframe style='border: none; margin: 30px;"
83 " width: 240px; height: 190px'></iframe>"
84 " </foreignObject>"
85 "</svg>");
86 setChildFrameHTML(
87 "<style>"
88 " body { margin: 0 }"
89 " * { background: white; }"
90 "</style>"
91 "<div id='div' style='margin: 70px; width: 100px; height: 50px'></div>");
92 document().view()->updateAllLifecyclePhases();
93
94 const auto& svg = *document().getElementById("svg");
95 const auto& foreignObject = *getLayoutObjectByElementId("foreign");
96 const auto& div = *childDocument().getElementById("div")->layoutObject();
97
98 EXPECT_EQ(FloatRect(100, 100, 300, 250), foreignObject.objectBoundingBox());
99 EXPECT_EQ(AffineTransform(), foreignObject.localSVGTransform());
100 EXPECT_EQ(AffineTransform(), foreignObject.localToSVGParentTransform());
101
102 // mapToVisualRectInAncestorSpace
103 LayoutRect divRect(0, 0, 100, 50);
104 EXPECT_TRUE(div.mapToVisualRectInAncestorSpace(&layoutView(), divRect));
105 EXPECT_EQ(LayoutRect(200, 200, 100, 50), divRect);
106
107 // mapLocalToAncestor
108 TransformState transformState(TransformState::ApplyTransformDirection,
109 FloatPoint());
110 div.mapLocalToAncestor(&layoutView(), transformState,
111 TraverseDocumentBoundaries);
112 transformState.flatten();
113 EXPECT_EQ(FloatPoint(200, 200), transformState.lastPlanarPoint());
114
115 // mapAncestorToLocal
116 TransformState transformState1(
117 TransformState::UnapplyInverseTransformDirection, FloatPoint());
118 div.mapAncestorToLocal(&layoutView(), transformState1,
119 TraverseDocumentBoundaries);
120 transformState1.flatten();
121 EXPECT_EQ(FloatPoint(-200, -200), transformState1.lastPlanarPoint());
122
123 // pushMappingToContainer
124 LayoutGeometryMap rgm(TraverseDocumentBoundaries);
125 rgm.pushMappingsToAncestor(&div, nullptr);
126 EXPECT_EQ(FloatQuad(FloatRect(200, 200, 1, 2)),
127 rgm.mapToAncestor(FloatRect(0, 0, 1, 2), nullptr));
128
129 // Hit testing
130 EXPECT_EQ(svg, hitTest(129, 129));
131 EXPECT_EQ(childDocument().documentElement(), hitTest(130, 130));
132 EXPECT_EQ(childDocument().documentElement(), hitTest(199, 199));
133 EXPECT_EQ(div.node(), hitTest(200, 200));
134 EXPECT_EQ(div.node(), hitTest(299, 249));
135 EXPECT_EQ(childDocument().documentElement(), hitTest(300, 250));
136 EXPECT_EQ(childDocument().documentElement(), hitTest(369, 319));
137 EXPECT_EQ(svg, hitTest(370, 320));
138 }
139
140 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698