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/loader/cache/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(const QualifiedName&, 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(const QualifiedName&, 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 willRecalcStyle(StyleChange) OVERRIDE;
     68 
     69     virtual RenderObject* createRenderer(RenderStyle*);
     70     virtual void toClipPath(Path&);
     71 
     72     void clearResourceReferences();
     73     void buildShadowAndInstanceTree(SVGElement* target);
     74     void detachInstance();
     75 
     76     virtual bool haveLoadedRequiredResources() { return SVGExternalResourcesRequired::haveLoadedRequiredResources(); }
     77 
     78     virtual void finishParsingChildren();
     79     virtual bool selfHasRelativeLengths() const;
     80 
     81     // Instance tree handling
     82     void buildInstanceTree(SVGElement* target, SVGElementInstance* targetInstance, bool& foundCycle, bool foundUse);
     83     bool hasCycleUseReferencing(SVGUseElement*, SVGElementInstance* targetInstance, SVGElement*& newTarget);
     84 
     85     // Shadow tree handling
     86     void buildShadowTree(SVGElement* target, SVGElementInstance* targetInstance);
     87 
     88     void expandUseElementsInShadowTree(Node* element);
     89     void expandSymbolElementsInShadowTree(Node* element);
     90 
     91     // "Tree connector"
     92     void associateInstancesWithShadowTreeElements(Node* target, SVGElementInstance* targetInstance);
     93     SVGElementInstance* instanceForShadowTreeElement(Node* element, SVGElementInstance* instance) const;
     94 
     95     void transferUseAttributesToReplacedElement(SVGElement* from, SVGElement* to) const;
     96     void transferEventListenersToShadowTree(SVGElementInstance* target);
     97 
     98     BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGUseElement)
     99         DECLARE_ANIMATED_LENGTH(X, x)
    100         DECLARE_ANIMATED_LENGTH(Y, y)
    101         DECLARE_ANIMATED_LENGTH(Width, width)
    102         DECLARE_ANIMATED_LENGTH(Height, height)
    103         DECLARE_ANIMATED_STRING(Href, href)
    104         DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
    105     END_DECLARE_ANIMATED_PROPERTIES
    106 
    107     bool resourceIsStillLoading();
    108     Document* externalDocument() const;
    109     bool instanceTreeIsLoading(SVGElementInstance*);
    110     virtual void notifyFinished(Resource*);
    111     Document* referencedDocument() const;
    112     void setDocumentResource(ResourcePtr<DocumentResource>);
    113 
    114     // SVGExternalResourcesRequired
    115     virtual void setHaveFiredLoadEvent(bool haveFiredLoadEvent) { m_haveFiredLoadEvent = haveFiredLoadEvent; }
    116     virtual bool isParserInserted() const { return m_wasInsertedByParser; }
    117     virtual bool haveFiredLoadEvent() const { return m_haveFiredLoadEvent; }
    118     virtual Timer<SVGElement>* svgLoadEventTimer() OVERRIDE { return &m_svgLoadEventTimer; }
    119 
    120     bool m_wasInsertedByParser;
    121     bool m_haveFiredLoadEvent;
    122     bool m_needsShadowTreeRecreation;
    123     RefPtr<SVGElementInstance> m_targetElementInstance;
    124     ResourcePtr<DocumentResource> m_resource;
    125     Timer<SVGElement> m_svgLoadEventTimer;
    126 };
    127 
    128 inline SVGUseElement* toSVGUseElement(Node* node)
    129 {
    130     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->hasTagName(SVGNames::useTag));
    131     return static_cast<SVGUseElement*>(node);
    132 }
    133 
    134 }
    135 
    136 #endif
    137