don't discard iframe children.
[kdelibs.git] / khtml / svg / SVGAElement.cpp
blob8ccea04a9294b8204835b59e21341bf463c0c1b3
1 /*
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.
24 #include "config.h"
25 #include "wtf/Platform.h"
27 #if ENABLE(SVG)
28 #include "SVGAElement.h"
30 /*#include "Attr.h"
31 #include "CSSHelper.h"*/
32 #include "Document.h"
33 /*#include "EventHandler.h"
34 #include "EventNames.h"
35 #include "Frame.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"*/
44 #include "SVGNames.h"
45 #include "XLinkNames.h"
47 namespace WebCore {
49 //using namespace EventNames;
51 SVGAElement::SVGAElement(const QualifiedName& tagName, Document *doc)
52 : SVGStyledTransformableElement(tagName, doc)
53 , SVGURIReference()
54 , SVGTests()
55 , SVGLangSpace()
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());
75 else {
76 if (SVGURIReference::parseMappedAttribute(attr))
77 return;
78 if (SVGTests::parseMappedAttribute(attr))
79 return;
80 if (SVGLangSpace::parseMappedAttribute(attr))
81 return;
82 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
83 return;
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)
99 setChanged();*/
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))) {
114 MouseEvent* e = 0;
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);
124 return;
127 if (k) {
128 if (k->keyIdentifier() != "Enter") {
129 SVGStyledTransformableElement::defaultEventHandler(evt);
130 return;
132 evt->setDefaultHandled();
133 dispatchSimulatedClick(evt);
134 return;
137 String target = this->target();
138 if (e && e->button() == MiddleButton)
139 target = "_blank";
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);
153 return;
156 #endif
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))
182 return false;
184 //khtml FIXME return !renderer()->absoluteClippedOverflowRect().isEmpty();
185 return false;
188 bool SVGAElement::isMouseFocusable() const
190 return false;
193 bool SVGAElement::isKeyboardFocusable(KeyboardEvent* event) const
195 if (!isFocusable())
196 return false;
198 if (!document()->view())
199 return false;
201 //khtml FIXME return document()->view()->eventHandler()->tabsToLinks(event);
202 return false;
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))
210 return false;
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)