109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)/*
209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Copyright (C) 2014 Google Inc. All rights reserved.
309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * modification, are permitted provided that the following conditions are
609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * met:
709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *     * Redistributions of source code must retain the above copyright
909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * notice, this list of conditions and the following disclaimer.
1009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *     * Redistributions in binary form must reproduce the above
1109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
1209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * in the documentation and/or other materials provided with the
1309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * distribution.
1409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
1509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * contributors may be used to endorse or promote products derived from
1609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * this software without specific prior written permission.
1709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) *
1809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) */
3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#ifndef SVGStringListTearOff_h
3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#define SVGStringListTearOff_h
3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
34197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/dom/ExceptionCode.h"
3509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/svg/SVGStringList.h"
3607a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch#include "core/svg/properties/SVGPropertyTearOff.h"
3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
38c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4007a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdochclass SVGStringListTearOff : public SVGPropertyTearOff<SVGStringList>, public ScriptWrappable {
417242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    DEFINE_WRAPPERTYPEINFO();
4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)public:
435d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    static PassRefPtr<SVGStringListTearOff> create(PassRefPtr<SVGStringList> target, SVGElement* contextElement, PropertyIsAnimValType propertyIsAnimVal, const QualifiedName& attributeName = QualifiedName::null())
4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return adoptRef(new SVGStringListTearOff(target, contextElement, propertyIsAnimVal, attributeName));
4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // SVGStringList DOM interface:
4909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // WebIDL requires "unsigned long" type instead of size_t.
51d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    unsigned long length()
5209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
53d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return target()->length();
5409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
5509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
5609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    void clear(ExceptionState& exceptionState)
5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (isImmutable()) {
5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return;
6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        target()->clear();
6409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        commitChange();
6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    String initialize(const String& item, ExceptionState& exceptionState)
6809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
6909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (isImmutable()) {
7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
7109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return String();
7209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
7309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
7409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        target()->initialize(item);
7509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        commitChange();
7609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
7709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return item;
7809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
7909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
8009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    String getItem(unsigned long index, ExceptionState& exceptionState)
8109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
8209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return target()->getItem(index, exceptionState);
8309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    String insertItemBefore(const String& item, unsigned long index, ExceptionState& exceptionState)
8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (isImmutable()) {
8809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
8909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return String();
9009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
9109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
9209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        target()->insertItemBefore(item, index);
9309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        commitChange();
9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return item;
9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
9709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
9809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    String replaceItem(const String& item, unsigned long index, ExceptionState& exceptionState)
9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
10009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (isImmutable()) {
10109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
10209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return String();
10309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
10409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
10509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        target()->replaceItem(item, index, exceptionState);
10609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        commitChange();
10709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
10809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return item;
10909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
11009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
111d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    bool anonymousIndexedSetter(unsigned index, const String& item, ExceptionState& exceptionState)
112d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    {
113d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        replaceItem(item, index, exceptionState);
114d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)        return true;
115d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    }
116d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)
11709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    String removeItem(unsigned long index, ExceptionState& exceptionState)
11809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
11909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (isImmutable()) {
12009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
12109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return String();
12209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
12309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
12409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        String removedItem = target()->removeItem(index, exceptionState);
12509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        commitChange();
12609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
12709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return removedItem;
12809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
12909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
13009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    String appendItem(const String& item, ExceptionState& exceptionState)
13109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    {
13209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        if (isImmutable()) {
13309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            exceptionState.throwDOMException(NoModificationAllowedError, "The object is read-only.");
13409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)            return String();
13509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        }
13609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
13709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        target()->appendItem(item);
13809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        commitChange();
13909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
14009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return item;
14109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    }
14209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
14309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)protected:
14409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    SVGStringListTearOff(PassRefPtr<SVGStringList>, SVGElement*, PropertyIsAnimValType, const QualifiedName&);
14509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)};
14609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
147c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
14809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
1497242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci#endif // SVGStringListTearOff_h
150