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 SVGStaticListPropertyTearOff_h 21#define SVGStaticListPropertyTearOff_h 22 23#if ENABLE(SVG) 24#include "SVGListProperty.h" 25 26namespace WebCore { 27 28template<typename PropertyType> 29class SVGStaticListPropertyTearOff : public SVGListProperty<PropertyType> { 30public: 31 typedef SVGListProperty<PropertyType> Base; 32 33 typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType; 34 typedef SVGPropertyTearOff<ListItemType> ListItemTearOff; 35 36 static PassRefPtr<SVGStaticListPropertyTearOff<PropertyType> > create(SVGElement* contextElement, PropertyType& values) 37 { 38 ASSERT(contextElement); 39 return adoptRef(new SVGStaticListPropertyTearOff<PropertyType>(contextElement, values)); 40 } 41 42 // SVGList API 43 void clear(ExceptionCode& ec) 44 { 45 Base::clearValues(m_values, ec); 46 } 47 48 unsigned numberOfItems() const 49 { 50 return Base::numberOfItemsValues(m_values); 51 } 52 53 ListItemType initialize(const ListItemType& newItem, ExceptionCode& ec) 54 { 55 return Base::initializeValues(m_values, newItem, ec); 56 } 57 58 ListItemType getItem(unsigned index, ExceptionCode& ec) 59 { 60 return Base::getItemValues(m_values, index, ec); 61 } 62 63 ListItemType insertItemBefore(const ListItemType& newItem, unsigned index, ExceptionCode& ec) 64 { 65 return Base::insertItemBeforeValues(m_values, newItem, index, ec); 66 } 67 68 ListItemType replaceItem(const ListItemType& newItem, unsigned index, ExceptionCode& ec) 69 { 70 return Base::replaceItemValues(m_values, newItem, index, ec); 71 } 72 73 ListItemType removeItem(unsigned index, ExceptionCode& ec) 74 { 75 return Base::removeItemValues(m_values, index, ec); 76 } 77 78 ListItemType appendItem(const ListItemType& newItem, ExceptionCode& ec) 79 { 80 return Base::appendItemValues(m_values, newItem, ec); 81 } 82 83private: 84 SVGStaticListPropertyTearOff(SVGElement* contextElement, PropertyType& values) 85 : SVGListProperty<PropertyType>(UndefinedRole) 86 , m_contextElement(contextElement) 87 , m_values(values) 88 { 89 } 90 91 virtual void commitChange() 92 { 93 m_values.commitChange(m_contextElement.get()); 94 } 95 96 virtual void processIncomingListItemValue(const ListItemType&, unsigned*) 97 { 98 // no-op for static lists 99 } 100 101 virtual void processIncomingListItemWrapper(RefPtr<ListItemTearOff>&, unsigned*) 102 { 103 ASSERT_NOT_REACHED(); 104 } 105 106private: 107 RefPtr<SVGElement> m_contextElement; 108 PropertyType& m_values; 109}; 110 111} 112 113#endif // ENABLE(SVG) 114#endif // SVGStaticListPropertyTearOff_h 115