• Skip to content
  • Skip to link menu
KDE 4.3 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 DOM;
00050 
00051 //using namespace HTMLNames;
00052 //using namespace EventNames;
00053 
00054 SVGElement::SVGElement(const QualifiedName& tagName, Document* doc)
00055     : StyledElement(doc) // it's wrong, remove it!!! FIXME: vtokarev
00056 //    : StyledElement(tagName, doc)
00057 //    , m_shadowParent(0)
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     //return getAttribute(XMLNames::baseAttr);
00090     ASSERT(false);
00091     return "";
00092 }
00093 
00094 void SVGElement::setXmlbase(const String& value, ExceptionCode&)
00095 {
00096     //setAttribute(XMLNames::baseAttr, value);
00097 }
00098 
00099 SVGSVGElement* SVGElement::ownerSVGElement() const
00100 {
00101     Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
00102     while (n) {
00103         if (/*n->hasTagName(SVGNames::svgTag)*/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     // This function needs shadow tree support - as RenderSVGContainer uses this function
00115     // to determine the "overflow" property. <use> on <symbol> wouldn't work otherwhise.
00116     /*Node* n = isShadowNode() ? const_cast<SVGElement*>(this)->shadowParentNode() : parentNode();
00117     while (n) {
00118         if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::imageTag) || n->hasTagName(SVGNames::symbolTag))
00119             return static_cast<SVGElement*>(n);
00120 
00121         n = n->isShadowNode() ? n->shadowParentNode() : n->parentNode();
00122     }*/
00123 
00124     return 0;
00125 }
00126 
00127 void SVGElement::addSVGEventListener(/*const AtomicString& eventType*/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     // standard events
00137     if (/*attr->name() == onloadAttr*/attr->id() == ATTR_ONLOAD)
00138         addSVGEventListener(/*loadEvent*/EventImpl::LOAD_EVENT, attr);
00139     else if (/*attr->name() == onclickAttr*/attr->id() == ATTR_ONCLICK)
00140         addSVGEventListener(/*clickEvent*/EventImpl::CLICK_EVENT, attr);
00141     else /*if (attr->name() == onmousedownAttr)
00142         addSVGEventListener(mousedownEvent, attr);
00143     else if (attr->name() == onmousemoveAttr)
00144         addSVGEventListener(mousemoveEvent, attr);
00145     else if (attr->name() == onmouseoutAttr)
00146         addSVGEventListener(mouseoutEvent, attr);
00147     else if (attr->name() == onmouseoverAttr)
00148         addSVGEventListener(mouseoverEvent, attr);
00149     else if (attr->name() == onmouseupAttr)
00150         addSVGEventListener(mouseupEvent, attr);
00151     else if (attr->name() == SVGNames::onfocusinAttr)
00152         addSVGEventListener(DOMFocusInEvent, attr);
00153     else if (attr->name() == SVGNames::onfocusoutAttr)
00154         addSVGEventListener(DOMFocusOutEvent, attr);
00155     else if (attr->name() == SVGNames::onactivateAttr)
00156         addSVGEventListener(DOMActivateEvent, attr);
00157     else*/
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/* || currentNode == node*/)
00185                     return true;
00186                 /*if ((*it)->eventType() == loadEvent &&
00187                     (*it)->useCapture() == true || currentNode == node)
00188                     return true;*/
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(); // save the next parent to dispatch too incase dispatching the event changes the tree
00205         kDebug() << hasLoadListener(currentTarget.get()) << endl;
00206         if (hasLoadListener(currentTarget.get())) {
00207             //Event* event = new Event(EventImpl::LOAD_EVENT, true/*false*/, false);
00208             //event->setTarget(currentTarget.get());
00209             //ExceptionCode ignored = 0;
00210             //dispatchGenericEvent(/*currentTarget.get(), */event, ignored/*, false*/);
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     // finishParsingChildren() is called when the close tag is reached for an element (e.g. </svg>)
00220     // we send SVGLoad events here if we can, otherwise they'll be sent when any required loads finish
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     /*SVGDocumentExtensions* extensions = document()->accessSVGExtensions();
00235 
00236     String resourceId = SVGURIReference::getTarget(id());
00237     if (extensions->isPendingResource(resourceId)) {
00238         std::auto_ptr<HashSet<SVGStyledElement*> > clients(extensions->removePendingResource(resourceId));
00239         if (clients->isEmpty())
00240             return;
00241 
00242         HashSet<SVGStyledElement*>::const_iterator it = clients->begin();
00243         const HashSet<SVGStyledElement*>::const_iterator end = clients->end();
00244 
00245         for (; it != end; ++it)
00246             (*it)->buildPendingResource();
00247 
00248         SVGResource::invalidateClients(*clients);
00249     }*/
00250 }
00251 
00252 static Node* shadowTreeParentElementForShadowTreeElement(Node* node)
00253 {
00254     for (Node* n = node; n; n = n->parentNode()) {
00255         /*if (n->isShadowNode())
00256             return n->shadowParentNode();*/
00257     }
00258 
00259     return 0;
00260 }
00261 
00262 bool SVGElement::dispatchEvent(Event* e, ExceptionCode& ec, bool tempEvent)
00263 {
00264     kDebug() << "dispatch event" << endl;
00265     // TODO: This function will be removed in a follow-up patch!
00266 
00267     /*EventTarget* target = this;
00268     Node* useNode = shadowTreeParentElementForShadowTreeElement(this);
00269 
00270     // If we are a hidden shadow tree element, the target must
00271     // point to our corresponding SVGElementInstance object
00272     if (useNode) {
00273         ASSERT(useNode->hasTagName(SVGNames::useTag));
00274         SVGUseElement* use = static_cast<SVGUseElement*>(useNode);
00275 
00276         SVGElementInstance* instance = use->instanceForShadowTreeElement(this);
00277 
00278         if (instance)
00279             target = instance;
00280     }
00281 
00282     e->setTarget(target);
00283 
00284     RefPtr<FrameView> view = document()->view();
00285     return EventTargetNode::dispatchGenericEvent(this, e, ec, tempEvent);*/
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 // for KHTML compatibility
00301 void SVGElement::addCSSProperty(Attribute* attr, int id, const String& value)
00302 {
00303     kDebug() << "called with: " << id << " " << value << endl;
00304     /* WARNING: copy&past'ed from HTMLElementImpl class */
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     /* WARNING: copy&past'ed from HTMLElementImpl class */
00314     if (!m_hasCombinedStyle) createNonCSSDecl();
00315     nonCSSStyleDecls()->setProperty(id, value, false);
00316     setChanged();
00317 }
00318 
00319 
00320 }
00321 
00322 #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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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