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