#include "config.h"
#include "core/rendering/svg/SVGResources.h"
-#include "SVGNames.h"
+#include "core/SVGNames.h"
#include "core/rendering/style/SVGRenderStyle.h"
#include "core/rendering/svg/RenderSVGResourceClipper.h"
#include "core/rendering/svg/RenderSVGResourceFilter.h"
#include "core/rendering/svg/RenderSVGResourceMarker.h"
#include "core/rendering/svg/RenderSVGResourceMasker.h"
+#include "core/rendering/svg/RenderSVGResourcePaintServer.h"
#include "core/svg/SVGFilterElement.h"
#include "core/svg/SVGGradientElement.h"
-#include "core/svg/SVGPaint.h"
#include "core/svg/SVGPatternElement.h"
#include "core/svg/SVGURIReference.h"
#include <stdio.h>
#endif
-namespace WebCore {
+namespace blink {
+
+using namespace SVGNames;
SVGResources::SVGResources()
: m_linkedResource(0)
if (s_tagList.isEmpty()) {
// "container elements": http://www.w3.org/TR/SVG11/intro.html#TermContainerElement
// "graphics elements" : http://www.w3.org/TR/SVG11/intro.html#TermGraphicsElement
- s_tagList.add(SVGNames::aTag.localName());
- s_tagList.add(SVGNames::circleTag.localName());
- s_tagList.add(SVGNames::ellipseTag.localName());
- s_tagList.add(SVGNames::glyphTag.localName());
- s_tagList.add(SVGNames::gTag.localName());
- s_tagList.add(SVGNames::imageTag.localName());
- s_tagList.add(SVGNames::lineTag.localName());
- s_tagList.add(SVGNames::markerTag.localName());
- s_tagList.add(SVGNames::maskTag.localName());
- s_tagList.add(SVGNames::missing_glyphTag.localName());
- s_tagList.add(SVGNames::pathTag.localName());
- s_tagList.add(SVGNames::polygonTag.localName());
- s_tagList.add(SVGNames::polylineTag.localName());
- s_tagList.add(SVGNames::rectTag.localName());
- s_tagList.add(SVGNames::svgTag.localName());
- s_tagList.add(SVGNames::textTag.localName());
- s_tagList.add(SVGNames::useTag.localName());
+ s_tagList.add(aTag.localName());
+ s_tagList.add(circleTag.localName());
+ s_tagList.add(ellipseTag.localName());
+ s_tagList.add(gTag.localName());
+ s_tagList.add(imageTag.localName());
+ s_tagList.add(lineTag.localName());
+ s_tagList.add(markerTag.localName());
+ s_tagList.add(maskTag.localName());
+ s_tagList.add(pathTag.localName());
+ s_tagList.add(polygonTag.localName());
+ s_tagList.add(polylineTag.localName());
+ s_tagList.add(rectTag.localName());
+ s_tagList.add(svgTag.localName());
+ s_tagList.add(textTag.localName());
+ s_tagList.add(useTag.localName());
// Not listed in the definitions is the clipPath element, the SVG spec says though:
// The "clipPath" element or any of its children can specify property "clip-path".
// So we have to add clipPathTag here, otherwhise clip-path on clipPath will fail.
// (Already mailed SVG WG, waiting for a solution)
- s_tagList.add(SVGNames::clipPathTag.localName());
+ s_tagList.add(clipPathTag.localName());
// Not listed in the definitions are the text content elements, though filter/clipper/masker on tspan/text/.. is allowed.
// (Already mailed SVG WG, waiting for a solution)
- s_tagList.add(SVGNames::altGlyphTag.localName());
- s_tagList.add(SVGNames::textPathTag.localName());
- s_tagList.add(SVGNames::tspanTag.localName());
+ s_tagList.add(textPathTag.localName());
+ s_tagList.add(tspanTag.localName());
// Not listed in the definitions is the foreignObject element, but clip-path
// is a supported attribute.
- s_tagList.add(SVGNames::foreignObjectTag.localName());
+ s_tagList.add(foreignObjectTag.localName());
// Elements that we ignore, as it doesn't make any sense.
// defs, pattern, switch (FIXME: Mail SVG WG about these)
{
DEFINE_STATIC_LOCAL(HashSet<AtomicString>, s_tagList, ());
if (s_tagList.isEmpty()) {
- s_tagList.add(SVGNames::lineTag.localName());
- s_tagList.add(SVGNames::pathTag.localName());
- s_tagList.add(SVGNames::polygonTag.localName());
- s_tagList.add(SVGNames::polylineTag.localName());
+ s_tagList.add(lineTag.localName());
+ s_tagList.add(pathTag.localName());
+ s_tagList.add(polygonTag.localName());
+ s_tagList.add(polylineTag.localName());
}
return s_tagList.contains(element.localName());
{
DEFINE_STATIC_LOCAL(HashSet<AtomicString>, s_tagList, ());
if (s_tagList.isEmpty()) {
- s_tagList.add(SVGNames::altGlyphTag.localName());
- s_tagList.add(SVGNames::circleTag.localName());
- s_tagList.add(SVGNames::ellipseTag.localName());
- s_tagList.add(SVGNames::lineTag.localName());
- s_tagList.add(SVGNames::pathTag.localName());
- s_tagList.add(SVGNames::polygonTag.localName());
- s_tagList.add(SVGNames::polylineTag.localName());
- s_tagList.add(SVGNames::rectTag.localName());
- s_tagList.add(SVGNames::textTag.localName());
- s_tagList.add(SVGNames::textPathTag.localName());
- s_tagList.add(SVGNames::tspanTag.localName());
+ s_tagList.add(circleTag.localName());
+ s_tagList.add(ellipseTag.localName());
+ s_tagList.add(lineTag.localName());
+ s_tagList.add(pathTag.localName());
+ s_tagList.add(polygonTag.localName());
+ s_tagList.add(polylineTag.localName());
+ s_tagList.add(rectTag.localName());
+ s_tagList.add(textTag.localName());
+ s_tagList.add(textPathTag.localName());
+ s_tagList.add(tspanTag.localName());
}
return s_tagList;
{
DEFINE_STATIC_LOCAL(HashSet<AtomicString>, s_tagList, ());
if (s_tagList.isEmpty()) {
- s_tagList.add(SVGNames::linearGradientTag.localName());
- s_tagList.add(SVGNames::filterTag.localName());
- s_tagList.add(SVGNames::patternTag.localName());
- s_tagList.add(SVGNames::radialGradientTag.localName());
+ s_tagList.add(linearGradientTag.localName());
+ s_tagList.add(filterTag.localName());
+ s_tagList.add(patternTag.localName());
+ s_tagList.add(radialGradientTag.localName());
}
return s_tagList;
else
ASSERT_NOT_REACHED();
- return SVGURIReference::fragmentIdentifierFromIRIString(target, element.document());
+ return SVGURIReference::fragmentIdentifierFromIRIString(target, element.treeScope());
}
-static inline bool svgPaintTypeHasURL(SVGPaint::SVGPaintType paintType)
+static inline bool svgPaintTypeHasURL(SVGPaintType paintType)
{
switch (paintType) {
- case SVGPaint::SVG_PAINTTYPE_URI_NONE:
- case SVGPaint::SVG_PAINTTYPE_URI_CURRENTCOLOR:
- case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR:
- case SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR:
- case SVGPaint::SVG_PAINTTYPE_URI:
+ case SVG_PAINTTYPE_URI_NONE:
+ case SVG_PAINTTYPE_URI_CURRENTCOLOR:
+ case SVG_PAINTTYPE_URI_RGBCOLOR:
+ case SVG_PAINTTYPE_URI:
return true;
default:
break;
return false;
}
-static inline RenderSVGResourceContainer* paintingResourceFromSVGPaint(Document& document, const SVGPaint::SVGPaintType& paintType, const String& paintUri, AtomicString& id, bool& hasPendingResource)
+static inline RenderSVGResourcePaintServer* paintingResourceFromSVGPaint(TreeScope& treeScope, const SVGPaintType& paintType, const String& paintUri, AtomicString& id, bool& hasPendingResource)
{
if (!svgPaintTypeHasURL(paintType))
return 0;
- id = SVGURIReference::fragmentIdentifierFromIRIString(paintUri, document);
- RenderSVGResourceContainer* container = getRenderSVGResourceContainerById(document, id);
+ id = SVGURIReference::fragmentIdentifierFromIRIString(paintUri, treeScope);
+ RenderSVGResourceContainer* container = getRenderSVGResourceContainerById(treeScope, id);
if (!container) {
hasPendingResource = true;
return 0;
}
- RenderSVGResourceType resourceType = container->resourceType();
- if (resourceType != PatternResourceType && resourceType != LinearGradientResourceType && resourceType != RadialGradientResourceType)
+ if (!container->isSVGPaintServer())
return 0;
- return container;
+ return toRenderSVGResourcePaintServer(container);
}
static inline void registerPendingResource(SVGDocumentExtensions& extensions, const AtomicString& id, SVGElement* element)
bool SVGResources::hasResourceData() const
{
- return !m_clipperFilterMaskerData
- && !m_markerData
- && !m_fillStrokeData
- && !m_linkedResource;
+ return m_clipperFilterMaskerData
+ || m_markerData
+ || m_fillStrokeData
+ || m_linkedResource;
}
static inline SVGResources* ensureResources(OwnPtr<SVGResources>& resources)
return resources.get();
}
-PassOwnPtr<SVGResources> SVGResources::buildResources(const RenderObject* object, const SVGRenderStyle* style)
+PassOwnPtr<SVGResources> SVGResources::buildResources(const RenderObject* object, const SVGRenderStyle& style)
{
ASSERT(object);
- ASSERT(style);
Node* node = object->node();
ASSERT(node);
if (!element)
return nullptr;
- Document& document = object->document();
+ TreeScope& treeScope = element->treeScope();
- SVGDocumentExtensions& extensions = document.accessSVGExtensions();
+ SVGDocumentExtensions& extensions = object->document().accessSVGExtensions();
const AtomicString& tagName = element->localName();
if (tagName.isNull())
OwnPtr<SVGResources> resources;
if (clipperFilterMaskerTags().contains(tagName)) {
- if (style->hasClipper()) {
- AtomicString id = style->clipperResource();
- if (!ensureResources(resources)->setClipper(getRenderSVGResourceById<RenderSVGResourceClipper>(document, id)))
+ if (style.hasClipper()) {
+ AtomicString id = style.clipperResource();
+ if (!ensureResources(resources)->setClipper(getRenderSVGResourceById<RenderSVGResourceClipper>(treeScope, id)))
registerPendingResource(extensions, id, element);
}
- if (style->hasFilter()) {
- AtomicString id = style->filterResource();
- if (!ensureResources(resources)->setFilter(getRenderSVGResourceById<RenderSVGResourceFilter>(document, id)))
+ if (style.hasFilter()) {
+ AtomicString id = style.filterResource();
+ if (!ensureResources(resources)->setFilter(getRenderSVGResourceById<RenderSVGResourceFilter>(treeScope, id)))
registerPendingResource(extensions, id, element);
}
- if (style->hasMasker()) {
- AtomicString id = style->maskerResource();
- if (!ensureResources(resources)->setMasker(getRenderSVGResourceById<RenderSVGResourceMasker>(document, id)))
+ if (style.hasMasker()) {
+ AtomicString id = style.maskerResource();
+ if (!ensureResources(resources)->setMasker(getRenderSVGResourceById<RenderSVGResourceMasker>(treeScope, id)))
registerPendingResource(extensions, id, element);
}
}
- if (style->hasMarkers() && supportsMarkers(*element)) {
- const AtomicString& markerStartId = style->markerStartResource();
- if (!ensureResources(resources)->setMarkerStart(getRenderSVGResourceById<RenderSVGResourceMarker>(document, markerStartId)))
+ if (style.hasMarkers() && supportsMarkers(*element)) {
+ const AtomicString& markerStartId = style.markerStartResource();
+ if (!ensureResources(resources)->setMarkerStart(getRenderSVGResourceById<RenderSVGResourceMarker>(treeScope, markerStartId)))
registerPendingResource(extensions, markerStartId, element);
- const AtomicString& markerMidId = style->markerMidResource();
- if (!ensureResources(resources)->setMarkerMid(getRenderSVGResourceById<RenderSVGResourceMarker>(document, markerMidId)))
+ const AtomicString& markerMidId = style.markerMidResource();
+ if (!ensureResources(resources)->setMarkerMid(getRenderSVGResourceById<RenderSVGResourceMarker>(treeScope, markerMidId)))
registerPendingResource(extensions, markerMidId, element);
- const AtomicString& markerEndId = style->markerEndResource();
- if (!ensureResources(resources)->setMarkerEnd(getRenderSVGResourceById<RenderSVGResourceMarker>(document, style->markerEndResource())))
+ const AtomicString& markerEndId = style.markerEndResource();
+ if (!ensureResources(resources)->setMarkerEnd(getRenderSVGResourceById<RenderSVGResourceMarker>(treeScope, style.markerEndResource())))
registerPendingResource(extensions, markerEndId, element);
}
if (fillAndStrokeTags().contains(tagName)) {
- if (style->hasFill()) {
+ if (style.hasFill()) {
bool hasPendingResource = false;
AtomicString id;
- RenderSVGResourceContainer* resource = paintingResourceFromSVGPaint(document, style->fillPaintType(), style->fillPaintUri(), id, hasPendingResource);
+ RenderSVGResourcePaintServer* resource = paintingResourceFromSVGPaint(treeScope, style.fillPaintType(), style.fillPaintUri(), id, hasPendingResource);
if (!ensureResources(resources)->setFill(resource) && hasPendingResource) {
registerPendingResource(extensions, id, element);
}
}
- if (style->hasStroke()) {
+ if (style.hasStroke()) {
bool hasPendingResource = false;
AtomicString id;
- RenderSVGResourceContainer* resource = paintingResourceFromSVGPaint(document, style->strokePaintType(), style->strokePaintUri(), id, hasPendingResource);
+ RenderSVGResourcePaintServer* resource = paintingResourceFromSVGPaint(treeScope, style.strokePaintType(), style.strokePaintUri(), id, hasPendingResource);
if (!ensureResources(resources)->setStroke(resource) && hasPendingResource) {
registerPendingResource(extensions, id, element);
}
if (chainableResourceTags().contains(tagName)) {
AtomicString id = targetReferenceFromResource(*element);
- if (!ensureResources(resources)->setLinkedResource(getRenderSVGResourceContainerById(document, id)))
+ if (!ensureResources(resources)->setLinkedResource(getRenderSVGResourceContainerById(treeScope, id)))
registerPendingResource(extensions, id, element);
}
- return (!resources || resources->hasResourceData()) ? nullptr : resources.release();
+ return (!resources || !resources->hasResourceData()) ? nullptr : resources.release();
}
void SVGResources::layoutIfNeeded()
}
if (m_fillStrokeData) {
- if (RenderSVGResourceContainer* fill = m_fillStrokeData->fill)
+ if (RenderSVGResourcePaintServer* fill = m_fillStrokeData->fill)
fill->layoutIfNeeded();
- if (RenderSVGResourceContainer* stroke = m_fillStrokeData->stroke)
+ if (RenderSVGResourcePaintServer* stroke = m_fillStrokeData->stroke)
stroke->layoutIfNeeded();
}
void SVGResources::removeClientFromCache(RenderObject* object, bool markForInvalidation) const
{
- if (hasResourceData())
+ if (!hasResourceData())
return;
if (m_linkedResource) {
void SVGResources::resourceDestroyed(RenderSVGResourceContainer* resource)
{
ASSERT(resource);
- if (hasResourceData())
+ if (!hasResourceData())
return;
if (m_linkedResource == resource) {
m_clipperFilterMaskerData->clipper = 0;
}
break;
- case SolidColorResourceType:
+ default:
ASSERT_NOT_REACHED();
}
}
void SVGResources::buildSetOfResources(HashSet<RenderSVGResourceContainer*>& set)
{
- if (hasResourceData())
+ if (!hasResourceData())
return;
if (m_linkedResource) {
m_clipperFilterMaskerData->masker = 0;
}
-bool SVGResources::setFill(RenderSVGResourceContainer* fill)
+bool SVGResources::setFill(RenderSVGResourcePaintServer* fill)
{
if (!fill)
return false;
- ASSERT(fill->resourceType() == PatternResourceType
- || fill->resourceType() == LinearGradientResourceType
- || fill->resourceType() == RadialGradientResourceType);
-
if (!m_fillStrokeData)
m_fillStrokeData = FillStrokeData::create();
m_fillStrokeData->fill = 0;
}
-bool SVGResources::setStroke(RenderSVGResourceContainer* stroke)
+bool SVGResources::setStroke(RenderSVGResourcePaintServer* stroke)
{
if (!stroke)
return false;
- ASSERT(stroke->resourceType() == PatternResourceType
- || stroke->resourceType() == LinearGradientResourceType
- || stroke->resourceType() == RadialGradientResourceType);
-
if (!m_fillStrokeData)
m_fillStrokeData = FillStrokeData::create();
}
if (m_fillStrokeData) {
- if (RenderSVGResourceContainer* fill = m_fillStrokeData->fill)
+ if (RenderSVGResourcePaintServer* fill = m_fillStrokeData->fill)
fprintf(stderr, " |-> Fill : %p (node=%p)\n", fill, fill->element());
- if (RenderSVGResourceContainer* stroke = m_fillStrokeData->stroke)
+ if (RenderSVGResourcePaintServer* stroke = m_fillStrokeData->stroke)
fprintf(stderr, " |-> Stroke : %p (node=%p)\n", stroke, stroke->element());
}