summaryrefslogtreecommitdiff
path: root/Source/WebCore/svg/SVGImageElement.cpp
diff options
context:
space:
mode:
authorKonstantin Tokarev <annulen@yandex.ru>2016-08-25 19:20:41 +0300
committerKonstantin Tokarev <annulen@yandex.ru>2017-02-02 12:30:55 +0000
commit6882a04fb36642862b11efe514251d32070c3d65 (patch)
treeb7959826000b061fd5ccc7512035c7478742f7b0 /Source/WebCore/svg/SVGImageElement.cpp
parentab6df191029eeeb0b0f16f127d553265659f739e (diff)
downloadqtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebCore/svg/SVGImageElement.cpp')
-rw-r--r--Source/WebCore/svg/SVGImageElement.cpp134
1 files changed, 58 insertions, 76 deletions
diff --git a/Source/WebCore/svg/SVGImageElement.cpp b/Source/WebCore/svg/SVGImageElement.cpp
index 27e7274b4..322d67de6 100644
--- a/Source/WebCore/svg/SVGImageElement.cpp
+++ b/Source/WebCore/svg/SVGImageElement.cpp
@@ -2,6 +2,7 @@
* Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis <buis@kde.org>
* Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
+ * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -20,19 +21,15 @@
*/
#include "config.h"
-
-#if ENABLE(SVG)
#include "SVGImageElement.h"
-#include "Attribute.h"
#include "CSSPropertyNames.h"
#include "RenderImageResource.h"
#include "RenderSVGImage.h"
#include "RenderSVGResource.h"
-#include "SVGElementInstance.h"
#include "SVGNames.h"
-#include "SVGSVGElement.h"
#include "XLinkNames.h"
+#include <wtf/NeverDestroyed.h>
namespace WebCore {
@@ -56,81 +53,72 @@ BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGImageElement)
REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
END_REGISTER_ANIMATED_PROPERTIES
-inline SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document* document)
+inline SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document& document)
: SVGGraphicsElement(tagName, document)
, m_x(LengthModeWidth)
, m_y(LengthModeHeight)
, m_width(LengthModeWidth)
, m_height(LengthModeHeight)
- , m_imageLoader(this)
+ , m_imageLoader(*this)
{
- ASSERT(isSVGImageElement(this));
registerAnimatedPropertiesForSVGImageElement();
}
-PassRefPtr<SVGImageElement> SVGImageElement::create(const QualifiedName& tagName, Document* document)
+Ref<SVGImageElement> SVGImageElement::create(const QualifiedName& tagName, Document& document)
{
- return adoptRef(new SVGImageElement(tagName, document));
+ return adoptRef(*new SVGImageElement(tagName, document));
+}
+
+bool SVGImageElement::hasSingleSecurityOrigin() const
+{
+ auto* renderer = downcast<RenderSVGImage>(this->renderer());
+ if (!renderer || !renderer->imageResource().hasImage())
+ return true;
+ auto* image = renderer->imageResource().cachedImage()->image();
+ return !image || image->hasSingleSecurityOrigin();
}
bool SVGImageElement::isSupportedAttribute(const QualifiedName& attrName)
{
- DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
- if (supportedAttributes.isEmpty()) {
+ static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes;
+ if (supportedAttributes.get().isEmpty()) {
SVGLangSpace::addSupportedAttributes(supportedAttributes);
SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
SVGURIReference::addSupportedAttributes(supportedAttributes);
- supportedAttributes.add(SVGNames::xAttr);
- supportedAttributes.add(SVGNames::yAttr);
- supportedAttributes.add(SVGNames::widthAttr);
- supportedAttributes.add(SVGNames::heightAttr);
- supportedAttributes.add(SVGNames::preserveAspectRatioAttr);
+ supportedAttributes.get().add(SVGNames::xAttr);
+ supportedAttributes.get().add(SVGNames::yAttr);
+ supportedAttributes.get().add(SVGNames::widthAttr);
+ supportedAttributes.get().add(SVGNames::heightAttr);
+ supportedAttributes.get().add(SVGNames::preserveAspectRatioAttr);
}
- return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
-}
-
-bool SVGImageElement::isPresentationAttribute(const QualifiedName& name) const
-{
- if (name == SVGNames::widthAttr || name == SVGNames::heightAttr)
- return true;
- return SVGGraphicsElement::isPresentationAttribute(name);
-}
-
-void SVGImageElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
-{
- if (!isSupportedAttribute(name))
- SVGGraphicsElement::collectStyleForPresentationAttribute(name, value, style);
- else if (name == SVGNames::widthAttr)
- addPropertyToPresentationAttributeStyle(style, CSSPropertyWidth, value);
- else if (name == SVGNames::heightAttr)
- addPropertyToPresentationAttributeStyle(style, CSSPropertyHeight, value);
+ return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName);
}
void SVGImageElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
+ if (name == SVGNames::preserveAspectRatioAttr) {
+ SVGPreserveAspectRatio preserveAspectRatio;
+ preserveAspectRatio.parse(value);
+ setPreserveAspectRatioBaseValue(preserveAspectRatio);
+ return;
+ }
+
SVGParsingError parseError = NoError;
- if (!isSupportedAttribute(name))
- SVGGraphicsElement::parseAttribute(name, value);
- else if (name == SVGNames::xAttr)
+ if (name == SVGNames::xAttr)
setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
else if (name == SVGNames::yAttr)
setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
- else if (name == SVGNames::preserveAspectRatioAttr) {
- SVGPreserveAspectRatio preserveAspectRatio;
- preserveAspectRatio.parse(value);
- setPreserveAspectRatioBaseValue(preserveAspectRatio);
- } else if (name == SVGNames::widthAttr)
+ else if (name == SVGNames::widthAttr)
setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
else if (name == SVGNames::heightAttr)
setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
- else if (SVGLangSpace::parseAttribute(name, value)
- || SVGExternalResourcesRequired::parseAttribute(name, value)
- || SVGURIReference::parseAttribute(name, value)) {
- } else
- ASSERT_NOT_REACHED();
reportAttributeParsingError(parseError, name, value);
+
+ SVGGraphicsElement::parseAttribute(name, value);
+ SVGExternalResourcesRequired::parseAttribute(name, value);
+ SVGURIReference::parseAttribute(name, value);
}
void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
@@ -140,8 +128,14 @@ void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
return;
}
- SVGElementInstance::InvalidationGuard invalidationGuard(this);
-
+ InstanceInvalidationGuard guard(*this);
+
+ if (attrName == SVGNames::widthAttr
+ || attrName == SVGNames::heightAttr) {
+ invalidateSVGPresentationAttributeStyle();
+ return;
+ }
+
bool isLengthAttribute = attrName == SVGNames::xAttr
|| attrName == SVGNames::yAttr
|| attrName == SVGNames::widthAttr
@@ -155,37 +149,29 @@ void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
return;
}
- RenderObject* renderer = this->renderer();
+ auto* renderer = this->renderer();
if (!renderer)
return;
if (isLengthAttribute) {
- if (toRenderSVGImage(renderer)->updateImageViewport())
- RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
+ if (downcast<RenderSVGImage>(*renderer).updateImageViewport())
+ RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
return;
}
if (attrName == SVGNames::preserveAspectRatioAttr
|| SVGLangSpace::isKnownAttribute(attrName)
|| SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
- RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
+ RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
return;
}
ASSERT_NOT_REACHED();
}
-bool SVGImageElement::selfHasRelativeLengths() const
-{
- return x().isRelative()
- || y().isRelative()
- || width().isRelative()
- || height().isRelative();
-}
-
-RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle*)
+RenderPtr<RenderElement> SVGImageElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
{
- return new (arena) RenderSVGImage(this);
+ return createRenderer<RenderSVGImage>(*this, WTFMove(style));
}
bool SVGImageElement::haveLoadedRequiredResources()
@@ -193,22 +179,20 @@ bool SVGImageElement::haveLoadedRequiredResources()
return !externalResourcesRequiredBaseValue() || !m_imageLoader.hasPendingActivity();
}
-void SVGImageElement::attach(const AttachContext& context)
+void SVGImageElement::didAttachRenderers()
{
- SVGGraphicsElement::attach(context);
-
- if (RenderSVGImage* imageObj = toRenderSVGImage(renderer())) {
- if (imageObj->imageResource()->hasImage())
+ if (auto* imageObj = downcast<RenderSVGImage>(renderer())) {
+ if (imageObj->imageResource().hasImage())
return;
- imageObj->imageResource()->setCachedImage(m_imageLoader.image());
+ imageObj->imageResource().setCachedImage(m_imageLoader.image());
}
}
-Node::InsertionNotificationRequest SVGImageElement::insertedInto(ContainerNode* rootParent)
+Node::InsertionNotificationRequest SVGImageElement::insertedInto(ContainerNode& rootParent)
{
SVGGraphicsElement::insertedInto(rootParent);
- if (!rootParent->inDocument())
+ if (!rootParent.inDocument())
return InsertionDone;
// Update image loader, as soon as we're living in the tree.
// We can only resolve base URIs properly, after that!
@@ -221,11 +205,11 @@ const AtomicString& SVGImageElement::imageSourceURL() const
return getAttribute(XLinkNames::hrefAttr);
}
-void SVGImageElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
+void SVGImageElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const
{
SVGGraphicsElement::addSubresourceAttributeURLs(urls);
- addSubresourceURL(urls, document()->completeURL(href()));
+ addSubresourceURL(urls, document().completeURL(href()));
}
void SVGImageElement::didMoveToNewDocument(Document* oldDocument)
@@ -235,5 +219,3 @@ void SVGImageElement::didMoveToNewDocument(Document* oldDocument)
}
}
-
-#endif // ENABLE(SVG)