initial import
[vuplus_webkit] / Source / WebCore / css / CSSValueList.cpp
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22 #include "CSSValueList.h"
23
24 #include "CSSParserValues.h"
25 #include "PlatformString.h"
26 #include <wtf/PassOwnPtr.h>
27
28 namespace WebCore {
29
30 CSSValueList::CSSValueList(bool isSpaceSeparated)
31     : m_isSpaceSeparated(isSpaceSeparated)
32 {
33 }
34
35 CSSValueList::CSSValueList(CSSParserValueList* list)
36     : m_isSpaceSeparated(true)
37 {
38     if (list) {
39         size_t size = list->size();
40         for (unsigned i = 0; i < size; ++i)
41             append(list->valueAt(i)->createCSSValue());
42     }
43 }
44
45 CSSValueList::~CSSValueList()
46 {
47 }
48
49 unsigned short CSSValueList::cssValueType() const
50 {
51     return CSS_VALUE_LIST;
52 }
53
54 void CSSValueList::append(PassRefPtr<CSSValue> val)
55 {
56     m_values.append(val);
57 }
58
59 void CSSValueList::prepend(PassRefPtr<CSSValue> val)
60 {
61     m_values.prepend(val);
62 }
63
64 bool CSSValueList::removeAll(CSSValue* val)
65 {
66     bool found = false;
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);
72             found = true;
73         }
74     }
75     
76     return found;
77 }
78     
79 bool CSSValueList::hasValue(CSSValue* val)
80 {
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())
85             return true;
86     }
87     return false;
88 }
89
90 PassRefPtr<CSSValueList> CSSValueList::copy()
91 {
92     PassRefPtr<CSSValueList> newList = m_isSpaceSeparated ? createSpaceSeparated() : createCommaSeparated();
93     for (size_t index = 0; index < m_values.size(); index++)
94         newList->append(m_values[index]);
95     return newList;
96 }
97
98 String CSSValueList::cssText() const
99 {
100     String result = "";
101
102     unsigned size = m_values.size();
103     for (unsigned i = 0; i < size; i++) {
104         if (!result.isEmpty()) {
105             if (m_isSpaceSeparated)
106                 result += " ";
107             else
108                 result += ", ";
109         }
110         result += m_values[i]->cssText();
111     }
112
113     return result;
114 }
115
116 void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
117 {
118     size_t size = m_values.size();
119     for (size_t i = 0; i < size; ++i)
120         m_values[i]->addSubresourceStyleURLs(urls, styleSheet);
121 }
122
123 } // namespace WebCore