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.javascript.host;
16  
17  import static org.htmlunit.javascript.configuration.SupportedBrowser.CHROME;
18  import static org.htmlunit.javascript.configuration.SupportedBrowser.EDGE;
19  import static org.htmlunit.javascript.configuration.SupportedBrowser.FF;
20  import static org.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR;
21  
22  import org.htmlunit.corejs.javascript.Function;
23  import org.htmlunit.javascript.configuration.JsxClass;
24  import org.htmlunit.javascript.configuration.JsxConstructor;
25  import org.htmlunit.javascript.configuration.JsxGetter;
26  import org.htmlunit.javascript.configuration.JsxSetter;
27  import org.htmlunit.javascript.host.event.Event;
28  import org.htmlunit.javascript.host.event.EventTarget;
29  
30  /**
31   * JavaScript host object for {@code Screen}.
32   *
33   * @author Mike Bowler
34   * @author Daniel Gredler
35   * @author Chris Erskine
36   * @author Ronald Brill
37   * @author Ahmed Ashour
38   * @author cd alexndr
39   *
40   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Screen">MDN Documentation</a>
41   */
42  @JsxClass
43  public class Screen extends EventTarget {
44  
45      private org.htmlunit.Screen screen_;
46  
47      /**
48       * Creates an instance.
49       */
50      public Screen() {
51          super();
52      }
53  
54      /**
55       * Creates an instance of this object.
56       */
57      @Override
58      @JsxConstructor
59      public void jsConstructor() {
60          super.jsConstructor();
61      }
62  
63      /**
64       * Creates an instance backed by the given screen.
65       *
66       * @param screen the backend screen
67       */
68      public Screen(final org.htmlunit.Screen screen) {
69          screen_ = screen;
70      }
71  
72      /**
73       * Returns the {@code availHeight} property.
74       *
75       * @return the {@code availHeight} property
76       */
77      @JsxGetter
78      public int getAvailHeight() {
79          return screen_.getAvailHeight();
80      }
81  
82      /**
83       * Returns the {@code availLeft} property.
84       *
85       * @return the {@code availLeft} property
86       */
87      @JsxGetter
88      public int getAvailLeft() {
89          return screen_.getAvailLeft();
90      }
91  
92      /**
93       * Returns the {@code availTop} property.
94       *
95       * @return the {@code availTop} property
96       */
97      @JsxGetter
98      public int getAvailTop() {
99          return screen_.getAvailTop();
100     }
101 
102     /**
103      * Returns the {@code availWidth} property.
104      *
105      * @return the {@code availWidth} property
106      */
107     @JsxGetter
108     public int getAvailWidth() {
109         return screen_.getAvailWidth();
110     }
111 
112     /**
113      * Returns the {@code colorDepth} property.
114      *
115      * @return the {@code colorDepth} property
116      */
117     @JsxGetter
118     public int getColorDepth() {
119         return screen_.getColorDepth();
120     }
121 
122     /**
123      * Returns the {@code height} property.
124      *
125      * @return the {@code height} property
126      */
127     @JsxGetter
128     public int getHeight() {
129         return screen_.getHeight();
130     }
131 
132     /**
133      * Returns the {@code left} property.
134      *
135      * @return the {@code left} property
136      */
137     @JsxGetter({FF, FF_ESR})
138     public int getLeft() {
139         return screen_.getLeft();
140     }
141 
142     /**
143      * Returns the {@code pixelDepth} property.
144      *
145      * @return the {@code pixelDepth} property
146      */
147     @JsxGetter
148     public int getPixelDepth() {
149         return screen_.getPixelDepth();
150     }
151 
152     /**
153      * Returns the {@code top} property.
154      *
155      * @return the {@code top} property
156      */
157     @JsxGetter({FF, FF_ESR})
158     public int getTop() {
159         return screen_.getTop();
160     }
161 
162     /**
163      * Returns the {@code width} property.
164      *
165      * @return the {@code width} property
166      */
167     @JsxGetter
168     public int getWidth() {
169         return screen_.getWidth();
170     }
171 
172     /**
173      * Returns the {@code orientation} property.
174      *
175      * @return the {@code orientation} property
176      */
177     @JsxGetter
178     public ScreenOrientation getOrientation() {
179         final ScreenOrientation screenOrientation = new ScreenOrientation();
180         screenOrientation.setPrototype(getPrototype(screenOrientation.getClass()));
181         screenOrientation.setParentScope(getParentScope());
182 
183         return screenOrientation;
184     }
185 
186     /**
187      * Returns the {@code mozOrientation} property.
188      *
189      * @return the {@code mozOrientation} property
190      */
191     @JsxGetter({FF, FF_ESR})
192     public String getMozOrientation() {
193         return "landscape-primary";
194     }
195 
196     /**
197      * Returns the {@code isExtended} property.
198      *
199      * @return the {@code isExtended} property
200      */
201     @JsxGetter({CHROME, EDGE})
202     public boolean isIsExtended() {
203         return false;
204     }
205 
206     /**
207      * Returns the {@code onchange} event handler for this element.
208      *
209      * @return the {@code onchange} event handler for this element
210      */
211     @JsxGetter({CHROME, EDGE})
212     public Function getOnchange() {
213         return getEventHandler(Event.TYPE_CHANGE);
214     }
215 
216     /**
217      * Sets the {@code onchange} event handler.
218      *
219      * @param change the {@code onchange} event handler
220      */
221     @JsxSetter({CHROME, EDGE})
222     public void setOnchange(final Object change) {
223         setEventHandler(Event.TYPE_CHANGE, change);
224     }
225 }