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#History} class.</p>
028  * <p>This class was originally designed to represent the browsing history of a window. 
029  * For privacy reasons, however, it no longer allows scripted access to the actual URLs 
030  * that have been visited. The only functionality that remains is in the use of the 
031  * {@link #back()}, {@link #forward()}, and {@link #go(Number)} methods.</p>
032  *
033  * @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>
034  * @see JsWindow#history
035  * @see JsLocation
036  *
037  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be
038  * generated into the target codes. Re-compilers must exit with error on the operations of
039  * accessing that kind of class objects.
040  * The <tt>checkcast</tt> operation to the class literal of this interface must be ignored
041  * and <tt>instanceof</tt> to it always <tt>true</tt>.
042  */
043 public class JsHistory extends JsClient.History.Prototype
044 {
045     /**
046      * <p>An <b>internal</b> class containing membership data for its enclosing
047      * opaque class.</p>
048      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or
049      * class members.</p>
050      *
051      * @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>
052      * 
053      * @javascript Re-compilers must report error on resolving an <b>internal</b> class.
054      */
055     protected static abstract class Members extends JsClient.History.Prototype.Members
056     {
057         /**
058          * <p>An <b>internal</b> static field defining a member ID of the field name and
059          * used internally to define a member of the same name.</p>
060          * @since 1.0
061          * @see JsHistory#length
062          * @see JsHistory.Member#length
063          * @javascript Re-compilers must report error on accessing an <b>internal</b> field.
064          */
065         public final static Mid length = id("length");
066     }
067     /**
068      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
069      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
070      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
071      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
072      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
073      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
074      * either circumstance, the field names must be exactly same as the member names, as 
075      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
076      * based on the field names.</p>
077      *
078      * @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>
079      * 
080      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created
081      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
082      * of class objects.
083      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in
084      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
085      * <pre>q.m</pre>
086      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier
087      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
088      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
089      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
090      * <pre>m</pre>
091      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report
092      * error on the access to <b>opaque</b> fields declared by this class under any other 
093      * circumstances.
094      */
095     public static class Member extends JsClient.History.Prototype.Member
096     {
097         /**
098          * <p>Internally constructs a member based on a qualifying member.</p>
099          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
100          * or <b>internal</b> classes or class members.</p>
101          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
102          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
103          * declared in the declaring class of this constructor itself or its subclasses. 
104          * Under this circumstance, the field names must be exactly same as the member 
105          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
106          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly
107          * to their names appending to the name resolved from the specified qualifying 
108          * member with a dot in between.</p>
109          * @param q A qualifying member
110          * @param mid The ID of the member to construct
111          * @since 1.0
112          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
113          */
114         public Member(JsObject.Member q, Mid mid) {
115             super(q, mid);
116         }
117         /**
118          * <p>Internally constructs a member without a qualifying member.</p>
119          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b>
120          * or <b>internal</b> classes or class members.</p>
121          * <p>Note that, this constructor is <b>internal</b> but its declaring class is
122          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
123          * declared in <b>opaque</b> types other than the declaring class of this constructor 
124          * itself and its subclasses. Under this circumstance, the field names must be
125          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b>
126          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
127          * @param mid The ID of the member to construct
128          * @since 1.0
129          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor.
130          */
131         public Member(Mid mid) {
132             super(mid);
133         }
134         @Override
135         /**
136          * <p>Evaluates the property, represented by the current member instance, of the
137          * argument object.</p>
138          * @param o The argument object
139          * @return The value of the current member based on the object argument.
140          * @since 1.0
141          * @javascript Re-compilers must convert the instance invocation of this method into
142          * the JavaScript expression: 
143          * <pre>o.m</pre>
144          * where <tt>m</tt> is the identifier name resolved from the current member
145          * instance of the invocation.
146          */
147         public JsHistory with(ObjectLike o) {
148             return new JsHistory(super.with(o));
149         }
150         /**
151          * <p>Evaluates a property, represented by the current member instance, of the
152          * JavaScript global object, that is, evaluates the member to a global identifier.</p>
153          * @return The value of the current member based on the JavaScript global object.
154          * @since 1.0
155          * @javascript Re-compilers must convert the instance invocation of this method into
156          * the JavaScript expression: 
157          * <pre>m</pre>
158          * where <tt>m</tt> is the identifier name resolved from the current member
159          * instance of the invocation.
160          */
161         public JsHistory with() {
162             return with(Js.win());
163         }
164 
165         /**
166          * <p>An <b>opaque</b> instance field defining a sub-member that is named by the
167          * name of this field, qualified by the current member instance of the field, and 
168          * to access the property of the name on an object.</p>
169          * <p>The property, identified by this member, of a {@link JsHistory} object is 
170          * reference to an integer value specifying the number of URLs in the browser's 
171          * history list. Since there is no way to determine the index of the currently 
172          * displayed document within this list, knowing the size of this list is not 
173          * particularly helpful.</p> 
174          * @since 1.0
175          * @javascript Re-compilers must resolve the member of this instance field to the
176          * identifier of the field name appending to the identifier resolved from its 
177          * qualifying member with a dot in between.
178          */
179         public final Value.Number.Member length = new Value.Number.Member(this, Members.length);
180     }
181 
182     /**
183      * <p>Casts an <b>opaque</b> object to the current <b>opaque</b> type by wrapping it
184      * with the wrapping constructor.</p>
185      * @param var The argument of an <b>opaque</b> object.
186      * @since 1.0
187      * @javascript Re-compilers must ignore the construction operation of this constructor,
188      * that is, replacing it with its only argument.
189      */
190     public JsHistory(JsObject var) {
191         super(var);
192     }
193 
194     /**
195      * <p>An <b>opaque</b> static field defining a member that is named by the field name
196      * without a qualifying member and to access the property of the name on an object.</p>
197      * <p>The property, identified by this member, of a {@link JsHistory} object is 
198      * reference to an integer value specifying the number of URLs in the browser's 
199      * history list. Since there is no way to determine the index of the currently 
200      * displayed document within this list, knowing the size of this list is not 
201      * particularly helpful.</p> 
202      * @since 1.0
203      * @javascript Re-compilers must resolve the member of this static field to the
204      * identifier of the field name.
205      */
206     public static final Value.Number.Member length = new Value.Number.Member(Members.length);
207 
208     @Override
209     /**
210      * <p>Returns the primitive value associated with the current instance, if there is one.
211      * This invocation simply returns the instance itself for the current instance is an 
212      * object and there is no primitive value for it.</p>
213      * @return The current object itself.
214      * @since 1.0
215      * @javascript Re-compilers must convert the instance invocation of this method directly
216      * into a JavaScript invocation on its current object instance without changing the 
217      * method name, but expanding variable arguments, if any, into comma-separated values. 
218      */
219     public final JsHistory valueOf() {
220         return new JsHistory((JsObject)var().valueOf());
221     }
222 
223     /**
224      * <p>Goes backward to a previously visited URL.</p>
225      * <p>A call of this method causes the window or frame to which the {@link JsHistory} 
226      * object belongs to revisit the URL (if any) that was visited immediately before 
227      * the current one. Calling this method has the same effect as clicking on the 
228      * browser's <tt>Back</tt> button. It is also equivalent to:
229      * <pre>Js.g().history.go(-1);</pre>
230      * </p>
231      * @since 1.0
232      * @javascript Re-compilers must convert the instance invocation of this method directly
233      * into a JavaScript invocation on its current object instance without changing the 
234      * method name, but expanding variable arguments, if any, into comma-separated values. 
235      */
236     public final void back() {
237         call(back);
238     }
239     /**
240      * <p>Goes forward to a previously visited URL.</p>
241      * <p>A call of this method causes the window or frame to which the {@link JsHistory} 
242      * object belongs to revisit the URL (if any) that was visited immediately afters 
243      * the current one. Calling this method has the same effect as clicking on the 
244      * browser's <tt>Forward</tt> button. It is also equivalent to:
245      * <pre>Js.g().history.go(1);</pre>
246      * </p>
247      * <p>Note that if the browser user has not used the <tt>Back</tt> button or the 
248      * <tt>Go</tt> menu to move backward through the history, and {@link #back()} and 
249      * {@link #go(Number)} methods have not been invoked, invoking this method has no 
250      * effect because the browser is already at the end of its list of URLs, and there 
251      * is no URL to go forward to.</p>
252      * @since 1.0
253      * @javascript Re-compilers must convert the instance invocation of this method directly
254      * into a JavaScript invocation on its current object instance without changing the 
255      * method name, but expanding variable arguments, if any, into comma-separated values. 
256      */
257     public final void forward() {
258         call(forward);
259     }
260     /**
261      * <p>Goes to a previously visited URL.</p>
262      * <p>This method takes an integer argument and causes the browser to visit the URL 
263      * that is the specified number of positions away in the history list maintained by 
264      * the {@link JsHistory} object. Positive arguments move the browser forward through 
265      * the list, and negative arguments move it backward. Thus, calling <tt>Js.g().history.go(-1)</tt> 
266      * is equivalent to calling <tt>Js.g().history.back()</tt> and produces the same 
267      * effect as clicking on the <tt>Back</tt> button. Similarly, <tt>Js.g().history.go(3)</tt> 
268      * revisits the same URL that would be visited by calling <tt>Js.g().history.forward()</tt> 
269      * three times.</p>
270      * @param relative_position The relative position in the history list of the URL to 
271      * be visited.
272      * @since 1.0
273      * @javascript Re-compilers must convert the instance invocation of this method directly
274      * into a JavaScript invocation on its current object instance without changing the 
275      * method name, but expanding variable arguments, if any, into comma-separated values. 
276      */
277     public final void go(Number relative_position) {
278         call(go, relative_position);
279     }
280     /**
281      * <p>Goes to a previously visited URL.</p>
282      * <p>This method takes an integer argument and causes the browser to visit the URL 
283      * that is the specified number of positions away in the history list maintained by 
284      * the {@link JsHistory} object. Positive arguments move the browser forward through 
285      * the list, and negative arguments move it backward. Thus, calling <tt>Js.g().history.go(-1)</tt> 
286      * is equivalent to calling <tt>Js.g().history.back()</tt> and produces the same 
287      * effect as clicking on the <tt>Back</tt> button. Similarly, <tt>Js.g().history.go(3)</tt> 
288      * revisits the same URL that would be visited by calling <tt>Js.g().history.forward()</tt> 
289      * three times.</p>
290      * @param relative_position The relative position in the history list of the URL to 
291      * be visited.
292      * @since 1.0
293      * @javascript Re-compilers must convert the instance invocation of this method directly
294      * into a JavaScript invocation on its current object instance without changing the 
295      * method name, but expanding variable arguments, if any, into comma-separated values. 
296      */
297     public final void go(NumberLike<?> relative_position) {
298         go(Js.valueOf(relative_position));
299     }
300     /**
301      * <p>Goes to a previously visited URL.</p>
302      * <p>This method takes a string argument and causes the browser to revisit the 
303      * first, that is most recently visited, URL that contains the specified string. 
304      * This form of the method is not well specified and may work differently on different 
305      * browsers. For example, Microsoft's documentation specifies that the argument 
306      * must match the URL of a previously specified site exactly, while old Netscape 
307      * documentation (Netscape created the <tt>History</tt> object) says that the 
308      * argument may be a substring of a previously visited URL.</p>
309      * @param target_string A URL (or URL fragment) to be visited, if a matching URL 
310      * exists in the history list.
311      * @since 1.0
312      * @javascript Re-compilers must convert the instance invocation of this method directly
313      * into a JavaScript invocation on its current object instance without changing the 
314      * method name, but expanding variable arguments, if any, into comma-separated values. 
315      */
316     public final void go(String target_string) {
317         call(go, target_string);
318     }
319     /**
320      * <p>Goes to a previously visited URL.</p>
321      * <p>This method takes a string argument and causes the browser to revisit the 
322      * first, that is most recently visited, URL that contains the specified string. 
323      * This form of the method is not well specified and may work differently on different 
324      * browsers. For example, Microsoft's documentation specifies that the argument 
325      * must match the URL of a previously specified site exactly, while old Netscape 
326      * documentation (Netscape created the <tt>History</tt> object) says that the 
327      * argument may be a substring of a previously visited URL.</p>
328      * @param target_string A URL (or URL fragment) to be visited, if a matching URL 
329      * exists in the history list.
330      * @since 1.0
331      * @javascript Re-compilers must convert the instance invocation of this method directly
332      * into a JavaScript invocation on its current object instance without changing the 
333      * method name, but expanding variable arguments, if any, into comma-separated values. 
334      */
335     public final void go(StringLike target_string) {
336         go(Js.valueOf(target_string));
337     }
338 }