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 org.htmlunit.corejs.javascript.Context;
18  import org.htmlunit.corejs.javascript.Function;
19  import org.htmlunit.corejs.javascript.Scriptable;
20  import org.htmlunit.javascript.configuration.JsxClass;
21  import org.htmlunit.javascript.configuration.JsxConstructor;
22  import org.htmlunit.javascript.configuration.JsxGetter;
23  import org.htmlunit.javascript.configuration.JsxSetter;
24  import org.htmlunit.javascript.host.dom.DOMRectReadOnly;
25  
26  /**
27   * Specifies a rectangle that contains a line of text in either an element or a TextRange object.
28   *
29   * @author Ahmed Ashour
30   * @author Ronald Brill
31   * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMRect">DOMRect</a>
32   */
33  @JsxClass
34  public class DOMRect extends DOMRectReadOnly {
35  
36      /**
37       * JavaScript constructor.
38       * @param cx the current context
39       * @param scope the scope
40       * @param args the arguments to the WebSocket constructor
41       * @param ctorObj the function object
42       * @param inNewExpr Is new or not
43       * @return the java object to allow JavaScript to access
44       */
45      @JsxConstructor
46      public static DOMRect jsConstructor(final Context cx, final Scriptable scope,
47              final Object[] args, final Function ctorObj, final boolean inNewExpr) {
48  
49          final DOMRect rect = new DOMRect();
50          rect.init(args, ctorObj);
51          return rect;
52      }
53  
54      /**
55       * Creates an instance.
56       */
57      public DOMRect() {
58          super();
59      }
60  
61      /**
62       * Creates an instance, with the given coordinates.
63       *
64       * @param x the x coordinate of the rectangle surrounding the object content
65       * @param y the y coordinate of the rectangle surrounding the object content
66       * @param width the width coordinate of the rectangle surrounding the object content
67       * @param height the height of the rectangle surrounding the object content
68       */
69      public DOMRect(final int x, final int y, final int width, final int height) {
70          super(x, y, width, height);
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      @JsxGetter
78      public double getX() {
79          return super.getX();
80      }
81  
82      /**
83       * {@inheritDoc}
84       */
85      @Override
86      @JsxSetter
87      public void setX(final double x) {
88          super.setX(x);
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      @JsxGetter
96      public double getY() {
97          return super.getY();
98      }
99  
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     @JsxSetter
105     public void setY(final double y) {
106         super.setY(y);
107     }
108 
109     /**
110      * {@inheritDoc}
111      */
112     @Override
113     @JsxGetter
114     public double getWidth() {
115         return super.getWidth();
116     }
117 
118     /**
119      * {@inheritDoc}
120      */
121     @Override
122     @JsxSetter
123     public void setWidth(final double width) {
124         super.setWidth(width);
125     }
126 
127     /**
128      * {@inheritDoc}
129      */
130     @Override
131     @JsxGetter
132     public double getHeight() {
133         return super.getHeight();
134     }
135 
136     /**
137      * {@inheritDoc}
138      */
139     @Override
140     @JsxSetter
141     public void setHeight(final double height) {
142         super.setHeight(height);
143     }
144 }