2 * Copyright (C) 2008, 2009, 2010, 2014, 2016 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.
24 #include "CustomElementReactionQueue.h"
25 #include "DOMTokenList.h"
26 #include "DatasetDOMStringMap.h"
27 #include "IntersectionObserver.h"
28 #include "NamedNodeMap.h"
29 #include "NodeRareData.h"
30 #include "PseudoElement.h"
31 #include "RenderElement.h"
32 #include "ResizeObserver.h"
33 #include "ShadowRoot.h"
34 #include "SpaceSplitString.h"
35 #include "StylePropertyMap.h"
39 inline IntSize defaultMinimumSizeForResizing()
41 return IntSize(LayoutUnit::max(), LayoutUnit::max());
44 class ElementRareData : public NodeRareData {
46 explicit ElementRareData();
49 void setBeforePseudoElement(RefPtr<PseudoElement>&&);
50 void setAfterPseudoElement(RefPtr<PseudoElement>&&);
52 PseudoElement* beforePseudoElement() const { return m_beforePseudoElement.get(); }
53 PseudoElement* afterPseudoElement() const { return m_afterPseudoElement.get(); }
55 void resetComputedStyle();
56 void resetStyleRelations();
58 Optional<int> tabIndex() const { return m_tabIndexWasSetExplicitly ? Optional<int> { m_tabIndex } : WTF::nullopt; }
59 void setTabIndexExplicitly(int index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
60 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
61 void clearTabIndexExplicitly() { m_tabIndex = 0; m_tabIndexWasSetExplicitly = false; }
63 #if ENABLE(FULLSCREEN_API)
64 bool containsFullScreenElement() { return m_containsFullScreenElement; }
65 void setContainsFullScreenElement(bool value) { m_containsFullScreenElement = value; }
68 unsigned childIndex() const { return m_childIndex; }
69 void setChildIndex(unsigned index) { m_childIndex = index; }
70 static ptrdiff_t childIndexMemoryOffset() { return OBJECT_OFFSETOF(ElementRareData, m_childIndex); }
72 void clearShadowRoot() { m_shadowRoot = nullptr; }
73 ShadowRoot* shadowRoot() const { return m_shadowRoot.get(); }
74 void setShadowRoot(RefPtr<ShadowRoot>&& shadowRoot) { m_shadowRoot = WTFMove(shadowRoot); }
76 CustomElementReactionQueue* customElementReactionQueue() { return m_customElementReactionQueue.get(); }
77 void setCustomElementReactionQueue(std::unique_ptr<CustomElementReactionQueue>&& queue) { m_customElementReactionQueue = WTFMove(queue); }
79 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
80 void setAttributeMap(std::unique_ptr<NamedNodeMap> attributeMap) { m_attributeMap = WTFMove(attributeMap); }
82 RenderStyle* computedStyle() const { return m_computedStyle.get(); }
83 void setComputedStyle(std::unique_ptr<RenderStyle> computedStyle) { m_computedStyle = WTFMove(computedStyle); }
85 DOMTokenList* classList() const { return m_classList.get(); }
86 void setClassList(std::unique_ptr<DOMTokenList> classList) { m_classList = WTFMove(classList); }
88 DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
89 void setDataset(std::unique_ptr<DatasetDOMStringMap> dataset) { m_dataset = WTFMove(dataset); }
91 LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; }
92 void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; }
94 IntPoint savedLayerScrollPosition() const { return m_savedLayerScrollPosition; }
95 void setSavedLayerScrollPosition(IntPoint position) { m_savedLayerScrollPosition = position; }
97 bool hasPendingResources() const { return m_hasPendingResources; }
98 void setHasPendingResources(bool has) { m_hasPendingResources = has; }
100 bool hasCSSAnimation() const { return m_hasCSSAnimation; }
101 void setHasCSSAnimation(bool value) { m_hasCSSAnimation = value; }
103 bool hasElementIdentifier() const { return m_hasElementIdentifier; }
104 void setHasElementIdentifier(bool value) { m_hasElementIdentifier = value; }
106 DOMTokenList* partList() const { return m_partList.get(); }
107 void setPartList(std::unique_ptr<DOMTokenList> partList) { m_partList = WTFMove(partList); }
109 const SpaceSplitString& partNames() const { return m_partNames; }
110 void setPartNames(SpaceSplitString&& partNames) { m_partNames = WTFMove(partNames); }
112 #if ENABLE(INTERSECTION_OBSERVER)
113 IntersectionObserverData* intersectionObserverData() { return m_intersectionObserverData.get(); }
114 void setIntersectionObserverData(std::unique_ptr<IntersectionObserverData>&& data) { m_intersectionObserverData = WTFMove(data); }
117 #if ENABLE(RESIZE_OBSERVER)
118 ResizeObserverData* resizeObserverData() { return m_resizeObserverData.get(); }
119 void setResizeObserverData(std::unique_ptr<ResizeObserverData>&& data) { m_resizeObserverData = WTFMove(data); }
122 #if ENABLE(CSS_TYPED_OM)
123 StylePropertyMap* attributeStyleMap() { return m_attributeStyleMap.get(); }
124 void setAttributeStyleMap(Ref<StylePropertyMap>&& map) { m_attributeStyleMap = WTFMove(map); }
127 #if DUMP_NODE_STATISTICS
128 OptionSet<UseType> useTypes() const
130 auto result = NodeRareData::useTypes();
131 if (m_tabIndexWasSetExplicitly)
132 result.add(UseType::TabIndex);
133 if (m_minimumSizeForResizing != defaultMinimumSizeForResizing())
134 result.add(UseType::MinimumSize);
135 if (!m_savedLayerScrollPosition.isZero())
136 result.add(UseType::ScrollingPosition);
138 result.add(UseType::ComputedStyle);
140 result.add(UseType::Dataset);
142 result.add(UseType::ClassList);
144 result.add(UseType::ShadowRoot);
145 if (m_customElementReactionQueue)
146 result.add(UseType::CustomElementQueue);
148 result.add(UseType::AttributeMap);
149 if (m_intersectionObserverData)
150 result.add(UseType::InteractionObserver);
151 #if ENABLE(RESIZE_OBSERVER)
152 if (m_resizeObserverData)
153 result.add(UseType::ResizeObserver);
155 if (m_beforePseudoElement || m_afterPseudoElement)
156 result.add(UseType::PseudoElements);
163 unsigned short m_childIndex;
164 unsigned m_tabIndexWasSetExplicitly : 1;
165 #if ENABLE(FULLSCREEN_API)
166 unsigned m_containsFullScreenElement : 1;
168 unsigned m_hasPendingResources : 1;
169 unsigned m_hasCSSAnimation : 1;
170 unsigned m_hasElementIdentifier : 1;
172 LayoutSize m_minimumSizeForResizing;
173 IntPoint m_savedLayerScrollPosition;
174 std::unique_ptr<RenderStyle> m_computedStyle;
176 std::unique_ptr<DatasetDOMStringMap> m_dataset;
177 std::unique_ptr<DOMTokenList> m_classList;
178 RefPtr<ShadowRoot> m_shadowRoot;
179 std::unique_ptr<CustomElementReactionQueue> m_customElementReactionQueue;
180 std::unique_ptr<NamedNodeMap> m_attributeMap;
181 #if ENABLE(INTERSECTION_OBSERVER)
182 std::unique_ptr<IntersectionObserverData> m_intersectionObserverData;
185 #if ENABLE(RESIZE_OBSERVER)
186 std::unique_ptr<ResizeObserverData> m_resizeObserverData;
189 RefPtr<PseudoElement> m_beforePseudoElement;
190 RefPtr<PseudoElement> m_afterPseudoElement;
192 #if ENABLE(CSS_TYPED_OM)
193 RefPtr<StylePropertyMap> m_attributeStyleMap;
196 std::unique_ptr<DOMTokenList> m_partList;
197 SpaceSplitString m_partNames;
199 void releasePseudoElement(PseudoElement*);
202 inline ElementRareData::ElementRareData()
203 : NodeRareData(Type::Element)
206 , m_tabIndexWasSetExplicitly(false)
207 #if ENABLE(FULLSCREEN_API)
208 , m_containsFullScreenElement(false)
210 , m_hasPendingResources(false)
211 , m_hasCSSAnimation(false)
212 , m_hasElementIdentifier(false)
213 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
217 inline ElementRareData::~ElementRareData()
219 ASSERT(!m_shadowRoot);
220 ASSERT(!m_beforePseudoElement);
221 ASSERT(!m_afterPseudoElement);
224 inline void ElementRareData::setBeforePseudoElement(RefPtr<PseudoElement>&& pseudoElement)
226 ASSERT(!m_beforePseudoElement || !pseudoElement);
227 m_beforePseudoElement = WTFMove(pseudoElement);
230 inline void ElementRareData::setAfterPseudoElement(RefPtr<PseudoElement>&& pseudoElement)
232 ASSERT(!m_afterPseudoElement || !pseudoElement);
233 m_afterPseudoElement = WTFMove(pseudoElement);
236 inline void ElementRareData::resetComputedStyle()
238 m_computedStyle = nullptr;
241 inline void ElementRareData::resetStyleRelations()
246 } // namespace WebCore