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.SVGElement; 040import org.vectomatic.dom.svg.impl.SVGUseElement; 041import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired; 042import org.vectomatic.dom.svg.itf.ISVGGraphicsElement; 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.OMSVGUseElement} interface corresponds 093 * to the <a href='http://www.w3.org/TR/SVG11/struct.html#UseElement' title='use 094 * element specification'>use</a> element. 095 */ 096@TagName("use") 097public class OMSVGUseElement extends OMSVGElement implements HasGraphicalHandlers, ISVGURIReference, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable, ISVGTransformable, ISVGGraphicsElement { 098 public OMSVGUseElement() { 099 this((SVGUseElement)DOMHelper.createElementNS(DOMHelper.getCurrentDocument(), SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_USE_TAG).cast()); 100 } 101 102 protected OMSVGUseElement(SVGUseElement ot) { 103 super(ot); 104 } 105 106 // Implementation of the svg::SVGUseElement W3C IDL interface 107 /** 108 * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGUseElement#getX()} 109 * on the given <a href='http://www.w3.org/TR/SVG11/struct.html#UseElement' 110 * title='use element specification'>use</a> element. 111 */ 112 public final OMSVGAnimatedLength getX() { 113 return ((SVGUseElement)ot).getX(); 114 } 115 /** 116 * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGUseElement#getY()} 117 * on the given <a href='http://www.w3.org/TR/SVG11/struct.html#UseElement' 118 * title='use element specification'>use</a> element. 119 */ 120 public final OMSVGAnimatedLength getY() { 121 return ((SVGUseElement)ot).getY(); 122 } 123 /** 124 * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGUseElement#getWidth()} 125 * on the given <a href='http://www.w3.org/TR/SVG11/struct.html#UseElement' 126 * title='use element specification'>use</a> element. 127 */ 128 public final OMSVGAnimatedLength getWidth() { 129 return ((SVGUseElement)ot).getWidth(); 130 } 131 /** 132 * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGUseElement#getHeight()} 133 * on the given <a href='http://www.w3.org/TR/SVG11/struct.html#UseElement' 134 * title='use element specification'>use</a> element. 135 */ 136 public final OMSVGAnimatedLength getHeight() { 137 return ((SVGUseElement)ot).getHeight(); 138 } 139 /** 140 * The root of the "instance tree". See description of {@link org.vectomatic.dom.svg.OMSVGElementInstance} 141 * for a discussion on the instance tree. 142 */ 143 public final OMSVGElementInstance getInstanceRoot() { 144 return ((SVGUseElement)ot).getInstanceRoot(); 145 } 146 /** 147 * If the <code>xlink:href</code> attribute is being animated, contains the 148 * current animated root of the "instance tree". If the <code>xlink:href</code> 149 * attribute is not currently being animated, contains the same value as {@link 150 * org.vectomatic.dom.svg.OMSVGUseElement#getInstanceRoot()}. See description 151 * of {@link org.vectomatic.dom.svg.OMSVGElementInstance} for a discussion 152 * on the instance tree. 153 */ 154 public final OMSVGElementInstance getAnimatedInstanceRoot() { 155 return ((SVGUseElement)ot).getAnimatedInstanceRoot(); 156 } 157 158 // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface 159 /** 160 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 161 * on the given element. Note that the SVG DOM defines the attribute {@link 162 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 163 * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas 164 * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 165 * is not animated. Because the SVG language definition states that {@link 166 * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()} 167 * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()} 168 * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}. 169 */ 170 public final OMSVGAnimatedBoolean getExternalResourcesRequired() { 171 return ((SVGUseElement)ot).getExternalResourcesRequired(); 172 } 173 174 // Implementation of the svg::SVGLangSpace W3C IDL interface 175 /** 176 * Corresponds to attribute <code>xml:lang</code> on the given element. 177 */ 178 public final String getXmllang() { 179 return ((SVGUseElement)ot).getXmllang(); 180 } 181 /** 182 * Corresponds to attribute <code>xml:lang</code> on the given element. 183 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt 184 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only 185 * attribute</a>. 186 */ 187 public final void setXmllang(java.lang.String value) throws JavaScriptException { 188 ((SVGUseElement)ot).setXmllang(value); 189 } 190 /** 191 * Corresponds to attribute <code>xml:space</code> on the given element. 192 */ 193 public final String getXmlspace() { 194 return ((SVGUseElement)ot).getXmlspace(); 195 } 196 /** 197 * Corresponds to attribute <code>xml:space</code> on the given element. 198 * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an attempt 199 * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only 200 * attribute</a>. 201 */ 202 public final void setXmlspace(java.lang.String value) throws JavaScriptException { 203 ((SVGUseElement)ot).setXmlspace(value); 204 } 205 206 // Implementation of the svg::SVGLocatable W3C IDL interface 207 /** 208 * The element which established the current viewport. Often, the nearest 209 * ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' title='svg 210 * element specification'>svg</a> element. Null if the current element is 211 * the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' 212 * title='svg element specification'>svg</a> element. 213 */ 214 public final OMSVGElement getNearestViewportElement() { 215 SVGElement elt = ((SVGUseElement)ot).getNearestViewportElement(); 216 return elt != null ? (OMSVGElement)convert(elt) : null; 217 } 218 /** 219 * The farthest ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' 220 * title='svg element specification'>svg</a> element. Null if the current 221 * element is the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' 222 * title='svg element specification'>svg</a> element. 223 */ 224 public final OMSVGElement getFarthestViewportElement() { 225 SVGElement elt = ((SVGUseElement)ot).getFarthestViewportElement(); 226 return elt != null ? (OMSVGElement)convert(elt) : null; 227 } 228 /** 229 * Returns the tight bounding box in current user space (i.e., after application 230 * of the <code>transform</code> attribute, if any) on the geometry of all 231 * contained graphics elements, exclusive of stroking, clipping, masking and 232 * filter effects). Note that getBBox must return the actual bounding box 233 * at the time the method was called, even in case the element has not yet 234 * been rendered. 235 * @return An {@link org.vectomatic.dom.svg.OMSVGRect} object that defines 236 * the bounding box. 237 */ 238 public final OMSVGRect getBBox() { 239 return ((SVGUseElement)ot).getBBox(); 240 } 241 /** 242 * Returns the transformation matrix from current user units (i.e., after 243 * application of the <code>transform</code> attribute, if any) to the viewport 244 * coordinate system for the {@link org.vectomatic.dom.svg.itf.ISVGLocatable#getNearestViewportElement()}. 245 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines 246 * the CTM. 247 */ 248 public final OMSVGMatrix getCTM() { 249 return ((SVGUseElement)ot).getCTM(); 250 } 251 /** 252 * Returns the transformation matrix from current user units (i.e., after 253 * application of the <code>transform</code> attribute, if any) to the parent 254 * user agent's notice of a "pixel". For display devices, ideally this represents 255 * a physical screen pixel. For other devices or environments where physical 256 * pixel sizes are not known, then an algorithm similar to the CSS2 definition 257 * of a "pixel" can be used instead. Note that null is returned if this element 258 * is not hooked into the document tree. This method would have been more 259 * aptly named as <code>getClientCTM</code>, but the name <code>getScreenCTM</code> 260 * is kept for historical reasons. 261 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines 262 * the given transformation matrix. 263 */ 264 public final OMSVGMatrix getScreenCTM() { 265 return ((SVGUseElement)ot).getScreenCTM(); 266 } 267 /** 268 * Returns the transformation matrix from the user coordinate system on the 269 * current element (after application of the <code>transform</code> attribute, 270 * if any) to the user coordinate system on parameter <var>element</var> (after 271 * application of its <code>transform</code> attribute, if any). 272 * @param element The target element. 273 * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines 274 * the transformation. 275 * @throws SVGException(SVG_MATRIX_NOT_INVERTABLE) Raised if the currently 276 * defined transformation matrices make it impossible to compute the given 277 * matrix (e.g., because one of the transformations is singular). 278 */ 279 public final OMSVGMatrix getTransformToElement(OMSVGElement element) throws JavaScriptException { 280 return ((SVGUseElement)ot).getTransformToElement(((SVGElement)element.ot)); 281 } 282 283 // Implementation of the svg::SVGTests W3C IDL interface 284 /** 285 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()} 286 * on the given element. 287 */ 288 public final OMSVGStringList getRequiredFeatures() { 289 return ((SVGUseElement)ot).getRequiredFeatures(); 290 } 291 /** 292 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()} 293 * on the given element. 294 */ 295 public final OMSVGStringList getRequiredExtensions() { 296 return ((SVGUseElement)ot).getRequiredExtensions(); 297 } 298 /** 299 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()} 300 * on the given element. 301 */ 302 public final OMSVGStringList getSystemLanguage() { 303 return ((SVGUseElement)ot).getSystemLanguage(); 304 } 305 /** 306 * Returns true if the user agent supports the given extension, specified 307 * by a URI. 308 * @param extension The name of the extension, expressed as a URI. 309 * @return True or false, depending on whether the given extension is supported. 310 */ 311 public final boolean hasExtension(String extension) { 312 return ((SVGUseElement)ot).hasExtension(extension); 313 } 314 315 // Implementation of the svg::SVGTransformable W3C IDL interface 316 /** 317 * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTransformable#getTransform()} 318 * on the given element. 319 */ 320 public final OMSVGAnimatedTransformList getTransform() { 321 return ((SVGUseElement)ot).getTransform(); 322 } 323 324 // Implementation of the svg::SVGURIReference W3C IDL interface 325 /** 326 * Corresponds to attribute <span class='attr-name'>'xlink:href'</span> on 327 * the given element. 328 */ 329 public final OMSVGAnimatedString getHref() { 330 return ((SVGUseElement)ot).getHref(); 331 } 332 333 @Override 334 public final HandlerRegistration addClickHandler(ClickHandler handler) { 335 return addDomHandler(handler, ClickEvent.getType()); 336 } 337 @Override 338 public final HandlerRegistration addDragEndHandler(DragEndHandler handler) { 339 return addDomHandler(handler, DragEndEvent.getType()); 340 } 341 @Override 342 public final HandlerRegistration addDragEnterHandler(DragEnterHandler handler) { 343 return addDomHandler(handler, DragEnterEvent.getType()); 344 } 345 @Override 346 public final HandlerRegistration addDragHandler(DragHandler handler) { 347 return addDomHandler(handler, DragEvent.getType()); 348 } 349 @Override 350 public final HandlerRegistration addDragLeaveHandler(DragLeaveHandler handler) { 351 return addDomHandler(handler, DragLeaveEvent.getType()); 352 } 353 @Override 354 public final HandlerRegistration addDragOverHandler(DragOverHandler handler) { 355 return addDomHandler(handler, DragOverEvent.getType()); 356 } 357 @Override 358 public final HandlerRegistration addDragStartHandler(DragStartHandler handler) { 359 return addDomHandler(handler, DragStartEvent.getType()); 360 } 361 @Override 362 public final HandlerRegistration addDropHandler(DropHandler handler) { 363 return addDomHandler(handler, DropEvent.getType()); 364 } 365 @Override 366 public final HandlerRegistration addLoadHandler(LoadHandler handler) { 367 return addDomHandler(handler, LoadEvent.getType()); 368 } 369 @Override 370 public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) { 371 return addDomHandler(handler, MouseDownEvent.getType()); 372 } 373 @Override 374 public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) { 375 return addDomHandler(handler, MouseMoveEvent.getType()); 376 } 377 @Override 378 public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) { 379 return addDomHandler(handler, MouseOutEvent.getType()); 380 } 381 @Override 382 public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) { 383 return addDomHandler(handler, MouseOverEvent.getType()); 384 } 385 @Override 386 public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) { 387 return addDomHandler(handler, MouseUpEvent.getType()); 388 } 389 @Override 390 public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) { 391 return addDomHandler(handler, TouchCancelEvent.getType()); 392 } 393 @Override 394 public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) { 395 return addDomHandler(handler, TouchEndEvent.getType()); 396 } 397 @Override 398 public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) { 399 return addDomHandler(handler, TouchMoveEvent.getType()); 400 } 401 @Override 402 public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) { 403 return addDomHandler(handler, TouchStartEvent.getType()); 404 } 405 @Override 406 public final HandlerRegistration addActivateHandler(ActivateHandler handler) { 407 return addDomHandler(handler, ActivateEvent.getType()); 408 } 409 @Override 410 public final HandlerRegistration addFocusInHandler(FocusInHandler handler) { 411 return addDomHandler(handler, FocusInEvent.getType()); 412 } 413 @Override 414 public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) { 415 return addDomHandler(handler, FocusOutEvent.getType()); 416 } 417}