001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js.user;
021 
022 import js.*;
023 import js.core.*;
024 
025 /**
026  * <p>An <b>opaque</b> class representing JavaScript client-side objects of the global 
027  * {@link JsClient#HTMLCanvasElement} class.</p>
028  * <p>This class represents a canvas 
029  * in an HTML page, or a {@link JsHTMLElement} object created with the HTML 
030  * <tt>&lt;canvas&gt;</tt> tag.</p>
031  * <p>This class represents an HTML canvas element. It has no behavior of its own but 
032  * defines an API that supports scripted client-side drawing operations. You may specify 
033  * the {@link JsHTMLCanvasElement#width} and {@link JsHTMLCanvasElement#height} properties 
034  * directly on an object of this type, but most of its functionality is available via 
035  * the object of {@link JsCanvasRenderingContext2D} obtained by calling the {@link JsHTMLCanvasElement#getContext(String)} 
036  * method of the {@link JsHTMLCanvasElement} object and passing the literal string "2d" 
037  * as the sole argument.</p>
038  * <p>The <tt>&lt;canvas&gt;</tt> tag and its API is not supported by but can be simulated 
039  * in IE with an open source project called <a href = "http://excanvas.sourceforge.net/">ExplorerCanvas</a>.</p>
040  *
041  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
042  *
043  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
044  * generated into the target codes. Re-compilers must exit with error on the operations of
045  * accessing that kind of class objects.
046  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
047  * and <tt>instanceof</tt> to it always <tt>true</tt>.
048  */
049 public class JsHTMLCanvasElement extends JsClient.HTMLCanvasElement.Prototype
050 {
051     /**
052      * <p>An <b>internal</b> class containing membership data for its enclosing
053      * opaque class.</p>
054      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
055      * class members.</p>
056      *
057      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
058      * 
059      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
060      */
061     protected static abstract class Members extends JsClient.HTMLCanvasElement.Prototype.Members
062     {
063         /**
064          * <p>An <b>internal</b> static field defining a member ID of the field name and
065          * used internally to define a member of the same name.</p>
066          * @since 1.0
067          * @see JsHTMLCanvasElement#height
068          * @see JsHTMLCanvasElement.Member#height
069          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
070          */
071         public final static Mid height = id("height");
072         /**
073          * <p>An <b>internal</b> static field defining a member ID of the field name and
074          * used internally to define a member of the same name.</p>
075          * @since 1.0
076          * @see JsHTMLCanvasElement#width
077          * @see JsHTMLCanvasElement.Member#width
078          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
079          */
080         public final static Mid width  = id("width" );
081     }
082     /**
083      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
084      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
085      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
086      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
087      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
088      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
089      * either circumstance, the field names must be exactly same as the member names, as 
090      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
091      * based on the field names.</p>
092      *
093      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
094      * 
095      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
096      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
097      * of class objects.
098      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
099      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
100      * <pre>q.m</pre>
101      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
102      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
103      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
104      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
105      * <pre>m</pre>
106      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
107      * error on the access to <b>opaque</b> fields declared by this class under any other 
108      * circumstances.
109      */
110     public static class Member extends JsClient.HTMLCanvasElement.Prototype.Member
111     {
112         /**
113          * <p>Internally constructs a member based on a qualifying member.</p>
114          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
115          * or <b>internal</b> classes or class members.</p>
116          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
117          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
118          * declared in the declaring class of this constructor itself or its subclasses. 
119          * Under this circumstance, the field names must be exactly same as the member 
120          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
121          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
122          * to their names appending to the name resolved from the specified qualifying 
123          * member with a dot in between.</p>
124          * @param q A qualifying member
125          * @param mid The ID of the member to construct
126          * @since 1.0
127          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
128          */
129         public Member(JsObject.Member q, Mid mid) {
130             super(q, mid);
131         }
132         /**
133          * <p>Internally constructs a member without a qualifying member.</p>
134          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
135          * or <b>internal</b> classes or class members.</p>
136          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
137          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
138          * declared in <b>opaque</b> types other than the declaring class of this constructor 
139          * itself and its subclasses. Under this circumstance, the field names must be
140          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
141          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
142          * @param mid The ID of the member to construct
143          * @since 1.0
144          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
145          */
146         public Member(Mid mid) {
147             super(mid);
148         }
149         @Override
150         /**
151          * <p>Evaluates the property, represented by the current member instance, of the
152          * argument object.</p>
153          * @param o The argument object
154          * @return The value of the current member based on the object argument.
155          * @since 1.0
156          * @javascript Re-compilers must convert the instance invocation of this method into
157          * the JavaScript expression: 
158          * <pre>o.m</pre>
159          * where <tt>m</tt> is the identifier name resolved from the current member
160          * instance of the invocation.
161          */
162         public JsHTMLCanvasElement with(ObjectLike o) {
163             return new JsHTMLCanvasElement(super.with(o));
164         }
165 
166         /**
167          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
168          * name of this field, qualified by the current member instance of the field, and 
169          * to access the property of the name on an object.</p>
170          * <p>The property, identified by this member, of a {@link JsHTMLCanvasElement} 
171          * object refers to a string or numerical value specifying the height of the 
172          * canvas. As with an image, this may be specified as an integer pixel value or 
173          * percentage of the window height. When this value is changed, any drawing that 
174          * has been done in the canvas is erased. The default value is 300.</p> 
175          * @since 1.0
176          * @javascript Re-compilers must resolve the member of this instance field to the
177          * identifier of the field name appending to the identifier resolved from its 
178          * qualifying member with a dot in between.
179          */
180         public final Value.Member<Object> height = new Value.Member<Object>(this, Members.height);
181         /**
182          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
183          * name of this field, qualified by the current member instance of the field, and 
184          * to access the property of the name on an object.</p>
185          * <p>The property, identified by this member, of a {@link JsHTMLCanvasElement} 
186          * object refers to a string or numerical value specifying the width of the 
187          * canvas. As with an image, this may be specified as an integer pixel value or 
188          * percentage of the window width. When this value is changed, any drawing that 
189          * has been done in the canvas is erased. The default value is 300.</p> 
190          * @since 1.0
191          * @javascript Re-compilers must resolve the member of this instance field to the
192          * identifier of the field name appending to the identifier resolved from its 
193          * qualifying member with a dot in between.
194          */
195         public final Value.Member<Object> width  = new Value.Member<Object>(this, Members.width );
196     }
197 
198     /**
199      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
200      * with the wrapping constructor.</p>
201      * @param var The argument of an <b>opaque</b> object.
202      * @since 1.0
203      * @javascript Re-compilers must ignore the construction operation of this constructor,
204      * that is, replacing it with its only argument.
205      */
206     public JsHTMLCanvasElement(JsObject var) {
207         super(var);
208     }
209 
210     /**
211      * <p>An <b>opaque</b> static field defining a member that is named by the field name
212      * without a qualifying member and to access the property of the name on an object.</p>
213      * <p>The property, identified by this member, of a {@link JsHTMLCanvasElement} 
214      * object refers to a string or numerical value specifying the height of the 
215      * canvas. As with an image, this may be specified as an integer pixel value or 
216      * percentage of the window height. When this value is changed, any drawing that 
217      * has been done in the canvas is erased. The default value is 300.</p> 
218      * @since 1.0
219      * @javascript Re-compilers must resolve the member of this static field to the
220      * identifier of the field name.
221      */
222     public static final Value.Member<Object> height = new Value.Member<Object>(Members.height);
223     /**
224      * <p>An <b>opaque</b> static field defining a member that is named by the field name
225      * without a qualifying member and to access the property of the name on an object.</p>
226      * <p>The property, identified by this member, of a {@link JsHTMLCanvasElement} 
227      * object refers to a string or numerical value specifying the width of the 
228      * canvas. As with an image, this may be specified as an integer pixel value or 
229      * percentage of the window width. When this value is changed, any drawing that 
230      * has been done in the canvas is erased. The default value is 300.</p> 
231      * @since 1.0
232      * @javascript Re-compilers must resolve the member of this static field to the
233      * identifier of the field name.
234      */
235     public static final Value.Member<Object> width  = new Value.Member<Object>(Members.width );
236 
237     @Override
238     /**
239      * <p>Returns the primitive value associated with the current instance, if there is one.
240      * This invocation simply returns the instance itself for the current instance is an 
241      * object and there is no primitive value for it.</p>
242      * @return The current object itself.
243      * @since 1.0
244      * @javascript Re-compilers must convert the instance invocation of this method directly
245      * into a JavaScript invocation on its current object instance without changing the 
246      * method name, but expanding variable arguments, if any, into comma-separated values. 
247      */
248     public JsHTMLCanvasElement valueOf() {
249         return new JsHTMLCanvasElement((JsObject)var().valueOf());
250     }
251 
252     /**
253      * <p>Gets a context object with which to draw on the canvas.</p>
254      * <p>You must pass the string "2d" to this method to specify that you want to do 
255      * 2-dimension drawing.</p>
256      * @param contextID Specifies the type of drawing you want to do with the canvas. 
257      * Currently the only valid value is "2d", which specifies 2-D drawing and causes 
258      * this method to return a context object that exports a 2-D drawing API.
259      * @return A context object with which you can draw into the canvas.
260      * @since 1.0
261      * @see #getContext(StringLike)
262      * @javascript Re-compilers must convert the instance invocation of this method directly
263      * into a JavaScript invocation on its current object instance without changing the 
264      * method name, but expanding variable arguments, if any, into comma-separated values. 
265      */
266     public final JsCanvasRenderingContext2D getContext(String contextID) {
267         return new JsCanvasRenderingContext2D(call(getContext, contextID));
268     }
269     /**
270      * <p>Gets a context object with which to draw on the canvas.</p>
271      * <p>You must pass the string "2d" to this method to specify that you want to do 
272      * 2-dimension drawing.</p>
273      * @param contextID Specifies the type of drawing you want to do with the canvas. 
274      * Currently the only valid value is "2d", which specifies 2-D drawing and causes 
275      * this method to return a context object that exports a 2-D drawing API.
276      * @return A context object with which you can draw into the canvas.
277      * @since 1.0
278      * @see #getContext(String)
279      * @javascript Re-compilers must convert the instance invocation of this method directly
280      * into a JavaScript invocation on its current object instance without changing the 
281      * method name, but expanding variable arguments, if any, into comma-separated values. 
282      */
283     public final JsCanvasRenderingContext2D getContext(StringLike contextID) {
284         return new JsCanvasRenderingContext2D(call(getContext, contextID));
285     }
286 }