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 mozilla_dom_SVGAngle_h
8 #define mozilla_dom_SVGAngle_h
9 
10 #include "nsWrapperCache.h"
11 #include "SVGElement.h"
12 #include "mozilla/Attributes.h"
13 
14 namespace mozilla {
15 
16 class SVGAnimatedOrient;
17 
18 namespace dom {
19 class SVGSVGElement;
20 
21 class DOMSVGAngle final : public nsWrapperCache {
22  public:
23   typedef enum { BaseValue, AnimValue, CreatedValue } AngleType;
24 
25   NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGAngle)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMSVGAngle)26   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(DOMSVGAngle)
27 
28   /**
29    * Generic ctor for DOMSVGAngle objects that are created for an attribute.
30    */
31   DOMSVGAngle(SVGAnimatedOrient* aVal, SVGElement* aSVGElement, AngleType aType)
32       : mVal(aVal), mSVGElement(aSVGElement), mType(aType) {}
33 
34   /**
35    * Ctor for creating the objects returned by SVGSVGElement.createSVGAngle(),
36    * which do not initially belong to an attribute.
37    */
38   explicit DOMSVGAngle(SVGSVGElement* aSVGElement);
39 
40   // WebIDL
GetParentObject()41   SVGElement* GetParentObject() { return mSVGElement; }
42   virtual JSObject* WrapObject(JSContext* aCx,
43                                JS::Handle<JSObject*> aGivenProto) override;
44   uint16_t UnitType() const;
45   float Value() const;
46   void GetValueAsString(nsAString& aValue);
47   void SetValue(float aValue, ErrorResult& rv);
48   float ValueInSpecifiedUnits() const;
49   void SetValueInSpecifiedUnits(float aValue, ErrorResult& rv);
50   void SetValueAsString(const nsAString& aValue, ErrorResult& rv);
51   void NewValueSpecifiedUnits(uint16_t unitType, float value, ErrorResult& rv);
52   void ConvertToSpecifiedUnits(uint16_t unitType, ErrorResult& rv);
53 
54  protected:
55   ~DOMSVGAngle();
56 
57   SVGAnimatedOrient* mVal;  // if mType is CreatedValue, we own the angle.
58                             // Otherwise, the element does.
59   RefPtr<SVGElement> mSVGElement;
60   AngleType mType;
61 };
62 
63 }  // namespace dom
64 }  // namespace mozilla
65 
66 #endif  // mozilla_dom_SVGAngle_h
67