1 /* 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef SVGPathSegListPropertyTearOff_h 21 #define SVGPathSegListPropertyTearOff_h 22 23 #include "bindings/v8/ExceptionState.h" 24 #include "core/svg/SVGPathSegList.h" 25 #include "core/svg/properties/SVGAnimatedListPropertyTearOff.h" 26 27 namespace WebCore { 28 29 class SVGPathElement; 30 31 class SVGPathSegListPropertyTearOff : public SVGListProperty<SVGPathSegList> { 32 public: 33 typedef SVGListProperty<SVGPathSegList> Base; 34 typedef SVGAnimatedListPropertyTearOff<SVGPathSegList> AnimatedListPropertyTearOff; 35 typedef SVGPropertyTraits<SVGPathSegList>::ListItemType ListItemType; 36 typedef PassRefPtr<SVGPathSeg> PassListItemType; 37 38 static PassRefPtr<SVGPathSegListPropertyTearOff> create(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role, SVGPathSegRole pathSegRole, SVGPathSegList& values, ListWrapperCache& wrappers) 39 { 40 ASSERT(animatedProperty); 41 return adoptRef(new SVGPathSegListPropertyTearOff(animatedProperty, role, pathSegRole, values, wrappers)); 42 } 43 44 int findItem(const ListItemType& item) const 45 { 46 ASSERT(m_values); 47 48 unsigned size = m_values->size(); 49 for (size_t i = 0; i < size; ++i) { 50 if (item == m_values->at(i)) 51 return i; 52 } 53 54 return -1; 55 } 56 57 void removeItemFromList(size_t itemIndex, bool shouldSynchronizeWrappers) 58 { 59 ASSERT(m_values); 60 ASSERT_WITH_SECURITY_IMPLICATION(itemIndex < m_values->size()); 61 62 m_values->remove(itemIndex); 63 64 if (shouldSynchronizeWrappers) 65 commitChange(); 66 } 67 68 // SVGList API 69 void clear(ExceptionState&); 70 71 PassListItemType initialize(PassListItemType passNewItem, ExceptionState& es) 72 { 73 // Not specified, but FF/Opera do it this way, and it's just sane. 74 if (!passNewItem) { 75 es.throwTypeError(); 76 return 0; 77 } 78 79 clearContextAndRoles(); 80 ListItemType newItem = passNewItem; 81 return Base::initializeValues(newItem, es); 82 } 83 84 PassListItemType getItem(unsigned index, ExceptionState&); 85 86 PassListItemType insertItemBefore(PassListItemType passNewItem, unsigned index, ExceptionState& es) 87 { 88 // Not specified, but FF/Opera do it this way, and it's just sane. 89 if (!passNewItem) { 90 es.throwTypeError(); 91 return 0; 92 } 93 94 ListItemType newItem = passNewItem; 95 return Base::insertItemBeforeValues(newItem, index, es); 96 } 97 98 PassListItemType replaceItem(PassListItemType, unsigned index, ExceptionState&); 99 100 PassListItemType removeItem(unsigned index, ExceptionState&); 101 102 PassListItemType appendItem(PassListItemType passNewItem, ExceptionState& es) 103 { 104 // Not specified, but FF/Opera do it this way, and it's just sane. 105 if (!passNewItem) { 106 es.throwTypeError(); 107 return 0; 108 } 109 110 ListItemType newItem = passNewItem; 111 return Base::appendItemValues(newItem, es); 112 } 113 114 private: 115 SVGPathSegListPropertyTearOff(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role, SVGPathSegRole pathSegRole, SVGPathSegList& values, ListWrapperCache& wrappers) 116 : SVGListProperty<SVGPathSegList>(role, values, &wrappers) 117 , m_animatedProperty(animatedProperty) 118 , m_pathSegRole(pathSegRole) 119 { 120 } 121 122 SVGPathElement* contextElement() const; 123 124 void clearContextAndRoles(); 125 126 using Base::m_role; 127 128 virtual bool isReadOnly() const 129 { 130 if (m_role == AnimValRole) 131 return true; 132 if (m_animatedProperty && m_animatedProperty->isReadOnly()) 133 return true; 134 return false; 135 } 136 137 virtual void commitChange() 138 { 139 ASSERT(m_values); 140 m_values->commitChange(m_animatedProperty->contextElement(), ListModificationUnknown); 141 } 142 143 virtual void commitChange(ListModification listModification) 144 { 145 ASSERT(m_values); 146 m_values->commitChange(m_animatedProperty->contextElement(), listModification); 147 } 148 149 virtual bool processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify) OVERRIDE; 150 virtual bool processIncomingListItemWrapper(RefPtr<ListItemTearOff>&, unsigned*) 151 { 152 ASSERT_NOT_REACHED(); 153 return true; 154 } 155 156 private: 157 RefPtr<AnimatedListPropertyTearOff> m_animatedProperty; 158 SVGPathSegRole m_pathSegRole; 159 }; 160 161 } 162 163 #endif // SVGListPropertyTearOff_h 164