Diff
Modified: trunk/LayoutTests/ChangeLog (231152 => 231153)
--- trunk/LayoutTests/ChangeLog 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/LayoutTests/ChangeLog 2018-04-29 17:30:35 UTC (rev 231153)
@@ -1,3 +1,14 @@
+2018-04-28 Simon Fraser <[email protected]>
+
+ Fix color-filter to apply to SVG colors
+ https://bugs.webkit.org/show_bug.cgi?id=185113
+ rdar://problem/39665082
+
+ Reviewed by Dean Jackson.
+
+ * css3/color-filters/svg/color-filter-inline-svg-expected.html: Added.
+ * css3/color-filters/svg/color-filter-inline-svg.html: Added.
+
2018-04-27 Ryan Haddad <[email protected]>
Unreviewed test gardening for iOS and macOS.
Added: trunk/LayoutTests/css3/color-filters/svg/color-filter-inline-svg-expected.html (0 => 231153)
--- trunk/LayoutTests/css3/color-filters/svg/color-filter-inline-svg-expected.html (rev 0)
+++ trunk/LayoutTests/css3/color-filters/svg/color-filter-inline-svg-expected.html 2018-04-29 17:30:35 UTC (rev 231153)
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>CSS Test: color-filter reference</title>
+ <link rel="author" title="Apple" href=""
+
+ <style>
+ body {
+ margin: 0;
+ }
+ </style>
+ </head>
+<body>
+
+<svg viewBox="0 0 800 600" style="width: 800px; height: 600px">
+ <defs>
+ <radialGradient id="grad">
+ <stop offset="0" stop-color="cyan" />
+ <stop offset="0.5" stop-color="green" />
+ <stop offset="0.75" stop-color="blue" />
+ </radialGradient>
+
+ <filter id="flood" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
+ <feFlood flood-color="green" />
+ </filter>
+
+ <filter id="diffuse-light" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
+ <feDiffuseLighting lighting-color="green">
+ <feDistantLight azimuth="100" elevation="100"/>
+ </feDiffuseLighting>
+ </filter>
+
+ <filter id="specular-light" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
+ <feSpecularLighting surfaceScale="2" specularExponent="2" specularConstant="2" lighting-color="green">
+ <fePointLight x="20" y="20" z="2"/>
+ </feSpecularLighting>
+ </filter>
+
+ <filter id="shadow" x="0" y="0" width="160%" height="160%">
+ <feDropShadow dx="50" dy="50" stdDeviation="0" flood-color="green" flood-opacity="1" />
+ </filter>
+
+ <pattern id="pattern" patternUnits="userSpaceOnUse" x="20" y="0" width="50" height="50">
+ <rect x="5" y="5" width="30" height="30" fill="green"/>
+ </pattern>
+ </defs>
+
+ <rect x="20" y="10" width="150" height="150" fill="url(#grad)" />
+
+ <rect x="200" y="10" width="150" height="150" fill="green" />
+ <rect x="400" y="10" width="150" height="150" fill="green" stroke="blue" stroke-width="15" />
+
+ <rect x="20" y="200" width="150" height="150" filter="url(#flood)"/>
+ <rect x="200" y="200" width="150" height="150" filter="url(#diffuse-light)"/>
+ <rect x="400" y="200" width="150" height="150" filter="url(#specular-light)"/>
+
+ <rect x="20" y="400" width="150" height="150" fill="url(#pattern)"/>
+
+ <rect x="200" y="400" width="100" height="100" fill="blue" filter="url(#shadow)"/>
+</svg>
+
+</body>
+</html>
Added: trunk/LayoutTests/css3/color-filters/svg/color-filter-inline-svg.html (0 => 231153)
--- trunk/LayoutTests/css3/color-filters/svg/color-filter-inline-svg.html (rev 0)
+++ trunk/LayoutTests/css3/color-filters/svg/color-filter-inline-svg.html 2018-04-29 17:30:35 UTC (rev 231153)
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html >
+ <head>
+ <title>CSS Test: color-filter affects colors in inline SVG</title>
+ <link rel="author" title="Apple" href=""
+ <link rel="match" href=""
+
+ <meta name="assert" content="color-filter affects colors in inline SVG">
+ <style>
+ html {
+ color-filter: invert();
+ }
+
+ body {
+ margin: 0;
+ }
+ </style>
+ </head>
+<body>
+
+<svg viewBox="0 0 800 600" style="width: 800px; height: 600px">
+ <defs>
+ <radialGradient id="grad">
+ <stop offset="0" stop-color="red" />
+ <stop offset="0.5" stop-color="rgb(255, 128, 255)" />
+ <stop offset="0.75" stop-color="yellow" />
+ </radialGradient>
+
+ <filter id="flood" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
+ <feFlood flood-color="rgb(255, 128, 255)" />
+ </filter>
+
+ <filter id="diffuse-light" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
+ <feDiffuseLighting lighting-color="rgb(255, 128, 255)">
+ <feDistantLight azimuth="100" elevation="100"/>
+ </feDiffuseLighting>
+ </filter>
+
+ <filter id="specular-light" filterUnits="objectBoundingBox" x="0" y="0" width="100%" height="100%">
+ <feSpecularLighting surfaceScale="2" specularExponent="2" specularConstant="2" lighting-color="rgb(255, 128, 255)">
+ <fePointLight x="20" y="20" z="2"/>
+ </feSpecularLighting>
+ </filter>
+
+ <filter id="shadow" x="0" y="0" width="160%" height="160%">
+ <feDropShadow dx="50" dy="50" stdDeviation="0" flood-color="rgb(255, 128, 255)" flood-opacity="1" />
+ </filter>
+
+ <pattern id="pattern" patternUnits="userSpaceOnUse" x="20" y="0" width="50" height="50">
+ <rect x="5" y="5" width="30" height="30" fill="rgb(255, 128, 255)"/>
+ </pattern>
+ </defs>
+
+ <rect x="20" y="10" width="150" height="150" fill="url(#grad)" />
+
+ <rect x="200" y="10" width="150" height="150" fill="rgb(255, 128, 255)" />
+ <rect x="400" y="10" width="150" height="150" fill="rgb(255, 128, 255)" stroke="yellow" stroke-width="15" />
+
+ <rect x="20" y="200" width="150" height="150" filter="url(#flood)"/>
+ <rect x="200" y="200" width="150" height="150" filter="url(#diffuse-light)"/>
+ <rect x="400" y="200" width="150" height="150" filter="url(#specular-light)"/>
+
+ <rect x="20" y="400" width="150" height="150" fill="url(#pattern)"/>
+
+ <rect x="200" y="400" width="100" height="100" fill="yellow" filter="url(#shadow)"/>
+</svg>
+
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (231152 => 231153)
--- trunk/Source/WebCore/ChangeLog 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/ChangeLog 2018-04-29 17:30:35 UTC (rev 231153)
@@ -1,3 +1,39 @@
+2018-04-28 Simon Fraser <[email protected]>
+
+ Fix color-filter to apply to SVG colors
+ https://bugs.webkit.org/show_bug.cgi?id=185113
+ rdar://problem/39665082
+
+ Reviewed by Dean Jackson.
+
+ Convert SVG colors through color-filter operations for the places in SVG
+ that use color, namely fill and stroke, gradients, lighting colors and
+ drop-shadow.
+
+ Test: css3/color-filters/svg/color-filter-inline-svg.html
+
+ * rendering/svg/RenderSVGResourceGradient.cpp:
+ (WebCore::RenderSVGResourceGradient::applyResource):
+ * rendering/svg/RenderSVGResourceGradient.h:
+ * rendering/svg/RenderSVGResourceLinearGradient.cpp:
+ (WebCore::RenderSVGResourceLinearGradient::buildGradient const):
+ * rendering/svg/RenderSVGResourceLinearGradient.h:
+ * rendering/svg/RenderSVGResourceRadialGradient.cpp:
+ (WebCore::RenderSVGResourceRadialGradient::buildGradient const):
+ * rendering/svg/RenderSVGResourceRadialGradient.h:
+ * rendering/svg/RenderSVGResourceSolidColor.cpp:
+ (WebCore::RenderSVGResourceSolidColor::applyResource):
+ * svg/SVGFEDiffuseLightingElement.cpp:
+ (WebCore::SVGFEDiffuseLightingElement::setFilterEffectAttribute):
+ (WebCore::SVGFEDiffuseLightingElement::build):
+ * svg/SVGFEDropShadowElement.cpp:
+ (WebCore::SVGFEDropShadowElement::build):
+ * svg/SVGFEFloodElement.cpp:
+ (WebCore::SVGFEFloodElement::build):
+ * svg/SVGFESpecularLightingElement.cpp:
+ (WebCore::SVGFESpecularLightingElement::setFilterEffectAttribute):
+ (WebCore::SVGFESpecularLightingElement::build):
+
2018-04-29 Michael Catanzaro <[email protected]>
[CMake] Require GCC 6
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -125,7 +125,7 @@
// Create gradient object
if (!gradientData->gradient) {
- buildGradient(gradientData.get());
+ buildGradient(gradientData.get(), style);
// CG platforms will handle the gradient space transform for text after applying the
// resource, so don't apply it here. For non-CG platforms, we want the text bounding
@@ -232,13 +232,14 @@
context->restore();
}
-void RenderSVGResourceGradient::addStops(GradientData* gradientData, const Vector<Gradient::ColorStop>& stops) const
+void RenderSVGResourceGradient::addStops(GradientData* gradientData, const Vector<Gradient::ColorStop>& stops, const RenderStyle& style) const
{
ASSERT(gradientData->gradient);
- const Vector<Gradient::ColorStop>::const_iterator end = stops.end();
- for (Vector<Gradient::ColorStop>::const_iterator it = stops.begin(); it != end; ++it)
- gradientData->gradient->addColorStop(*it);
+ for (Gradient::ColorStop stop : stops) {
+ stop.color = style.colorByApplyingColorFilter(stop.color);
+ gradientData->gradient->addColorStop(stop);
+ }
}
GradientSpreadMethod RenderSVGResourceGradient::platformSpreadMethodFromSVGType(SVGSpreadMethodType method) const
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceGradient.h 2018-04-29 17:30:35 UTC (rev 231153)
@@ -56,12 +56,12 @@
void element() const = delete;
- void addStops(GradientData*, const Vector<Gradient::ColorStop>&) const;
+ void addStops(GradientData*, const Vector<Gradient::ColorStop>&, const RenderStyle&) const;
virtual SVGUnitTypes::SVGUnitType gradientUnits() const = 0;
virtual void calculateGradientTransform(AffineTransform&) = 0;
virtual bool collectGradientAttributes() = 0;
- virtual void buildGradient(GradientData*) const = 0;
+ virtual void buildGradient(GradientData*, const RenderStyle&) const = 0;
GradientSpreadMethod platformSpreadMethodFromSVGType(SVGSpreadMethodType) const;
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -50,11 +50,11 @@
return SVGLengthContext::resolvePoint(&linearGradientElement(), attributes.gradientUnits(), attributes.x2(), attributes.y2());
}
-void RenderSVGResourceLinearGradient::buildGradient(GradientData* gradientData) const
+void RenderSVGResourceLinearGradient::buildGradient(GradientData* gradientData, const RenderStyle& style) const
{
gradientData->gradient = Gradient::create(Gradient::LinearData { startPoint(m_attributes), endPoint(m_attributes) });
gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
- addStops(gradientData, m_attributes.stops());
+ addStops(gradientData, m_attributes.stops(), style);
}
}
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.h (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.h 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceLinearGradient.h 2018-04-29 17:30:35 UTC (rev 231153)
@@ -39,7 +39,7 @@
SVGUnitTypes::SVGUnitType gradientUnits() const override { return m_attributes.gradientUnits(); }
void calculateGradientTransform(AffineTransform& transform) override { transform = m_attributes.gradientTransform(); }
bool collectGradientAttributes() override;
- void buildGradient(GradientData*) const override;
+ void buildGradient(GradientData*, const RenderStyle&) const override;
FloatPoint startPoint(const LinearGradientAttributes&) const;
FloatPoint endPoint(const LinearGradientAttributes&) const;
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -61,12 +61,12 @@
return SVGLengthContext::resolveLength(&radialGradientElement(), attributes.gradientUnits(), attributes.fr());
}
-void RenderSVGResourceRadialGradient::buildGradient(GradientData* gradientData) const
+void RenderSVGResourceRadialGradient::buildGradient(GradientData* gradientData, const RenderStyle& style) const
{
gradientData->gradient = Gradient::create(Gradient::RadialData { this->focalPoint(m_attributes), this->centerPoint(m_attributes), this->focalRadius(m_attributes), this->radius(m_attributes), 1 });
gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod()));
- addStops(gradientData, m_attributes.stops());
+ addStops(gradientData, m_attributes.stops(), style);
}
}
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.h (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.h 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceRadialGradient.h 2018-04-29 17:30:35 UTC (rev 231153)
@@ -40,7 +40,7 @@
SVGUnitTypes::SVGUnitType gradientUnits() const override { return m_attributes.gradientUnits(); }
void calculateGradientTransform(AffineTransform& transform) override { transform = m_attributes.gradientTransform(); }
- void buildGradient(GradientData*) const override;
+ void buildGradient(GradientData*, const RenderStyle&) const override;
FloatPoint centerPoint(const RadialGradientAttributes&) const;
FloatPoint focalPoint(const RadialGradientAttributes&) const;
Modified: trunk/Source/WebCore/rendering/svg/RenderSVGResourceSolidColor.cpp (231152 => 231153)
--- trunk/Source/WebCore/rendering/svg/RenderSVGResourceSolidColor.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGResourceSolidColor.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -46,7 +46,7 @@
context->setAlpha(svgStyle.fillOpacity());
else
context->setAlpha(1);
- context->setFillColor(m_color);
+ context->setFillColor(style.colorByApplyingColorFilter(m_color));
if (!isRenderingMask)
context->setFillRule(svgStyle.fillRule());
@@ -56,7 +56,7 @@
// When rendering the mask for a RenderSVGResourceClipper, the stroke code path is never hit.
ASSERT(!isRenderingMask);
context->setAlpha(svgStyle.strokeOpacity());
- context->setStrokeColor(m_color);
+ context->setStrokeColor(style.colorByApplyingColorFilter(m_color));
SVGRenderSupport::applyStrokeStyleToContext(context, style, renderer);
Modified: trunk/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp (231152 => 231153)
--- trunk/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/svg/SVGFEDiffuseLightingElement.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -111,7 +111,8 @@
if (attrName == SVGNames::lighting_colorAttr) {
RenderObject* renderer = this->renderer();
ASSERT(renderer);
- return diffuseLighting->setLightingColor(renderer->style().svgStyle().lightingColor());
+ Color color = renderer->style().colorByApplyingColorFilter(renderer->style().svgStyle().lightingColor());
+ return diffuseLighting->setLightingColor(color);
}
if (attrName == SVGNames::surfaceScaleAttr)
return diffuseLighting->setSurfaceScale(surfaceScale());
@@ -190,7 +191,7 @@
if (!renderer)
return nullptr;
- const Color& color = renderer->style().svgStyle().lightingColor();
+ Color color = renderer->style().colorByApplyingColorFilter(renderer->style().svgStyle().lightingColor());
RefPtr<FilterEffect> effect = FEDiffuseLighting::create(filter, color, surfaceScale(), diffuseConstant(), kernelUnitLengthX(), kernelUnitLengthY(), WTFMove(lightSource));
effect->inputEffects().append(input1);
Modified: trunk/Source/WebCore/svg/SVGFEDropShadowElement.cpp (231152 => 231153)
--- trunk/Source/WebCore/svg/SVGFEDropShadowElement.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/svg/SVGFEDropShadowElement.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -133,7 +133,7 @@
const SVGRenderStyle& svgStyle = renderer->style().svgStyle();
- const Color& color = svgStyle.floodColor();
+ Color color = renderer->style().colorByApplyingColorFilter(svgStyle.floodColor());
float opacity = svgStyle.floodOpacity();
auto input1 = filterBuilder->getEffectById(in1());
Modified: trunk/Source/WebCore/svg/SVGFEFloodElement.cpp (231152 => 231153)
--- trunk/Source/WebCore/svg/SVGFEFloodElement.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/svg/SVGFEFloodElement.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -66,7 +66,7 @@
const SVGRenderStyle& svgStyle = renderer->style().svgStyle();
- const Color& color = svgStyle.floodColor();
+ Color color = renderer->style().colorByApplyingColorFilter(svgStyle.floodColor());
float opacity = svgStyle.floodOpacity();
return FEFlood::create(filter, color, opacity);
Modified: trunk/Source/WebCore/svg/SVGFESpecularLightingElement.cpp (231152 => 231153)
--- trunk/Source/WebCore/svg/SVGFESpecularLightingElement.cpp 2018-04-29 17:29:56 UTC (rev 231152)
+++ trunk/Source/WebCore/svg/SVGFESpecularLightingElement.cpp 2018-04-29 17:30:35 UTC (rev 231153)
@@ -120,7 +120,8 @@
if (attrName == SVGNames::lighting_colorAttr) {
RenderObject* renderer = this->renderer();
ASSERT(renderer);
- return specularLighting->setLightingColor(renderer->style().svgStyle().lightingColor());
+ Color color = renderer->style().colorByApplyingColorFilter(renderer->style().svgStyle().lightingColor());
+ return specularLighting->setLightingColor(color);
}
if (attrName == SVGNames::surfaceScaleAttr)
return specularLighting->setSurfaceScale(surfaceScale());
@@ -201,7 +202,7 @@
if (!renderer)
return nullptr;
- const Color& color = renderer->style().svgStyle().lightingColor();
+ Color color = renderer->style().colorByApplyingColorFilter(renderer->style().svgStyle().lightingColor());
RefPtr<FilterEffect> effect = FESpecularLighting::create(filter, color, surfaceScale(), specularConstant(), specularExponent(), kernelUnitLengthX(), kernelUnitLengthY(), WTFMove(lightSource));
effect->inputEffects().append(input1);