weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 1 | /* |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 2 | * Copyright (C) 2007, 2014, 2015 Apple Inc. All rights reserved. |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 3 | * Copyright (C) 2007 David Smith (catfish.man@gmail.com) |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 14 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 15 | * its contributors may be used to endorse or promote products derived |
| 16 | * from this software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
commit-queue@webkit.org | d862d77 | 2016-10-31 22:07:53 +0000 | [diff] [blame] | 30 | #pragma once |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 31 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 32 | #include "CachedHTMLCollection.h" |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 33 | #include "Element.h" |
japhet@chromium.org | 8e9f23f | 2009-12-09 17:43:16 +0000 | [diff] [blame] | 34 | #include "SpaceSplitString.h" |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 35 | |
| 36 | namespace WebCore { |
| 37 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 38 | class ClassCollection final : public CachedHTMLCollection<ClassCollection, CollectionTypeTraits<ByClass>::traversalType> { |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 39 | public: |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 40 | static Ref<ClassCollection> create(ContainerNode&, CollectionType, const AtomicString& classNames); |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 41 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 42 | virtual ~ClassCollection(); |
eric@webkit.org | 433116c | 2010-04-29 18:02:47 +0000 | [diff] [blame] | 43 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 44 | bool elementMatches(Element&) const; |
darin@apple.com | 642f500 | 2008-06-07 22:51:37 +0000 | [diff] [blame] | 45 | |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 46 | private: |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 47 | ClassCollection(ContainerNode& rootNode, CollectionType, const AtomicString& classNames); |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 48 | |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 49 | SpaceSplitString m_classNames; |
cdumez@apple.com | 0f20661 | 2014-09-16 04:09:58 +0000 | [diff] [blame] | 50 | AtomicString m_originalClassNames; |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 53 | inline ClassCollection::ClassCollection(ContainerNode& rootNode, CollectionType type, const AtomicString& classNames) |
| 54 | : CachedHTMLCollection<ClassCollection, CollectionTypeTraits<ByClass>::traversalType>(rootNode, type) |
| 55 | , m_classNames(classNames, rootNode.document().inQuirksMode()) |
cdumez@apple.com | 0f20661 | 2014-09-16 04:09:58 +0000 | [diff] [blame] | 56 | , m_originalClassNames(classNames) |
| 57 | { |
| 58 | } |
| 59 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 60 | inline bool ClassCollection::elementMatches(Element& element) const |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 61 | { |
cdumez@apple.com | 2102270 | 2014-09-18 16:32:41 +0000 | [diff] [blame] | 62 | if (!element.hasClass()) |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 63 | return false; |
cdumez@apple.com | ac8fffa | 2016-08-16 22:26:40 +0000 | [diff] [blame] | 64 | if (m_classNames.isEmpty()) |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 65 | return false; |
cdumez@apple.com | 2102270 | 2014-09-18 16:32:41 +0000 | [diff] [blame] | 66 | return element.classNames().containsAll(m_classNames); |
antti@apple.com | 59718f5 | 2012-12-19 22:39:28 +0000 | [diff] [blame] | 67 | } |
weinig@apple.com | 1bed3cb | 2007-12-14 21:48:20 +0000 | [diff] [blame] | 68 | |
| 69 | } // namespace WebCore |
| 70 | |
cdumez@apple.com | 406f150 | 2015-08-21 02:10:29 +0000 | [diff] [blame] | 71 | SPECIALIZE_TYPE_TRAITS_HTMLCOLLECTION(ClassCollection, ByClass) |