diff --git a/dom/base/DOMQuad.cpp b/dom/base/DOMQuad.cpp index 2cf55e1b8b..a64c883982 100644 --- a/dom/base/DOMQuad.cpp +++ b/dom/base/DOMQuad.cpp @@ -14,7 +14,7 @@ using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::gfx; -NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMQuad, mParent, mPoints[0], +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(DOMQuad, mParent, mBounds, mPoints[0], mPoints[1], mPoints[2], mPoints[3]) NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMQuad, AddRef) @@ -101,6 +101,15 @@ DOMQuad::GetVerticalMinMax(double* aY1, double* aY2) const *aY2 = y2; } +DOMRectReadOnly* +DOMQuad::Bounds() +{ + if (!mBounds) { + mBounds = GetBounds(); + } + return mBounds; +} + already_AddRefed DOMQuad::GetBounds() const { @@ -114,3 +123,12 @@ DOMQuad::GetBounds() const x1, y1, x2 - x1, y2 - y1); return rval.forget(); } + +void +DOMQuad::ToJSON(DOMQuadJSON& aInit) +{ + aInit.mP1.Construct(RefPtr(P1()).forget()); + aInit.mP2.Construct(RefPtr(P2()).forget()); + aInit.mP3.Construct(RefPtr(P3()).forget()); + aInit.mP4.Construct(RefPtr(P4()).forget()); +} diff --git a/dom/base/DOMQuad.h b/dom/base/DOMQuad.h index 25cf7dbd06..db38e5d236 100644 --- a/dom/base/DOMQuad.h +++ b/dom/base/DOMQuad.h @@ -20,6 +20,7 @@ namespace dom { class DOMRectReadOnly; class DOMPoint; +struct DOMQuadJSON; struct DOMPointInit; class DOMQuad final : public nsWrapperCache @@ -47,6 +48,7 @@ public: Constructor(const GlobalObject& aGlobal, const DOMRectReadOnly& aRect, ErrorResult& aRV); + DOMRectReadOnly* Bounds(); already_AddRefed GetBounds() const; DOMPoint* P1() const { return mPoints[0]; } DOMPoint* P2() const { return mPoints[1]; } @@ -55,12 +57,15 @@ public: DOMPoint* Point(uint32_t aIndex) const { return mPoints[aIndex]; } + void ToJSON(DOMQuadJSON& aInit); + protected: void GetHorizontalMinMax(double* aX1, double* aX2) const; void GetVerticalMinMax(double* aY1, double* aY2) const; nsCOMPtr mParent; RefPtr mPoints[4]; + RefPtr mBounds; }; } // namespace dom diff --git a/dom/base/nsDeprecatedOperationList.h b/dom/base/nsDeprecatedOperationList.h index 0bae2d6211..bb9d8fd3b1 100644 --- a/dom/base/nsDeprecatedOperationList.h +++ b/dom/base/nsDeprecatedOperationList.h @@ -47,3 +47,4 @@ DEPRECATED_OPERATION(PrefixedFullscreenAPI) DEPRECATED_OPERATION(LenientSetter) DEPRECATED_OPERATION(FileLastModifiedDate) DEPRECATED_OPERATION(ImageBitmapRenderingContext_TransferImageBitmap) +DEPRECATED_OPERATION(DOMQuadBoundsAttr) diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index 60104a63ad..27b4eebf12 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -320,3 +320,4 @@ LargeAllocationNonE10S=A Large-Allocation header was ignored due to the document PushStateFloodingPrevented=Call to pushState or replaceState ignored due to excessive calls within a short timeframe. # LOCALIZATION NOTE: Do not translate "Reload" ReloadFloodingPrevented=Call to Reload ignored due to excessive calls within a short timeframe. +DOMQuadBoundsAttrWarning=DOMQuad.bounds is deprecated in favor of DOMQuad.getBounds() diff --git a/dom/webidl/DOMQuad.webidl b/dom/webidl/DOMQuad.webidl index f3674e9ad7..7370330b29 100644 --- a/dom/webidl/DOMQuad.webidl +++ b/dom/webidl/DOMQuad.webidl @@ -21,5 +21,21 @@ interface DOMQuad { [SameObject] readonly attribute DOMPoint p4; [NewObject] DOMRectReadOnly getBounds(); - [Default] object toJSON(); + [SameObject, Deprecated=DOMQuadBoundsAttr] readonly attribute DOMRectReadOnly bounds; + + DOMQuadJSON toJSON(); +}; + +dictionary DOMQuadJSON { + DOMPoint p1; + DOMPoint p2; + DOMPoint p3; + DOMPoint p4; +}; + +dictionary DOMQuadInit { + DOMPointInit p1; + DOMPointInit p2; + DOMPointInit p3; + DOMPointInit p4; };