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/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/html/ime/InputMethodContext.h"
35 #include "core/rendering/style/StyleInheritedData.h"
36 #include "platform/heap/Handle.h"
37 #include "wtf/OwnPtr.h"
43 class ElementRareData : public NodeRareData {
45 static ElementRareData* create(RenderObject* renderer)
47 return new ElementRareData(renderer);
52 void setPseudoElement(PseudoId, PassRefPtrWillBeRawPtr<PseudoElement>);
53 PseudoElement* pseudoElement(PseudoId) const;
55 short tabIndex() const { return m_tabindex; }
57 void setTabIndexExplicitly(short index)
60 setElementFlag(TabIndexWasSetExplicitly, true);
63 void clearTabIndexExplicitly()
66 clearElementFlag(TabIndexWasSetExplicitly);
69 CSSStyleDeclaration& ensureInlineCSSStyleDeclaration(Element* ownerElement);
71 void clearShadow() { m_shadow = nullptr; }
72 ElementShadow* shadow() const { return m_shadow.get(); }
73 ElementShadow& ensureShadow()
76 m_shadow = ElementShadow::create();
80 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
81 void setAttributeMap(PassOwnPtrWillBeRawPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; }
83 RenderStyle* computedStyle() const { return m_computedStyle.get(); }
84 void setComputedStyle(PassRefPtr<RenderStyle> computedStyle) { m_computedStyle = computedStyle; }
85 void clearComputedStyle() { m_computedStyle = nullptr; }
87 ClassList* classList() const { return m_classList.get(); }
88 void setClassList(PassOwnPtrWillBeRawPtr<ClassList> classList) { m_classList = classList; }
89 void clearClassListValueForQuirksMode()
93 m_classList->clearValueForQuirksMode();
96 DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
97 void setDataset(PassOwnPtrWillBeRawPtr<DatasetDOMStringMap> dataset) { m_dataset = dataset; }
99 LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; }
100 void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; }
102 IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
103 void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
105 ActiveAnimations* activeAnimations() { return m_activeAnimations.get(); }
106 void setActiveAnimations(PassOwnPtrWillBeRawPtr<ActiveAnimations> activeAnimations)
108 m_activeAnimations = activeAnimations;
111 bool hasInputMethodContext() const { return m_inputMethodContext; }
112 InputMethodContext& ensureInputMethodContext(HTMLElement* element)
114 if (!m_inputMethodContext)
115 m_inputMethodContext = InputMethodContext::create(element);
116 return *m_inputMethodContext;
119 bool hasPseudoElements() const;
120 void clearPseudoElements();
122 void setCustomElementDefinition(PassRefPtr<CustomElementDefinition> definition) { m_customElementDefinition = definition; }
123 CustomElementDefinition* customElementDefinition() const { return m_customElementDefinition.get(); }
125 WillBeHeapVector<RefPtrWillBeMember<Attr> >& ensureAttrNodeList();
126 WillBeHeapVector<RefPtrWillBeMember<Attr> >* attrNodeList() { return m_attrNodeList.get(); }
127 void removeAttrNodeList() { m_attrNodeList.clear(); }
129 void traceAfterDispatch(Visitor*);
134 LayoutSize m_minimumSizeForResizing;
135 IntSize m_savedLayerScrollOffset;
137 OwnPtrWillBeMember<DatasetDOMStringMap> m_dataset;
138 OwnPtrWillBeMember<ClassList> m_classList;
139 OwnPtrWillBeMember<ElementShadow> m_shadow;
140 OwnPtrWillBeMember<NamedNodeMap> m_attributeMap;
141 OwnPtrWillBeMember<WillBeHeapVector<RefPtrWillBeMember<Attr> > > m_attrNodeList;
142 OwnPtrWillBeMember<InputMethodContext> m_inputMethodContext;
143 OwnPtrWillBeMember<ActiveAnimations> m_activeAnimations;
144 OwnPtrWillBeMember<InlineCSSStyleDeclaration> m_cssomWrapper;
146 RefPtr<RenderStyle> m_computedStyle;
147 RefPtr<CustomElementDefinition> m_customElementDefinition;
149 RefPtrWillBeMember<PseudoElement> m_generatedBefore;
150 RefPtrWillBeMember<PseudoElement> m_generatedAfter;
151 RefPtrWillBeMember<PseudoElement> m_backdrop;
153 explicit ElementRareData(RenderObject*);
156 inline IntSize defaultMinimumSizeForResizing()
158 return IntSize(LayoutUnit::max(), LayoutUnit::max());
161 inline ElementRareData::ElementRareData(RenderObject* renderer)
162 : NodeRareData(renderer)
164 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
166 m_isElementRareData = true;
169 inline ElementRareData::~ElementRareData()
174 ASSERT(!m_generatedBefore);
175 ASSERT(!m_generatedAfter);
179 inline bool ElementRareData::hasPseudoElements() const
181 return m_generatedBefore || m_generatedAfter || m_backdrop;
184 inline void ElementRareData::clearPseudoElements()
186 setPseudoElement(BEFORE, nullptr);
187 setPseudoElement(AFTER, nullptr);
188 setPseudoElement(BACKDROP, nullptr);
191 inline void ElementRareData::setPseudoElement(PseudoId pseudoId, PassRefPtrWillBeRawPtr<PseudoElement> element)
195 if (m_generatedBefore)
196 m_generatedBefore->dispose();
197 m_generatedBefore = element;
200 if (m_generatedAfter)
201 m_generatedAfter->dispose();
202 m_generatedAfter = element;
206 m_backdrop->dispose();
207 m_backdrop = element;
210 ASSERT_NOT_REACHED();
214 inline PseudoElement* ElementRareData::pseudoElement(PseudoId pseudoId) const
218 return m_generatedBefore.get();
220 return m_generatedAfter.get();
222 return m_backdrop.get();
230 #endif // ElementRareData_h