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 Q_UNUSED(style); 00106 if (static_cast<SVGElement*>(parent())->isTextContent()) 00107 return new (arena) RenderSVGInline(this); 00108 00109 return new (arena) RenderSVGTransformableContainer(this); 00110 } 00111 00112 void SVGAElement::defaultEventHandler(Event* evt) 00113 { 00114 /*if (m_isLink && (evt->type() == clickEvent || (evt->type() == keydownEvent && m_focused))) { 00115 MouseEvent* e = 0; 00116 if (evt->type() == clickEvent && evt->isMouseEvent()) 00117 e = static_cast<MouseEvent*>(evt); 00118 00119 KeyboardEvent* k = 0; 00120 if (evt->type() == keydownEvent && evt->isKeyboardEvent()) 00121 k = static_cast<KeyboardEvent*>(evt); 00122 00123 if (e && e->button() == RightButton) { 00124 SVGStyledTransformableElement::defaultEventHandler(evt); 00125 return; 00126 } 00127 00128 if (k) { 00129 if (k->keyIdentifier() != "Enter") { 00130 SVGStyledTransformableElement::defaultEventHandler(evt); 00131 return; 00132 } 00133 evt->setDefaultHandled(); 00134 dispatchSimulatedClick(evt); 00135 return; 00136 } 00137 00138 String target = this->target(); 00139 if (e && e->button() == MiddleButton) 00140 target = "_blank"; 00141 else if (target.isEmpty()) // if target is empty, default to "_self" or use xlink:target if set 00142 target = (getAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self"; 00143 00144 if (!evt->defaultPrevented()) { 00145 String url = parseURL(href()); 00146 #if ENABLE(SVG_ANIMATION) 00147 if (url.startsWith("#")) { 00148 Element* targetElement = document()->getElementById(url.substring(1)); 00149 if (SVGSMILElement::isSMILElement(targetElement)) { 00150 SVGSMILElement* timed = static_cast<SVGSMILElement*>(targetElement); 00151 timed->beginByLinkActivation(); 00152 evt->setDefaultHandled(); 00153 SVGStyledTransformableElement::defaultEventHandler(evt); 00154 return; 00155 } 00156 } 00157 #endif 00158 if (document()->frame()) 00159 document()->frame()->loader()->urlSelected(document()->completeURL(url), target, evt, false, true); 00160 } 00161 00162 evt->setDefaultHandled(); 00163 }*/ 00164 00165 SVGStyledTransformableElement::defaultEventHandler(evt); 00166 } 00167 00168 bool SVGAElement::supportsFocus() const 00169 { 00170 /*if (isContentEditable()) 00171 return SVGStyledTransformableElement::supportsFocus();*/ 00172 return isFocusable() || (document() && !document()->haveStylesheetsLoaded()); 00173 } 00174 00175 bool SVGAElement::isFocusable() const 00176 { 00177 if (isContentEditable()) 00178 return SVGStyledTransformableElement::isFocusable(); 00179 00180 // FIXME: Even if we are not visible, we might have a child that is visible. 00181 // Dave wants to fix that some day with a "has visible content" flag or the like. 00182 if (!renderer() || !(renderer()->style()->visibility() == VISIBLE)) 00183 return false; 00184 00185 //khtml FIXME return !renderer()->absoluteClippedOverflowRect().isEmpty(); 00186 return false; 00187 } 00188 00189 bool SVGAElement::isMouseFocusable() const 00190 { 00191 return false; 00192 } 00193 00194 bool SVGAElement::isKeyboardFocusable(DOM::KeyboardEventImpl* event) const 00195 { 00196 Q_UNUSED(event); 00197 if (!isFocusable()) 00198 return false; 00199 00200 if (!document()->view()) 00201 return false; 00202 00203 //khtml FIXME return document()->view()->eventHandler()->tabsToLinks(event); 00204 return false; 00205 } 00206 00207 bool SVGAElement::childShouldCreateRenderer(Node* child) const 00208 { 00209 // http://www.w3.org/2003/01/REC-SVG11-20030114-errata#linking-text-environment 00210 // The 'a' element may contain any element that its parent may contain, except itself. 00211 if (child->hasTagName(SVGNames::aTag)) 00212 return false; 00213 if (parent() && parent()->isSVGElement()) 00214 return static_cast<SVGElement*>(parent())->childShouldCreateRenderer(child); 00215 00216 return SVGElement::childShouldCreateRenderer(child); 00217 } 00218 00219 } // namespace WebCore 00220 00221 #endif // ENABLE(SVG)
KDE 4.6 API Reference