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#KeyEvent} class.</p>
028  * <p>An object of this class provides details about a keyboard event and is passed to 
029  * event handlers for "keydown", "keypress", and "keyup" events.</p>
030  * {@link JsClient#KeyEvent} 
031  * object has not been standardized. The property members of this class describes the 
032  * Firefox implementation. Many of these properties are also supported in the IE event 
033  * model. See the IE-specific properties defined in {@link JsEvent}. Note that in 
034  * addition to the property members in this class, {@link JsKeyEvent} objects also 
035  * inherit the properties of {@link JsUIEvent} and {@link JsEvent}.</p>
036  *
037  * @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>
038  *
039  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
040  * generated into the target codes. Re-compilers must exit with error on the operations of
041  * accessing that kind of class objects.
042  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
043  * and <tt>instanceof</tt> to it always <tt>true</tt>.
044  */
045 public class JsKeyEvent extends JsClient.KeyEvent.Prototype
046 {
047     /**
048      * <p>An <b>internal</b> class containing membership data for its enclosing
049      * opaque class.</p>
050      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
051      * class members.</p>
052      *
053      * @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>
054      * 
055      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
056      */
057     protected static abstract class Members extends JsClient.KeyEvent.Prototype.Members
058     {
059         /**
060          * <p>An <b>internal</b> static field defining a member ID of the field name and
061          * used internally to define a member of the same name.</p>
062          * @since 1.0
063          * @see JsKeyEvent#altKey
064          * @see JsKeyEvent.Member#altKey
065          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
066          */
067         public final static Mid altKey   = id("altKey"  );
068         /**
069          * <p>An <b>internal</b> static field defining a member ID of the field name and
070          * used internally to define a member of the same name.</p>
071          * @since 1.0
072          * @see JsKeyEvent#charCode
073          * @see JsKeyEvent.Member#charCode
074          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
075          */
076         public final static Mid charCode = id("charCode");
077         /**
078          * <p>An <b>internal</b> static field defining a member ID of the field name and
079          * used internally to define a member of the same name.</p>
080          * @since 1.0
081          * @see JsKeyEvent#ctrlKey
082          * @see JsKeyEvent.Member#ctrlKey
083          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
084          */
085         public final static Mid ctrlKey  = id("ctrlKey" );
086         /**
087          * <p>An <b>internal</b> static field defining a member ID of the field name and
088          * used internally to define a member of the same name.</p>
089          * @since 1.0
090          * @see JsKeyEvent#keyCode
091          * @see JsKeyEvent.Member#keyCode
092          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
093          */
094         public final static Mid keyCode  = id("keyCode" );
095         /**
096          * <p>An <b>internal</b> static field defining a member ID of the field name and
097          * used internally to define a member of the same name.</p>
098          * @since 1.0
099          * @see JsKeyEvent#shiftKey
100          * @see JsKeyEvent.Member#shiftKey
101          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
102          */
103         public final static Mid shiftKey = id("shiftKey");
104     }
105 
106     /**
107      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
108      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
109      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
110      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
111      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
112      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
113      * either circumstance, the field names must be exactly same as the member names, as 
114      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
115      * based on the field names.</p>
116      *
117      * @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>
118      * 
119      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
120      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
121      * of class objects.
122      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
123      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
124      * <pre>q.m</pre>
125      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
126      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
127      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
128      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
129      * <pre>m</pre>
130      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
131      * error on the access to <b>opaque</b> fields declared by this class under any other 
132      * circumstances.
133      */
134     public static class Member extends JsClient.KeyEvent.Prototype.Member
135     {
136         /**
137          * <p>Internally constructs a member based on a qualifying member.</p>
138          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
139          * or <b>internal</b> classes or class members.</p>
140          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
141          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
142          * declared in the declaring class of this constructor itself or its subclasses. 
143          * Under this circumstance, the field names must be exactly same as the member 
144          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
145          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
146          * to their names appending to the name resolved from the specified qualifying 
147          * member with a dot in between.</p>
148          * @param q A qualifying member
149          * @param mid The ID of the member to construct
150          * @since 1.0
151          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
152          */
153         public Member(JsObject.Member q, Mid mid) {
154             super(q, mid);
155         }
156         /**
157          * <p>Internally constructs a member without a qualifying member.</p>
158          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
159          * or <b>internal</b> classes or class members.</p>
160          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
161          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
162          * declared in <b>opaque</b> types other than the declaring class of this constructor 
163          * itself and its subclasses. Under this circumstance, the field names must be
164          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
165          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
166          * @param mid The ID of the member to construct
167          * @since 1.0
168          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
169          */
170         public Member(Mid mid) {
171             super(mid);
172         }
173         @Override
174         /**
175          * <p>Evaluates the property, represented by the current member instance, of the
176          * argument object.</p>
177          * @param o The argument object
178          * @return The value of the current member based on the object argument.
179          * @since 1.0
180          * @javascript Re-compilers must convert the instance invocation of this method into
181          * the JavaScript expression: 
182          * <pre>o.m</pre>
183          * where <tt>m</tt> is the identifier name resolved from the current member
184          * instance of the invocation.
185          */
186         public JsKeyEvent with(ObjectLike o) {
187             return new JsKeyEvent(super.with(o));
188         }
189 
190         /**
191          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
192          * name of this field, qualified by the current member instance of the field, and 
193          * to access the property of the name on an object.</p>
194          * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
195          * refers to a read-only boolean value which tells whether the <tt>Alt</tt> key 
196          * was held down when the event occurred.</p>
197          * @since 1.0
198          * @javascript Re-compilers must resolve the member of this instance field to the
199          * identifier of the field name appending to the identifier resolved from its 
200          * qualifying member with a dot in between.
201          */
202         public final Value.Boolean.Member altKey   = new Value.Boolean.Member(this, Members.altKey  );
203         /**
204          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
205          * name of this field, qualified by the current member instance of the field, and 
206          * to access the property of the name on an object.</p>
207          * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
208          * refers to a read-only boolean value which tells whether the <tt>Ctrl</tt> key 
209          * was held down when the event occurred.</p>
210          * @since 1.0
211          * @javascript Re-compilers must resolve the member of this instance field to the
212          * identifier of the field name appending to the identifier resolved from its 
213          * qualifying member with a dot in between.
214          */
215         public final Value.Boolean.Member ctrlKey  = new Value.Boolean.Member(this, Members.ctrlKey );
216         /**
217          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
218          * name of this field, qualified by the current member instance of the field, and 
219          * to access the property of the name on an object.</p>
220          * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
221          * refers to a read-only boolean value which tells whether the <tt>Shift</tt> key 
222          * was held down when the event occurred.</p>
223          * @since 1.0
224          * @javascript Re-compilers must resolve the member of this instance field to the
225          * identifier of the field name appending to the identifier resolved from its 
226          * qualifying member with a dot in between.
227          */
228         public final Value.Boolean.Member shiftKey = new Value.Boolean.Member(this, Members.shiftKey);
229         /**
230          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
231          * name of this field, qualified by the current member instance of the field, and 
232          * to access the property of the name on an object.</p>
233          * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
234          * refers to a read-only integer value specifying the unicode encoding of the 
235          * printable character (if any) generated by a "keypress" event. This property 
236          * is 0 for non-printing function keys and is not used for "keydown" and "keyup" 
237          * events. Use {@link js.core.JsGlobal.String#fromCharCode(Object)} to convert this 
238          * property to a string.</p>
239          * @since 1.0
240          * @javascript Re-compilers must resolve the member of this instance field to the
241          * identifier of the field name appending to the identifier resolved from its 
242          * qualifying member with a dot in between.
243          */
244         public final Value.Number.Member charCode = new Value.Number.Member(this, Members.charCode);
245         /**
246          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
247          * name of this field, qualified by the current member instance of the field, and 
248          * to access the property of the name on an object.</p>
249          * <p>The property, identified by this member, of a {@link JsKeyEvent} object is 
250          * reference to an integer value representing virtual key code of the key that 
251          * was pressed. Key codes may be browser, OS, and keyboard dependent. Typically, 
252          * when a key displays a printing character on it, the virtual key code for that 
253          * key is the same as the encoding of the character. Key codes for non-printing 
254          * function keys may vary more.</p> 
255          * @since 1.0
256          * @javascript Re-compilers must resolve the member of this instance field to the
257          * identifier of the field name appending to the identifier resolved from its 
258          * qualifying member with a dot in between.
259          */
260         public final Value.Number.Member keyCode  = new Value.Number.Member(this, Members.keyCode );
261     }
262 
263     /**
264      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
265      * with the wrapping constructor.</p>
266      * @param var The argument of an <b>opaque</b> object.
267      * @since 1.0
268      * @javascript Re-compilers must ignore the construction operation of this constructor,
269      * that is, replacing it with its only argument.
270      */
271     public JsKeyEvent(JsObject var) {
272         super(var);
273     }
274 
275     /**
276      * <p>An <b>opaque</b> static field defining a member that is named by the field name
277      * without a qualifying member and to access the property of the name on an object.</p>
278      * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
279      * refers to a read-only boolean value which tells whether the <tt>Alt</tt> key 
280      * was held down when the event occurred.</p>
281      * @since 1.0
282      * @javascript Re-compilers must resolve the member of this static field to the
283      * identifier of the field name.
284      */
285     public static final Value.Boolean.Member altKey   = new Value.Boolean.Member(Members.altKey  );
286     /**
287      * <p>An <b>opaque</b> static field defining a member that is named by the field name
288      * without a qualifying member and to access the property of the name on an object.</p>
289      * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
290      * refers to a read-only boolean value which tells whether the <tt>Ctrl</tt> key 
291      * was held down when the event occurred.</p>
292      * @since 1.0
293      * @javascript Re-compilers must resolve the member of this static field to the
294      * identifier of the field name.
295      */
296     public static final Value.Boolean.Member ctrlKey  = new Value.Boolean.Member(Members.ctrlKey );
297     /**
298      * <p>An <b>opaque</b> static field defining a member that is named by the field name
299      * without a qualifying member and to access the property of the name on an object.</p>
300      * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
301      * refers to a read-only boolean value which tells whether the <tt>Shift</tt> key 
302      * was held down when the event occurred.</p>
303      * @since 1.0
304      * @javascript Re-compilers must resolve the member of this static field to the
305      * identifier of the field name.
306      */
307     public static final Value.Boolean.Member shiftKey = new Value.Boolean.Member(Members.shiftKey);
308     /**
309      * <p>An <b>opaque</b> static field defining a member that is named by the field name
310      * without a qualifying member and to access the property of the name on an object.</p>
311      * <p>The property, identified by this member, of a {@link JsKeyEvent} object 
312      * refers to a read-only integer value specifying the unicode encoding of the 
313      * printable character (if any) generated by a "keypress" event. This property 
314      * is 0 for non-printing function keys and is not used for "keydown" and "keyup" 
315      * events. Use {@link js.core.JsGlobal.String#fromCharCode(Object)} to convert this 
316      * property to a string.</p>
317      * @since 1.0
318      * @javascript Re-compilers must resolve the member of this static field to the
319      * identifier of the field name.
320      */
321     public static final Value.Number.Member charCode = new Value.Number.Member(Members.charCode);
322     /**
323      * <p>An <b>opaque</b> static field defining a member that is named by the field name
324      * without a qualifying member and to access the property of the name on an object.</p>
325      * <p>The property, identified by this member, of a {@link JsKeyEvent} object is 
326      * reference to an integer value representing virtual key code of the key that 
327      * was pressed. Key codes may be browser, OS, and keyboard dependent. Typically, 
328      * when a key displays a printing character on it, the virtual key code for that 
329      * key is the same as the encoding of the character. Key codes for non-printing 
330      * function keys may vary more.</p> 
331      * @since 1.0
332      * @javascript Re-compilers must resolve the member of this static field to the
333      * identifier of the field name.
334      */
335     public static final Value.Number.Member keyCode  = new Value.Number.Member(Members.keyCode );
336 
337     @Override
338     /**
339      * <p>Returns the primitive value associated with the current instance, if there is one.
340      * This invocation simply returns the instance itself for the current instance is an 
341      * object and there is no primitive value for it.</p>
342      * @return The current object itself.
343      * @since 1.0
344      * @javascript Re-compilers must convert the instance invocation of this method directly
345      * into a JavaScript invocation on its current object instance without changing the 
346      * method name, but expanding variable arguments, if any, into comma-separated values. 
347      */
348     public JsKeyEvent valueOf() {
349         return new JsKeyEvent((JsObject)var().valueOf());
350     }
351 }