/* * Copyright (C) 2007 Eric Seidel * Copyright (C) 2018 Apple Inc. 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 * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "config.h" #include "SVGMPathElement.h" #include "Document.h" #include "SVGAnimateMotionElement.h" #include "SVGDocumentExtensions.h" #include "SVGNames.h" #include "SVGPathElement.h" #include namespace WebCore { WTF_MAKE_ISO_ALLOCATED_IMPL(SVGMPathElement); inline SVGMPathElement::SVGMPathElement(const QualifiedName& tagName, Document& document) : SVGElement(tagName, document) , SVGURIReference(this) { ASSERT(hasTagName(SVGNames::mpathTag)); } Ref SVGMPathElement::create(const QualifiedName& tagName, Document& document) { return adoptRef(*new SVGMPathElement(tagName, document)); } SVGMPathElement::~SVGMPathElement() { clearResourceReferences(); } void SVGMPathElement::buildPendingResource() { clearResourceReferences(); if (!isConnected()) return; auto target = SVGURIReference::targetElementFromIRIString(href(), treeScope()); if (!target.element) { // Do not register as pending if we are already pending this resource. if (document().accessSVGExtensions().isPendingResource(*this, target.identifier)) return; if (!target.identifier.isEmpty()) { document().accessSVGExtensions().addPendingResource(target.identifier, *this); ASSERT(hasPendingResources()); } } else if (is(*target.element)) downcast(*target.element).addReferencingElement(*this); targetPathChanged(); } void SVGMPathElement::clearResourceReferences() { removeElementReference(); } Node::InsertedIntoAncestorResult SVGMPathElement::insertedIntoAncestor(InsertionType insertionType, ContainerNode& parentOfInsertedTree) { SVGElement::insertedIntoAncestor(insertionType, parentOfInsertedTree); if (insertionType.connectedToDocument) return InsertedIntoAncestorResult::NeedsPostInsertionCallback; return InsertedIntoAncestorResult::Done; } void SVGMPathElement::didFinishInsertingNode() { buildPendingResource(); } void SVGMPathElement::removedFromAncestor(RemovalType removalType, ContainerNode& oldParentOfRemovedTree) { SVGElement::removedFromAncestor(removalType, oldParentOfRemovedTree); notifyParentOfPathChange(&oldParentOfRemovedTree); if (removalType.disconnectedFromDocument) clearResourceReferences(); } void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomString& value) { SVGElement::parseAttribute(name, value); SVGURIReference::parseAttribute(name, value); } void SVGMPathElement::svgAttributeChanged(const QualifiedName& attrName) { if (SVGURIReference::isKnownAttribute(attrName)) { InstanceInvalidationGuard guard(*this); buildPendingResource(); return; } SVGElement::svgAttributeChanged(attrName); } RefPtr SVGMPathElement::pathElement() { auto target = targetElementFromIRIString(href(), treeScope()); if (is(target.element)) return downcast(target.element.get()); return nullptr; } void SVGMPathElement::targetPathChanged() { notifyParentOfPathChange(parentNode()); } void SVGMPathElement::notifyParentOfPathChange(ContainerNode* parent) { if (is(parent)) downcast(*parent).updateAnimationPath(); } } // namespace WebCore