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

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

Issue 2641173008: [SPv2] Add CSS mask support (Closed)
Patch Set: update layout test expectation && add unit tests Created 3 years, 10 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/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 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after
2973 EXPECT_TRUE( 2973 EXPECT_TRUE(
2974 getLayoutObjectByElementId("absolute")->container()->isLayoutBlock()); 2974 getLayoutObjectByElementId("absolute")->container()->isLayoutBlock());
2975 } 2975 }
2976 2976
2977 TEST_P(PaintPropertyTreeBuilderTest, SimpleFilter) { 2977 TEST_P(PaintPropertyTreeBuilderTest, SimpleFilter) {
2978 setBodyInnerHTML( 2978 setBodyInnerHTML(
2979 "<div id='filter' style='filter:opacity(0.5); height:1000px;'>" 2979 "<div id='filter' style='filter:opacity(0.5); height:1000px;'>"
2980 "</div>"); 2980 "</div>");
2981 const ObjectPaintProperties* filterProperties = 2981 const ObjectPaintProperties* filterProperties =
2982 getLayoutObjectByElementId("filter")->paintProperties(); 2982 getLayoutObjectByElementId("filter")->paintProperties();
2983 EXPECT_TRUE(filterProperties->effect()->parent()->isRoot()); 2983 EXPECT_TRUE(filterProperties->filter()->parent()->isRoot());
2984 EXPECT_EQ(frameScrollTranslation(), 2984 EXPECT_EQ(frameScrollTranslation(),
2985 filterProperties->effect()->localTransformSpace()); 2985 filterProperties->filter()->localTransformSpace());
2986 EXPECT_EQ(frameContentClip(), filterProperties->effect()->outputClip()); 2986 EXPECT_EQ(frameContentClip(), filterProperties->filter()->outputClip());
2987 } 2987 }
2988 2988
2989 TEST_P(PaintPropertyTreeBuilderTest, FilterReparentClips) { 2989 TEST_P(PaintPropertyTreeBuilderTest, FilterReparentClips) {
2990 setBodyInnerHTML( 2990 setBodyInnerHTML(
2991 "<div id='clip' style='overflow:hidden;'>" 2991 "<div id='clip' style='overflow:hidden;'>"
2992 " <div id='filter' style='filter:opacity(0.5); height:1000px;'>" 2992 " <div id='filter' style='filter:opacity(0.5); height:1000px;'>"
2993 " <div id='child' style='position:fixed;'></div>" 2993 " <div id='child' style='position:fixed;'></div>"
2994 " </div>" 2994 " </div>"
2995 "</div>"); 2995 "</div>");
2996 const ObjectPaintProperties* clipProperties = 2996 const ObjectPaintProperties* clipProperties =
2997 getLayoutObjectByElementId("clip")->paintProperties(); 2997 getLayoutObjectByElementId("clip")->paintProperties();
2998 const ObjectPaintProperties* filterProperties = 2998 const ObjectPaintProperties* filterProperties =
2999 getLayoutObjectByElementId("filter")->paintProperties(); 2999 getLayoutObjectByElementId("filter")->paintProperties();
3000 EXPECT_TRUE(filterProperties->effect()->parent()->isRoot()); 3000 EXPECT_TRUE(filterProperties->filter()->parent()->isRoot());
3001 EXPECT_EQ(frameScrollTranslation(), 3001 EXPECT_EQ(frameScrollTranslation(),
3002 filterProperties->effect()->localTransformSpace()); 3002 filterProperties->filter()->localTransformSpace());
3003 EXPECT_EQ(clipProperties->overflowClip(), 3003 EXPECT_EQ(clipProperties->overflowClip(),
3004 filterProperties->effect()->outputClip()); 3004 filterProperties->filter()->outputClip());
3005 3005
3006 const PropertyTreeState& childPaintState = 3006 const PropertyTreeState& childPaintState =
3007 *getLayoutObjectByElementId("child") 3007 *getLayoutObjectByElementId("child")
3008 ->paintProperties() 3008 ->paintProperties()
3009 ->localBorderBoxProperties(); 3009 ->localBorderBoxProperties();
3010 3010
3011 // This will change once we added clip expansion node. 3011 // This will change once we added clip expansion node.
3012 EXPECT_EQ(filterProperties->effect()->outputClip(), childPaintState.clip()); 3012 EXPECT_EQ(filterProperties->filter()->outputClip(), childPaintState.clip());
3013 EXPECT_EQ(filterProperties->effect(), childPaintState.effect()); 3013 EXPECT_EQ(filterProperties->filter(), childPaintState.effect());
3014 } 3014 }
3015 3015
3016 TEST_P(PaintPropertyTreeBuilderTest, TransformOriginWithAndWithoutTransform) { 3016 TEST_P(PaintPropertyTreeBuilderTest, TransformOriginWithAndWithoutTransform) {
3017 setBodyInnerHTML( 3017 setBodyInnerHTML(
3018 "<style>" 3018 "<style>"
3019 " body { margin: 0 }" 3019 " body { margin: 0 }"
3020 " div {" 3020 " div {"
3021 " width: 400px;" 3021 " width: 400px;"
3022 " height: 100px;" 3022 " height: 100px;"
3023 " }" 3023 " }"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3167 setBodyInnerHTML( 3167 setBodyInnerHTML(
3168 "<div id='target' style='overflow: auto; width: 100px; height: 100px'>" 3168 "<div id='target' style='overflow: auto; width: 100px; height: 100px'>"
3169 " <div style='width: 200px; height: 200px'></div>" 3169 " <div style='width: 200px; height: 200px'></div>"
3170 "</div>"); 3170 "</div>");
3171 3171
3172 const ObjectPaintProperties* properties = paintPropertiesForElement("target"); 3172 const ObjectPaintProperties* properties = paintPropertiesForElement("target");
3173 EXPECT_NE(CompositorElementId(), 3173 EXPECT_NE(CompositorElementId(),
3174 properties->scrollTranslation()->compositorElementId()); 3174 properties->scrollTranslation()->compositorElementId());
3175 } 3175 }
3176 3176
3177 TEST_P(PaintPropertyTreeBuilderTest, MaskSimple) {
3178 setBodyInnerHTML(
3179 "<div id='target' style='width:300px; height:200px; "
3180 "-webkit-mask:linear-gradient(red,red)'>"
3181 " Lorem ipsum"
3182 "</div>");
3183
3184 const ObjectPaintProperties* properties = paintPropertiesForElement("target");
3185 const ClipPaintPropertyNode* outputClip = properties->maskClip();
3186
3187 EXPECT_EQ(outputClip, properties->localBorderBoxProperties()->clip());
3188 EXPECT_EQ(frameContentClip(), outputClip->parent());
3189 EXPECT_EQ(FloatRoundedRect(8, 8, 300, 200), outputClip->clipRect());
3190
3191 EXPECT_EQ(properties->effect(),
3192 properties->localBorderBoxProperties()->effect());
3193 EXPECT_TRUE(properties->effect()->parent()->isRoot());
3194 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode());
3195 EXPECT_EQ(outputClip, properties->effect()->outputClip());
3196
3197 EXPECT_EQ(properties->effect(), properties->mask()->parent());
3198 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode());
3199 EXPECT_EQ(outputClip, properties->mask()->outputClip());
3200 }
3201
3202 TEST_P(PaintPropertyTreeBuilderTest, MaskUnescapeClip) {
chrishtr 2017/02/13 23:23:49 MaskEscapeClip?
trchen 2017/02/14 01:37:30 Done. Actually this test is not very good. I chang
3203 // This test verifies an abs-pos element still escape the scroll of a
3204 // static-pos ancestor, but gets clipped due to the presence of a mask.
3205 setBodyInnerHTML(
3206 "<div id='target' style='width:300px; height:200px; overflow:scroll; "
3207 "-webkit-mask:linear-gradient(red,red)'>"
3208 " <div id='normal' style='position:relative; height:1000px;'>Lorem "
3209 "ipsum</div>"
3210 " <div id='absolute' style='position:absolute; left:0; top:0;'>Lorem "
3211 "ipsum</div>"
3212 "</div>");
3213
3214 const ObjectPaintProperties* properties = paintPropertiesForElement("target");
3215 const ClipPaintPropertyNode* outputClip = properties->maskClip();
3216
3217 EXPECT_EQ(framePreTranslation(),
3218 properties->localBorderBoxProperties()->transform());
3219
3220 EXPECT_EQ(outputClip, properties->localBorderBoxProperties()->clip());
3221 EXPECT_EQ(frameContentClip(), outputClip->parent());
3222 EXPECT_EQ(FloatRoundedRect(8, 8, 300, 200), outputClip->clipRect());
3223
3224 EXPECT_EQ(properties->effect(),
3225 properties->localBorderBoxProperties()->effect());
3226 EXPECT_TRUE(properties->effect()->parent()->isRoot());
3227 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode());
3228 EXPECT_EQ(outputClip, properties->effect()->outputClip());
3229
3230 EXPECT_EQ(properties->effect(), properties->mask()->parent());
3231 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode());
3232 EXPECT_EQ(outputClip, properties->mask()->outputClip());
3233
3234 const ObjectPaintProperties* properties2 =
3235 paintPropertiesForElement("normal");
3236 EXPECT_EQ(properties->scrollTranslation(),
3237 properties2->localBorderBoxProperties()->transform());
3238 EXPECT_EQ(properties->overflowClip(),
3239 properties2->localBorderBoxProperties()->clip());
3240
3241 const ObjectPaintProperties* properties3 =
3242 paintPropertiesForElement("absolute");
3243 EXPECT_EQ(framePreTranslation(),
3244 properties3->localBorderBoxProperties()->transform());
3245 EXPECT_EQ(outputClip, properties3->localBorderBoxProperties()->clip());
3246 }
3247
3248 TEST_P(PaintPropertyTreeBuilderTest, MaskInline) {
3249 // This test verifies CSS mask applied on an inline element is clipped to
3250 // the line box of the said element. In this test the masked element has
3251 // only one box, and one of the child element overflows the box.
3252 setBodyInnerHTML(
3253 "<span style='display:inline-block; width:50px;'></span>"
3254 "<span id='target' style='-webkit-mask:linear-gradient(red,red); "
3255 "font-size:16px;'>"
3256 " <span style='display:inline-block; width:50px;'></span>"
3257 " <span id='overflowing' style='position:relative; font-size:32px;'>"
3258 " <span style='display:inline-block; width:50px;'></span>"
3259 " </span>"
3260 " <span style='display:inline-block; width:50px;'></span>"
3261 "</span>");
3262
3263 const ObjectPaintProperties* properties = paintPropertiesForElement("target");
3264 const ClipPaintPropertyNode* outputClip = properties->maskClip();
3265
3266 EXPECT_EQ(outputClip, properties->localBorderBoxProperties()->clip());
3267 EXPECT_EQ(frameContentClip(), outputClip->parent());
3268 EXPECT_EQ(FloatRoundedRect(58, 23, 170, 19), outputClip->clipRect());
3269
3270 EXPECT_EQ(properties->effect(),
3271 properties->localBorderBoxProperties()->effect());
3272 EXPECT_TRUE(properties->effect()->parent()->isRoot());
3273 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode());
3274 EXPECT_EQ(outputClip, properties->effect()->outputClip());
3275
3276 EXPECT_EQ(properties->effect(), properties->mask()->parent());
3277 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode());
3278 EXPECT_EQ(outputClip, properties->mask()->outputClip());
3279
3280 const ObjectPaintProperties* properties2 =
3281 paintPropertiesForElement("overflowing");
3282 EXPECT_EQ(outputClip, properties2->localBorderBoxProperties()->clip());
3283 EXPECT_EQ(properties->effect(),
3284 properties2->localBorderBoxProperties()->effect());
3285 }
3286
3177 } // namespace blink 3287 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698