Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) kde.org>
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #ifndef SVGUseElement_h
     22 #define SVGUseElement_h
     23 
     24 #include "SVGNames.h"
     25 #include "core/fetch/DocumentResource.h"
     26 #include "core/svg/SVGAnimatedBoolean.h"
     27 #include "core/svg/SVGAnimatedLength.h"
     28 #include "core/svg/SVGExternalResourcesRequired.h"
     29 #include "core/svg/SVGGraphicsElement.h"
     30 #include "core/svg/SVGURIReference.h"
     31 
     32 namespace WebCore {
     33 
     34 class DocumentResource;
     35 class SVGElementInstance;
     36 
     37 class SVGUseElement FINAL : public SVGGraphicsElement,
     38                             public SVGExternalResourcesRequired,
     39                             public SVGURIReference,
     40                             public DocumentResourceClient {
     41 public:
     42     static PassRefPtr<SVGUseElement> create(Document&, bool wasInsertedByParser);
     43     virtual ~SVGUseElement();
     44 
     45     SVGElementInstance* instanceRoot();
     46     SVGElementInstance* animatedInstanceRoot() const;
     47     SVGElementInstance* instanceForShadowTreeElement(Node*) const;
     48     void invalidateShadowTree();
     49     void invalidateDependentShadowTrees();
     50 
     51     RenderObject* rendererClipChild() const;
     52 
     53 private:
     54     SVGUseElement(Document&, bool wasInsertedByParser);
     55 
     56     virtual bool isValid() const { return SVGTests::isValid(); }
     57     virtual bool supportsFocus() const OVERRIDE { return hasFocusEventListeners(); }
     58 
     59     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
     60     virtual void removedFrom(ContainerNode*) OVERRIDE;
     61     virtual void buildPendingResource();
     62 
     63     bool isSupportedAttribute(const QualifiedName&);
     64     virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
     65     virtual void svgAttributeChanged(const QualifiedName&);
     66 
     67     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
     68     virtual void willRecalcStyle(StyleRecalcChange) OVERRIDE;
     69 
     70     virtual RenderObject* createRenderer(RenderStyle*);
     71     virtual void toClipPath(Path&);
     72 
     73     void clearResourceReferences();
     74     void buildShadowAndInstanceTree(SVGElement* target);
     75     void detachInstance();
     76 
     77     virtual bool haveLoadedRequiredResources() { return SVGExternalResourcesRequired::haveLoadedRequiredResources(); }
     78 
     79     virtual void finishParsingChildren();
     80     virtual bool selfHasRelativeLengths() const;
     81 
     82     // Instance tree handling
     83     void buildInstanceTree(SVGElement* target, SVGElementInstance* targetInstance, bool& foundCycle, bool foundUse);
     84     bool hasCycleUseReferencing(SVGUseElement*, SVGElementInstance* targetInstance, SVGElement*& newTarget);
     85 
     86     // Shadow tree handling
     87     void buildShadowTree(SVGElement* target, SVGElementInstance* targetInstance);
     88 
     89     void expandUseElementsInShadowTree(Node* element);
     90     void expandSymbolElementsInShadowTree(Node* element);
     91 
     92     // "Tree connector"
     93     void associateInstancesWithShadowTreeElements(Node* target, SVGElementInstance* targetInstance);
     94     SVGElementInstance* instanceForShadowTreeElement(Node* element, SVGElementInstance* instance) const;
     95 
     96     void transferUseAttributesToReplacedElement(SVGElement* from, SVGElement* to) const;
     97     void transferEventListenersToShadowTree(SVGElementInstance* target);
     98 
     99     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGUseElement)
    100         DECLARE_ANIMATED_LENGTH(X, x)
    101         DECLARE_ANIMATED_LENGTH(Y, y)
    102         DECLARE_ANIMATED_LENGTH(Width, width)
    103         DECLARE_ANIMATED_LENGTH(Height, height)
    104         DECLARE_ANIMATED_STRING(Href, href)
    105         DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
    106     END_DECLARE_ANIMATED_PROPERTIES
    107 
    108     bool resourceIsStillLoading();
    109     Document* externalDocument() const;
    110     bool instanceTreeIsLoading(SVGElementInstance*);
    111     virtual void notifyFinished(Resource*);
    112     Document* referencedDocument() const;
    113     void setDocumentResource(ResourcePtr<DocumentResource>);
    114 
    115     // SVGExternalResourcesRequired
    116     virtual void setHaveFiredLoadEvent(bool haveFiredLoadEvent) { m_haveFiredLoadEvent = haveFiredLoadEvent; }
    117     virtual bool isParserInserted() const { return m_wasInsertedByParser; }
    118     virtual bool haveFiredLoadEvent() const { return m_haveFiredLoadEvent; }
    119     virtual Timer<SVGElement>* svgLoadEventTimer() OVERRIDE { return &m_svgLoadEventTimer; }
    120 
    121     bool m_wasInsertedByParser;
    122     bool m_haveFiredLoadEvent;
    123     bool m_needsShadowTreeRecreation;
    124     RefPtr<SVGElementInstance> m_targetElementInstance;
    125     ResourcePtr<DocumentResource> m_resource;
    126     Timer<SVGElement> m_svgLoadEventTimer;
    127 };
    128 
    129 DEFINE_NODE_TYPE_CASTS(SVGUseElement, hasTagName(SVGNames::useTag));
    130 
    131 }
    132 
    133 #endif
    134