DOMQuad.h (3013B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_DOMQUAD_H_ 8 #define MOZILLA_DOMQUAD_H_ 9 10 #include <cstdint> 11 12 #include "Units.h" 13 #include "js/TypeDecls.h" 14 #include "mozilla/AlreadyAddRefed.h" 15 #include "mozilla/RefPtr.h" 16 #include "nsCOMPtr.h" 17 #include "nsCycleCollectionParticipant.h" 18 #include "nsISupports.h" 19 #include "nsWrapperCache.h" 20 21 class JSObject; 22 class nsIGlobalObject; 23 struct JSContext; 24 struct JSStructuredCloneReader; 25 struct JSStructuredCloneWriter; 26 27 namespace mozilla::dom { 28 29 class DOMRectReadOnly; 30 class DOMPoint; 31 class GlobalObject; 32 struct DOMPointInit; 33 struct DOMQuadInit; 34 struct DOMRectInit; 35 36 class DOMQuad final : public nsWrapperCache { 37 ~DOMQuad(); 38 39 public: 40 DOMQuad(nsISupports* aParent, CSSPoint aPoints[4]); 41 explicit DOMQuad(nsISupports* aParent); 42 43 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMQuad) 44 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DOMQuad) 45 46 nsISupports* GetParentObject() const { return mParent; } 47 virtual JSObject* WrapObject(JSContext* aCx, 48 JS::Handle<JSObject*> aGivenProto) override; 49 50 static already_AddRefed<DOMQuad> FromRect(const GlobalObject& aGlobal, 51 const DOMRectInit& aInit); 52 53 static already_AddRefed<DOMQuad> FromQuad(const GlobalObject& aGlobal, 54 const DOMQuadInit& aInit); 55 56 static already_AddRefed<DOMQuad> Constructor(const GlobalObject& aGlobal, 57 const DOMPointInit& aP1, 58 const DOMPointInit& aP2, 59 const DOMPointInit& aP3, 60 const DOMPointInit& aP4); 61 static already_AddRefed<DOMQuad> Constructor(const GlobalObject& aGlobal, 62 const DOMRectReadOnly& aRect); 63 64 already_AddRefed<DOMRectReadOnly> GetBounds() const; 65 DOMPoint* P1() const { return mPoints[0]; } 66 DOMPoint* P2() const { return mPoints[1]; } 67 DOMPoint* P3() const { return mPoints[2]; } 68 DOMPoint* P4() const { return mPoints[3]; } 69 70 DOMPoint* Point(uint32_t aIndex) const { return mPoints[aIndex]; } 71 72 bool WriteStructuredClone(JSContext* aCx, 73 JSStructuredCloneWriter* aWriter) const; 74 75 static already_AddRefed<DOMQuad> ReadStructuredClone( 76 JSContext* aCx, nsIGlobalObject* aGlobal, 77 JSStructuredCloneReader* aReader); 78 79 protected: 80 void GetHorizontalMinMax(double* aX1, double* aX2) const; 81 void GetVerticalMinMax(double* aY1, double* aY2) const; 82 83 nsCOMPtr<nsISupports> mParent; 84 RefPtr<DOMPoint> mPoints[4]; 85 }; 86 87 } // namespace mozilla::dom 88 89 #endif /*MOZILLA_DOMRECT_H_*/