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