CSSStyleValue.h (2964B)
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 LAYOUT_STYLE_TYPEDOM_CSSSTYLEVALUE_H_ 8 #define LAYOUT_STYLE_TYPEDOM_CSSSTYLEVALUE_H_ 9 10 #include "js/TypeDecls.h" 11 #include "nsCOMPtr.h" 12 #include "nsISupports.h" 13 #include "nsISupportsImpl.h" 14 #include "nsStringFwd.h" 15 #include "nsTArrayForwardDeclare.h" 16 #include "nsWrapperCache.h" 17 18 template <class T> 19 class RefPtr; 20 21 namespace mozilla { 22 23 struct CSSPropertyId; 24 class ErrorResult; 25 26 namespace dom { 27 28 class GlobalObject; 29 class CSSKeywordValue; 30 class CSSMathSum; 31 class CSSUnitValue; 32 class CSSUnsupportedValue; 33 34 class CSSStyleValue : public nsISupports, public nsWrapperCache { 35 public: 36 enum class ValueType { 37 Uninitialized, 38 UnsupportedValue, 39 KeywordValue, 40 UnitValue, 41 MathSum, 42 }; 43 44 explicit CSSStyleValue(nsCOMPtr<nsISupports> aParent); 45 46 CSSStyleValue(nsCOMPtr<nsISupports> aParent, ValueType aValueType); 47 48 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 49 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(CSSStyleValue) 50 51 nsISupports* GetParentObject() const; 52 53 JSObject* WrapObject(JSContext*, JS::Handle<JSObject*> aGivenProto) override; 54 55 // start of CSSStyleValue Web IDL declarations 56 57 [[nodiscard]] static RefPtr<CSSStyleValue> Parse(const GlobalObject& aGlobal, 58 const nsACString& aProperty, 59 const nsACString& aCssText, 60 ErrorResult& aRv); 61 62 static void ParseAll(const GlobalObject& aGlobal, const nsACString& aProperty, 63 const nsACString& aCssText, 64 nsTArray<RefPtr<CSSStyleValue>>& aRetVal, 65 ErrorResult& aRv); 66 67 void Stringify(nsAString& aRetVal) const; 68 69 // end of CSSStyleValue Web IDL declarations 70 71 ValueType GetValueType() const { return mValueType; } 72 73 bool IsCSSUnsupportedValue() const; 74 75 // Defined in CSSUnsupportedValue.cpp 76 CSSUnsupportedValue& GetAsCSSUnsupportedValue(); 77 78 // Returns nullptr if this value is not a CSSUnsupportedValue, caller must 79 // null check. 80 // 81 // Defined in CSSUnsupportedValue.cpp 82 const CSSPropertyId* GetPropertyId(); 83 84 bool IsCSSKeywordValue() const; 85 86 // Defined in CSSKeywordValue.cpp 87 CSSKeywordValue& GetAsCSSKeywordValue(); 88 89 bool IsCSSUnitValue() const; 90 91 // Defined in CSSUnitValue.cpp 92 CSSUnitValue& GetAsCSSUnitValue(); 93 94 bool IsCSSMathSum() const; 95 96 // Defined in CSSMathSum.cpp 97 CSSMathSum& GetAsCSSMathSum(); 98 99 protected: 100 virtual ~CSSStyleValue() = default; 101 102 nsCOMPtr<nsISupports> mParent; 103 const ValueType mValueType; 104 }; 105 106 } // namespace dom 107 } // namespace mozilla 108 109 #endif // LAYOUT_STYLE_TYPEDOM_CSSSTYLEVALUE_H_