001/********************************************** 002 * Copyright (C) 2010-2011 Lukas Laag 003 * This file is part of lib-gwt-svg. 004 * 005 * libgwtsvg is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * libgwtsvg is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/ 017 **********************************************/ 018/* 019 * Copyright (c) 2004 World Wide Web Consortium, 020 * 021 * (Massachusetts Institute of Technology, European Research Consortium for 022 * Informatics and Mathematics, Keio University). All Rights Reserved. This 023 * work is distributed under the W3C(r) Software License [1] in the hope that 024 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied 025 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 026 * 027 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 028 */ 029 030package org.vectomatic.dom.svg; 031 032import org.vectomatic.dom.svg.events.ActivateEvent; 033import org.vectomatic.dom.svg.events.ActivateHandler; 034import org.vectomatic.dom.svg.events.FocusInEvent; 035import org.vectomatic.dom.svg.events.FocusInHandler; 036import org.vectomatic.dom.svg.events.FocusOutEvent; 037import org.vectomatic.dom.svg.events.FocusOutHandler; 038import org.vectomatic.dom.svg.events.HasGraphicalHandlers; 039import org.vectomatic.dom.svg.impl.SVGAElement; 040import org.vectomatic.dom.svg.impl.SVGElement; 041import org.vectomatic.dom.svg.itf.ISVGContainerElement; 042import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired; 043import org.vectomatic.dom.svg.itf.ISVGLangSpace; 044import org.vectomatic.dom.svg.itf.ISVGStylable; 045import org.vectomatic.dom.svg.itf.ISVGTests; 046import org.vectomatic.dom.svg.itf.ISVGTransformable; 047import org.vectomatic.dom.svg.itf.ISVGURIReference; 048import org.vectomatic.dom.svg.utils.DOMHelper; 049import org.vectomatic.dom.svg.utils.SVGConstants; 050 051import com.google.gwt.core.client.JavaScriptException; 052import com.google.gwt.dom.client.TagName; 053import com.google.gwt.event.dom.client.ClickEvent; 054import com.google.gwt.event.dom.client.ClickHandler; 055import com.google.gwt.event.dom.client.DragEndEvent; 056import com.google.gwt.event.dom.client.DragEndHandler; 057import com.google.gwt.event.dom.client.DragEnterEvent; 058import com.google.gwt.event.dom.client.DragEnterHandler; 059import com.google.gwt.event.dom.client.DragEvent; 060import com.google.gwt.event.dom.client.DragHandler; 061import com.google.gwt.event.dom.client.DragLeaveEvent; 062import com.google.gwt.event.dom.client.DragLeaveHandler; 063import com.google.gwt.event.dom.client.DragOverEvent; 064import com.google.gwt.event.dom.client.DragOverHandler; 065import com.google.gwt.event.dom.client.DragStartEvent; 066import com.google.gwt.event.dom.client.DragStartHandler; 067import com.google.gwt.event.dom.client.DropEvent; 068import com.google.gwt.event.dom.client.DropHandler; 069import com.google.gwt.event.dom.client.LoadEvent; 070import com.google.gwt.event.dom.client.LoadHandler; 071import com.google.gwt.event.dom.client.MouseDownEvent; 072import com.google.gwt.event.dom.client.MouseDownHandler; 073import com.google.gwt.event.dom.client.MouseMoveEvent; 074import com.google.gwt.event.dom.client.MouseMoveHandler; 075import com.google.gwt.event.dom.client.MouseOutEvent; 076import com.google.gwt.event.dom.client.MouseOutHandler; 077import com.google.gwt.event.dom.client.MouseOverEvent; 078import com.google.gwt.event.dom.client.MouseOverHandler; 079import com.google.gwt.event.dom.client.MouseUpEvent; 080import com.google.gwt.event.dom.client.MouseUpHandler; 081import com.google.gwt.event.dom.client.TouchCancelEvent; 082import com.google.gwt.event.dom.client.TouchCancelHandler; 083import com.google.gwt.event.dom.client.TouchEndEvent; 084import com.google.gwt.event.dom.client.TouchEndHandler; 085import com.google.gwt.event.dom.client.TouchMoveEvent; 086import com.google.gwt.event.dom.client.TouchMoveHandler; 087import com.google.gwt.event.dom.client.TouchStartEvent; 088import com.google.gwt.event.dom.client.TouchStartHandler; 089import com.google.gwt.event.shared.HandlerRegistration; 090 091/** 092 * The {@link org.vectomatic.dom.svg.OMSVGAElement} interface corresponds 093 * to the <a href='http://www.w3.org/TR/SVG11/linking.html#AElement' title='a 094 * element specification'>a</a> element. 095 */ 096@TagName("a") 097public class OMSVGAElement extends OMSVGElement implements HasGraphicalHandlers, ISVGURIReference, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable, ISVGTransformable, ISVGContainerElement { 098 public OMSVGAElement() { 099 this((SVGAElement)DOMHelper.createElementNS(DOMHelper.getCurrentDocument(), SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_A_TAG).cast()); 100 } 101 102 protected OMSVGAElement(SVGAElement ot) { 103 super(ot); 104 } 105 106 // Implementation of the svg::SVGAElement W3C IDL interface 107 /** 108 * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGAElement#getTarget()} 109 * on the given <a href='http://www.w3.org/TR/SVG11/linking.html#AElement' 110 * title='a element specification'>a</a> element. 111 */ 112 public final OMSVGAnimatedString getTarget() { 113 return ((SVGAElement)ot).getTarget(); 114 } 115 116 // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface 117 /** 118 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 119 * on the given element. Note that the SVG DOM defines the attribute {@link 120 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 121 * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas 122 * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 123 * is not animated. Because the SVG language definition states that {@link 124 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 125 * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()} 126 * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}. 127 */ 128 public final OMSVGAnimatedBoolean getExternalResourcesRequired() { 129 return ((SVGAElement)ot).getExternalResourcesRequired(); 130 } 131 132 // Implementation of the svg::SVGLangSpace W3C IDL interface 133 /** 134 * Corresponds to attribute <code>xml:lang</code> on the given element. 135 */ 136 public final String getXmllang() { 137 return ((SVGAElement)ot).getXmllang(); 138 } 139 /** 140 * Corresponds to attribute <code>xml:lang</code> on the given element. 141 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt 142 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only 143 * attribute</a>. 144 */ 145 public final void setXmllang(java.lang.String value) throws JavaScriptException { 146 ((SVGAElement)ot).setXmllang(value); 147 } 148 /** 149 * Corresponds to attribute <code>xml:space</code> on the given element. 150 */ 151 public final String getXmlspace() { 152 return ((SVGAElement)ot).getXmlspace(); 153 } 154 /** 155 * Corresponds to attribute <code>xml:space</code> on the given element. 156 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt 157 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only 158 * attribute</a>. 159 */ 160 public final void setXmlspace(java.lang.String value) throws JavaScriptException { 161 ((SVGAElement)ot).setXmlspace(value); 162 } 163 164 // Implementation of the svg::SVGLocatable W3C IDL interface 165 /** 166 * The element which established the current viewport. Often, the nearest 167 * ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' title='svg 168 * element specification'>svg</a> element. Null if the current element is 169 * the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' 170 * title='svg element specification'>svg</a> element. 171 */ 172 public final OMSVGElement getNearestViewportElement() { 173 SVGElement elt = ((SVGAElement)ot).getNearestViewportElement(); 174 return elt != null ? (OMSVGElement)convert(elt) : null; 175 } 176 /** 177 * The farthest ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' 178 * title='svg element specification'>svg</a> element. Null if the current 179 * element is the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' 180 * title='svg element specification'>svg</a> element. 181 */ 182 public final OMSVGElement getFarthestViewportElement() { 183 SVGElement elt = ((SVGAElement)ot).getFarthestViewportElement(); 184 return elt != null ? (OMSVGElement)convert(elt) : null; 185 } 186 /** 187 * Returns the tight bounding box in current user space (i.e., after application 188 * of the <code>transform</code> attribute, if any) on the geometry of all 189 * contained graphics elements, exclusive of stroking, clipping, masking and 190 * filter effects). Note that getBBox must return the actual bounding box 191 * at the time the method was called, even in case the element has not yet 192 * been rendered. 193 * @return An {@link org.vectomatic.dom.svg.OMSVGRect} object that defines 194 * the bounding box. 195 */ 196 public final OMSVGRect getBBox() { 197 return ((SVGAElement)ot).getBBox(); 198 } 199 /** 200 * Returns the transformation matrix from current user units (i.e., after 201 * application of the <code>transform</code> attribute, if any) to the viewport 202 * coordinate system for the {@link org.vectomatic.dom.svg.itf.ISVGLocatable#getNearestViewportElement()}. 203 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines 204 * the CTM. 205 */ 206 public final OMSVGMatrix getCTM() { 207 return ((SVGAElement)ot).getCTM(); 208 } 209 /** 210 * Returns the transformation matrix from current user units (i.e., after 211 * application of the <code>transform</code> attribute, if any) to the parent 212 * user agent's notice of a "pixel". For display devices, ideally this represents 213 * a physical screen pixel. For other devices or environments where physical 214 * pixel sizes are not known, then an algorithm similar to the CSS2 definition 215 * of a "pixel" can be used instead. Note that null is returned if this element 216 * is not hooked into the document tree. This method would have been more 217 * aptly named as <code>getClientCTM</code>, but the name <code>getScreenCTM</code> 218 * is kept for historical reasons. 219 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines 220 * the given transformation matrix. 221 */ 222 public final OMSVGMatrix getScreenCTM() { 223 return ((SVGAElement)ot).getScreenCTM(); 224 } 225 /** 226 * Returns the transformation matrix from the user coordinate system on the 227 * current element (after application of the <code>transform</code> attribute, 228 * if any) to the user coordinate system on parameter <var>element</var> (after 229 * application of its <code>transform</code> attribute, if any). 230 * @param element The target element. 231 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines 232 * the transformation. 233 * @throws SVGException(SVG_MATRIX_NOT_INVERTABLE) Raised if the currently 234 * defined transformation matrices make it impossible to compute the given 235 * matrix (e.g., because one of the transformations is singular). 236 */ 237 public final OMSVGMatrix getTransformToElement(OMSVGElement element) throws JavaScriptException { 238 return ((SVGAElement)ot).getTransformToElement(((SVGElement)element.ot)); 239 } 240 241 // Implementation of the svg::SVGTests W3C IDL interface 242 /** 243 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()} 244 * on the given element. 245 */ 246 public final OMSVGStringList getRequiredFeatures() { 247 return ((SVGAElement)ot).getRequiredFeatures(); 248 } 249 /** 250 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()} 251 * on the given element. 252 */ 253 public final OMSVGStringList getRequiredExtensions() { 254 return ((SVGAElement)ot).getRequiredExtensions(); 255 } 256 /** 257 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()} 258 * on the given element. 259 */ 260 public final OMSVGStringList getSystemLanguage() { 261 return ((SVGAElement)ot).getSystemLanguage(); 262 } 263 /** 264 * Returns true if the user agent supports the given extension, specified 265 * by a URI. 266 * @param extension The name of the extension, expressed as a URI. 267 * @return True or false, depending on whether the given extension is supported. 268 */ 269 public final boolean hasExtension(String extension) { 270 return ((SVGAElement)ot).hasExtension(extension); 271 } 272 273 // Implementation of the svg::SVGTransformable W3C IDL interface 274 /** 275 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTransformable#getTransform()} 276 * on the given element. 277 */ 278 public final OMSVGAnimatedTransformList getTransform() { 279 return ((SVGAElement)ot).getTransform(); 280 } 281 282 // Implementation of the svg::SVGURIReference W3C IDL interface 283 /** 284 * Corresponds to attribute <span class='attr-name'>'xlink:href'</span> on 285 * the given element. 286 */ 287 public final OMSVGAnimatedString getHref() { 288 return ((SVGAElement)ot).getHref(); 289 } 290 291 @Override 292 public final HandlerRegistration addClickHandler(ClickHandler handler) { 293 return addDomHandler(handler, ClickEvent.getType()); 294 } 295 @Override 296 public final HandlerRegistration addDragEndHandler(DragEndHandler handler) { 297 return addDomHandler(handler, DragEndEvent.getType()); 298 } 299 @Override 300 public final HandlerRegistration addDragEnterHandler(DragEnterHandler handler) { 301 return addDomHandler(handler, DragEnterEvent.getType()); 302 } 303 @Override 304 public final HandlerRegistration addDragHandler(DragHandler handler) { 305 return addDomHandler(handler, DragEvent.getType()); 306 } 307 @Override 308 public final HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) { 309 return addDomHandler(handler, DragLeaveEvent.getType()); 310 } 311 @Override 312 public final HandlerRegistration addDragOverHandler(DragOverHandler handler) { 313 return addDomHandler(handler, DragOverEvent.getType()); 314 } 315 @Override 316 public final HandlerRegistration addDragStartHandler(DragStartHandler handler) { 317 return addDomHandler(handler, DragStartEvent.getType()); 318 } 319 @Override 320 public final HandlerRegistration addDropHandler(DropHandler handler) { 321 return addDomHandler(handler, DropEvent.getType()); 322 } 323 @Override 324 public final HandlerRegistration addLoadHandler(LoadHandler handler) { 325 return addDomHandler(handler, LoadEvent.getType()); 326 } 327 @Override 328 public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) { 329 return addDomHandler(handler, MouseDownEvent.getType()); 330 } 331 @Override 332 public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) { 333 return addDomHandler(handler, MouseMoveEvent.getType()); 334 } 335 @Override 336 public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { 337 return addDomHandler(handler, MouseOutEvent.getType()); 338 } 339 @Override 340 public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { 341 return addDomHandler(handler, MouseOverEvent.getType()); 342 } 343 @Override 344 public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) { 345 return addDomHandler(handler, MouseUpEvent.getType()); 346 } 347 @Override 348 public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) { 349 return addDomHandler(handler, TouchCancelEvent.getType()); 350 } 351 @Override 352 public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) { 353 return addDomHandler(handler, TouchEndEvent.getType()); 354 } 355 @Override 356 public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) { 357 return addDomHandler(handler, TouchMoveEvent.getType()); 358 } 359 @Override 360 public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) { 361 return addDomHandler(handler, TouchStartEvent.getType()); 362 } 363 @Override 364 public final HandlerRegistration addActivateHandler(ActivateHandler handler) { 365 return addDomHandler(handler, ActivateEvent.getType()); 366 } 367 @Override 368 public final HandlerRegistration addFocusInHandler(FocusInHandler handler) { 369 return addDomHandler(handler, FocusInEvent.getType()); 370 } 371 @Override 372 public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) { 373 return addDomHandler(handler, FocusOutEvent.getType()); 374 } 375}