KHtml

SVGAElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2007 Rob Buis <[email protected]>
4  2007 Eric Seidel <[email protected]>
5 
6  This file is part of the KDE project
7 
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.
12 
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.
17 
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.
22 */
23 
24 #include "wtf/Platform.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGAElement.h"
28 
29 /*#include "Attr.h"
30 #include "CSSHelper.h"*/
31 #include "Document.h"
32 /*#include "EventHandler.h"
33 #include "EventNames.h"
34 #include "Frame.h"
35 #include "FrameLoader.h"
36 #include "KeyboardEvent.h"
37 #include "MouseEvent.h"
38 #include "PlatformMouseEvent.h"*/
39 #include "RenderSVGTransformableContainer.h"
40 #include "RenderSVGInline.h"
41 /*#include "ResourceRequest.h"
42 #include "SVGSMILElement.h"*/
43 #include "SVGNames.h"
44 #include "XLinkNames.h"
45 
46 namespace WebCore
47 {
48 
49 //using namespace EventNames;
50 
51 SVGAElement::SVGAElement(const QualifiedName &tagName, Document *doc)
52  : SVGStyledTransformableElement(tagName, doc)
53  , SVGURIReference()
54  , SVGTests()
55  , SVGLangSpace()
56  , SVGExternalResourcesRequired()
57 {
58 }
59 
60 SVGAElement::~SVGAElement()
61 {
62 }
63 
64 String SVGAElement::title() const
65 {
66  return getAttribute(XLinkNames::titleAttr);
67 }
68 
69 ANIMATED_PROPERTY_DEFINITIONS(SVGAElement, String, String, string, Target, target, SVGNames::targetAttr, m_target)
70 
71 void SVGAElement::parseMappedAttribute(MappedAttribute *attr)
72 {
73  if (attr->name() == SVGNames::targetAttr) {
74  setTargetBaseValue(attr->value());
75  } else {
76  if (SVGURIReference::parseMappedAttribute(attr)) {
77  return;
78  }
79  if (SVGTests::parseMappedAttribute(attr)) {
80  return;
81  }
82  if (SVGLangSpace::parseMappedAttribute(attr)) {
83  return;
84  }
85  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
86  return;
87  }
88  SVGStyledTransformableElement::parseMappedAttribute(attr);
89  }
90 }
91 
92 void SVGAElement::svgAttributeChanged(const QualifiedName &attrName)
93 {
94  SVGStyledTransformableElement::svgAttributeChanged(attrName);
95 
96  // Unlike other SVG*Element classes, SVGAElement only listens to SVGURIReference changes
97  // as none of the other properties changes the linking behaviour for our <a> element.
98  if (SVGURIReference::isKnownAttribute(attrName)) {
99  /*khtml FIXME bool wasLink = m_isLink;
100  m_isLink = !href().isNull();
101 
102  if (wasLink != m_isLink)
103  setChanged();*/
104  }
105 }
106 
107 RenderObject *SVGAElement::createRenderer(RenderArena *arena, RenderStyle *style)
108 {
109  Q_UNUSED(style);
110  if (static_cast<SVGElement *>(parent())->isTextContent()) {
111  return new(arena) RenderSVGInline(this);
112  }
113 
114  return new(arena) RenderSVGTransformableContainer(this);
115 }
116 
117 void SVGAElement::defaultEventHandler(Event *evt)
118 {
119  /*if (m_isLink && (evt->type() == clickEvent || (evt->type() == keydownEvent && m_focused))) {
120  MouseEvent* e = 0;
121  if (evt->type() == clickEvent && evt->isMouseEvent())
122  e = static_cast<MouseEvent*>(evt);
123 
124  KeyboardEvent* k = 0;
125  if (evt->type() == keydownEvent && evt->isKeyboardEvent())
126  k = static_cast<KeyboardEvent*>(evt);
127 
128  if (e && e->button() == RightButton) {
129  SVGStyledTransformableElement::defaultEventHandler(evt);
130  return;
131  }
132 
133  if (k) {
134  if (k->keyIdentifier() != "Enter") {
135  SVGStyledTransformableElement::defaultEventHandler(evt);
136  return;
137  }
138  evt->setDefaultHandled();
139  dispatchSimulatedClick(evt);
140  return;
141  }
142 
143  String target = this->target();
144  if (e && e->button() == MiddleButton)
145  target = "_blank";
146  else if (target.isEmpty()) // if target is empty, default to "_self" or use xlink:target if set
147  target = (getAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self";
148 
149  if (!evt->defaultPrevented()) {
150  String url = parseURL(href());
151  #if ENABLE(SVG_ANIMATION)
152  if (url.startsWith("#")) {
153  Element* targetElement = document()->getElementById(url.substring(1));
154  if (SVGSMILElement::isSMILElement(targetElement)) {
155  SVGSMILElement* timed = static_cast<SVGSMILElement*>(targetElement);
156  timed->beginByLinkActivation();
157  evt->setDefaultHandled();
158  SVGStyledTransformableElement::defaultEventHandler(evt);
159  return;
160  }
161  }
162  #endif
163  if (document()->frame())
164  document()->frame()->loader()->urlSelected(document()->completeURL(url), target, evt, false, true);
165  }
166 
167  evt->setDefaultHandled();
168  }*/
169 
170  SVGStyledTransformableElement::defaultEventHandler(evt);
171 }
172 
173 bool SVGAElement::supportsFocus() const
174 {
175  /*if (isContentEditable())
176  return SVGStyledTransformableElement::supportsFocus();*/
177  return isFocusable() || (document() && !document()->haveStylesheetsLoaded());
178 }
179 
180 bool SVGAElement::isFocusableImpl(FocusType ft) const
181 {
182  if (ft == FT_Mouse) {
183  return false;
184  }
185 
186  if (isContentEditable()) {
187  return SVGStyledTransformableElement::isFocusableImpl(ft);
188  }
189 
190  // TODO: implement focus rules for SVG
191  return false;
192 }
193 
194 bool SVGAElement::childShouldCreateRenderer(Node *child) const
195 {
196  // https://www.w3.org/2003/01/REC-SVG11-20030114-errata#linking-text-environment
197  // The 'a' element may contain any element that its parent may contain, except itself.
198  if (child->hasTagName(SVGNames::aTag)) {
199  return false;
200  }
201  if (parent() && parent()->isSVGElement()) {
202  return static_cast<SVGElement *>(parent())->childShouldCreateRenderer(child);
203  }
204 
205  return SVGElement::childShouldCreateRenderer(child);
206 }
207 
208 } // namespace WebCore
209 
210 #endif // ENABLE(SVG)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.