| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 David Smith (catfish.man@gmail.com) | 3 * Copyright (C) 2007 David Smith (catfish.man@gmail.com) |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "core/dom/Element.h" | 33 #include "core/dom/Element.h" |
| 34 #include "core/dom/SpaceSplitString.h" | 34 #include "core/dom/SpaceSplitString.h" |
| 35 #include "core/html/HTMLCollection.h" | 35 #include "core/html/HTMLCollection.h" |
| 36 | 36 |
| 37 namespace WebCore { | 37 namespace WebCore { |
| 38 | 38 |
| 39 class ClassCollection FINAL : public HTMLCollection { | 39 class ClassCollection FINAL : public HTMLCollection { |
| 40 public: | 40 public: |
| 41 // classNames argument is an AtomicString because it is common for Elements
to share the same class names. | 41 // classNames argument is an AtomicString because it is common for Elements
to share the same class names. |
| 42 // It is also used to construct a SpaceSplitString (m_classNames) and its co
nstructor requires an AtomicString. | 42 // It is also used to construct a SpaceSplitString (m_classNames) and its co
nstructor requires an AtomicString. |
| 43 static PassRefPtr<ClassCollection> create(ContainerNode& rootNode, Collectio
nType type, const AtomicString& classNames) | 43 static PassRefPtrWillBeRawPtr<ClassCollection> create(ContainerNode& rootNod
e, CollectionType type, const AtomicString& classNames) |
| 44 { | 44 { |
| 45 ASSERT_UNUSED(type, type == ClassCollectionType); | 45 ASSERT_UNUSED(type, type == ClassCollectionType); |
| 46 return adoptRef(new ClassCollection(rootNode, classNames)); | 46 return adoptRefWillBeNoop(new ClassCollection(rootNode, classNames)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual ~ClassCollection(); | 49 virtual ~ClassCollection(); |
| 50 | 50 |
| 51 bool elementMatches(const Element&) const; | 51 bool elementMatches(const Element&) const; |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 ClassCollection(ContainerNode& rootNode, const AtomicString& classNames); | 54 ClassCollection(ContainerNode& rootNode, const AtomicString& classNames); |
| 55 | 55 |
| 56 SpaceSplitString m_classNames; | 56 SpaceSplitString m_classNames; |
| 57 AtomicString m_originalClassNames; | 57 AtomicString m_originalClassNames; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 inline bool ClassCollection::elementMatches(const Element& testElement) const | 60 inline bool ClassCollection::elementMatches(const Element& testElement) const |
| 61 { | 61 { |
| 62 if (!testElement.hasClass()) | 62 if (!testElement.hasClass()) |
| 63 return false; | 63 return false; |
| 64 if (!m_classNames.size()) | 64 if (!m_classNames.size()) |
| 65 return false; | 65 return false; |
| 66 // FIXME: DOM4 allows getElementsByClassName to return non StyledElement. | 66 // FIXME: DOM4 allows getElementsByClassName to return non StyledElement. |
| 67 // https://bugs.webkit.org/show_bug.cgi?id=94718 | 67 // https://bugs.webkit.org/show_bug.cgi?id=94718 |
| 68 if (!testElement.isStyledElement()) | 68 if (!testElement.isStyledElement()) |
| 69 return false; | 69 return false; |
| 70 return testElement.classNames().containsAll(m_classNames); | 70 return testElement.classNames().containsAll(m_classNames); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace WebCore | 73 } // namespace WebCore |
| 74 | 74 |
| 75 #endif // ClassCollection_h | 75 #endif // ClassCollection_h |
| OLD | NEW |