1/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 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#pragma once
22
23#include "CSSValue.h"
24#include <wtf/Function.h>
25#include <wtf/Vector.h>
26
27namespace WebCore {
28
29class CSSCustomPropertyValue;
30struct CSSParserValue;
31class CSSParserValueList;
32
33class CSSValueList : public CSSValue {
34public:
35 typedef Vector<Ref<CSSValue>, 4>::iterator iterator;
36 typedef Vector<Ref<CSSValue>, 4>::const_iterator const_iterator;
37
38 static Ref<CSSValueList> createCommaSeparated()
39 {
40 return adoptRef(*new CSSValueList(CommaSeparator));
41 }
42 static Ref<CSSValueList> createSpaceSeparated()
43 {
44 return adoptRef(*new CSSValueList(SpaceSeparator));
45 }
46 static Ref<CSSValueList> createSlashSeparated()
47 {
48 return adoptRef(*new CSSValueList(SlashSeparator));
49 }
50
51 size_t length() const { return m_values.size(); }
52 CSSValue* item(size_t index) { return index < m_values.size() ? m_values[index].ptr() : nullptr; }
53 const CSSValue* item(size_t index) const { return index < m_values.size() ? m_values[index].ptr() : nullptr; }
54 CSSValue* itemWithoutBoundsCheck(size_t index) { return m_values[index].ptr(); }
55 const CSSValue* itemWithoutBoundsCheck(size_t index) const { ASSERT(index < m_values.size()); return m_values[index].ptr(); }
56
57 const_iterator begin() const { return m_values.begin(); }
58 const_iterator end() const { return m_values.end(); }
59 iterator begin() { return m_values.begin(); }
60 iterator end() { return m_values.end(); }
61
62 void append(Ref<CSSValue>&&);
63 void prepend(Ref<CSSValue>&&);
64 bool removeAll(CSSValue*);
65 bool hasValue(CSSValue*) const;
66 Ref<CSSValueList> copy();
67
68 String customCSSText() const;
69 bool equals(const CSSValueList&) const;
70 bool equals(const CSSValue&) const;
71
72 bool traverseSubresources(const WTF::Function<bool (const CachedResource&)>& handler) const;
73
74 unsigned separator() const { return m_valueListSeparator; }
75
76protected:
77 CSSValueList(ClassType, ValueListSeparator);
78
79private:
80 explicit CSSValueList(ValueListSeparator);
81
82 Vector<Ref<CSSValue>, 4> m_values;
83};
84
85inline void CSSValueList::append(Ref<CSSValue>&& value)
86{
87 m_values.append(WTFMove(value));
88}
89
90inline void CSSValueList::prepend(Ref<CSSValue>&& value)
91{
92 m_values.insert(0, WTFMove(value));
93}
94
95} // namespace WebCore
96
97SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSValueList, isValueList())
98