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.javascript.configuration.JsxClass;
18 import org.htmlunit.javascript.configuration.JsxConstructor;
19 import org.htmlunit.javascript.configuration.JsxGetter;
20 import org.htmlunit.javascript.configuration.JsxSetter;
21 import org.htmlunit.javascript.host.dom.DOMRectReadOnly;
22
23 /**
24 * Specifies a rectangle that contains a line of text in either an element or a TextRange object.
25 *
26 * @author Ahmed Ashour
27 * @author Ronald Brill
28 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMRect">DOMRect</a>
29 */
30 @JsxClass
31 public class DOMRect extends DOMRectReadOnly {
32
33 private int bottom_;
34 private int left_;
35 private int right_;
36 private int top_;
37
38 /**
39 * Creates an instance.
40 */
41 public DOMRect() {
42 super();
43 }
44
45 /**
46 * JavaScript constructor.
47 */
48 @JsxConstructor
49 @Override
50 public void jsConstructor() {
51 super.jsConstructor();
52 }
53
54 /**
55 * Creates an instance, with the given coordinates.
56 *
57 * @param bottom the bottom coordinate of the rectangle surrounding the object content
58 * @param left the left coordinate of the rectangle surrounding the object content
59 * @param right the right coordinate of the rectangle surrounding the object content
60 * @param top the top coordinate of the rectangle surrounding the object content
61 */
62 public DOMRect(final int bottom, final int left, final int right, final int top) {
63 this();
64 bottom_ = bottom;
65 left_ = left;
66 right_ = right;
67 top_ = top;
68 }
69
70 /**
71 * Sets the bottom coordinate of the rectangle surrounding the object content.
72 * @param bottom the bottom coordinate of the rectangle surrounding the object content
73 */
74 @JsxSetter
75 public void setBottom(final int bottom) {
76 bottom_ = bottom;
77 }
78
79 /**
80 * Returns the bottom coordinate of the rectangle surrounding the object content.
81 * @return the bottom coordinate of the rectangle surrounding the object content
82 */
83 @JsxGetter
84 public int getBottom() {
85 return bottom_;
86 }
87
88 /**
89 * Sets the left coordinate of the rectangle surrounding the object content.
90 * @param left the left coordinate of the rectangle surrounding the object content
91 */
92 @JsxSetter
93 public void setLeft(final int left) {
94 left_ = left;
95 }
96
97 /**
98 * Returns the left coordinate of the rectangle surrounding the object content.
99 * @return the left coordinate of the rectangle surrounding the object content
100 */
101 @JsxGetter
102 public int getLeft() {
103 return left_;
104 }
105
106 /**
107 * Sets the right coordinate of the rectangle surrounding the object content.
108 * @param right the right coordinate of the rectangle surrounding the object content
109 */
110 @JsxSetter
111 public void setRight(final int right) {
112 right_ = right;
113 }
114
115 /**
116 * Returns the right coordinate of the rectangle surrounding the object content.
117 * @return the right coordinate of the rectangle surrounding the object content
118 */
119 @JsxGetter
120 public int getRight() {
121 return right_;
122 }
123
124 /**
125 * Sets the top coordinate of the rectangle surrounding the object content.
126 * @param top the top coordinate of the rectangle surrounding the object content
127 */
128 @JsxSetter
129 public void setTop(final int top) {
130 top_ = top;
131 }
132
133 /**
134 * Returns the top coordinate of the rectangle surrounding the object content.
135 * @return the top coordinate of the rectangle surrounding the object content
136 */
137 @JsxGetter
138 public int getTop() {
139 return top_;
140 }
141
142 /**
143 * Returns the {@code width} property.
144 * @return the {@code width} property
145 */
146 @JsxGetter
147 public int getWidth() {
148 return getRight() - getLeft();
149 }
150
151 /**
152 * Returns the {@code height} property.
153 * @return the {@code height} property
154 */
155 @JsxGetter
156 public int getHeight() {
157 return getBottom() - getTop();
158 }
159 }