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