1 /**
2 * This file is part of the DOM implementation for KDE.
3 *
4 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22 #include "config.h"
23 #include "CSSValueList.h"
24
25 #include "CSSParserValues.h"
26 #include "PlatformString.h"
27
28 namespace WebCore {
29
CSSValueList(bool isSpaceSeparated)30 CSSValueList::CSSValueList(bool isSpaceSeparated)
31 : m_isSpaceSeparated(isSpaceSeparated)
32 {
33 }
34
CSSValueList(CSSParserValueList * list)35 CSSValueList::CSSValueList(CSSParserValueList* list)
36 : m_isSpaceSeparated(true)
37 {
38 if (list) {
39 unsigned s = list->size();
40 for (unsigned i = 0; i < s; ++i) {
41 CSSParserValue* v = list->valueAt(i);
42 append(v->createCSSValue());
43 }
44 }
45 }
46
~CSSValueList()47 CSSValueList::~CSSValueList()
48 {
49 }
50
item(unsigned index)51 CSSValue* CSSValueList::item(unsigned index)
52 {
53 if (index >= m_values.size())
54 return 0;
55 return m_values[index].get();
56 }
57
cssValueType() const58 unsigned short CSSValueList::cssValueType() const
59 {
60 return CSS_VALUE_LIST;
61 }
62
append(PassRefPtr<CSSValue> val)63 void CSSValueList::append(PassRefPtr<CSSValue> val)
64 {
65 m_values.append(val);
66 }
67
prepend(PassRefPtr<CSSValue> val)68 void CSSValueList::prepend(PassRefPtr<CSSValue> val)
69 {
70 m_values.prepend(val);
71 }
72
removeAll(CSSValue * val)73 bool CSSValueList::removeAll(CSSValue* val)
74 {
75 bool found = false;
76 // FIXME: we should be implementing operator== to CSSValue and its derived classes
77 // to make comparison more flexible and fast.
78 for (size_t index = 0; index < m_values.size(); index++) {
79 if (m_values.at(index)->cssText() == val->cssText()) {
80 m_values.remove(index);
81 found = true;
82 }
83 }
84
85 return found;
86 }
87
hasValue(CSSValue * val)88 bool CSSValueList::hasValue(CSSValue* val)
89 {
90 // FIXME: we should be implementing operator== to CSSValue and its derived classes
91 // to make comparison more flexible and fast.
92 for (size_t index = 0; index < m_values.size(); index++) {
93 if (m_values.at(index)->cssText() == val->cssText())
94 return true;
95 }
96 return false;
97 }
98
cssText() const99 String CSSValueList::cssText() const
100 {
101 String result = "";
102
103 unsigned size = m_values.size();
104 for (unsigned i = 0; i < size; i++) {
105 if (!result.isEmpty()) {
106 if (m_isSpaceSeparated)
107 result += " ";
108 else
109 result += ", ";
110 }
111 result += m_values[i]->cssText();
112 }
113
114 return result;
115 }
116
createParserValueList() const117 CSSParserValueList* CSSValueList::createParserValueList() const
118 {
119 unsigned s = m_values.size();
120 if (!s)
121 return 0;
122 CSSParserValueList* result = new CSSParserValueList;
123 for (unsigned i = 0; i < s; ++i)
124 result->addValue(m_values[i]->parserValue());
125 return result;
126 }
127
addSubresourceStyleURLs(ListHashSet<KURL> & urls,const CSSStyleSheet * styleSheet)128 void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
129 {
130 size_t size = m_values.size();
131 for (size_t i = 0; i < size; ++i)
132 m_values[i]->addSubresourceStyleURLs(urls, styleSheet);
133 }
134
135 } // namespace WebCore
136