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 ~NodeListsNodeDataNodeListsNodeData48 ~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: NodeRareData()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 rareDataMap()72 static NodeRareDataMap& rareDataMap() 73 { 74 static NodeRareDataMap* dataMap = new NodeRareDataMap; 75 return *dataMap; 76 } 77 rareDataFromMap(const Node * node)78 static NodeRareData* rareDataFromMap(const Node* node) 79 { 80 return rareDataMap().get(node); 81 } 82 clearNodeLists()83 void clearNodeLists() { m_nodeLists.clear(); } setNodeLists(std::auto_ptr<NodeListsNodeData> lists)84 void setNodeLists(std::auto_ptr<NodeListsNodeData> lists) { m_nodeLists.set(lists.release()); } nodeLists()85 NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); } 86 tabIndex()87 short tabIndex() const { return m_tabIndex; } setTabIndexExplicitly(short index)88 void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; } tabIndexSetExplicitly()89 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; } 90 listeners()91 RegisteredEventListenerVector* listeners() { return m_eventListeners.get(); } ensureListeners()92 RegisteredEventListenerVector& ensureListeners() 93 { 94 if (!m_eventListeners) 95 m_eventListeners.set(new RegisteredEventListenerVector); 96 return *m_eventListeners; 97 } 98 isFocused()99 bool isFocused() const { return m_isFocused; } setFocused(bool focused)100 void setFocused(bool focused) { m_isFocused = focused; } 101 102 protected: 103 // for ElementRareData needsFocusAppearanceUpdateSoonAfterAttach()104 bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; } setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs)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 119