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