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 "AXTextStateChangeIntent.h"
30 #include "ElementData.h"
31 #include "HTMLNames.h"
32 #include "RegionOversetState.h"
33 #include "ScrollTypes.h"
34 #include "SimulatedClickOptions.h"
35 #include "StyleChange.h"
41 class DatasetDOMStringMap;
44 class ElementRareData;
48 class PlatformKeyboardEvent;
49 class PlatformMouseEvent;
50 class PlatformWheelEvent;
52 class RenderNamedFlowFragment;
53 class RenderTreePosition;
56 enum SpellcheckAttributeState {
57 SpellcheckAttributeTrue,
58 SpellcheckAttributeFalse,
59 SpellcheckAttributeDefault
62 class Element : public ContainerNode {
64 static Ref<Element> create(const QualifiedName&, Document&);
67 WEBCORE_EXPORT bool hasAttribute(const QualifiedName&) const;
68 WEBCORE_EXPORT const AtomicString& getAttribute(const QualifiedName&) const;
69 WEBCORE_EXPORT void setAttribute(const QualifiedName&, const AtomicString& value);
70 void setAttributeWithoutSynchronization(const QualifiedName&, const AtomicString& value);
71 void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
72 bool removeAttribute(const QualifiedName&);
74 // Typed getters and setters for language bindings.
75 int getIntegralAttribute(const QualifiedName& attributeName) const;
76 void setIntegralAttribute(const QualifiedName& attributeName, int value);
77 unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
78 void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
80 // Call this to get the value of an attribute that is known not to be the style
81 // attribute or one of the SVG animatable attributes.
82 bool fastHasAttribute(const QualifiedName&) const;
83 const AtomicString& fastGetAttribute(const QualifiedName&) const;
85 WEBCORE_EXPORT bool fastAttributeLookupAllowed(const QualifiedName&) const;
88 #ifdef DUMP_NODE_STATISTICS
89 bool hasNamedNodeMap() const;
91 bool hasAttributes() const;
92 // This variant will not update the potentially invalid attributes. To be used when not interested
93 // in style attribute or one of the SVG animation attributes.
94 bool hasAttributesWithoutUpdate() const;
96 WEBCORE_EXPORT bool hasAttribute(const AtomicString& name) const;
97 bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
99 WEBCORE_EXPORT const AtomicString& getAttribute(const AtomicString& name) const;
100 const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
102 WEBCORE_EXPORT void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
103 static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
104 void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
106 const AtomicString& getIdAttribute() const;
107 void setIdAttribute(const AtomicString&);
109 const AtomicString& getNameAttribute() const;
111 // Call this to get the value of the id attribute for style resolution purposes.
112 // The value will already be lowercased if the document is in compatibility mode,
113 // so this function is not suitable for non-style uses.
114 const AtomicString& idForStyleResolution() const;
116 // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
117 // before calling them.
118 AttributeIteratorAccessor attributesIterator() const { return elementData()->attributesIterator(); }
119 unsigned attributeCount() const;
120 const Attribute& attributeAt(unsigned index) const;
121 const Attribute* findAttributeByName(const QualifiedName&) const;
122 unsigned findAttributeIndexByName(const QualifiedName& name) const { return elementData()->findAttributeIndexByName(name); }
123 unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); }
125 void scrollIntoView(bool alignToTop = true);
126 void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
127 WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
129 void scrollByLines(int lines);
130 void scrollByPages(int pages);
134 double offsetWidth();
135 double offsetHeight();
137 bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const;
139 // FIXME: Replace uses of offsetParent in the platform with calls
140 // to the render layer and merge bindingsOffsetParent and offsetParent.
141 Element* bindingsOffsetParent();
143 Element* offsetParent();
146 double clientWidth();
147 double clientHeight();
148 virtual int scrollLeft();
149 virtual int scrollTop();
150 virtual void setScrollLeft(int);
151 virtual void setScrollTop(int);
152 virtual int scrollWidth();
153 virtual int scrollHeight();
155 WEBCORE_EXPORT IntRect boundsInRootViewSpace();
157 Ref<ClientRectList> getClientRects();
158 Ref<ClientRect> getBoundingClientRect();
160 // Returns the absolute bounding box translated into client coordinates.
161 WEBCORE_EXPORT IntRect clientRect() const;
162 // Returns the absolute bounding box translated into screen coordinates.
163 WEBCORE_EXPORT IntRect screenRect() const;
165 bool removeAttribute(const AtomicString& name);
166 bool removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
168 RefPtr<Attr> detachAttribute(unsigned index);
170 RefPtr<Attr> getAttributeNode(const AtomicString& name);
171 RefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
172 RefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
173 RefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
174 RefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
176 RefPtr<Attr> attrIfExists(const QualifiedName&);
177 RefPtr<Attr> attrIfExists(const AtomicString& localName, bool shouldIgnoreAttributeCase);
178 RefPtr<Attr> ensureAttr(const QualifiedName&);
180 const Vector<RefPtr<Attr>>& attrNodeList();
182 virtual CSSStyleDeclaration* style();
184 const QualifiedName& tagQName() const { return m_tagName; }
185 #if ENABLE(CSS_SELECTOR_JIT)
186 static ptrdiff_t tagQNameMemoryOffset() { return OBJECT_OFFSETOF(Element, m_tagName); }
187 #endif // ENABLE(CSS_SELECTOR_JIT)
188 String tagName() const { return nodeName(); }
189 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
190 bool hasTagName(const HTMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
191 bool hasTagName(const MathMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
192 bool hasTagName(const SVGQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
194 // A fast function for checking the local name against another atomic string.
195 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
197 virtual const AtomicString& localName() const override final { return m_tagName.localName(); }
198 virtual const AtomicString& prefix() const override final { return m_tagName.prefix(); }
199 virtual const AtomicString& namespaceURI() const override final { return m_tagName.namespaceURI(); }
201 virtual String nodeName() const override;
203 Ref<Element> cloneElementWithChildren(Document&);
204 Ref<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>&&, const RenderTreePosition&);
246 virtual bool rendererIsNeeded(const RenderStyle&);
248 WEBCORE_EXPORT ShadowRoot* shadowRoot() const;
249 WEBCORE_EXPORT RefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
251 ShadowRoot* bindingShadowRoot() const;
252 RefPtr<ShadowRoot> attachShadow(const Dictionary&, ExceptionCode&);
254 ShadowRoot* userAgentShadowRoot() const;
255 WEBCORE_EXPORT ShadowRoot& ensureUserAgentShadowRoot();
257 // FIXME: this should not be virtual, do not override this.
258 virtual const AtomicString& shadowPseudoId() const;
260 bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
261 bool active() const { return isUserActionElement() && isUserActionElementActive(); }
262 bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
263 bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
265 virtual void setActive(bool flag = true, bool pause = false);
266 virtual void setHovered(bool flag = true);
267 virtual void setFocus(bool flag);
269 virtual bool supportsFocus() const;
270 virtual bool isFocusable() const;
271 virtual bool isKeyboardFocusable(KeyboardEvent*) const;
272 virtual bool isMouseFocusable() const;
274 virtual bool shouldUseInputMethod();
276 virtual short tabIndex() const;
277 void setTabIndex(int);
278 virtual Element* focusDelegate();
280 virtual RenderStyle* computedStyle(PseudoId = NOPSEUDO) override;
282 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
283 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
284 bool childrenAffectedByHover() const { return getFlag(ChildrenAffectedByHoverRulesFlag); }
285 bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
286 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
287 bool childrenAffectedByFirstChildRules() const { return getFlag(ChildrenAffectedByFirstChildRulesFlag); }
288 bool childrenAffectedByLastChildRules() const { return getFlag(ChildrenAffectedByLastChildRulesFlag); }
289 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
290 bool childrenAffectedByPropertyBasedBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules(); }
291 bool affectsNextSiblingElementStyle() const { return getFlag(AffectsNextSiblingElementStyle); }
292 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
294 bool hasFlagsSetDuringStylingOfChildren() const;
296 void setStyleAffectedByEmpty();
297 void setChildrenAffectedByHover() { setFlag(ChildrenAffectedByHoverRulesFlag); }
298 void setChildrenAffectedByActive();
299 void setChildrenAffectedByDrag();
300 void setChildrenAffectedByFirstChildRules() { setFlag(ChildrenAffectedByFirstChildRulesFlag); }
301 void setChildrenAffectedByLastChildRules() { setFlag(ChildrenAffectedByLastChildRulesFlag); }
302 void setChildrenAffectedByBackwardPositionalRules();
303 void setChildrenAffectedByPropertyBasedBackwardPositionalRules();
304 void setAffectsNextSiblingElementStyle() { setFlag(AffectsNextSiblingElementStyle); }
305 void setStyleIsAffectedByPreviousSibling() { setFlag(StyleIsAffectedByPreviousSibling); }
306 void setChildIndex(unsigned);
308 void setRegionOversetState(RegionOversetState);
309 RegionOversetState regionOversetState() const;
311 AtomicString computeInheritedLanguage() const;
312 Locale& locale() const;
314 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
316 virtual bool isURLAttribute(const Attribute&) const { return false; }
317 virtual bool attributeContainsURL(const Attribute& attribute) const { return isURLAttribute(attribute); }
318 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const;
319 virtual bool isHTMLContentAttribute(const Attribute&) const { return false; }
321 WEBCORE_EXPORT URL getURLAttribute(const QualifiedName&) const;
322 URL getNonEmptyURLAttribute(const QualifiedName&) const;
324 virtual const AtomicString& imageSourceURL() const;
325 virtual String target() const { return String(); }
327 static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); }
328 void updateFocusAppearanceAfterAttachIfNeeded();
329 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
330 virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal);
333 String innerHTML() const;
334 String outerHTML() const;
335 void setInnerHTML(const String&, ExceptionCode&);
336 void setOuterHTML(const String&, ExceptionCode&);
337 WEBCORE_EXPORT String innerText();
340 virtual String title() const;
342 const AtomicString& pseudo() const;
343 WEBCORE_EXPORT void setPseudo(const AtomicString&);
345 LayoutSize minimumSizeForResizing() const;
346 void setMinimumSizeForResizing(const LayoutSize&);
348 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
349 virtual void prepareForDocumentSuspension() { }
350 virtual void resumeFromDocumentSuspension() { }
352 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
353 virtual void mediaVolumeDidChange() { }
355 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
356 virtual void privateBrowsingStateDidChange() { }
358 virtual void didBecomeFullscreenElement() { }
359 virtual void willStopBeingFullscreenElement() { }
361 // Use Document::registerForVisibilityStateChangedCallbacks() to subscribe to this.
362 virtual void visibilityStateChanged() { }
364 #if ENABLE(VIDEO_TRACK)
365 virtual void captionPreferencesChanged() { }
368 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
369 virtual void finishParsingChildren() override;
370 virtual void beginParsingChildren() override final;
372 WEBCORE_EXPORT PseudoElement* beforePseudoElement() const;
373 WEBCORE_EXPORT PseudoElement* afterPseudoElement() const;
374 bool childNeedsShadowWalker() const;
375 void didShadowTreeAwareChildrenChange();
377 virtual bool matchesReadWritePseudoClass() const;
378 bool matches(const String& selectors, ExceptionCode&);
379 Element* closest(const String& selectors, ExceptionCode&);
380 virtual bool shouldAppearIndeterminate() const;
382 DOMTokenList& classList();
384 DatasetDOMStringMap& dataset();
387 virtual bool isMediaElement() const { return false; }
390 virtual bool matchesValidPseudoClass() const { return false; }
391 virtual bool matchesInvalidPseudoClass() const { return false; }
392 virtual bool isFormControlElement() const { return false; }
393 virtual bool isSpinButtonElement() const { return false; }
394 virtual bool isTextFormControl() const { return false; }
395 virtual bool isOptionalFormControl() const { return false; }
396 virtual bool isRequiredFormControl() const { return false; }
397 virtual bool isDefaultButtonForForm() const { return false; }
398 virtual bool isInRange() const { return false; }
399 virtual bool isOutOfRange() const { return false; }
400 virtual bool isFrameElementBase() const { return false; }
402 virtual bool canContainRangeEndPoint() const override;
404 // Used for disabled form elements; if true, prevents mouse events from being dispatched
405 // to event listeners, and prevents DOMActivate events from being sent at all.
406 virtual bool isDisabledFormControl() const { return false; }
408 virtual bool childShouldCreateRenderer(const Node&) const;
410 bool hasPendingResources() const;
411 void setHasPendingResources();
412 void clearHasPendingResources();
413 virtual void buildPendingResource() { };
415 #if ENABLE(FULLSCREEN_API)
417 ALLOW_KEYBOARD_INPUT = 1 << 0,
418 LEGACY_MOZILLA_REQUEST = 1 << 1,
421 void webkitRequestFullScreen(unsigned short flags);
422 WEBCORE_EXPORT bool containsFullScreenElement() const;
423 void setContainsFullScreenElement(bool);
424 void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
427 void webkitRequestFullscreen();
430 #if ENABLE(POINTER_LOCK)
431 void requestPointerLock();
435 void setUIActions(const AtomicString&);
436 const AtomicString& UIActions() const;
439 virtual bool isSpellCheckingEnabled() const;
441 RenderNamedFlowFragment* renderNamedFlowFragment() const;
443 #if ENABLE(CSS_REGIONS)
444 virtual bool shouldMoveToFlowThread(const RenderStyle&) const;
446 const AtomicString& webkitRegionOverset() const;
447 Vector<RefPtr<Range>> webkitGetRegionFlowRanges() const;
451 bool hasClass() const;
452 bool hasName() const;
453 const SpaceSplitString& classNames() const;
455 IntPoint savedLayerScrollPosition() const;
456 void setSavedLayerScrollPosition(const IntPoint&);
458 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Element* relatedTarget = nullptr);
459 bool dispatchWheelEvent(const PlatformWheelEvent&);
460 bool dispatchKeyEvent(const PlatformKeyboardEvent&);
461 void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
462 void dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement);
463 void dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement);
464 virtual void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, FocusDirection);
465 virtual void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement);
467 WEBCORE_EXPORT bool dispatchMouseForceWillBegin();
469 virtual bool willRecalcStyle(Style::Change);
470 virtual void didRecalcStyle(Style::Change);
471 virtual void willResetComputedStyle();
472 virtual void willAttachRenderers();
473 virtual void didAttachRenderers();
474 virtual void willDetachRenderers();
475 virtual void didDetachRenderers();
476 virtual RefPtr<RenderStyle> customStyleForRenderer(RenderStyle& parentStyle);
478 LayoutRect absoluteEventHandlerBounds(bool& includesFixedPositionElements) override;
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;
490 #if ENABLE(TOUCH_EVENTS)
491 virtual bool allowsDoubleTapGesture() const override;
494 StyleResolver& styleResolver();
495 Ref<RenderStyle> resolveStyle(RenderStyle* parentStyle);
497 virtual void isVisibleInViewportChanged() { }
500 Element(const QualifiedName&, Document&, ConstructionType);
502 virtual InsertionNotificationRequest insertedInto(ContainerNode&) override;
503 virtual void removedFrom(ContainerNode&) override;
504 virtual void childrenChanged(const ChildChange&) override;
505 virtual void removeAllEventListeners() override final;
506 virtual void parserDidSetAttributes();
508 void clearTabIndexExplicitlyIfNeeded();
509 void setTabIndexExplicitly(short);
511 // classAttributeChanged() exists to share code between
512 // parseAttribute (called via setAttribute()) and
513 // svgAttributeChanged (called when element.className.baseValue is set)
514 void classAttributeChanged(const AtomicString& newClassString);
516 void addShadowRoot(Ref<ShadowRoot>&&);
518 static void mergeWithNextTextNode(Text& node, ExceptionCode&);
521 bool isTextNode() const;
523 bool isUserActionElementInActiveChain() const;
524 bool isUserActionElementActive() const;
525 bool isUserActionElementFocused() const;
526 bool isUserActionElementHovered() const;
528 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
529 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
531 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
534 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
536 void didAddAttribute(const QualifiedName&, const AtomicString&);
537 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
538 void didModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
539 void didRemoveAttribute(const QualifiedName&, const AtomicString& oldValue);
541 void synchronizeAttribute(const QualifiedName&) const;
542 void synchronizeAttribute(const AtomicString& localName) const;
544 void updateName(const AtomicString& oldName, const AtomicString& newName);
545 void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName);
546 void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName);
548 enum class NotifyObservers { No, Yes };
549 void updateId(const AtomicString& oldId, const AtomicString& newId, NotifyObservers = NotifyObservers::Yes);
550 void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId, NotifyObservers = NotifyObservers::Yes);
552 enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute };
553 void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition);
554 void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
556 void scrollByUnits(int units, ScrollGranularity);
558 virtual void setPrefix(const AtomicString&, ExceptionCode&) override final;
559 virtual NodeType nodeType() const override final;
560 virtual bool childTypeAllowed(NodeType) const override final;
562 void setAttributeInternal(unsigned index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
563 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
564 void removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute);
566 LayoutRect absoluteEventBounds(bool& boundsIncludeAllDescendantElements, bool& includesFixedPositionElements);
567 LayoutRect absoluteEventBoundsOfElementAndDescendants(bool& includesFixedPositionElements);
569 #if ENABLE(TREE_DEBUGGING)
570 virtual void formatForDebugger(char* buffer, unsigned length) const override;
573 void cancelFocusAppearanceUpdate();
575 // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
577 virtual Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
578 virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&);
580 void removeShadowRoot();
582 RenderStyle* existingComputedStyle();
583 RenderStyle& resolveComputedStyle();
585 bool rareDataStyleAffectedByEmpty() const;
586 bool rareDataChildrenAffectedByHover() const;
587 bool rareDataChildrenAffectedByActive() const;
588 bool rareDataChildrenAffectedByDrag() const;
589 bool rareDataChildrenAffectedByLastChildRules() const;
590 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
591 bool rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules() const;
592 unsigned rareDataChildIndex() const;
594 SpellcheckAttributeState spellcheckAttributeState() const;
596 void unregisterNamedFlowContentElement();
598 void createUniqueElementData();
600 ElementRareData* elementRareData() const;
601 ElementRareData& ensureElementRareData();
603 void detachAllAttrNodesFromElement();
604 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
606 bool isJavaScriptURLAttribute(const Attribute&) const;
608 // Anyone thinking of using this should call document instead of ownerDocument.
609 void ownerDocument() const = delete;
611 QualifiedName m_tagName;
612 RefPtr<ElementData> m_elementData;
615 inline bool Node::hasAttributes() const
617 return is<Element>(*this) && downcast<Element>(*this).hasAttributes();
620 inline NamedNodeMap* Node::attributes() const
622 return is<Element>(*this) ? &downcast<Element>(*this).attributes() : nullptr;
625 inline Element* Node::parentElement() const
627 ContainerNode* parent = parentNode();
628 return is<Element>(parent) ? downcast<Element>(parent) : nullptr;
631 inline bool Element::fastHasAttribute(const QualifiedName& name) const
633 ASSERT(fastAttributeLookupAllowed(name));
634 return elementData() && findAttributeByName(name);
637 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
639 ASSERT(fastAttributeLookupAllowed(name));
641 if (const Attribute* attribute = findAttributeByName(name))
642 return attribute->value();
647 inline bool Element::hasAttributesWithoutUpdate() const
649 return elementData() && !elementData()->isEmpty();
652 inline const AtomicString& Element::idForStyleResolution() const
655 return elementData()->idForStyleResolution();
658 inline const AtomicString& Element::getIdAttribute() const
661 return elementData()->findAttributeByName(HTMLNames::idAttr)->value();
665 inline const AtomicString& Element::getNameAttribute() const
668 return elementData()->findAttributeByName(HTMLNames::nameAttr)->value();
672 inline void Element::setIdAttribute(const AtomicString& value)
674 setAttribute(HTMLNames::idAttr, value);
677 inline const SpaceSplitString& Element::classNames() const
680 ASSERT(elementData());
681 return elementData()->classNames();
684 inline unsigned Element::attributeCount() const
686 ASSERT(elementData());
687 return elementData()->length();
690 inline const Attribute& Element::attributeAt(unsigned index) const
692 ASSERT(elementData());
693 return elementData()->attributeAt(index);
696 inline const Attribute* Element::findAttributeByName(const QualifiedName& name) const
698 ASSERT(elementData());
699 return elementData()->findAttributeByName(name);
702 inline bool Element::hasID() const
704 return elementData() && elementData()->hasID();
707 inline bool Element::hasClass() const
709 return elementData() && elementData()->hasClass();
712 inline bool Element::hasName() const
714 return elementData() && elementData()->hasName();
717 inline UniqueElementData& Element::ensureUniqueElementData()
719 if (!elementData() || !elementData()->isUnique())
720 createUniqueElementData();
721 return static_cast<UniqueElementData&>(*m_elementData);
724 inline bool shouldIgnoreAttributeCase(const Element& element)
726 return element.isHTMLElement() && element.document().isHTMLDocument();
729 } // namespace WebCore
731 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Element)
732 static bool isType(const WebCore::Node& node) { return node.isElementNode(); }
733 SPECIALIZE_TYPE_TRAITS_END()