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);
125 WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
127 void scrollByLines(int lines);
128 void scrollByPages(int pages);
132 double offsetWidth();
133 double offsetHeight();
135 bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const;
137 // FIXME: Replace uses of offsetParent in the platform with calls
138 // to the render layer and merge bindingsOffsetParent and offsetParent.
139 Element* bindingsOffsetParent();
141 Element* offsetParent();
144 double clientWidth();
145 double clientHeight();
146 virtual int scrollLeft();
147 virtual int scrollTop();
148 virtual void setScrollLeft(int);
149 virtual void setScrollTop(int);
150 virtual int scrollWidth();
151 virtual int scrollHeight();
153 WEBCORE_EXPORT IntRect boundsInRootViewSpace();
155 Ref<ClientRectList> getClientRects();
156 Ref<ClientRect> getBoundingClientRect();
158 // Returns the absolute bounding box translated into client coordinates.
159 WEBCORE_EXPORT IntRect clientRect() const;
160 // Returns the absolute bounding box translated into screen coordinates.
161 WEBCORE_EXPORT IntRect screenRect() const;
163 bool removeAttribute(const AtomicString& name);
164 bool removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
166 RefPtr<Attr> detachAttribute(unsigned index);
168 RefPtr<Attr> getAttributeNode(const AtomicString& name);
169 RefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
170 RefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
171 RefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
172 RefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
174 RefPtr<Attr> attrIfExists(const QualifiedName&);
175 RefPtr<Attr> attrIfExists(const AtomicString& localName, bool shouldIgnoreAttributeCase);
176 RefPtr<Attr> ensureAttr(const QualifiedName&);
178 const Vector<RefPtr<Attr>>& attrNodeList();
180 virtual CSSStyleDeclaration* style();
182 const QualifiedName& tagQName() const { return m_tagName; }
183 #if ENABLE(CSS_SELECTOR_JIT)
184 static ptrdiff_t tagQNameMemoryOffset() { return OBJECT_OFFSETOF(Element, m_tagName); }
185 #endif // ENABLE(CSS_SELECTOR_JIT)
186 String tagName() const { return nodeName(); }
187 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
188 bool hasTagName(const HTMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
189 bool hasTagName(const MathMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
190 bool hasTagName(const SVGQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
192 // A fast function for checking the local name against another atomic string.
193 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
195 virtual const AtomicString& localName() const override final { return m_tagName.localName(); }
196 virtual const AtomicString& prefix() const override final { return m_tagName.prefix(); }
197 virtual const AtomicString& namespaceURI() const override final { return m_tagName.namespaceURI(); }
199 virtual URL baseURI() const override final;
201 virtual String nodeName() const override;
203 RefPtr<Element> cloneElementWithChildren(Document&);
204 RefPtr<Element> cloneElementWithoutChildren(Document&);
206 void normalizeAttributes();
207 String nodeNamePreservingCase() const;
209 void setBooleanAttribute(const QualifiedName& name, bool);
211 // For exposing to DOM only.
212 NamedNodeMap& attributes() const;
214 enum AttributeModificationReason {
219 // This method is called whenever an attribute is added, changed or removed.
220 virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly);
221 virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
223 // Only called by the parser immediately after element construction.
224 void parserSetAttributes(const Vector<Attribute>&);
226 // Remove attributes that might introduce scripting from the vector leaving the element unchanged.
227 void stripScriptingAttributes(Vector<Attribute>&) const;
229 const ElementData* elementData() const { return m_elementData.get(); }
230 static ptrdiff_t elementDataMemoryOffset() { return OBJECT_OFFSETOF(Element, m_elementData); }
231 UniqueElementData& ensureUniqueElementData();
233 void synchronizeAllAttributes() const;
235 // Clones attributes only.
236 void cloneAttributesFromElement(const Element&);
238 // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
239 void cloneDataFromElement(const Element&);
241 bool hasEquivalentAttributes(const Element* other) const;
243 virtual void copyNonAttributePropertiesFromElement(const Element&) { }
245 virtual RenderPtr<RenderElement> createElementRenderer(Ref<RenderStyle>&&);
246 virtual bool rendererIsNeeded(const RenderStyle&);
248 WEBCORE_EXPORT ShadowRoot* shadowRoot() const;
249 WEBCORE_EXPORT RefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
251 ShadowRoot* userAgentShadowRoot() const;
252 ShadowRoot& ensureUserAgentShadowRoot();
254 // FIXME: this should not be virtual, do not override this.
255 virtual const AtomicString& shadowPseudoId() const;
257 bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
258 bool active() const { return isUserActionElement() && isUserActionElementActive(); }
259 bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
260 bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
262 virtual void setActive(bool flag = true, bool pause = false);
263 virtual void setHovered(bool flag = true);
264 virtual void setFocus(bool flag);
266 virtual bool supportsFocus() const;
267 virtual bool isFocusable() const;
268 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
269 virtual bool isMouseFocusable() const;
271 virtual bool shouldUseInputMethod();
273 virtual short tabIndex() const;
274 void setTabIndex(int);
275 virtual Element* focusDelegate();
277 virtual RenderStyle* computedStyle(PseudoId = NOPSEUDO) override;
279 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
280 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
281 bool childrenAffectedByHover() const { return getFlag(ChildrenAffectedByHoverRulesFlag); }
282 bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
283 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
284 bool childrenAffectedByFirstChildRules() const { return getFlag(ChildrenAffectedByFirstChildRulesFlag); }
285 bool childrenAffectedByLastChildRules() const { return getFlag(ChildrenAffectedByLastChildRulesFlag); }
286 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
287 bool childrenAffectedByPropertyBasedBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules(); }
288 bool affectsNextSiblingElementStyle() const { return getFlag(AffectsNextSiblingElementStyle); }
289 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
291 bool hasFlagsSetDuringStylingOfChildren() const;
293 void setStyleAffectedByEmpty();
294 void setChildrenAffectedByHover() { setFlag(ChildrenAffectedByHoverRulesFlag); }
295 void setChildrenAffectedByActive();
296 void setChildrenAffectedByDrag();
297 void setChildrenAffectedByFirstChildRules() { setFlag(ChildrenAffectedByFirstChildRulesFlag); }
298 void setChildrenAffectedByLastChildRules() { setFlag(ChildrenAffectedByLastChildRulesFlag); }
299 void setChildrenAffectedByBackwardPositionalRules();
300 void setChildrenAffectedByPropertyBasedBackwardPositionalRules();
301 void setAffectsNextSiblingElementStyle() { setFlag(AffectsNextSiblingElementStyle); }
302 void setStyleIsAffectedByPreviousSibling() { setFlag(StyleIsAffectedByPreviousSibling); }
303 void setChildIndex(unsigned);
305 void setRegionOversetState(RegionOversetState);
306 RegionOversetState regionOversetState() const;
308 AtomicString computeInheritedLanguage() const;
309 Locale& locale() const;
311 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
313 virtual bool isURLAttribute(const Attribute&) const { return false; }
314 virtual bool attributeContainsURL(const Attribute& attribute) const { return isURLAttribute(attribute); }
315 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const;
316 virtual bool isHTMLContentAttribute(const Attribute&) const { return false; }
318 WEBCORE_EXPORT URL getURLAttribute(const QualifiedName&) const;
319 URL getNonEmptyURLAttribute(const QualifiedName&) const;
321 virtual const AtomicString& imageSourceURL() const;
322 virtual String target() const { return String(); }
324 void updateFocusAppearanceAfterAttachIfNeeded();
325 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
326 virtual void updateFocusAppearance(bool restorePreviousSelection);
329 String innerHTML() const;
330 String outerHTML() const;
331 void setInnerHTML(const String&, ExceptionCode&);
332 void setOuterHTML(const String&, ExceptionCode&);
333 WEBCORE_EXPORT String innerText();
336 virtual String title() const;
338 const AtomicString& pseudo() const;
339 WEBCORE_EXPORT void setPseudo(const AtomicString&);
341 LayoutSize minimumSizeForResizing() const;
342 void setMinimumSizeForResizing(const LayoutSize&);
344 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
345 virtual void documentWillSuspendForPageCache() { }
346 virtual void documentDidResumeFromPageCache() { }
348 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
349 virtual void mediaVolumeDidChange() { }
351 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
352 virtual void privateBrowsingStateDidChange() { }
354 virtual void didBecomeFullscreenElement() { }
355 virtual void willStopBeingFullscreenElement() { }
357 // Use Document::registerForVisibilityStateChangedCallbacks() to subscribe to this.
358 virtual void visibilityStateChanged() { }
360 #if ENABLE(VIDEO_TRACK)
361 virtual void captionPreferencesChanged() { }
364 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
365 virtual void finishParsingChildren() override;
366 virtual void beginParsingChildren() override final;
368 WEBCORE_EXPORT PseudoElement* beforePseudoElement() const;
369 WEBCORE_EXPORT PseudoElement* afterPseudoElement() const;
370 bool childNeedsShadowWalker() const;
371 void didShadowTreeAwareChildrenChange();
373 // ElementTraversal API
374 Element* firstElementChild() const;
375 Element* lastElementChild() const;
376 Element* previousElementSibling() const;
377 Element* nextElementSibling() const;
378 unsigned childElementCount() const;
380 virtual bool matchesReadWritePseudoClass() const;
381 bool matches(const String& selectors, ExceptionCode&);
382 Element* closest(const String& selectors, ExceptionCode&);
383 virtual bool shouldAppearIndeterminate() const;
385 DOMTokenList& classList();
387 DatasetDOMStringMap& dataset();
390 virtual bool isMediaElement() const { return false; }
393 virtual bool matchesValidPseudoClass() const { return false; }
394 virtual bool matchesInvalidPseudoClass() const { return false; }
395 virtual bool isFormControlElement() const { return false; }
396 virtual bool isSpinButtonElement() const { return false; }
397 virtual bool isTextFormControl() const { return false; }
398 virtual bool isOptionalFormControl() const { return false; }
399 virtual bool isRequiredFormControl() const { return false; }
400 virtual bool isDefaultButtonForForm() const { return false; }
401 virtual bool isInRange() const { return false; }
402 virtual bool isOutOfRange() const { return false; }
403 virtual bool isFrameElementBase() const { return false; }
404 virtual bool isSearchFieldCancelButtonElement() const { return false; }
406 virtual bool canContainRangeEndPoint() const override;
408 // Used for disabled form elements; if true, prevents mouse events from being dispatched
409 // to event listeners, and prevents DOMActivate events from being sent at all.
410 virtual bool isDisabledFormControl() const { return false; }
412 virtual bool childShouldCreateRenderer(const Node&) const;
414 bool hasPendingResources() const;
415 void setHasPendingResources();
416 void clearHasPendingResources();
417 virtual void buildPendingResource() { };
419 #if ENABLE(FULLSCREEN_API)
421 ALLOW_KEYBOARD_INPUT = 1 << 0,
422 LEGACY_MOZILLA_REQUEST = 1 << 1,
425 void webkitRequestFullScreen(unsigned short flags);
426 WEBCORE_EXPORT bool containsFullScreenElement() const;
427 void setContainsFullScreenElement(bool);
428 void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
431 void webkitRequestFullscreen();
434 #if ENABLE(POINTER_LOCK)
435 void requestPointerLock();
439 void setUIActions(const AtomicString&);
440 const AtomicString& UIActions() const;
443 virtual bool isSpellCheckingEnabled() const;
445 RenderNamedFlowFragment* renderNamedFlowFragment() const;
447 #if ENABLE(CSS_REGIONS)
448 virtual bool shouldMoveToFlowThread(const RenderStyle&) const;
450 const AtomicString& webkitRegionOverset() const;
451 Vector<RefPtr<Range>> webkitGetRegionFlowRanges() const;
455 bool hasClass() const;
456 bool hasName() const;
457 const SpaceSplitString& classNames() const;
459 IntSize savedLayerScrollOffset() const;
460 void setSavedLayerScrollOffset(const IntSize&);
462 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Element* relatedTarget = nullptr);
463 bool dispatchWheelEvent(const PlatformWheelEvent&);
464 bool dispatchKeyEvent(const PlatformKeyboardEvent&);
465 void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
466 void dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement);
467 void dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement);
468 virtual void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, FocusDirection);
469 virtual void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement);
471 virtual bool willRecalcStyle(Style::Change);
472 virtual void didRecalcStyle(Style::Change);
473 virtual void willResetComputedStyle();
474 virtual void willAttachRenderers();
475 virtual void didAttachRenderers();
476 virtual void willDetachRenderers();
477 virtual void didDetachRenderers();
478 virtual RefPtr<RenderStyle> customStyleForRenderer(RenderStyle& parentStyle);
480 void setBeforePseudoElement(Ref<PseudoElement>&&);
481 void setAfterPseudoElement(Ref<PseudoElement>&&);
482 void clearBeforePseudoElement();
483 void clearAfterPseudoElement();
484 void resetComputedStyle();
485 void clearStyleDerivedDataBeforeDetachingRenderer();
486 void clearHoverAndActiveStatusBeforeDetachingRenderer();
488 WEBCORE_EXPORT URL absoluteLinkURL() const;
489 WeakPtr<Element> createWeakPtr();
492 Element(const QualifiedName&, Document&, ConstructionType);
494 virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
495 virtual void removedFrom(ContainerNode&) override;
496 virtual void childrenChanged(const ChildChange&) override;
497 virtual void removeAllEventListeners() override final;
498 virtual void parserDidSetAttributes();
500 void clearTabIndexExplicitlyIfNeeded();
501 void setTabIndexExplicitly(short);
503 Ref<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
504 HTMLCollection* cachedHTMLCollection(CollectionType);
506 // classAttributeChanged() exists to share code between
507 // parseAttribute (called via setAttribute()) and
508 // svgAttributeChanged (called when element.className.baseValue is set)
509 void classAttributeChanged(const AtomicString& newClassString);
511 static void mergeWithNextTextNode(Text& node, ExceptionCode&);
514 bool isTextNode() const;
516 bool isUserActionElementInActiveChain() const;
517 bool isUserActionElementActive() const;
518 bool isUserActionElementFocused() const;
519 bool isUserActionElementHovered() const;
521 void resetNeedsNodeRenderingTraversalSlowPath();
523 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
524 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
526 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
529 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
531 void didAddAttribute(const QualifiedName&, const AtomicString&);
532 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
533 void didModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
534 void didRemoveAttribute(const QualifiedName&, const AtomicString& oldValue);
536 void synchronizeAttribute(const QualifiedName&) const;
537 void synchronizeAttribute(const AtomicString& localName) const;
539 void updateName(const AtomicString& oldName, const AtomicString& newName);
540 void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName);
541 void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName);
542 void updateId(const AtomicString& oldId, const AtomicString& newId);
543 void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId);
544 enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute };
545 void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition);
546 void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
548 void scrollByUnits(int units, ScrollGranularity);
550 virtual void setPrefix(const AtomicString&, ExceptionCode&) override final;
551 virtual NodeType nodeType() const override final;
552 virtual bool childTypeAllowed(NodeType) const override final;
554 void setAttributeInternal(unsigned index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
555 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
556 void removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute);
558 #if ENABLE(TREE_DEBUGGING)
559 virtual void formatForDebugger(char* buffer, unsigned length) const override;
562 void cancelFocusAppearanceUpdate();
564 // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
566 virtual RefPtr<Node> cloneNodeInternal(Document&, CloningOperation) override;
567 virtual RefPtr<Element> cloneElementWithoutAttributesAndChildren(Document&);
569 void addShadowRoot(Ref<ShadowRoot>&&);
570 void removeShadowRoot();
572 bool rareDataStyleAffectedByEmpty() const;
573 bool rareDataChildrenAffectedByHover() const;
574 bool rareDataChildrenAffectedByActive() const;
575 bool rareDataChildrenAffectedByDrag() const;
576 bool rareDataChildrenAffectedByLastChildRules() const;
577 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
578 bool rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules() const;
579 unsigned rareDataChildIndex() const;
581 SpellcheckAttributeState spellcheckAttributeState() const;
583 void unregisterNamedFlowContentElement();
585 void createUniqueElementData();
587 ElementRareData* elementRareData() const;
588 ElementRareData& ensureElementRareData();
590 void detachAllAttrNodesFromElement();
591 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
593 bool isJavaScriptURLAttribute(const Attribute&) const;
595 // Anyone thinking of using this should call document instead of ownerDocument.
596 void ownerDocument() const = delete;
598 QualifiedName m_tagName;
599 RefPtr<ElementData> m_elementData;
602 inline bool Node::hasAttributes() const
604 return is<Element>(*this) && downcast<Element>(*this).hasAttributes();
607 inline NamedNodeMap* Node::attributes() const
609 return is<Element>(*this) ? &downcast<Element>(*this).attributes() : nullptr;
612 inline Element* Node::parentElement() const
614 ContainerNode* parent = parentNode();
615 return is<Element>(parent) ? downcast<Element>(parent) : nullptr;
618 inline bool Element::fastHasAttribute(const QualifiedName& name) const
620 ASSERT(fastAttributeLookupAllowed(name));
621 return elementData() && findAttributeByName(name);
624 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
626 ASSERT(fastAttributeLookupAllowed(name));
628 if (const Attribute* attribute = findAttributeByName(name))
629 return attribute->value();
634 inline bool Element::hasAttributesWithoutUpdate() const
636 return elementData() && !elementData()->isEmpty();
639 inline const AtomicString& Element::idForStyleResolution() const
642 return elementData()->idForStyleResolution();
645 inline const AtomicString& Element::getIdAttribute() const
648 return elementData()->findAttributeByName(HTMLNames::idAttr)->value();
652 inline const AtomicString& Element::getNameAttribute() const
655 return elementData()->findAttributeByName(HTMLNames::nameAttr)->value();
659 inline void Element::setIdAttribute(const AtomicString& value)
661 setAttribute(HTMLNames::idAttr, value);
664 inline const SpaceSplitString& Element::classNames() const
667 ASSERT(elementData());
668 return elementData()->classNames();
671 inline unsigned Element::attributeCount() const
673 ASSERT(elementData());
674 return elementData()->length();
677 inline const Attribute& Element::attributeAt(unsigned index) const
679 ASSERT(elementData());
680 return elementData()->attributeAt(index);
683 inline const Attribute* Element::findAttributeByName(const QualifiedName& name) const
685 ASSERT(elementData());
686 return elementData()->findAttributeByName(name);
689 inline bool Element::hasID() const
691 return elementData() && elementData()->hasID();
694 inline bool Element::hasClass() const
696 return elementData() && elementData()->hasClass();
699 inline bool Element::hasName() const
701 return elementData() && elementData()->hasName();
704 inline UniqueElementData& Element::ensureUniqueElementData()
706 if (!elementData() || !elementData()->isUnique())
707 createUniqueElementData();
708 return static_cast<UniqueElementData&>(*m_elementData);
711 } // namespace WebCore
713 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Element)
714 static bool isType(const WebCore::Node& node) { return node.isElementNode(); }
715 SPECIALIZE_TYPE_TRAITS_END()