From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/svg/SVGImageElement.cpp | 123 +++++++++++++++------------------ 1 file changed, 54 insertions(+), 69 deletions(-) (limited to 'Source/WebCore/svg/SVGImageElement.cpp') diff --git a/Source/WebCore/svg/SVGImageElement.cpp b/Source/WebCore/svg/SVGImageElement.cpp index 0ad8f793b..b361b741e 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Rob Buis * Copyright (C) 2006 Alexander Kellett + * 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 namespace WebCore { @@ -62,74 +59,66 @@ inline SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document& , m_y(LengthModeHeight) , m_width(LengthModeWidth) , m_height(LengthModeHeight) - , m_imageLoader(this) + , m_imageLoader(*this) { registerAnimatedPropertiesForSVGImageElement(); } -PassRefPtr SVGImageElement::create(const QualifiedName& tagName, Document& document) +Ref SVGImageElement::create(const QualifiedName& tagName, Document& document) +{ + return adoptRef(*new SVGImageElement(tagName, document)); +} + +bool SVGImageElement::hasSingleSecurityOrigin() const { - return adoptRef(new SVGImageElement(tagName, document)); + auto* renderer = downcast(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, supportedAttributes, ()); - if (supportedAttributes.isEmpty()) { + static NeverDestroyed> 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(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, MutableStyleProperties& 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(attrName); } void SVGImageElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { + if (name == SVGNames::preserveAspectRatioAttr) { + SVGPreserveAspectRatioValue preserveAspectRatio; + preserveAspectRatio.parse(value); + setPreserveAspectRatioBaseValue(preserveAspectRatio); + return; + } + SVGParsingError parseError = NoError; - if (!isSupportedAttribute(name)) - SVGGraphicsElement::parseAttribute(name, value); - else if (name == SVGNames::xAttr) - setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError)); + if (name == SVGNames::xAttr) + setXBaseValue(SVGLengthValue::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) - setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths)); + setYBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError)); + else if (name == SVGNames::widthAttr) + setWidthBaseValue(SVGLengthValue::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(); + setHeightBaseValue(SVGLengthValue::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths)); reportAttributeParsingError(parseError, name, value); + + SVGGraphicsElement::parseAttribute(name, value); + SVGExternalResourcesRequired::parseAttribute(name, value); + SVGURIReference::parseAttribute(name, value); } void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName) @@ -139,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 @@ -154,12 +149,12 @@ void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName) return; } - auto renderer = this->renderer(); + auto* renderer = this->renderer(); if (!renderer) return; if (isLengthAttribute) { - if (toRenderSVGImage(renderer)->updateImageViewport()) + if (downcast(*renderer).updateImageViewport()) RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer); return; } @@ -174,17 +169,9 @@ void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName) ASSERT_NOT_REACHED(); } -bool SVGImageElement::selfHasRelativeLengths() const +RenderPtr SVGImageElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) { - return x().isRelative() - || y().isRelative() - || width().isRelative() - || height().isRelative(); -} - -RenderPtr SVGImageElement::createElementRenderer(PassRef style) -{ - return createRenderer(*this, std::move(style)); + return createRenderer(*this, WTFMove(style)); } bool SVGImageElement::haveLoadedRequiredResources() @@ -194,7 +181,7 @@ bool SVGImageElement::haveLoadedRequiredResources() void SVGImageElement::didAttachRenderers() { - if (RenderSVGImage* imageObj = toRenderSVGImage(renderer())) { + if (auto* imageObj = downcast(renderer())) { if (imageObj->imageResource().hasImage()) return; @@ -205,7 +192,7 @@ void SVGImageElement::didAttachRenderers() Node::InsertionNotificationRequest SVGImageElement::insertedInto(ContainerNode& rootParent) { SVGGraphicsElement::insertedInto(rootParent); - if (!rootParent.inDocument()) + if (!rootParent.isConnected()) return InsertionDone; // Update image loader, as soon as we're living in the tree. // We can only resolve base URIs properly, after that! @@ -225,12 +212,10 @@ void SVGImageElement::addSubresourceAttributeURLs(ListHashSet& urls) const addSubresourceURL(urls, document().completeURL(href())); } -void SVGImageElement::didMoveToNewDocument(Document* oldDocument) +void SVGImageElement::didMoveToNewDocument(Document& oldDocument) { m_imageLoader.elementDidMoveToNewDocument(); SVGGraphicsElement::didMoveToNewDocument(oldDocument); } } - -#endif // ENABLE(SVG) -- cgit v1.2.1