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.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   * A JavaScript object for {@code Screen}.
32   *
33   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
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="http://msdn.microsoft.com/en-us/library/ms535868.aspx">
41   * MSDN documentation</a>
42   * @see <a href="http://www.mozilla.org/docs/dom/domref/dom_window_ref.html">Mozilla documentation</a>
43   */
44  @JsxClass
45  public class Screen extends EventTarget {
46  
47      private org.htmlunit.Screen screen_;
48  
49      /**
50       * Creates an instance.
51       */
52      public Screen() {
53          super();
54      }
55  
56      /**
57       * JavaScript constructor.
58       */
59      @Override
60      @JsxConstructor
61      public void jsConstructor() {
62          super.jsConstructor();
63      }
64  
65      /**
66       * Creates an instance.
67       * @param screen the backend
68       */
69      public Screen(final org.htmlunit.Screen screen) {
70          screen_ = screen;
71      }
72  
73      /**
74       * Returns the {@code availHeight} property.
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       * @return the {@code availLeft} property
85       */
86      @JsxGetter
87      public int getAvailLeft() {
88          return screen_.getAvailLeft();
89      }
90  
91      /**
92       * Returns the {@code availTop} property.
93       * @return the {@code availTop} property
94       */
95      @JsxGetter
96      public int getAvailTop() {
97          return screen_.getAvailTop();
98      }
99  
100     /**
101      * Returns the {@code availWidth} property.
102      * @return the {@code availWidth} property
103      */
104     @JsxGetter
105     public int getAvailWidth() {
106         return screen_.getAvailWidth();
107     }
108 
109     /**
110      * Returns the {@code colorDepth} property.
111      * @return the {@code colorDepth} property
112      */
113     @JsxGetter
114     public int getColorDepth() {
115         return screen_.getColorDepth();
116     }
117 
118     /**
119      * Returns the {@code height} property.
120      * @return the {@code height} property
121      */
122     @JsxGetter
123     public int getHeight() {
124         return screen_.getHeight();
125     }
126 
127     /**
128      * Returns the {@code left} property.
129      * @return the {@code left} property
130      */
131     @JsxGetter({FF, FF_ESR})
132     public int getLeft() {
133         return screen_.getLeft();
134     }
135 
136     /**
137      * Returns the {@code pixelDepth} property.
138      * @return the {@code pixelDepth} property
139      */
140     @JsxGetter
141     public int getPixelDepth() {
142         return screen_.getPixelDepth();
143     }
144 
145     /**
146      * Returns the {@code top} property.
147      * @return the {@code top} property
148      */
149     @JsxGetter({FF, FF_ESR})
150     public int getTop() {
151         return screen_.getTop();
152     }
153 
154     /**
155      * Returns the {@code width} property.
156      * @return the {@code width} property
157      */
158     @JsxGetter
159     public int getWidth() {
160         return screen_.getWidth();
161     }
162 
163     /**
164      * Returns the {@code orientation} property.
165      * @return the {@code orientation} property
166      */
167     @JsxGetter
168     public ScreenOrientation getOrientation() {
169         final ScreenOrientation screenOrientation = new ScreenOrientation();
170         screenOrientation.setPrototype(getPrototype(screenOrientation.getClass()));
171         screenOrientation.setParentScope(getParentScope());
172 
173         return screenOrientation;
174     }
175 
176     /**
177      * Returns the {@code orientation} property.
178      * @return the {@code orientation} property
179      */
180     @JsxGetter({FF, FF_ESR})
181     public String getMozOrientation() {
182         return "landscape-primary";
183     }
184 
185     /**
186      * Returns the {@code orientation} property.
187      * @return the {@code orientation} property
188      */
189     @JsxGetter({CHROME, EDGE})
190     public boolean getIsExtended() {
191         return false;
192     }
193 
194     /**
195      * Returns the {@code onchange} event handler for this element.
196      * @return the {@code onchange} event handler for this element
197      */
198     @JsxGetter({CHROME, EDGE})
199     public Function getOnchange() {
200         return getEventHandler(Event.TYPE_CHANGE);
201     }
202 
203     /**
204      * Setter for the {@code onchange} event handler.
205      * @param change the handler
206      */
207     @JsxSetter({CHROME, EDGE})
208     public void setOnchange(final Object change) {
209         setEventHandler(Event.TYPE_CHANGE, change);
210     }
211 }