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 @@ ...@@ -32,6 +32,37 @@
namespace blink { 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(Color color) : color_(color) {}
SVGPaintServer::SVGPaintServer(scoped_refptr<Gradient> gradient, SVGPaintServer::SVGPaintServer(scoped_refptr<Gradient> gradient,
...@@ -154,11 +185,4 @@ LayoutSVGResourcePaintServer::LayoutSVGResourcePaintServer(SVGElement* element) ...@@ -154,11 +185,4 @@ LayoutSVGResourcePaintServer::LayoutSVGResourcePaintServer(SVGElement* element)
LayoutSVGResourcePaintServer::~LayoutSVGResourcePaintServer() = default; 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 } // namespace blink
...@@ -35,7 +35,6 @@ enum LayoutSVGResourceMode { ...@@ -35,7 +35,6 @@ enum LayoutSVGResourceMode {
}; };
class LayoutObject; class LayoutObject;
class LayoutSVGResourcePaintServer;
class ComputedStyle; class ComputedStyle;
class SVGPaintServer { class SVGPaintServer {
...@@ -70,35 +69,6 @@ class SVGPaintServer { ...@@ -70,35 +69,6 @@ class SVGPaintServer {
Color color_; 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 { class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer {
public: public:
LayoutSVGResourcePaintServer(SVGElement*); LayoutSVGResourcePaintServer(SVGElement*);
...@@ -107,11 +77,6 @@ class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer { ...@@ -107,11 +77,6 @@ class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer {
virtual SVGPaintServer PreparePaintServer( virtual SVGPaintServer PreparePaintServer(
const SVGResourceClient&, const SVGResourceClient&,
const FloatRect& object_bounding_box) = 0; 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 <> template <>
......
...@@ -231,30 +231,64 @@ static WTF::TextStream& operator<<(WTF::TextStream& ts, ...@@ -231,30 +231,64 @@ static WTF::TextStream& operator<<(WTF::TextStream& ts,
return ts; return ts;
} }
static void WriteSVGPaintingResource( static void WriteSVGPaintingResource(WTF::TextStream& ts,
WTF::TextStream& ts, const SVGResource& resource) {
const SVGPaintDescription& paint_description) { const LayoutSVGResourceContainer* container = resource.ResourceContainer();
DCHECK(paint_description.is_valid); DCHECK(container);
if (!paint_description.resource) { switch (container->ResourceType()) {
ts << "[type=SOLID] [color=" << paint_description.color << "]"; case kPatternResourceType:
return; ts << "[type=PATTERN]";
break;
case kLinearGradientResourceType:
ts << "[type=LINEAR-GRADIENT]";
break;
case kRadialGradientResourceType:
ts << "[type=RADIAL-GRADIENT]";
break;
default:
NOTREACHED();
break;
} }
ts << " [id=\"" << resource.Target()->GetIdAttribute() << "\"]";
LayoutSVGResourcePaintServer* paint_server_container = }
paint_description.resource;
SVGElement* element = paint_server_container->GetElement(); static base::Optional<Color> ResolveColor(const ComputedStyle& style,
DCHECK(element); const SVGPaint& paint,
const SVGPaint& visited_paint) {
if (paint_server_container->ResourceType() == kPatternResourceType) if (!paint.HasColor())
ts << "[type=PATTERN]"; return base::nullopt;
else if (paint_server_container->ResourceType() == Color color = style.ResolvedColor(paint.GetColor());
kLinearGradientResourceType) if (style.InsideLink() != EInsideLink::kInsideVisitedLink)
ts << "[type=LINEAR-GRADIENT]"; return color;
else if (paint_server_container->ResourceType() == // FIXME: This code doesn't support the uri component of the visited link
kRadialGradientResourceType) // paint, https://bugs.webkit.org/show_bug.cgi?id=70006
ts << "[type=RADIAL-GRADIENT]"; if (!visited_paint.HasColor())
return color;
ts << " [id=\"" << element->GetIdAttribute() << "\"]"; 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) { static void WriteStyle(WTF::TextStream& ts, const LayoutObject& object) {
...@@ -269,17 +303,10 @@ 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(), WriteIfNotDefault(ts, "opacity", style.Opacity(),
ComputedStyleInitialValues::InitialOpacity()); ComputedStyleInitialValues::InitialOpacity());
if (object.IsSVGShape()) { if (object.IsSVGShape()) {
const LayoutSVGShape& shape = static_cast<const LayoutSVGShape&>(object); if (WriteSVGPaint(ts, style, svg_style.StrokePaint(),
DCHECK(shape.GetElement()); svg_style.InternalVisitedStrokePaint(), "stroke")) {
const LayoutSVGShape& shape = static_cast<const LayoutSVGShape&>(object);
SVGPaintDescription stroke_paint_description = DCHECK(shape.GetElement());
LayoutSVGResourcePaintServer::RequestPaintDescription(
shape, shape.StyleRef(), kApplyToStrokeMode);
if (stroke_paint_description.is_valid) {
TextStreamSeparator s(" ");
ts << " [stroke={" << s;
WriteSVGPaintingResource(ts, stroke_paint_description);
SVGLengthContext length_context(shape.GetElement()); SVGLengthContext length_context(shape.GetElement());
double dash_offset = double dash_offset =
length_context.ValueForLength(svg_style.StrokeDashOffset(), style); length_context.ValueForLength(svg_style.StrokeDashOffset(), style);
...@@ -300,14 +327,8 @@ static void WriteStyle(WTF::TextStream& ts, const LayoutObject& object) { ...@@ -300,14 +327,8 @@ static void WriteStyle(WTF::TextStream& ts, const LayoutObject& object) {
ts << "}]"; ts << "}]";
} }
SVGPaintDescription fill_paint_description = if (WriteSVGPaint(ts, style, svg_style.FillPaint(),
LayoutSVGResourcePaintServer::RequestPaintDescription( svg_style.InternalVisitedFillPaint(), "fill")) {
shape, shape.StyleRef(), kApplyToFillMode);
if (fill_paint_description.is_valid) {
TextStreamSeparator s(" ");
ts << " [fill={" << s;
WriteSVGPaintingResource(ts, fill_paint_description);
WriteIfNotDefault(ts, "opacity", svg_style.FillOpacity(), 1.0f); WriteIfNotDefault(ts, "opacity", svg_style.FillOpacity(), 1.0f);
WriteIfNotDefault(ts, "fill rule", svg_style.FillRule(), RULE_NONZERO); WriteIfNotDefault(ts, "fill rule", svg_style.FillRule(), RULE_NONZERO);
ts << "}]"; 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