| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include <wtf/FastMalloc.h> | 29 #include <wtf/FastMalloc.h> |
| 30 #include <wtf/Forward.h> | 30 #include <wtf/Forward.h> |
| 31 #include <wtf/HashMap.h> | 31 #include <wtf/HashMap.h> |
| 32 #include <wtf/PassOwnPtr.h> | 32 #include <wtf/PassOwnPtr.h> |
| 33 #include <wtf/Vector.h> | 33 #include <wtf/Vector.h> |
| 34 | 34 |
| 35 namespace WebCore { | 35 namespace WebCore { |
| 36 | 36 |
| 37 class HTMLCollection : public LiveNodeListBase { | 37 class HTMLCollection : public LiveNodeListBase { |
| 38 public: | 38 public: |
| 39 static PassRefPtr<HTMLCollection> create(Node* base, CollectionType); | 39 static PassRefPtr<HTMLCollection> create(const Handle<Node>& base, Collectio
nType); |
| 40 virtual ~HTMLCollection(); | 40 virtual ~HTMLCollection(); |
| 41 | 41 |
| 42 // DOM API | 42 // DOM API |
| 43 virtual Result<Node> namedItem(const AtomicString& name) const; | 43 virtual Result<Node> namedItem(const AtomicString& name) const; |
| 44 PassRefPtr<NodeList> tags(const String&); | 44 PassRefPtr<NodeList> tags(const String&); |
| 45 | 45 |
| 46 // Non-DOM API | 46 // Non-DOM API |
| 47 virtual bool hasNamedItem(const AtomicString& name) const; | 47 virtual bool hasNamedItem(const AtomicString& name) const; |
| 48 void namedItems(const AtomicString& name, Vector<Member<Node> >&) const; | 48 void namedItems(const AtomicString& name, Vector<Member<Node> >&) const; |
| 49 bool isEmpty() const | 49 bool isEmpty() const |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 return cachedItem() && !cachedItemOffset() && !item(1); | 62 return cachedItem() && !cachedItemOffset() && !item(1); |
| 63 return item(0) && !item(1); | 63 return item(0) && !item(1); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual Result<Element> virtualItemAfter(unsigned& offsetInArray, const Hand
le<Element>&) const; | 66 virtual Result<Element> virtualItemAfter(unsigned& offsetInArray, const Hand
le<Element>&) const; |
| 67 | 67 |
| 68 Result<Element> traverseFirstElement(unsigned& offsetInArray, const Handle<C
ontainerNode>& root) const; | 68 Result<Element> traverseFirstElement(unsigned& offsetInArray, const Handle<C
ontainerNode>& root) const; |
| 69 Result<Element> traverseForwardToOffset(unsigned offset, const Handle<Elemen
t>& currentElement, unsigned& currentOffset, unsigned& offsetInArray, const Hand
le<ContainerNode>& root) const; | 69 Result<Element> traverseForwardToOffset(unsigned offset, const Handle<Elemen
t>& currentElement, unsigned& currentOffset, unsigned& offsetInArray, const Hand
le<ContainerNode>& root) const; |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 HTMLCollection(Node* base, CollectionType, ItemAfterOverrideType); | 72 HTMLCollection(const Handle<Node>& base, CollectionType, ItemAfterOverrideTy
pe); |
| 73 | 73 |
| 74 virtual void updateNameCache() const; | 74 virtual void updateNameCache() const; |
| 75 | 75 |
| 76 // FIXME(oilpan): Move NodeList to the heap and visit members in NodeCacheMa
p. | 76 // FIXME(oilpan): Move NodeList to the heap and visit members in NodeCacheMa
p. |
| 77 // See more discussion in https://codereview.chromium.org/23005018/ | 77 // See more discussion in https://codereview.chromium.org/23005018/ |
| 78 typedef HashMap<AtomicStringImpl*, OwnPtr<CollectionRoot<Vector<Member<Eleme
nt> > > > > NodeCacheMap; | 78 typedef HashMap<AtomicStringImpl*, OwnPtr<CollectionRoot<Vector<Member<Eleme
nt> > > > > NodeCacheMap; |
| 79 CollectionRoot<Vector<Member<Element> > >* idCache(const AtomicString& name)
const { return m_idCache.get(name.impl()); } | 79 CollectionRoot<Vector<Member<Element> > >* idCache(const AtomicString& name)
const { return m_idCache.get(name.impl()); } |
| 80 CollectionRoot<Vector<Member<Element> > >* nameCache(const AtomicString& nam
e) const { return m_nameCache.get(name.impl()); } | 80 CollectionRoot<Vector<Member<Element> > >* nameCache(const AtomicString& nam
e) const { return m_nameCache.get(name.impl()); } |
| 81 void appendIdCache(const AtomicString& name, const Handle<Element>& element)
const { append(m_idCache, name, element); } | 81 void appendIdCache(const AtomicString& name, const Handle<Element>& element)
const { append(m_idCache, name, element); } |
| 82 void appendNameCache(const AtomicString& name, const Handle<Element>& elemen
t) const { append(m_nameCache, name, element); } | 82 void appendNameCache(const AtomicString& name, const Handle<Element>& elemen
t) const { append(m_nameCache, name, element); } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 bool checkForNameMatch(const Handle<Element>&, bool checkName, const AtomicS
tring& name) const; | 85 bool checkForNameMatch(const Handle<Element>&, bool checkName, const AtomicS
tring& name) const; |
| 86 Result<Element> traverseNextElement(unsigned& offsetInArray, const Handle<El
ement>& previous, const Handle<ContainerNode>& root) const; | 86 Result<Element> traverseNextElement(unsigned& offsetInArray, const Handle<El
ement>& previous, const Handle<ContainerNode>& root) const; |
| 87 | 87 |
| 88 virtual bool isLiveNodeList() const OVERRIDE { ASSERT_NOT_REACHED(); return
true; } | 88 virtual bool isLiveNodeList() const OVERRIDE { ASSERT_NOT_REACHED(); return
true; } |
| 89 | 89 |
| 90 static void append(NodeCacheMap&, const AtomicString&, const Handle<Element>
&); | 90 static void append(NodeCacheMap&, const AtomicString&, const Handle<Element>
&); |
| 91 | 91 |
| 92 mutable NodeCacheMap m_idCache; | 92 mutable NodeCacheMap m_idCache; |
| 93 mutable NodeCacheMap m_nameCache; | 93 mutable NodeCacheMap m_nameCache; |
| 94 mutable unsigned m_cachedElementsArrayOffset; | 94 mutable unsigned m_cachedElementsArrayOffset; |
| 95 | 95 |
| 96 friend class LiveNodeListBase; | 96 friend class LiveNodeListBase; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 #endif | 101 #endif |
| OLD | NEW |