| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef DOMTokenList_h | 25 #ifndef DOMTokenList_h |
| 26 #define DOMTokenList_h | 26 #define DOMTokenList_h |
| 27 | 27 |
| 28 #include "bindings/core/v8/Iterable.h" | 28 #include "bindings/core/v8/Iterable.h" |
| 29 #include "bindings/core/v8/ScriptWrappable.h" | 29 #include "bindings/core/v8/ScriptWrappable.h" |
| 30 #include "core/dom/SpaceSplitString.h" |
| 30 #include "platform/heap/Handle.h" | 31 #include "platform/heap/Handle.h" |
| 31 #include "wtf/Vector.h" | 32 #include "wtf/Vector.h" |
| 32 #include "wtf/text/AtomicString.h" | 33 #include "wtf/text/AtomicString.h" |
| 33 | 34 |
| 34 namespace blink { | 35 namespace blink { |
| 35 | 36 |
| 36 class Element; | 37 class Element; |
| 37 class ExceptionState; | 38 class ExceptionState; |
| 38 | 39 |
| 39 class CORE_EXPORT DOMTokenList : public NoBaseWillBeGarbageCollectedFinalized<DO
MTokenList>, public ScriptWrappable, public ValueIterable<String> { | 40 class CORE_EXPORT DOMTokenListObserver : public WillBeGarbageCollectedMixin { |
| 41 public: |
| 42 // Called when the value property is set, even if the tokens in |
| 43 // the set have not changed. |
| 44 virtual void valueWasSet() = 0; |
| 45 |
| 46 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 47 }; |
| 48 |
| 49 class CORE_EXPORT DOMTokenList : public RefCountedWillBeGarbageCollectedFinalize
d<DOMTokenList>, |
| 50 public ScriptWrappable, public ValueIterable<String> { |
| 40 DEFINE_WRAPPERTYPEINFO(); | 51 DEFINE_WRAPPERTYPEINFO(); |
| 41 USING_FAST_MALLOC_WILL_BE_REMOVED(DOMTokenList); | 52 USING_FAST_MALLOC_WILL_BE_REMOVED(DOMTokenList); |
| 42 WTF_MAKE_NONCOPYABLE(DOMTokenList); | 53 WTF_MAKE_NONCOPYABLE(DOMTokenList); |
| 43 public: | 54 public: |
| 44 DOMTokenList() { } | 55 static PassRefPtrWillBeRawPtr<DOMTokenList> create(DOMTokenListObserver* obs
erver = nullptr) |
| 56 { |
| 57 return adoptRefWillBeNoop(new DOMTokenList(observer)); |
| 58 } |
| 59 |
| 45 virtual ~DOMTokenList() { } | 60 virtual ~DOMTokenList() { } |
| 46 | 61 |
| 47 #if !ENABLE(OILPAN) | 62 virtual unsigned length() const { return m_tokens.size(); } |
| 48 virtual void ref() = 0; | 63 virtual const AtomicString item(unsigned index) const; |
| 49 virtual void deref() = 0; | |
| 50 #endif | |
| 51 | |
| 52 virtual unsigned length() const = 0; | |
| 53 virtual const AtomicString item(unsigned index) const = 0; | |
| 54 | 64 |
| 55 bool contains(const AtomicString&, ExceptionState&) const; | 65 bool contains(const AtomicString&, ExceptionState&) const; |
| 56 virtual void add(const Vector<String>&, ExceptionState&); | 66 virtual void add(const Vector<String>&, ExceptionState&); |
| 57 void add(const AtomicString&, ExceptionState&); | 67 void add(const AtomicString&, ExceptionState&); |
| 58 virtual void remove(const Vector<String>&, ExceptionState&); | 68 virtual void remove(const Vector<String>&, ExceptionState&); |
| 59 void remove(const AtomicString&, ExceptionState&); | 69 void remove(const AtomicString&, ExceptionState&); |
| 60 bool toggle(const AtomicString&, ExceptionState&); | 70 bool toggle(const AtomicString&, ExceptionState&); |
| 61 bool toggle(const AtomicString&, bool force, ExceptionState&); | 71 bool toggle(const AtomicString&, bool force, ExceptionState&); |
| 62 bool supports(const AtomicString&, ExceptionState&); | 72 bool supports(const AtomicString&, ExceptionState&); |
| 63 | 73 |
| 74 virtual const AtomicString& value() const { return m_value; } |
| 75 virtual void setValue(const AtomicString&); |
| 76 |
| 77 const SpaceSplitString& tokens() const { return m_tokens; } |
| 78 void setObserver(DOMTokenListObserver* observer) { m_observer = observer; } |
| 79 |
| 64 const AtomicString& toString() const { return value(); } | 80 const AtomicString& toString() const { return value(); } |
| 65 | 81 |
| 66 virtual Element* element() { return 0; } | 82 virtual Element* element() { return 0; } |
| 67 | 83 |
| 68 DEFINE_INLINE_VIRTUAL_TRACE() { } | 84 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 85 visitor->trace(m_observer); |
| 86 } |
| 69 | 87 |
| 70 protected: | 88 protected: |
| 71 | 89 DOMTokenList(DOMTokenListObserver* observer) |
| 72 virtual const AtomicString& value() const = 0; | 90 : m_observer(observer) |
| 73 virtual void setValue(const AtomicString&) = 0; | 91 { |
| 92 } |
| 74 | 93 |
| 75 virtual void addInternal(const AtomicString&); | 94 virtual void addInternal(const AtomicString&); |
| 76 virtual bool containsInternal(const AtomicString&) const = 0; | 95 virtual bool containsInternal(const AtomicString&) const; |
| 77 virtual void removeInternal(const AtomicString&); | 96 virtual void removeInternal(const AtomicString&); |
| 78 | 97 |
| 79 bool validateToken(const String&, ExceptionState&) const; | 98 bool validateToken(const String&, ExceptionState&) const; |
| 80 bool validateTokens(const Vector<String>&, ExceptionState&) const; | 99 bool validateTokens(const Vector<String>&, ExceptionState&) const; |
| 81 virtual bool validateTokenValue(const AtomicString&, ExceptionState&) const; | 100 virtual bool validateTokenValue(const AtomicString&, ExceptionState&) const; |
| 82 static AtomicString addToken(const AtomicString&, const AtomicString&); | 101 static AtomicString addToken(const AtomicString&, const AtomicString&); |
| 83 static AtomicString addTokens(const AtomicString&, const Vector<String>&); | 102 static AtomicString addTokens(const AtomicString&, const Vector<String>&); |
| 84 static AtomicString removeToken(const AtomicString&, const AtomicString&); | 103 static AtomicString removeToken(const AtomicString&, const AtomicString&); |
| 85 static AtomicString removeTokens(const AtomicString&, const Vector<String>&)
; | 104 static AtomicString removeTokens(const AtomicString&, const Vector<String>&)
; |
| 86 | 105 |
| 87 private: | 106 private: |
| 88 IterationSource* startIteration(ScriptState*, ExceptionState&) override; | 107 IterationSource* startIteration(ScriptState*, ExceptionState&) override; |
| 108 SpaceSplitString m_tokens; |
| 109 AtomicString m_value; |
| 110 RawPtrWillBeWeakMember<DOMTokenListObserver> m_observer; |
| 89 }; | 111 }; |
| 90 | 112 |
| 91 } // namespace blink | 113 } // namespace blink |
| 92 | 114 |
| 93 #endif // DOMTokenList_h | 115 #endif // DOMTokenList_h |
| OLD | NEW |