blob: 7905cb548e5ffc49f204a39dec501c409ed2fa15 [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:
commit-queue@webkit.orgf0dfc632012-12-02 11:16:33 +000038 ElementRareData(Document*);
morrita@google.comd75075c2011-01-20 01:24:40 +000039 virtual ~ElementRareData();
darin@apple.com929b9072008-12-13 22:53:55 +000040
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +000041 void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
42 PseudoElement* pseudoElement(PseudoId) const;
43
darin@apple.comfaced262009-01-12 07:44:27 +000044 void resetComputedStyle();
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +000045 void resetDynamicRestyleObservations();
alp@webkit.org2122a042008-10-03 12:38:12 +000046
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000047 bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; }
48 void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; }
49
50 bool styleAffectedByEmpty() const { return m_styleAffectedByEmpty; }
51 void setStyleAffectedByEmpty(bool value) { m_styleAffectedByEmpty = value; }
52
53 bool isInCanvasSubtree() const { return m_isInCanvasSubtree; }
54 void setIsInCanvasSubtree(bool value) { m_isInCanvasSubtree = value; }
55
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000056#if ENABLE(FULLSCREEN_API)
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000057 bool containsFullScreenElement() { return m_containsFullScreenElement; }
58 void setContainsFullScreenElement(bool value) { m_containsFullScreenElement = value; }
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000059#endif
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000060
commit-queue@webkit.org86b2dc12012-11-20 04:45:02 +000061#if ENABLE(DIALOG_ELEMENT)
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000062 bool isInTopLayer() const { return m_isInTopLayer; }
63 void setIsInTopLayer(bool value) { m_isInTopLayer = value; }
commit-queue@webkit.org86b2dc12012-11-20 04:45:02 +000064#endif
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000065
66 bool childrenAffectedByHover() const { return m_childrenAffectedByHover; }
67 void setChildrenAffectedByHover(bool value) { m_childrenAffectedByHover = value; }
68 bool childrenAffectedByActive() const { return m_childrenAffectedByActive; }
69 void setChildrenAffectedByActive(bool value) { m_childrenAffectedByActive = value; }
70 bool childrenAffectedByDrag() const { return m_childrenAffectedByDrag; }
71 void setChildrenAffectedByDrag(bool value) { m_childrenAffectedByDrag = value; }
72
73 bool childrenAffectedByFirstChildRules() const { return m_childrenAffectedByFirstChildRules; }
74 void setChildrenAffectedByFirstChildRules(bool value) { m_childrenAffectedByFirstChildRules = value; }
75 bool childrenAffectedByLastChildRules() const { return m_childrenAffectedByLastChildRules; }
76 void setChildrenAffectedByLastChildRules(bool value) { m_childrenAffectedByLastChildRules = value; }
77 bool childrenAffectedByDirectAdjacentRules() const { return m_childrenAffectedByDirectAdjacentRules; }
78 void setChildrenAffectedByDirectAdjacentRules(bool value) { m_childrenAffectedByDirectAdjacentRules = value; }
79 bool childrenAffectedByForwardPositionalRules() const { return m_childrenAffectedByForwardPositionalRules; }
80 void setChildrenAffectedByForwardPositionalRules(bool value) { m_childrenAffectedByForwardPositionalRules = value; }
81 bool childrenAffectedByBackwardPositionalRules() const { return m_childrenAffectedByBackwardPositionalRules; }
82 void setChildrenAffectedByBackwardPositionalRules(bool value) { m_childrenAffectedByBackwardPositionalRules = value; }
83 unsigned childIndex() const { return m_childIndex; }
84 void setChildIndex(unsigned index) { m_childIndex = index; }
darin@apple.com929b9072008-12-13 22:53:55 +000085
loislo@chromium.orgedc22012012-11-02 09:11:19 +000086 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
87
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000088 ElementShadow* shadow() const { return m_shadow.get(); }
89 void setShadow(PassOwnPtr<ElementShadow> shadow) { m_shadow = shadow; }
90
91 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
92 void setAttributeMap(PassOwnPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; }
93
94 RenderStyle* computedStyle() const { return m_computedStyle.get(); }
95 void setComputedStyle(PassRefPtr<RenderStyle> computedStyle) { m_computedStyle = computedStyle; }
96
97 ClassList* classList() const { return m_classList.get(); }
98 void setClassList(PassOwnPtr<ClassList> classList) { m_classList = classList; }
99
100 DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
101 void setDataset(PassOwnPtr<DatasetDOMStringMap> dataset) { m_dataset = dataset; }
102
103 LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; }
104 void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; }
105
106 IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
107 void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
108
109private:
110 // Many fields are in NodeRareData for better packing.
eae@chromium.org5b93f412011-08-15 23:51:21 +0000111 LayoutSize m_minimumSizeForResizing;
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000112 RefPtr<RenderStyle> m_computedStyle;
weinig@apple.com96a2cf92010-06-30 23:15:15 +0000113
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000114 OwnPtr<DatasetDOMStringMap> m_dataset;
commit-queue@webkit.org691d04f2010-10-29 09:32:14 +0000115 OwnPtr<ClassList> m_classList;
morrita@google.com948bd532012-05-07 06:05:42 +0000116 OwnPtr<ElementShadow> m_shadow;
caio.oliveira@openbossa.org26b85d32012-03-08 17:42:28 +0000117 OwnPtr<NamedNodeMap> m_attributeMap;
jer.noble@apple.com366ebb02011-05-30 02:05:30 +0000118
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000119 RefPtr<PseudoElement> m_generatedBefore;
120 RefPtr<PseudoElement> m_generatedAfter;
121
commit-queue@webkit.orgba181c42012-04-02 19:37:59 +0000122 IntSize m_savedLayerScrollOffset;
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000123
124private:
125 void releasePseudoElement(PseudoElement*);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000126};
127
128inline IntSize defaultMinimumSizeForResizing()
129{
eae@chromium.org9717cd82012-11-07 18:33:44 +0000130 return IntSize(LayoutUnit::max(), LayoutUnit::max());
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000131}
132
commit-queue@webkit.orgf0dfc632012-12-02 11:16:33 +0000133inline ElementRareData::ElementRareData(Document* document)
134 : NodeRareData(document)
135 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000136 , m_generatedBefore(0)
137 , m_generatedAfter(0)
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000138{
139}
140
morrita@google.comd75075c2011-01-20 01:24:40 +0000141inline ElementRareData::~ElementRareData()
142{
morrita@google.com948bd532012-05-07 06:05:42 +0000143 ASSERT(!m_shadow);
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000144 ASSERT(!m_generatedBefore);
145 ASSERT(!m_generatedAfter);
146}
147
148inline void ElementRareData::setPseudoElement(PseudoId pseudoId, PassRefPtr<PseudoElement> element)
149{
150 switch (pseudoId) {
151 case BEFORE:
152 releasePseudoElement(m_generatedBefore.get());
153 m_generatedBefore = element;
154 break;
155 case AFTER:
156 releasePseudoElement(m_generatedAfter.get());
157 m_generatedAfter = element;
158 break;
159 default:
160 ASSERT_NOT_REACHED();
161 }
162}
163
164inline PseudoElement* ElementRareData::pseudoElement(PseudoId pseudoId) const
165{
166 switch (pseudoId) {
167 case BEFORE:
168 return m_generatedBefore.get();
169 case AFTER:
170 return m_generatedAfter.get();
171 default:
172 ASSERT_NOT_REACHED();
173 return 0;
174 }
175}
176
177inline void ElementRareData::releasePseudoElement(PseudoElement* element)
178{
179 if (!element)
180 return;
181
182 if (element->attached())
183 element->detach();
184
185 ASSERT(!element->nextSibling());
186 ASSERT(!element->previousSibling());
187
188 element->setParentOrHostNode(0);
morrita@google.comd75075c2011-01-20 01:24:40 +0000189}
190
darin@apple.comfaced262009-01-12 07:44:27 +0000191inline void ElementRareData::resetComputedStyle()
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000192{
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000193 setComputedStyle(0);
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000194 setStyleAffectedByEmpty(false);
195 setChildIndex(0);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000196}
197
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000198inline void ElementRareData::resetDynamicRestyleObservations()
199{
200 setChildrenAffectedByHover(false);
201 setChildrenAffectedByActive(false);
202 setChildrenAffectedByDrag(false);
203 setChildrenAffectedByFirstChildRules(false);
204 setChildrenAffectedByLastChildRules(false);
205 setChildrenAffectedByDirectAdjacentRules(false);
206 setChildrenAffectedByForwardPositionalRules(false);
207 setChildrenAffectedByBackwardPositionalRules(false);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000208}
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000209
210} // namespace
211
alp@webkit.org2122a042008-10-03 12:38:12 +0000212#endif // ElementRareData_h