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/PassOwnPtr.h> 32 #include <wtf/OwnPtr.h> 33 34 namespace WebCore { 35 36 struct NodeListsNodeData { 37 typedef HashSet<DynamicNodeList*> NodeListSet; 38 NodeListSet m_listsWithCaches; 39 40 RefPtr<DynamicNodeList::Caches> m_childNodeListCaches; 41 42 typedef HashMap<String, RefPtr<DynamicNodeList::Caches> > CacheMap; 43 CacheMap m_classNodeListCaches; 44 CacheMap m_nameNodeListCaches; 45 46 typedef HashMap<QualifiedName, RefPtr<DynamicNodeList::Caches> > TagCacheMap; 47 TagCacheMap m_tagNodeListCaches; 48 createNodeListsNodeData49 static PassOwnPtr<NodeListsNodeData> create() 50 { 51 return new NodeListsNodeData; 52 } 53 54 void invalidateCaches(); 55 void invalidateCachesThatDependOnAttributes(); 56 bool isEmpty() const; 57 58 private: NodeListsNodeDataNodeListsNodeData59 NodeListsNodeData() 60 : m_childNodeListCaches(DynamicNodeList::Caches::create()) 61 { 62 } 63 }; 64 65 class NodeRareData { 66 public: NodeRareData()67 NodeRareData() 68 : m_tabIndex(0) 69 , m_tabIndexWasSetExplicitly(false) 70 , m_isFocused(false) 71 , m_needsFocusAppearanceUpdateSoonAfterAttach(false) 72 { 73 } 74 75 typedef HashMap<const Node*, NodeRareData*> NodeRareDataMap; 76 rareDataMap()77 static NodeRareDataMap& rareDataMap() 78 { 79 static NodeRareDataMap* dataMap = new NodeRareDataMap; 80 return *dataMap; 81 } 82 rareDataFromMap(const Node * node)83 static NodeRareData* rareDataFromMap(const Node* node) 84 { 85 return rareDataMap().get(node); 86 } 87 clearNodeLists()88 void clearNodeLists() { m_nodeLists.clear(); } setNodeLists(PassOwnPtr<NodeListsNodeData> lists)89 void setNodeLists(PassOwnPtr<NodeListsNodeData> lists) { m_nodeLists = lists; } nodeLists()90 NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); } 91 tabIndex()92 short tabIndex() const { return m_tabIndex; } setTabIndexExplicitly(short index)93 void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; } tabIndexSetExplicitly()94 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; } 95 listeners()96 RegisteredEventListenerVector* listeners() { return m_eventListeners.get(); } ensureListeners()97 RegisteredEventListenerVector& ensureListeners() 98 { 99 if (!m_eventListeners) 100 m_eventListeners.set(new RegisteredEventListenerVector); 101 return *m_eventListeners; 102 } 103 isFocused()104 bool isFocused() const { return m_isFocused; } setFocused(bool focused)105 void setFocused(bool focused) { m_isFocused = focused; } 106 107 protected: 108 // for ElementRareData needsFocusAppearanceUpdateSoonAfterAttach()109 bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; } setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs)110 void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; } 111 112 private: 113 OwnPtr<NodeListsNodeData> m_nodeLists; 114 OwnPtr<RegisteredEventListenerVector > m_eventListeners; 115 short m_tabIndex; 116 bool m_tabIndexWasSetExplicitly : 1; 117 bool m_isFocused : 1; 118 bool m_needsFocusAppearanceUpdateSoonAfterAttach : 1; 119 }; 120 121 } //namespace 122 123 #endif 124