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-2017 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.
27 #include "AXTextStateChangeIntent.h"
29 #include "ElementData.h"
30 #include "HTMLNames.h"
31 #include "ScrollToOptions.h"
32 #include "ScrollTypes.h"
33 #include "ShadowRootMode.h"
34 #include "SimulatedClickOptions.h"
35 #include "StyleChange.h"
39 class CustomElementReactionQueue;
40 class DatasetDOMStringMap;
44 class ElementRareData;
47 class JSCustomElementInterface;
50 class PlatformKeyboardEvent;
51 class PlatformMouseEvent;
52 class PlatformWheelEvent;
54 class RenderTreePosition;
58 enum SpellcheckAttributeState {
59 SpellcheckAttributeTrue,
60 SpellcheckAttributeFalse,
61 SpellcheckAttributeDefault
64 enum class SelectionRevealMode {
66 RevealUpToMainFrame, // Scroll overflow and iframes, but not the main frame.
70 class Element : public ContainerNode {
72 static Ref<Element> create(const QualifiedName&, Document&);
75 WEBCORE_EXPORT bool hasAttribute(const QualifiedName&) const;
76 WEBCORE_EXPORT const AtomicString& getAttribute(const QualifiedName&) const;
77 WEBCORE_EXPORT void setAttribute(const QualifiedName&, const AtomicString& value);
78 WEBCORE_EXPORT void setAttributeWithoutSynchronization(const QualifiedName&, const AtomicString& value);
79 void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
80 bool removeAttribute(const QualifiedName&);
81 Vector<String> getAttributeNames() const;
83 // Typed getters and setters for language bindings.
84 WEBCORE_EXPORT int getIntegralAttribute(const QualifiedName& attributeName) const;
85 WEBCORE_EXPORT void setIntegralAttribute(const QualifiedName& attributeName, int value);
86 WEBCORE_EXPORT unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
87 WEBCORE_EXPORT void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
89 // Call this to get the value of an attribute that is known not to be the style
90 // attribute or one of the SVG animatable attributes.
91 bool hasAttributeWithoutSynchronization(const QualifiedName&) const;
92 const AtomicString& attributeWithoutSynchronization(const QualifiedName&) const;
94 WEBCORE_EXPORT bool fastAttributeLookupAllowed(const QualifiedName&) const;
97 #ifdef DUMP_NODE_STATISTICS
98 bool hasNamedNodeMap() const;
100 WEBCORE_EXPORT bool hasAttributes() const;
101 // This variant will not update the potentially invalid attributes. To be used when not interested
102 // in style attribute or one of the SVG animation attributes.
103 bool hasAttributesWithoutUpdate() const;
105 WEBCORE_EXPORT bool hasAttribute(const AtomicString& name) const;
106 WEBCORE_EXPORT bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
108 WEBCORE_EXPORT const AtomicString& getAttribute(const AtomicString& name) const;
109 WEBCORE_EXPORT const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
111 WEBCORE_EXPORT ExceptionOr<void> setAttribute(const AtomicString& name, const AtomicString& value);
112 static ExceptionOr<QualifiedName> parseAttributeName(const AtomicString& namespaceURI, const AtomicString& qualifiedName);
113 WEBCORE_EXPORT ExceptionOr<void> setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value);
115 const AtomicString& getIdAttribute() const;
116 void setIdAttribute(const AtomicString&);
118 const AtomicString& getNameAttribute() const;
120 // Call this to get the value of the id attribute for style resolution purposes.
121 // The value will already be lowercased if the document is in compatibility mode,
122 // so this function is not suitable for non-style uses.
123 const AtomicString& idForStyleResolution() const;
125 // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
126 // before calling them.
127 AttributeIteratorAccessor attributesIterator() const { return elementData()->attributesIterator(); }
128 unsigned attributeCount() const;
129 const Attribute& attributeAt(unsigned index) const;
130 const Attribute* findAttributeByName(const QualifiedName&) const;
131 unsigned findAttributeIndexByName(const QualifiedName& name) const { return elementData()->findAttributeIndexByName(name); }
132 unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); }
134 WEBCORE_EXPORT void scrollIntoView(bool alignToTop = true);
135 WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
136 WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
138 void scrollBy(const ScrollToOptions&);
139 void scrollBy(double x, double y);
140 virtual void scrollTo(const ScrollToOptions&);
141 void scrollTo(double x, double y);
143 WEBCORE_EXPORT void scrollByLines(int lines);
144 WEBCORE_EXPORT void scrollByPages(int pages);
146 WEBCORE_EXPORT double offsetLeft();
147 WEBCORE_EXPORT double offsetTop();
148 WEBCORE_EXPORT double offsetWidth();
149 WEBCORE_EXPORT double offsetHeight();
151 bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const;
153 // FIXME: Replace uses of offsetParent in the platform with calls
154 // to the render layer and merge bindingsOffsetParent and offsetParent.
155 WEBCORE_EXPORT Element* bindingsOffsetParent();
157 const Element* rootElement() const;
159 Element* offsetParent();
160 WEBCORE_EXPORT double clientLeft();
161 WEBCORE_EXPORT double clientTop();
162 WEBCORE_EXPORT double clientWidth();
163 WEBCORE_EXPORT double clientHeight();
165 virtual int scrollLeft();
166 virtual int scrollTop();
167 virtual void setScrollLeft(int);
168 virtual void setScrollTop(int);
169 virtual int scrollWidth();
170 virtual int scrollHeight();
172 WEBCORE_EXPORT IntRect boundsInRootViewSpace();
174 FloatRect boundingClientRect();
176 WEBCORE_EXPORT Ref<DOMRectList> getClientRects();
177 Ref<DOMRect> getBoundingClientRect();
179 // Returns the absolute bounding box translated into client coordinates.
180 WEBCORE_EXPORT IntRect clientRect() const;
181 // Returns the absolute bounding box translated into screen coordinates.
182 WEBCORE_EXPORT IntRect screenRect() const;
184 WEBCORE_EXPORT bool removeAttribute(const AtomicString& name);
185 WEBCORE_EXPORT bool removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
187 Ref<Attr> detachAttribute(unsigned index);
189 WEBCORE_EXPORT RefPtr<Attr> getAttributeNode(const AtomicString& name);
190 WEBCORE_EXPORT RefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
191 WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setAttributeNode(Attr&);
192 WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setAttributeNodeNS(Attr&);
193 WEBCORE_EXPORT ExceptionOr<Ref<Attr>> removeAttributeNode(Attr&);
195 RefPtr<Attr> attrIfExists(const QualifiedName&);
196 RefPtr<Attr> attrIfExists(const AtomicString& localName, bool shouldIgnoreAttributeCase);
197 Ref<Attr> ensureAttr(const QualifiedName&);
199 const Vector<RefPtr<Attr>>& attrNodeList();
201 const QualifiedName& tagQName() const { return m_tagName; }
203 static ptrdiff_t tagQNameMemoryOffset() { return OBJECT_OFFSETOF(Element, m_tagName); }
204 #endif // ENABLE(JIT)
205 String tagName() const { return nodeName(); }
206 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
207 bool hasTagName(const HTMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
208 bool hasTagName(const MathMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
209 bool hasTagName(const SVGQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); }
211 // A fast function for checking the local name against another atomic string.
212 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
214 const AtomicString& localName() const final { return m_tagName.localName(); }
215 const AtomicString& prefix() const final { return m_tagName.prefix(); }
216 const AtomicString& namespaceURI() const final { return m_tagName.namespaceURI(); }
218 ExceptionOr<void> setPrefix(const AtomicString&) final;
220 String nodeName() const override;
222 Ref<Element> cloneElementWithChildren(Document&);
223 Ref<Element> cloneElementWithoutChildren(Document&);
225 void normalizeAttributes();
226 String nodeNamePreservingCase() const;
228 WEBCORE_EXPORT void setBooleanAttribute(const QualifiedName& name, bool);
230 // For exposing to DOM only.
231 WEBCORE_EXPORT NamedNodeMap& attributes() const;
233 enum AttributeModificationReason {
238 // This method is called whenever an attribute is added, changed or removed.
239 virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly);
240 virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
242 // Only called by the parser immediately after element construction.
243 void parserSetAttributes(const Vector<Attribute>&);
245 bool isEventHandlerAttribute(const Attribute&) const;
246 bool isJavaScriptURLAttribute(const Attribute&) const;
248 // Remove attributes that might introduce scripting from the vector leaving the element unchanged.
249 void stripScriptingAttributes(Vector<Attribute>&) const;
251 const ElementData* elementData() const { return m_elementData.get(); }
252 static ptrdiff_t elementDataMemoryOffset() { return OBJECT_OFFSETOF(Element, m_elementData); }
253 UniqueElementData& ensureUniqueElementData();
255 void synchronizeAllAttributes() const;
257 // Clones attributes only.
258 void cloneAttributesFromElement(const Element&);
260 // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
261 void cloneDataFromElement(const Element&);
263 bool hasEquivalentAttributes(const Element* other) const;
265 virtual void copyNonAttributePropertiesFromElement(const Element&) { }
267 virtual RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&);
268 virtual bool rendererIsNeeded(const RenderStyle&);
270 WEBCORE_EXPORT ShadowRoot* shadowRoot() const;
271 ShadowRoot* shadowRootForBindings(JSC::ExecState&) const;
273 struct ShadowRootInit {
276 ExceptionOr<ShadowRoot&> attachShadow(const ShadowRootInit&);
278 RefPtr<ShadowRoot> userAgentShadowRoot() const;
279 WEBCORE_EXPORT ShadowRoot& ensureUserAgentShadowRoot();
281 void setIsDefinedCustomElement(JSCustomElementInterface&);
282 void setIsFailedCustomElement(JSCustomElementInterface&);
283 void setIsCustomElementUpgradeCandidate();
284 void enqueueToUpgrade(JSCustomElementInterface&);
285 CustomElementReactionQueue* reactionQueue() const;
287 // FIXME: this should not be virtual, do not override this.
288 virtual const AtomicString& shadowPseudoId() const;
290 bool inActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); }
291 bool active() const { return isUserActionElement() && isUserActionElementActive(); }
292 bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); }
293 bool focused() const { return isUserActionElement() && isUserActionElementFocused(); }
294 bool hasFocusWithin() const { return getFlag(HasFocusWithin); };
296 virtual void setActive(bool flag = true, bool pause = false);
297 virtual void setHovered(bool flag = true);
298 virtual void setFocus(bool flag);
299 void setHasFocusWithin(bool flag);
301 bool tabIndexSetExplicitly() const;
302 virtual bool supportsFocus() const;
303 virtual bool isFocusable() const;
304 virtual bool isKeyboardFocusable(KeyboardEvent&) const;
305 virtual bool isMouseFocusable() const;
307 virtual bool shouldUseInputMethod();
309 virtual int tabIndex() const;
310 WEBCORE_EXPORT void setTabIndex(int);
311 virtual RefPtr<Element> focusDelegate();
313 WEBCORE_EXPORT ExceptionOr<Element*> insertAdjacentElement(const String& where, Element& newChild);
314 WEBCORE_EXPORT ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html);
315 WEBCORE_EXPORT ExceptionOr<void> insertAdjacentText(const String& where, const String& text);
317 const RenderStyle* computedStyle(PseudoId = NOPSEUDO) override;
319 bool needsStyleInvalidation() const;
321 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
322 bool styleAffectedByActive() const { return hasRareData() && rareDataStyleAffectedByActive(); }
323 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
324 bool styleAffectedByFocusWithin() const { return hasRareData() && rareDataStyleAffectedByFocusWithin(); }
325 bool childrenAffectedByHover() const { return getFlag(ChildrenAffectedByHoverRulesFlag); }
326 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
327 bool childrenAffectedByFirstChildRules() const { return getFlag(ChildrenAffectedByFirstChildRulesFlag); }
328 bool childrenAffectedByLastChildRules() const { return getFlag(ChildrenAffectedByLastChildRulesFlag); }
329 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
330 bool childrenAffectedByPropertyBasedBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules(); }
331 bool affectsNextSiblingElementStyle() const { return getFlag(AffectsNextSiblingElementStyle); }
332 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
334 bool hasFlagsSetDuringStylingOfChildren() const;
336 void setStyleAffectedByEmpty();
337 void setStyleAffectedByFocusWithin();
338 void setChildrenAffectedByHover() { setFlag(ChildrenAffectedByHoverRulesFlag); }
339 void setStyleAffectedByActive();
340 void setChildrenAffectedByDrag();
341 void setChildrenAffectedByFirstChildRules() { setFlag(ChildrenAffectedByFirstChildRulesFlag); }
342 void setChildrenAffectedByLastChildRules() { setFlag(ChildrenAffectedByLastChildRulesFlag); }
343 void setChildrenAffectedByBackwardPositionalRules();
344 void setChildrenAffectedByPropertyBasedBackwardPositionalRules();
345 void setAffectsNextSiblingElementStyle() { setFlag(AffectsNextSiblingElementStyle); }
346 void setStyleIsAffectedByPreviousSibling() { setFlag(StyleIsAffectedByPreviousSibling); }
347 void setChildIndex(unsigned);
349 AtomicString computeInheritedLanguage() const;
350 Locale& locale() const;
352 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
354 virtual bool isURLAttribute(const Attribute&) const { return false; }
355 virtual bool attributeContainsURL(const Attribute& attribute) const { return isURLAttribute(attribute); }
356 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const;
357 virtual bool isHTMLContentAttribute(const Attribute&) const { return false; }
359 WEBCORE_EXPORT URL getURLAttribute(const QualifiedName&) const;
360 URL getNonEmptyURLAttribute(const QualifiedName&) const;
362 virtual const AtomicString& imageSourceURL() const;
363 virtual String target() const { return String(); }
365 static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); }
366 void updateFocusAppearanceAfterAttachIfNeeded();
367 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
368 virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal);
371 WEBCORE_EXPORT String innerHTML() const;
372 WEBCORE_EXPORT String outerHTML() const;
373 WEBCORE_EXPORT ExceptionOr<void> setInnerHTML(const String&);
374 WEBCORE_EXPORT ExceptionOr<void> setOuterHTML(const String&);
375 WEBCORE_EXPORT String innerText();
376 WEBCORE_EXPORT String outerText();
378 virtual String title() const;
380 const AtomicString& pseudo() const;
381 WEBCORE_EXPORT void setPseudo(const AtomicString&);
383 LayoutSize minimumSizeForResizing() const;
384 void setMinimumSizeForResizing(const LayoutSize&);
386 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
387 virtual void prepareForDocumentSuspension() { }
388 virtual void resumeFromDocumentSuspension() { }
390 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
391 virtual void mediaVolumeDidChange() { }
393 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
394 virtual void privateBrowsingStateDidChange() { }
396 virtual void willBecomeFullscreenElement();
397 virtual void ancestorWillEnterFullscreen() { }
398 virtual void didBecomeFullscreenElement() { }
399 virtual void willStopBeingFullscreenElement() { }
401 #if ENABLE(VIDEO_TRACK)
402 virtual void captionPreferencesChanged() { }
405 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
406 void finishParsingChildren() override;
407 void beginParsingChildren() final;
409 WEBCORE_EXPORT PseudoElement* beforePseudoElement() const;
410 WEBCORE_EXPORT PseudoElement* afterPseudoElement() const;
411 bool childNeedsShadowWalker() const;
412 void didShadowTreeAwareChildrenChange();
414 virtual bool matchesValidPseudoClass() const;
415 virtual bool matchesInvalidPseudoClass() const;
416 virtual bool matchesReadWritePseudoClass() const;
417 virtual bool matchesIndeterminatePseudoClass() const;
418 virtual bool matchesDefaultPseudoClass() const;
419 WEBCORE_EXPORT ExceptionOr<bool> matches(const String& selectors);
420 WEBCORE_EXPORT ExceptionOr<Element*> closest(const String& selectors);
421 virtual bool shouldAppearIndeterminate() const;
423 WEBCORE_EXPORT DOMTokenList& classList();
425 DatasetDOMStringMap& dataset();
428 virtual bool isMediaElement() const { return false; }
431 virtual bool isFormControlElement() const { return false; }
432 virtual bool isSpinButtonElement() const { return false; }
433 virtual bool isTextFormControl() const { return false; }
434 virtual bool isOptionalFormControl() const { return false; }
435 virtual bool isRequiredFormControl() const { return false; }
436 virtual bool isInRange() const { return false; }
437 virtual bool isOutOfRange() const { return false; }
438 virtual bool isFrameElementBase() const { return false; }
439 virtual bool isUploadButton() const { return false; }
440 virtual bool isSliderContainerElement() const { return false; }
442 bool canContainRangeEndPoint() const override;
444 // Used for disabled form elements; if true, prevents mouse events from being dispatched
445 // to event listeners, and prevents DOMActivate events from being sent at all.
446 virtual bool isDisabledFormControl() const { return false; }
448 virtual bool childShouldCreateRenderer(const Node&) const;
450 bool hasPendingResources() const;
451 void setHasPendingResources();
452 void clearHasPendingResources();
453 virtual void buildPendingResource() { };
455 bool hasCSSAnimation() const;
456 void setHasCSSAnimation();
457 void clearHasCSSAnimation();
459 #if ENABLE(FULLSCREEN_API)
460 WEBCORE_EXPORT bool containsFullScreenElement() const;
461 void setContainsFullScreenElement(bool);
462 void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
463 WEBCORE_EXPORT void webkitRequestFullscreen();
466 #if ENABLE(POINTER_LOCK)
467 WEBCORE_EXPORT void requestPointerLock();
470 bool isSpellCheckingEnabled() const;
473 bool hasClass() const;
474 bool hasName() const;
475 const SpaceSplitString& classNames() const;
477 IntPoint savedLayerScrollPosition() const;
478 void setSavedLayerScrollPosition(const IntPoint&);
480 bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Element* relatedTarget = nullptr);
481 bool dispatchWheelEvent(const PlatformWheelEvent&);
482 bool dispatchKeyEvent(const PlatformKeyboardEvent&);
483 void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook);
484 void dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement);
485 void dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement);
486 virtual void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, FocusDirection);
487 virtual void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement);
488 void dispatchWebKitImageReadyEventForTesting();
490 WEBCORE_EXPORT bool dispatchMouseForceWillBegin();
492 virtual void willRecalcStyle(Style::Change);
493 virtual void didRecalcStyle(Style::Change);
494 virtual void willResetComputedStyle();
495 virtual void willAttachRenderers();
496 virtual void didAttachRenderers();
497 virtual void willDetachRenderers();
498 virtual void didDetachRenderers();
499 virtual std::optional<ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle);
501 LayoutRect absoluteEventHandlerBounds(bool& includesFixedPositionElements) override;
503 const RenderStyle* existingComputedStyle() const;
505 void setBeforePseudoElement(Ref<PseudoElement>&&);
506 void setAfterPseudoElement(Ref<PseudoElement>&&);
507 void clearBeforePseudoElement();
508 void clearAfterPseudoElement();
509 void resetComputedStyle();
510 void resetStyleRelations();
511 void clearStyleDerivedDataBeforeDetachingRenderer();
512 void clearHoverAndActiveStatusBeforeDetachingRenderer();
514 WEBCORE_EXPORT URL absoluteLinkURL() const;
516 #if ENABLE(TOUCH_EVENTS)
517 bool allowsDoubleTapGesture() const override;
520 StyleResolver& styleResolver();
521 ElementStyle resolveStyle(const RenderStyle* parentStyle);
523 // Invalidates the style of a single element. Style is resolved lazily.
524 // Descendant elements are resolved as needed, for example if an inherited property changes.
525 // This should be called whenever an element changes in a manner that can affect its style.
526 void invalidateStyle();
528 // As above but also call RenderElement::setStyle with StyleDifferenceRecompositeLayer flag for
529 // the element even when the style doesn't change. This is mostly needed by the animation code.
530 WEBCORE_EXPORT void invalidateStyleAndLayerComposition();
532 // Invalidate the element and all its descendants. This is used when there is some sort of change
533 // in the tree that may affect the style of any of the descendants and we don't know how to optimize
534 // the case to limit the scope. This is expensive and should be avoided.
535 void invalidateStyleForSubtree();
537 // Invalidates renderers for the element and all its descendants causing them to be torn down
538 // and rebuild during style resolution. Style is also recomputed. This is used in code dealing with
539 // custom (not style based) renderers. This is expensive and should be avoided.
540 // Elements newly added to the tree are also in this state.
541 void invalidateStyleAndRenderersForSubtree();
543 bool hasDisplayContents() const;
544 void storeDisplayContentsStyle(std::unique_ptr<RenderStyle>);
546 using ContainerNode::setAttributeEventListener;
547 void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
549 Element* findAnchorElementForLink(String& outAnchorName);
552 Element(const QualifiedName&, Document&, ConstructionType);
554 InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) override;
555 void removedFromAncestor(RemovalType, ContainerNode&) override;
556 void childrenChanged(const ChildChange&) override;
557 void removeAllEventListeners() final;
558 virtual void parserDidSetAttributes();
559 void didMoveToNewDocument(Document& oldDocument, Document& newDocument) override;
561 void clearTabIndexExplicitlyIfNeeded();
562 void setTabIndexExplicitly(int);
564 // classAttributeChanged() exists to share code between
565 // parseAttribute (called via setAttribute()) and
566 // svgAttributeChanged (called when element.className.baseValue is set)
567 void classAttributeChanged(const AtomicString& newClassString);
569 void addShadowRoot(Ref<ShadowRoot>&&);
571 static ExceptionOr<void> mergeWithNextTextNode(Text&);
574 bool isTextNode() const;
576 bool isUserActionElementInActiveChain() const;
577 bool isUserActionElementActive() const;
578 bool isUserActionElementFocused() const;
579 bool isUserActionElementHovered() const;
581 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
582 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
584 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
587 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
589 void didAddAttribute(const QualifiedName&, const AtomicString&);
590 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
591 void didModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
592 void didRemoveAttribute(const QualifiedName&, const AtomicString& oldValue);
594 void synchronizeAttribute(const QualifiedName&) const;
595 void synchronizeAttribute(const AtomicString& localName) const;
597 void updateName(const AtomicString& oldName, const AtomicString& newName);
598 void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName);
599 void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName);
601 enum class NotifyObservers { No, Yes };
602 void updateId(const AtomicString& oldId, const AtomicString& newId, NotifyObservers = NotifyObservers::Yes);
603 void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId, NotifyObservers = NotifyObservers::Yes);
605 enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute };
606 void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition);
607 void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
609 ExceptionOr<Node*> insertAdjacent(const String& where, Ref<Node>&& newChild);
611 void scrollByUnits(int units, ScrollGranularity);
613 NodeType nodeType() const final;
614 bool childTypeAllowed(NodeType) const final;
616 void setAttributeInternal(unsigned index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
617 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
618 void removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute);
620 LayoutRect absoluteEventBounds(bool& boundsIncludeAllDescendantElements, bool& includesFixedPositionElements);
621 LayoutRect absoluteEventBoundsOfElementAndDescendants(bool& includesFixedPositionElements);
623 #if ENABLE(TREE_DEBUGGING)
624 void formatForDebugger(char* buffer, unsigned length) const override;
627 // The cloneNode function is private so that non-virtual cloneElementWith/WithoutChildren are used instead.
628 Ref<Node> cloneNodeInternal(Document&, CloningOperation) override;
629 virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&);
631 void removeShadowRoot();
633 const RenderStyle& resolveComputedStyle();
634 const RenderStyle& resolvePseudoElementStyle(PseudoId);
636 bool rareDataStyleAffectedByEmpty() const;
637 bool rareDataStyleAffectedByFocusWithin() const;
638 bool rareDataChildrenAffectedByHover() const;
639 bool rareDataStyleAffectedByActive() const;
640 bool rareDataChildrenAffectedByDrag() const;
641 bool rareDataChildrenAffectedByLastChildRules() const;
642 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
643 bool rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules() const;
644 unsigned rareDataChildIndex() const;
646 SpellcheckAttributeState spellcheckAttributeState() const;
648 void createUniqueElementData();
650 ElementRareData* elementRareData() const;
651 ElementRareData& ensureElementRareData();
653 void detachAllAttrNodesFromElement();
654 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
656 // Anyone thinking of using this should call document instead of ownerDocument.
657 void ownerDocument() const = delete;
659 void attachAttributeNodeIfNeeded(Attr&);
661 QualifiedName m_tagName;
662 RefPtr<ElementData> m_elementData;
665 inline bool Node::hasAttributes() const
667 return is<Element>(*this) && downcast<Element>(*this).hasAttributes();
670 inline NamedNodeMap* Node::attributes() const
672 return is<Element>(*this) ? &downcast<Element>(*this).attributes() : nullptr;
675 inline Element* Node::parentElement() const
677 ContainerNode* parent = parentNode();
678 return is<Element>(parent) ? downcast<Element>(parent) : nullptr;
681 inline const Element* Element::rootElement() const
684 return document().documentElement();
686 const Element* highest = this;
687 while (highest->parentElement())
688 highest = highest->parentElement();
692 inline bool Element::hasAttributeWithoutSynchronization(const QualifiedName& name) const
694 ASSERT(fastAttributeLookupAllowed(name));
695 return elementData() && findAttributeByName(name);
698 inline const AtomicString& Element::attributeWithoutSynchronization(const QualifiedName& name) const
700 ASSERT(fastAttributeLookupAllowed(name));
702 if (const Attribute* attribute = findAttributeByName(name))
703 return attribute->value();
708 inline bool Element::hasAttributesWithoutUpdate() const
710 return elementData() && !elementData()->isEmpty();
713 inline const AtomicString& Element::idForStyleResolution() const
715 return hasID() ? elementData()->idForStyleResolution() : nullAtom();
718 inline const AtomicString& Element::getIdAttribute() const
721 return elementData()->findAttributeByName(HTMLNames::idAttr)->value();
725 inline const AtomicString& Element::getNameAttribute() const
728 return elementData()->findAttributeByName(HTMLNames::nameAttr)->value();
732 inline void Element::setIdAttribute(const AtomicString& value)
734 setAttributeWithoutSynchronization(HTMLNames::idAttr, value);
737 inline const SpaceSplitString& Element::classNames() const
740 ASSERT(elementData());
741 return elementData()->classNames();
744 inline unsigned Element::attributeCount() const
746 ASSERT(elementData());
747 return elementData()->length();
750 inline const Attribute& Element::attributeAt(unsigned index) const
752 ASSERT(elementData());
753 return elementData()->attributeAt(index);
756 inline const Attribute* Element::findAttributeByName(const QualifiedName& name) const
758 ASSERT(elementData());
759 return elementData()->findAttributeByName(name);
762 inline bool Element::hasID() const
764 return elementData() && elementData()->hasID();
767 inline bool Element::hasClass() const
769 return elementData() && elementData()->hasClass();
772 inline bool Element::hasName() const
774 return elementData() && elementData()->hasName();
777 inline UniqueElementData& Element::ensureUniqueElementData()
779 if (!elementData() || !elementData()->isUnique())
780 createUniqueElementData();
781 return static_cast<UniqueElementData&>(*m_elementData);
784 inline bool shouldIgnoreAttributeCase(const Element& element)
786 return element.isHTMLElement() && element.document().isHTMLDocument();
789 inline void Element::setHasFocusWithin(bool flag)
791 if (hasFocusWithin() == flag)
793 setFlag(flag, HasFocusWithin);
794 if (styleAffectedByFocusWithin())
795 invalidateStyleForSubtree();
798 } // namespace WebCore
800 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Element)
801 static bool isType(const WebCore::Node& node) { return node.isElementNode(); }
802 SPECIALIZE_TYPE_TRAITS_END()