SVGPathElement.h (3508B)
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 DOM_SVG_SVGPATHELEMENT_H_ 8 #define DOM_SVG_SVGPATHELEMENT_H_ 9 10 #include "SVGAnimatedPathSegList.h" 11 #include "SVGGeometryElement.h" 12 #include "mozilla/RefPtr.h" 13 #include "mozilla/gfx/2D.h" 14 15 nsresult NS_NewSVGPathElement( 16 nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 17 18 namespace mozilla::dom { 19 20 struct SVGPathDataSettings; 21 struct SVGPathSegmentInit; 22 class SVGPathSegment; 23 24 using SVGPathElementBase = SVGGeometryElement; 25 26 class SVGPathElement final : public SVGPathElementBase { 27 using Path = mozilla::gfx::Path; 28 29 protected: 30 friend nsresult(::NS_NewSVGPathElement( 31 nsIContent** aResult, 32 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)); 33 JSObject* WrapNode(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override; 34 explicit SVGPathElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 35 36 void GetAsSimplePath(SimplePath* aSimplePath) override; 37 38 public: 39 NS_DECL_ADDSIZEOFEXCLUDINGTHIS 40 41 // nsIContent interface 42 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* name) const override; 43 44 // SVGSVGElement methods: 45 bool HasValidDimensions() const override; 46 47 // SVGGeometryElement methods: 48 bool AttributeDefinesGeometry(const nsAtom* aName) override; 49 bool IsMarkable() override; 50 void GetMarkPoints(nsTArray<SVGMark>* aMarks) override; 51 /* 52 * Note: This function maps d attribute to CSS d property, and we don't flush 53 * style in this function because some callers don't need it, so if the caller 54 * needs style to be flushed (e.g. DOM APIs), the caller should flush style 55 * before calling this. 56 */ 57 already_AddRefed<Path> BuildPath(PathBuilder* aBuilder) override; 58 59 /** 60 * This returns a path without the extra little line segments that 61 * ApproximateZeroLengthSubpathSquareCaps can insert if we have square-caps. 62 * See the comment for that function for more info on that. 63 * 64 * Note: This function maps d attribute to CSS d property, and we don't flush 65 * style in this function because some callers don't need it, so if the caller 66 * needs style to be flushed (e.g. DOM APIs), the caller should flush style 67 * before calling this. 68 */ 69 already_AddRefed<Path> GetOrBuildPathForMeasuring() override; 70 71 bool GetDistancesFromOriginToEndsOfVisibleSegments( 72 FallibleTArray<double>* aOutput) override; 73 74 bool IsClosedLoop() const override; 75 76 // nsIContent interface 77 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 78 79 SVGAnimatedPathSegList* GetAnimPathSegList() override { return &mD; } 80 81 nsStaticAtom* GetPathDataAttrName() const override { return nsGkAtoms::d; } 82 83 // WebIDL 84 MOZ_CAN_RUN_SCRIPT 85 already_AddRefed<SVGPathSegment> GetPathSegmentAtLength(float distance); 86 MOZ_CAN_RUN_SCRIPT 87 void GetPathData(const SVGPathDataSettings& aOptions, 88 nsTArray<RefPtr<SVGPathSegment>>& aValues); 89 void SetPathData(const Sequence<SVGPathSegmentInit>& aValues); 90 91 static bool IsDPropertyChangedViaCSS(const ComputedStyle& aNewStyle, 92 const ComputedStyle& aOldStyle); 93 94 protected: 95 SVGAnimatedPathSegList mD; 96 }; 97 98 } // namespace mozilla::dom 99 100 #endif // DOM_SVG_SVGPATHELEMENT_H_