blob: 0aa900dd55feef4d5130fd170f827d6ccfd6f5f5 [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"
morrita@google.com948bd532012-05-07 06:05:42 +000027#include "ElementShadow.h"
caio.oliveira@openbossa.org26b85d32012-03-08 17:42:28 +000028#include "NamedNodeMap.h"
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000029#include "NodeRareData.h"
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +000030#include "PseudoElement.h"
commit-queue@webkit.orgd0c076d2012-08-22 22:25:59 +000031#include "StyleInheritedData.h"
weinig@apple.com96a2cf92010-06-30 23:15:15 +000032#include <wtf/OwnPtr.h>
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000033
34namespace WebCore {
alp@webkit.org2122a042008-10-03 12:38:12 +000035
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000036class ElementRareData : public NodeRareData {
37public:
rniwa@webkit.orgfdb7fa22013-01-16 07:36:55 +000038 static PassOwnPtr<ElementRareData> create(RenderObject* renderer) { return adoptPtr(new ElementRareData(renderer)); }
39
rniwa@webkit.orgc311c022013-01-16 05:23:04 +000040 ~ElementRareData();
darin@apple.com929b9072008-12-13 22:53:55 +000041
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +000042 void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
43 PseudoElement* pseudoElement(PseudoId) const;
morrita@google.com98dfec22012-12-14 06:50:52 +000044 bool hasPseudoElements() const { return m_generatedBefore || m_generatedAfter; }
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +000045
darin@apple.comfaced262009-01-12 07:44:27 +000046 void resetComputedStyle();
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +000047 void resetDynamicRestyleObservations();
rniwa@webkit.org2015feb2013-01-14 23:57:39 +000048
49 short tabIndex() const { return m_tabIndex; }
50 void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
51 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
52 void clearTabIndexExplicitly() { m_tabIndex = 0; m_tabIndexWasSetExplicitly = false; }
alp@webkit.org2122a042008-10-03 12:38:12 +000053
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000054 bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; }
55 void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; }
56
57 bool styleAffectedByEmpty() const { return m_styleAffectedByEmpty; }
58 void setStyleAffectedByEmpty(bool value) { m_styleAffectedByEmpty = value; }
59
60 bool isInCanvasSubtree() const { return m_isInCanvasSubtree; }
61 void setIsInCanvasSubtree(bool value) { m_isInCanvasSubtree = value; }
62
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000063#if ENABLE(FULLSCREEN_API)
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000064 bool containsFullScreenElement() { return m_containsFullScreenElement; }
65 void setContainsFullScreenElement(bool value) { m_containsFullScreenElement = value; }
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000066#endif
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000067
commit-queue@webkit.org80403142013-01-23 18:25:06 +000068#if ENABLE(DIALOG_ELEMENT)
69 bool isInTopLayer() const { return m_isInTopLayer; }
70 void setIsInTopLayer(bool value) { m_isInTopLayer = value; }
71#endif
72
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000073 bool childrenAffectedByHover() const { return m_childrenAffectedByHover; }
74 void setChildrenAffectedByHover(bool value) { m_childrenAffectedByHover = value; }
75 bool childrenAffectedByActive() const { return m_childrenAffectedByActive; }
76 void setChildrenAffectedByActive(bool value) { m_childrenAffectedByActive = value; }
77 bool childrenAffectedByDrag() const { return m_childrenAffectedByDrag; }
78 void setChildrenAffectedByDrag(bool value) { m_childrenAffectedByDrag = value; }
79
80 bool childrenAffectedByFirstChildRules() const { return m_childrenAffectedByFirstChildRules; }
81 void setChildrenAffectedByFirstChildRules(bool value) { m_childrenAffectedByFirstChildRules = value; }
82 bool childrenAffectedByLastChildRules() const { return m_childrenAffectedByLastChildRules; }
83 void setChildrenAffectedByLastChildRules(bool value) { m_childrenAffectedByLastChildRules = value; }
84 bool childrenAffectedByDirectAdjacentRules() const { return m_childrenAffectedByDirectAdjacentRules; }
85 void setChildrenAffectedByDirectAdjacentRules(bool value) { m_childrenAffectedByDirectAdjacentRules = value; }
86 bool childrenAffectedByForwardPositionalRules() const { return m_childrenAffectedByForwardPositionalRules; }
87 void setChildrenAffectedByForwardPositionalRules(bool value) { m_childrenAffectedByForwardPositionalRules = value; }
88 bool childrenAffectedByBackwardPositionalRules() const { return m_childrenAffectedByBackwardPositionalRules; }
89 void setChildrenAffectedByBackwardPositionalRules(bool value) { m_childrenAffectedByBackwardPositionalRules = value; }
90 unsigned childIndex() const { return m_childIndex; }
91 void setChildIndex(unsigned index) { m_childIndex = index; }
darin@apple.com929b9072008-12-13 22:53:55 +000092
rniwa@webkit.orgc311c022013-01-16 05:23:04 +000093 // Manually called by Node::reportMemoryUsage.
94 void reportMemoryUsage(MemoryObjectInfo*) const;
loislo@chromium.orgedc22012012-11-02 09:11:19 +000095
esprehn@chromium.orgc5b45222013-01-29 18:22:03 +000096 void clearShadow() { m_shadow = nullptr; }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000097 ElementShadow* shadow() const { return m_shadow.get(); }
esprehn@chromium.orgc5b45222013-01-29 18:22:03 +000098 ElementShadow* ensureShadow()
99 {
100 if (!m_shadow)
101 m_shadow = ElementShadow::create();
102 return m_shadow.get();
103 }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000104
105 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
106 void setAttributeMap(PassOwnPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; }
107
108 RenderStyle* computedStyle() const { return m_computedStyle.get(); }
109 void setComputedStyle(PassRefPtr<RenderStyle> computedStyle) { m_computedStyle = computedStyle; }
110
111 ClassList* classList() const { return m_classList.get(); }
112 void setClassList(PassOwnPtr<ClassList> classList) { m_classList = classList; }
esprehn@chromium.orgfbc22e52013-01-03 02:59:32 +0000113 void clearClassListValueForQuirksMode()
114 {
115 if (!m_classList)
116 return;
117 m_classList->clearValueForQuirksMode();
118 }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000119
120 DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
121 void setDataset(PassOwnPtr<DatasetDOMStringMap> dataset) { m_dataset = dataset; }
122
123 LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; }
124 void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; }
125
126 IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
127 void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
128
senorblanco@chromium.org7b6792b2013-01-04 19:48:10 +0000129#if ENABLE(SVG)
130 bool hasPendingResources() const { return m_hasPendingResources; }
131 void setHasPendingResources(bool has) { m_hasPendingResources = has; }
132#endif
133
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000134private:
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000135 short m_tabIndex;
136 unsigned short m_childIndex;
137 unsigned m_tabIndexWasSetExplicitly : 1;
138 unsigned m_needsFocusAppearanceUpdateSoonAfterAttach : 1;
139 unsigned m_styleAffectedByEmpty : 1;
140 unsigned m_isInCanvasSubtree : 1;
141#if ENABLE(FULLSCREEN_API)
142 unsigned m_containsFullScreenElement : 1;
143#endif
commit-queue@webkit.org80403142013-01-23 18:25:06 +0000144#if ENABLE(DIALOG_ELEMENT)
145 unsigned m_isInTopLayer : 1;
146#endif
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000147#if ENABLE(SVG)
148 unsigned m_hasPendingResources : 1;
149#endif
150 unsigned m_childrenAffectedByHover : 1;
151 unsigned m_childrenAffectedByActive : 1;
152 unsigned m_childrenAffectedByDrag : 1;
153 // Bits for dynamic child matching.
154 // We optimize for :first-child and :last-child. The other positional child selectors like nth-child or
155 // *-child-of-type, we will just give up and re-evaluate whenever children change at all.
156 unsigned m_childrenAffectedByFirstChildRules : 1;
157 unsigned m_childrenAffectedByLastChildRules : 1;
158 unsigned m_childrenAffectedByDirectAdjacentRules : 1;
159 unsigned m_childrenAffectedByForwardPositionalRules : 1;
160 unsigned m_childrenAffectedByBackwardPositionalRules : 1;
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000161
eae@chromium.org5b93f412011-08-15 23:51:21 +0000162 LayoutSize m_minimumSizeForResizing;
rniwa@webkit.orgc311c022013-01-16 05:23:04 +0000163 IntSize m_savedLayerScrollOffset;
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000164 RefPtr<RenderStyle> m_computedStyle;
weinig@apple.com96a2cf92010-06-30 23:15:15 +0000165
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000166 OwnPtr<DatasetDOMStringMap> m_dataset;
commit-queue@webkit.org691d04f2010-10-29 09:32:14 +0000167 OwnPtr<ClassList> m_classList;
morrita@google.com948bd532012-05-07 06:05:42 +0000168 OwnPtr<ElementShadow> m_shadow;
caio.oliveira@openbossa.org26b85d32012-03-08 17:42:28 +0000169 OwnPtr<NamedNodeMap> m_attributeMap;
jer.noble@apple.com366ebb02011-05-30 02:05:30 +0000170
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000171 RefPtr<PseudoElement> m_generatedBefore;
172 RefPtr<PseudoElement> m_generatedAfter;
173
rniwa@webkit.orgfdb7fa22013-01-16 07:36:55 +0000174 ElementRareData(RenderObject*);
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000175 void releasePseudoElement(PseudoElement*);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000176};
177
178inline IntSize defaultMinimumSizeForResizing()
179{
eae@chromium.org9717cd82012-11-07 18:33:44 +0000180 return IntSize(LayoutUnit::max(), LayoutUnit::max());
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000181}
182
rniwa@webkit.orgfdb7fa22013-01-16 07:36:55 +0000183inline ElementRareData::ElementRareData(RenderObject* renderer)
184 : NodeRareData(renderer)
185 , m_tabIndex(0)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000186 , m_childIndex(0)
187 , m_tabIndexWasSetExplicitly(false)
188 , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
189 , m_styleAffectedByEmpty(false)
190 , m_isInCanvasSubtree(false)
191#if ENABLE(FULLSCREEN_API)
192 , m_containsFullScreenElement(false)
193#endif
commit-queue@webkit.org80403142013-01-23 18:25:06 +0000194#if ENABLE(DIALOG_ELEMENT)
195 , m_isInTopLayer(false)
196#endif
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000197#if ENABLE(SVG)
198 , m_hasPendingResources(false)
199#endif
200 , m_childrenAffectedByHover(false)
201 , m_childrenAffectedByActive(false)
202 , m_childrenAffectedByDrag(false)
203 , m_childrenAffectedByFirstChildRules(false)
204 , m_childrenAffectedByLastChildRules(false)
205 , m_childrenAffectedByDirectAdjacentRules(false)
206 , m_childrenAffectedByForwardPositionalRules(false)
207 , m_childrenAffectedByBackwardPositionalRules(false)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000208 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000209{
210}
211
morrita@google.comd75075c2011-01-20 01:24:40 +0000212inline ElementRareData::~ElementRareData()
213{
morrita@google.com948bd532012-05-07 06:05:42 +0000214 ASSERT(!m_shadow);
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000215 ASSERT(!m_generatedBefore);
216 ASSERT(!m_generatedAfter);
217}
218
219inline void ElementRareData::setPseudoElement(PseudoId pseudoId, PassRefPtr<PseudoElement> element)
220{
221 switch (pseudoId) {
222 case BEFORE:
223 releasePseudoElement(m_generatedBefore.get());
224 m_generatedBefore = element;
225 break;
226 case AFTER:
227 releasePseudoElement(m_generatedAfter.get());
228 m_generatedAfter = element;
229 break;
230 default:
231 ASSERT_NOT_REACHED();
232 }
233}
234
235inline PseudoElement* ElementRareData::pseudoElement(PseudoId pseudoId) const
236{
237 switch (pseudoId) {
238 case BEFORE:
239 return m_generatedBefore.get();
240 case AFTER:
241 return m_generatedAfter.get();
242 default:
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000243 return 0;
244 }
245}
246
247inline void ElementRareData::releasePseudoElement(PseudoElement* element)
248{
249 if (!element)
250 return;
251
252 if (element->attached())
253 element->detach();
254
255 ASSERT(!element->nextSibling());
256 ASSERT(!element->previousSibling());
257
commit-queue@webkit.org632b5322013-02-01 03:17:19 +0000258 element->setParentOrShadowHostNode(0);
morrita@google.comd75075c2011-01-20 01:24:40 +0000259}
260
darin@apple.comfaced262009-01-12 07:44:27 +0000261inline void ElementRareData::resetComputedStyle()
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000262{
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000263 setComputedStyle(0);
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000264 setStyleAffectedByEmpty(false);
265 setChildIndex(0);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000266}
267
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000268inline void ElementRareData::resetDynamicRestyleObservations()
269{
270 setChildrenAffectedByHover(false);
271 setChildrenAffectedByActive(false);
272 setChildrenAffectedByDrag(false);
273 setChildrenAffectedByFirstChildRules(false);
274 setChildrenAffectedByLastChildRules(false);
275 setChildrenAffectedByDirectAdjacentRules(false);
276 setChildrenAffectedByForwardPositionalRules(false);
277 setChildrenAffectedByBackwardPositionalRules(false);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000278}
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000279
280} // namespace
281
alp@webkit.org2122a042008-10-03 12:38:12 +0000282#endif // ElementRareData_h