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.HtmlUnitScriptable;
18 import org.htmlunit.javascript.configuration.JsxClass;
19 import org.htmlunit.javascript.configuration.JsxConstructor;
20 import org.htmlunit.javascript.configuration.JsxGetter;
21 import org.htmlunit.javascript.configuration.JsxSetter;
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="http://msdn2.microsoft.com/en-us/library/ms535906.aspx">MSDN Documentation</a>
29 */
30 @JsxClass(className = "DOMRect")
31 public class ClientRect extends HtmlUnitScriptable {
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 ClientRect() {
42 super();
43 }
44
45 /**
46 * JavaScript constructor.
47 */
48 @JsxConstructor
49 public void jsConstructor() {
50 // nothing to do
51 }
52
53 /**
54 * Creates an instance, with the given coordinates.
55 *
56 * @param bottom the bottom coordinate of the rectangle surrounding the object content
57 * @param left the left coordinate of the rectangle surrounding the object content
58 * @param right the right coordinate of the rectangle surrounding the object content
59 * @param top the top coordinate of the rectangle surrounding the object content
60 */
61 public ClientRect(final int bottom, final int left, final int right, final int top) {
62 this();
63 bottom_ = bottom;
64 left_ = left;
65 right_ = right;
66 top_ = top;
67 }
68
69 /**
70 * Sets the bottom coordinate of the rectangle surrounding the object content.
71 * @param bottom the bottom coordinate of the rectangle surrounding the object content
72 */
73 @JsxSetter
74 public void setBottom(final int bottom) {
75 bottom_ = bottom;
76 }
77
78 /**
79 * Returns the bottom coordinate of the rectangle surrounding the object content.
80 * @return the bottom coordinate of the rectangle surrounding the object content
81 */
82 @JsxGetter
83 public int getBottom() {
84 return bottom_;
85 }
86
87 /**
88 * Sets the left coordinate of the rectangle surrounding the object content.
89 * @param left the left coordinate of the rectangle surrounding the object content
90 */
91 @JsxSetter
92 public void setLeft(final int left) {
93 left_ = left;
94 }
95
96 /**
97 * Returns the left coordinate of the rectangle surrounding the object content.
98 * @return the left coordinate of the rectangle surrounding the object content
99 */
100 @JsxGetter
101 public int getLeft() {
102 return left_;
103 }
104
105 /**
106 * Sets the right coordinate of the rectangle surrounding the object content.
107 * @param right the right coordinate of the rectangle surrounding the object content
108 */
109 @JsxSetter
110 public void setRight(final int right) {
111 right_ = right;
112 }
113
114 /**
115 * Returns the right coordinate of the rectangle surrounding the object content.
116 * @return the right coordinate of the rectangle surrounding the object content
117 */
118 @JsxGetter
119 public int getRight() {
120 return right_;
121 }
122
123 /**
124 * Sets the top coordinate of the rectangle surrounding the object content.
125 * @param top the top coordinate of the rectangle surrounding the object content
126 */
127 @JsxSetter
128 public void setTop(final int top) {
129 top_ = top;
130 }
131
132 /**
133 * Returns the top coordinate of the rectangle surrounding the object content.
134 * @return the top coordinate of the rectangle surrounding the object content
135 */
136 @JsxGetter
137 public int getTop() {
138 return top_;
139 }
140
141 /**
142 * Returns the {@code width} property.
143 * @return the {@code width} property
144 */
145 @JsxGetter
146 public int getWidth() {
147 return getRight() - getLeft();
148 }
149
150 /**
151 * Returns the {@code height} property.
152 * @return the {@code height} property
153 */
154 @JsxGetter
155 public int getHeight() {
156 return getBottom() - getTop();
157 }
158 }