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/ActiveAnimations.h"
26 #include "core/dom/DatasetDOMStringMap.h"
27 #include "core/dom/NamedNodeMap.h"
28 #include "core/dom/NodeRareData.h"
29 #include "core/dom/PseudoElement.h"
30 #include "core/dom/custom/CustomElementDefinition.h"
31 #include "core/dom/shadow/ElementShadow.h"
32 #include "core/html/ClassList.h"
33 #include "core/html/ime/InputMethodContext.h"
34 #include "core/rendering/style/StyleInheritedData.h"
35 #include "platform/heap/Handle.h"
36 #include "wtf/OwnPtr.h"
42 class ElementRareData : public NodeRareData {
44 static ElementRareData* create(RenderObject* renderer)
46 return new ElementRareData(renderer);
51 void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
52 PseudoElement* pseudoElement(PseudoId) const;
54 void resetStyleState();
56 short tabIndex() const { return m_tabindex; }
58 void setTabIndexExplicitly(short index)
61 setElementFlag(TabIndexWasSetExplicitly, true);
64 void clearTabIndexExplicitly()
67 clearElementFlag(TabIndexWasSetExplicitly);
70 CSSStyleDeclaration& ensureInlineCSSStyleDeclaration(Element* ownerElement);
72 void clearShadow() { m_shadow = nullptr; }
73 ElementShadow* shadow() const { return m_shadow.get(); }
74 ElementShadow& ensureShadow()
77 m_shadow = ElementShadow::create();
81 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
82 void setAttributeMap(PassOwnPtrWillBeRawPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; }
84 RenderStyle* computedStyle() const { return m_computedStyle.get(); }
85 void setComputedStyle(PassRefPtr<RenderStyle> computedStyle) { m_computedStyle = computedStyle; }
86 void clearComputedStyle() { m_computedStyle = nullptr; }
88 ClassList* classList() const { return m_classList.get(); }
89 void setClassList(PassOwnPtrWillBeRawPtr<ClassList> classList) { m_classList = classList; }
90 void clearClassListValueForQuirksMode()
94 m_classList->clearValueForQuirksMode();
97 DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
98 void setDataset(PassOwnPtrWillBeRawPtr<DatasetDOMStringMap> dataset) { m_dataset = dataset; }
100 IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
101 void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
103 ActiveAnimations* activeAnimations() { return m_activeAnimations.get(); }
104 void setActiveAnimations(PassOwnPtrWillBeRawPtr<ActiveAnimations> activeAnimations)
106 m_activeAnimations = activeAnimations;
109 bool hasInputMethodContext() const { return m_inputMethodContext; }
110 InputMethodContext& ensureInputMethodContext(HTMLElement* element)
112 if (!m_inputMethodContext)
113 m_inputMethodContext = InputMethodContext::create(element);
114 return *m_inputMethodContext;
117 bool hasPseudoElements() const;
118 void clearPseudoElements();
120 void setCustomElementDefinition(PassRefPtr<CustomElementDefinition> definition) { m_customElementDefinition = definition; }
121 CustomElementDefinition* customElementDefinition() const { return m_customElementDefinition.get(); }
123 void traceAfterDispatch(Visitor*);
128 IntSize m_savedLayerScrollOffset;
130 OwnPtrWillBeMember<DatasetDOMStringMap> m_dataset;
131 OwnPtrWillBeMember<ClassList> m_classList;
132 OwnPtrWillBeMember<ElementShadow> m_shadow;
133 OwnPtrWillBeMember<NamedNodeMap> m_attributeMap;
134 OwnPtr<InputMethodContext> m_inputMethodContext;
135 OwnPtrWillBeMember<ActiveAnimations> m_activeAnimations;
136 OwnPtrWillBeMember<InlineCSSStyleDeclaration> m_cssomWrapper;
138 RefPtr<RenderStyle> m_computedStyle;
139 RefPtr<CustomElementDefinition> m_customElementDefinition;
141 RefPtr<PseudoElement> m_generatedBefore;
142 RefPtr<PseudoElement> m_generatedAfter;
143 RefPtr<PseudoElement> m_backdrop;
145 explicit ElementRareData(RenderObject*);
148 inline ElementRareData::ElementRareData(RenderObject* renderer)
149 : NodeRareData(renderer)
152 m_isElementRareData = true;
155 inline ElementRareData::~ElementRareData()
160 ASSERT(!m_generatedBefore);
161 ASSERT(!m_generatedAfter);
165 inline bool ElementRareData::hasPseudoElements() const
167 return m_generatedBefore || m_generatedAfter || m_backdrop;
170 inline void ElementRareData::clearPseudoElements()
172 setPseudoElement(BEFORE, nullptr);
173 setPseudoElement(AFTER, nullptr);
174 setPseudoElement(BACKDROP, nullptr);
177 inline void ElementRareData::setPseudoElement(PseudoId pseudoId, PassRefPtr<PseudoElement> element)
181 if (m_generatedBefore)
182 m_generatedBefore->dispose();
183 m_generatedBefore = element;
186 if (m_generatedAfter)
187 m_generatedAfter->dispose();
188 m_generatedAfter = element;
192 m_backdrop->dispose();
193 m_backdrop = element;
196 ASSERT_NOT_REACHED();
200 inline PseudoElement* ElementRareData::pseudoElement(PseudoId pseudoId) const
204 return m_generatedBefore.get();
206 return m_generatedAfter.get();
208 return m_backdrop.get();
214 inline void ElementRareData::resetStyleState()
216 clearElementFlag(StyleAffectedByEmpty);
221 #endif // ElementRareData_h