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