michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* DOM object representing values in DOM computed style */ michael@0: michael@0: #ifndef nsROCSSPrimitiveValue_h___ michael@0: #define nsROCSSPrimitiveValue_h___ michael@0: michael@0: #include "nsIDOMCSSValue.h" michael@0: #include "nsIDOMCSSPrimitiveValue.h" michael@0: #include "nsCSSKeywords.h" michael@0: #include "CSSValue.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCoord.h" michael@0: michael@0: class nsIURI; michael@0: class nsDOMCSSRect; michael@0: class nsDOMCSSRGBColor; michael@0: michael@0: // There is no CSS_TURN constant on the CSSPrimitiveValue interface, michael@0: // since that unit is newer than DOM Level 2 Style, and CSS OM will michael@0: // probably expose CSS values in some other way in the future. We michael@0: // use this value in mType for "turn"-unit angles, but we define it michael@0: // here to avoid exposing it to content. michael@0: #define CSS_TURN 30U michael@0: // Likewise we have some internal aliases for CSS_NUMBER that we don't michael@0: // want to expose. michael@0: #define CSS_NUMBER_INT32 31U michael@0: #define CSS_NUMBER_UINT32 32U michael@0: michael@0: /** michael@0: * Read-only CSS primitive value - a DOM object representing values in DOM michael@0: * computed style. michael@0: */ michael@0: class nsROCSSPrimitiveValue MOZ_FINAL : public mozilla::dom::CSSValue, michael@0: public nsIDOMCSSPrimitiveValue michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsROCSSPrimitiveValue, mozilla::dom::CSSValue) michael@0: michael@0: // nsIDOMCSSPrimitiveValue michael@0: NS_DECL_NSIDOMCSSPRIMITIVEVALUE michael@0: michael@0: // nsIDOMCSSValue michael@0: NS_DECL_NSIDOMCSSVALUE michael@0: michael@0: // CSSValue michael@0: virtual void GetCssText(nsString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL; michael@0: virtual void SetCssText(const nsAString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL; michael@0: virtual uint16_t CssValueType() const MOZ_OVERRIDE MOZ_FINAL; michael@0: michael@0: // CSSPrimitiveValue michael@0: uint16_t PrimitiveType() michael@0: { michael@0: // New value types were introduced but not added to CSS OM. michael@0: // Return CSS_UNKNOWN to avoid exposing CSS_TURN to content. michael@0: if (mType > CSS_RGBCOLOR) { michael@0: if (mType == CSS_NUMBER_INT32 || mType == CSS_NUMBER_UINT32) { michael@0: return CSS_NUMBER; michael@0: } michael@0: return CSS_UNKNOWN; michael@0: } michael@0: return mType; michael@0: } michael@0: void SetFloatValue(uint16_t aUnitType, float aValue, michael@0: mozilla::ErrorResult& aRv); michael@0: float GetFloatValue(uint16_t aUnitType, mozilla::ErrorResult& aRv); michael@0: void GetStringValue(nsString& aString, mozilla::ErrorResult& aRv); michael@0: void SetStringValue(uint16_t aUnitType, const nsAString& aString, michael@0: mozilla::ErrorResult& aRv); michael@0: already_AddRefed GetCounterValue(mozilla::ErrorResult& aRv); michael@0: nsDOMCSSRect* GetRectValue(mozilla::ErrorResult& aRv); michael@0: nsDOMCSSRGBColor *GetRGBColorValue(mozilla::ErrorResult& aRv); michael@0: michael@0: // nsROCSSPrimitiveValue michael@0: nsROCSSPrimitiveValue(); michael@0: ~nsROCSSPrimitiveValue(); michael@0: michael@0: void SetNumber(float aValue); michael@0: void SetNumber(int32_t aValue); michael@0: void SetNumber(uint32_t aValue); michael@0: void SetPercent(float aValue); michael@0: void SetDegree(float aValue); michael@0: void SetGrad(float aValue); michael@0: void SetRadian(float aValue); michael@0: void SetTurn(float aValue); michael@0: void SetAppUnits(nscoord aValue); michael@0: void SetAppUnits(float aValue); michael@0: void SetIdent(nsCSSKeyword aKeyword); michael@0: // FIXME: CSS_STRING should imply a string with "" and a need for escaping. michael@0: void SetString(const nsACString& aString, uint16_t aType = CSS_STRING); michael@0: // FIXME: CSS_STRING should imply a string with "" and a need for escaping. michael@0: void SetString(const nsAString& aString, uint16_t aType = CSS_STRING); michael@0: void SetURI(nsIURI *aURI); michael@0: void SetColor(nsDOMCSSRGBColor* aColor); michael@0: void SetRect(nsDOMCSSRect* aRect); michael@0: void SetTime(float aValue); michael@0: void Reset(); michael@0: michael@0: nsISupports* GetParentObject() const michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: virtual JSObject *WrapObject(JSContext *cx) MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: uint16_t mType; michael@0: michael@0: union { michael@0: nscoord mAppUnits; michael@0: float mFloat; michael@0: int32_t mInt32; michael@0: uint32_t mUint32; michael@0: nsDOMCSSRGBColor* mColor; michael@0: nsDOMCSSRect* mRect; michael@0: char16_t* mString; michael@0: nsIURI* mURI; michael@0: nsCSSKeyword mKeyword; michael@0: } mValue; michael@0: }; michael@0: michael@0: inline nsROCSSPrimitiveValue *mozilla::dom::CSSValue::AsPrimitiveValue() michael@0: { michael@0: return CssValueType() == nsIDOMCSSValue::CSS_PRIMITIVE_VALUE ? michael@0: static_cast(this) : nullptr; michael@0: } michael@0: michael@0: #endif /* nsROCSSPrimitiveValue_h___ */ michael@0: