OLD | NEW |
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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 // This is an implementation of the SVG*List property spec: | 41 // This is an implementation of the SVG*List property spec: |
42 // http://www.w3.org/TR/SVG/single-page.html#types-InterfaceSVGLengthList | 42 // http://www.w3.org/TR/SVG/single-page.html#types-InterfaceSVGLengthList |
43 template<typename Derived, typename ItemProperty> | 43 template<typename Derived, typename ItemProperty> |
44 class NewSVGListPropertyHelper : public NewSVGPropertyBase { | 44 class NewSVGListPropertyHelper : public NewSVGPropertyBase { |
45 public: | 45 public: |
46 typedef ItemProperty ItemPropertyType; | 46 typedef ItemProperty ItemPropertyType; |
47 | 47 |
| 48 NewSVGListPropertyHelper() |
| 49 : NewSVGPropertyBase(Derived::classType()) |
| 50 { |
| 51 } |
| 52 |
48 // used from Blink C++ code: | 53 // used from Blink C++ code: |
49 | 54 |
50 ItemPropertyType* at(size_t index) | 55 ItemPropertyType* at(size_t index) |
51 { | 56 { |
52 ASSERT(index < m_values.size()); | 57 ASSERT(index < m_values.size()); |
53 return m_values.at(index).get(); | 58 return m_values.at(index).get(); |
54 } | 59 } |
55 | 60 |
56 const ItemPropertyType* at(size_t index) const | 61 const ItemPropertyType* at(size_t index) const |
57 { | 62 { |
58 return const_cast<NewSVGListPropertyHelper<Derived, ItemProperty>*>(this
)->at(index); | 63 return const_cast<NewSVGListPropertyHelper<Derived, ItemProperty>*>(this
)->at(index); |
59 } | 64 } |
60 | 65 |
| 66 class ConstIterator { |
| 67 private: |
| 68 typedef typename Vector<RefPtr<ItemPropertyType> >::const_iterator Wrapp
edType; |
| 69 |
| 70 public: |
| 71 ConstIterator(WrappedType it) |
| 72 : m_it(it) |
| 73 { |
| 74 } |
| 75 |
| 76 ConstIterator& operator++() { ++m_it; return *this; } |
| 77 |
| 78 bool operator==(const ConstIterator& o) const { return m_it == o.m_it; } |
| 79 bool operator!=(const ConstIterator& o) const { return m_it != o.m_it; } |
| 80 |
| 81 PassRefPtr<ItemPropertyType> operator*() { return *m_it; } |
| 82 PassRefPtr<ItemPropertyType> operator->() { return *m_it; } |
| 83 |
| 84 private: |
| 85 WrappedType m_it; |
| 86 }; |
| 87 |
| 88 ConstIterator begin() const |
| 89 { |
| 90 return ConstIterator(m_values.begin()); |
| 91 } |
| 92 |
| 93 ConstIterator end() const |
| 94 { |
| 95 return ConstIterator(m_values.end()); |
| 96 } |
| 97 |
61 void append(PassRefPtr<ItemPropertyType> newItem) | 98 void append(PassRefPtr<ItemPropertyType> newItem) |
62 { | 99 { |
63 ASSERT(newItem); | 100 ASSERT(newItem); |
64 m_values.append(newItem); | 101 m_values.append(newItem); |
65 } | 102 } |
66 | 103 |
67 bool operator==(const Derived&) const; | 104 bool operator==(const Derived&) const; |
68 bool operator!=(const Derived& other) const | 105 bool operator!=(const Derived& other) const |
69 { | 106 { |
70 return !(*this == other); | 107 return !(*this == other); |
(...skipping 20 matching lines...) Expand all Loading... |
91 PassRefPtr<ItemPropertyType> getItem(size_t, ExceptionState&); | 128 PassRefPtr<ItemPropertyType> getItem(size_t, ExceptionState&); |
92 PassRefPtr<ItemPropertyType> insertItemBefore(PassRefPtr<ItemPropertyType>,
PassRefPtr<Derived>, size_t); | 129 PassRefPtr<ItemPropertyType> insertItemBefore(PassRefPtr<ItemPropertyType>,
PassRefPtr<Derived>, size_t); |
93 PassRefPtr<ItemPropertyType> removeItem(size_t, ExceptionState&); | 130 PassRefPtr<ItemPropertyType> removeItem(size_t, ExceptionState&); |
94 PassRefPtr<ItemPropertyType> appendItem(PassRefPtr<ItemPropertyType>, PassRe
fPtr<Derived>); | 131 PassRefPtr<ItemPropertyType> appendItem(PassRefPtr<ItemPropertyType>, PassRe
fPtr<Derived>); |
95 PassRefPtr<ItemPropertyType> replaceItem(PassRefPtr<ItemPropertyType>, PassR
efPtr<Derived>, size_t, ExceptionState&); | 132 PassRefPtr<ItemPropertyType> replaceItem(PassRefPtr<ItemPropertyType>, PassR
efPtr<Derived>, size_t, ExceptionState&); |
96 | 133 |
97 protected: | 134 protected: |
98 inline bool checkIndexBound(size_t, ExceptionState&); | 135 inline bool checkIndexBound(size_t, ExceptionState&); |
99 bool removeFromOldOwnerListAndAdjustIndex(PassRefPtr<ItemPropertyType>, Pass
RefPtr<Derived>, size_t* indexToModify); | 136 bool removeFromOldOwnerListAndAdjustIndex(PassRefPtr<ItemPropertyType>, Pass
RefPtr<Derived>, size_t* indexToModify); |
100 size_t findItem(PassRefPtr<ItemPropertyType>); | 137 size_t findItem(PassRefPtr<ItemPropertyType>); |
101 void deepCopy(const Derived&); | 138 void deepCopy(PassRefPtr<Derived>); |
102 | 139 |
103 Vector<RefPtr<ItemPropertyType> > m_values; | 140 Vector<RefPtr<ItemPropertyType> > m_values; |
104 }; | 141 }; |
105 | 142 |
106 template<typename Derived, typename ItemProperty> | 143 template<typename Derived, typename ItemProperty> |
107 bool NewSVGListPropertyHelper<Derived, ItemProperty>::operator==(const Derived&
other) const | 144 bool NewSVGListPropertyHelper<Derived, ItemProperty>::operator==(const Derived&
other) const |
108 { | 145 { |
109 if (numberOfItems() != other.numberOfItems()) | 146 if (numberOfItems() != other.numberOfItems()) |
110 return false; | 147 return false; |
111 | 148 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 return true; | 299 return true; |
263 } | 300 } |
264 | 301 |
265 template<typename Derived, typename ItemProperty> | 302 template<typename Derived, typename ItemProperty> |
266 size_t NewSVGListPropertyHelper<Derived, ItemProperty>::findItem(PassRefPtr<Item
PropertyType> item) | 303 size_t NewSVGListPropertyHelper<Derived, ItemProperty>::findItem(PassRefPtr<Item
PropertyType> item) |
267 { | 304 { |
268 return m_values.find(item); | 305 return m_values.find(item); |
269 } | 306 } |
270 | 307 |
271 template<typename Derived, typename ItemProperty> | 308 template<typename Derived, typename ItemProperty> |
272 void NewSVGListPropertyHelper<Derived, ItemProperty>::deepCopy(const Derived& fr
om) | 309 void NewSVGListPropertyHelper<Derived, ItemProperty>::deepCopy(PassRefPtr<Derive
d> passFrom) |
273 { | 310 { |
| 311 RefPtr<Derived> from = passFrom; |
| 312 |
274 m_values.clear(); | 313 m_values.clear(); |
275 for (size_t i = 0; i < from.m_values.size(); ++i) { | 314 typename Vector<RefPtr<ItemPropertyType> >::const_iterator it = from->m_valu
es.begin(); |
276 m_values.append(from.m_values[i]->clone()); | 315 typename Vector<RefPtr<ItemPropertyType> >::const_iterator itEnd = from->m_v
alues.end(); |
| 316 for (; it != itEnd; ++it) { |
| 317 m_values.append((*it)->clone()); |
277 } | 318 } |
278 } | 319 } |
279 | 320 |
280 } | 321 } |
281 | 322 |
282 #endif // NewSVGListPropertyHelper_h | 323 #endif // NewSVGListPropertyHelper_h |
OLD | NEW |