2 Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2007 Rob Buis <buis@kde.org>
4 2007 Eric Seidel <eric@webkit.org>
6 This file is part of the KDE project
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
25 #include "wtf/Platform.h"
28 #include "SVGAElement.h"
31 #include "CSSHelper.h"*/
33 /*#include "EventHandler.h"
34 #include "EventNames.h"
36 #include "FrameLoader.h"
37 #include "KeyboardEvent.h"
38 #include "MouseEvent.h"
39 #include "PlatformMouseEvent.h"*/
40 #include "RenderSVGTransformableContainer.h"
41 #include "RenderSVGInline.h"
42 /*#include "ResourceRequest.h"
43 #include "SVGSMILElement.h"*/
45 #include "XLinkNames.h"
49 //using namespace EventNames;
51 SVGAElement::SVGAElement(const QualifiedName
& tagName
, Document
*doc
)
52 : SVGStyledTransformableElement(tagName
, doc
)
56 , SVGExternalResourcesRequired()
60 SVGAElement::~SVGAElement()
64 String
SVGAElement::title() const
66 return getAttribute(XLinkNames::titleAttr
);
69 ANIMATED_PROPERTY_DEFINITIONS(SVGAElement
, String
, String
, string
, Target
, target
, SVGNames::targetAttr
, m_target
)
71 void SVGAElement::parseMappedAttribute(MappedAttribute
* attr
)
73 if (attr
->name() == SVGNames::targetAttr
)
74 setTargetBaseValue(attr
->value());
76 if (SVGURIReference::parseMappedAttribute(attr
))
78 if (SVGTests::parseMappedAttribute(attr
))
80 if (SVGLangSpace::parseMappedAttribute(attr
))
82 if (SVGExternalResourcesRequired::parseMappedAttribute(attr
))
84 SVGStyledTransformableElement::parseMappedAttribute(attr
);
88 void SVGAElement::svgAttributeChanged(const QualifiedName
& attrName
)
90 SVGStyledTransformableElement::svgAttributeChanged(attrName
);
92 // Unlike other SVG*Element classes, SVGAElement only listens to SVGURIReference changes
93 // as none of the other properties changes the linking behaviour for our <a> element.
94 if (SVGURIReference::isKnownAttribute(attrName
)) {
95 /*khtml FIXME bool wasLink = m_isLink;
96 m_isLink = !href().isNull();
98 if (wasLink != m_isLink)
103 RenderObject
* SVGAElement::createRenderer(RenderArena
* arena
, RenderStyle
* style
)
105 if (static_cast<SVGElement
*>(parent())->isTextContent())
106 return new (arena
) RenderSVGInline(this);
108 return new (arena
) RenderSVGTransformableContainer(this);
111 void SVGAElement::defaultEventHandler(Event
* evt
)
113 /*if (m_isLink && (evt->type() == clickEvent || (evt->type() == keydownEvent && m_focused))) {
115 if (evt->type() == clickEvent && evt->isMouseEvent())
116 e = static_cast<MouseEvent*>(evt);
118 KeyboardEvent* k = 0;
119 if (evt->type() == keydownEvent && evt->isKeyboardEvent())
120 k = static_cast<KeyboardEvent*>(evt);
122 if (e && e->button() == RightButton) {
123 SVGStyledTransformableElement::defaultEventHandler(evt);
128 if (k->keyIdentifier() != "Enter") {
129 SVGStyledTransformableElement::defaultEventHandler(evt);
132 evt->setDefaultHandled();
133 dispatchSimulatedClick(evt);
137 String target = this->target();
138 if (e && e->button() == MiddleButton)
140 else if (target.isEmpty()) // if target is empty, default to "_self" or use xlink:target if set
141 target = (getAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self";
143 if (!evt->defaultPrevented()) {
144 String url = parseURL(href());
145 #if ENABLE(SVG_ANIMATION)
146 if (url.startsWith("#")) {
147 Element* targetElement = document()->getElementById(url.substring(1));
148 if (SVGSMILElement::isSMILElement(targetElement)) {
149 SVGSMILElement* timed = static_cast<SVGSMILElement*>(targetElement);
150 timed->beginByLinkActivation();
151 evt->setDefaultHandled();
152 SVGStyledTransformableElement::defaultEventHandler(evt);
157 if (document()->frame())
158 document()->frame()->loader()->urlSelected(document()->completeURL(url), target, evt, false, true);
161 evt->setDefaultHandled();
164 SVGStyledTransformableElement::defaultEventHandler(evt
);
167 bool SVGAElement::supportsFocus() const
169 /*if (isContentEditable())
170 return SVGStyledTransformableElement::supportsFocus();*/
171 return isFocusable() || (document() && !document()->haveStylesheetsLoaded());
174 bool SVGAElement::isFocusable() const
176 if (isContentEditable())
177 return SVGStyledTransformableElement::isFocusable();
179 // FIXME: Even if we are not visible, we might have a child that is visible.
180 // Dave wants to fix that some day with a "has visible content" flag or the like.
181 if (!renderer() || !(renderer()->style()->visibility() == VISIBLE
))
184 //khtml FIXME return !renderer()->absoluteClippedOverflowRect().isEmpty();
188 bool SVGAElement::isMouseFocusable() const
193 bool SVGAElement::isKeyboardFocusable(KeyboardEvent
* event
) const
198 if (!document()->view())
201 //khtml FIXME return document()->view()->eventHandler()->tabsToLinks(event);
205 bool SVGAElement::childShouldCreateRenderer(Node
* child
) const
207 // http://www.w3.org/2003/01/REC-SVG11-20030114-errata#linking-text-environment
208 // The 'a' element may contain any element that its parent may contain, except itself.
209 if (child
->hasTagName(SVGNames::aTag
))
211 if (parent() && parent()->isSVGElement())
212 return static_cast<SVGElement
*>(parent())->childShouldCreateRenderer(child
);
214 return SVGElement::childShouldCreateRenderer(child
);
217 } // namespace WebCore
219 #endif // ENABLE(SVG)