tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

DOMPoint.h (3640B)


      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_DOMPOINT_H_
      8 #define MOZILLA_DOMPOINT_H_
      9 
     10 #include "js/TypeDecls.h"
     11 #include "mozilla/AlreadyAddRefed.h"
     12 #include "nsCOMPtr.h"
     13 #include "nsCycleCollectionParticipant.h"
     14 #include "nsISupports.h"
     15 #include "nsWrapperCache.h"
     16 
     17 class JSObject;
     18 class nsIGlobalObject;
     19 struct JSContext;
     20 struct JSStructuredCloneReader;
     21 struct JSStructuredCloneWriter;
     22 
     23 namespace mozilla {
     24 class ErrorResult;
     25 
     26 namespace dom {
     27 
     28 class GlobalObject;
     29 class DOMPoint;
     30 struct DOMPointInit;
     31 struct DOMMatrixInit;
     32 
     33 class DOMPointReadOnly : public nsWrapperCache {
     34 public:
     35  explicit DOMPointReadOnly(nsISupports* aParent, double aX = 0.0,
     36                            double aY = 0.0, double aZ = 0.0, double aW = 1.0)
     37      : mParent(aParent), mX(aX), mY(aY), mZ(aZ), mW(aW) {}
     38 
     39  static already_AddRefed<DOMPointReadOnly> FromPoint(
     40      const GlobalObject& aGlobal, const DOMPointInit& aParams);
     41  static already_AddRefed<DOMPointReadOnly> Constructor(
     42      const GlobalObject& aGlobal, double aX, double aY, double aZ, double aW);
     43 
     44  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMPointReadOnly)
     45  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(DOMPointReadOnly)
     46 
     47  double X() const { return mX; }
     48  double Y() const { return mY; }
     49  double Z() const { return mZ; }
     50  double W() const { return mW; }
     51 
     52  already_AddRefed<DOMPoint> MatrixTransform(const DOMMatrixInit& aInit,
     53                                             ErrorResult& aRv);
     54 
     55  nsISupports* GetParentObject() const { return mParent; }
     56  virtual JSObject* WrapObject(JSContext* aCx,
     57                               JS::Handle<JSObject*> aGivenProto) override;
     58 
     59  bool WriteStructuredClone(JSContext* aCx,
     60                            JSStructuredCloneWriter* aWriter) const;
     61 
     62  static already_AddRefed<DOMPointReadOnly> ReadStructuredClone(
     63      JSContext* aCx, nsIGlobalObject* aGlobal,
     64      JSStructuredCloneReader* aReader);
     65 
     66 protected:
     67  virtual ~DOMPointReadOnly() = default;
     68 
     69  // Shared implementation of ReadStructuredClone for DOMPoint and
     70  // DOMPointReadOnly.
     71  bool ReadStructuredClone(JSStructuredCloneReader* aReader);
     72 
     73  nsCOMPtr<nsISupports> mParent;
     74  double mX, mY, mZ, mW;
     75 };
     76 
     77 class DOMPoint final : public DOMPointReadOnly {
     78 public:
     79  explicit DOMPoint(nsISupports* aParent, double aX = 0.0, double aY = 0.0,
     80                    double aZ = 0.0, double aW = 1.0)
     81      : DOMPointReadOnly(aParent, aX, aY, aZ, aW) {}
     82 
     83  static already_AddRefed<DOMPoint> FromPoint(const GlobalObject& aGlobal,
     84                                              const DOMPointInit& aParams);
     85  static already_AddRefed<DOMPoint> Constructor(const GlobalObject& aGlobal,
     86                                                double aX, double aY, double aZ,
     87                                                double aW);
     88 
     89  virtual JSObject* WrapObject(JSContext* aCx,
     90                               JS::Handle<JSObject*> aGivenProto) override;
     91 
     92  static already_AddRefed<DOMPoint> ReadStructuredClone(
     93      JSContext* aCx, nsIGlobalObject* aGlobal,
     94      JSStructuredCloneReader* aReader);
     95  using DOMPointReadOnly::ReadStructuredClone;
     96 
     97  void SetX(double aX) { mX = aX; }
     98  void SetY(double aY) { mY = aY; }
     99  void SetZ(double aZ) { mZ = aZ; }
    100  void SetW(double aW) { mW = aW; }
    101 };
    102 
    103 }  // namespace dom
    104 }  // namespace mozilla
    105 
    106 #endif /*MOZILLA_DOMPOINT_H_*/