2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "CSSValueList.h"
24 #include "CSSParserValues.h"
25 #include "PlatformString.h"
26 #include <wtf/PassOwnPtr.h>
27 #include <wtf/text/StringBuilder.h>
31 CSSValueList::CSSValueList(ClassType classType, ValueListSeparator listSeparator)
34 m_valueListSeparator = listSeparator;
37 CSSValueList::CSSValueList(ValueListSeparator listSeparator)
38 : CSSValue(ValueListClass)
40 m_valueListSeparator = listSeparator;
43 CSSValueList::CSSValueList(CSSParserValueList* list)
44 : CSSValue(ValueListClass)
46 m_valueListSeparator = SpaceSeparator;
48 size_t size = list->size();
49 for (unsigned i = 0; i < size; ++i)
50 append(list->valueAt(i)->createCSSValue());
54 void CSSValueList::append(PassRefPtr<CSSValue> val)
59 void CSSValueList::prepend(PassRefPtr<CSSValue> val)
61 m_values.prepend(val);
64 bool CSSValueList::removeAll(CSSValue* val)
67 // FIXME: we should be implementing operator== to CSSValue and its derived classes
68 // to make comparison more flexible and fast.
69 for (size_t index = 0; index < m_values.size(); index++) {
70 if (m_values.at(index)->cssText() == val->cssText()) {
71 m_values.remove(index);
79 bool CSSValueList::hasValue(CSSValue* val) const
81 // FIXME: we should be implementing operator== to CSSValue and its derived classes
82 // to make comparison more flexible and fast.
83 for (size_t index = 0; index < m_values.size(); index++) {
84 if (m_values.at(index)->cssText() == val->cssText())
90 PassRefPtr<CSSValueList> CSSValueList::copy()
92 RefPtr<CSSValueList> newList;
93 switch (m_valueListSeparator) {
95 newList = createSpaceSeparated();
98 newList = createCommaSeparated();
101 newList = createSlashSeparated();
104 ASSERT_NOT_REACHED();
106 for (size_t index = 0; index < m_values.size(); index++)
107 newList->append(m_values[index]);
108 return newList.release();
111 String CSSValueList::customCssText() const
113 StringBuilder result;
115 switch (m_valueListSeparator) {
126 ASSERT_NOT_REACHED();
129 unsigned size = m_values.size();
130 for (unsigned i = 0; i < size; i++) {
131 if (!result.isEmpty())
132 result.append(separator);
133 result.append(m_values[i]->cssText());
136 return result.toString();
139 #if ENABLE(CSS_VARIABLES)
140 String CSSValueList::customSerializeResolvingVariables(const HashMap<AtomicString, String>& variables) const
142 StringBuilder result;
144 switch (m_valueListSeparator) {
155 ASSERT_NOT_REACHED();
158 unsigned size = m_values.size();
159 for (unsigned i = 0; i < size; i++) {
160 if (!result.isEmpty())
161 result.append(separator);
162 result.append(m_values[i]->serializeResolvingVariables(variables));
165 return result.toString();
169 void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const StyleSheetContents* styleSheet) const
171 size_t size = m_values.size();
172 for (size_t i = 0; i < size; ++i)
173 m_values[i]->addSubresourceStyleURLs(urls, styleSheet);
176 CSSValueList::CSSValueList(const CSSValueList& cloneFrom)
177 : CSSValue(cloneFrom.classType(), /* isCSSOMSafe */ true)
179 m_valueListSeparator = cloneFrom.m_valueListSeparator;
180 m_values.resize(cloneFrom.m_values.size());
181 for (unsigned i = 0; i < m_values.size(); ++i)
182 m_values[i] = cloneFrom.m_values[i]->cloneForCSSOM();
185 PassRefPtr<CSSValueList> CSSValueList::cloneForCSSOM() const
187 return adoptRef(new CSSValueList(*this));
190 } // namespace WebCore