• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

SVGElement.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
00003                   2004, 2005, 2006, 2008 Rob Buis <buis@kde.org>
00004 
00005     This file is part of the KDE project
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025 
00026 #if ENABLE(SVG)
00027 #include "SVGElement.h"
00028 
00029 /*#include "DOMImplementation.h"*/
00030 #include "Document.h"
00031 /*#include "Event.h"
00032 #include "EventListener.h"
00033 #include "EventNames.h"
00034 #include "FrameView.h"
00035 #include "HTMLNames.h"
00036 #include "PlatformString.h"
00037 #include "RenderObject.h"
00038 #include "SVGDocumentExtensions.h"
00039 #include "SVGElementInstance.h"*/
00040 #include "SVGNames.h"
00041 #include "SVGSVGElement.h"
00042 /*#include "SVGURIReference.h"
00043 #include "SVGUseElement.h"
00044 #include "XMLNames.h"
00045 #include "RegisteredEventListener.h"*/
00046 
00047 namespace WebCore {
00048 
00049 //using namespace HTMLNames;
00050 //using namespace EventNames;
00051 
00052 SVGElement::SVGElement(const QualifiedName& tagName, Document* doc)
00053     : StyledElement(doc) // it's wrong, remove it!!! FIXME: vtokarev
00054 //    : StyledElement(tagName, doc)
00055 //    , m_shadowParent(0)
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     //return getAttribute(XMLNames::baseAttr);
00087     ASSERT(false);
00088     return "";
00089 }
00090 
00091 void SVGElement::setXmlbase(const String& value, ExceptionCode&)
00092 {
00093     //setAttribute(XMLNames::baseAttr, value);
00094 }
00095 
00096 SVGSVGElement* SVGElement::ownerSVGElement() const
00097 {
00098     Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
00099     while (n) {
00100         if (/*n->hasTagName(SVGNames::svgTag)*/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     // This function needs shadow tree support - as RenderSVGContainer uses this function
00112     // to determine the "overflow" property. <use> on <symbol> wouldn't work otherwhise.
00113     /*Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
00114     while (n) {
00115         if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::symbolTag))
00116             return static_cast<SVGElement*>(n);
00117 
00118         n = n->isShadowNode() ? n->shadowParentNode() : n->parentNode();
00119     }*/
00120 
00121     return 0;
00122 }
00123 
00124 void SVGElement::addSVGEventListener(/*const AtomicString& eventType*/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     // standard events
00134     if (/*attr->name() == onloadAttr*/attr->id() == ATTR_ONLOAD)
00135         addSVGEventListener(/*loadEvent*/EventImpl::LOAD_EVENT, attr);
00136     else if (/*attr->name() == onclickAttr*/attr->id() == ATTR_ONCLICK)
00137         addSVGEventListener(/*clickEvent*/EventImpl::CLICK_EVENT, attr);
00138     else /*if (attr->name() == onmousedownAttr)
00139         addSVGEventListener(mousedownEvent, attr);
00140     else if (attr->name() == onmousemoveAttr)
00141         addSVGEventListener(mousemoveEvent, attr);
00142     else if (attr->name() == onmouseoutAttr)
00143         addSVGEventListener(mouseoutEvent, attr);
00144     else if (attr->name() == onmouseoverAttr)
00145         addSVGEventListener(mouseoverEvent, attr);
00146     else if (attr->name() == onmouseupAttr)
00147         addSVGEventListener(mouseupEvent, attr);
00148     else if (attr->name() == SVGNames::onfocusinAttr)
00149         addSVGEventListener(DOMFocusInEvent, attr);
00150     else if (attr->name() == SVGNames::onfocusoutAttr)
00151         addSVGEventListener(DOMFocusOutEvent, attr);
00152     else if (attr->name() == SVGNames::onactivateAttr)
00153         addSVGEventListener(DOMActivateEvent, attr);
00154     else*/
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/* || currentNode == node*/)
00182                     return true;
00183                 /*if ((*it)->eventType() == loadEvent &&
00184                     (*it)->useCapture() == true || currentNode == node)
00185                     return true;*/
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(); // save the next parent to dispatch too incase dispatching the event changes the tree
00202         kDebug() << hasLoadListener(currentTarget.get()) << endl;
00203         if (hasLoadListener(currentTarget.get())) {
00204             //Event* event = new Event(EventImpl::LOAD_EVENT, true/*false*/, false);
00205             //event->setTarget(currentTarget.get());
00206             //ExceptionCode ignored = 0;
00207             //dispatchGenericEvent(/*currentTarget.get(), */event, ignored/*, false*/);
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     // finishParsingChildren() is called when the close tag is reached for an element (e.g. </svg>)
00217     // we send SVGLoad events here if we can, otherwise they'll be sent when any required loads finish
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     /*SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
00232 
00233     String resourceId = SVGURIReference::getTarget(id());
00234     if (extensions->isPendingResource(resourceId)) {
00235         std::auto_ptr<HashSet<SVGStyledElement*> > clients(extensions->removePendingResource(resourceId));
00236         if (clients->isEmpty())
00237             return;
00238 
00239         HashSet<SVGStyledElement*>::const_iterator it = clients->begin();
00240         const HashSet<SVGStyledElement*>::const_iterator end = clients->end();
00241 
00242         for (; it != end; ++it)
00243             (*it)->buildPendingResource();
00244 
00245         SVGResource::invalidateClients(*clients);
00246     }*/
00247 }
00248 
00249 static Node* shadowTreeParentElementForShadowTreeElement(Node* node)
00250 {
00251     for (Node* n = node; n; n = n->parentNode()) {
00252         /*if (n->isShadowNode())
00253             return n->shadowParentNode();*/
00254     }
00255 
00256     return 0;
00257 }
00258 
00259 bool SVGElement::dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent)
00260 {
00261     kDebug() << "dispatch event" << endl;
00262     // TODO: This function will be removed in a follow-up patch!
00263 
00264     /*EventTarget* target = this;
00265     Node* useNode = shadowTreeParentElementForShadowTreeElement(this);
00266 
00267     // If we are a hidden shadow tree element, the target must
00268     // point to our corresponding SVGElementInstance object
00269     if (useNode) {
00270         ASSERT(useNode->hasTagName(SVGNames::useTag));
00271         SVGUseElement* use = static_cast<SVGUseElement*>(useNode);
00272 
00273         SVGElementInstance* instance = use->instanceForShadowTreeElement(this);
00274 
00275         if (instance)
00276             target = instance;
00277     }
00278 
00279     e->setTarget(target);
00280 
00281     RefPtr<FrameView> view = document()->view();
00282     return EventTargetNode::dispatchGenericEvent(this, e, ec, tempEvent);*/
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 // for KHTML compatibility
00298 void SVGElement::addCSSProperty(Attribute* attr, int id, const String& value)
00299 {
00300     kDebug() << "called with: " << id << " " << value << endl;
00301     /* WARNING: copy&past'ed from HTMLElementImpl class */
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     /* WARNING: copy&past'ed from HTMLElementImpl class */
00311     if (!m_hasCombinedStyle) createNonCSSDecl();
00312     nonCSSStyleDecls()->setProperty(id, value, false);
00313     setChanged();
00314 }
00315 
00316 
00317 }
00318 
00319 #endif // ENABLE(SVG)

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal