Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* DOM object representing values in DOM computed style */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef nsROCSSPrimitiveValue_h___ |
michael@0 | 9 | #define nsROCSSPrimitiveValue_h___ |
michael@0 | 10 | |
michael@0 | 11 | #include "nsIDOMCSSValue.h" |
michael@0 | 12 | #include "nsIDOMCSSPrimitiveValue.h" |
michael@0 | 13 | #include "nsCSSKeywords.h" |
michael@0 | 14 | #include "CSSValue.h" |
michael@0 | 15 | #include "nsCOMPtr.h" |
michael@0 | 16 | #include "nsCoord.h" |
michael@0 | 17 | |
michael@0 | 18 | class nsIURI; |
michael@0 | 19 | class nsDOMCSSRect; |
michael@0 | 20 | class nsDOMCSSRGBColor; |
michael@0 | 21 | |
michael@0 | 22 | // There is no CSS_TURN constant on the CSSPrimitiveValue interface, |
michael@0 | 23 | // since that unit is newer than DOM Level 2 Style, and CSS OM will |
michael@0 | 24 | // probably expose CSS values in some other way in the future. We |
michael@0 | 25 | // use this value in mType for "turn"-unit angles, but we define it |
michael@0 | 26 | // here to avoid exposing it to content. |
michael@0 | 27 | #define CSS_TURN 30U |
michael@0 | 28 | // Likewise we have some internal aliases for CSS_NUMBER that we don't |
michael@0 | 29 | // want to expose. |
michael@0 | 30 | #define CSS_NUMBER_INT32 31U |
michael@0 | 31 | #define CSS_NUMBER_UINT32 32U |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * Read-only CSS primitive value - a DOM object representing values in DOM |
michael@0 | 35 | * computed style. |
michael@0 | 36 | */ |
michael@0 | 37 | class nsROCSSPrimitiveValue MOZ_FINAL : public mozilla::dom::CSSValue, |
michael@0 | 38 | public nsIDOMCSSPrimitiveValue |
michael@0 | 39 | { |
michael@0 | 40 | public: |
michael@0 | 41 | NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
michael@0 | 42 | NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsROCSSPrimitiveValue, mozilla::dom::CSSValue) |
michael@0 | 43 | |
michael@0 | 44 | // nsIDOMCSSPrimitiveValue |
michael@0 | 45 | NS_DECL_NSIDOMCSSPRIMITIVEVALUE |
michael@0 | 46 | |
michael@0 | 47 | // nsIDOMCSSValue |
michael@0 | 48 | NS_DECL_NSIDOMCSSVALUE |
michael@0 | 49 | |
michael@0 | 50 | // CSSValue |
michael@0 | 51 | virtual void GetCssText(nsString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL; |
michael@0 | 52 | virtual void SetCssText(const nsAString& aText, mozilla::ErrorResult& aRv) MOZ_OVERRIDE MOZ_FINAL; |
michael@0 | 53 | virtual uint16_t CssValueType() const MOZ_OVERRIDE MOZ_FINAL; |
michael@0 | 54 | |
michael@0 | 55 | // CSSPrimitiveValue |
michael@0 | 56 | uint16_t PrimitiveType() |
michael@0 | 57 | { |
michael@0 | 58 | // New value types were introduced but not added to CSS OM. |
michael@0 | 59 | // Return CSS_UNKNOWN to avoid exposing CSS_TURN to content. |
michael@0 | 60 | if (mType > CSS_RGBCOLOR) { |
michael@0 | 61 | if (mType == CSS_NUMBER_INT32 || mType == CSS_NUMBER_UINT32) { |
michael@0 | 62 | return CSS_NUMBER; |
michael@0 | 63 | } |
michael@0 | 64 | return CSS_UNKNOWN; |
michael@0 | 65 | } |
michael@0 | 66 | return mType; |
michael@0 | 67 | } |
michael@0 | 68 | void SetFloatValue(uint16_t aUnitType, float aValue, |
michael@0 | 69 | mozilla::ErrorResult& aRv); |
michael@0 | 70 | float GetFloatValue(uint16_t aUnitType, mozilla::ErrorResult& aRv); |
michael@0 | 71 | void GetStringValue(nsString& aString, mozilla::ErrorResult& aRv); |
michael@0 | 72 | void SetStringValue(uint16_t aUnitType, const nsAString& aString, |
michael@0 | 73 | mozilla::ErrorResult& aRv); |
michael@0 | 74 | already_AddRefed<nsIDOMCounter> GetCounterValue(mozilla::ErrorResult& aRv); |
michael@0 | 75 | nsDOMCSSRect* GetRectValue(mozilla::ErrorResult& aRv); |
michael@0 | 76 | nsDOMCSSRGBColor *GetRGBColorValue(mozilla::ErrorResult& aRv); |
michael@0 | 77 | |
michael@0 | 78 | // nsROCSSPrimitiveValue |
michael@0 | 79 | nsROCSSPrimitiveValue(); |
michael@0 | 80 | ~nsROCSSPrimitiveValue(); |
michael@0 | 81 | |
michael@0 | 82 | void SetNumber(float aValue); |
michael@0 | 83 | void SetNumber(int32_t aValue); |
michael@0 | 84 | void SetNumber(uint32_t aValue); |
michael@0 | 85 | void SetPercent(float aValue); |
michael@0 | 86 | void SetDegree(float aValue); |
michael@0 | 87 | void SetGrad(float aValue); |
michael@0 | 88 | void SetRadian(float aValue); |
michael@0 | 89 | void SetTurn(float aValue); |
michael@0 | 90 | void SetAppUnits(nscoord aValue); |
michael@0 | 91 | void SetAppUnits(float aValue); |
michael@0 | 92 | void SetIdent(nsCSSKeyword aKeyword); |
michael@0 | 93 | // FIXME: CSS_STRING should imply a string with "" and a need for escaping. |
michael@0 | 94 | void SetString(const nsACString& aString, uint16_t aType = CSS_STRING); |
michael@0 | 95 | // FIXME: CSS_STRING should imply a string with "" and a need for escaping. |
michael@0 | 96 | void SetString(const nsAString& aString, uint16_t aType = CSS_STRING); |
michael@0 | 97 | void SetURI(nsIURI *aURI); |
michael@0 | 98 | void SetColor(nsDOMCSSRGBColor* aColor); |
michael@0 | 99 | void SetRect(nsDOMCSSRect* aRect); |
michael@0 | 100 | void SetTime(float aValue); |
michael@0 | 101 | void Reset(); |
michael@0 | 102 | |
michael@0 | 103 | nsISupports* GetParentObject() const |
michael@0 | 104 | { |
michael@0 | 105 | return nullptr; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | virtual JSObject *WrapObject(JSContext *cx) MOZ_OVERRIDE; |
michael@0 | 109 | |
michael@0 | 110 | private: |
michael@0 | 111 | uint16_t mType; |
michael@0 | 112 | |
michael@0 | 113 | union { |
michael@0 | 114 | nscoord mAppUnits; |
michael@0 | 115 | float mFloat; |
michael@0 | 116 | int32_t mInt32; |
michael@0 | 117 | uint32_t mUint32; |
michael@0 | 118 | nsDOMCSSRGBColor* mColor; |
michael@0 | 119 | nsDOMCSSRect* mRect; |
michael@0 | 120 | char16_t* mString; |
michael@0 | 121 | nsIURI* mURI; |
michael@0 | 122 | nsCSSKeyword mKeyword; |
michael@0 | 123 | } mValue; |
michael@0 | 124 | }; |
michael@0 | 125 | |
michael@0 | 126 | inline nsROCSSPrimitiveValue *mozilla::dom::CSSValue::AsPrimitiveValue() |
michael@0 | 127 | { |
michael@0 | 128 | return CssValueType() == nsIDOMCSSValue::CSS_PRIMITIVE_VALUE ? |
michael@0 | 129 | static_cast<nsROCSSPrimitiveValue*>(this) : nullptr; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | #endif /* nsROCSSPrimitiveValue_h___ */ |
michael@0 | 133 |