Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / ElementRareData.h
1 /*
2  * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved.
3  * 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
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"
38
39 namespace blink {
40
41 class HTMLElement;
42
43 class ElementRareData : public NodeRareData {
44 public:
45     static ElementRareData* create(RenderObject* renderer)
46     {
47         return new ElementRareData(renderer);
48     }
49
50     ~ElementRareData();
51
52     void setPseudoElement(PseudoId, PassRefPtrWillBeRawPtr<PseudoElement>);
53     PseudoElement* pseudoElement(PseudoId) const;
54
55     short tabIndex() const { return m_tabindex; }
56
57     void setTabIndexExplicitly(short index)
58     {
59         m_tabindex = index;
60         setElementFlag(TabIndexWasSetExplicitly, true);
61     }
62
63     void clearTabIndexExplicitly()
64     {
65         m_tabindex = 0;
66         clearElementFlag(TabIndexWasSetExplicitly);
67     }
68
69     CSSStyleDeclaration& ensureInlineCSSStyleDeclaration(Element* ownerElement);
70
71     void clearShadow() { m_shadow = nullptr; }
72     ElementShadow* shadow() const { return m_shadow.get(); }
73     ElementShadow& ensureShadow()
74     {
75         if (!m_shadow)
76             m_shadow = ElementShadow::create();
77         return *m_shadow;
78     }
79
80     NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
81     void setAttributeMap(PassOwnPtrWillBeRawPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; }
82
83     RenderStyle* computedStyle() const { return m_computedStyle.get(); }
84     void setComputedStyle(PassRefPtr<RenderStyle> computedStyle) { m_computedStyle = computedStyle; }
85     void clearComputedStyle() { m_computedStyle = nullptr; }
86
87     ClassList* classList() const { return m_classList.get(); }
88     void setClassList(PassOwnPtrWillBeRawPtr<ClassList> classList) { m_classList = classList; }
89     void clearClassListValueForQuirksMode()
90     {
91         if (!m_classList)
92             return;
93         m_classList->clearValueForQuirksMode();
94     }
95
96     DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
97     void setDataset(PassOwnPtrWillBeRawPtr<DatasetDOMStringMap> dataset) { m_dataset = dataset; }
98
99     LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; }
100     void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; }
101
102     IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
103     void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
104
105     ActiveAnimations* activeAnimations() { return m_activeAnimations.get(); }
106     void setActiveAnimations(PassOwnPtrWillBeRawPtr<ActiveAnimations> activeAnimations)
107     {
108         m_activeAnimations = activeAnimations;
109     }
110
111     bool hasInputMethodContext() const { return m_inputMethodContext; }
112     InputMethodContext& ensureInputMethodContext(HTMLElement* element)
113     {
114         if (!m_inputMethodContext)
115             m_inputMethodContext = InputMethodContext::create(element);
116         return *m_inputMethodContext;
117     }
118
119     bool hasPseudoElements() const;
120     void clearPseudoElements();
121
122     void setCustomElementDefinition(PassRefPtr<CustomElementDefinition> definition) { m_customElementDefinition = definition; }
123     CustomElementDefinition* customElementDefinition() const { return m_customElementDefinition.get(); }
124
125     WillBeHeapVector<RefPtrWillBeMember<Attr> >& ensureAttrNodeList();
126     WillBeHeapVector<RefPtrWillBeMember<Attr> >* attrNodeList() { return m_attrNodeList.get(); }
127     void removeAttrNodeList() { m_attrNodeList.clear(); }
128
129     void traceAfterDispatch(Visitor*);
130
131 private:
132     short m_tabindex;
133
134     LayoutSize m_minimumSizeForResizing;
135     IntSize m_savedLayerScrollOffset;
136
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;
145
146     RefPtr<RenderStyle> m_computedStyle;
147     RefPtr<CustomElementDefinition> m_customElementDefinition;
148
149     RefPtrWillBeMember<PseudoElement> m_generatedBefore;
150     RefPtrWillBeMember<PseudoElement> m_generatedAfter;
151     RefPtrWillBeMember<PseudoElement> m_backdrop;
152
153     explicit ElementRareData(RenderObject*);
154 };
155
156 inline IntSize defaultMinimumSizeForResizing()
157 {
158     return IntSize(LayoutUnit::max(), LayoutUnit::max());
159 }
160
161 inline ElementRareData::ElementRareData(RenderObject* renderer)
162     : NodeRareData(renderer)
163     , m_tabindex(0)
164     , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
165 {
166     m_isElementRareData = true;
167 }
168
169 inline ElementRareData::~ElementRareData()
170 {
171 #if !ENABLE(OILPAN)
172     ASSERT(!m_shadow);
173 #endif
174     ASSERT(!m_generatedBefore);
175     ASSERT(!m_generatedAfter);
176     ASSERT(!m_backdrop);
177 }
178
179 inline bool ElementRareData::hasPseudoElements() const
180 {
181     return m_generatedBefore || m_generatedAfter || m_backdrop;
182 }
183
184 inline void ElementRareData::clearPseudoElements()
185 {
186     setPseudoElement(BEFORE, nullptr);
187     setPseudoElement(AFTER, nullptr);
188     setPseudoElement(BACKDROP, nullptr);
189 }
190
191 inline void ElementRareData::setPseudoElement(PseudoId pseudoId, PassRefPtrWillBeRawPtr<PseudoElement> element)
192 {
193     switch (pseudoId) {
194     case BEFORE:
195         if (m_generatedBefore)
196             m_generatedBefore->dispose();
197         m_generatedBefore = element;
198         break;
199     case AFTER:
200         if (m_generatedAfter)
201             m_generatedAfter->dispose();
202         m_generatedAfter = element;
203         break;
204     case BACKDROP:
205         if (m_backdrop)
206             m_backdrop->dispose();
207         m_backdrop = element;
208         break;
209     default:
210         ASSERT_NOT_REACHED();
211     }
212 }
213
214 inline PseudoElement* ElementRareData::pseudoElement(PseudoId pseudoId) const
215 {
216     switch (pseudoId) {
217     case BEFORE:
218         return m_generatedBefore.get();
219     case AFTER:
220         return m_generatedAfter.get();
221     case BACKDROP:
222         return m_backdrop.get();
223     default:
224         return 0;
225     }
226 }
227
228 } // namespace
229
230 #endif // ElementRareData_h