1 /**********************************************
2 * Copyright (C) 2010-2011 Lukas Laag
3 * This file is part of lib-gwt-svg.
4 *
5 * libgwtsvg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * libgwtsvg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/
17 **********************************************/
18 /*
19 * Copyright (c) 2004 World Wide Web Consortium,
20 *
21 * (Massachusetts Institute of Technology, European Research Consortium for
22 * Informatics and Mathematics, Keio University). All Rights Reserved. This
23 * work is distributed under the W3C(r) Software License [1] in the hope that
24 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 *
27 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
28 */
29
30 package org.vectomatic.dom.svg;
31
32 import org.vectomatic.dom.svg.events.ActivateEvent;
33 import org.vectomatic.dom.svg.events.ActivateHandler;
34 import org.vectomatic.dom.svg.events.FocusInEvent;
35 import org.vectomatic.dom.svg.events.FocusInHandler;
36 import org.vectomatic.dom.svg.events.FocusOutEvent;
37 import org.vectomatic.dom.svg.events.FocusOutHandler;
38 import org.vectomatic.dom.svg.events.HasGraphicalHandlers;
39 import org.vectomatic.dom.svg.impl.SVGAElement;
40 import org.vectomatic.dom.svg.impl.SVGElement;
41 import org.vectomatic.dom.svg.itf.ISVGContainerElement;
42 import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired;
43 import org.vectomatic.dom.svg.itf.ISVGLangSpace;
44 import org.vectomatic.dom.svg.itf.ISVGStylable;
45 import org.vectomatic.dom.svg.itf.ISVGTests;
46 import org.vectomatic.dom.svg.itf.ISVGTransformable;
47 import org.vectomatic.dom.svg.itf.ISVGURIReference;
48 import org.vectomatic.dom.svg.utils.DOMHelper;
49 import org.vectomatic.dom.svg.utils.SVGConstants;
50
51 import com.google.gwt.core.client.JavaScriptException;
52 import com.google.gwt.dom.client.TagName;
53 import com.google.gwt.event.dom.client.ClickEvent;
54 import com.google.gwt.event.dom.client.ClickHandler;
55 import com.google.gwt.event.dom.client.LoadEvent;
56 import com.google.gwt.event.dom.client.LoadHandler;
57 import com.google.gwt.event.dom.client.MouseDownEvent;
58 import com.google.gwt.event.dom.client.MouseDownHandler;
59 import com.google.gwt.event.dom.client.MouseMoveEvent;
60 import com.google.gwt.event.dom.client.MouseMoveHandler;
61 import com.google.gwt.event.dom.client.MouseOutEvent;
62 import com.google.gwt.event.dom.client.MouseOutHandler;
63 import com.google.gwt.event.dom.client.MouseOverEvent;
64 import com.google.gwt.event.dom.client.MouseOverHandler;
65 import com.google.gwt.event.dom.client.MouseUpEvent;
66 import com.google.gwt.event.dom.client.MouseUpHandler;
67 import com.google.gwt.event.dom.client.TouchCancelEvent;
68 import com.google.gwt.event.dom.client.TouchCancelHandler;
69 import com.google.gwt.event.dom.client.TouchEndEvent;
70 import com.google.gwt.event.dom.client.TouchEndHandler;
71 import com.google.gwt.event.dom.client.TouchMoveEvent;
72 import com.google.gwt.event.dom.client.TouchMoveHandler;
73 import com.google.gwt.event.dom.client.TouchStartEvent;
74 import com.google.gwt.event.dom.client.TouchStartHandler;
75 import com.google.gwt.event.shared.HandlerRegistration;
76
77 /**
78 * The {@link org.vectomatic.dom.svg.OMSVGAElement} interface corresponds
79 * to the <a href='http://www.w3.org/TR/SVG11/linking.html#AElement' title='a
80 * element specification'>a</a> element.
81 */
82 @TagName("a")
83 public class OMSVGAElement extends OMSVGElement implements HasGraphicalHandlers, ISVGURIReference, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable, ISVGTransformable, ISVGContainerElement {
84 public OMSVGAElement() {
85 this((SVGAElement)DOMHelper.createElementNS(DOMHelper.getCurrentDocument(), SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG).cast());
86 }
87
88 protected OMSVGAElement(SVGAElement ot) {
89 super(ot);
90 }
91
92 // Implementation of the svg::SVGAElement W3C IDL interface
93 /**
94 * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGAElement#getTarget()}
95 * on the given <a href='http://www.w3.org/TR/SVG11/linking.html#AElement'
96 * title='a element specification'>a</a> element.
97 */
98 public final OMSVGAnimatedString getTarget() {
99 return ((SVGAElement)ot).getTarget();
100 }
101
102 // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface
103 /**
104 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
105 * on the given element. Note that the SVG DOM defines the attribute {@link
106 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
107 * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas
108 * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
109 * is not animated. Because the SVG language definition states that {@link
110 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
111 * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()}
112 * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}.
113 */
114 public final OMSVGAnimatedBoolean getExternalResourcesRequired() {
115 return ((SVGAElement)ot).getExternalResourcesRequired();
116 }
117
118 // Implementation of the svg::SVGLangSpace W3C IDL interface
119 /**
120 * Corresponds to attribute <code>xml:lang</code> on the given element.
121 */
122 public final String getXmllang() {
123 return ((SVGAElement)ot).getXmllang();
124 }
125 /**
126 * Corresponds to attribute <code>xml:lang</code> on the given element.
127 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt
128 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
129 * attribute</a>.
130 */
131 public final void setXmllang(java.lang.String value) throws JavaScriptException {
132 ((SVGAElement)ot).setXmllang(value);
133 }
134 /**
135 * Corresponds to attribute <code>xml:space</code> on the given element.
136 */
137 public final String getXmlspace() {
138 return ((SVGAElement)ot).getXmlspace();
139 }
140 /**
141 * Corresponds to attribute <code>xml:space</code> on the given element.
142 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt
143 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
144 * attribute</a>.
145 */
146 public final void setXmlspace(java.lang.String value) throws JavaScriptException {
147 ((SVGAElement)ot).setXmlspace(value);
148 }
149
150 // Implementation of the svg::SVGLocatable W3C IDL interface
151 /**
152 * The element which established the current viewport. Often, the nearest
153 * ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' title='svg
154 * element specification'>svg</a> element. Null if the current element is
155 * the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
156 * title='svg element specification'>svg</a> element.
157 */
158 public final OMSVGElement getNearestViewportElement() {
159 return (OMSVGElement)convert(((SVGAElement)ot).getNearestViewportElement());
160 }
161 /**
162 * The farthest ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
163 * title='svg element specification'>svg</a> element. Null if the current
164 * element is the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
165 * title='svg element specification'>svg</a> element.
166 */
167 public final OMSVGElement getFarthestViewportElement() {
168 return (OMSVGElement)convert(((SVGAElement)ot).getFarthestViewportElement());
169 }
170 /**
171 * Returns the tight bounding box in current user space (i.e., after application
172 * of the <code>transform</code> attribute, if any) on the geometry of all
173 * contained graphics elements, exclusive of stroking, clipping, masking and
174 * filter effects). Note that getBBox must return the actual bounding box
175 * at the time the method was called, even in case the element has not yet
176 * been rendered.
177 * @return An {@link org.vectomatic.dom.svg.OMSVGRect} object that defines
178 * the bounding box.
179 */
180 public final OMSVGRect getBBox() {
181 return ((SVGAElement)ot).getBBox();
182 }
183 /**
184 * Returns the transformation matrix from current user units (i.e., after
185 * application of the <code>transform</code> attribute, if any) to the viewport
186 * coordinate system for the {@link org.vectomatic.dom.svg.itf.ISVGLocatable#getNearestViewportElement()}.
187 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
188 * the CTM.
189 */
190 public final OMSVGMatrix getCTM() {
191 return ((SVGAElement)ot).getCTM();
192 }
193 /**
194 * Returns the transformation matrix from current user units (i.e., after
195 * application of the <code>transform</code> attribute, if any) to the parent
196 * user agent's notice of a "pixel". For display devices, ideally this represents
197 * a physical screen pixel. For other devices or environments where physical
198 * pixel sizes are not known, then an algorithm similar to the CSS2 definition
199 * of a "pixel" can be used instead. Note that null is returned if this element
200 * is not hooked into the document tree. This method would have been more
201 * aptly named as <code>getClientCTM</code>, but the name <code>getScreenCTM</code>
202 * is kept for historical reasons.
203 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
204 * the given transformation matrix.
205 */
206 public final OMSVGMatrix getScreenCTM() {
207 return ((SVGAElement)ot).getScreenCTM();
208 }
209 /**
210 * Returns the transformation matrix from the user coordinate system on the
211 * current element (after application of the <code>transform</code> attribute,
212 * if any) to the user coordinate system on parameter <var>element</var> (after
213 * application of its <code>transform</code> attribute, if any).
214 * @param element The target element.
215 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
216 * the transformation.
217 * @throws SVGException(SVG_MATRIX_NOT_INVERTABLE) Raised if the currently
218 * defined transformation matrices make it impossible to compute the given
219 * matrix (e.g., because one of the transformations is singular).
220 */
221 public final OMSVGMatrix getTransformToElement(OMSVGElement element) throws JavaScriptException {
222 return ((SVGAElement)ot).getTransformToElement(((SVGElement)element.ot));
223 }
224
225 // Implementation of the svg::SVGTests W3C IDL interface
226 /**
227 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()}
228 * on the given element.
229 */
230 public final OMSVGStringList getRequiredFeatures() {
231 return ((SVGAElement)ot).getRequiredFeatures();
232 }
233 /**
234 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()}
235 * on the given element.
236 */
237 public final OMSVGStringList getRequiredExtensions() {
238 return ((SVGAElement)ot).getRequiredExtensions();
239 }
240 /**
241 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()}
242 * on the given element.
243 */
244 public final OMSVGStringList getSystemLanguage() {
245 return ((SVGAElement)ot).getSystemLanguage();
246 }
247 /**
248 * Returns true if the user agent supports the given extension, specified
249 * by a URI.
250 * @param extension The name of the extension, expressed as a URI.
251 * @return True or false, depending on whether the given extension is supported.
252 */
253 public final boolean hasExtension(String extension) {
254 return ((SVGAElement)ot).hasExtension(extension);
255 }
256
257 // Implementation of the svg::SVGTransformable W3C IDL interface
258 /**
259 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTransformable#getTransform()}
260 * on the given element.
261 */
262 public final OMSVGAnimatedTransformList getTransform() {
263 return ((SVGAElement)ot).getTransform();
264 }
265
266 // Implementation of the svg::SVGURIReference W3C IDL interface
267 /**
268 * Corresponds to attribute <span class='attr-name'>'xlink:href'</span> on
269 * the given element.
270 */
271 public final OMSVGAnimatedString getHref() {
272 return ((SVGAElement)ot).getHref();
273 }
274
275 @Override
276 public final HandlerRegistration addClickHandler(ClickHandler handler) {
277 return addDomHandler(handler, ClickEvent.getType());
278 }
279 @Override
280 public final HandlerRegistration addLoadHandler(LoadHandler handler) {
281 return addDomHandler(handler, LoadEvent.getType());
282 }
283 @Override
284 public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
285 return addDomHandler(handler, MouseDownEvent.getType());
286 }
287 @Override
288 public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
289 return addDomHandler(handler, MouseMoveEvent.getType());
290 }
291 @Override
292 public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
293 return addDomHandler(handler, MouseOutEvent.getType());
294 }
295 @Override
296 public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
297 return addDomHandler(handler, MouseOverEvent.getType());
298 }
299 @Override
300 public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
301 return addDomHandler(handler, MouseUpEvent.getType());
302 }
303 @Override
304 public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
305 return addDomHandler(handler, TouchCancelEvent.getType());
306 }
307 @Override
308 public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
309 return addDomHandler(handler, TouchEndEvent.getType());
310 }
311 @Override
312 public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
313 return addDomHandler(handler, TouchMoveEvent.getType());
314 }
315 @Override
316 public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
317 return addDomHandler(handler, TouchStartEvent.getType());
318 }
319 @Override
320 public final HandlerRegistration addActivateHandler(ActivateHandler handler) {
321 return addDomHandler(handler, ActivateEvent.getType());
322 }
323 @Override
324 public final HandlerRegistration addFocusInHandler(FocusInHandler handler) {
325 return addDomHandler(handler, FocusInEvent.getType());
326 }
327 @Override
328 public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) {
329 return addDomHandler(handler, FocusOutEvent.getType());
330 }
331 }