1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
/*
* Copyright (C) 2008, 2009, 2010, 2014, 2016 Apple Inc. All rights reserved.
* Copyright (C) 2008 David Smith <catfish.man@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#pragma once
#include "CustomElementDefaultARIA.h"
#include "CustomElementReactionQueue.h"
#include "DOMTokenList.h"
#include "DatasetDOMStringMap.h"
#include "ElementAnimationRareData.h"
#include "FormAssociatedCustomElement.h"
#include "IntersectionObserver.h"
#include "KeyframeEffectStack.h"
#include "NamedNodeMap.h"
#include "NodeRareData.h"
#include "PopoverData.h"
#include "PseudoElement.h"
#include "RenderElement.h"
#include "ResizeObserver.h"
#include "ShadowRoot.h"
#include "SpaceSplitString.h"
#include "StylePropertyMap.h"
#include "StylePropertyMapReadOnly.h"
#include <wtf/Markable.h>
namespace WebCore {
struct LayoutUnitMarkableTraits {
static bool isEmptyValue(LayoutUnit value)
{
return value == LayoutUnit(-1);
}
static LayoutUnit emptyValue()
{
return LayoutUnit(-1);
}
};
class ElementRareData : public NodeRareData {
public:
explicit ElementRareData();
~ElementRareData();
void setBeforePseudoElement(RefPtr<PseudoElement>&&);
void setAfterPseudoElement(RefPtr<PseudoElement>&&);
PseudoElement* beforePseudoElement() const { return m_beforePseudoElement.get(); }
PseudoElement* afterPseudoElement() const { return m_afterPseudoElement.get(); }
void resetComputedStyle();
int unusualTabIndex() const;
void setUnusualTabIndex(int);
unsigned childIndex() const { return m_childIndex; }
void setChildIndex(unsigned index) { m_childIndex = index; }
static ptrdiff_t childIndexMemoryOffset() { return OBJECT_OFFSETOF(ElementRareData, m_childIndex); }
void clearShadowRoot() { m_shadowRoot = nullptr; }
ShadowRoot* shadowRoot() const { return m_shadowRoot.get(); }
void setShadowRoot(RefPtr<ShadowRoot>&& shadowRoot) { m_shadowRoot = WTFMove(shadowRoot); }
CustomElementReactionQueue* customElementReactionQueue() { return m_customElementReactionQueue.get(); }
void setCustomElementReactionQueue(std::unique_ptr<CustomElementReactionQueue>&& queue) { m_customElementReactionQueue = WTFMove(queue); }
CustomElementDefaultARIA* customElementDefaultARIA() { return m_customElementDefaultARIA.get(); }
void setCustomElementDefaultARIA(std::unique_ptr<CustomElementDefaultARIA>&& defaultARIA) { m_customElementDefaultARIA = WTFMove(defaultARIA); }
FormAssociatedCustomElement* formAssociatedCustomElement() { return m_formAssociatedCustomElement.get(); }
void setFormAssociatedCustomElement(std::unique_ptr<FormAssociatedCustomElement>&& element) { m_formAssociatedCustomElement = WTFMove(element); }
NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
void setAttributeMap(std::unique_ptr<NamedNodeMap>&& attributeMap) { m_attributeMap = WTFMove(attributeMap); }
RenderStyle* computedStyle() const { return m_computedStyle.get(); }
void setComputedStyle(std::unique_ptr<RenderStyle>&& computedStyle) { m_computedStyle = WTFMove(computedStyle); }
RenderStyle* displayContentsStyle() const { return m_displayContentsStyle.get(); }
void setDisplayContentsStyle(std::unique_ptr<RenderStyle> style) { m_displayContentsStyle = WTFMove(style); }
const AtomString& effectiveLang() const { return m_effectiveLang; }
void setEffectiveLang(const AtomString& lang) { m_effectiveLang = lang; }
DOMTokenList* classList() const { return m_classList.get(); }
void setClassList(std::unique_ptr<DOMTokenList>&& classList) { m_classList = WTFMove(classList); }
DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
void setDataset(std::unique_ptr<DatasetDOMStringMap>&& dataset) { m_dataset = WTFMove(dataset); }
IntPoint savedLayerScrollPosition() const { return m_savedLayerScrollPosition; }
void setSavedLayerScrollPosition(IntPoint position) { m_savedLayerScrollPosition = position; }
ElementAnimationRareData* animationRareData(PseudoId) const;
ElementAnimationRareData& ensureAnimationRareData(PseudoId);
DOMTokenList* partList() const { return m_partList.get(); }
void setPartList(std::unique_ptr<DOMTokenList>&& partList) { m_partList = WTFMove(partList); }
const SpaceSplitString& partNames() const { return m_partNames; }
void setPartNames(SpaceSplitString&& partNames) { m_partNames = WTFMove(partNames); }
IntersectionObserverData* intersectionObserverData() { return m_intersectionObserverData.get(); }
void setIntersectionObserverData(std::unique_ptr<IntersectionObserverData>&& data) { m_intersectionObserverData = WTFMove(data); }
ResizeObserverData* resizeObserverData() { return m_resizeObserverData.get(); }
void setResizeObserverData(std::unique_ptr<ResizeObserverData>&& data) { m_resizeObserverData = WTFMove(data); }
std::optional<LayoutUnit> lastRememberedLogicalWidth() const { return m_lastRememberedLogicalWidth; }
std::optional<LayoutUnit> lastRememberedLogicalHeight() const { return m_lastRememberedLogicalHeight; }
void setLastRememberedLogicalWidth(LayoutUnit width) { m_lastRememberedLogicalWidth = width; }
void setLastRememberedLogicalHeight(LayoutUnit height) { m_lastRememberedLogicalHeight = height; }
void clearLastRememberedLogicalWidth() { m_lastRememberedLogicalWidth.reset(); }
void clearLastRememberedLogicalHeight() { m_lastRememberedLogicalHeight.reset(); }
const AtomString& nonce() const { return m_nonce; }
void setNonce(const AtomString& value) { m_nonce = value; }
StylePropertyMap* attributeStyleMap() { return m_attributeStyleMap.get(); }
void setAttributeStyleMap(Ref<StylePropertyMap>&& map) { m_attributeStyleMap = WTFMove(map); }
StylePropertyMapReadOnly* computedStyleMap() { return m_computedStyleMap.get(); }
void setComputedStyleMap(Ref<StylePropertyMapReadOnly>&& map) { m_computedStyleMap = WTFMove(map); }
ExplicitlySetAttrElementsMap& explicitlySetAttrElementsMap() { return m_explicitlySetAttrElementsMap; }
PopoverData* popoverData() { return m_popoverData.get(); }
void setPopoverData(std::unique_ptr<PopoverData>&& popoverData) { m_popoverData = WTFMove(popoverData); }
const OptionSet<ContentRelevancyStatus>& contentRelevancyStatus() const { return m_contentRelevancyStatus; }
void setContentRelevancyStatus(OptionSet<ContentRelevancyStatus>& contentRelevancyStatus) { m_contentRelevancyStatus = contentRelevancyStatus; }
#if DUMP_NODE_STATISTICS
OptionSet<UseType> useTypes() const
{
auto result = NodeRareData::useTypes();
if (!m_savedLayerScrollPosition.isZero())
result.add(UseType::ScrollingPosition);
if (m_computedStyle)
result.add(UseType::ComputedStyle);
if (m_displayContentsStyle)
result.add(UseType::DisplayContentsStyle);
if (!m_effectiveLang.isEmpty())
result.add(UseType::EffectiveLang);
if (m_dataset)
result.add(UseType::Dataset);
if (m_classList)
result.add(UseType::ClassList);
if (m_shadowRoot)
result.add(UseType::ShadowRoot);
if (m_customElementReactionQueue)
result.add(UseType::CustomElementReactionQueue);
if (m_customElementDefaultARIA)
result.add(UseType::CustomElementDefaultARIA);
if (m_formAssociatedCustomElement)
result.add(UseType::FormAssociatedCustomElement);
if (m_attributeMap)
result.add(UseType::AttributeMap);
if (m_intersectionObserverData)
result.add(UseType::InteractionObserver);
if (m_resizeObserverData || m_lastRememberedLogicalWidth || m_lastRememberedLogicalHeight)
result.add(UseType::ResizeObserver);
if (!m_animationRareData.isEmpty())
result.add(UseType::Animations);
if (m_beforePseudoElement || m_afterPseudoElement)
result.add(UseType::PseudoElements);
if (m_attributeStyleMap)
result.add(UseType::AttributeStyleMap);
if (m_computedStyleMap)
result.add(UseType::ComputedStyleMap);
if (m_partList)
result.add(UseType::PartList);
if (!m_partNames.isEmpty())
result.add(UseType::PartNames);
if (!m_nonce.isEmpty())
result.add(UseType::Nonce);
if (!m_explicitlySetAttrElementsMap.isEmpty())
result.add(UseType::ExplicitlySetAttrElementsMap);
if (m_popoverData)
result.add(UseType::Popover);
if (m_childIndex)
result.add(UseType::ChildIndex);
return result;
}
#endif
private:
unsigned short m_childIndex { 0 }; // Keep on top for better bit packing with NodeRareData.
int m_unusualTabIndex { 0 }; // Keep on top for better bit packing with NodeRareData.
OptionSet<ContentRelevancyStatus> m_contentRelevancyStatus;
IntPoint m_savedLayerScrollPosition;
std::unique_ptr<RenderStyle> m_computedStyle;
std::unique_ptr<RenderStyle> m_displayContentsStyle;
AtomString m_effectiveLang;
std::unique_ptr<DatasetDOMStringMap> m_dataset;
std::unique_ptr<DOMTokenList> m_classList;
RefPtr<ShadowRoot> m_shadowRoot;
std::unique_ptr<CustomElementReactionQueue> m_customElementReactionQueue;
std::unique_ptr<CustomElementDefaultARIA> m_customElementDefaultARIA;
std::unique_ptr<FormAssociatedCustomElement> m_formAssociatedCustomElement;
std::unique_ptr<NamedNodeMap> m_attributeMap;
std::unique_ptr<IntersectionObserverData> m_intersectionObserverData;
std::unique_ptr<ResizeObserverData> m_resizeObserverData;
Markable<LayoutUnit, LayoutUnitMarkableTraits> m_lastRememberedLogicalWidth;
Markable<LayoutUnit, LayoutUnitMarkableTraits> m_lastRememberedLogicalHeight;
Vector<std::unique_ptr<ElementAnimationRareData>> m_animationRareData;
RefPtr<PseudoElement> m_beforePseudoElement;
RefPtr<PseudoElement> m_afterPseudoElement;
RefPtr<StylePropertyMap> m_attributeStyleMap;
RefPtr<StylePropertyMapReadOnly> m_computedStyleMap;
std::unique_ptr<DOMTokenList> m_partList;
SpaceSplitString m_partNames;
AtomString m_nonce;
ExplicitlySetAttrElementsMap m_explicitlySetAttrElementsMap;
std::unique_ptr<PopoverData> m_popoverData;
};
inline ElementRareData::ElementRareData()
: NodeRareData(Type::Element)
{
}
inline ElementRareData::~ElementRareData()
{
ASSERT(!m_shadowRoot);
ASSERT(!m_beforePseudoElement);
ASSERT(!m_afterPseudoElement);
}
inline void ElementRareData::setBeforePseudoElement(RefPtr<PseudoElement>&& pseudoElement)
{
ASSERT(!m_beforePseudoElement || !pseudoElement);
m_beforePseudoElement = WTFMove(pseudoElement);
}
inline void ElementRareData::setAfterPseudoElement(RefPtr<PseudoElement>&& pseudoElement)
{
ASSERT(!m_afterPseudoElement || !pseudoElement);
m_afterPseudoElement = WTFMove(pseudoElement);
}
inline void ElementRareData::resetComputedStyle()
{
m_computedStyle = nullptr;
}
inline int ElementRareData::unusualTabIndex() const
{
ASSERT(m_unusualTabIndex); // setUnusualTabIndex must have been called before this.
return m_unusualTabIndex;
}
inline void ElementRareData::setUnusualTabIndex(int tabIndex)
{
ASSERT(tabIndex && tabIndex != -1); // Common values of 0 and -1 are stored as TabIndexState in Node.
m_unusualTabIndex = tabIndex;
}
inline ElementAnimationRareData* ElementRareData::animationRareData(PseudoId pseudoId) const
{
for (auto& animationRareData : m_animationRareData) {
if (animationRareData->pseudoId() == pseudoId)
return animationRareData.get();
}
return nullptr;
}
inline ElementAnimationRareData& ElementRareData::ensureAnimationRareData(PseudoId pseudoId)
{
if (auto* animationRareData = this->animationRareData(pseudoId))
return *animationRareData;
m_animationRareData.append(makeUnique<ElementAnimationRareData>(pseudoId));
return *m_animationRareData.last().get();
}
inline ElementRareData* Element::elementRareData() const
{
ASSERT_WITH_SECURITY_IMPLICATION(hasRareData());
return static_cast<ElementRareData*>(rareData());
}
inline ShadowRoot* Node::shadowRoot() const
{
if (!is<Element>(*this))
return nullptr;
return downcast<Element>(*this).shadowRoot();
}
inline ShadowRoot* Element::shadowRoot() const
{
return hasRareData() ? elementRareData()->shadowRoot() : nullptr;
}
inline void Element::removeShadowRoot()
{
RefPtr shadowRoot = this->shadowRoot();
if (LIKELY(!shadowRoot))
return;
removeShadowRootSlow(*shadowRoot);
}
} // namespace WebCore
|