2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007 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.
21 #include "CSSValueList.h"
23 #include "CSSParserValues.h"
24 #include "PlatformString.h"
28 CSSValueList::CSSValueList(bool isSpaceSeparated)
29 : m_isSpaceSeparated(isSpaceSeparated)
33 CSSValueList::CSSValueList(CSSParserValueList* list)
34 : m_isSpaceSeparated(true)
37 unsigned s = list->size();
38 for (unsigned i = 0; i < s; ++i) {
39 CSSParserValue* v = list->valueAt(i);
40 append(v->createCSSValue());
45 CSSValueList::~CSSValueList()
49 CSSValue* CSSValueList::item(unsigned index)
51 if (index >= m_values.size())
53 return m_values[index].get();
56 unsigned short CSSValueList::cssValueType() const
58 return CSS_VALUE_LIST;
61 void CSSValueList::append(PassRefPtr<CSSValue> val)
66 void CSSValueList::prepend(PassRefPtr<CSSValue> val)
68 m_values.prepend(val);
71 bool CSSValueList::removeAll(CSSValue* val)
74 // FIXME: we should be implementing operator== to CSSValue and its derived classes
75 // to make comparison more flexible and fast.
76 for (size_t index = 0; index < m_values.size(); index++) {
77 if (m_values.at(index)->cssText() == val->cssText()) {
78 m_values.remove(index);
86 bool CSSValueList::hasValue(CSSValue* val)
88 // FIXME: we should be implementing operator== to CSSValue and its derived classes
89 // to make comparison more flexible and fast.
90 for (size_t index = 0; index < m_values.size(); index++) {
91 if (m_values.at(index)->cssText() == val->cssText())
97 PassRefPtr<CSSValueList> CSSValueList::copy()
99 PassRefPtr<CSSValueList> newList = m_isSpaceSeparated ? createSpaceSeparated() : createCommaSeparated();
100 for (size_t index = 0; index < m_values.size(); index++)
101 newList->append(item(index));
105 String CSSValueList::cssText() const
109 unsigned size = m_values.size();
110 for (unsigned i = 0; i < size; i++) {
111 if (!result.isEmpty()) {
112 if (m_isSpaceSeparated)
117 result += m_values[i]->cssText();
123 CSSParserValueList* CSSValueList::createParserValueList() const
125 unsigned s = m_values.size();
128 CSSParserValueList* result = new CSSParserValueList;
129 for (unsigned i = 0; i < s; ++i)
130 result->addValue(m_values[i]->parserValue());
134 void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
136 size_t size = m_values.size();
137 for (size_t i = 0; i < size; ++i)
138 m_values[i]->addSubresourceStyleURLs(urls, styleSheet);
141 } // namespace WebCore