OSDN Git Service

am 3c54ece0: am 5dc34a85: activeDocumentLoader() causes crash in WebCoreFrameBridge.cpp
[android-x86/external-webkit.git] / WebCore / css / CSSValueList.cpp
1 /**
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007 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 #include "config.h"
21 #include "CSSValueList.h"
22
23 #include "CSSParserValues.h"
24 #include "PlatformString.h"
25
26 namespace WebCore {
27
28 CSSValueList::CSSValueList(bool isSpaceSeparated)
29     : m_isSpaceSeparated(isSpaceSeparated)
30 {
31 }
32
33 CSSValueList::CSSValueList(CSSParserValueList* list)
34     : m_isSpaceSeparated(true)
35 {
36     if (list) {
37         unsigned s = list->size();
38         for (unsigned i = 0; i < s; ++i) {
39             CSSParserValue* v = list->valueAt(i);
40             append(v->createCSSValue());
41         }
42     }
43 }
44
45 CSSValueList::~CSSValueList()
46 {
47 }
48
49 CSSValue* CSSValueList::item(unsigned index)
50 {
51     if (index >= m_values.size())
52         return 0;
53     return m_values[index].get();
54 }
55
56 unsigned short CSSValueList::cssValueType() const
57 {
58     return CSS_VALUE_LIST;
59 }
60
61 void CSSValueList::append(PassRefPtr<CSSValue> val)
62 {
63     m_values.append(val);
64 }
65
66 void CSSValueList::prepend(PassRefPtr<CSSValue> val)
67 {
68     m_values.prepend(val);
69 }
70
71 bool CSSValueList::removeAll(CSSValue* val)
72 {
73     bool found = false;
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);
79             found = true;
80         }
81     }
82     
83     return found;
84 }
85     
86 bool CSSValueList::hasValue(CSSValue* val)
87 {
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())
92             return true;
93     }
94     return false;
95 }
96
97 PassRefPtr<CSSValueList> CSSValueList::copy()
98 {
99     PassRefPtr<CSSValueList> newList = m_isSpaceSeparated ? createSpaceSeparated() : createCommaSeparated();
100     for (size_t index = 0; index < m_values.size(); index++)
101         newList->append(item(index));
102     return newList;
103 }
104
105 String CSSValueList::cssText() const
106 {
107     String result = "";
108
109     unsigned size = m_values.size();
110     for (unsigned i = 0; i < size; i++) {
111         if (!result.isEmpty()) {
112             if (m_isSpaceSeparated)
113                 result += " ";
114             else
115                 result += ", ";
116         }
117         result += m_values[i]->cssText();
118     }
119
120     return result;
121 }
122
123 CSSParserValueList* CSSValueList::createParserValueList() const
124 {
125     unsigned s = m_values.size();
126     if (!s)
127         return 0;
128     CSSParserValueList* result = new CSSParserValueList;
129     for (unsigned i = 0; i < s; ++i)
130         result->addValue(m_values[i]->parserValue());
131     return result;
132 }
133
134 void CSSValueList::addSubresourceStyleURLs(ListHashSet<KURL>& urls, const CSSStyleSheet* styleSheet)
135 {
136     size_t size = m_values.size();
137     for (size_t i = 0; i < size; ++i)
138         m_values[i]->addSubresourceStyleURLs(urls, styleSheet);
139 }
140
141 } // namespace WebCore