OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org> |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/svg/SVGStringList.h" | 22 #include "core/svg/SVGStringList.h" |
23 | 23 |
24 #include "core/svg/SVGElement.h" | 24 #include "core/svg/SVGElement.h" |
25 #include "core/svg/SVGParserUtilities.h" | 25 #include "core/svg/SVGParserUtilities.h" |
26 #include "wtf/text/StringBuilder.h" | 26 #include "wtf/text/StringBuilder.h" |
27 | 27 |
28 namespace WebCore { | 28 namespace WebCore { |
29 | 29 |
30 void SVGStringList::commitChange(SVGElement* contextElement) | 30 SVGStringList::SVGStringList() |
31 : NewSVGPropertyBase(classType()) | |
31 { | 32 { |
32 ASSERT(contextElement); | |
33 contextElement->invalidateSVGAttributes(); | |
34 contextElement->svgAttributeChanged(m_attributeName); | |
35 } | 33 } |
36 | 34 |
37 void SVGStringList::reset(const String& string) | 35 SVGStringList::~SVGStringList() |
38 { | 36 { |
39 parse(string, ' '); | 37 } |
40 | 38 |
41 // Add empty string, if list is empty. | 39 void SVGStringList::initialize(const String& item) |
42 if (isEmpty()) | 40 { |
43 append(emptyString()); | 41 m_values.clear(); |
42 m_values.append(item); | |
43 } | |
44 | |
45 String SVGStringList::getItem(size_t index, ExceptionState& exceptionState) | |
46 { | |
47 if (!checkIndexBound(index, exceptionState)) | |
48 return String(); | |
49 | |
50 ASSERT(index < m_values.size()); | |
haraken
2014/01/29 05:18:00
You don't need this.
kouhei (in TOK)
2014/01/30 08:18:56
Done.
| |
51 return m_values.at(index); | |
52 } | |
53 | |
54 void SVGStringList::insertItemBefore(const String& newItem, size_t index) | |
55 { | |
56 // Spec: If the index is greater than or equal to numberOfItems, then the ne w item is appended to the end of the list. | |
57 if (index > m_values.size()) | |
58 index = m_values.size(); | |
59 | |
60 // Spec: Inserts a new item into the list at the specified position. The ind ex of the item before which the new item is to be | |
61 // inserted. The first item is number 0. If the index is equal to 0, then th e new item is inserted at the front of the list. | |
62 m_values.insert(index, newItem); | |
63 } | |
64 | |
65 String SVGStringList::removeItem(size_t index, ExceptionState& exceptionState) | |
66 { | |
67 if (!checkIndexBound(index, exceptionState)) | |
68 return String(); | |
69 | |
70 String oldItem = m_values.at(index); | |
71 m_values.remove(index); | |
72 return oldItem; | |
73 } | |
74 | |
75 void SVGStringList::appendItem(const String& newItem) | |
76 { | |
77 m_values.append(newItem); | |
78 } | |
79 | |
80 void SVGStringList::replaceItem(const String& newItem, size_t index, ExceptionSt ate& exceptionState) | |
81 { | |
82 if (!checkIndexBound(index, exceptionState)) | |
83 return; | |
84 | |
85 // Update the value at the desired position 'index'. | |
86 m_values[index] = newItem; | |
44 } | 87 } |
45 | 88 |
46 template<typename CharType> | 89 template<typename CharType> |
47 void SVGStringList::parseInternal(const CharType*& ptr, const CharType* end, UCh ar delimiter) | 90 void SVGStringList::parseInternal(const CharType*& ptr, const CharType* end) |
48 { | 91 { |
92 const UChar delimiter = ' '; | |
93 | |
49 while (ptr < end) { | 94 while (ptr < end) { |
50 const CharType* start = ptr; | 95 const CharType* start = ptr; |
51 while (ptr < end && *ptr != delimiter && !isSVGSpace(*ptr)) | 96 while (ptr < end && *ptr != delimiter && !isSVGSpace(*ptr)) |
52 ptr++; | 97 ptr++; |
53 if (ptr == start) | 98 if (ptr == start) |
54 break; | 99 break; |
55 append(String(start, ptr - start)); | 100 m_values.append(String(start, ptr - start)); |
56 skipOptionalSVGSpacesOrDelimiter(ptr, end, delimiter); | 101 skipOptionalSVGSpacesOrDelimiter(ptr, end, delimiter); |
57 } | 102 } |
58 } | 103 } |
59 | 104 |
60 void SVGStringList::parse(const String& data, UChar delimiter) | 105 PassRefPtr<SVGStringList> SVGStringList::clone() |
106 { | |
107 RefPtr<SVGStringList> svgStringList = create(); | |
108 svgStringList->m_values = m_values; | |
109 return svgStringList.release(); | |
110 } | |
111 | |
112 void SVGStringList::setValueAsString(const String& data, ExceptionState&) | |
61 { | 113 { |
62 // FIXME: Add more error checking and reporting. | 114 // FIXME: Add more error checking and reporting. |
63 clear(); | 115 m_values.clear(); |
64 if (data.isEmpty()) | 116 if (data.isEmpty()) |
65 return; | 117 return; |
66 if (data.is8Bit()) { | 118 if (data.is8Bit()) { |
67 const LChar* ptr = data.characters8(); | 119 const LChar* ptr = data.characters8(); |
68 const LChar* end = ptr + data.length(); | 120 const LChar* end = ptr + data.length(); |
69 parseInternal(ptr, end, delimiter); | 121 parseInternal(ptr, end); |
70 } else { | 122 } else { |
71 const UChar* ptr = data.characters16(); | 123 const UChar* ptr = data.characters16(); |
72 const UChar* end = ptr + data.length(); | 124 const UChar* end = ptr + data.length(); |
73 parseInternal(ptr, end, delimiter); | 125 parseInternal(ptr, end); |
74 } | 126 } |
75 } | 127 } |
76 | 128 |
129 PassRefPtr<NewSVGPropertyBase> SVGStringList::cloneForAnimation(const String& st ring) const | |
130 { | |
131 RefPtr<SVGStringList> svgStringList = create(); | |
132 svgStringList->setValueAsString(string, IGNORE_EXCEPTION); | |
133 return svgStringList.release(); | |
134 } | |
135 | |
77 String SVGStringList::valueAsString() const | 136 String SVGStringList::valueAsString() const |
78 { | 137 { |
79 StringBuilder builder; | 138 StringBuilder builder; |
80 | 139 |
81 unsigned size = this->size(); | 140 Vector<String>::const_iterator it = m_values.begin(); |
82 for (unsigned i = 0; i < size; ++i) { | 141 Vector<String>::const_iterator itEnd = m_values.end(); |
83 if (i > 0) | 142 if (it != itEnd) { |
143 builder.append(*it); | |
144 ++it; | |
145 | |
146 for (; it != itEnd; ++it) { | |
84 builder.append(' '); | 147 builder.append(' '); |
85 | 148 builder.append(*it); |
86 builder.append(at(i)); | 149 } |
87 } | 150 } |
88 | 151 |
89 return builder.toString(); | 152 return builder.toString(); |
90 } | 153 } |
91 | 154 |
155 bool SVGStringList::checkIndexBound(size_t index, ExceptionState& exceptionState ) | |
156 { | |
157 if (index >= m_values.size()) { | |
158 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMaximumBound("index", index, m_values.size())); | |
159 return false; | |
160 } | |
161 | |
162 return true; | |
92 } | 163 } |
164 | |
165 void SVGStringList::add(PassRefPtr<NewSVGPropertyBase> other, SVGElement* contex tElement) | |
166 { | |
167 // SVGStringList is never animated. | |
168 ASSERT_NOT_REACHED(); | |
169 } | |
170 | |
171 void SVGStringList::calculateAnimatedValue(SVGAnimationElement*, float, unsigned , PassRefPtr<NewSVGPropertyBase>, PassRefPtr<NewSVGPropertyBase>, PassRefPtr<New SVGPropertyBase>, SVGElement*) | |
172 { | |
173 // SVGStringList is never animated. | |
174 ASSERT_NOT_REACHED(); | |
175 } | |
176 | |
177 float SVGStringList::calculateDistance(PassRefPtr<NewSVGPropertyBase>, SVGElemen t*) | |
178 { | |
179 // SVGStringList is never animated. | |
180 ASSERT_NOT_REACHED(); | |
181 | |
182 return -1.0f; | |
183 } | |
184 | |
185 } | |
OLD | NEW |