| 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 2962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3184 | 3184 |
| 3185 LayoutBoxModelObject* clipper = toLayoutBoxModelObject( | 3185 LayoutBoxModelObject* clipper = toLayoutBoxModelObject( |
| 3186 document().getElementById("clipper")->layoutObject()); | 3186 document().getElementById("clipper")->layoutObject()); |
| 3187 const ObjectPaintProperties* clipProperties = clipper->paintProperties(); | 3187 const ObjectPaintProperties* clipProperties = clipper->paintProperties(); |
| 3188 | 3188 |
| 3189 EXPECT_EQ(LayoutPoint(FloatPoint(31.5, 20)), clipper->paintOffset()); | 3189 EXPECT_EQ(LayoutPoint(FloatPoint(31.5, 20)), clipper->paintOffset()); |
| 3190 EXPECT_EQ(FloatRect(31.5, 20, 400, 300), | 3190 EXPECT_EQ(FloatRect(31.5, 20, 400, 300), |
| 3191 clipProperties->overflowClip()->clipRect().rect()); | 3191 clipProperties->overflowClip()->clipRect().rect()); |
| 3192 } | 3192 } |
| 3193 | 3193 |
| 3194 TEST_P(PaintPropertyTreeBuilderTest, MaskSimple) { |
| 3195 setBodyInnerHTML( |
| 3196 "<div id='target' style='width:300px; height:200px; " |
| 3197 "-webkit-mask:linear-gradient(red,red)'>" |
| 3198 " Lorem ipsum" |
| 3199 "</div>"); |
| 3200 |
| 3201 const ObjectPaintProperties* properties = paintPropertiesForElement("target"); |
| 3202 const ClipPaintPropertyNode* outputClip = properties->maskClip(); |
| 3203 |
| 3204 EXPECT_EQ(outputClip, properties->localBorderBoxProperties()->clip()); |
| 3205 EXPECT_EQ(frameContentClip(), outputClip->parent()); |
| 3206 EXPECT_EQ(FloatRoundedRect(8, 8, 300, 200), outputClip->clipRect()); |
| 3207 |
| 3208 EXPECT_EQ(properties->effect(), |
| 3209 properties->localBorderBoxProperties()->effect()); |
| 3210 EXPECT_TRUE(properties->effect()->parent()->isRoot()); |
| 3211 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode()); |
| 3212 EXPECT_EQ(outputClip, properties->effect()->outputClip()); |
| 3213 |
| 3214 EXPECT_EQ(properties->effect(), properties->mask()->parent()); |
| 3215 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode()); |
| 3216 EXPECT_EQ(outputClip, properties->mask()->outputClip()); |
| 3217 } |
| 3218 |
| 3219 TEST_P(PaintPropertyTreeBuilderTest, MaskEscapeClip) { |
| 3220 // This test verifies an abs-pos element still escape the scroll of a |
| 3221 // static-pos ancestor, but gets clipped due to the presence of a mask. |
| 3222 setBodyInnerHTML( |
| 3223 "<div style='width:300px; height:200px; overflow:scroll;'>" |
| 3224 " <div id='target' style='width:200px; height:300px; " |
| 3225 "-webkit-mask:linear-gradient(red,red); border:10px dashed black; " |
| 3226 "overflow:hidden;'>" |
| 3227 " <div id='absolute' style='position:absolute; left:0; top:0;'>Lorem " |
| 3228 "ipsum</div>" |
| 3229 " </div>" |
| 3230 "</div>"); |
| 3231 |
| 3232 const ObjectPaintProperties* properties = paintPropertiesForElement("target"); |
| 3233 const ClipPaintPropertyNode* overflowClip1 = properties->maskClip()->parent(); |
| 3234 const ClipPaintPropertyNode* maskClip = properties->maskClip(); |
| 3235 const ClipPaintPropertyNode* overflowClip2 = properties->overflowClip(); |
| 3236 const TransformPaintPropertyNode* scrollTranslation = |
| 3237 properties->localBorderBoxProperties()->transform(); |
| 3238 |
| 3239 EXPECT_EQ(frameContentClip(), overflowClip1->parent()); |
| 3240 EXPECT_EQ(FloatRoundedRect(8, 8, 300, 200), overflowClip1->clipRect()); |
| 3241 EXPECT_EQ(framePreTranslation(), overflowClip1->localTransformSpace()); |
| 3242 |
| 3243 EXPECT_EQ(maskClip, properties->localBorderBoxProperties()->clip()); |
| 3244 EXPECT_EQ(overflowClip1, maskClip->parent()); |
| 3245 EXPECT_EQ(FloatRoundedRect(8, 8, 220, 320), maskClip->clipRect()); |
| 3246 EXPECT_EQ(scrollTranslation, maskClip->localTransformSpace()); |
| 3247 |
| 3248 EXPECT_EQ(maskClip, overflowClip2->parent()); |
| 3249 EXPECT_EQ(FloatRoundedRect(18, 18, 200, 300), overflowClip2->clipRect()); |
| 3250 EXPECT_EQ(scrollTranslation, overflowClip2->localTransformSpace()); |
| 3251 |
| 3252 EXPECT_EQ(properties->effect(), |
| 3253 properties->localBorderBoxProperties()->effect()); |
| 3254 EXPECT_TRUE(properties->effect()->parent()->isRoot()); |
| 3255 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode()); |
| 3256 EXPECT_EQ(maskClip, properties->effect()->outputClip()); |
| 3257 |
| 3258 EXPECT_EQ(properties->effect(), properties->mask()->parent()); |
| 3259 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode()); |
| 3260 EXPECT_EQ(maskClip, properties->mask()->outputClip()); |
| 3261 |
| 3262 const ObjectPaintProperties* properties2 = |
| 3263 paintPropertiesForElement("absolute"); |
| 3264 EXPECT_EQ(framePreTranslation(), |
| 3265 properties2->localBorderBoxProperties()->transform()); |
| 3266 EXPECT_EQ(maskClip, properties2->localBorderBoxProperties()->clip()); |
| 3267 } |
| 3268 |
| 3269 TEST_P(PaintPropertyTreeBuilderTest, MaskInline) { |
| 3270 loadAhem(); |
| 3271 // This test verifies CSS mask applied on an inline element is clipped to |
| 3272 // the line box of the said element. In this test the masked element has |
| 3273 // only one box, and one of the child element overflows the box. |
| 3274 setBodyInnerHTML( |
| 3275 "<style>* { font-family:Ahem; font-size:16px; }</style>" |
| 3276 "Lorem" |
| 3277 "<span id='target' style='-webkit-mask:linear-gradient(red,red);'>" |
| 3278 " ipsum" |
| 3279 " <span id='overflowing' style='position:relative; font-size:32px;'>" |
| 3280 " dolor" |
| 3281 " </span>" |
| 3282 " sit amet," |
| 3283 "</span>"); |
| 3284 |
| 3285 const ObjectPaintProperties* properties = paintPropertiesForElement("target"); |
| 3286 const ClipPaintPropertyNode* outputClip = properties->maskClip(); |
| 3287 |
| 3288 EXPECT_EQ(outputClip, properties->localBorderBoxProperties()->clip()); |
| 3289 EXPECT_EQ(frameContentClip(), outputClip->parent()); |
| 3290 EXPECT_EQ(FloatRoundedRect(88, 21, 448, 16), outputClip->clipRect()); |
| 3291 |
| 3292 EXPECT_EQ(properties->effect(), |
| 3293 properties->localBorderBoxProperties()->effect()); |
| 3294 EXPECT_TRUE(properties->effect()->parent()->isRoot()); |
| 3295 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode()); |
| 3296 EXPECT_EQ(outputClip, properties->effect()->outputClip()); |
| 3297 |
| 3298 EXPECT_EQ(properties->effect(), properties->mask()->parent()); |
| 3299 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode()); |
| 3300 EXPECT_EQ(outputClip, properties->mask()->outputClip()); |
| 3301 |
| 3302 const ObjectPaintProperties* properties2 = |
| 3303 paintPropertiesForElement("overflowing"); |
| 3304 EXPECT_EQ(outputClip, properties2->localBorderBoxProperties()->clip()); |
| 3305 EXPECT_EQ(properties->effect(), |
| 3306 properties2->localBorderBoxProperties()->effect()); |
| 3307 } |
| 3308 |
| 3194 } // namespace blink | 3309 } // namespace blink |
| OLD | NEW |