KHTML
SVGElementInstance.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "wtf/Platform.h"
00024
00025 #if ENABLE(SVG)
00026 #include "SVGElementInstance.h"
00027
00028
00029
00030 #include "SVGElementInstanceList.h"
00031 #include "SVGUseElement.h"
00032
00033 #include <wtf/Assertions.h>
00034
00035 namespace WebCore {
00036
00037 SVGElementInstance::SVGElementInstance(SVGUseElement* useElement, PassRefPtr<SVGElement> originalElement)
00038 : m_refCount(0)
00039 , m_parent(0)
00040 , m_useElement(useElement)
00041 , m_element(originalElement)
00042 , m_shadowTreeElement(0)
00043 , m_previousSibling(0)
00044 , m_nextSibling(0)
00045 , m_firstChild(0)
00046 , m_lastChild(0)
00047 {
00048 ASSERT(m_useElement);
00049 ASSERT(m_element);
00050
00051
00052 m_element->document()->accessSVGExtensions()->mapInstanceToElement(this, m_element.get());
00053 }
00054
00055 SVGElementInstance::~SVGElementInstance()
00056 {
00057 for (RefPtr<SVGElementInstance> child = m_firstChild; child; child = child->m_nextSibling)
00058 child->setParent(0);
00059
00060
00061 m_element->document()->accessSVGExtensions()->removeInstanceMapping(this, m_element.get());
00062 }
00063
00064 SVGElement* SVGElementInstance::correspondingElement() const
00065 {
00066 return m_element.get();
00067 }
00068
00069 SVGUseElement* SVGElementInstance::correspondingUseElement() const
00070 {
00071 return m_useElement;
00072 }
00073
00074 SVGElementInstance* SVGElementInstance::parentNode() const
00075 {
00076 return parent();
00077 }
00078
00079 PassRefPtr<SVGElementInstanceList> SVGElementInstance::childNodes()
00080 {
00081 return SVGElementInstanceList::create(this);
00082 }
00083
00084 SVGElementInstance* SVGElementInstance::previousSibling() const
00085 {
00086 return m_previousSibling;
00087 }
00088
00089 SVGElementInstance* SVGElementInstance::nextSibling() const
00090 {
00091 return m_nextSibling;
00092 }
00093
00094 SVGElementInstance* SVGElementInstance::firstChild() const
00095 {
00096 return m_firstChild;
00097 }
00098
00099 SVGElementInstance* SVGElementInstance::lastChild() const
00100 {
00101 return m_lastChild;
00102 }
00103
00104 SVGElement* SVGElementInstance::shadowTreeElement() const
00105 {
00106 return m_shadowTreeElement;
00107 }
00108
00109 void SVGElementInstance::setShadowTreeElement(SVGElement* element)
00110 {
00111 ASSERT(element);
00112 m_shadowTreeElement = element;
00113 }
00114
00115 void SVGElementInstance::appendChild(PassRefPtr<SVGElementInstance> child)
00116 {
00117 child->setParent(this);
00118
00119 if (m_lastChild) {
00120 child->m_previousSibling = m_lastChild;
00121 m_lastChild->m_nextSibling = child.get();
00122 } else
00123 m_firstChild = child.get();
00124
00125 m_lastChild = child.get();
00126 }
00127
00128
00129 static bool containsUseChildNode(Node* start)
00130 {
00131 if (start->hasTagName(SVGNames::useTag))
00132 return true;
00133
00134 for (Node* current = start->firstChild(); current; current = current->nextSibling()) {
00135 if (containsUseChildNode(current))
00136 return true;
00137 }
00138
00139 return false;
00140 }
00141
00142 void SVGElementInstance::updateInstance(SVGElement* element)
00143 {
00144 ASSERT(element == m_element);
00145 ASSERT(m_shadowTreeElement);
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 if (m_element->hasTagName(SVGNames::symbolTag) ||
00158 m_element->hasTagName(SVGNames::svgTag) ||
00159 containsUseChildNode(m_element.get())) {
00160 m_useElement->buildPendingResource();
00161 return;
00162 }
00163
00164
00165 WTF::PassRefPtr<Node> clone = m_element->cloneNode(true);
00166 SVGUseElement::removeDisallowedElementsFromSubtree(clone.get());
00167 SVGElement* svgClone = 0;
00168 if (clone && clone->isSVGElement())
00169 svgClone = static_cast<SVGElement*>(clone.get());
00170 ASSERT(svgClone);
00171
00172
00173 int ec = 0;
00174 m_shadowTreeElement->parentNode()->replaceChild(clone.releaseRef(), m_shadowTreeElement, ec);
00175 ASSERT(ec == 0);
00176
00177 m_shadowTreeElement = svgClone;
00178 }
00179
00180 SVGElementInstance* SVGElementInstance::toSVGElementInstance()
00181 {
00182 return this;
00183 }
00184
00185 EventTargetNode* SVGElementInstance::toNode()
00186 {
00187 return m_element.get();
00188 }
00189
00190 void SVGElementInstance::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> eventListener, bool useCapture)
00191 {
00192
00193 }
00194
00195 void SVGElementInstance::removeEventListener(const AtomicString& eventType, EventListener* eventListener, bool useCapture)
00196 {
00197
00198 }
00199
00200 bool SVGElementInstance::dispatchEvent(PassRefPtr<Event>, ExceptionCode& ec, bool tempEvent)
00201 {
00202
00203 return false;
00204 }
00205
00206 }
00207
00208 #endif // ENABLE(SVG)
00209
00210