KHTML
SVGElement.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
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025
00026 #if ENABLE(SVG)
00027 #include "SVGElement.h"
00028
00029
00030 #include "Document.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "SVGNames.h"
00041 #include "SVGSVGElement.h"
00042
00043
00044
00045
00046
00047 namespace WebCore {
00048
00049
00050
00051
00052 SVGElement::SVGElement(const QualifiedName& tagName, Document* doc)
00053 : StyledElement(doc)
00054
00055
00056 {
00057 }
00058
00059 SVGElement::~SVGElement()
00060 {
00061 }
00062
00063 bool SVGElement::isSupported(StringImpl* feature, StringImpl* version) const
00064 {
00065 if (DOMImplementation::instance()->hasFeature(feature, version))
00066 return true;
00067
00068 return DOMImplementation::instance()->hasFeature(feature, version);
00069 }
00070
00071
00072 String SVGElement::attrid() const
00073 {
00074 return getAttribute(idAttr);
00075 }
00076
00077
00078 void SVGElement::setId(const String& value, ExceptionCode&)
00079 {
00080 setAttribute(idAttr, value);
00081 }
00082
00083
00084 String SVGElement::xmlbase() const
00085 {
00086
00087 ASSERT(false);
00088 return "";
00089 }
00090
00091 void SVGElement::setXmlbase(const String& value, ExceptionCode&)
00092 {
00093
00094 }
00095
00096 SVGSVGElement* SVGElement::ownerSVGElement() const
00097 {
00098 Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
00099 while (n) {
00100 if (n->id() == SVGNames::svgTag.id())
00101 return static_cast<SVGSVGElement*>(n);
00102
00103 n = n->isShadowNode() ? n->shadowParentNode() : n->parentNode();
00104 }
00105
00106 return 0;
00107 }
00108
00109 SVGElement* SVGElement::viewportElement() const
00110 {
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 return 0;
00122 }
00123
00124 void SVGElement::addSVGEventListener(const EventImpl::EventId& eventType, const Attribute* attr)
00125 {
00126 kDebug() << "add listener for: " << EventName::fromId(eventType).toString() << endl;
00127 Element::setHTMLEventListener(EventName::fromId(eventType), document()->accessSVGExtensions()->
00128 createSVGEventListener(attr->localName().string(), attr->value(), this));
00129 }
00130
00131 void SVGElement::parseMappedAttribute(MappedAttribute* attr)
00132 {
00133
00134 if (attr->id() == ATTR_ONLOAD)
00135 addSVGEventListener(EventImpl::LOAD_EVENT, attr);
00136 else if (attr->id() == ATTR_ONCLICK)
00137 addSVGEventListener(EventImpl::CLICK_EVENT, attr);
00138 else
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 if (attr->id() == ATTR_ID) {
00156 setHasID();
00157 document()->incDOMTreeVersion();
00158 } else
00159 StyledElement::parseAttribute(attr);
00160 }
00161
00162 bool SVGElement::haveLoadedRequiredResources()
00163 {
00164 Node* child = firstChild();
00165 while (child) {
00166 if (child->isSVGElement() && !static_cast<SVGElement*>(child)->haveLoadedRequiredResources())
00167 return false;
00168 child = child->nextSibling();
00169 }
00170 return true;
00171 }
00172
00173 static bool hasLoadListener(SVGElement* node)
00174 {
00175 Node* currentNode = node;
00176 while (currentNode && currentNode->isElementNode()) {
00177 QList<RegisteredEventListener> *list = static_cast<Element*>(currentNode)->localEventListeners();
00178 if (list) {
00179 QList<RegisteredEventListener>::Iterator end = list->end();
00180 for (QList<RegisteredEventListener>::Iterator it = list->begin(); it != end; ++it)
00181 if ((*it).useCapture || (*it).eventName.id() == EventImpl::LOAD_EVENT)
00182 return true;
00183
00184
00185
00186 }
00187 currentNode = currentNode->parentNode();
00188 }
00189
00190 return false;
00191 }
00192
00193 void SVGElement::sendSVGLoadEventIfPossible(bool sendParentLoadEvents)
00194 {
00195 kDebug() << "send svg load event" << endl;
00196 RefPtr<SVGElement> currentTarget = this;
00197 kDebug() << currentTarget << currentTarget->haveLoadedRequiredResources() << endl;
00198 while (currentTarget && currentTarget->haveLoadedRequiredResources()) {
00199 RefPtr<Node> parent;
00200 if (sendParentLoadEvents)
00201 parent = currentTarget->parentNode();
00202 kDebug() << hasLoadListener(currentTarget.get()) << endl;
00203 if (hasLoadListener(currentTarget.get())) {
00204
00205
00206
00207
00208 dispatchHTMLEvent(EventImpl::LOAD_EVENT, false, false);
00209 }
00210 currentTarget = (parent && parent->isSVGElement()) ? static_pointer_cast<SVGElement>(parent) : RefPtr<SVGElement>();
00211 }
00212 }
00213
00214 void SVGElement::finishParsingChildren()
00215 {
00216
00217
00218 sendSVGLoadEventIfPossible();
00219 }
00220
00221 bool SVGElement::childShouldCreateRenderer(Node* child) const
00222 {
00223 if (child->isSVGElement())
00224 return static_cast<SVGElement*>(child)->isValid();
00225 return false;
00226 }
00227
00228 void SVGElement::insertedIntoDocument()
00229 {
00230 StyledElement::insertedIntoDocument();
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 }
00248
00249 static Node* shadowTreeParentElementForShadowTreeElement(Node* node)
00250 {
00251 for (Node* n = node; n; n = n->parentNode()) {
00252
00253
00254 }
00255
00256 return 0;
00257 }
00258
00259 bool SVGElement::dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent)
00260 {
00261 kDebug() << "dispatch event" << endl;
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 ASSERT(false);
00284 return false;
00285 }
00286
00287 void SVGElement::attributeChanged(Attribute* attr, bool preserveDecls)
00288 {
00289 ASSERT(attr);
00290 if (!attr)
00291 return;
00292
00293 StyledElement::attributeChanged(attr, preserveDecls);
00294 svgAttributeChanged(attr->name());
00295 }
00296
00297
00298 void SVGElement::addCSSProperty(Attribute* attr, int id, const String& value)
00299 {
00300 kDebug() << "called with: " << id << " " << value << endl;
00301
00302 if (!m_hasCombinedStyle) createNonCSSDecl();
00303 nonCSSStyleDecls()->setProperty(id, value, false);
00304 setChanged();
00305 }
00306
00307 void SVGElement::addCSSProperty(Attribute* attr, int id, int value)
00308 {
00309 kDebug() << "called with: " << id << " " << value << endl;
00310
00311 if (!m_hasCombinedStyle) createNonCSSDecl();
00312 nonCSSStyleDecls()->setProperty(id, value, false);
00313 setChanged();
00314 }
00315
00316
00317 }
00318
00319 #endif // ENABLE(SVG)