tor-browser

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

CanvasPath.h (3657B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef CanvasPath_h
      6 #define CanvasPath_h
      7 
      8 #include "mozilla/RefPtr.h"
      9 #include "mozilla/dom/BindingDeclarations.h"
     10 #include "mozilla/gfx/2D.h"
     11 #include "nsWrapperCache.h"
     12 
     13 namespace mozilla {
     14 class ErrorResult;
     15 
     16 namespace dom {
     17 
     18 enum class CanvasWindingRule : uint8_t;
     19 struct DOMMatrix2DInit;
     20 
     21 class
     22    UnrestrictedDoubleOrDOMPointInitOrUnrestrictedDoubleOrDOMPointInitSequence;
     23 
     24 class CanvasPath final : public nsWrapperCache {
     25 public:
     26  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasPath)
     27  NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(CanvasPath)
     28 
     29  nsISupports* GetParentObject() { return mParent; }
     30 
     31  JSObject* WrapObject(JSContext* aCx,
     32                       JS::Handle<JSObject*> aGivenProto) override;
     33 
     34  static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal);
     35  static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
     36                                                  CanvasPath& aCanvasPath);
     37  static already_AddRefed<CanvasPath> Constructor(
     38      const GlobalObject& aGlobal, const nsACString& aPathString);
     39 
     40  void ClosePath();
     41  void MoveTo(double x, double y);
     42  void LineTo(double x, double y);
     43  void QuadraticCurveTo(double cpx, double cpy, double x, double y);
     44  void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y,
     45                     double x, double y);
     46  void ArcTo(double x1, double y1, double x2, double y2, double radius,
     47             ErrorResult& error);
     48  void Rect(double x, double y, double w, double h);
     49  void RoundRect(
     50      double aX, double aY, double aW, double aH,
     51      const UnrestrictedDoubleOrDOMPointInitOrUnrestrictedDoubleOrDOMPointInitSequence&
     52          aRadii,
     53      ErrorResult& aError);
     54  void Arc(double x, double y, double radius, double startAngle,
     55           double endAngle, bool anticlockwise, ErrorResult& error);
     56  void Ellipse(double x, double y, double radiusX, double radiusY,
     57               double rotation, double startAngle, double endAngle,
     58               bool anticlockwise, ErrorResult& error);
     59 
     60  void LineTo(const gfx::Point& aPoint);
     61  void BezierTo(const gfx::Point& aCP1, const gfx::Point& aCP2,
     62                const gfx::Point& aCP3);
     63 
     64  already_AddRefed<gfx::Path> GetPath(const CanvasWindingRule& aWinding,
     65                                      gfx::BackendType aBackendType) const;
     66  already_AddRefed<gfx::Path> GetPath(const CanvasWindingRule& aWinding,
     67                                      const gfx::DrawTarget* aTarget) const {
     68    return GetPath(aWinding, aTarget->GetPathType());
     69  }
     70 
     71  explicit CanvasPath(nsISupports* aParent);
     72  // already_AddRefed arg because the return value from Path::CopyToBuilder()
     73  // is passed directly and we can't drop the only ref to have a raw pointer.
     74  CanvasPath(nsISupports* aParent,
     75             already_AddRefed<gfx::PathBuilder> aPathBuilder);
     76 
     77  void AddPath(CanvasPath& aCanvasPath, const DOMMatrix2DInit& aInit,
     78               ErrorResult& aError);
     79 
     80 private:
     81  virtual ~CanvasPath() = default;
     82 
     83  nsCOMPtr<nsISupports> mParent;
     84  static gfx::Float ToFloat(double aValue) { return gfx::Float(aValue); }
     85 
     86  mutable RefPtr<gfx::Path> mPath;
     87  mutable RefPtr<gfx::PathBuilder> mPathBuilder;
     88 
     89  // Whether an internal segment was zero-length.
     90  mutable bool mPruned = false;
     91 
     92  void EnsurePathBuilder() const;
     93  void EnsureCapped() const;
     94  void EnsureActive() const;
     95 };
     96 
     97 }  // namespace dom
     98 }  // namespace mozilla
     99 
    100 #endif /* CanvasPath_h */