Commit 7f488e21 authored by Fredrik Söderqvist's avatar Fredrik Söderqvist Committed by Commit Bot

Reorder and simplify RequestPaint()

Reorder the function to check for a paintserver resource first and then
return any color. This structure should be more conducive to future
paintserver handling.

Change so that we don't resolve a color if there is no color value to
resolve. Also apply the same restriction to the visited paint/color,
such that only a color can "replace" a color.

Bug: 109212
Change-Id: I81a0c47b694406c931663804df6705f7bf651572
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2418372Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#808885}
parent 23c6c84c
...@@ -63,6 +63,23 @@ void SVGPaintServer::PrependTransform(const AffineTransform& transform) { ...@@ -63,6 +63,23 @@ void SVGPaintServer::PrependTransform(const AffineTransform& transform) {
transform_ = transform * transform_; transform_ = transform * transform_;
} }
static base::Optional<Color> ResolveColor(const ComputedStyle& style,
const SVGPaint& paint,
const SVGPaint& visited_paint) {
if (!paint.HasColor())
return base::nullopt;
Color color = style.ResolvedColor(paint.GetColor());
if (style.InsideLink() != EInsideLink::kInsideVisitedLink)
return color;
// FIXME: This code doesn't support the uri component of the visited link
// paint, https://bugs.webkit.org/show_bug.cgi?id=70006
if (!visited_paint.HasColor())
return color;
const Color& visited_color = style.ResolvedColor(visited_paint.GetColor());
return Color(visited_color.Red(), visited_color.Green(), visited_color.Blue(),
color.Alpha());
}
static SVGPaintDescription RequestPaint(const LayoutObject& object, static SVGPaintDescription RequestPaint(const LayoutObject& object,
const ComputedStyle& style, const ComputedStyle& style,
LayoutSVGResourceMode mode) { LayoutSVGResourceMode mode) {
...@@ -74,57 +91,32 @@ static SVGPaintDescription RequestPaint(const LayoutObject& object, ...@@ -74,57 +91,32 @@ static SVGPaintDescription RequestPaint(const LayoutObject& object,
const SVGPaint& visited_paint = apply_to_fill const SVGPaint& visited_paint = apply_to_fill
? svg_style.InternalVisitedFillPaint() ? svg_style.InternalVisitedFillPaint()
: svg_style.InternalVisitedStrokePaint(); : svg_style.InternalVisitedStrokePaint();
base::Optional<Color> color = ResolveColor(style, paint, visited_paint);
// If we have no, ignore it.
if (paint.IsNone()) if (paint.HasUrl()) {
return SVGPaintDescription(); LayoutSVGResourcePaintServer* uri_resource = nullptr;
if (SVGResources* resources =
Color color = style.ResolvedColor(paint.GetColor()); SVGResourcesCache::CachedResourcesForLayoutObject(object))
bool has_color = paint.HasColor(); uri_resource = apply_to_fill ? resources->Fill() : resources->Stroke();
if (uri_resource) {
if (style.InsideLink() == EInsideLink::kInsideVisitedLink) { // The paint server resource exists, though it may be invalid (pattern
// FIXME: This code doesn't support the uri component of the visited link // with width/height=0). Return the fallback color to our caller so it can
// paint, https://bugs.webkit.org/show_bug.cgi?id=70006 // use it, if PreparePaintServer() on the resource container failed.
if (!visited_paint.HasUrl()) { if (color)
const Color& visited_color = return SVGPaintDescription(uri_resource, *color);
style.ResolvedColor(visited_paint.GetColor()); return SVGPaintDescription(uri_resource);
color = Color(visited_color.Red(), visited_color.Green(),
visited_color.Blue(), color.Alpha());
has_color = true;
} }
// If the requested resource is not available, return the color resource or
// 'none'.
} }
// If the primary resource is just a color, return immediately. // Color or fallback color.
if (!paint.HasUrl()) { if (color)
// |paint.type| will be either <current-color> or <rgb-color> here - both of return SVGPaintDescription(*color);
// which will have a color.
DCHECK(has_color);
return SVGPaintDescription(color);
}
LayoutSVGResourcePaintServer* uri_resource = nullptr;
if (SVGResources* resources =
SVGResourcesCache::CachedResourcesForLayoutObject(object))
uri_resource = apply_to_fill ? resources->Fill() : resources->Stroke();
// If the requested resource is not available, return the color resource or
// 'none'.
if (!uri_resource) {
// The fallback is 'none'. (SVG2 say 'none' is implied when no fallback is
// specified.)
if (!paint.HasFallbackColor() || !has_color)
return SVGPaintDescription();
return SVGPaintDescription(color);
}
// The paint server resource exists, though it may be invalid (pattern with
// width/height=0). Return the fallback color to our caller so it can use it,
// if preparePaintServer() on the resource container failed.
if (has_color)
return SVGPaintDescription(uri_resource, color);
return SVGPaintDescription(uri_resource); // Either 'none' or a 'none' fallback. (SVG2 say 'none' is implied when no
// fallback is specified.)
return SVGPaintDescription();
} }
SVGPaintServer SVGPaintServer::RequestForLayoutObject( SVGPaintServer SVGPaintServer::RequestForLayoutObject(
......
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