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

Move LayoutSVGResourcePaintServer::RequestPaintDescription to SVG DRT

This functions is only used by the SVG layout tree dumper, so move it
there as part of deconstructing SVGPaintServer and related classes.

Make SVGPaintDescription strictly an implement detail now that it's not
exposed.

Bug: 109212
Change-Id: I924603534154de84e0726cb4b9164ad558b0f157
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435191Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Cr-Commit-Position: refs/heads/master@{#811962}
parent 6f838129
......@@ -32,6 +32,37 @@
namespace blink {
namespace {
// If |SVGPaintDescription::has_fallback| is true, |SVGPaintDescription::color|
// is set to a fallback color.
struct SVGPaintDescription {
STACK_ALLOCATED();
public:
SVGPaintDescription() = default;
explicit SVGPaintDescription(Color color) : color(color), is_valid(true) {}
explicit SVGPaintDescription(LayoutSVGResourcePaintServer* resource)
: resource(resource), is_valid(true) {
DCHECK(resource);
}
SVGPaintDescription(LayoutSVGResourcePaintServer* resource,
Color fallback_color)
: resource(resource),
color(fallback_color),
is_valid(true),
has_fallback(true) {
DCHECK(resource);
}
LayoutSVGResourcePaintServer* resource = nullptr;
Color color;
bool is_valid = false;
bool has_fallback = false;
};
} // namespace
SVGPaintServer::SVGPaintServer(Color color) : color_(color) {}
SVGPaintServer::SVGPaintServer(scoped_refptr<Gradient> gradient,
......@@ -154,11 +185,4 @@ LayoutSVGResourcePaintServer::LayoutSVGResourcePaintServer(SVGElement* element)
LayoutSVGResourcePaintServer::~LayoutSVGResourcePaintServer() = default;
SVGPaintDescription LayoutSVGResourcePaintServer::RequestPaintDescription(
const LayoutObject& layout_object,
const ComputedStyle& style,
LayoutSVGResourceMode resource_mode) {
return RequestPaint(layout_object, style, resource_mode);
}
} // namespace blink
......@@ -35,7 +35,6 @@ enum LayoutSVGResourceMode {
};
class LayoutObject;
class LayoutSVGResourcePaintServer;
class ComputedStyle;
class SVGPaintServer {
......@@ -70,35 +69,6 @@ class SVGPaintServer {
Color color_;
};
// If |SVGPaintDescription::hasFallback| is true, |SVGPaintDescription::color|
// is set to a fallback color.
struct SVGPaintDescription {
STACK_ALLOCATED();
public:
SVGPaintDescription()
: resource(nullptr), is_valid(false), has_fallback(false) {}
SVGPaintDescription(Color color)
: resource(nullptr), color(color), is_valid(true), has_fallback(false) {}
SVGPaintDescription(LayoutSVGResourcePaintServer* resource)
: resource(resource), is_valid(true), has_fallback(false) {
DCHECK(resource);
}
SVGPaintDescription(LayoutSVGResourcePaintServer* resource,
Color fallback_color)
: resource(resource),
color(fallback_color),
is_valid(true),
has_fallback(true) {
DCHECK(resource);
}
LayoutSVGResourcePaintServer* resource;
Color color;
bool is_valid;
bool has_fallback;
};
class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer {
public:
LayoutSVGResourcePaintServer(SVGElement*);
......@@ -107,11 +77,6 @@ class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer {
virtual SVGPaintServer PreparePaintServer(
const SVGResourceClient&,
const FloatRect& object_bounding_box) = 0;
// Helper utilities used in to access the underlying resources for DRT.
static SVGPaintDescription RequestPaintDescription(const LayoutObject&,
const ComputedStyle&,
LayoutSVGResourceMode);
};
template <>
......
......@@ -231,30 +231,64 @@ static WTF::TextStream& operator<<(WTF::TextStream& ts,
return ts;
}
static void WriteSVGPaintingResource(
WTF::TextStream& ts,
const SVGPaintDescription& paint_description) {
DCHECK(paint_description.is_valid);
if (!paint_description.resource) {
ts << "[type=SOLID] [color=" << paint_description.color << "]";
return;
static void WriteSVGPaintingResource(WTF::TextStream& ts,
const SVGResource& resource) {
const LayoutSVGResourceContainer* container = resource.ResourceContainer();
DCHECK(container);
switch (container->ResourceType()) {
case kPatternResourceType:
ts << "[type=PATTERN]";
break;
case kLinearGradientResourceType:
ts << "[type=LINEAR-GRADIENT]";
break;
case kRadialGradientResourceType:
ts << "[type=RADIAL-GRADIENT]";
break;
default:
NOTREACHED();
break;
}
LayoutSVGResourcePaintServer* paint_server_container =
paint_description.resource;
SVGElement* element = paint_server_container->GetElement();
DCHECK(element);
if (paint_server_container->ResourceType() == kPatternResourceType)
ts << "[type=PATTERN]";
else if (paint_server_container->ResourceType() ==
kLinearGradientResourceType)
ts << "[type=LINEAR-GRADIENT]";
else if (paint_server_container->ResourceType() ==
kRadialGradientResourceType)
ts << "[type=RADIAL-GRADIENT]";
ts << " [id=\"" << element->GetIdAttribute() << "\"]";
ts << " [id=\"" << resource.Target()->GetIdAttribute() << "\"]";
}
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 bool WriteSVGPaint(WTF::TextStream& ts,
const ComputedStyle& style,
const SVGPaint& paint,
const SVGPaint& visited_paint,
const char* paint_name) {
TextStreamSeparator s(" ");
if (const StyleSVGResource* resource = paint.Resource()) {
const SVGResource* paint_resource = resource->Resource();
if (GetSVGResourceAsType<LayoutSVGResourcePaintServer>(paint_resource)) {
ts << " [" << paint_name << "={" << s;
WriteSVGPaintingResource(ts, *paint_resource);
return true;
}
}
if (base::Optional<Color> color = ResolveColor(style, paint, visited_paint)) {
ts << " [" << paint_name << "={" << s;
ts << "[type=SOLID] [color=" << *color << "]";
return true;
}
return false;
}
static void WriteStyle(WTF::TextStream& ts, const LayoutObject& object) {
......@@ -269,17 +303,10 @@ static void WriteStyle(WTF::TextStream& ts, const LayoutObject& object) {
WriteIfNotDefault(ts, "opacity", style.Opacity(),
ComputedStyleInitialValues::InitialOpacity());
if (object.IsSVGShape()) {
const LayoutSVGShape& shape = static_cast<const LayoutSVGShape&>(object);
DCHECK(shape.GetElement());
SVGPaintDescription stroke_paint_description =
LayoutSVGResourcePaintServer::RequestPaintDescription(
shape, shape.StyleRef(), kApplyToStrokeMode);
if (stroke_paint_description.is_valid) {
TextStreamSeparator s(" ");
ts << " [stroke={" << s;
WriteSVGPaintingResource(ts, stroke_paint_description);
if (WriteSVGPaint(ts, style, svg_style.StrokePaint(),
svg_style.InternalVisitedStrokePaint(), "stroke")) {
const LayoutSVGShape& shape = static_cast<const LayoutSVGShape&>(object);
DCHECK(shape.GetElement());
SVGLengthContext length_context(shape.GetElement());
double dash_offset =
length_context.ValueForLength(svg_style.StrokeDashOffset(), style);
......@@ -300,14 +327,8 @@ static void WriteStyle(WTF::TextStream& ts, const LayoutObject& object) {
ts << "}]";
}
SVGPaintDescription fill_paint_description =
LayoutSVGResourcePaintServer::RequestPaintDescription(
shape, shape.StyleRef(), kApplyToFillMode);
if (fill_paint_description.is_valid) {
TextStreamSeparator s(" ");
ts << " [fill={" << s;
WriteSVGPaintingResource(ts, fill_paint_description);
if (WriteSVGPaint(ts, style, svg_style.FillPaint(),
svg_style.InternalVisitedFillPaint(), "fill")) {
WriteIfNotDefault(ts, "opacity", svg_style.FillOpacity(), 1.0f);
WriteIfNotDefault(ts, "fill rule", svg_style.FillRule(), RULE_NONZERO);
ts << "}]";
......
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