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

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

Issue 137433008: Have HTMLCollection::item() return an Element as per specification (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update WebNodeCollection API Created 6 years, 10 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
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 21 matching lines...) Expand all
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(ContainerNode* 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 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); } 41 unsigned length() const { return m_collectionIndexCache.nodeCount(*this); }
42 Node* item(unsigned offset) const { return m_collectionIndexCache.nodeAt(*th is, offset); } 42 Element* item(unsigned offset) const { return m_collectionIndexCache.nodeAt( *this, offset); }
43 virtual Element* namedItem(const AtomicString& name) const; 43 virtual Element* namedItem(const AtomicString& name) const;
44 44
45 // Non-DOM API 45 // Non-DOM API
46 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const; 46 void namedItems(const AtomicString& name, Vector<RefPtr<Element> >&) const;
47 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); } 47 bool isEmpty() const { return m_collectionIndexCache.isEmpty(*this); }
48 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne Node(*this); } 48 bool hasExactlyOneItem() const { return m_collectionIndexCache.hasExactlyOne Node(*this); }
49 49
50 virtual Element* virtualItemAfter(Element*) const; 50 virtual Element* virtualItemAfter(Element*) const;
51 51
52 // CollectionIndexCache API. 52 // CollectionIndexCache API.
53 Element* itemBefore(const Node* previousItem) const;
53 Element* traverseToFirstElement(const ContainerNode& root) const; 54 Element* traverseToFirstElement(const ContainerNode& root) const;
54 Element* traverseForwardToOffset(unsigned offset, Node& currentElement, unsi gned& currentOffset, const ContainerNode& root) const; 55 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, const ContainerNode& root) const;
55 56
56 protected: 57 protected:
57 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType); 58 HTMLCollection(ContainerNode* base, CollectionType, ItemAfterOverrideType);
58 59
59 virtual void updateNameCache() const; 60 virtual void updateNameCache() const;
60 bool hasNameCache() const { return m_isNameCacheValid; } 61 bool hasNameCache() const { return m_isNameCacheValid; }
61 void setHasNameCache() const { m_isNameCacheValid = true; } 62 void setHasNameCache() const { m_isNameCacheValid = true; }
62 63
63 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; 64 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
64 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); } 65 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); }
65 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); } 66 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); }
66 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); } 67 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); }
67 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); } 68 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); }
68 69
69 private: 70 private:
70 bool checkForNameMatch(const Element&, bool checkName, const AtomicString& n ame) const; 71 bool checkForNameMatch(const Element&, bool checkName, const AtomicString& n ame) const;
71 Element* traverseNextElement(Element& previous, const ContainerNode& root) c onst; 72 Element* traverseNextElement(Element& previous, const ContainerNode& root) c onst;
72 73
73 static void append(NodeCacheMap&, const AtomicString&, Element*); 74 static void append(NodeCacheMap&, const AtomicString&, Element*);
74 void invalidateIdNameCacheMaps() const 75 void invalidateIdNameCacheMaps() const
75 { 76 {
76 m_idCache.clear(); 77 m_idCache.clear();
77 m_nameCache.clear(); 78 m_nameCache.clear();
78 m_isNameCacheValid = false; 79 m_isNameCacheValid = false;
79 } 80 }
80 81
81 mutable unsigned m_isNameCacheValid : 1; 82 mutable unsigned m_isNameCacheValid : 1;
82 mutable NodeCacheMap m_idCache; 83 mutable NodeCacheMap m_idCache;
83 mutable NodeCacheMap m_nameCache; 84 mutable NodeCacheMap m_nameCache;
84 mutable CollectionIndexCache<HTMLCollection> m_collectionIndexCache; 85 mutable CollectionIndexCache<HTMLCollection, Element> m_collectionIndexCache ;
85 86
86 friend class LiveNodeListBase; 87 friend class LiveNodeListBase;
87 }; 88 };
88 89
89 } // namespace 90 } // namespace
90 91
91 #endif 92 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698