2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * Copyright (C) 2015 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef DOMTokenList_h
27 #define DOMTokenList_h
29 #include <wtf/Optional.h>
30 #include <wtf/Vector.h>
31 #include <wtf/text/AtomicString.h>
37 typedef int ExceptionCode;
40 WTF_MAKE_NONCOPYABLE(DOMTokenList); WTF_MAKE_FAST_ALLOCATED;
42 virtual ~DOMTokenList() { }
44 virtual void ref() = 0;
45 virtual void deref() = 0;
47 unsigned length() const;
48 const AtomicString& item(unsigned index) const;
50 bool contains(const AtomicString&, ExceptionCode&) const;
51 void add(const Vector<String>&, ExceptionCode&);
52 void add(const AtomicString&, ExceptionCode&);
53 void remove(const Vector<String>&, ExceptionCode&);
54 void remove(const AtomicString&, ExceptionCode&);
55 bool toggle(const AtomicString&, ExceptionCode&);
56 bool toggle(const AtomicString&, Optional<bool> force, ExceptionCode&);
58 const AtomicString& toString() const { return value(); }
60 virtual Element* element() const { return nullptr; }
63 DOMTokenList() = default;
64 const AtomicString& value() const;
65 void setValue(const String&);
67 virtual void updateAfterTokenChange() { m_cachedValue = nullAtom; }
70 static bool validateToken(const String&, ExceptionCode&);
71 static bool validateTokens(const String* tokens, size_t length, ExceptionCode&);
72 void addInternal(const String* tokens, size_t length, ExceptionCode&);
73 void removeInternal(const String* tokens, size_t length, ExceptionCode&);
75 Vector<AtomicString> m_tokens;
76 mutable AtomicString m_cachedValue;
79 inline unsigned DOMTokenList::length() const
81 return m_tokens.size();
84 inline const AtomicString& DOMTokenList::item(unsigned index) const
86 return index < m_tokens.size() ? m_tokens[index] : nullAtom;
89 inline bool DOMTokenList::toggle(const AtomicString& token, ExceptionCode& ec)
91 return toggle(token, Nullopt, ec);
94 } // namespace WebCore
96 #endif // DOMTokenList_h