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