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"
15 nsresult
NS_NewSVGPathElement(
16 nsIContent
** aResult
, already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
18 namespace mozilla::dom
{
20 struct SVGPathDataSettings
;
23 using SVGPathElementBase
= SVGGeometryElement
;
25 class SVGPathElement final
: public SVGPathElementBase
{
26 using Path
= mozilla::gfx::Path
;
29 friend nsresult(::NS_NewSVGPathElement(
31 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
));
32 JSObject
* WrapNode(JSContext
* cx
, JS::Handle
<JSObject
*> aGivenProto
) override
;
33 explicit SVGPathElement(already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
);
35 void GetAsSimplePath(SimplePath
* aSimplePath
) override
;
38 NS_DECL_ADDSIZEOFEXCLUDINGTHIS
40 // nsIContent interface
41 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom
* name
) const override
;
43 // SVGSVGElement methods:
44 bool HasValidDimensions() const override
;
46 // SVGGeometryElement methods:
47 bool AttributeDefinesGeometry(const nsAtom
* aName
) override
;
48 bool IsMarkable() override
;
49 void GetMarkPoints(nsTArray
<SVGMark
>* aMarks
) override
;
51 * Note: This function maps d attribute to CSS d property, and we don't flush
52 * style in this function because some callers don't need it, so if the caller
53 * needs style to be flushed (e.g. DOM APIs), the caller should flush style
54 * before calling this.
56 already_AddRefed
<Path
> BuildPath(PathBuilder
* aBuilder
) override
;
59 * This returns a path without the extra little line segments that
60 * ApproximateZeroLengthSubpathSquareCaps can insert if we have square-caps.
61 * See the comment for that function for more info on that.
63 * Note: This function maps d attribute to CSS d property, and we don't flush
64 * style in this function because some callers don't need it, so if the caller
65 * needs style to be flushed (e.g. DOM APIs), the caller should flush style
66 * before calling this.
68 already_AddRefed
<Path
> GetOrBuildPathForMeasuring() override
;
70 bool GetDistancesFromOriginToEndsOfVisibleSegments(
71 FallibleTArray
<double>* aOutput
) override
;
73 bool IsClosedLoop() const override
;
75 // nsIContent interface
76 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
78 SVGAnimatedPathSegList
* GetAnimPathSegList() override
{ return &mD
; }
80 nsStaticAtom
* GetPathDataAttrName() const override
{ return nsGkAtoms::d
; }
84 already_AddRefed
<SVGPathSegment
> GetPathSegmentAtLength(float distance
);
86 void GetPathData(const SVGPathDataSettings
& aOptions
,
87 nsTArray
<RefPtr
<SVGPathSegment
>>& aValues
);
88 void SetPathData(const Sequence
<OwningNonNull
<SVGPathSegment
>>& aValues
);
90 static bool IsDPropertyChangedViaCSS(const ComputedStyle
& aNewStyle
,
91 const ComputedStyle
& aOldStyle
);
94 SVGAnimatedPathSegList mD
;
97 } // namespace mozilla::dom
99 #endif // DOM_SVG_SVGPATHELEMENT_H_