| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, MaskEscapeClip) { |
| 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 style='width:300px; height:200px; overflow:scroll;'>" |
| 3207 " <div id='target' style='width:200px; height:300px; " |
| 3208 "-webkit-mask:linear-gradient(red,red); border:10px dashed black; " |
| 3209 "overflow:hidden;'>" |
| 3210 " <div id='absolute' style='position:absolute; left:0; top:0;'>Lorem " |
| 3211 "ipsum</div>" |
| 3212 " </div>" |
| 3213 "</div>"); |
| 3214 |
| 3215 const ObjectPaintProperties* properties = paintPropertiesForElement("target"); |
| 3216 const ClipPaintPropertyNode* overflowClip1 = properties->maskClip()->parent(); |
| 3217 const ClipPaintPropertyNode* maskClip = properties->maskClip(); |
| 3218 const ClipPaintPropertyNode* overflowClip2 = properties->overflowClip(); |
| 3219 const TransformPaintPropertyNode* scrollTranslation = |
| 3220 properties->localBorderBoxProperties()->transform(); |
| 3221 |
| 3222 EXPECT_EQ(frameContentClip(), overflowClip1->parent()); |
| 3223 EXPECT_EQ(FloatRoundedRect(8, 8, 300, 200), overflowClip1->clipRect()); |
| 3224 EXPECT_EQ(framePreTranslation(), overflowClip1->localTransformSpace()); |
| 3225 |
| 3226 EXPECT_EQ(maskClip, properties->localBorderBoxProperties()->clip()); |
| 3227 EXPECT_EQ(overflowClip1, maskClip->parent()); |
| 3228 EXPECT_EQ(FloatRoundedRect(8, 8, 220, 320), maskClip->clipRect()); |
| 3229 EXPECT_EQ(scrollTranslation, maskClip->localTransformSpace()); |
| 3230 |
| 3231 EXPECT_EQ(maskClip, overflowClip2->parent()); |
| 3232 EXPECT_EQ(FloatRoundedRect(18, 18, 200, 300), overflowClip2->clipRect()); |
| 3233 EXPECT_EQ(scrollTranslation, overflowClip2->localTransformSpace()); |
| 3234 |
| 3235 EXPECT_EQ(properties->effect(), |
| 3236 properties->localBorderBoxProperties()->effect()); |
| 3237 EXPECT_TRUE(properties->effect()->parent()->isRoot()); |
| 3238 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode()); |
| 3239 EXPECT_EQ(maskClip, properties->effect()->outputClip()); |
| 3240 |
| 3241 EXPECT_EQ(properties->effect(), properties->mask()->parent()); |
| 3242 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode()); |
| 3243 EXPECT_EQ(maskClip, properties->mask()->outputClip()); |
| 3244 |
| 3245 const ObjectPaintProperties* properties2 = |
| 3246 paintPropertiesForElement("absolute"); |
| 3247 EXPECT_EQ(framePreTranslation(), |
| 3248 properties2->localBorderBoxProperties()->transform()); |
| 3249 EXPECT_EQ(maskClip, properties2->localBorderBoxProperties()->clip()); |
| 3250 } |
| 3251 |
| 3252 TEST_P(PaintPropertyTreeBuilderTest, MaskInline) { |
| 3253 loadAhem(); |
| 3254 // This test verifies CSS mask applied on an inline element is clipped to |
| 3255 // the line box of the said element. In this test the masked element has |
| 3256 // only one box, and one of the child element overflows the box. |
| 3257 setBodyInnerHTML( |
| 3258 "<style>* { font-family:Ahem; font-size:16px; }</style>" |
| 3259 "Lorem" |
| 3260 "<span id='target' style='-webkit-mask:linear-gradient(red,red);'>" |
| 3261 " ipsum" |
| 3262 " <span id='overflowing' style='position:relative; font-size:32px;'>" |
| 3263 " dolor" |
| 3264 " </span>" |
| 3265 " sit amet," |
| 3266 "</span>"); |
| 3267 |
| 3268 const ObjectPaintProperties* properties = paintPropertiesForElement("target"); |
| 3269 const ClipPaintPropertyNode* outputClip = properties->maskClip(); |
| 3270 |
| 3271 EXPECT_EQ(outputClip, properties->localBorderBoxProperties()->clip()); |
| 3272 EXPECT_EQ(frameContentClip(), outputClip->parent()); |
| 3273 EXPECT_EQ(FloatRoundedRect(88, 21, 448, 16), outputClip->clipRect()); |
| 3274 |
| 3275 EXPECT_EQ(properties->effect(), |
| 3276 properties->localBorderBoxProperties()->effect()); |
| 3277 EXPECT_TRUE(properties->effect()->parent()->isRoot()); |
| 3278 EXPECT_EQ(SkBlendMode::kSrcOver, properties->effect()->blendMode()); |
| 3279 EXPECT_EQ(outputClip, properties->effect()->outputClip()); |
| 3280 |
| 3281 EXPECT_EQ(properties->effect(), properties->mask()->parent()); |
| 3282 EXPECT_EQ(SkBlendMode::kDstIn, properties->mask()->blendMode()); |
| 3283 EXPECT_EQ(outputClip, properties->mask()->outputClip()); |
| 3284 |
| 3285 const ObjectPaintProperties* properties2 = |
| 3286 paintPropertiesForElement("overflowing"); |
| 3287 EXPECT_EQ(outputClip, properties2->localBorderBoxProperties()->clip()); |
| 3288 EXPECT_EQ(properties->effect(), |
| 3289 properties2->localBorderBoxProperties()->effect()); |
| 3290 } |
| 3291 |
| 3177 } // namespace blink | 3292 } // namespace blink |
| OLD | NEW |