View Javadoc
1   /*
2    * Copyright (c) 2002-2026 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit;
16  
17  import java.io.Serializable;
18  
19  import org.htmlunit.css.ComputedCssStyleDeclaration;
20  import org.htmlunit.html.DomElement;
21  import org.htmlunit.javascript.HtmlUnitScriptable;
22  import org.htmlunit.javascript.background.JavaScriptJobManager;
23  
24  /**
25   * An interface that represents one window in a browser. It could be a top level window or a frame.
26   *
27   * @author Mike Bowler
28   * @author David K. Taylor
29   * @author David D. Kilzer
30   * @author Ronald Brill
31   */
32  public interface WebWindow extends Serializable {
33  
34      /**
35       * Returns the name of this window.
36       *
37       * @return the name of this window
38       */
39      String getName();
40  
41      /**
42       * Sets the name of this window.
43       *
44       * @param name the new window name
45       */
46      void setName(String name);
47  
48      /**
49       * Returns the currently loaded page or null if no page has been loaded.
50       *
51       * @return the currently loaded page or null if no page has been loaded
52       */
53      Page getEnclosedPage();
54  
55      /**
56       * Sets the currently loaded page.
57       *
58       * @param page the new page or null if there is no page (ie empty window)
59       */
60      void setEnclosedPage(Page page);
61  
62      /**
63       * Returns the window that contains this window. If this is a top
64       * level window, then return this window.
65       *
66       * @return the parent window or this window if there is no parent
67       */
68      WebWindow getParentWindow();
69  
70      /**
71       * Returns the top level window that contains this window. If this
72       * is a top level window, then return this window.
73       *
74       * @return the top level window that contains this window or this
75       *         window if there is no parent.
76       */
77      WebWindow getTopWindow();
78  
79      /**
80       * Returns the web client that "owns" this window.
81       *
82       * @return the web client or null if this window has been closed
83       */
84      WebClient getWebClient();
85  
86      /**
87       * Returns this window's navigation history.
88       *
89       * @return this window's navigation history
90       */
91      History getHistory();
92  
93      /**
94       * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
95       *
96       * Sets the JavaScript object that corresponds to this element. This is not guaranteed
97       * to be set even if there is a JavaScript object for this HTML element.
98       *
99       * @param <T> the object type
100      * @param scriptObject the JavaScript object
101      */
102     <T extends HtmlUnitScriptable> void setScriptableObject(T scriptObject);
103 
104     /**
105      * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
106      *
107      * Returns the JavaScript object that corresponds to this element.
108      *
109      * @param <T> the object type
110      * @return the JavaScript object that corresponds to this element
111      */
112     <T> T getScriptableObject();
113 
114     /**
115      * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
116      *
117      * Returns the job manager for this window.
118      *
119      * @return the job manager for this window
120      */
121     JavaScriptJobManager getJobManager();
122 
123     /**
124      * Indicates if this window is closed. No action should be performed on a closed window.
125      * @return {@code true} when the window is closed
126      */
127     boolean isClosed();
128 
129     /**
130      * Returns the width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.
131      * @return the inner width.
132      */
133     int getInnerWidth();
134 
135     /**
136      * Sets the width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.
137      * @param innerWidth the inner width
138      */
139     void setInnerWidth(int innerWidth);
140 
141     /**
142      * Returns the width of the outside of the browser window.
143      * It represents the width of the whole browser window including sidebar (if expanded),
144      * window chrome and window resizing borders/handles.
145      * @return the outer width
146      */
147     int getOuterWidth();
148 
149     /**
150      * Sets the width of the outside of the browser window.
151      * It represents the width of the whole browser window including sidebar (if expanded),
152      * window chrome and window resizing borders/handles.
153      * @param outerWidth the outer width
154      */
155     void setOuterWidth(int outerWidth);
156 
157     /**
158      * Returns the height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.
159      * @return a inner height
160      */
161     int getInnerHeight();
162 
163     /**
164      * Sets the height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.
165      * @param innerHeight the inner height
166      */
167     void setInnerHeight(int innerHeight);
168 
169     /**
170      * Returns the height in pixels of the whole browser window.
171      * It represents the height of the whole browser window including sidebar (if expanded),
172      * window chrome and window resizing borders/handles.
173      * @return the outer height
174      */
175     int getOuterHeight();
176 
177     /**
178      * Sets the height in pixels of the whole browser window.
179      * It represents the height of the whole browser window including sidebar (if expanded),
180      * window chrome and window resizing borders/handles.
181      * @param outerHeight the outer height
182      */
183     void setOuterHeight(int outerHeight);
184 
185     /**
186      * @return the screen this window belongs to
187      */
188     Screen getScreen();
189 
190     /**
191      * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
192      *
193      * Returns computed style of the element. Computed style represents the final computed values
194      * of all CSS properties for the element. This method's return value is of the same type as
195      * that of <code>element.style</code>, but the value returned by this method is read-only.
196      *
197      * @param element the element
198      * @param pseudoElement a string specifying the pseudo-element to match (may be {@code null});
199      *        e.g. ':before'
200      * @return the computed style
201      */
202     ComputedCssStyleDeclaration getComputedStyle(DomElement element, String pseudoElement);
203 }