nsROCSSPrimitiveValue.h (1991B)
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 /* DOM object representing values in DOM computed style */ 8 9 #ifndef nsROCSSPrimitiveValue_h___ 10 #define nsROCSSPrimitiveValue_h___ 11 12 #include "CSSValue.h" 13 #include "nsCoord.h" 14 #include "nsString.h" 15 16 /** 17 * Read-only CSS primitive value - a DOM object representing values in DOM 18 * computed style. 19 */ 20 class nsROCSSPrimitiveValue final : public mozilla::dom::CSSValue { 21 public: 22 enum : uint16_t { 23 CSS_UNKNOWN, 24 CSS_NUMBER, 25 CSS_PERCENTAGE, 26 CSS_PX, 27 CSS_DEG, 28 CSS_S, 29 CSS_STRING, 30 CSS_RGBCOLOR, 31 CSS_NUMBER_INT32, 32 CSS_NUMBER_UINT32, 33 }; 34 35 // CSSValue 36 void GetCssText(nsAString&) final; 37 uint16_t CssValueType() const final; 38 39 // CSSPrimitiveValue 40 uint16_t PrimitiveType(); 41 42 // nsROCSSPrimitiveValue 43 nsROCSSPrimitiveValue(); 44 45 void SetNumber(float aValue); 46 void SetNumber(int32_t aValue); 47 void SetNumber(uint32_t aValue); 48 void SetPercent(float aValue); 49 void SetDegree(float aValue); 50 void SetPixels(float aValue); 51 void SetString(const nsACString& aString); 52 void SetString(const nsAString& aString); 53 54 template <size_t N> 55 void SetString(const char (&aString)[N]) { 56 SetString(nsLiteralCString(aString)); 57 } 58 59 void SetTime(float aValue); 60 void Reset(); 61 62 virtual ~nsROCSSPrimitiveValue(); 63 64 protected: 65 uint16_t mType; 66 67 union { 68 float mFloat; 69 int32_t mInt32; 70 uint32_t mUint32; 71 char16_t* mString; 72 } mValue; 73 }; 74 75 inline nsROCSSPrimitiveValue* mozilla::dom::CSSValue::AsPrimitiveValue() { 76 return CssValueType() == mozilla::dom::CSSValue::CSS_PRIMITIVE_VALUE 77 ? static_cast<nsROCSSPrimitiveValue*>(this) 78 : nullptr; 79 } 80 81 #endif /* nsROCSSPrimitiveValue_h___ */