2 * Copyright (C) 2014 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef SVGPathSegList_h
32 #define SVGPathSegList_h
34 #include "core/svg/SVGPathByteStream.h"
35 #include "core/svg/SVGPathSeg.h"
36 #include "core/svg/properties/SVGAnimatedProperty.h"
37 #include "core/svg/properties/SVGListPropertyHelper.h"
38 #include "wtf/WeakPtr.h"
43 class SVGPathSegListTearOff;
45 class SVGPathSegList : public SVGListPropertyHelper<SVGPathSegList, SVGPathSeg> {
47 typedef void PrimitiveType;
48 typedef SVGPathSeg ItemPropertyType;
49 typedef SVGPathSegListTearOff TearOffType;
50 typedef SVGListPropertyHelper<SVGPathSegList, SVGPathSeg> Base;
52 static PassRefPtr<SVGPathSegList> create(SVGPathElement* contextElement)
54 return adoptRef(new SVGPathSegList(contextElement));
56 static PassRefPtr<SVGPathSegList> create() { ASSERT_NOT_REACHED(); return nullptr; }
58 virtual ~SVGPathSegList();
60 const SVGPathByteStream* byteStream() const;
61 void clearByteStream() { m_byteStream.clear(); }
63 // SVGListPropertyHelper methods with |m_byteStream| sync:
65 ItemPropertyType* at(size_t index)
67 updateListFromByteStream();
68 return Base::at(index);
73 updateListFromByteStream();
74 return Base::length();
79 if (m_listSyncedToByteStream)
80 return Base::isEmpty();
82 return !m_byteStream || m_byteStream->isEmpty();
91 void append(PassRefPtr<ItemPropertyType> passNewItem)
93 updateListFromByteStream();
95 Base::append(passNewItem);
98 PassRefPtr<ItemPropertyType> initialize(PassRefPtr<ItemPropertyType> passItem)
101 return Base::initialize(passItem);
104 PassRefPtr<ItemPropertyType> getItem(size_t index, ExceptionState& exceptionState)
106 updateListFromByteStream();
107 return Base::getItem(index, exceptionState);
110 PassRefPtr<ItemPropertyType> insertItemBefore(PassRefPtr<ItemPropertyType> passItem, size_t index)
112 updateListFromByteStream();
114 return Base::insertItemBefore(passItem, index);
117 PassRefPtr<ItemPropertyType> replaceItem(PassRefPtr<ItemPropertyType> passItem, size_t index, ExceptionState& exceptionState)
119 updateListFromByteStream();
121 return Base::replaceItem(passItem, index, exceptionState);
124 PassRefPtr<ItemPropertyType> removeItem(size_t index, ExceptionState& exceptionState)
126 updateListFromByteStream();
128 return Base::removeItem(index, exceptionState);
131 PassRefPtr<ItemPropertyType> appendItem(PassRefPtr<ItemPropertyType> passItem);
134 virtual PassRefPtr<SVGPropertyBase> cloneForAnimation(const String&) const override;
135 virtual PassRefPtr<SVGPathSegList> clone() override;
136 virtual String valueAsString() const override;
137 void setValueAsString(const String&, ExceptionState&);
139 virtual void add(PassRefPtrWillBeRawPtr<SVGPropertyBase>, SVGElement*) override;
140 virtual void calculateAnimatedValue(SVGAnimationElement*, float percentage, unsigned repeatCount, PassRefPtr<SVGPropertyBase> fromValue, PassRefPtr<SVGPropertyBase> toValue, PassRefPtr<SVGPropertyBase> toAtEndOfDurationValue, SVGElement*) override;
141 virtual float calculateDistance(PassRefPtr<SVGPropertyBase> to, SVGElement*) override;
143 static AnimatedPropertyType classType() { return AnimatedPath; }
146 SVGPathSegList(SVGPathElement*);
147 SVGPathSegList(SVGPathElement*, PassOwnPtr<SVGPathByteStream>);
149 friend class SVGPathSegListBuilder;
150 // This is only to be called from SVGPathSegListBuilder.
151 void appendWithoutByteStreamSync(PassRefPtr<ItemPropertyType> passNewItem)
153 Base::append(passNewItem);
156 void updateListFromByteStream();
157 void invalidateList();
159 // FIXME: This pointer should be removed after SVGPathSeg has a tear-off.
160 // FIXME: oilpan: This is raw-ptr to avoid reference cycles.
161 // SVGPathSegList is either owned by SVGAnimatedPath or
162 // SVGPathSegListTearOff. Both keep |contextElement| alive,
163 // so this ptr is always valid.
164 SVGPathElement* m_contextElement;
166 mutable OwnPtr<SVGPathByteStream> m_byteStream;
167 bool m_listSyncedToByteStream;
170 inline PassRefPtr<SVGPathSegList> toSVGPathSegList(PassRefPtr<SVGPropertyBase> passBase)
172 RefPtr<SVGPropertyBase> base = passBase;
173 ASSERT(base->type() == SVGPathSegList::classType());
174 return static_pointer_cast<SVGPathSegList>(base.release());