Skip to content

Commit 44b3f42

Browse files
committed
DOMRectReadOnly and DOMRect implementation improved, now we implement the whole interface
1 parent 804eb68 commit 44b3f42

File tree

12 files changed

+964
-127
lines changed

12 files changed

+964
-127
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="4.21.0" date="December xx, 2025" description="Firefox 145, core-js, Bugfixes">
11+
<action type="add" dev="rbri">
12+
DOMRectReadOnly and DOMRect implementation improved, now we implement the whole interface.
13+
</action>
1114
<action type="update" dev="rbri">
1215
neko: minor improvements by replacing some equalsIgnoreCase() calls by simple equals().
1316
</action>

src/main/java/org/htmlunit/javascript/host/DOMRect.java

Lines changed: 61 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
*/
1515
package org.htmlunit.javascript.host;
1616

17+
import org.htmlunit.corejs.javascript.Context;
18+
import org.htmlunit.corejs.javascript.Function;
19+
import org.htmlunit.corejs.javascript.Scriptable;
1720
import org.htmlunit.javascript.configuration.JsxClass;
1821
import org.htmlunit.javascript.configuration.JsxConstructor;
22+
import org.htmlunit.javascript.configuration.JsxConstructorAlias;
1923
import org.htmlunit.javascript.configuration.JsxGetter;
2024
import org.htmlunit.javascript.configuration.JsxSetter;
2125
import org.htmlunit.javascript.host.dom.DOMRectReadOnly;
@@ -30,130 +34,113 @@
3034
@JsxClass
3135
public class DOMRect extends DOMRectReadOnly {
3236

33-
private int bottom_;
34-
private int left_;
35-
private int right_;
36-
private int top_;
37-
3837
/**
39-
* Creates an instance.
38+
* JavaScript constructor.
39+
* @param cx the current context
40+
* @param scope the scope
41+
* @param args the arguments to the WebSocket constructor
42+
* @param ctorObj the function object
43+
* @param inNewExpr Is new or not
44+
* @return the java object to allow JavaScript to access
4045
*/
41-
public DOMRect() {
42-
super();
46+
@JsxConstructor
47+
@JsxConstructorAlias(alias = "WebKitCSSMatrix")
48+
public static DOMRect jsConstructor(final Context cx, final Scriptable scope,
49+
final Object[] args, final Function ctorObj, final boolean inNewExpr) {
50+
51+
final DOMRect rect = new DOMRect();
52+
rect.init(args, ctorObj);
53+
return rect;
4354
}
4455

4556
/**
46-
* JavaScript constructor.
57+
* Creates an instance.
4758
*/
48-
@JsxConstructor
49-
@Override
50-
public void jsConstructor() {
51-
super.jsConstructor();
59+
public DOMRect() {
60+
super();
5261
}
5362

5463
/**
5564
* Creates an instance, with the given coordinates.
5665
*
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
66+
* @param x the x coordinate of the rectangle surrounding the object content
67+
* @param y the y coordinate of the rectangle surrounding the object content
68+
* @param width the width coordinate of the rectangle surrounding the object content
69+
* @param height the height of the rectangle surrounding the object content
6170
*/
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;
71+
public DOMRect(final int x, final int y, final int width, final int height) {
72+
super(x, y, width, height);
6873
}
6974

7075
/**
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
76+
* {@inheritDoc}
8277
*/
78+
@Override
8379
@JsxGetter
84-
public int getBottom() {
85-
return bottom_;
80+
public double getX() {
81+
return super.getX();
8682
}
8783

8884
/**
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
85+
* {@inheritDoc}
9186
*/
87+
@Override
9288
@JsxSetter
93-
public void setLeft(final int left) {
94-
left_ = left;
89+
public void setX(final double x) {
90+
super.setX(x);
9591
}
9692

9793
/**
98-
* Returns the left coordinate of the rectangle surrounding the object content.
99-
* @return the left coordinate of the rectangle surrounding the object content
94+
* {@inheritDoc}
10095
*/
96+
@Override
10197
@JsxGetter
102-
public int getLeft() {
103-
return left_;
98+
public double getY() {
99+
return super.getY();
104100
}
105101

106102
/**
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
103+
* {@inheritDoc}
109104
*/
105+
@Override
110106
@JsxSetter
111-
public void setRight(final int right) {
112-
right_ = right;
107+
public void setY(final double y) {
108+
super.setY(y);
113109
}
114110

115111
/**
116-
* Returns the right coordinate of the rectangle surrounding the object content.
117-
* @return the right coordinate of the rectangle surrounding the object content
112+
* {@inheritDoc}
118113
*/
114+
@Override
119115
@JsxGetter
120-
public int getRight() {
121-
return right_;
116+
public double getWidth() {
117+
return super.getWidth();
122118
}
123119

124120
/**
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
121+
* {@inheritDoc}
127122
*/
123+
@Override
128124
@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_;
125+
public void setWidth(final double width) {
126+
super.setWidth(width);
140127
}
141128

142129
/**
143-
* Returns the {@code width} property.
144-
* @return the {@code width} property
130+
* {@inheritDoc}
145131
*/
132+
@Override
146133
@JsxGetter
147-
public int getWidth() {
148-
return getRight() - getLeft();
134+
public double getHeight() {
135+
return super.getHeight();
149136
}
150137

151138
/**
152-
* Returns the {@code height} property.
153-
* @return the {@code height} property
139+
* {@inheritDoc}
154140
*/
155-
@JsxGetter
156-
public int getHeight() {
157-
return getBottom() - getTop();
141+
@Override
142+
@JsxSetter
143+
public void setHeight(final double height) {
144+
super.setHeight(height);
158145
}
159146
}

src/main/java/org/htmlunit/javascript/host/Element.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public void removeAttribute(final String name) {
342342
*/
343343
@JsxFunction
344344
public DOMRect getBoundingClientRect() {
345-
final DOMRect textRectangle = new DOMRect(1, 1, 1, 1);
345+
final DOMRect textRectangle = new DOMRect(1, 1, 0, 0);
346346
textRectangle.setParentScope(getWindow());
347347
textRectangle.setPrototype(getPrototype(textRectangle.getClass()));
348348
return textRectangle;

0 commit comments

Comments
 (0)