Bug 1795723 - Unified extensions UI should support High Contrast Mode. r=ayeddi,deskt...
[gecko.git] / dom / canvas / CanvasPath.h
blob141f86fee0f45321916a63a32bc11aaa26561e4e
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/. */
5 #ifndef CanvasPath_h
6 #define CanvasPath_h
8 #include "mozilla/Attributes.h"
9 #include "mozilla/RefPtr.h"
10 #include "nsWrapperCache.h"
11 #include "mozilla/gfx/2D.h"
12 #include "mozilla/dom/BindingDeclarations.h"
14 namespace mozilla {
15 class ErrorResult;
17 namespace dom {
19 enum class CanvasWindingRule : uint8_t;
20 struct DOMMatrix2DInit;
22 class CanvasPath final : public nsWrapperCache {
23 public:
24 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(CanvasPath)
25 NS_DECL_CYCLE_COLLECTION_NATIVE_WRAPPERCACHE_CLASS(CanvasPath)
27 nsCOMPtr<nsISupports> GetParentObject() { return mParent; }
29 JSObject* WrapObject(JSContext* aCx,
30 JS::Handle<JSObject*> aGivenProto) override;
32 static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal);
33 static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
34 CanvasPath& aCanvasPath);
35 static already_AddRefed<CanvasPath> Constructor(const GlobalObject& aGlobal,
36 const nsAString& aPathString);
38 void ClosePath();
39 void MoveTo(double x, double y);
40 void LineTo(double x, double y);
41 void QuadraticCurveTo(double cpx, double cpy, double x, double y);
42 void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y,
43 double x, double y);
44 void ArcTo(double x1, double y1, double x2, double y2, double radius,
45 ErrorResult& error);
46 void Rect(double x, double y, double w, double h);
47 void Arc(double x, double y, double radius, double startAngle,
48 double endAngle, bool anticlockwise, ErrorResult& error);
49 void Ellipse(double x, double y, double radiusX, double radiusY,
50 double rotation, double startAngle, double endAngle,
51 bool anticlockwise, ErrorResult& error);
53 void LineTo(const gfx::Point& aPoint);
54 void BezierTo(const gfx::Point& aCP1, const gfx::Point& aCP2,
55 const gfx::Point& aCP3);
57 already_AddRefed<gfx::Path> GetPath(const CanvasWindingRule& aWinding,
58 const gfx::DrawTarget* aTarget) const;
60 explicit CanvasPath(nsISupports* aParent);
61 // already_AddRefed arg because the return value from Path::CopyToBuilder()
62 // is passed directly and we can't drop the only ref to have a raw pointer.
63 CanvasPath(nsISupports* aParent,
64 already_AddRefed<gfx::PathBuilder> aPathBuilder);
66 void AddPath(CanvasPath& aCanvasPath, const DOMMatrix2DInit& aInit,
67 ErrorResult& aError);
69 private:
70 virtual ~CanvasPath() = default;
72 nsCOMPtr<nsISupports> mParent;
73 static gfx::Float ToFloat(double aValue) { return gfx::Float(aValue); }
75 mutable RefPtr<gfx::Path> mPath;
76 mutable RefPtr<gfx::PathBuilder> mPathBuilder;
78 void EnsurePathBuilder() const;
81 } // namespace dom
82 } // namespace mozilla
84 #endif /* CanvasPath_h */