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

KHTML

SVGAElement.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
00003                   2004, 2005, 2007 Rob Buis <buis@kde.org>
00004                   2007 Eric Seidel <eric@webkit.org>
00005 
00006     This file is part of the KDE project
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "config.h"
00025 #include "wtf/Platform.h"
00026 
00027 #if ENABLE(SVG)
00028 #include "SVGAElement.h"
00029 
00030 /*#include "Attr.h"
00031 #include "CSSHelper.h"*/
00032 #include "Document.h"
00033 /*#include "EventHandler.h"
00034 #include "EventNames.h"
00035 #include "Frame.h"
00036 #include "FrameLoader.h"
00037 #include "KeyboardEvent.h"
00038 #include "MouseEvent.h"
00039 #include "PlatformMouseEvent.h"*/
00040 #include "RenderSVGTransformableContainer.h"
00041 #include "RenderSVGInline.h"
00042 /*#include "ResourceRequest.h"
00043 #include "SVGSMILElement.h"*/
00044 #include "SVGNames.h"
00045 #include "XLinkNames.h"
00046 
00047 namespace WebCore {
00048 
00049 //using namespace EventNames;
00050 
00051 SVGAElement::SVGAElement(const QualifiedName& tagName, Document *doc)
00052     : SVGStyledTransformableElement(tagName, doc)
00053     , SVGURIReference()
00054     , SVGTests()
00055     , SVGLangSpace()
00056     , SVGExternalResourcesRequired()
00057 {
00058 }
00059 
00060 SVGAElement::~SVGAElement()
00061 {
00062 }
00063 
00064 String SVGAElement::title() const
00065 {
00066     return getAttribute(XLinkNames::titleAttr);
00067 }
00068 
00069 ANIMATED_PROPERTY_DEFINITIONS(SVGAElement, String, String, string, Target, target, SVGNames::targetAttr, m_target)
00070 
00071 void SVGAElement::parseMappedAttribute(MappedAttribute* attr)
00072 {
00073     if (attr->name() == SVGNames::targetAttr)
00074         setTargetBaseValue(attr->value());
00075     else {
00076         if (SVGURIReference::parseMappedAttribute(attr))
00077             return;
00078         if (SVGTests::parseMappedAttribute(attr))
00079             return;
00080         if (SVGLangSpace::parseMappedAttribute(attr))
00081             return;
00082         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00083             return;
00084         SVGStyledTransformableElement::parseMappedAttribute(attr);
00085     }
00086 }
00087 
00088 void SVGAElement::svgAttributeChanged(const QualifiedName& attrName)
00089 {
00090     SVGStyledTransformableElement::svgAttributeChanged(attrName);
00091 
00092     // Unlike other SVG*Element classes, SVGAElement only listens to SVGURIReference changes
00093     // as none of the other properties changes the linking behaviour for our <a> element.
00094     if (SVGURIReference::isKnownAttribute(attrName)) {
00095         /*khtml FIXME bool wasLink = m_isLink;
00096         m_isLink = !href().isNull();
00097 
00098         if (wasLink != m_isLink)
00099             setChanged();*/
00100     }
00101 }
00102 
00103 RenderObject* SVGAElement::createRenderer(RenderArena* arena, RenderStyle* style)
00104 {
00105     if (static_cast<SVGElement*>(parent())->isTextContent())
00106         return new (arena) RenderSVGInline(this);
00107 
00108     return new (arena) RenderSVGTransformableContainer(this);
00109 }
00110 
00111 void SVGAElement::defaultEventHandler(Event* evt)
00112 {
00113     /*if (m_isLink && (evt->type() == clickEvent || (evt->type() == keydownEvent && m_focused))) {
00114         MouseEvent* e = 0;
00115         if (evt->type() == clickEvent && evt->isMouseEvent())
00116             e = static_cast<MouseEvent*>(evt);
00117         
00118         KeyboardEvent* k = 0;
00119         if (evt->type() == keydownEvent && evt->isKeyboardEvent())
00120             k = static_cast<KeyboardEvent*>(evt);
00121         
00122         if (e && e->button() == RightButton) {
00123             SVGStyledTransformableElement::defaultEventHandler(evt);
00124             return;
00125         }
00126         
00127         if (k) {
00128             if (k->keyIdentifier() != "Enter") {
00129                 SVGStyledTransformableElement::defaultEventHandler(evt);
00130                 return;
00131             }
00132             evt->setDefaultHandled();
00133             dispatchSimulatedClick(evt);
00134             return;
00135         }
00136         
00137         String target = this->target();
00138         if (e && e->button() == MiddleButton)
00139             target = "_blank";
00140         else if (target.isEmpty()) // if target is empty, default to "_self" or use xlink:target if set
00141             target = (getAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self";
00142 
00143         if (!evt->defaultPrevented()) {
00144             String url = parseURL(href());
00145 #if ENABLE(SVG_ANIMATION)
00146             if (url.startsWith("#")) {
00147                 Element* targetElement = document()->getElementById(url.substring(1));
00148                 if (SVGSMILElement::isSMILElement(targetElement)) {
00149                     SVGSMILElement* timed = static_cast<SVGSMILElement*>(targetElement);
00150                     timed->beginByLinkActivation();
00151                     evt->setDefaultHandled();
00152                     SVGStyledTransformableElement::defaultEventHandler(evt);
00153                     return;
00154                 }
00155             }
00156 #endif
00157             if (document()->frame())
00158                 document()->frame()->loader()->urlSelected(document()->completeURL(url), target, evt, false, true);
00159         }
00160 
00161         evt->setDefaultHandled();
00162     }*/
00163 
00164     SVGStyledTransformableElement::defaultEventHandler(evt);
00165 }
00166 
00167 bool SVGAElement::supportsFocus() const
00168 {
00169     /*if (isContentEditable())
00170         return SVGStyledTransformableElement::supportsFocus();*/
00171     return isFocusable() || (document() && !document()->haveStylesheetsLoaded());
00172 }
00173 
00174 bool SVGAElement::isFocusable() const
00175 {
00176     if (isContentEditable())
00177         return SVGStyledTransformableElement::isFocusable();
00178     
00179     // FIXME: Even if we are not visible, we might have a child that is visible.
00180     // Dave wants to fix that some day with a "has visible content" flag or the like.
00181     if (!renderer() || !(renderer()->style()->visibility() == VISIBLE))
00182         return false;
00183     
00184     //khtml FIXME return !renderer()->absoluteClippedOverflowRect().isEmpty();
00185     return false;
00186 }
00187 
00188 bool SVGAElement::isMouseFocusable() const
00189 {
00190     return false;
00191 }
00192 
00193 bool SVGAElement::isKeyboardFocusable(KeyboardEvent* event) const
00194 {
00195     if (!isFocusable())
00196         return false;
00197     
00198     if (!document()->view())
00199         return false;
00200     
00201     //khtml FIXME return document()->view()->eventHandler()->tabsToLinks(event);
00202     return false;
00203 }
00204 
00205 bool SVGAElement::childShouldCreateRenderer(Node* child) const
00206 {
00207     // http://www.w3.org/2003/01/REC-SVG11-20030114-errata#linking-text-environment
00208     // The 'a' element may contain any element that its parent may contain, except itself.
00209     if (child->hasTagName(SVGNames::aTag))
00210         return false;
00211     if (parent() && parent()->isSVGElement())
00212         return static_cast<SVGElement*>(parent())->childShouldCreateRenderer(child);
00213 
00214     return SVGElement::childShouldCreateRenderer(child);
00215 }
00216 
00217 } // namespace WebCore
00218 
00219 #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