2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013, 2014 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 #include "CollectionType.h"
30 #include "ElementData.h"
31 #include "HTMLNames.h"
32 #include "RegionOversetState.h"
33 #include "ScrollTypes.h"
34 #include "SimulatedClickOptions.h"
35 #include "StyleResolveTree.h"
41 class DatasetDOMStringMap;
43 class ElementRareData;
47 class PlatformKeyboardEvent;
48 class PlatformMouseEvent;
49 class PlatformWheelEvent;
51 class RenderNamedFlowFragment;
54 enum SpellcheckAttributeState {
55 SpellcheckAttributeTrue,
56 SpellcheckAttributeFalse,
57 SpellcheckAttributeDefault
60 class Element : public ContainerNode {
62 static Ref<Element> create(const QualifiedName&, Document&);
65 WEBCORE_EXPORT bool hasAttribute(const QualifiedName&) const;
66 WEBCORE_EXPORT const AtomicString& getAttribute(const QualifiedName&) const;
67 WEBCORE_EXPORT void setAttribute(const QualifiedName&, const AtomicString& value);
68 void setAttributeWithoutSynchronization(const QualifiedName&, const AtomicString& value);
69 void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
70 bool removeAttribute(const QualifiedName&);
72 // Typed getters and setters for language bindings.
73 int getIntegralAttribute(const QualifiedName& attributeName) const;
74 void setIntegralAttribute(const QualifiedName& attributeName, int value);
75 unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
76 void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
78 // Call this to get the value of an attribute that is known not to be the style
79 // attribute or one of the SVG animatable attributes.
80 bool fastHasAttribute(const QualifiedName&) const;
81 const AtomicString& fastGetAttribute(const QualifiedName&) const;
83 WEBCORE_EXPORT bool fastAttributeLookupAllowed(const QualifiedName&) const;
86 #ifdef DUMP_NODE_STATISTICS
87 bool hasNamedNodeMap() const;
89 bool hasAttributes() const;
90 // This variant will not update the potentially invalid attributes. To be used when not interested
91 // in style attribute or one of the SVG animation attributes.
92 bool hasAttributesWithoutUpdate() const;
94 WEBCORE_EXPORT bool hasAttribute(const AtomicString& name) const;
95 bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
97 WEBCORE_EXPORT const AtomicString& getAttribute(const AtomicString& name) const;
98 const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
100 WEBCORE_EXPORT void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
101 static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
102 void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
104 const AtomicString& getIdAttribute() const;
105 void setIdAttribute(const AtomicString&);
107 const AtomicString& getNameAttribute() const;
109 // Call this to get the value of the id attribute for style resolution purposes.
110 // The value will already be lowercased if the document is in compatibility mode,
111 // so this function is not suitable for non-style uses.
112 const AtomicString& idForStyleResolution() const;
114 // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
115 // before calling them.
116 AttributeIteratorAccessor attributesIterator() const { return elementData()->attributesIterator(); }
117 unsigned attributeCount() const;
118 const Attribute& attributeAt(unsigned index) const;
119 const Attribute* findAttributeByName(const QualifiedName&) const;
120 unsigned findAttributeIndexByName(const QualifiedName& name) const { return elementData()->findAttributeIndexByName(name); }
121 unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); }
123 void scrollIntoView(bool alignToTop = true);
124 void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
126 void scrollByLines(int lines);
127 void scrollByPages(int pages);
131 double offsetWidth();
132 double offsetHeight();
134 bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const;
136 // FIXME: Replace uses of offsetParent in the platform with calls
137 // to the render layer and merge bindingsOffsetParent and offsetParent.
138 Element* bindingsOffsetParent();
140 Element* offsetParent();
143 double clientWidth();
144 double clientHeight();
145 virtual int scrollLeft();
146 virtual int scrollTop();
147 virtual void setScrollLeft(int);
148 virtual void setScrollTop(int);
149 virtual int scrollWidth();
150 virtual int scrollHeight();
152 WEBCORE_EXPORT IntRect boundsInRootViewSpace();
154 Ref<ClientRectList> getClientRects();
155 Ref<ClientRect> getBoundingClientRect();
157 // Returns the absolute bounding box translated into client coordinates.
158 WEBCORE_EXPORT IntRect clientRect() const;
159 // Returns the absolute bounding box translated into screen coordinates.
160 WEBCORE_EXPORT IntRect screenRect() const;
162 bool removeAttribute(const AtomicString& name);
163 bool removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
165 RefPtr<Attr> detachAttribute(unsigned index);
167 RefPtr<Attr> getAttributeNode(const AtomicString& name);
168 RefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
169 RefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
170 RefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
171 RefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
173 RefPtr<Attr> attrIfExists(const QualifiedName&);
174 RefPtr<Attr> attrIfExists(const AtomicString& localName, bool shouldIgnoreAttributeCase);
175 RefPtr<Attr> ensureAttr(const QualifiedName&);
177 const Vector<RefPtr<Attr>>& attrNodeList();
179 virtual CSSStyleDeclaration* style();
181 const QualifiedName& tagQName() const { return m_tagName; }
182 #if ENABLE(CSS_SELECTOR_JIT)
183 static ptrdiff_t tagQNameMemoryOffset() { return OBJECT_OFFSETOF(Element, m_tagName); }
184 #endif // ENABLE(CSS_SELECTOR_JIT)
185 String tagName() const { return nodeName(); }
186 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
187 bool hasTagName(const HTMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
188 bool hasTagName(const MathMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
189 bool hasTagName(const SVGQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
191 // A fast function for checking the local name against another atomic string.
192 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
194 virtual const AtomicString& localName() const override final { return m_tagName.localName(); }
195 virtual const AtomicString& prefix() const override final { return m_tagName.prefix(); }
196 virtual const AtomicString& namespaceURI() const override final { return m_tagName.namespaceURI(); }
198 virtual URL baseURI() const override final;
200 virtual String nodeName() const override;
202 RefPtr<Element> cloneElementWithChildren(Document&);
203 RefPtr<Element> cloneElementWithoutChildren(Document&);
205 void normalizeAttributes();
206 String nodeNamePreservingCase() const;
208 void setBooleanAttribute(const QualifiedName& name, bool);
210 // For exposing to DOM only.
211 NamedNodeMap& attributes() const;
213 enum AttributeModificationReason {
218 // This method is called whenever an attribute is added, changed or removed.
219 virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly);
220 virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
222 // Only called by the parser immediately after element construction.
223 void parserSetAttributes(const Vector<Attribute>&);
225 // Remove attributes that might introduce scripting from the vector leaving the element unchanged.
226 void stripScriptingAttributes(Vector<Attribute>&) const;
228 const ElementData* elementData() const { return m_elementData.get(); }
229 static ptrdiff_t elementDataMemoryOffset() { return OBJECT_OFFSETOF(Element, m_elementData); }
230 UniqueElementData& ensureUniqueElementData();
232 void synchronizeAllAttributes() const;
234 // Clones attributes only.
235 void cloneAttributesFromElement(const Element&);
237 // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
238 void cloneDataFromElement(const Element&);
240 bool hasEquivalentAttributes(const Element* other) const;
242 virtual void copyNonAttributePropertiesFromElement(const Element&) { }
244 virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&);
245 virtual bool rendererIsNeeded(const RenderStyle&);
247 WEBCORE_EXPORT ShadowRoot* shadowRoot() const;
248 WEBCORE_EXPORT RefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
250 ShadowRoot* userAgentShadowRoot() const;
251 ShadowRoot& ensureUserAgentShadowRoot();
253 // FIXME: this should not be virtual, do not override this.
254 virtual const AtomicString& shadowPseudoId() const;
256 bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
257 bool active() const { return isUserActionElement() && isUserActionElementActive(); }
258 bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
259 bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
261 virtual void setActive(bool flag = true, bool pause = false);
262 virtual void setHovered(bool flag = true);
263 virtual void setFocus(bool flag);
265 virtual bool supportsFocus() const;
266 virtual bool isFocusable() const;
267 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
268 virtual bool isMouseFocusable() const;
270 virtual bool shouldUseInputMethod();
272 virtual short tabIndex() const;
273 void setTabIndex(int);
274 virtual Element* focusDelegate();
276 virtual RenderStyle* computedStyle(PseudoId = NOPSEUDO) override;
278 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
279 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
280 bool childrenAffectedByHover() const { return getFlag(ChildrenAffectedByHoverRulesFlag); }
281 bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
282 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
283 bool childrenAffectedByFirstChildRules() const { return getFlag(ChildrenAffectedByFirstChildRulesFlag); }
284 bool childrenAffectedByLastChildRules() const { return getFlag(ChildrenAffectedByLastChildRulesFlag); }
285 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
286 bool childrenAffectedByPropertyBasedBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules(); }
287 bool affectsNextSiblingElementStyle() const { return getFlag(AffectsNextSiblingElementStyle); }
288 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
290 bool hasFlagsSetDuringStylingOfChildren() const;
292 void setStyleAffectedByEmpty();
293 void setChildrenAffectedByHover() { setFlag(ChildrenAffectedByHoverRulesFlag); }
294 void setChildrenAffectedByActive();
295 void setChildrenAffectedByDrag();
296 void setChildrenAffectedByFirstChildRules() { setFlag(ChildrenAffectedByFirstChildRulesFlag); }
297 void setChildrenAffectedByLastChildRules() { setFlag(ChildrenAffectedByLastChildRulesFlag); }
298 void setChildrenAffectedByBackwardPositionalRules();
299 void setChildrenAffectedByPropertyBasedBackwardPositionalRules();
300 void setAffectsNextSiblingElementStyle() { setFlag(AffectsNextSiblingElementStyle); }
301 void setStyleIsAffectedByPreviousSibling() { setFlag(StyleIsAffectedByPreviousSibling); }
302 void setChildIndex(unsigned);
304 void setRegionOversetState(RegionOversetState);
305 RegionOversetState regionOversetState() const;
307 AtomicString computeInheritedLanguage() const;
308 Locale& locale() const;
310 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
312 virtual bool isURLAttribute(const Attribute&) const { return false; }
313 virtual bool attributeContainsURL(const Attribute& attribute) const { return isURLAttribute(attribute); }
314 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const;
315 virtual bool isHTMLContentAttribute(const Attribute&) const { return false; }
317 WEBCORE_EXPORT URL getURLAttribute(const QualifiedName&) const;
318 URL getNonEmptyURLAttribute(const QualifiedName&) const;
320 virtual const AtomicString& imageSourceURL() const;
321 virtual String target() const { return String(); }
323 void updateFocusAppearanceAfterAttachIfNeeded();
324 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
325 virtual void updateFocusAppearance(bool restorePreviousSelection);
328 String innerHTML() const;
329 String outerHTML() const;
330 void setInnerHTML(const String&, ExceptionCode&);
331 void setOuterHTML(const String&, ExceptionCode&);
332 WEBCORE_EXPORT String innerText();
335 virtual String title() const;
337 const AtomicString& pseudo() const;
338 WEBCORE_EXPORT void setPseudo(const AtomicString&);
340 LayoutSize minimumSizeForResizing() const;
341 void setMinimumSizeForResizing(const LayoutSize&);
343 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
344 virtual void documentWillSuspendForPageCache() { }
345 virtual void documentDidResumeFromPageCache() { }
347 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
348 virtual void mediaVolumeDidChange() { }
350 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
351 virtual void privateBrowsingStateDidChange() { }
353 virtual void didBecomeFullscreenElement() { }
354 virtual void willStopBeingFullscreenElement() { }
356 // Use Document::registerForVisibilityStateChangedCallbacks() to subscribe to this.
357 virtual void visibilityStateChanged() { }
359 #if ENABLE(VIDEO_TRACK)
360 virtual void captionPreferencesChanged() { }
363 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
364 virtual void finishParsingChildren() override;
365 virtual void beginParsingChildren() override final;
367 WEBCORE_EXPORT PseudoElement* beforePseudoElement() const;
368 WEBCORE_EXPORT PseudoElement* afterPseudoElement() const;
369 bool childNeedsShadowWalker() const;
370 void didShadowTreeAwareChildrenChange();
372 // ElementTraversal API
373 Element* firstElementChild() const;
374 Element* lastElementChild() const;
375 Element* previousElementSibling() const;
376 Element* nextElementSibling() const;
377 unsigned childElementCount() const;
379 virtual bool matchesReadWritePseudoClass() const;
380 bool matches(const String& selectors, ExceptionCode&);
381 Element* closest(const String& selectors, ExceptionCode&);
382 virtual bool shouldAppearIndeterminate() const;
384 DOMTokenList& classList();
386 DatasetDOMStringMap& dataset();
389 virtual bool isMediaElement() const { return false; }
392 virtual bool matchesValidPseudoClass() const { return false; }
393 virtual bool matchesInvalidPseudoClass() const { return false; }
394 virtual bool isFormControlElement() const { return false; }
395 virtual bool isSpinButtonElement() const { return false; }
396 virtual bool isTextFormControl() const { return false; }
397 virtual bool isOptionalFormControl() const { return false; }
398 virtual bool isRequiredFormControl() const { return false; }
399 virtual bool isDefaultButtonForForm() const { return false; }
400 virtual bool isInRange() const { return false; }
401 virtual bool isOutOfRange() const { return false; }
402 virtual bool isFrameElementBase() const { return false; }
403 virtual bool isSearchFieldCancelButtonElement() const { return false; }
405 virtual bool canContainRangeEndPoint() const override;
407 // Used for disabled form elements; if true, prevents mouse events from being dispatched
408 // to event listeners, and prevents DOMActivate events from being sent at all.
409 virtual bool isDisabledFormControl() const { return false; }
411 virtual bool childShouldCreateRenderer(const Node&) const;
413 bool hasPendingResources() const;
414 void setHasPendingResources();
415 void clearHasPendingResources();
416 virtual void buildPendingResource() { };
418 #if ENABLE(FULLSCREEN_API)
420 ALLOW_KEYBOARD_INPUT = 1 << 0,
421 LEGACY_MOZILLA_REQUEST = 1 << 1,
424 void webkitRequestFullScreen(unsigned short flags);
425 WEBCORE_EXPORT bool containsFullScreenElement() const;
426 void setContainsFullScreenElement(bool);
427 void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
430 void webkitRequestFullscreen();
433 #if ENABLE(POINTER_LOCK)
434 void requestPointerLock();
438 void setUIActions(const AtomicString&);
439 const AtomicString& UIActions() const;
442 virtual bool isSpellCheckingEnabled() const;
444 RenderNamedFlowFragment* renderNamedFlowFragment() const;
446 #if ENABLE(CSS_REGIONS)
447 virtual bool shouldMoveToFlowThread(const RenderStyle&) const;
449 const AtomicString& webkitRegionOverset() const;
450 Vector<RefPtr<Range>> webkitGetRegionFlowRanges() const;
454 bool hasClass() const;
455 bool hasName() const;
456 const SpaceSplitString& classNames() const;
458 IntSize savedLayerScrollOffset() const;
459 void setSavedLayerScrollOffset(const IntSize&);
461 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Element* relatedTarget = nullptr);
462 bool dispatchWheelEvent(const PlatformWheelEvent&);
463 bool dispatchKeyEvent(const PlatformKeyboardEvent&);
464 void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
465 void dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement);
466 void dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement);
467 virtual void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, FocusDirection);
468 virtual void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement);
470 virtual bool willRecalcStyle(Style::Change);
471 virtual void didRecalcStyle(Style::Change);
472 virtual void willResetComputedStyle();
473 virtual void willAttachRenderers();
474 virtual void didAttachRenderers();
475 virtual void willDetachRenderers();
476 virtual void didDetachRenderers();
477 virtual RefPtr<RenderStyle> customStyleForRenderer(RenderStyle& parentStyle);
479 void setBeforePseudoElement(Ref<PseudoElement>&&);
480 void setAfterPseudoElement(Ref<PseudoElement>&&);
481 void clearBeforePseudoElement();
482 void clearAfterPseudoElement();
483 void resetComputedStyle();
484 void clearStyleDerivedDataBeforeDetachingRenderer();
485 void clearHoverAndActiveStatusBeforeDetachingRenderer();
487 WEBCORE_EXPORT URL absoluteLinkURL() const;
488 WeakPtr<Element> createWeakPtr();
491 Element(const QualifiedName&, Document&, ConstructionType);
493 virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
494 virtual void removedFrom(ContainerNode&) override;
495 virtual void childrenChanged(const ChildChange&) override;
496 virtual void removeAllEventListeners() override final;
497 virtual void parserDidSetAttributes();
499 void clearTabIndexExplicitlyIfNeeded();
500 void setTabIndexExplicitly(short);
502 Ref<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
503 HTMLCollection* cachedHTMLCollection(CollectionType);
505 // classAttributeChanged() exists to share code between
506 // parseAttribute (called via setAttribute()) and
507 // svgAttributeChanged (called when element.className.baseValue is set)
508 void classAttributeChanged(const AtomicString& newClassString);
510 static void mergeWithNextTextNode(Text& node, ExceptionCode&);
513 bool isTextNode() const;
515 bool isUserActionElementInActiveChain() const;
516 bool isUserActionElementActive() const;
517 bool isUserActionElementFocused() const;
518 bool isUserActionElementHovered() const;
520 void resetNeedsNodeRenderingTraversalSlowPath();
522 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
523 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
525 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
528 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
530 void didAddAttribute(const QualifiedName&, const AtomicString&);
531 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
532 void didModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
533 void didRemoveAttribute(const QualifiedName&, const AtomicString& oldValue);
535 void synchronizeAttribute(const QualifiedName&) const;
536 void synchronizeAttribute(const AtomicString& localName) const;
538 void updateName(const AtomicString& oldName, const AtomicString& newName);
539 void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName);
540 void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName);
541 void updateId(const AtomicString& oldId, const AtomicString& newId);
542 void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId);
543 enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute };
544 void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition);
545 void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
547 void scrollByUnits(int units, ScrollGranularity);
549 virtual void setPrefix(const AtomicString&, ExceptionCode&) override final;
550 virtual NodeType nodeType() const override final;
551 virtual bool childTypeAllowed(NodeType) const override final;
553 void setAttributeInternal(unsigned index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
554 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
555 void removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute);
557 #if ENABLE(TREE_DEBUGGING)
558 virtual void formatForDebugger(char* buffer, unsigned length) const override;
561 void cancelFocusAppearanceUpdate();
563 // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
565 virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
566 virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&);
568 void addShadowRoot(Ref<ShadowRoot>&&);
569 void removeShadowRoot();
571 bool rareDataStyleAffectedByEmpty() const;
572 bool rareDataChildrenAffectedByHover() const;
573 bool rareDataChildrenAffectedByActive() const;
574 bool rareDataChildrenAffectedByDrag() const;
575 bool rareDataChildrenAffectedByLastChildRules() const;
576 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
577 bool rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules() const;
578 unsigned rareDataChildIndex() const;
580 SpellcheckAttributeState spellcheckAttributeState() const;
582 void unregisterNamedFlowContentElement();
584 void createUniqueElementData();
586 ElementRareData* elementRareData() const;
587 ElementRareData& ensureElementRareData();
589 void detachAllAttrNodesFromElement();
590 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
592 bool isJavaScriptURLAttribute(const Attribute&) const;
594 // Anyone thinking of using this should call document instead of ownerDocument.
595 void ownerDocument() const = delete;
597 QualifiedName m_tagName;
598 RefPtr<ElementData> m_elementData;
601 inline bool Node::hasAttributes() const
603 return is<Element>(*this) && downcast<Element>(*this).hasAttributes();
606 inline NamedNodeMap* Node::attributes() const
608 return is<Element>(*this) ? &downcast<Element>(*this).attributes() : nullptr;
611 inline Element* Node::parentElement() const
613 ContainerNode* parent = parentNode();
614 return is<Element>(parent) ? downcast<Element>(parent) : nullptr;
617 inline bool Element::fastHasAttribute(const QualifiedName& name) const
619 ASSERT(fastAttributeLookupAllowed(name));
620 return elementData() && findAttributeByName(name);
623 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
625 ASSERT(fastAttributeLookupAllowed(name));
627 if (const Attribute* attribute = findAttributeByName(name))
628 return attribute->value();
633 inline bool Element::hasAttributesWithoutUpdate() const
635 return elementData() && !elementData()->isEmpty();
638 inline const AtomicString& Element::idForStyleResolution() const
641 return elementData()->idForStyleResolution();
644 inline const AtomicString& Element::getIdAttribute() const
647 return elementData()->findAttributeByName(HTMLNames::idAttr)->value();
651 inline const AtomicString& Element::getNameAttribute() const
654 return elementData()->findAttributeByName(HTMLNames::nameAttr)->value();
658 inline void Element::setIdAttribute(const AtomicString& value)
660 setAttribute(HTMLNames::idAttr, value);
663 inline const SpaceSplitString& Element::classNames() const
666 ASSERT(elementData());
667 return elementData()->classNames();
670 inline unsigned Element::attributeCount() const
672 ASSERT(elementData());
673 return elementData()->length();
676 inline const Attribute& Element::attributeAt(unsigned index) const
678 ASSERT(elementData());
679 return elementData()->attributeAt(index);
682 inline const Attribute* Element::findAttributeByName(const QualifiedName& name) const
684 ASSERT(elementData());
685 return elementData()->findAttributeByName(name);
688 inline bool Element::hasID() const
690 return elementData() && elementData()->hasID();
693 inline bool Element::hasClass() const
695 return elementData() && elementData()->hasClass();
698 inline bool Element::hasName() const
700 return elementData() && elementData()->hasName();
703 inline UniqueElementData& Element::ensureUniqueElementData()
705 if (!elementData() || !elementData()->isUnique())
706 createUniqueElementData();
707 return static_cast<UniqueElementData&>(*m_elementData);
710 } // namespace WebCore
712 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Element)
713 static bool isType(const WebCore::Node& node) { return node.isElementNode(); }
714 SPECIALIZE_TYPE_TRAITS_END()