View Javadoc
1   /*
2    * Copyright (c) 2002-2025 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 <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
28   * @author David K. Taylor
29   * @author David D. Kilzer
30   */
31  public interface WebWindow extends Serializable {
32  
33      /**
34       * Returns the name of this window.
35       *
36       * @return the name of this window
37       */
38      String getName();
39  
40      /**
41       * Sets the name of this window.
42       *
43       * @param name the new window name
44       */
45      void setName(String name);
46  
47      /**
48       * Returns the currently loaded page or null if no page has been loaded.
49       *
50       * @return the currently loaded page or null if no page has been loaded
51       */
52      Page getEnclosedPage();
53  
54      /**
55       * Sets the currently loaded page.
56       *
57       * @param page the new page or null if there is no page (ie empty window)
58       */
59      void setEnclosedPage(Page page);
60  
61      /**
62       * Returns the window that contains this window. If this is a top
63       * level window, then return this window.
64       *
65       * @return the parent window or this window if there is no parent
66       */
67      WebWindow getParentWindow();
68  
69      /**
70       * Returns the top level window that contains this window. If this
71       * is a top level window, then return this window.
72       *
73       * @return the top level window that contains this window or this
74       *         window if there is no parent.
75       */
76      WebWindow getTopWindow();
77  
78      /**
79       * Returns the web client that "owns" this window.
80       *
81       * @return the web client or null if this window has been closed
82       */
83      WebClient getWebClient();
84  
85      /**
86       * Returns this window's navigation history.
87       *
88       * @return this window's navigation history
89       */
90      History getHistory();
91  
92      /**
93       * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
94       *
95       * Sets the JavaScript object that corresponds to this element. This is not guaranteed
96       * to be set even if there is a JavaScript object for this HTML element.
97       *
98       * @param <T> the object type
99       * @param scriptObject the JavaScript object
100      */
101     <T extends HtmlUnitScriptable> void setScriptableObject(T scriptObject);
102 
103     /**
104      * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
105      *
106      * Returns the JavaScript object that corresponds to this element.
107      *
108      * @param <T> the object type
109      * @return the JavaScript object that corresponds to this element
110      */
111     <T> T getScriptableObject();
112 
113     /**
114      * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
115      *
116      * Returns the job manager for this window.
117      *
118      * @return the job manager for this window
119      */
120     JavaScriptJobManager getJobManager();
121 
122     /**
123      * Indicates if this window is closed. No action should be performed on a closed window.
124      * @return {@code true} when the window is closed
125      */
126     boolean isClosed();
127 
128     /**
129      * Returns the width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.
130      * @return the inner width.
131      */
132     int getInnerWidth();
133 
134     /**
135      * Sets the width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.
136      * @param innerWidth the inner width
137      */
138     void setInnerWidth(int innerWidth);
139 
140     /**
141      * Returns the width of the outside of the browser window.
142      * It represents the width of the whole browser window including sidebar (if expanded),
143      * window chrome and window resizing borders/handles.
144      * @return the outer width
145      */
146     int getOuterWidth();
147 
148     /**
149      * Sets the width of the outside of the browser window.
150      * It represents the width of the whole browser window including sidebar (if expanded),
151      * window chrome and window resizing borders/handles.
152      * @param outerWidth the outer width
153      */
154     void setOuterWidth(int outerWidth);
155 
156     /**
157      * Returns the height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.
158      * @return a inner height
159      */
160     int getInnerHeight();
161 
162     /**
163      * Sets the height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.
164      * @param innerHeight the inner height
165      */
166     void setInnerHeight(int innerHeight);
167 
168     /**
169      * Returns the height in pixels of the whole browser window.
170      * It represents the height of the whole browser window including sidebar (if expanded),
171      * window chrome and window resizing borders/handles.
172      * @return the outer height
173      */
174     int getOuterHeight();
175 
176     /**
177      * Sets the height in pixels of the whole browser window.
178      * It represents the height of the whole browser window including sidebar (if expanded),
179      * window chrome and window resizing borders/handles.
180      * @param outerHeight the outer height
181      */
182     void setOuterHeight(int outerHeight);
183 
184     /**
185      * @return the screen this window belongs to
186      */
187     Screen getScreen();
188 
189     /**
190      * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
191      *
192      * Returns computed style of the element. Computed style represents the final computed values
193      * of all CSS properties for the element. This method's return value is of the same type as
194      * that of <code>element.style</code>, but the value returned by this method is read-only.
195      *
196      * @param element the element
197      * @param pseudoElement a string specifying the pseudo-element to match (may be {@code null});
198      *        e.g. ':before'
199      * @return the computed style
200      */
201     ComputedCssStyleDeclaration getComputedStyle(DomElement element, String pseudoElement);
202 }