2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / dom / NodeRareData.h
blobacad86c41b79941f671b87bb0c55ff5286104d12
1 /**
3 * Copyright (C) 2008 Apple Computer, Inc.
4 * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef NodeRareData_h
24 #define NodeRareData_h
26 #include "DynamicNodeList.h"
27 #include "StringHash.h"
28 #include <wtf/HashSet.h>
29 #include <wtf/OwnPtr.h>
31 namespace WebCore {
33 struct NodeListsNodeData {
34 typedef HashSet<DynamicNodeList*> NodeListSet;
35 NodeListSet m_listsWithCaches;
37 DynamicNodeList::Caches m_childNodeListCaches;
39 typedef HashMap<String, DynamicNodeList::Caches*> CacheMap;
40 CacheMap m_classNodeListCaches;
41 CacheMap m_nameNodeListCaches;
43 ~NodeListsNodeData()
45 deleteAllValues(m_classNodeListCaches);
46 deleteAllValues(m_nameNodeListCaches);
49 void invalidateCaches();
50 void invalidateCachesThatDependOnAttributes();
51 bool isEmpty() const;
54 class NodeRareData {
55 public:
56 NodeRareData()
57 : m_focused(false)
58 , m_tabIndex(0)
59 , m_tabIndexSetExplicitly(false)
60 , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
64 typedef HashMap<const Node*, NodeRareData*> NodeRareDataMap;
66 static NodeRareDataMap& rareDataMap()
68 static NodeRareDataMap* dataMap = new NodeRareDataMap;
69 return *dataMap;
72 static NodeRareData* rareDataFromMap(const Node* node)
74 return rareDataMap().get(node);
77 void clearNodeLists() { m_nodeLists.clear(); }
78 void setNodeLists(std::auto_ptr<NodeListsNodeData> lists) { m_nodeLists.set(lists.release()); }
79 NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
81 short tabIndex() const { return m_tabIndex; }
82 void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexSetExplicitly = true; }
83 bool tabIndexSetExplicitly() const { return m_tabIndexSetExplicitly; }
85 bool m_focused : 1;
87 private:
88 OwnPtr<NodeListsNodeData> m_nodeLists;
89 short m_tabIndex;
90 bool m_tabIndexSetExplicitly : 1;
91 public:
92 bool m_needsFocusAppearanceUpdateSoonAfterAttach : 1; //for ElementRareData
94 } //namespace
96 #endif