Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/core/html/HTMLCollection.h

Issue 132923003: Make sure the rootNode of a LiveNodeListBase is always a ContainerNode (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Slightly clearer cast Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 #include "core/dom/LiveNodeList.h" 26 #include "core/dom/LiveNodeList.h"
27 #include "core/html/CollectionType.h" 27 #include "core/html/CollectionType.h"
28 #include "wtf/Forward.h" 28 #include "wtf/Forward.h"
29 #include "wtf/HashMap.h" 29 #include "wtf/HashMap.h"
30 #include "wtf/Vector.h" 30 #include "wtf/Vector.h"
31 31
32 namespace WebCore { 32 namespace WebCore {
33 33
34 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase { 34 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase {
35 public: 35 public:
36 static PassRefPtr<HTMLCollection> create(Node* base, CollectionType); 36 static PassRefPtr<HTMLCollection> create(ContainerNode* base, CollectionType );
37 virtual ~HTMLCollection(); 37 virtual ~HTMLCollection();
38 virtual void invalidateCache() const OVERRIDE; 38 virtual void invalidateCache() const OVERRIDE;
39 39
40 // DOM API 40 // DOM API
41 virtual Node* namedItem(const AtomicString& name) const; 41 virtual Node* namedItem(const AtomicString& name) const;
42 42
43 // Non-DOM API 43 // Non-DOM API
44 void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const; 44 void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const;
45 bool isEmpty() const 45 bool isEmpty() const
46 { 46 {
47 if (isLengthCacheValid()) 47 if (isLengthCacheValid())
48 return !cachedLength(); 48 return !cachedLength();
49 if (isItemCacheValid()) 49 if (isItemCacheValid())
50 return !cachedItem(); 50 return !cachedItem();
51 return !item(0); 51 return !item(0);
52 } 52 }
53 bool hasExactlyOneItem() const 53 bool hasExactlyOneItem() const
54 { 54 {
55 if (isLengthCacheValid()) 55 if (isLengthCacheValid())
56 return cachedLength() == 1; 56 return cachedLength() == 1;
57 if (isItemCacheValid()) 57 if (isItemCacheValid())
58 return cachedItem() && !cachedItemOffset() && !item(1); 58 return cachedItem() && !cachedItemOffset() && !item(1);
59 return item(0) && !item(1); 59 return item(0) && !item(1);
60 } 60 }
61 61
62 virtual Element* virtualItemAfter(Element*) const; 62 virtual Element* virtualItemAfter(Element*) const;
63 63
64 Element* traverseToFirstElement(ContainerNode& root) const; 64 Element* traverseToFirstElement(ContainerNode& root) const;
65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, ContainerNode* root) const; 65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, ContainerNode& root) const;
66 66
67 protected: 67 protected:
68 HTMLCollection(Node* base, CollectionType, ItemAfterOverrideType); 68 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType);
69 69
70 virtual void updateNameCache() const; 70 virtual void updateNameCache() const;
71 bool hasNameCache() const { return m_isNameCacheValid; } 71 bool hasNameCache() const { return m_isNameCacheValid; }
72 void setHasNameCache() const { m_isNameCacheValid = true; } 72 void setHasNameCache() const { m_isNameCacheValid = true; }
73 73
74 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; 74 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
75 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); } 75 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); }
76 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); } 76 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); }
77 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); } 77 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); }
78 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); } 78 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); }
79 79
80 private: 80 private:
81 bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) c onst; 81 bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) c onst;
82 Element* traverseNextElement(Element& previous, ContainerNode* root) const; 82 Element* traverseNextElement(Element& previous, ContainerNode& root) const;
83 83
84 static void append(NodeCacheMap&, const AtomicString&, Element*); 84 static void append(NodeCacheMap&, const AtomicString&, Element*);
85 void invalidateIdNameCacheMaps() const 85 void invalidateIdNameCacheMaps() const
86 { 86 {
87 m_idCache.clear(); 87 m_idCache.clear();
88 m_nameCache.clear(); 88 m_nameCache.clear();
89 m_isNameCacheValid = false; 89 m_isNameCacheValid = false;
90 } 90 }
91 91
92 mutable unsigned m_isNameCacheValid : 1; 92 mutable unsigned m_isNameCacheValid : 1;
93 mutable NodeCacheMap m_idCache; 93 mutable NodeCacheMap m_idCache;
94 mutable NodeCacheMap m_nameCache; 94 mutable NodeCacheMap m_nameCache;
95 95
96 friend class LiveNodeListBase; 96 friend class LiveNodeListBase;
97 }; 97 };
98 98
99 } // namespace 99 } // namespace
100 100
101 #endif 101 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698