1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
/*
Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
2004, 2005, 2007 Rob Buis <buis@kde.org>
2007 Eric Seidel <eric@webkit.org>
This file is part of the KDE project
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "wtf/Platform.h"
#if ENABLE(SVG)
#include "SVGAElement.h"
/*#include "Attr.h"
#include "CSSHelper.h"*/
#include "Document.h"
/*#include "EventHandler.h"
#include "EventNames.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "KeyboardEvent.h"
#include "MouseEvent.h"
#include "PlatformMouseEvent.h"*/
#include "RenderSVGTransformableContainer.h"
#include "RenderSVGInline.h"
/*#include "ResourceRequest.h"
#include "SVGSMILElement.h"*/
#include "SVGNames.h"
#include "XLinkNames.h"
namespace WebCore {
//using namespace EventNames;
SVGAElement::SVGAElement(const QualifiedName& tagName, Document *doc)
: SVGStyledTransformableElement(tagName, doc)
, SVGURIReference()
, SVGTests()
, SVGLangSpace()
, SVGExternalResourcesRequired()
{
}
SVGAElement::~SVGAElement()
{
}
String SVGAElement::title() const
{
return getAttribute(XLinkNames::titleAttr);
}
ANIMATED_PROPERTY_DEFINITIONS(SVGAElement, String, String, string, Target, target, SVGNames::targetAttr, m_target)
void SVGAElement::parseMappedAttribute(MappedAttribute* attr)
{
if (attr->name() == SVGNames::targetAttr)
setTargetBaseValue(attr->value());
else {
if (SVGURIReference::parseMappedAttribute(attr))
return;
if (SVGTests::parseMappedAttribute(attr))
return;
if (SVGLangSpace::parseMappedAttribute(attr))
return;
if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
return;
SVGStyledTransformableElement::parseMappedAttribute(attr);
}
}
void SVGAElement::svgAttributeChanged(const QualifiedName& attrName)
{
SVGStyledTransformableElement::svgAttributeChanged(attrName);
// Unlike other SVG*Element classes, SVGAElement only listens to SVGURIReference changes
// as none of the other properties changes the linking behaviour for our <a> element.
if (SVGURIReference::isKnownAttribute(attrName)) {
/*khtml FIXME bool wasLink = m_isLink;
m_isLink = !href().isNull();
if (wasLink != m_isLink)
setChanged();*/
}
}
RenderObject* SVGAElement::createRenderer(RenderArena* arena, RenderStyle* style)
{
if (static_cast<SVGElement*>(parent())->isTextContent())
return new (arena) RenderSVGInline(this);
return new (arena) RenderSVGTransformableContainer(this);
}
void SVGAElement::defaultEventHandler(Event* evt)
{
/*if (m_isLink && (evt->type() == clickEvent || (evt->type() == keydownEvent && m_focused))) {
MouseEvent* e = 0;
if (evt->type() == clickEvent && evt->isMouseEvent())
e = static_cast<MouseEvent*>(evt);
KeyboardEvent* k = 0;
if (evt->type() == keydownEvent && evt->isKeyboardEvent())
k = static_cast<KeyboardEvent*>(evt);
if (e && e->button() == RightButton) {
SVGStyledTransformableElement::defaultEventHandler(evt);
return;
}
if (k) {
if (k->keyIdentifier() != "Enter") {
SVGStyledTransformableElement::defaultEventHandler(evt);
return;
}
evt->setDefaultHandled();
dispatchSimulatedClick(evt);
return;
}
String target = this->target();
if (e && e->button() == MiddleButton)
target = "_blank";
else if (target.isEmpty()) // if target is empty, default to "_self" or use xlink:target if set
target = (getAttribute(XLinkNames::showAttr) == "new") ? "_blank" : "_self";
if (!evt->defaultPrevented()) {
String url = parseURL(href());
#if ENABLE(SVG_ANIMATION)
if (url.startsWith("#")) {
Element* targetElement = document()->getElementById(url.substring(1));
if (SVGSMILElement::isSMILElement(targetElement)) {
SVGSMILElement* timed = static_cast<SVGSMILElement*>(targetElement);
timed->beginByLinkActivation();
evt->setDefaultHandled();
SVGStyledTransformableElement::defaultEventHandler(evt);
return;
}
}
#endif
if (document()->frame())
document()->frame()->loader()->urlSelected(document()->completeURL(url), target, evt, false, true);
}
evt->setDefaultHandled();
}*/
SVGStyledTransformableElement::defaultEventHandler(evt);
}
bool SVGAElement::supportsFocus() const
{
/*if (isContentEditable())
return SVGStyledTransformableElement::supportsFocus();*/
return isFocusable() || (document() && !document()->haveStylesheetsLoaded());
}
bool SVGAElement::isFocusable() const
{
if (isContentEditable())
return SVGStyledTransformableElement::isFocusable();
// FIXME: Even if we are not visible, we might have a child that is visible.
// Dave wants to fix that some day with a "has visible content" flag or the like.
if (!renderer() || !(renderer()->style()->visibility() == VISIBLE))
return false;
//khtml FIXME return !renderer()->absoluteClippedOverflowRect().isEmpty();
return false;
}
bool SVGAElement::isMouseFocusable() const
{
return false;
}
bool SVGAElement::isKeyboardFocusable(DOM::KeyboardEventImpl* event) const
{
if (!isFocusable())
return false;
if (!document()->view())
return false;
//khtml FIXME return document()->view()->eventHandler()->tabsToLinks(event);
return false;
}
bool SVGAElement::childShouldCreateRenderer(Node* child) const
{
// http://www.w3.org/2003/01/REC-SVG11-20030114-errata#linking-text-environment
// The 'a' element may contain any element that its parent may contain, except itself.
if (child->hasTagName(SVGNames::aTag))
return false;
if (parent() && parent()->isSVGElement())
return static_cast<SVGElement*>(parent())->childShouldCreateRenderer(child);
return SVGElement::childShouldCreateRenderer(child);
}
} // namespace WebCore
#endif // ENABLE(SVG)
|