blob: af135f09bc363590c72e04ebf928f5d3ec0821af [file] [log] [blame]
darin@apple.comfaced262009-01-12 07:44:27 +00001/*
darin@apple.comf5247d12010-06-13 17:29:10 +00002 * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved.
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +00003 * 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 ElementRareData_h
23#define ElementRareData_h
24
commit-queue@webkit.org691d04f2010-10-29 09:32:14 +000025#include "ClassList.h"
weinig@apple.com96a2cf92010-06-30 23:15:15 +000026#include "DatasetDOMStringMap.h"
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000027#include "Element.h"
morrita@google.com948bd532012-05-07 06:05:42 +000028#include "ElementShadow.h"
rniwa@webkit.orgf57f8e02012-07-13 19:48:40 +000029#include "HTMLCollection.h"
caio.oliveira@openbossa.org26b85d32012-03-08 17:42:28 +000030#include "NamedNodeMap.h"
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000031#include "NodeRareData.h"
commit-queue@webkit.orgd0c076d2012-08-22 22:25:59 +000032#include "StyleInheritedData.h"
weinig@apple.com96a2cf92010-06-30 23:15:15 +000033#include <wtf/OwnPtr.h>
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000034
35namespace WebCore {
alp@webkit.org2122a042008-10-03 12:38:12 +000036
rniwa@webkit.org28acc312012-06-29 23:56:42 +000037class HTMLCollection;
38
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000039class ElementRareData : public NodeRareData {
40public:
darin@apple.comfaced262009-01-12 07:44:27 +000041 ElementRareData();
morrita@google.comd75075c2011-01-20 01:24:40 +000042 virtual ~ElementRareData();
darin@apple.com929b9072008-12-13 22:53:55 +000043
darin@apple.comfaced262009-01-12 07:44:27 +000044 void resetComputedStyle();
alp@webkit.org2122a042008-10-03 12:38:12 +000045
darin@apple.com929b9072008-12-13 22:53:55 +000046 using NodeRareData::needsFocusAppearanceUpdateSoonAfterAttach;
47 using NodeRareData::setNeedsFocusAppearanceUpdateSoonAfterAttach;
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000048 using NodeRareData::styleAffectedByEmpty;
49 using NodeRareData::setStyleAffectedByEmpty;
50 using NodeRareData::isInCanvasSubtree;
51 using NodeRareData::setIsInCanvasSubtree;
52#if ENABLE(FULLSCREEN_API)
53 using NodeRareData::containsFullScreenElement;
54 using NodeRareData::setContainsFullScreenElement;
55#endif
darin@apple.com929b9072008-12-13 22:53:55 +000056
kling@webkit.orga3a65e32012-01-01 21:05:42 +000057 bool hasCachedHTMLCollections() const
58 {
59 return m_cachedCollections;
60 }
61
rniwa@webkit.org4823cc12012-07-09 17:40:09 +000062 PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(Element*, CollectionType);
rniwa@webkit.org28acc312012-06-29 23:56:42 +000063 HTMLCollection* cachedHTMLCollection(CollectionType type)
kling@webkit.orga3a65e32012-01-01 21:05:42 +000064 {
65 if (!m_cachedCollections)
rniwa@webkit.org28acc312012-06-29 23:56:42 +000066 return 0;
kling@webkit.orga3a65e32012-01-01 21:05:42 +000067
rniwa@webkit.org4823cc12012-07-09 17:40:09 +000068 return (*m_cachedCollections)[type - FirstNodeCollectionType];
69 }
rniwa@webkit.orgf57f8e02012-07-13 19:48:40 +000070
rniwa@webkit.org4823cc12012-07-09 17:40:09 +000071 void removeCachedHTMLCollection(HTMLCollection* collection, CollectionType type)
72 {
73 ASSERT(m_cachedCollections);
74 ASSERT_UNUSED(collection, (*m_cachedCollections)[type - FirstNodeCollectionType] == collection);
75 (*m_cachedCollections)[type - FirstNodeCollectionType] = 0;
kling@webkit.orga3a65e32012-01-01 21:05:42 +000076 }
77
rniwa@webkit.org198f43c2012-07-13 22:44:46 +000078 void clearHTMLCollectionCaches(const QualifiedName* attrName)
rniwa@webkit.orgf57f8e02012-07-13 19:48:40 +000079 {
80 if (!m_cachedCollections)
81 return;
82
rniwa@webkit.org198f43c2012-07-13 22:44:46 +000083 bool shouldIgnoreType = !attrName || *attrName == HTMLNames::idAttr || *attrName == HTMLNames::nameAttr;
84
rniwa@webkit.orgf57f8e02012-07-13 19:48:40 +000085 for (unsigned i = 0; i < (*m_cachedCollections).size(); i++) {
rniwa@webkit.org198f43c2012-07-13 22:44:46 +000086 if (HTMLCollection* collection = (*m_cachedCollections)[i]) {
87 if (shouldIgnoreType || DynamicNodeListCacheBase::shouldInvalidateTypeOnAttributeChange(collection->invalidationType(), *attrName))
88 collection->invalidateCache();
89 }
rniwa@webkit.orgf57f8e02012-07-13 19:48:40 +000090 }
91 }
92
93 void adoptTreeScope(Document* oldDocument, Document* newDocument)
94 {
95 if (!m_cachedCollections)
96 return;
97
98 for (unsigned i = 0; i < (*m_cachedCollections).size(); i++) {
99 HTMLCollection* collection = (*m_cachedCollections)[i];
100 if (!collection)
101 continue;
102 collection->invalidateCache();
103 if (oldDocument != newDocument) {
104 oldDocument->unregisterNodeListCache(collection);
105 newDocument->registerNodeListCache(collection);
106 }
107 }
108 }
109
loislo@chromium.orgedc22012012-11-02 09:11:19 +0000110 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
111
rniwa@webkit.org4823cc12012-07-09 17:40:09 +0000112 typedef FixedArray<HTMLCollection*, NumNodeCollectionTypes> CachedHTMLCollectionArray;
kling@webkit.orga3a65e32012-01-01 21:05:42 +0000113 OwnPtr<CachedHTMLCollectionArray> m_cachedCollections;
114
eae@chromium.org5b93f412011-08-15 23:51:21 +0000115 LayoutSize m_minimumSizeForResizing;
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000116 RefPtr<RenderStyle> m_computedStyle;
weinig@apple.com96a2cf92010-06-30 23:15:15 +0000117
118 OwnPtr<DatasetDOMStringMap> m_datasetDOMStringMap;
commit-queue@webkit.org691d04f2010-10-29 09:32:14 +0000119 OwnPtr<ClassList> m_classList;
morrita@google.com948bd532012-05-07 06:05:42 +0000120 OwnPtr<ElementShadow> m_shadow;
caio.oliveira@openbossa.org26b85d32012-03-08 17:42:28 +0000121 OwnPtr<NamedNodeMap> m_attributeMap;
jer.noble@apple.com366ebb02011-05-30 02:05:30 +0000122
commit-queue@webkit.orgba181c42012-04-02 19:37:59 +0000123 IntSize m_savedLayerScrollOffset;
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000124};
125
126inline IntSize defaultMinimumSizeForResizing()
127{
eae@chromium.org9717cd82012-11-07 18:33:44 +0000128 return IntSize(LayoutUnit::max(), LayoutUnit::max());
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000129}
130
darin@apple.comfaced262009-01-12 07:44:27 +0000131inline ElementRareData::ElementRareData()
kling@webkit.orgc7b06df2012-10-03 12:55:24 +0000132 : m_minimumSizeForResizing(defaultMinimumSizeForResizing())
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000133{
134}
135
morrita@google.comd75075c2011-01-20 01:24:40 +0000136inline ElementRareData::~ElementRareData()
137{
morrita@google.com948bd532012-05-07 06:05:42 +0000138 ASSERT(!m_shadow);
morrita@google.comd75075c2011-01-20 01:24:40 +0000139}
140
darin@apple.comfaced262009-01-12 07:44:27 +0000141inline void ElementRareData::resetComputedStyle()
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000142{
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000143 m_computedStyle.clear();
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000144}
145
146}
alp@webkit.org2122a042008-10-03 12:38:12 +0000147#endif // ElementRareData_h