Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: Source/core/svg/properties/SVGListPropertyHelper.h

Issue 208133002: [SVG] Remove "New" prefix from properties implementation. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef NewSVGListPropertyHelper_h 31 #ifndef SVGListPropertyHelper_h
32 #define NewSVGListPropertyHelper_h 32 #define SVGListPropertyHelper_h
33 33
34 #include "bindings/v8/ExceptionMessages.h" 34 #include "bindings/v8/ExceptionMessages.h"
35 #include "bindings/v8/ExceptionStatePlaceholder.h" 35 #include "bindings/v8/ExceptionStatePlaceholder.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/svg/properties/NewSVGProperty.h" 37 #include "core/svg/properties/SVGProperty.h"
38 #include "wtf/PassRefPtr.h" 38 #include "wtf/PassRefPtr.h"
39 #include "wtf/Vector.h" 39 #include "wtf/Vector.h"
40 40
41 namespace WebCore { 41 namespace WebCore {
42 42
43 // This is an implementation of the SVG*List property spec: 43 // This is an implementation of the SVG*List property spec:
44 // http://www.w3.org/TR/SVG/single-page.html#types-InterfaceSVGLengthList 44 // http://www.w3.org/TR/SVG/single-page.html#types-InterfaceSVGLengthList
45 template<typename Derived, typename ItemProperty> 45 template<typename Derived, typename ItemProperty>
46 class NewSVGListPropertyHelper : public NewSVGPropertyBase { 46 class SVGListPropertyHelper : public SVGPropertyBase {
47 public: 47 public:
48 typedef ItemProperty ItemPropertyType; 48 typedef ItemProperty ItemPropertyType;
49 49
50 NewSVGListPropertyHelper() 50 SVGListPropertyHelper()
51 : NewSVGPropertyBase(Derived::classType()) 51 : SVGPropertyBase(Derived::classType())
52 { 52 {
53 } 53 }
54 54
55 ~NewSVGListPropertyHelper() 55 ~SVGListPropertyHelper()
56 { 56 {
57 clear(); 57 clear();
58 } 58 }
59 59
60 // used from Blink C++ code: 60 // used from Blink C++ code:
61 61
62 ItemPropertyType* at(size_t index) 62 ItemPropertyType* at(size_t index)
63 { 63 {
64 ASSERT(index < m_values.size()); 64 ASSERT(index < m_values.size());
65 ASSERT(m_values.at(index)->ownerList() == this); 65 ASSERT(m_values.at(index)->ownerList() == this);
66 return m_values.at(index).get(); 66 return m_values.at(index).get();
67 } 67 }
68 68
69 const ItemPropertyType* at(size_t index) const 69 const ItemPropertyType* at(size_t index) const
70 { 70 {
71 return const_cast<NewSVGListPropertyHelper<Derived, ItemProperty>*>(this )->at(index); 71 return const_cast<SVGListPropertyHelper<Derived, ItemProperty>*>(this)-> at(index);
72 } 72 }
73 73
74 class ConstIterator { 74 class ConstIterator {
75 private: 75 private:
76 typedef typename Vector<RefPtr<ItemPropertyType> >::const_iterator Wrapp edType; 76 typedef typename Vector<RefPtr<ItemPropertyType> >::const_iterator Wrapp edType;
77 77
78 public: 78 public:
79 ConstIterator(WrappedType it) 79 ConstIterator(WrappedType it)
80 : m_it(it) 80 : m_it(it)
81 { 81 {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 protected: 147 protected:
148 void deepCopy(PassRefPtr<Derived>); 148 void deepCopy(PassRefPtr<Derived>);
149 149
150 private: 150 private:
151 inline bool checkIndexBound(size_t, ExceptionState&); 151 inline bool checkIndexBound(size_t, ExceptionState&);
152 bool removeFromOldOwnerListAndAdjustIndex(PassRefPtr<ItemPropertyType>, size _t* indexToModify); 152 bool removeFromOldOwnerListAndAdjustIndex(PassRefPtr<ItemPropertyType>, size _t* indexToModify);
153 size_t findItem(PassRefPtr<ItemPropertyType>); 153 size_t findItem(PassRefPtr<ItemPropertyType>);
154 154
155 Vector<RefPtr<ItemPropertyType> > m_values; 155 Vector<RefPtr<ItemPropertyType> > m_values;
156 156
157 static PassRefPtr<Derived> toDerived(PassRefPtr<NewSVGPropertyBase> passBase ) 157 static PassRefPtr<Derived> toDerived(PassRefPtr<SVGPropertyBase> passBase)
158 { 158 {
159 if (!passBase) 159 if (!passBase)
160 return nullptr; 160 return nullptr;
161 161
162 RefPtr<NewSVGPropertyBase> base = passBase; 162 RefPtr<SVGPropertyBase> base = passBase;
163 ASSERT(base->type() == Derived::classType()); 163 ASSERT(base->type() == Derived::classType());
164 return static_pointer_cast<Derived>(base); 164 return static_pointer_cast<Derived>(base);
165 } 165 }
166 }; 166 };
167 167
168 template<typename Derived, typename ItemProperty> 168 template<typename Derived, typename ItemProperty>
169 bool NewSVGListPropertyHelper<Derived, ItemProperty>::operator==(const Derived& other) const 169 bool SVGListPropertyHelper<Derived, ItemProperty>::operator==(const Derived& oth er) const
170 { 170 {
171 if (length() != other.length()) 171 if (length() != other.length())
172 return false; 172 return false;
173 173
174 size_t size = length(); 174 size_t size = length();
175 for (size_t i = 0; i < size; ++i) { 175 for (size_t i = 0; i < size; ++i) {
176 if (*at(i) != *other.at(i)) 176 if (*at(i) != *other.at(i))
177 return false; 177 return false;
178 } 178 }
179 179
180 return true; 180 return true;
181 } 181 }
182 182
183 template<typename Derived, typename ItemProperty> 183 template<typename Derived, typename ItemProperty>
184 void NewSVGListPropertyHelper<Derived, ItemProperty>::clear() 184 void SVGListPropertyHelper<Derived, ItemProperty>::clear()
185 { 185 {
186 // detach all list items as they are no longer part of this list 186 // detach all list items as they are no longer part of this list
187 typename Vector<RefPtr<ItemPropertyType> >::const_iterator it = m_values.beg in(); 187 typename Vector<RefPtr<ItemPropertyType> >::const_iterator it = m_values.beg in();
188 typename Vector<RefPtr<ItemPropertyType> >::const_iterator itEnd = m_values. end(); 188 typename Vector<RefPtr<ItemPropertyType> >::const_iterator itEnd = m_values. end();
189 for (; it != itEnd; ++it) { 189 for (; it != itEnd; ++it) {
190 ASSERT((*it)->ownerList() == this); 190 ASSERT((*it)->ownerList() == this);
191 (*it)->setOwnerList(0); 191 (*it)->setOwnerList(0);
192 } 192 }
193 193
194 m_values.clear(); 194 m_values.clear();
195 } 195 }
196 196
197 template<typename Derived, typename ItemProperty> 197 template<typename Derived, typename ItemProperty>
198 PassRefPtr<ItemProperty> NewSVGListPropertyHelper<Derived, ItemProperty>::initia lize(PassRefPtr<ItemProperty> passNewItem) 198 PassRefPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty>::initializ e(PassRefPtr<ItemProperty> passNewItem)
199 { 199 {
200 RefPtr<ItemPropertyType> newItem = passNewItem; 200 RefPtr<ItemPropertyType> newItem = passNewItem;
201 201
202 // Spec: If the inserted item is already in a list, it is removed from its p revious list before it is inserted into this list. 202 // Spec: If the inserted item is already in a list, it is removed from its p revious list before it is inserted into this list.
203 removeFromOldOwnerListAndAdjustIndex(newItem, 0); 203 removeFromOldOwnerListAndAdjustIndex(newItem, 0);
204 204
205 // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter. 205 // Spec: Clears all existing current items from the list and re-initializes the list to hold the single item specified by the parameter.
206 clear(); 206 clear();
207 append(newItem); 207 append(newItem);
208 return newItem.release(); 208 return newItem.release();
209 } 209 }
210 210
211 template<typename Derived, typename ItemProperty> 211 template<typename Derived, typename ItemProperty>
212 PassRefPtr<ItemProperty> NewSVGListPropertyHelper<Derived, ItemProperty>::getIte m(size_t index, ExceptionState& exceptionState) 212 PassRefPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty>::getItem(s ize_t index, ExceptionState& exceptionState)
213 { 213 {
214 if (!checkIndexBound(index, exceptionState)) 214 if (!checkIndexBound(index, exceptionState))
215 return nullptr; 215 return nullptr;
216 216
217 ASSERT(index < m_values.size()); 217 ASSERT(index < m_values.size());
218 ASSERT(m_values.at(index)->ownerList() == this); 218 ASSERT(m_values.at(index)->ownerList() == this);
219 return m_values.at(index); 219 return m_values.at(index);
220 } 220 }
221 221
222 template<typename Derived, typename ItemProperty> 222 template<typename Derived, typename ItemProperty>
223 PassRefPtr<ItemProperty> NewSVGListPropertyHelper<Derived, ItemProperty>::insert ItemBefore(PassRefPtr<ItemProperty> passNewItem, size_t index) 223 PassRefPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty>::insertIte mBefore(PassRefPtr<ItemProperty> passNewItem, size_t index)
224 { 224 {
225 // Spec: If the index is greater than or equal to length, then the new item is appended to the end of the list. 225 // Spec: If the index is greater than or equal to length, then the new item is appended to the end of the list.
226 if (index > m_values.size()) 226 if (index > m_values.size())
227 index = m_values.size(); 227 index = m_values.size();
228 228
229 RefPtr<ItemPropertyType> newItem = passNewItem; 229 RefPtr<ItemPropertyType> newItem = passNewItem;
230 230
231 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list. 231 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list.
232 if (!removeFromOldOwnerListAndAdjustIndex(newItem, &index)) { 232 if (!removeFromOldOwnerListAndAdjustIndex(newItem, &index)) {
233 // Inserting the item before itself is a no-op. 233 // Inserting the item before itself is a no-op.
234 return newItem.release(); 234 return newItem.release();
235 } 235 }
236 236
237 // 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 237 // 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
238 // 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. 238 // 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.
239 m_values.insert(index, newItem); 239 m_values.insert(index, newItem);
240 newItem->setOwnerList(this); 240 newItem->setOwnerList(this);
241 241
242 return newItem.release(); 242 return newItem.release();
243 } 243 }
244 244
245 template<typename Derived, typename ItemProperty> 245 template<typename Derived, typename ItemProperty>
246 PassRefPtr<ItemProperty> NewSVGListPropertyHelper<Derived, ItemProperty>::remove Item(size_t index, ExceptionState& exceptionState) 246 PassRefPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty>::removeIte m(size_t index, ExceptionState& exceptionState)
247 { 247 {
248 if (index >= m_values.size()) { 248 if (index >= m_values.size()) {
249 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMaximumBound("index", index, m_values.size())); 249 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMaximumBound("index", index, m_values.size()));
250 return nullptr; 250 return nullptr;
251 } 251 }
252 ASSERT(m_values.at(index)->ownerList() == this); 252 ASSERT(m_values.at(index)->ownerList() == this);
253 RefPtr<ItemPropertyType> oldItem = m_values.at(index); 253 RefPtr<ItemPropertyType> oldItem = m_values.at(index);
254 m_values.remove(index); 254 m_values.remove(index);
255 oldItem->setOwnerList(0); 255 oldItem->setOwnerList(0);
256 return oldItem.release(); 256 return oldItem.release();
257 } 257 }
258 258
259 template<typename Derived, typename ItemProperty> 259 template<typename Derived, typename ItemProperty>
260 PassRefPtr<ItemProperty> NewSVGListPropertyHelper<Derived, ItemProperty>::append Item(PassRefPtr<ItemProperty> passNewItem) 260 PassRefPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty>::appendIte m(PassRefPtr<ItemProperty> passNewItem)
261 { 261 {
262 RefPtr<ItemPropertyType> newItem = passNewItem; 262 RefPtr<ItemPropertyType> newItem = passNewItem;
263 263
264 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list. 264 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list.
265 removeFromOldOwnerListAndAdjustIndex(newItem, 0); 265 removeFromOldOwnerListAndAdjustIndex(newItem, 0);
266 266
267 // Append the value and wrapper at the end of the list. 267 // Append the value and wrapper at the end of the list.
268 append(newItem); 268 append(newItem);
269 269
270 return newItem.release(); 270 return newItem.release();
271 } 271 }
272 272
273 template<typename Derived, typename ItemProperty> 273 template<typename Derived, typename ItemProperty>
274 PassRefPtr<ItemProperty> NewSVGListPropertyHelper<Derived, ItemProperty>::replac eItem(PassRefPtr<ItemProperty> passNewItem, size_t index, ExceptionState& except ionState) 274 PassRefPtr<ItemProperty> SVGListPropertyHelper<Derived, ItemProperty>::replaceIt em(PassRefPtr<ItemProperty> passNewItem, size_t index, ExceptionState& exception State)
275 { 275 {
276 if (!checkIndexBound(index, exceptionState)) 276 if (!checkIndexBound(index, exceptionState))
277 return nullptr; 277 return nullptr;
278 278
279 RefPtr<ItemPropertyType> newItem = passNewItem; 279 RefPtr<ItemPropertyType> newItem = passNewItem;
280 280
281 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list. 281 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list.
282 // Spec: If the item is already in this list, note that the index of the ite m to replace is before the removal of the item. 282 // Spec: If the item is already in this list, note that the index of the ite m to replace is before the removal of the item.
283 if (!removeFromOldOwnerListAndAdjustIndex(newItem, &index)) { 283 if (!removeFromOldOwnerListAndAdjustIndex(newItem, &index)) {
284 // Replacing the item with itself is a no-op. 284 // Replacing the item with itself is a no-op.
(...skipping 10 matching lines...) Expand all
295 RefPtr<ItemPropertyType>& position = m_values[index]; 295 RefPtr<ItemPropertyType>& position = m_values[index];
296 ASSERT(position->ownerList() == this); 296 ASSERT(position->ownerList() == this);
297 position->setOwnerList(0); 297 position->setOwnerList(0);
298 position = newItem; 298 position = newItem;
299 newItem->setOwnerList(this); 299 newItem->setOwnerList(this);
300 300
301 return newItem.release(); 301 return newItem.release();
302 } 302 }
303 303
304 template<typename Derived, typename ItemProperty> 304 template<typename Derived, typename ItemProperty>
305 bool NewSVGListPropertyHelper<Derived, ItemProperty>::checkIndexBound(size_t ind ex, ExceptionState& exceptionState) 305 bool SVGListPropertyHelper<Derived, ItemProperty>::checkIndexBound(size_t index, ExceptionState& exceptionState)
306 { 306 {
307 if (index >= m_values.size()) { 307 if (index >= m_values.size()) {
308 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMaximumBound("index", index, m_values.size())); 308 exceptionState.throwDOMException(IndexSizeError, ExceptionMessages::inde xExceedsMaximumBound("index", index, m_values.size()));
309 return false; 309 return false;
310 } 310 }
311 311
312 return true; 312 return true;
313 } 313 }
314 314
315 template<typename Derived, typename ItemProperty> 315 template<typename Derived, typename ItemProperty>
316 bool NewSVGListPropertyHelper<Derived, ItemProperty>::removeFromOldOwnerListAndA djustIndex(PassRefPtr<ItemPropertyType> passItem, size_t* indexToModify) 316 bool SVGListPropertyHelper<Derived, ItemProperty>::removeFromOldOwnerListAndAdju stIndex(PassRefPtr<ItemPropertyType> passItem, size_t* indexToModify)
317 { 317 {
318 RefPtr<ItemPropertyType> item = passItem; 318 RefPtr<ItemPropertyType> item = passItem;
319 ASSERT(item); 319 ASSERT(item);
320 RefPtr<Derived> ownerList = toDerived(item->ownerList()); 320 RefPtr<Derived> ownerList = toDerived(item->ownerList());
321 if (!ownerList) 321 if (!ownerList)
322 return true; 322 return true;
323 323
324 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list. 324 // Spec: If newItem is already in a list, it is removed from its previous li st before it is inserted into this list.
325 // 'newItem' is already living in another list. If it's not our list, synchr onize the other lists wrappers after the removal. 325 // 'newItem' is already living in another list. If it's not our list, synchr onize the other lists wrappers after the removal.
326 bool livesInOtherList = ownerList.get() != this; 326 bool livesInOtherList = ownerList.get() != this;
(...skipping 14 matching lines...) Expand all
341 size_t& index = *indexToModify; 341 size_t& index = *indexToModify;
342 // Spec: If the item is already in this list, note that the index of the item to (replace|insert before) is before the removal of the item. 342 // Spec: If the item is already in this list, note that the index of the item to (replace|insert before) is before the removal of the item.
343 if (static_cast<size_t>(indexToRemove) < index) 343 if (static_cast<size_t>(indexToRemove) < index)
344 --index; 344 --index;
345 } 345 }
346 346
347 return true; 347 return true;
348 } 348 }
349 349
350 template<typename Derived, typename ItemProperty> 350 template<typename Derived, typename ItemProperty>
351 size_t NewSVGListPropertyHelper<Derived, ItemProperty>::findItem(PassRefPtr<Item PropertyType> item) 351 size_t SVGListPropertyHelper<Derived, ItemProperty>::findItem(PassRefPtr<ItemPro pertyType> item)
352 { 352 {
353 return m_values.find(item); 353 return m_values.find(item);
354 } 354 }
355 355
356 template<typename Derived, typename ItemProperty> 356 template<typename Derived, typename ItemProperty>
357 void NewSVGListPropertyHelper<Derived, ItemProperty>::deepCopy(PassRefPtr<Derive d> passFrom) 357 void SVGListPropertyHelper<Derived, ItemProperty>::deepCopy(PassRefPtr<Derived> passFrom)
358 { 358 {
359 RefPtr<Derived> from = passFrom; 359 RefPtr<Derived> from = passFrom;
360 360
361 clear(); 361 clear();
362 typename Vector<RefPtr<ItemPropertyType> >::const_iterator it = from->m_valu es.begin(); 362 typename Vector<RefPtr<ItemPropertyType> >::const_iterator it = from->m_valu es.begin();
363 typename Vector<RefPtr<ItemPropertyType> >::const_iterator itEnd = from->m_v alues.end(); 363 typename Vector<RefPtr<ItemPropertyType> >::const_iterator itEnd = from->m_v alues.end();
364 for (; it != itEnd; ++it) { 364 for (; it != itEnd; ++it) {
365 append((*it)->clone()); 365 append((*it)->clone());
366 } 366 }
367 } 367 }
368 368
369 } 369 }
370 370
371 #endif // NewSVGListPropertyHelper_h 371 #endif // SVGListPropertyHelper_h
OLDNEW
« no previous file with comments | « Source/core/svg/properties/SVGAnimatedProperty.cpp ('k') | Source/core/svg/properties/SVGListPropertyTearOffHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698