Commit 8a5a0362 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[PE] Allow blending for svg root etc.

Bug: 872437
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Idb0d69320ddfa2dcfe02e493cd117573618459d5
Reviewed-on: https://chromium-review.googlesource.com/1169624
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582299}
parent a2ce72e4
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<body> <body>
<div>Tspan elements are graphics elements per the latest SVG spec and should blend.<div>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="30px" style="background: yellow"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="30px" style="background: yellow">
<text x="0" y="20"> <text x="0" y="20">
Tspan elements should not blend. This test passes if the last word is This test passes if the last word is
<tspan font-weight="bold" fill="green">GREEN</tspan>. <tspan font-weight="bold" fill="lime">LIME</tspan>.
</text> </text>
</svg> </svg>
</body> </body>
......
<!DOCTYPE HTML> <!DOCTYPE HTML>
<html> <html>
<body> <body>
<div>Tspan elements are graphics elements per the latest SVG spec and should blend.<div>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="30px" style="background: yellow"> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="500px" height="30px" style="background: yellow">
<text x="0" y="20"> <text x="0" y="20">
Tspan elements should not blend. This test passes if the last word is This test passes if the last word is
<tspan font-weight="bold" fill="green" style="mix-blend-mode: difference;">GREEN</tspan>. <tspan font-weight="bold" fill="red" style="mix-blend-mode: difference;">LIME</tspan>.
</text> </text>
</svg> </svg>
</body> </body>
......
<!DOCTYPE html>
<div style="background: green">
<div>Expected: a black square on green background.</div>
<svg style="height: 200px">
<foreignObject>
<div style="width: 200px; height: 200px; background: black"></div>
</foreignObject>
</svg>
</div>
<!DOCTYPE html>
<title>'mix-blend-mode' for &lt;svg:foreignObject&gt;</title>
<link rel="help" href="https://www.w3.org/TR/SVG2/render.html#PaintersModel">
<link rel="match" href="blending-svg-foreign-object-ref.html">
<div style="background: green">
<div>Expected: a black square on green background.</div>
<svg style="width: 200px; height: 200px">
<foreignObject style="mix-blend-mode: multiply">
<div style="width: 200px; height: 200px; background: red"></div>
</foreignObject>
</svg>
</div>
<!DOCTYPE html>
<div style="background: green">
<div>Expected: a black square on green background.</div>
<svg style="width: 200px; height: 200px; background: black">
</svg>
</div>
<!DOCTYPE html>
<title>'mix-blend-mode' for &lt;svg&gt;</title>
<link rel="help" href="https://www.w3.org/TR/SVG2/render.html#PaintersModel">
<link rel="match" href="blending-svg-root-ref.html">
<div style="background: green">
<div>Expected: a black square on green background.</div>
<svg style="mix-blend-mode: multiply; width: 200px; height: 200px; background: red">
</svg>
</div>
...@@ -726,9 +726,16 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver, ...@@ -726,9 +726,16 @@ class CORE_EXPORT LayoutObject : public ImageResourceObserver,
virtual void SetNeedsTransformUpdate() {} virtual void SetNeedsTransformUpdate() {}
virtual void SetNeedsBoundariesUpdate(); virtual void SetNeedsBoundariesUpdate();
// Per the spec, mix-blend-mode applies to all non-SVG elements, and SVG
// elements that are container elements, graphics elements or graphics
// referencing elements.
// https://www.w3.org/TR/compositing-1/#propdef-mix-blend-mode
bool IsBlendingAllowed() const { bool IsBlendingAllowed() const {
return !IsSVG() || (IsSVGContainer() && !IsSVGHiddenContainer()) || return !IsSVG() || IsSVGShape() || IsSVGImage() || IsSVGText() ||
IsSVGShape() || IsSVGImage() || IsSVGText(); IsSVGInline() || IsSVGRoot() || IsSVGForeignObject() ||
// TODO(pdr): According to the current spec, blending should apply to
// hidden containers (e.g. pattern).
(IsSVGContainer() && !IsSVGHiddenContainer());
} }
virtual bool HasNonIsolatedBlendingDescendants() const { virtual bool HasNonIsolatedBlendingDescendants() const {
// This is only implemented for layout objects that containt SVG flow. // This is only implemented for layout objects that containt SVG flow.
......
...@@ -4733,21 +4733,49 @@ TEST_P(PaintPropertyTreeBuilderTest, SVGHiddenResource) { ...@@ -4733,21 +4733,49 @@ TEST_P(PaintPropertyTreeBuilderTest, SVGHiddenResource) {
transform_outside_use_properties->Transform()->Parent()); transform_outside_use_properties->Transform()->Parent());
} }
TEST_P(PaintPropertyTreeBuilderTest, SVGRootBlending) { TEST_P(PaintPropertyTreeBuilderTest, SVGBlending) {
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
<svg id='svgroot' 'width=100' height='100' <svg id='svgroot' width='100' height='100'
style='position: relative; z-index: 0'> style='position: relative; z-index: 0'>
<rect width='100' height='100' fill='#00FF00' <rect id='rect' width='100' height='100' fill='#00FF00'
style='mix-blend-mode: difference'/> style='mix-blend-mode: difference'/>
</svg> </svg>
)HTML"); )HTML");
LayoutObject& svg_root = *GetLayoutObjectByElementId("svgroot"); const auto* rect_properties = PaintPropertiesForElement("rect");
const ObjectPaintProperties* svg_root_properties = ASSERT_TRUE(rect_properties->Effect());
svg_root.FirstFragment().PaintProperties(); EXPECT_EQ(SkBlendMode::kDifference, rect_properties->Effect()->BlendMode());
EXPECT_TRUE(svg_root_properties->Effect());
const auto* svg_root_properties = PaintPropertiesForElement("svgroot");
ASSERT_TRUE(svg_root_properties->Effect());
EXPECT_EQ(SkBlendMode::kSrcOver, svg_root_properties->Effect()->BlendMode());
EXPECT_EQ(&EffectPaintPropertyNode::Root(), EXPECT_EQ(&EffectPaintPropertyNode::Root(),
svg_root_properties->Effect()->Parent()); svg_root_properties->Effect()->Parent());
EXPECT_EQ(svg_root_properties->Effect(), rect_properties->Effect()->Parent());
}
TEST_P(PaintPropertyTreeBuilderTest, SVGRootBlending) {
SetBodyInnerHTML(R"HTML(
<svg id='svgroot' 'width=100' height='100' style='mix-blend-mode: multiply'>
</svg>
)HTML");
const auto* html_properties = GetDocument()
.documentElement()
->GetLayoutObject()
->FirstFragment()
.PaintProperties();
ASSERT_TRUE(html_properties->Effect());
EXPECT_EQ(SkBlendMode::kSrcOver, html_properties->Effect()->BlendMode());
const auto* svg_root_properties = PaintPropertiesForElement("svgroot");
ASSERT_TRUE(svg_root_properties->Effect());
EXPECT_EQ(SkBlendMode::kMultiply, svg_root_properties->Effect()->BlendMode());
EXPECT_EQ(&EffectPaintPropertyNode::Root(),
html_properties->Effect()->Parent());
EXPECT_EQ(html_properties->Effect(), svg_root_properties->Effect()->Parent());
} }
TEST_P(PaintPropertyTreeBuilderTest, ScrollBoundsOffset) { TEST_P(PaintPropertyTreeBuilderTest, ScrollBoundsOffset) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment