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 "core/animation/ElementAnimations.h"
26 #include "core/dom/Attr.h"
27 #include "core/dom/DatasetDOMStringMap.h"
28 #include "core/dom/NamedNodeMap.h"
29 #include "core/dom/NodeRareData.h"
30 #include "core/dom/PseudoElement.h"
31 #include "core/dom/custom/CustomElementDefinition.h"
32 #include "core/dom/shadow/ElementShadow.h"
33 #include "core/html/ClassList.h"
34 #include "core/style/StyleInheritedData.h"
35 #include "platform/heap/Handle.h"
36 #include "wtf/OwnPtr.h"
42 class ElementRareData
: public NodeRareData
{
44 static ElementRareData
* create(LayoutObject
* layoutObject
)
46 return new ElementRareData(layoutObject
);
51 void setPseudoElement(PseudoId
, PassRefPtrWillBeRawPtr
<PseudoElement
>);
52 PseudoElement
* pseudoElement(PseudoId
) const;
54 short tabIndex() const { return m_tabindex
; }
56 void setTabIndexExplicitly(short index
)
59 setElementFlag(TabIndexWasSetExplicitly
, true);
62 void clearTabIndexExplicitly()
65 clearElementFlag(TabIndexWasSetExplicitly
);
68 CSSStyleDeclaration
& ensureInlineCSSStyleDeclaration(Element
* ownerElement
);
70 void clearShadow() { m_shadow
= nullptr; }
71 ElementShadow
* shadow() const { return m_shadow
.get(); }
72 ElementShadow
& ensureShadow()
75 m_shadow
= ElementShadow::create();
79 NamedNodeMap
* attributeMap() const { return m_attributeMap
.get(); }
80 void setAttributeMap(PassOwnPtrWillBeRawPtr
<NamedNodeMap
> attributeMap
) { m_attributeMap
= attributeMap
; }
82 ComputedStyle
* ensureComputedStyle() const { return m_computedStyle
.get(); }
83 void setComputedStyle(PassRefPtr
<ComputedStyle
> computedStyle
) { m_computedStyle
= computedStyle
; }
84 void clearComputedStyle() { m_computedStyle
= nullptr; }
86 ClassList
* classList() const { return m_classList
.get(); }
87 void setClassList(PassOwnPtrWillBeRawPtr
<ClassList
> classList
) { m_classList
= classList
; }
88 void clearClassListValueForQuirksMode()
92 m_classList
->clearValueForQuirksMode();
95 DatasetDOMStringMap
* dataset() const { return m_dataset
.get(); }
96 void setDataset(PassOwnPtrWillBeRawPtr
<DatasetDOMStringMap
> dataset
) { m_dataset
= dataset
; }
98 LayoutSize
minimumSizeForResizing() const { return m_minimumSizeForResizing
; }
99 void setMinimumSizeForResizing(LayoutSize size
) { m_minimumSizeForResizing
= size
; }
101 IntSize
savedLayerScrollOffset() const { return m_savedLayerScrollOffset
; }
102 void setSavedLayerScrollOffset(IntSize size
) { m_savedLayerScrollOffset
= size
; }
104 ElementAnimations
* elementAnimations() { return m_elementAnimations
.get(); }
105 void setElementAnimations(ElementAnimations
* elementAnimations
)
107 m_elementAnimations
= elementAnimations
;
110 bool hasPseudoElements() const;
111 void clearPseudoElements();
113 uint32_t incrementProxyCount() { return ++m_proxyCount
; }
114 uint32_t decrementProxyCount()
116 ASSERT(m_proxyCount
);
117 return --m_proxyCount
;
119 uint32_t proxyCount() const { return m_proxyCount
; }
121 void setCustomElementDefinition(PassRefPtrWillBeRawPtr
<CustomElementDefinition
> definition
) { m_customElementDefinition
= definition
; }
122 CustomElementDefinition
* customElementDefinition() const { return m_customElementDefinition
.get(); }
124 AttrNodeList
& ensureAttrNodeList();
125 AttrNodeList
* attrNodeList() { return m_attrNodeList
.get(); }
126 void removeAttrNodeList() { m_attrNodeList
.clear(); }
128 DECLARE_TRACE_AFTER_DISPATCH();
132 // As m_proxyCount usually doesn't exceed 10bits (1024), if you want to add some booleans you
133 // can steal some bits from m_proxyCount by using bitfields to prevent ElementRareData bloat.
134 unsigned short m_proxyCount
;
136 LayoutSize m_minimumSizeForResizing
;
137 IntSize m_savedLayerScrollOffset
;
139 OwnPtrWillBeMember
<DatasetDOMStringMap
> m_dataset
;
140 OwnPtrWillBeMember
<ClassList
> m_classList
;
141 OwnPtrWillBeMember
<ElementShadow
> m_shadow
;
142 OwnPtrWillBeMember
<NamedNodeMap
> m_attributeMap
;
143 OwnPtrWillBeMember
<AttrNodeList
> m_attrNodeList
;
144 PersistentWillBeMember
<ElementAnimations
> m_elementAnimations
;
145 OwnPtrWillBeMember
<InlineCSSStyleDeclaration
> m_cssomWrapper
;
147 RefPtr
<ComputedStyle
> m_computedStyle
;
148 RefPtrWillBeMember
<CustomElementDefinition
> m_customElementDefinition
;
150 RefPtrWillBeMember
<PseudoElement
> m_generatedBefore
;
151 RefPtrWillBeMember
<PseudoElement
> m_generatedAfter
;
152 RefPtrWillBeMember
<PseudoElement
> m_generatedFirstLetter
;
153 RefPtrWillBeMember
<PseudoElement
> m_backdrop
;
155 explicit ElementRareData(LayoutObject
*);
158 inline LayoutSize
defaultMinimumSizeForResizing()
160 return LayoutSize(LayoutUnit::max(), LayoutUnit::max());
163 inline ElementRareData::ElementRareData(LayoutObject
* layoutObject
)
164 : NodeRareData(layoutObject
)
167 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
169 m_isElementRareData
= true;
172 inline ElementRareData::~ElementRareData()
175 if (m_elementAnimations
)
176 m_elementAnimations
->dispose();
179 ASSERT(!m_generatedBefore
);
180 ASSERT(!m_generatedAfter
);
181 ASSERT(!m_generatedFirstLetter
);
185 inline bool ElementRareData::hasPseudoElements() const
187 return m_generatedBefore
|| m_generatedAfter
|| m_backdrop
|| m_generatedFirstLetter
;
190 inline void ElementRareData::clearPseudoElements()
192 setPseudoElement(BEFORE
, nullptr);
193 setPseudoElement(AFTER
, nullptr);
194 setPseudoElement(BACKDROP
, nullptr);
195 setPseudoElement(FIRST_LETTER
, nullptr);
198 inline void ElementRareData::setPseudoElement(PseudoId pseudoId
, PassRefPtrWillBeRawPtr
<PseudoElement
> element
)
202 if (m_generatedBefore
)
203 m_generatedBefore
->dispose();
204 m_generatedBefore
= element
;
207 if (m_generatedAfter
)
208 m_generatedAfter
->dispose();
209 m_generatedAfter
= element
;
213 m_backdrop
->dispose();
214 m_backdrop
= element
;
217 if (m_generatedFirstLetter
)
218 m_generatedFirstLetter
->dispose();
219 m_generatedFirstLetter
= element
;
222 ASSERT_NOT_REACHED();
226 inline PseudoElement
* ElementRareData::pseudoElement(PseudoId pseudoId
) const
230 return m_generatedBefore
.get();
232 return m_generatedAfter
.get();
234 return m_backdrop
.get();
236 return m_generatedFirstLetter
.get();
244 #endif // ElementRareData_h