Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / dom / svg / SVGPathElement.h
blobd377755917618f74095adc3dda0eae0ae2800583
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/. */
7 #ifndef DOM_SVG_SVGPATHELEMENT_H_
8 #define DOM_SVG_SVGPATHELEMENT_H_
10 #include "mozilla/gfx/2D.h"
11 #include "mozilla/RefPtr.h"
12 #include "SVGAnimatedPathSegList.h"
13 #include "SVGGeometryElement.h"
14 #include "DOMSVGPathSeg.h"
16 nsresult NS_NewSVGPathElement(
17 nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
19 namespace mozilla::dom {
21 using SVGPathElementBase = SVGGeometryElement;
23 class SVGPathElement final : public SVGPathElementBase {
24 using Path = mozilla::gfx::Path;
26 protected:
27 friend nsresult(::NS_NewSVGPathElement(
28 nsIContent** aResult,
29 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
30 JSObject* WrapNode(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
31 explicit SVGPathElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
33 void GetAsSimplePath(SimplePath* aSimplePath) override;
35 public:
36 NS_DECL_ADDSIZEOFEXCLUDINGTHIS
38 // nsIContent interface
39 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* name) const override;
41 // SVGSVGElement methods:
42 bool HasValidDimensions() const override;
44 // SVGGeometryElement methods:
45 bool AttributeDefinesGeometry(const nsAtom* aName) override;
46 bool IsMarkable() override;
47 void GetMarkPoints(nsTArray<SVGMark>* aMarks) override;
49 * Note: This function maps d attribute to CSS d property, and we don't flush
50 * style in this function because some callers don't need it, so if the caller
51 * needs style to be flushed (e.g. DOM APIs), the caller should flush style
52 * before calling this.
54 already_AddRefed<Path> BuildPath(PathBuilder* aBuilder) override;
56 /**
57 * This returns a path without the extra little line segments that
58 * ApproximateZeroLengthSubpathSquareCaps can insert if we have square-caps.
59 * See the comment for that function for more info on that.
61 * Note: This function maps d attribute to CSS d property, and we don't flush
62 * style in this function because some callers don't need it, so if the caller
63 * needs style to be flushed (e.g. DOM APIs), the caller should flush style
64 * before calling this.
66 already_AddRefed<Path> GetOrBuildPathForMeasuring() override;
68 bool GetDistancesFromOriginToEndsOfVisibleSegments(
69 FallibleTArray<double>* aOutput) override;
71 // nsIContent interface
72 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
74 SVGAnimatedPathSegList* GetAnimPathSegList() override { return &mD; }
76 nsStaticAtom* GetPathDataAttrName() const override { return nsGkAtoms::d; }
78 // WebIDL
79 MOZ_CAN_RUN_SCRIPT uint32_t GetPathSegAtLength(float distance);
80 already_AddRefed<DOMSVGPathSegClosePath> CreateSVGPathSegClosePath();
81 already_AddRefed<DOMSVGPathSegMovetoAbs> CreateSVGPathSegMovetoAbs(float x,
82 float y);
83 already_AddRefed<DOMSVGPathSegMovetoRel> CreateSVGPathSegMovetoRel(float x,
84 float y);
85 already_AddRefed<DOMSVGPathSegLinetoAbs> CreateSVGPathSegLinetoAbs(float x,
86 float y);
87 already_AddRefed<DOMSVGPathSegLinetoRel> CreateSVGPathSegLinetoRel(float x,
88 float y);
89 already_AddRefed<DOMSVGPathSegCurvetoCubicAbs>
90 CreateSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1,
91 float x2, float y2);
92 already_AddRefed<DOMSVGPathSegCurvetoCubicRel>
93 CreateSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1,
94 float x2, float y2);
95 already_AddRefed<DOMSVGPathSegCurvetoQuadraticAbs>
96 CreateSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1);
97 already_AddRefed<DOMSVGPathSegCurvetoQuadraticRel>
98 CreateSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1);
99 already_AddRefed<DOMSVGPathSegArcAbs> CreateSVGPathSegArcAbs(
100 float x, float y, float r1, float r2, float angle, bool largeArcFlag,
101 bool sweepFlag);
102 already_AddRefed<DOMSVGPathSegArcRel> CreateSVGPathSegArcRel(
103 float x, float y, float r1, float r2, float angle, bool largeArcFlag,
104 bool sweepFlag);
105 already_AddRefed<DOMSVGPathSegLinetoHorizontalAbs>
106 CreateSVGPathSegLinetoHorizontalAbs(float x);
107 already_AddRefed<DOMSVGPathSegLinetoHorizontalRel>
108 CreateSVGPathSegLinetoHorizontalRel(float x);
109 already_AddRefed<DOMSVGPathSegLinetoVerticalAbs>
110 CreateSVGPathSegLinetoVerticalAbs(float y);
111 already_AddRefed<DOMSVGPathSegLinetoVerticalRel>
112 CreateSVGPathSegLinetoVerticalRel(float y);
113 already_AddRefed<DOMSVGPathSegCurvetoCubicSmoothAbs>
114 CreateSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2);
115 already_AddRefed<DOMSVGPathSegCurvetoCubicSmoothRel>
116 CreateSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2);
117 already_AddRefed<DOMSVGPathSegCurvetoQuadraticSmoothAbs>
118 CreateSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y);
119 already_AddRefed<DOMSVGPathSegCurvetoQuadraticSmoothRel>
120 CreateSVGPathSegCurvetoQuadraticSmoothRel(float x, float y);
121 already_AddRefed<DOMSVGPathSegList> PathSegList();
122 already_AddRefed<DOMSVGPathSegList> AnimatedPathSegList();
124 static bool IsDPropertyChangedViaCSS(const ComputedStyle& aNewStyle,
125 const ComputedStyle& aOldStyle);
127 protected:
128 SVGAnimatedPathSegList mD;
131 } // namespace mozilla::dom
133 #endif // DOM_SVG_SVGPATHELEMENT_H_