OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2007 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2010 Apple Inc. All rights reserved. | 5 * Copyright (C) 2010 Apple Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "core/svg/SVGElementInstance.h" | 48 #include "core/svg/SVGElementInstance.h" |
49 #include "core/svg/animation/SVGSMILElement.h" | 49 #include "core/svg/animation/SVGSMILElement.h" |
50 #include "platform/PlatformMouseEvent.h" | 50 #include "platform/PlatformMouseEvent.h" |
51 #include "platform/network/ResourceRequest.h" | 51 #include "platform/network/ResourceRequest.h" |
52 | 52 |
53 namespace WebCore { | 53 namespace WebCore { |
54 | 54 |
55 using namespace HTMLNames; | 55 using namespace HTMLNames; |
56 | 56 |
57 // Animated property definitions | 57 // Animated property definitions |
58 DEFINE_ANIMATED_STRING(SVGAElement, SVGNames::targetAttr, SVGTarget, svgTarget) | |
59 DEFINE_ANIMATED_STRING(SVGAElement, XLinkNames::hrefAttr, Href, href) | |
60 | 58 |
61 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGAElement) | 59 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGAElement) |
62 REGISTER_LOCAL_ANIMATED_PROPERTY(svgTarget) | |
63 REGISTER_LOCAL_ANIMATED_PROPERTY(href) | |
64 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) | 60 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) |
65 END_REGISTER_ANIMATED_PROPERTIES | 61 END_REGISTER_ANIMATED_PROPERTIES |
66 | 62 |
67 inline SVGAElement::SVGAElement(Document& document) | 63 inline SVGAElement::SVGAElement(Document& document) |
68 : SVGGraphicsElement(SVGNames::aTag, document) | 64 : SVGGraphicsElement(SVGNames::aTag, document) |
| 65 , m_svgTarget(SVGAnimatedString::create(this, SVGNames::targetAttr, SVGStrin
g::create())) |
| 66 , m_href(SVGAnimatedString::create(this, XLinkNames::hrefAttr, SVGString::cr
eate())) |
69 { | 67 { |
70 ScriptWrappable::init(this); | 68 ScriptWrappable::init(this); |
| 69 addToPropertyMap(m_svgTarget); |
| 70 addToPropertyMap(m_href); |
71 registerAnimatedPropertiesForSVGAElement(); | 71 registerAnimatedPropertiesForSVGAElement(); |
72 } | 72 } |
73 | 73 |
74 PassRefPtr<SVGAElement> SVGAElement::create(Document& document) | 74 PassRefPtr<SVGAElement> SVGAElement::create(Document& document) |
75 { | 75 { |
76 return adoptRef(new SVGAElement(document)); | 76 return adoptRef(new SVGAElement(document)); |
77 } | 77 } |
78 | 78 |
79 String SVGAElement::title() const | 79 String SVGAElement::title() const |
80 { | 80 { |
(...skipping 16 matching lines...) Expand all Loading... |
97 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); | 97 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); |
98 } | 98 } |
99 | 99 |
100 void SVGAElement::parseAttribute(const QualifiedName& name, const AtomicString&
value) | 100 void SVGAElement::parseAttribute(const QualifiedName& name, const AtomicString&
value) |
101 { | 101 { |
102 if (!isSupportedAttribute(name)) { | 102 if (!isSupportedAttribute(name)) { |
103 SVGGraphicsElement::parseAttribute(name, value); | 103 SVGGraphicsElement::parseAttribute(name, value); |
104 return; | 104 return; |
105 } | 105 } |
106 | 106 |
107 if (name == SVGNames::targetAttr) { | 107 SVGParsingError parseError = NoError; |
108 setSVGTargetBaseValue(value); | |
109 return; | |
110 } | |
111 | 108 |
112 if (SVGURIReference::parseAttribute(name, value)) | 109 if (name == SVGNames::targetAttr) |
113 return; | 110 m_svgTarget->setBaseValueAsString(value, parseError); |
| 111 else if (name.matches(XLinkNames::hrefAttr)) |
| 112 m_href->setBaseValueAsString(value, parseError); |
| 113 else |
| 114 ASSERT_NOT_REACHED(); |
114 | 115 |
115 ASSERT_NOT_REACHED(); | 116 reportAttributeParsingError(parseError, name, value); |
116 } | 117 } |
117 | 118 |
118 void SVGAElement::svgAttributeChanged(const QualifiedName& attrName) | 119 void SVGAElement::svgAttributeChanged(const QualifiedName& attrName) |
119 { | 120 { |
120 if (!isSupportedAttribute(attrName)) { | 121 if (!isSupportedAttribute(attrName)) { |
121 SVGGraphicsElement::svgAttributeChanged(attrName); | 122 SVGGraphicsElement::svgAttributeChanged(attrName); |
122 return; | 123 return; |
123 } | 124 } |
124 | 125 |
125 SVGElementInstance::InvalidationGuard invalidationGuard(this); | 126 SVGElementInstance::InvalidationGuard invalidationGuard(this); |
126 | 127 |
127 // Unlike other SVG*Element classes, SVGAElement only listens to SVGURIRefer
ence changes | 128 // Unlike other SVG*Element classes, SVGAElement only listens to SVGURIRefer
ence changes |
128 // as none of the other properties changes the linking behaviour for our <a>
element. | 129 // as none of the other properties changes the linking behaviour for our <a>
element. |
129 if (SVGURIReference::isKnownAttribute(attrName)) { | 130 if (SVGURIReference::isKnownAttribute(attrName)) { |
130 bool wasLink = isLink(); | 131 bool wasLink = isLink(); |
131 setIsLink(!hrefCurrentValue().isNull()); | 132 setIsLink(!m_href->currentValue()->value().isNull()); |
132 | 133 |
133 if (wasLink != isLink()) | 134 if (wasLink != isLink()) |
134 setNeedsStyleRecalc(); | 135 setNeedsStyleRecalc(); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 RenderObject* SVGAElement::createRenderer(RenderStyle*) | 139 RenderObject* SVGAElement::createRenderer(RenderStyle*) |
139 { | 140 { |
140 if (parentNode() && parentNode()->isSVGElement() && toSVGElement(parentNode(
))->isTextContent()) | 141 if (parentNode() && parentNode()->isSVGElement() && toSVGElement(parentNode(
))->isTextContent()) |
141 return new RenderSVGInline(this); | 142 return new RenderSVGInline(this); |
142 | 143 |
143 return new RenderSVGTransformableContainer(this); | 144 return new RenderSVGTransformableContainer(this); |
144 } | 145 } |
145 | 146 |
146 void SVGAElement::defaultEventHandler(Event* event) | 147 void SVGAElement::defaultEventHandler(Event* event) |
147 { | 148 { |
148 if (isLink()) { | 149 if (isLink()) { |
149 if (focused() && isEnterKeyKeydownEvent(event)) { | 150 if (focused() && isEnterKeyKeydownEvent(event)) { |
150 event->setDefaultHandled(); | 151 event->setDefaultHandled(); |
151 dispatchSimulatedClick(event); | 152 dispatchSimulatedClick(event); |
152 return; | 153 return; |
153 } | 154 } |
154 | 155 |
155 if (isLinkClick(event)) { | 156 if (isLinkClick(event)) { |
156 String url = stripLeadingAndTrailingHTMLSpaces(hrefCurrentValue()); | 157 String url = stripLeadingAndTrailingHTMLSpaces(m_href->currentValue(
)->value()); |
157 | 158 |
158 if (url[0] == '#') { | 159 if (url[0] == '#') { |
159 Element* targetElement = treeScope().getElementById(AtomicString
(url.substring(1))); | 160 Element* targetElement = treeScope().getElementById(AtomicString
(url.substring(1))); |
160 if (targetElement && isSVGSMILElement(*targetElement)) { | 161 if (targetElement && isSVGSMILElement(*targetElement)) { |
161 toSVGSMILElement(targetElement)->beginByLinkActivation(); | 162 toSVGSMILElement(targetElement)->beginByLinkActivation(); |
162 event->setDefaultHandled(); | 163 event->setDefaultHandled(); |
163 return; | 164 return; |
164 } | 165 } |
165 // Only allow navigation to internal <view> anchors. | 166 // Only allow navigation to internal <view> anchors. |
166 if (targetElement && !targetElement->hasTagName(SVGNames::viewTa
g)) | 167 if (targetElement && !targetElement->hasTagName(SVGNames::viewTa
g)) |
167 return; | 168 return; |
168 } | 169 } |
169 | 170 |
170 AtomicString target(svgTargetCurrentValue()); | 171 AtomicString target(m_svgTarget->currentValue()->value()); |
171 if (target.isEmpty() && fastGetAttribute(XLinkNames::showAttr) == "n
ew") | 172 if (target.isEmpty() && fastGetAttribute(XLinkNames::showAttr) == "n
ew") |
172 target = AtomicString("_blank", AtomicString::ConstructFromLiter
al); | 173 target = AtomicString("_blank", AtomicString::ConstructFromLiter
al); |
173 event->setDefaultHandled(); | 174 event->setDefaultHandled(); |
174 | 175 |
175 Frame* frame = document().frame(); | 176 Frame* frame = document().frame(); |
176 if (!frame) | 177 if (!frame) |
177 return; | 178 return; |
178 FrameLoadRequest frameRequest(&document(), ResourceRequest(document(
).completeURL(url)), target); | 179 FrameLoadRequest frameRequest(&document(), ResourceRequest(document(
).completeURL(url)), target); |
179 frameRequest.setTriggeringEvent(event); | 180 frameRequest.setTriggeringEvent(event); |
180 frame->loader().load(frameRequest); | 181 frame->loader().load(frameRequest); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return page->chrome().client().tabsToLinks(); | 220 return page->chrome().client().tabsToLinks(); |
220 return false; | 221 return false; |
221 } | 222 } |
222 | 223 |
223 bool SVGAElement::willRespondToMouseClickEvents() | 224 bool SVGAElement::willRespondToMouseClickEvents() |
224 { | 225 { |
225 return isLink() || SVGGraphicsElement::willRespondToMouseClickEvents(); | 226 return isLink() || SVGGraphicsElement::willRespondToMouseClickEvents(); |
226 } | 227 } |
227 | 228 |
228 } // namespace WebCore | 229 } // namespace WebCore |
OLD | NEW |