| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
| 4 | * Copyright (C) 2015-2018 Apple Inc. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "CachedResourceHandle.h" |
| 25 | #include "CachedSVGDocumentClient.h" |
| 26 | #include "SVGExternalResourcesRequired.h" |
| 27 | #include "SVGGraphicsElement.h" |
| 28 | #include "SVGURIReference.h" |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class CachedSVGDocument; |
| 33 | class SVGGElement; |
| 34 | |
| 35 | class SVGUseElement final : public SVGGraphicsElement, public SVGExternalResourcesRequired, public SVGURIReference, private CachedSVGDocumentClient { |
| 36 | WTF_MAKE_ISO_ALLOCATED(SVGUseElement); |
| 37 | public: |
| 38 | static Ref<SVGUseElement> create(const QualifiedName&, Document&); |
| 39 | virtual ~SVGUseElement(); |
| 40 | |
| 41 | void invalidateShadowTree(); |
| 42 | bool shadowTreeNeedsUpdate() const { return m_shadowTreeNeedsUpdate; } |
| 43 | void updateShadowTree(); |
| 44 | |
| 45 | RenderElement* rendererClipChild() const; |
| 46 | |
| 47 | const SVGLengthValue& x() const { return m_x->currentValue(); } |
| 48 | const SVGLengthValue& y() const { return m_y->currentValue(); } |
| 49 | const SVGLengthValue& width() const { return m_width->currentValue(); } |
| 50 | const SVGLengthValue& height() const { return m_height->currentValue(); } |
| 51 | |
| 52 | SVGAnimatedLength& xAnimated() { return m_x; } |
| 53 | SVGAnimatedLength& yAnimated() { return m_y; } |
| 54 | SVGAnimatedLength& widthAnimated() { return m_width; } |
| 55 | SVGAnimatedLength& heightAnimated() { return m_height; } |
| 56 | |
| 57 | private: |
| 58 | SVGUseElement(const QualifiedName&, Document&); |
| 59 | |
| 60 | bool isValid() const override; |
| 61 | InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) override; |
| 62 | void didFinishInsertingNode() final; |
| 63 | void removedFromAncestor(RemovalType, ContainerNode&) override; |
| 64 | void buildPendingResource() override; |
| 65 | |
| 66 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGUseElement, SVGGraphicsElement, SVGExternalResourcesRequired, SVGURIReference>; |
| 67 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
| 68 | |
| 69 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
| 70 | void svgAttributeChanged(const QualifiedName&) override; |
| 71 | |
| 72 | RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override; |
| 73 | Path toClipPath() override; |
| 74 | bool haveLoadedRequiredResources() override; |
| 75 | void finishParsingChildren() override; |
| 76 | bool selfHasRelativeLengths() const override; |
| 77 | void setHaveFiredLoadEvent(bool) override; |
| 78 | bool haveFiredLoadEvent() const override; |
| 79 | Timer* svgLoadEventTimer() override; |
| 80 | void notifyFinished(CachedResource&) final; |
| 81 | |
| 82 | Document* externalDocument() const; |
| 83 | void updateExternalDocument(); |
| 84 | |
| 85 | SVGElement* findTarget(String* targetID = nullptr) const; |
| 86 | |
| 87 | void cloneTarget(ContainerNode&, SVGElement& target) const; |
| 88 | RefPtr<SVGElement> targetClone() const; |
| 89 | |
| 90 | void expandUseElementsInShadowTree() const; |
| 91 | void expandSymbolElementsInShadowTree() const; |
| 92 | void transferEventListenersToShadowTree() const; |
| 93 | void transferSizeAttributesToTargetClone(SVGElement&) const; |
| 94 | |
| 95 | void clearShadowTree(); |
| 96 | void invalidateDependentShadowTrees(); |
| 97 | |
| 98 | PropertyRegistry m_propertyRegistry { *this }; |
| 99 | Ref<SVGAnimatedLength> m_x { SVGAnimatedLength::create(this, LengthModeWidth) }; |
| 100 | Ref<SVGAnimatedLength> m_y { SVGAnimatedLength::create(this, LengthModeHeight) }; |
| 101 | Ref<SVGAnimatedLength> m_width { SVGAnimatedLength::create(this, LengthModeWidth) }; |
| 102 | Ref<SVGAnimatedLength> m_height { SVGAnimatedLength::create(this, LengthModeHeight) }; |
| 103 | |
| 104 | bool m_haveFiredLoadEvent { false }; |
| 105 | bool m_shadowTreeNeedsUpdate { true }; |
| 106 | CachedResourceHandle<CachedSVGDocument> m_externalDocument; |
| 107 | Timer m_svgLoadEventTimer; |
| 108 | }; |
| 109 | |
| 110 | } |
| 111 | |