|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 /* DOM object representing lists of values in DOM computed style */ |
|
6 |
|
7 #include "nsDOMCSSValueList.h" |
|
8 #include "mozilla/dom/CSSValueListBinding.h" |
|
9 #include "nsAutoPtr.h" |
|
10 |
|
11 using namespace mozilla; |
|
12 |
|
13 nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly) |
|
14 : CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly) |
|
15 { |
|
16 SetIsDOMBinding(); |
|
17 } |
|
18 |
|
19 nsDOMCSSValueList::~nsDOMCSSValueList() |
|
20 { |
|
21 } |
|
22 |
|
23 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList) |
|
24 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList) |
|
25 |
|
26 // QueryInterface implementation for nsDOMCSSValueList |
|
27 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList) |
|
28 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
29 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue) |
|
30 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList) |
|
31 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue) |
|
32 NS_INTERFACE_MAP_END |
|
33 |
|
34 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSValueList, mCSSValues) |
|
35 |
|
36 JSObject* |
|
37 nsDOMCSSValueList::WrapObject(JSContext *cx) |
|
38 { |
|
39 return dom::CSSValueListBinding::Wrap(cx, this); |
|
40 } |
|
41 |
|
42 void |
|
43 nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue) |
|
44 { |
|
45 mCSSValues.AppendElement(aValue); |
|
46 } |
|
47 |
|
48 // nsIDOMCSSValue |
|
49 |
|
50 NS_IMETHODIMP |
|
51 nsDOMCSSValueList::GetCssText(nsAString& aCssText) |
|
52 { |
|
53 aCssText.Truncate(); |
|
54 |
|
55 uint32_t count = mCSSValues.Length(); |
|
56 |
|
57 nsAutoString separator; |
|
58 if (mCommaDelimited) { |
|
59 separator.AssignLiteral(", "); |
|
60 } |
|
61 else { |
|
62 separator.Assign(char16_t(' ')); |
|
63 } |
|
64 |
|
65 nsAutoString tmpStr; |
|
66 for (uint32_t i = 0; i < count; ++i) { |
|
67 CSSValue *cssValue = mCSSValues[i]; |
|
68 NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!"); |
|
69 ErrorResult dummy; |
|
70 if (cssValue) { |
|
71 cssValue->GetCssText(tmpStr, dummy); |
|
72 |
|
73 if (tmpStr.IsEmpty()) { |
|
74 |
|
75 #ifdef DEBUG_caillon |
|
76 NS_ERROR("Eek! An empty CSSValue! Bad!"); |
|
77 #endif |
|
78 |
|
79 continue; |
|
80 } |
|
81 |
|
82 // If this isn't the first item in the list, then |
|
83 // it's ok to append a separator. |
|
84 if (!aCssText.IsEmpty()) { |
|
85 aCssText.Append(separator); |
|
86 } |
|
87 aCssText.Append(tmpStr); |
|
88 } |
|
89 } |
|
90 |
|
91 return NS_OK; |
|
92 } |
|
93 |
|
94 void |
|
95 nsDOMCSSValueList::GetCssText(nsString& aText, ErrorResult& aRv) |
|
96 { |
|
97 aRv = GetCssText(aText); |
|
98 } |
|
99 |
|
100 NS_IMETHODIMP |
|
101 nsDOMCSSValueList::SetCssText(const nsAString& aCssText) |
|
102 { |
|
103 if (mReadonly) { |
|
104 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; |
|
105 } |
|
106 |
|
107 NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!"); |
|
108 return NS_OK; |
|
109 } |
|
110 |
|
111 void |
|
112 nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv) |
|
113 { |
|
114 aRv = SetCssText(aText); |
|
115 } |
|
116 |
|
117 NS_IMETHODIMP |
|
118 nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType) |
|
119 { |
|
120 NS_ENSURE_ARG_POINTER(aValueType); |
|
121 *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST; |
|
122 return NS_OK; |
|
123 } |
|
124 |
|
125 uint16_t |
|
126 nsDOMCSSValueList::CssValueType() const |
|
127 { |
|
128 return nsIDOMCSSValue::CSS_VALUE_LIST; |
|
129 } |