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