2 * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
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.
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.
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.
22 #ifndef ElementRareData_h
23 #define ElementRareData_h
25 #include "ClassList.h"
26 #include "DatasetDOMStringMap.h"
28 #include "ElementShadow.h"
29 #include "HTMLCollection.h"
30 #include "NamedNodeMap.h"
31 #include "NodeRareData.h"
32 #include <wtf/OwnPtr.h>
38 class ElementRareData : public NodeRareData {
41 virtual ~ElementRareData();
43 void resetComputedStyle();
45 using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
46 using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
48 bool hasCachedHTMLCollections() const
50 return m_cachedCollections;
53 PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(Element*, CollectionType);
54 HTMLCollection* cachedHTMLCollection(CollectionType type)
56 if (!m_cachedCollections)
59 return (*m_cachedCollections)[type - FirstNodeCollectionType];
62 void removeCachedHTMLCollection(HTMLCollection* collection, CollectionType type)
64 ASSERT(m_cachedCollections);
65 ASSERT_UNUSED(collection, (*m_cachedCollections)[type - FirstNodeCollectionType] == collection);
66 (*m_cachedCollections)[type - FirstNodeCollectionType] = 0;
69 void clearHTMLCollectionCaches(const QualifiedName* attrName)
71 if (!m_cachedCollections)
74 bool shouldIgnoreType = !attrName || *attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr;
76 for (unsigned i = 0; i < (*m_cachedCollections).size(); i++) {
77 if (HTMLCollection* collection = (*m_cachedCollections)[i]) {
78 if (shouldIgnoreType || DynamicNodeListCacheBase::shouldInvalidateTypeOnAttributeChange(collection->invalidationType(), *attrName))
79 collection->invalidateCache();
84 void adoptTreeScope(Document* oldDocument, Document* newDocument)
86 if (!m_cachedCollections)
89 for (unsigned i = 0; i < (*m_cachedCollections).size(); i++) {
90 HTMLCollection* collection = (*m_cachedCollections)[i];
93 collection->invalidateCache();
94 if (oldDocument != newDocument) {
95 oldDocument->unregisterNodeListCache(collection);
96 newDocument->registerNodeListCache(collection);
101 typedef FixedArray<HTMLCollection*, NumNodeCollectionTypes> CachedHTMLCollectionArray;
102 OwnPtr<CachedHTMLCollectionArray> m_cachedCollections;
104 LayoutSize m_minimumSizeForResizing;
105 RefPtr<RenderStyle> m_computedStyle;
106 AtomicString m_shadowPseudoId;
108 OwnPtr<DatasetDOMStringMap> m_datasetDOMStringMap;
109 OwnPtr<ClassList> m_classList;
110 OwnPtr<ElementShadow> m_shadow;
111 OwnPtr<NamedNodeMap> m_attributeMap;
113 bool m_styleAffectedByEmpty : 1;
114 bool m_isInCanvasSubtree : 1;
116 IntSize m_savedLayerScrollOffset;
118 #if ENABLE(FULLSCREEN_API)
119 bool m_containsFullScreenElement;
123 inline IntSize defaultMinimumSizeForResizing()
125 return IntSize(MAX_LAYOUT_UNIT, MAX_LAYOUT_UNIT);
128 inline ElementRareData::ElementRareData()
130 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
131 , m_styleAffectedByEmpty(false)
132 , m_isInCanvasSubtree(false)
133 #if ENABLE(FULLSCREEN_API)
134 , m_containsFullScreenElement(false)
139 inline ElementRareData::~ElementRareData()
144 inline void ElementRareData::resetComputedStyle()
146 m_computedStyle.clear();
150 #endif // ElementRareData_h