-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement DOMRect and DOMRectReadOnly
- Loading branch information
Showing
7 changed files
with
176 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
const DOMRectReadOnlyImpl = require("./DOMRectReadOnly-impl").implementation; | ||
const DOMRect = require("../generated/DOMRect"); | ||
|
||
class DOMRectImpl extends DOMRectReadOnlyImpl { | ||
static fromRect(globalObject, other) { | ||
return DOMRect.createImpl(globalObject, [other.x, other.y, other.width, other.height]); | ||
} | ||
|
||
get x() { | ||
return super.x; | ||
} | ||
set x(newX) { | ||
this._x = newX; | ||
} | ||
|
||
get y() { | ||
return super.y; | ||
} | ||
set y(newY) { | ||
this._y = newY; | ||
} | ||
|
||
get width() { | ||
return super.width; | ||
} | ||
set width(newWidth) { | ||
this._width = newWidth; | ||
} | ||
|
||
get height() { | ||
return super.height; | ||
} | ||
set height(newHeight) { | ||
this._height = newHeight; | ||
} | ||
} | ||
|
||
exports.implementation = DOMRectImpl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// https://drafts.fxtf.org/geometry/#domrect | ||
|
||
// Commented out for https://github.com/w3c/svgwg/issues/706 | ||
// [LegacyWindowAlias=SVGRect] | ||
[Exposed=(Window,Worker), | ||
Serializable] | ||
interface DOMRect : DOMRectReadOnly { | ||
constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, | ||
optional unrestricted double width = 0, optional unrestricted double height = 0); | ||
|
||
[NewObject, WebIDL2JSCallWithGlobal] static DOMRect fromRect(optional DOMRectInit other = {}); | ||
|
||
inherit attribute unrestricted double x; | ||
inherit attribute unrestricted double y; | ||
inherit attribute unrestricted double width; | ||
inherit attribute unrestricted double height; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use strict"; | ||
const DOMRectReadOnly = require("../generated/DOMRectReadOnly"); | ||
|
||
class DOMRectReadOnlyImpl { | ||
constructor(globalObject, [x = 0, y = 0, width = 0, height = 0]) { | ||
this._globalObject = globalObject; | ||
this._x = x; | ||
this._y = y; | ||
this._width = width; | ||
this._height = height; | ||
} | ||
|
||
static fromRect(globalObject, other) { | ||
return DOMRectReadOnly.createImpl(globalObject, [other.x, other.y, other.width, other.height]); | ||
} | ||
|
||
get x() { | ||
return this._x; | ||
} | ||
|
||
get y() { | ||
return this._y; | ||
} | ||
|
||
get width() { | ||
return this._width; | ||
} | ||
|
||
get height() { | ||
return this._height; | ||
} | ||
|
||
get top() { | ||
const { height, y } = this; | ||
// We use Math.min's built-in NaN handling: https://github.com/w3c/fxtf-drafts/issues/222 | ||
return Math.min(y, y + height); | ||
} | ||
|
||
get right() { | ||
const { width, x } = this; | ||
// We use Math.max's built-in NaN handling: https://github.com/w3c/fxtf-drafts/issues/222 | ||
return Math.max(x, x + width); | ||
} | ||
|
||
get bottom() { | ||
const { height, y } = this; | ||
// We use Math.max's built-in NaN handling: https://github.com/w3c/fxtf-drafts/issues/222 | ||
return Math.max(y, y + height); | ||
} | ||
|
||
get left() { | ||
const { width, x } = this; | ||
// We use Math.min's built-in NaN handling: https://github.com/w3c/fxtf-drafts/issues/222 | ||
return Math.min(x, x + width); | ||
} | ||
|
||
// Could be removed after https://github.com/jsdom/webidl2js/issues/185 gets fixed. | ||
toJSON() { | ||
return { | ||
x: this.x, | ||
y: this.y, | ||
width: this.width, | ||
height: this.height, | ||
top: this.top, | ||
right: this.right, | ||
bottom: this.bottom, | ||
left: this.left | ||
}; | ||
} | ||
} | ||
|
||
exports.implementation = DOMRectReadOnlyImpl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// https://drafts.fxtf.org/geometry/#domrectreadonly | ||
[Exposed=(Window,Worker), | ||
Serializable] | ||
interface DOMRectReadOnly { | ||
constructor(optional unrestricted double x = 0, optional unrestricted double y = 0, | ||
optional unrestricted double width = 0, optional unrestricted double height = 0); | ||
|
||
[NewObject, WebIDL2JSCallWithGlobal] static DOMRectReadOnly fromRect(optional DOMRectInit other = {}); | ||
|
||
readonly attribute unrestricted double x; | ||
readonly attribute unrestricted double y; | ||
readonly attribute unrestricted double width; | ||
readonly attribute unrestricted double height; | ||
readonly attribute unrestricted double top; | ||
readonly attribute unrestricted double right; | ||
readonly attribute unrestricted double bottom; | ||
readonly attribute unrestricted double left; | ||
|
||
// https://github.com/jsdom/webidl2js/issues/185 | ||
[Default] object toJSON(); | ||
}; | ||
|
||
dictionary DOMRectInit { | ||
unrestricted double x = 0; | ||
unrestricted double y = 0; | ||
unrestricted double width = 0; | ||
unrestricted double height = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters