]> git.saurik.com Git - iphone-api.git/blob - WebCore/NodeRareData.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / NodeRareData.h
1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22 #ifndef NodeRareData_h
23 #define NodeRareData_h
24
25 #include "DynamicNodeList.h"
26 #include "EventListener.h"
27 #include "RegisteredEventListener.h"
28 #include "StringHash.h"
29 #include "QualifiedName.h"
30 #include <wtf/HashSet.h>
31 #include <wtf/OwnPtr.h>
32
33 namespace WebCore {
34
35 struct NodeListsNodeData {
36 typedef HashSet<DynamicNodeList*> NodeListSet;
37 NodeListSet m_listsWithCaches;
38
39 DynamicNodeList::Caches m_childNodeListCaches;
40
41 typedef HashMap<String, DynamicNodeList::Caches*> CacheMap;
42 CacheMap m_classNodeListCaches;
43 CacheMap m_nameNodeListCaches;
44
45 typedef HashMap<QualifiedName, DynamicNodeList::Caches*> TagCacheMap;
46 TagCacheMap m_tagNodeListCaches;
47
48 ~NodeListsNodeData()
49 {
50 deleteAllValues(m_classNodeListCaches);
51 deleteAllValues(m_nameNodeListCaches);
52 deleteAllValues(m_tagNodeListCaches);
53 }
54
55 void invalidateCaches();
56 void invalidateCachesThatDependOnAttributes();
57 bool isEmpty() const;
58 };
59
60 class NodeRareData {
61 public:
62 NodeRareData()
63 : m_tabIndex(0)
64 , m_tabIndexWasSetExplicitly(false)
65 , m_isFocused(false)
66 , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
67 {
68 }
69
70 typedef HashMap<const Node*, NodeRareData*> NodeRareDataMap;
71
72 static NodeRareDataMap& rareDataMap()
73 {
74 static NodeRareDataMap* dataMap = new NodeRareDataMap;
75 return *dataMap;
76 }
77
78 static NodeRareData* rareDataFromMap(const Node* node)
79 {
80 return rareDataMap().get(node);
81 }
82
83 void clearNodeLists() { m_nodeLists.clear(); }
84 void setNodeLists(std::auto_ptr<NodeListsNodeData> lists) { m_nodeLists.set(lists.release()); }
85 NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
86
87 short tabIndex() const { return m_tabIndex; }
88 void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
89 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
90
91 RegisteredEventListenerVector* listeners() { return m_eventListeners.get(); }
92 RegisteredEventListenerVector& ensureListeners()
93 {
94 if (!m_eventListeners)
95 m_eventListeners.set(new RegisteredEventListenerVector);
96 return *m_eventListeners;
97 }
98
99 bool isFocused() const { return m_isFocused; }
100 void setFocused(bool focused) { m_isFocused = focused; }
101
102 protected:
103 // for ElementRareData
104 bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; }
105 void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; }
106
107 private:
108 OwnPtr<NodeListsNodeData> m_nodeLists;
109 OwnPtr<RegisteredEventListenerVector > m_eventListeners;
110 short m_tabIndex;
111 bool m_tabIndexWasSetExplicitly : 1;
112 bool m_isFocused : 1;
113 bool m_needsFocusAppearanceUpdateSoonAfterAttach : 1;
114 };
115
116 } //namespace
117
118 #endif