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

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

Issue 2137173002: [SPv2] Respect transform-style in the Blink and cc property trees. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix perspective Created 4 years, 5 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/api/LayoutViewItem.h" 7 #include "core/layout/api/LayoutViewItem.h"
8 #include "core/paint/ObjectPaintProperties.h" 8 #include "core/paint/ObjectPaintProperties.h"
9 #include "platform/graphics/paint/GeometryMapper.h" 9 #include "platform/graphics/paint/GeometryMapper.h"
10 #include "platform/graphics/paint/TransformPaintPropertyNode.h" 10 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 EXPECT_EQ(nullptr, svgWithTransformProperties->svgLocalToBorderBoxTransform( )); 1100 EXPECT_EQ(nullptr, svgWithTransformProperties->svgLocalToBorderBoxTransform( ));
1101 1101
1102 LayoutObject& rectWithTransform = *document().getElementById("rect")->layout Object(); 1102 LayoutObject& rectWithTransform = *document().getElementById("rect")->layout Object();
1103 ObjectPaintProperties* rectWithTransformProperties = rectWithTransform.objec tPaintProperties(); 1103 ObjectPaintProperties* rectWithTransformProperties = rectWithTransform.objec tPaintProperties();
1104 EXPECT_EQ(TransformationMatrix().translate(1, 1), rectWithTransformPropertie s->transform()->matrix()); 1104 EXPECT_EQ(TransformationMatrix().translate(1, 1), rectWithTransformPropertie s->transform()->matrix());
1105 1105
1106 // Ensure there is no PaintOffset transform between the rect and the svg's t ransform. 1106 // Ensure there is no PaintOffset transform between the rect and the svg's t ransform.
1107 EXPECT_EQ(svgWithTransformProperties->transform(), rectWithTransformProperti es->transform()->parent()); 1107 EXPECT_EQ(svgWithTransformProperties->transform(), rectWithTransformProperti es->transform()->parent());
1108 } 1108 }
1109 1109
1110 TEST_F(PaintPropertyTreeBuilderTest, NoRenderingContextByDefault)
1111 {
1112 setBodyInnerHTML("<div style=\"transform: translateZ(0)\"></div>");
1113
1114 ObjectPaintProperties* properties = document().body()->firstChild()->layoutO bject()->objectPaintProperties();
1115 ASSERT_TRUE(properties->transform());
1116 EXPECT_FALSE(properties->transform()->hasRenderingContext());
1117 }
1118
1119 TEST_F(PaintPropertyTreeBuilderTest, Preserve3DCreatesSharedRenderingContext)
1120 {
1121 setBodyInnerHTML(
1122 "<div style=\"transform-style: preserve-3d\">"
1123 " <div id=\"a\" style=\"transform: translateZ(0)\"></div>"
1124 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>"
1125 "</div>");
1126
1127 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO bject()->objectPaintProperties();
1128 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO bject()->objectPaintProperties();
1129 ASSERT_TRUE(aProperties->transform() && bProperties->transform());
1130 EXPECT_NE(aProperties->transform(), bProperties->transform());
1131 EXPECT_TRUE(aProperties->transform()->hasRenderingContext());
1132 EXPECT_TRUE(bProperties->transform()->hasRenderingContext());
1133 EXPECT_EQ(aProperties->transform()->renderingContextRoot(), bProperties->tra nsform()->renderingContextRoot());
1134 }
1135
1136 TEST_F(PaintPropertyTreeBuilderTest, FlatTransformStyleEndsRenderingContext)
1137 {
1138 setBodyInnerHTML(
1139 "<div style=\"transform-style: preserve-3d\">"
1140 " <div id=\"a\" style=\"transform: translateZ(0)\">"
1141 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>"
1142 " </div>"
1143 "</div>");
1144
1145 ASSERT_FALSE(document().getElementById("a")->layoutObject()->styleRef().pres erves3D());
1146 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO bject()->objectPaintProperties();
1147 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO bject()->objectPaintProperties();
1148 ASSERT_TRUE(aProperties->transform() && bProperties->transform());
1149
1150 // #a should participate in a rendering context (due to its parent), but its
1151 // child #b should not.
1152 EXPECT_TRUE(aProperties->transform()->hasRenderingContext());
1153 EXPECT_FALSE(bProperties->transform()->hasRenderingContext());
1154 }
1155
1156 TEST_F(PaintPropertyTreeBuilderTest, NestedRenderingContexts)
1157 {
1158 setBodyInnerHTML(
1159 "<div style=\"transform-style: preserve-3d\">"
1160 " <div id=\"a\" style=\"transform: translateZ(0)\">"
1161 " <div style=\"transform-style: preserve-3d\">"
1162 " <div id=\"b\" style=\"transform: translateZ(0)\">"
1163 " </div>"
1164 " </div>"
1165 "</div>");
1166
1167 ASSERT_FALSE(document().getElementById("a")->layoutObject()->styleRef().pres erves3D());
1168 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO bject()->objectPaintProperties();
1169 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO bject()->objectPaintProperties();
1170 ASSERT_TRUE(aProperties->transform() && bProperties->transform());
1171
1172 // #a should participate in a rendering context (due to its parent). Its
1173 // child does preserve 3D, but since #a does not, #a's rendering context is
1174 // not passed on to its children. Thus #b ends up in a separate rendering
1175 // context rooted at its parent.
1176 EXPECT_TRUE(aProperties->transform()->hasRenderingContext());
1177 EXPECT_TRUE(bProperties->transform()->hasRenderingContext());
1178 EXPECT_NE(aProperties->transform()->renderingContextRoot(), bProperties->tra nsform()->renderingContextRoot());
1179 }
1180
1181 TEST_F(PaintPropertyTreeBuilderTest, FlatTransformStylePropagatesToTransformNode )
1182 {
1183 setBodyInnerHTML("<div style=\"transform: translateZ(0)\"></div>");
1184
1185 ObjectPaintProperties* properties = document().body()->firstChild()->layoutO bject()->objectPaintProperties();
1186 ASSERT_TRUE(properties->transform());
1187 EXPECT_TRUE(properties->transform()->flattensTransform());
1188 }
1189
1190 TEST_F(PaintPropertyTreeBuilderTest, Preserve3DTransformStylePropagatesToTransfo rmNode)
1191 {
1192 setBodyInnerHTML("<div style=\"transform: translateZ(0); transform-style: pr eserve-3d\"></div>");
1193
1194 ObjectPaintProperties* properties = document().body()->firstChild()->layoutO bject()->objectPaintProperties();
1195 ASSERT_TRUE(properties->transform());
1196 EXPECT_TRUE(properties->transform()->preserves3D());
1197 }
1198
1199 TEST_F(PaintPropertyTreeBuilderTest, PerspectiveIsNotFlattened)
1200 {
1201 // It's necessary to make nodes from the one that applies perspective to
1202 // ones that combine with it preserve 3D. Otherwise, the perspective doesn't
1203 // do anything.
1204 setBodyInnerHTML(
1205 "<div id=\"a\" style=\"perspective: 800px\">"
1206 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>"
1207 "</div>");
1208
1209 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO bject()->objectPaintProperties();
1210 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO bject()->objectPaintProperties();
1211 const TransformPaintPropertyNode* aPerspective = aProperties->perspective();
1212 ASSERT_TRUE(aPerspective);
1213 EXPECT_FALSE(aPerspective->flattensTransform());
1214 const TransformPaintPropertyNode* bTransform = bProperties->transform();
1215 ASSERT_TRUE(bTransform);
1216 EXPECT_TRUE(bTransform->flattensTransform());
1217 for (const auto* node = bTransform->parent(); node != aPerspective; node = n ode->parent()) {
1218 ASSERT_TRUE(node);
1219 EXPECT_FALSE(node->flattensTransform());
1220 }
1221 }
1222
1223 TEST_F(PaintPropertyTreeBuilderTest, PerspectiveDoesNotEstablishRenderingContext )
1224 {
1225 // It's necessary to make nodes from the one that applies perspective to
1226 // ones that combine with it preserve 3D. Otherwise, the perspective doesn't
1227 // do anything.
1228 setBodyInnerHTML(
1229 "<div id=\"a\" style=\"perspective: 800px\">"
1230 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>"
1231 "</div>");
1232
1233 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO bject()->objectPaintProperties();
1234 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO bject()->objectPaintProperties();
1235 const TransformPaintPropertyNode* aPerspective = aProperties->perspective();
1236 ASSERT_TRUE(aPerspective);
1237 EXPECT_FALSE(aPerspective->hasRenderingContext());
1238 const TransformPaintPropertyNode* bTransform = bProperties->transform();
1239 ASSERT_TRUE(bTransform);
1240 EXPECT_FALSE(bTransform->hasRenderingContext());
1241 }
1242
1110 } // namespace blink 1243 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698