Home | History | Annotate | Download | only in properties
      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 #if ENABLE(SVG)
     24 #include "SVGAnimatedListPropertyTearOff.h"
     25 #include "SVGPathSegList.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)
     39     {
     40         ASSERT(animatedProperty);
     41         return adoptRef(new SVGPathSegListPropertyTearOff(animatedProperty, role, pathSegRole));
     42     }
     43 
     44     int removeItemFromList(const ListItemType& removeItem, bool shouldSynchronizeWrappers)
     45     {
     46         SVGPathSegList& values = m_animatedProperty->values();
     47 
     48         unsigned size = values.size();
     49         for (unsigned i = 0; i < size; ++i) {
     50             ListItemType& item = values.at(i);
     51             if (item != removeItem)
     52                 continue;
     53 
     54             values.remove(i);
     55 
     56             if (shouldSynchronizeWrappers)
     57                 commitChange();
     58 
     59             return i;
     60         }
     61 
     62         return -1;
     63     }
     64 
     65     // SVGList API
     66     void clear(ExceptionCode&);
     67 
     68     unsigned numberOfItems() const
     69     {
     70         SVGPathSegList& values = m_animatedProperty->values();
     71         return Base::numberOfItemsValues(values);
     72     }
     73 
     74     PassListItemType initialize(PassListItemType passNewItem, ExceptionCode& ec)
     75     {
     76         // Not specified, but FF/Opera do it this way, and it's just sane.
     77         if (!passNewItem) {
     78             ec = SVGException::SVG_WRONG_TYPE_ERR;
     79             return 0;
     80         }
     81 
     82         ListItemType newItem = passNewItem;
     83         SVGPathSegList& values = m_animatedProperty->values();
     84         return Base::initializeValues(values, newItem, ec);
     85     }
     86 
     87     PassListItemType getItem(unsigned index, ExceptionCode&);
     88 
     89     PassListItemType insertItemBefore(PassListItemType passNewItem, unsigned index, ExceptionCode& ec)
     90     {
     91         // Not specified, but FF/Opera do it this way, and it's just sane.
     92         if (!passNewItem) {
     93             ec = SVGException::SVG_WRONG_TYPE_ERR;
     94             return 0;
     95         }
     96 
     97         ListItemType newItem = passNewItem;
     98         SVGPathSegList& values = m_animatedProperty->values();
     99         return Base::insertItemBeforeValues(values, newItem, index, ec);
    100     }
    101 
    102     PassListItemType replaceItem(PassListItemType passNewItem, unsigned index, ExceptionCode& ec)
    103     {
    104         // Not specified, but FF/Opera do it this way, and it's just sane.
    105         if (!passNewItem) {
    106             ec = SVGException::SVG_WRONG_TYPE_ERR;
    107             return 0;
    108         }
    109 
    110         ListItemType newItem = passNewItem;
    111         SVGPathSegList& values = m_animatedProperty->values();
    112         return Base::replaceItemValues(values, newItem, index, ec);
    113     }
    114 
    115     PassListItemType removeItem(unsigned index, ExceptionCode&);
    116 
    117     PassListItemType appendItem(PassListItemType passNewItem, ExceptionCode& ec)
    118     {
    119         // Not specified, but FF/Opera do it this way, and it's just sane.
    120         if (!passNewItem) {
    121             ec = SVGException::SVG_WRONG_TYPE_ERR;
    122             return 0;
    123         }
    124 
    125         ListItemType newItem = passNewItem;
    126         SVGPathSegList& values = m_animatedProperty->values();
    127         return Base::appendItemValues(values, newItem, ec);
    128     }
    129 
    130 private:
    131     SVGPathSegListPropertyTearOff(AnimatedListPropertyTearOff* animatedProperty, SVGPropertyRole role, SVGPathSegRole pathSegRole)
    132         : SVGListProperty<SVGPathSegList>(role)
    133         , m_animatedProperty(animatedProperty)
    134         , m_pathSegRole(pathSegRole)
    135     {
    136     }
    137 
    138     SVGPathElement* contextElement() const;
    139 
    140     virtual void commitChange()
    141     {
    142         SVGPathSegList& values = m_animatedProperty->values();
    143         values.commitChange(m_animatedProperty->contextElement());
    144     }
    145 
    146     virtual void processIncomingListItemValue(const ListItemType& newItem, unsigned* indexToModify);
    147     virtual void processIncomingListItemWrapper(RefPtr<ListItemTearOff>&, unsigned*)
    148     {
    149         ASSERT_NOT_REACHED();
    150     }
    151 
    152 private:
    153     RefPtr<AnimatedListPropertyTearOff> m_animatedProperty;
    154     SVGPathSegRole m_pathSegRole;
    155 };
    156 
    157 }
    158 
    159 #endif // ENABLE(SVG)
    160 #endif // SVGListPropertyTearOff_h
    161