diff options
author | Job Bautista <jobbautista9@aol.com> | 2023-05-12 16:07:16 +0800 |
---|---|---|
committer | Job Bautista <jobbautista9@aol.com> | 2023-05-12 16:26:06 +0800 |
commit | ecf05312e6e9b13bbf11781acd8e52788a77a943 (patch) | |
tree | eefe95265658a44e86de9557133662fb3ec4743a | |
parent | c7ca649bd14ddb24ad161c130c372f5979bc7e3c (diff) | |
download | uxp-ecf05312e6e9b13bbf11781acd8e52788a77a943.tar.gz |
Issue #2241 - Part 7.2: Implement .fromRect and .fromQuad.
Backported from Mozilla bug 1558101.
-rw-r--r-- | dom/base/DOMQuad.cpp | 26 | ||||
-rw-r--r-- | dom/base/DOMQuad.h | 7 | ||||
-rw-r--r-- | dom/base/DOMRect.cpp | 16 | ||||
-rw-r--r-- | dom/base/DOMRect.h | 8 | ||||
-rw-r--r-- | dom/webidl/DOMQuad.webidl | 11 | ||||
-rw-r--r-- | dom/webidl/DOMRect.webidl | 4 |
6 files changed, 68 insertions, 4 deletions
diff --git a/dom/base/DOMQuad.cpp b/dom/base/DOMQuad.cpp index 8457d9ddaa..258bfc1bfd 100644 --- a/dom/base/DOMQuad.cpp +++ b/dom/base/DOMQuad.cpp @@ -44,6 +44,32 @@ DOMQuad::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) } already_AddRefed<DOMQuad> +DOMQuad::FromRect(const GlobalObject& aGlobal, const DOMRectInit& aInit) +{ + nsISupports* parent = aGlobal.GetAsSupports(); + RefPtr<DOMQuad> obj = new DOMQuad(parent); + obj->mPoints[0] = new DOMPoint(parent, aInit.mX, aInit.mY, 0, 1); + obj->mPoints[1] = + new DOMPoint(parent, aInit.mX + aInit.mWidth, aInit.mY, 0, 1); + obj->mPoints[2] = new DOMPoint(parent, aInit.mX + aInit.mWidth, + aInit.mY + aInit.mHeight, 0, 1); + obj->mPoints[3] = + new DOMPoint(parent, aInit.mX, aInit.mY + aInit.mHeight, 0, 1); + return obj.forget(); +} + +already_AddRefed<DOMQuad> +DOMQuad::FromQuad(const GlobalObject& aGlobal, const DOMQuadInit& aInit) +{ + RefPtr<DOMQuad> obj = new DOMQuad(aGlobal.GetAsSupports()); + obj->mPoints[0] = DOMPoint::FromPoint(aGlobal, aInit.mP1); + obj->mPoints[1] = DOMPoint::FromPoint(aGlobal, aInit.mP2); + obj->mPoints[2] = DOMPoint::FromPoint(aGlobal, aInit.mP3); + obj->mPoints[3] = DOMPoint::FromPoint(aGlobal, aInit.mP4); + return obj.forget(); +} + +already_AddRefed<DOMQuad> DOMQuad::Constructor(const GlobalObject& aGlobal, const DOMPointInit& aP1, const DOMPointInit& aP2, diff --git a/dom/base/DOMQuad.h b/dom/base/DOMQuad.h index 9d740e0b5e..9508d9f431 100644 --- a/dom/base/DOMQuad.h +++ b/dom/base/DOMQuad.h @@ -23,6 +23,7 @@ class DOMRectReadOnly; class DOMPoint; struct DOMQuadJSON; struct DOMPointInit; +struct DOMQuadInit; class DOMQuad final : public nsWrapperCache { @@ -39,6 +40,12 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; static already_AddRefed<DOMQuad> + FromRect(const GlobalObject& aGlobal, const DOMRectInit& aInit); + + static already_AddRefed<DOMQuad> + FromQuad(const GlobalObject& aGlobal, const DOMQuadInit& aInit); + + static already_AddRefed<DOMQuad> Constructor(const GlobalObject& aGlobal, const DOMPointInit& aP1, const DOMPointInit& aP2, diff --git a/dom/base/DOMRect.cpp b/dom/base/DOMRect.cpp index 46f395a083..8dd634b547 100644 --- a/dom/base/DOMRect.cpp +++ b/dom/base/DOMRect.cpp @@ -28,6 +28,14 @@ DOMRectReadOnly::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) } already_AddRefed<DOMRectReadOnly> +DOMRectReadOnly::FromRect(const GlobalObject& aGlobal, const DOMRectInit& aInit) +{ + RefPtr<DOMRectReadOnly> obj = new DOMRectReadOnly( + aGlobal.GetAsSupports(), aInit.mX, aInit.mY, aInit.mWidth, aInit.mHeight); + return obj.forget(); +} + +already_AddRefed<DOMRectReadOnly> DOMRectReadOnly::Constructor(const GlobalObject& aGlobal, double aX, double aY, double aWidth, double aHeight, ErrorResult& aRv) { @@ -99,6 +107,14 @@ DOMRect::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) } already_AddRefed<DOMRect> +DOMRect::FromRect(const GlobalObject& aGlobal, const DOMRectInit& aInit) +{ + RefPtr<DOMRect> obj = new DOMRect(aGlobal.GetAsSupports(), aInit.mX, aInit.mY, + aInit.mWidth, aInit.mHeight); + return obj.forget(); +} + +already_AddRefed<DOMRect> DOMRect::Constructor(const GlobalObject& aGlobal, double aX, double aY, double aWidth, double aHeight, ErrorResult& aRv) { diff --git a/dom/base/DOMRect.h b/dom/base/DOMRect.h index 56478f284c..541ff02539 100644 --- a/dom/base/DOMRect.h +++ b/dom/base/DOMRect.h @@ -23,6 +23,8 @@ struct nsRect; namespace mozilla { namespace dom { +struct DOMRectInit; + class DOMRectReadOnly : public nsISupports , public nsWrapperCache { @@ -51,6 +53,9 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; static already_AddRefed<DOMRectReadOnly> + FromRect(const GlobalObject& aGlobal, const DOMRectInit& aInit); + + static already_AddRefed<DOMRectReadOnly> Constructor(const GlobalObject& aGlobal, double aX, double aY, double aWidth, double aHeight, ErrorResult& aRv); @@ -115,6 +120,9 @@ public: NS_DECL_NSIDOMCLIENTRECT static already_AddRefed<DOMRect> + FromRect(const GlobalObject& aGlobal, const DOMRectInit& aInit); + + static already_AddRefed<DOMRect> Constructor(const GlobalObject& aGlobal, double aX, double aY, double aWidth, double aHeight, ErrorResult& aRv); diff --git a/dom/webidl/DOMQuad.webidl b/dom/webidl/DOMQuad.webidl index 5b130d271f..05b611a5e3 100644 --- a/dom/webidl/DOMQuad.webidl +++ b/dom/webidl/DOMQuad.webidl @@ -15,6 +15,9 @@ Constructor(DOMRectReadOnly rect), Exposed=(Window,Worker)] interface DOMQuad { + [NewObject] static DOMQuad fromRect(optional DOMRectInit other); + [NewObject] static DOMQuad fromQuad(optional DOMQuadInit other); + [SameObject] readonly attribute DOMPoint p1; [SameObject] readonly attribute DOMPoint p2; [SameObject] readonly attribute DOMPoint p3; @@ -34,8 +37,8 @@ dictionary DOMQuadJSON { }; dictionary DOMQuadInit { - DOMPointInit p1; - DOMPointInit p2; - DOMPointInit p3; - DOMPointInit p4; + DOMPointInit p1 = null; + DOMPointInit p2 = null; + DOMPointInit p3 = null; + DOMPointInit p4 = null; }; diff --git a/dom/webidl/DOMRect.webidl b/dom/webidl/DOMRect.webidl index c3bedc7ef5..baf7ce2456 100644 --- a/dom/webidl/DOMRect.webidl +++ b/dom/webidl/DOMRect.webidl @@ -14,6 +14,8 @@ optional unrestricted double width = 0, optional unrestricted double height = 0), Exposed=(Window,Worker)] interface DOMRect : DOMRectReadOnly { + [NewObject] static DOMRect fromRect(optional DOMRectInit other); + inherit attribute unrestricted double x; inherit attribute unrestricted double y; inherit attribute unrestricted double width; @@ -24,6 +26,8 @@ interface DOMRect : DOMRectReadOnly { optional unrestricted double width = 0, optional unrestricted double height = 0), Exposed=(Window,Worker)] interface DOMRectReadOnly { + [NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other); + readonly attribute unrestricted double x; readonly attribute unrestricted double y; readonly attribute unrestricted double width; |