View Javadoc

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.SVGElement;
40  import org.vectomatic.dom.svg.impl.SVGForeignObjectElement;
41  import org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired;
42  import org.vectomatic.dom.svg.itf.ISVGLangSpace;
43  import org.vectomatic.dom.svg.itf.ISVGStylable;
44  import org.vectomatic.dom.svg.itf.ISVGTests;
45  import org.vectomatic.dom.svg.itf.ISVGTransformable;
46  import org.vectomatic.dom.svg.utils.DOMHelper;
47  import org.vectomatic.dom.svg.utils.SVGConstants;
48  
49  import com.google.gwt.core.client.JavaScriptException;
50  import com.google.gwt.dom.client.TagName;
51  import com.google.gwt.event.dom.client.ClickEvent;
52  import com.google.gwt.event.dom.client.ClickHandler;
53  import com.google.gwt.event.dom.client.LoadEvent;
54  import com.google.gwt.event.dom.client.LoadHandler;
55  import com.google.gwt.event.dom.client.MouseDownEvent;
56  import com.google.gwt.event.dom.client.MouseDownHandler;
57  import com.google.gwt.event.dom.client.MouseMoveEvent;
58  import com.google.gwt.event.dom.client.MouseMoveHandler;
59  import com.google.gwt.event.dom.client.MouseOutEvent;
60  import com.google.gwt.event.dom.client.MouseOutHandler;
61  import com.google.gwt.event.dom.client.MouseOverEvent;
62  import com.google.gwt.event.dom.client.MouseOverHandler;
63  import com.google.gwt.event.dom.client.MouseUpEvent;
64  import com.google.gwt.event.dom.client.MouseUpHandler;
65  import com.google.gwt.event.dom.client.TouchCancelEvent;
66  import com.google.gwt.event.dom.client.TouchCancelHandler;
67  import com.google.gwt.event.dom.client.TouchEndEvent;
68  import com.google.gwt.event.dom.client.TouchEndHandler;
69  import com.google.gwt.event.dom.client.TouchMoveEvent;
70  import com.google.gwt.event.dom.client.TouchMoveHandler;
71  import com.google.gwt.event.dom.client.TouchStartEvent;
72  import com.google.gwt.event.dom.client.TouchStartHandler;
73  import com.google.gwt.event.shared.HandlerRegistration;
74  
75  /**
76   * The {@link org.vectomatic.dom.svg.OMSVGForeignObjectElement} interface
77   * corresponds to the <a href='http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement'
78   * title='foreignObject element specification'>foreignObject</a> element.
79   */
80  @TagName("foreignObject")
81  public class OMSVGForeignObjectElement extends OMSVGElement implements HasGraphicalHandlers, ISVGTests, ISVGLangSpace, ISVGExternalResourcesRequired, ISVGStylable, ISVGTransformable {
82    public OMSVGForeignObjectElement() {
83      this((SVGForeignObjectElement)DOMHelper.createElementNS(DOMHelper.getCurrentDocument(), SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_FOREIGN_OBJECT_TAG).cast());
84    }
85  
86    protected OMSVGForeignObjectElement(SVGForeignObjectElement ot) {
87      super(ot);
88    }
89  
90    // Implementation of the svg::SVGForeignObjectElement W3C IDL interface
91    /**
92     * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGForeignObjectElement#getX()}
93     * on the given <a href='http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement'
94     * title='foreignObject element specification'>foreignObject</a> element.
95     */
96    public final OMSVGAnimatedLength getX() {
97      return ((SVGForeignObjectElement)ot).getX();
98    }
99    /**
100    * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGForeignObjectElement#getY()}
101    * on the given <a href='http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement'
102    * title='foreignObject element specification'>foreignObject</a> element.
103    */
104   public final OMSVGAnimatedLength getY() {
105     return ((SVGForeignObjectElement)ot).getY();
106   }
107   /**
108    * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGForeignObjectElement#getWidth()}
109    * on the given <a href='http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement'
110    * title='foreignObject element specification'>foreignObject</a> element.
111    */
112   public final OMSVGAnimatedLength getWidth() {
113     return ((SVGForeignObjectElement)ot).getWidth();
114   }
115   /**
116    * Corresponds to attribute {@link org.vectomatic.dom.svg.OMSVGForeignObjectElement#getHeight()}
117    * on the given <a href='http://www.w3.org/TR/SVG11/extend.html#ForeignObjectElement'
118    * title='foreignObject element specification'>foreignObject</a> element.
119    */
120   public final OMSVGAnimatedLength getHeight() {
121     return ((SVGForeignObjectElement)ot).getHeight();
122   }
123 
124   // Implementation of the svg::SVGExternalResourcesRequired W3C IDL interface
125   /**
126    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
127    * on the given element. Note that the SVG DOM defines the attribute {@link
128    * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
129    * as being of type {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean}, whereas
130    * the SVG language definition says that {@link org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
131    * is not animated. Because the SVG language definition states that {@link
132    * org.vectomatic.dom.svg.itf.ISVGExternalResourcesRequired#getExternalResourcesRequired()}
133    * cannot be animated, the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getAnimVal()}
134    * will always be the same as the {@link org.vectomatic.dom.svg.OMSVGAnimatedBoolean#getBaseVal()}.
135    */
136   public final OMSVGAnimatedBoolean getExternalResourcesRequired() {
137     return ((SVGForeignObjectElement)ot).getExternalResourcesRequired();
138   }
139 
140   // Implementation of the svg::SVGLangSpace W3C IDL interface
141   /**
142    * Corresponds to attribute <code>xml:lang</code> on the given element.
143    */
144   public final String getXmllang() {
145     return ((SVGForeignObjectElement)ot).getXmllang();
146   }
147   /**
148    * Corresponds to attribute <code>xml:lang</code> on the given element.
149    * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an   attempt
150    * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
151    * attribute</a>.
152    */
153   public final void setXmllang(java.lang.String value) throws JavaScriptException {
154     ((SVGForeignObjectElement)ot).setXmllang(value);
155   }
156   /**
157    * Corresponds to attribute <code>xml:space</code> on the given element.
158    */
159   public final String getXmlspace() {
160     return ((SVGForeignObjectElement)ot).getXmlspace();
161   }
162   /**
163    * Corresponds to attribute <code>xml:space</code> on the given element.
164    * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) Raised on an   attempt
165    * to change the value of a <a href="svgdom.html#ReadOnlyNodes">read only
166    * attribute</a>.
167    */
168   public final void setXmlspace(java.lang.String value) throws JavaScriptException {
169     ((SVGForeignObjectElement)ot).setXmlspace(value);
170   }
171 
172   // Implementation of the svg::SVGLocatable W3C IDL interface
173   /**
174    * The element which established the current viewport. Often, the nearest
175    * ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement' title='svg
176    * element specification'>svg</a> element. Null if the current element is
177    * the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
178    * title='svg element specification'>svg</a> element.
179    */
180   public final OMSVGElement getNearestViewportElement() {
181     return (OMSVGElement)convert(((SVGForeignObjectElement)ot).getNearestViewportElement());
182   }
183   /**
184    * The farthest ancestor <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
185    * title='svg element specification'>svg</a> element. Null if the current
186    * element is the outermost <a href='http://www.w3.org/TR/SVG11/struct.html#SVGElement'
187    * title='svg element specification'>svg</a> element.
188    */
189   public final OMSVGElement getFarthestViewportElement() {
190     return (OMSVGElement)convert(((SVGForeignObjectElement)ot).getFarthestViewportElement());
191   }
192   /**
193    * Returns the tight bounding box in current user space (i.e., after application
194    * of the <code>transform</code> attribute, if any) on the geometry of all
195    * contained graphics elements, exclusive of stroking, clipping, masking and
196    * filter effects). Note that getBBox must return the actual bounding box
197    * at the time the method was called, even in case the element has not yet
198    * been rendered.
199    * @return An {@link org.vectomatic.dom.svg.OMSVGRect} object that defines
200    * the bounding box.
201    */
202   public final OMSVGRect getBBox() {
203     return ((SVGForeignObjectElement)ot).getBBox();
204   }
205   /**
206    * Returns the transformation matrix from current user units (i.e., after
207    * application of the <code>transform</code> attribute, if any) to the viewport
208    * coordinate system for the {@link org.vectomatic.dom.svg.itf.ISVGLocatable#getNearestViewportElement()}.
209    * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
210    * the CTM.
211    */
212   public final OMSVGMatrix getCTM() {
213     return ((SVGForeignObjectElement)ot).getCTM();
214   }
215   /**
216    * Returns the transformation matrix from current user units (i.e., after
217    * application of the <code>transform</code> attribute, if any) to the parent
218    * user agent's notice of a "pixel". For display devices, ideally this represents
219    * a physical screen pixel. For other devices or environments where physical
220    * pixel sizes are not known, then an algorithm similar to the CSS2 definition
221    * of a "pixel" can be used instead.  Note that null is returned if this element
222    * is not hooked into the document tree. This method would have been more
223    * aptly named as <code>getClientCTM</code>, but the name <code>getScreenCTM</code>
224    * is kept for historical reasons.
225    * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
226    * the given   transformation matrix.
227    */
228   public final OMSVGMatrix getScreenCTM() {
229     return ((SVGForeignObjectElement)ot).getScreenCTM();
230   }
231   /**
232    * Returns the transformation matrix from the user coordinate system on the
233    * current element (after application of the <code>transform</code> attribute,
234    * if any) to the user coordinate system on parameter <var>element</var> (after
235    * application of its <code>transform</code> attribute, if any).
236    * @param element The target element.
237    * @return An {@link org.vectomatic.dom.svg.OMSVGMatrix} object that defines
238    * the transformation.
239    * @throws SVGException(SVG_MATRIX_NOT_INVERTABLE) Raised if the currently
240    * defined transformation matrices make it impossible to compute the   given
241    * matrix (e.g., because one of the transformations is singular).
242    */
243   public final OMSVGMatrix getTransformToElement(OMSVGElement element) throws JavaScriptException {
244     return ((SVGForeignObjectElement)ot).getTransformToElement(((SVGElement)element.ot));
245   }
246 
247   // Implementation of the svg::SVGTests W3C IDL interface
248   /**
249    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredFeatures()}
250    * on the given element.
251    */
252   public final OMSVGStringList getRequiredFeatures() {
253     return ((SVGForeignObjectElement)ot).getRequiredFeatures();
254   }
255   /**
256    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getRequiredExtensions()}
257    * on the given element.
258    */
259   public final OMSVGStringList getRequiredExtensions() {
260     return ((SVGForeignObjectElement)ot).getRequiredExtensions();
261   }
262   /**
263    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTests#getSystemLanguage()}
264    * on the given element.
265    */
266   public final OMSVGStringList getSystemLanguage() {
267     return ((SVGForeignObjectElement)ot).getSystemLanguage();
268   }
269   /**
270    * Returns true if the user agent supports the given extension, specified
271    * by a URI.
272    * @param extension The name of the extension, expressed as a URI.
273    * @return True or false, depending on whether the given extension is   supported.
274    */
275   public final boolean hasExtension(String extension) {
276     return ((SVGForeignObjectElement)ot).hasExtension(extension);
277   }
278 
279   // Implementation of the svg::SVGTransformable W3C IDL interface
280   /**
281    * Corresponds to attribute {@link org.vectomatic.dom.svg.itf.ISVGTransformable#getTransform()}
282    * on the given element.
283    */
284   public final OMSVGAnimatedTransformList getTransform() {
285     return ((SVGForeignObjectElement)ot).getTransform();
286   }
287 
288   @Override
289   public final HandlerRegistration addClickHandler(ClickHandler handler) {
290     return addDomHandler(handler, ClickEvent.getType());
291   }
292   @Override
293   public final HandlerRegistration addLoadHandler(LoadHandler handler) {
294     return addDomHandler(handler, LoadEvent.getType());
295   }
296   @Override
297   public final HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
298     return addDomHandler(handler, MouseDownEvent.getType());
299   }
300   @Override
301   public final HandlerRegistration addMouseMoveHandler(MouseMoveHandler handler) {
302     return addDomHandler(handler, MouseMoveEvent.getType());
303   }
304   @Override
305   public final HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
306     return addDomHandler(handler, MouseOutEvent.getType());
307   }
308   @Override
309   public final HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
310     return addDomHandler(handler, MouseOverEvent.getType());
311   }
312   @Override
313   public final HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
314     return addDomHandler(handler, MouseUpEvent.getType());
315   }
316   @Override
317   public final HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
318     return addDomHandler(handler, TouchCancelEvent.getType());
319   }
320   @Override
321   public final HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
322     return addDomHandler(handler, TouchEndEvent.getType());
323   }
324   @Override
325   public final HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
326     return addDomHandler(handler, TouchMoveEvent.getType());
327   }
328   @Override
329   public final HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
330     return addDomHandler(handler, TouchStartEvent.getType());
331   }
332   @Override
333   public final HandlerRegistration addActivateHandler(ActivateHandler handler) {
334     return addDomHandler(handler, ActivateEvent.getType());
335   }
336   @Override
337   public final HandlerRegistration addFocusInHandler(FocusInHandler handler) {
338     return addDomHandler(handler, FocusInEvent.getType());
339   }
340   @Override
341   public final HandlerRegistration addFocusOutHandler(FocusOutHandler handler) {
342     return addDomHandler(handler, FocusOutEvent.getType());
343   }
344 }