1 | /* |
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. |
7 | * |
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. |
12 | * |
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. |
17 | * |
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. |
22 | * |
23 | */ |
24 | |
25 | #pragma once |
26 | |
27 | #include "AXTextStateChangeIntent.h" |
28 | #include "Document.h" |
29 | #include "ElementData.h" |
30 | #include "HTMLNames.h" |
31 | #include "KeyframeAnimationOptions.h" |
32 | #include "ScrollToOptions.h" |
33 | #include "ScrollTypes.h" |
34 | #include "ShadowRootMode.h" |
35 | #include "SimulatedClickOptions.h" |
36 | #include "StyleChange.h" |
37 | |
38 | namespace WebCore { |
39 | |
40 | class CustomElementReactionQueue; |
41 | class DatasetDOMStringMap; |
42 | class DOMRect; |
43 | class DOMRectList; |
44 | class DOMTokenList; |
45 | class ElementRareData; |
46 | class Frame; |
47 | class HTMLDocument; |
48 | class IntSize; |
49 | class JSCustomElementInterface; |
50 | class KeyboardEvent; |
51 | class Locale; |
52 | class PlatformKeyboardEvent; |
53 | class PlatformMouseEvent; |
54 | class PlatformWheelEvent; |
55 | class PseudoElement; |
56 | class RenderTreePosition; |
57 | class StylePropertyMap; |
58 | class WebAnimation; |
59 | struct ElementStyle; |
60 | struct ScrollIntoViewOptions; |
61 | |
62 | #if ENABLE(INTERSECTION_OBSERVER) |
63 | struct IntersectionObserverData; |
64 | #endif |
65 | |
66 | #if ENABLE(RESIZE_OBSERVER) |
67 | struct ResizeObserverData; |
68 | #endif |
69 | |
70 | enum SpellcheckAttributeState { |
71 | SpellcheckAttributeTrue, |
72 | SpellcheckAttributeFalse, |
73 | SpellcheckAttributeDefault |
74 | }; |
75 | |
76 | #if ENABLE(POINTER_EVENTS) |
77 | enum class TouchAction : uint8_t; |
78 | #endif |
79 | |
80 | class Element : public ContainerNode , public CanMakeWeakPtr<Element> { |
81 | WTF_MAKE_ISO_ALLOCATED(Element); |
82 | public: |
83 | static Ref<Element> create(const QualifiedName&, Document&); |
84 | virtual ~Element(); |
85 | |
86 | WEBCORE_EXPORT bool hasAttribute(const QualifiedName&) const; |
87 | WEBCORE_EXPORT const AtomicString& getAttribute(const QualifiedName&) const; |
88 | template<typename... QualifiedNames> |
89 | const AtomicString& getAttribute(const QualifiedName&, const QualifiedNames&...) const; |
90 | WEBCORE_EXPORT void setAttribute(const QualifiedName&, const AtomicString& value); |
91 | WEBCORE_EXPORT void setAttributeWithoutSynchronization(const QualifiedName&, const AtomicString& value); |
92 | void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value); |
93 | bool removeAttribute(const QualifiedName&); |
94 | Vector<String> getAttributeNames() const; |
95 | |
96 | // Typed getters and setters for language bindings. |
97 | WEBCORE_EXPORT int getIntegralAttribute(const QualifiedName& attributeName) const; |
98 | WEBCORE_EXPORT void setIntegralAttribute(const QualifiedName& attributeName, int value); |
99 | WEBCORE_EXPORT unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const; |
100 | WEBCORE_EXPORT void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value); |
101 | |
102 | // Call this to get the value of an attribute that is known not to be the style |
103 | // attribute or one of the SVG animatable attributes. |
104 | bool hasAttributeWithoutSynchronization(const QualifiedName&) const; |
105 | const AtomicString& attributeWithoutSynchronization(const QualifiedName&) const; |
106 | #ifndef NDEBUG |
107 | WEBCORE_EXPORT bool fastAttributeLookupAllowed(const QualifiedName&) const; |
108 | #endif |
109 | |
110 | #if DUMP_NODE_STATISTICS |
111 | bool hasNamedNodeMap() const; |
112 | #endif |
113 | WEBCORE_EXPORT bool hasAttributes() const; |
114 | // This variant will not update the potentially invalid attributes. To be used when not interested |
115 | // in style attribute or one of the SVG animation attributes. |
116 | bool hasAttributesWithoutUpdate() const; |
117 | |
118 | WEBCORE_EXPORT bool hasAttribute(const AtomicString& qualifiedName) const; |
119 | WEBCORE_EXPORT bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const; |
120 | |
121 | WEBCORE_EXPORT const AtomicString& getAttribute(const AtomicString& qualifiedName) const; |
122 | WEBCORE_EXPORT const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const; |
123 | |
124 | WEBCORE_EXPORT ExceptionOr<void> setAttribute(const AtomicString& qualifiedName, const AtomicString& value); |
125 | static ExceptionOr<QualifiedName> parseAttributeName(const AtomicString& namespaceURI, const AtomicString& qualifiedName); |
126 | WEBCORE_EXPORT ExceptionOr<void> setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value); |
127 | |
128 | ExceptionOr<bool> toggleAttribute(const AtomicString& qualifiedName, Optional<bool> force); |
129 | |
130 | const AtomicString& getIdAttribute() const; |
131 | void setIdAttribute(const AtomicString&); |
132 | |
133 | const AtomicString& getNameAttribute() const; |
134 | |
135 | // Call this to get the value of the id attribute for style resolution purposes. |
136 | // The value will already be lowercased if the document is in compatibility mode, |
137 | // so this function is not suitable for non-style uses. |
138 | const AtomicString& idForStyleResolution() const; |
139 | |
140 | // Internal methods that assume the existence of attribute storage, one should use hasAttributes() |
141 | // before calling them. |
142 | AttributeIteratorAccessor attributesIterator() const { return elementData()->attributesIterator(); } |
143 | unsigned attributeCount() const; |
144 | const Attribute& attributeAt(unsigned index) const; |
145 | const Attribute* findAttributeByName(const QualifiedName&) const; |
146 | unsigned findAttributeIndexByName(const QualifiedName& name) const { return elementData()->findAttributeIndexByName(name); } |
147 | unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); } |
148 | |
149 | WEBCORE_EXPORT void scrollIntoView(Optional<Variant<bool, ScrollIntoViewOptions>>&& arg); |
150 | WEBCORE_EXPORT void scrollIntoView(bool alignToTop = true); |
151 | WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true); |
152 | WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true); |
153 | |
154 | void scrollBy(const ScrollToOptions&); |
155 | void scrollBy(double x, double y); |
156 | virtual void scrollTo(const ScrollToOptions&, ScrollClamping = ScrollClamping::Clamped); |
157 | void scrollTo(double x, double y); |
158 | |
159 | WEBCORE_EXPORT void scrollByLines(int lines); |
160 | WEBCORE_EXPORT void scrollByPages(int pages); |
161 | |
162 | WEBCORE_EXPORT double offsetLeftForBindings(); |
163 | WEBCORE_EXPORT double offsetLeft(); |
164 | WEBCORE_EXPORT double offsetTopForBindings(); |
165 | WEBCORE_EXPORT double offsetTop(); |
166 | WEBCORE_EXPORT double offsetWidth(); |
167 | WEBCORE_EXPORT double offsetHeight(); |
168 | |
169 | bool mayCauseRepaintInsideViewport(const IntRect* visibleRect = nullptr) const; |
170 | |
171 | // FIXME: Replace uses of offsetParent in the platform with calls |
172 | // to the render layer and merge bindingsOffsetParent and offsetParent. |
173 | WEBCORE_EXPORT Element* offsetParentForBindings(); |
174 | |
175 | const Element* rootElement() const; |
176 | |
177 | Element* offsetParent(); |
178 | WEBCORE_EXPORT double clientLeft(); |
179 | WEBCORE_EXPORT double clientTop(); |
180 | WEBCORE_EXPORT double clientWidth(); |
181 | WEBCORE_EXPORT double clientHeight(); |
182 | |
183 | virtual int scrollLeft(); |
184 | virtual int scrollTop(); |
185 | virtual void setScrollLeft(int); |
186 | virtual void setScrollTop(int); |
187 | virtual int scrollWidth(); |
188 | virtual int scrollHeight(); |
189 | |
190 | WEBCORE_EXPORT IntRect boundsInRootViewSpace(); |
191 | |
192 | WEBCORE_EXPORT FloatRect boundingClientRect(); |
193 | |
194 | WEBCORE_EXPORT Ref<DOMRectList> getClientRects(); |
195 | Ref<DOMRect> getBoundingClientRect(); |
196 | |
197 | // Returns the absolute bounding box translated into client coordinates. |
198 | WEBCORE_EXPORT IntRect clientRect() const; |
199 | // Returns the absolute bounding box translated into screen coordinates. |
200 | WEBCORE_EXPORT IntRect screenRect() const; |
201 | |
202 | WEBCORE_EXPORT bool removeAttribute(const AtomicString& qualifiedName); |
203 | WEBCORE_EXPORT bool removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName); |
204 | |
205 | Ref<Attr> detachAttribute(unsigned index); |
206 | |
207 | WEBCORE_EXPORT RefPtr<Attr> getAttributeNode(const AtomicString& qualifiedName); |
208 | WEBCORE_EXPORT RefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName); |
209 | WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setAttributeNode(Attr&); |
210 | WEBCORE_EXPORT ExceptionOr<RefPtr<Attr>> setAttributeNodeNS(Attr&); |
211 | WEBCORE_EXPORT ExceptionOr<Ref<Attr>> removeAttributeNode(Attr&); |
212 | |
213 | RefPtr<Attr> attrIfExists(const QualifiedName&); |
214 | RefPtr<Attr> attrIfExists(const AtomicString& localName, bool shouldIgnoreAttributeCase); |
215 | Ref<Attr> ensureAttr(const QualifiedName&); |
216 | |
217 | const Vector<RefPtr<Attr>>& attrNodeList(); |
218 | |
219 | const QualifiedName& tagQName() const { return m_tagName; } |
220 | #if ENABLE(JIT) |
221 | static ptrdiff_t tagQNameMemoryOffset() { return OBJECT_OFFSETOF(Element, m_tagName); } |
222 | #endif // ENABLE(JIT) |
223 | String tagName() const { return nodeName(); } |
224 | bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); } |
225 | bool hasTagName(const HTMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); } |
226 | bool hasTagName(const MathMLQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); } |
227 | bool hasTagName(const SVGQualifiedName& tagName) const { return ContainerNode::hasTagName(tagName); } |
228 | |
229 | // A fast function for checking the local name against another atomic string. |
230 | bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; } |
231 | |
232 | const AtomicString& localName() const final { return m_tagName.localName(); } |
233 | const AtomicString& prefix() const final { return m_tagName.prefix(); } |
234 | const AtomicString& namespaceURI() const final { return m_tagName.namespaceURI(); } |
235 | |
236 | ExceptionOr<void> setPrefix(const AtomicString&) final; |
237 | |
238 | String nodeName() const override; |
239 | |
240 | Ref<Element> cloneElementWithChildren(Document&); |
241 | Ref<Element> cloneElementWithoutChildren(Document&); |
242 | |
243 | void normalizeAttributes(); |
244 | String nodeNamePreservingCase() const; |
245 | |
246 | WEBCORE_EXPORT void setBooleanAttribute(const QualifiedName& name, bool); |
247 | |
248 | // For exposing to DOM only. |
249 | WEBCORE_EXPORT NamedNodeMap& attributes() const; |
250 | |
251 | enum AttributeModificationReason { |
252 | ModifiedDirectly, |
253 | ModifiedByCloning |
254 | }; |
255 | |
256 | // This method is called whenever an attribute is added, changed or removed. |
257 | virtual void attributeChanged(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue, AttributeModificationReason = ModifiedDirectly); |
258 | virtual void parseAttribute(const QualifiedName&, const AtomicString&) { } |
259 | |
260 | // Only called by the parser immediately after element construction. |
261 | void parserSetAttributes(const Vector<Attribute>&); |
262 | |
263 | bool isEventHandlerAttribute(const Attribute&) const; |
264 | bool isJavaScriptURLAttribute(const Attribute&) const; |
265 | |
266 | // Remove attributes that might introduce scripting from the vector leaving the element unchanged. |
267 | void stripScriptingAttributes(Vector<Attribute>&) const; |
268 | |
269 | const ElementData* elementData() const { return m_elementData.get(); } |
270 | static ptrdiff_t elementDataMemoryOffset() { return OBJECT_OFFSETOF(Element, m_elementData); } |
271 | UniqueElementData& ensureUniqueElementData(); |
272 | |
273 | void synchronizeAllAttributes() const; |
274 | |
275 | // Clones attributes only. |
276 | void cloneAttributesFromElement(const Element&); |
277 | |
278 | // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.) |
279 | void cloneDataFromElement(const Element&); |
280 | |
281 | virtual void didMoveToNewDocument(Document& oldDocument, Document& newDocument); |
282 | |
283 | bool hasEquivalentAttributes(const Element& other) const; |
284 | |
285 | virtual void copyNonAttributePropertiesFromElement(const Element&) { } |
286 | |
287 | virtual RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&); |
288 | virtual bool rendererIsNeeded(const RenderStyle&); |
289 | |
290 | WEBCORE_EXPORT ShadowRoot* shadowRoot() const; |
291 | ShadowRoot* shadowRootForBindings(JSC::ExecState&) const; |
292 | |
293 | struct ShadowRootInit { |
294 | ShadowRootMode mode; |
295 | }; |
296 | ExceptionOr<ShadowRoot&> attachShadow(const ShadowRootInit&); |
297 | |
298 | RefPtr<ShadowRoot> userAgentShadowRoot() const; |
299 | WEBCORE_EXPORT ShadowRoot& ensureUserAgentShadowRoot(); |
300 | |
301 | void setIsDefinedCustomElement(JSCustomElementInterface&); |
302 | void setIsFailedCustomElement(JSCustomElementInterface&); |
303 | void setIsCustomElementUpgradeCandidate(); |
304 | void enqueueToUpgrade(JSCustomElementInterface&); |
305 | CustomElementReactionQueue* reactionQueue() const; |
306 | |
307 | // FIXME: this should not be virtual, do not override this. |
308 | virtual const AtomicString& shadowPseudoId() const; |
309 | |
310 | bool isInActiveChain() const { return isUserActionElement() && isUserActionElementInActiveChain(); } |
311 | bool active() const { return isUserActionElement() && isUserActionElementActive(); } |
312 | bool hovered() const { return isUserActionElement() && isUserActionElementHovered(); } |
313 | bool focused() const { return isUserActionElement() && isUserActionElementFocused(); } |
314 | bool hasFocusWithin() const { return getFlag(HasFocusWithin); }; |
315 | |
316 | virtual void setActive(bool flag = true, bool pause = false); |
317 | virtual void setHovered(bool flag = true); |
318 | virtual void setFocus(bool flag); |
319 | void setHasFocusWithin(bool flag); |
320 | |
321 | bool tabIndexSetExplicitly() const; |
322 | virtual bool supportsFocus() const; |
323 | virtual bool isFocusable() const; |
324 | virtual bool isKeyboardFocusable(KeyboardEvent*) const; |
325 | virtual bool isMouseFocusable() const; |
326 | |
327 | virtual bool shouldUseInputMethod(); |
328 | |
329 | virtual int tabIndex() const; |
330 | WEBCORE_EXPORT void setTabIndex(int); |
331 | virtual RefPtr<Element> focusDelegate(); |
332 | |
333 | ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html, NodeVector* addedNodes); |
334 | |
335 | WEBCORE_EXPORT ExceptionOr<Element*> insertAdjacentElement(const String& where, Element& newChild); |
336 | WEBCORE_EXPORT ExceptionOr<void> insertAdjacentHTML(const String& where, const String& html); |
337 | WEBCORE_EXPORT ExceptionOr<void> insertAdjacentText(const String& where, const String& text); |
338 | |
339 | const RenderStyle* computedStyle(PseudoId = PseudoId::None) override; |
340 | |
341 | bool needsStyleInvalidation() const; |
342 | |
343 | // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.) |
344 | bool styleAffectedByActive() const { return hasRareData() && rareDataStyleAffectedByActive(); } |
345 | bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); } |
346 | bool styleAffectedByFocusWithin() const { return hasRareData() && rareDataStyleAffectedByFocusWithin(); } |
347 | bool descendantsAffectedByPreviousSibling() const { return getFlag(DescendantsAffectedByPreviousSiblingFlag); } |
348 | bool childrenAffectedByHover() const { return getFlag(ChildrenAffectedByHoverRulesFlag); } |
349 | bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); } |
350 | bool childrenAffectedByFirstChildRules() const { return getFlag(ChildrenAffectedByFirstChildRulesFlag); } |
351 | bool childrenAffectedByLastChildRules() const { return getFlag(ChildrenAffectedByLastChildRulesFlag); } |
352 | bool childrenAffectedByForwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByForwardPositionalRules(); } |
353 | bool descendantsAffectedByForwardPositionalRules() const { return hasRareData() && rareDataDescendantsAffectedByForwardPositionalRules(); } |
354 | bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); } |
355 | bool descendantsAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataDescendantsAffectedByBackwardPositionalRules(); } |
356 | bool childrenAffectedByPropertyBasedBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules(); } |
357 | bool affectsNextSiblingElementStyle() const { return getFlag(AffectsNextSiblingElementStyle); } |
358 | unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; } |
359 | |
360 | bool hasFlagsSetDuringStylingOfChildren() const; |
361 | |
362 | void setStyleAffectedByEmpty(); |
363 | void setStyleAffectedByFocusWithin(); |
364 | void setDescendantsAffectedByPreviousSibling() const { return setFlag(DescendantsAffectedByPreviousSiblingFlag); } |
365 | void setChildrenAffectedByHover() { setFlag(ChildrenAffectedByHoverRulesFlag); } |
366 | void setStyleAffectedByActive(); |
367 | void setChildrenAffectedByDrag(); |
368 | void setChildrenAffectedByFirstChildRules() { setFlag(ChildrenAffectedByFirstChildRulesFlag); } |
369 | void setChildrenAffectedByLastChildRules() { setFlag(ChildrenAffectedByLastChildRulesFlag); } |
370 | void setChildrenAffectedByForwardPositionalRules(); |
371 | void setDescendantsAffectedByForwardPositionalRules(); |
372 | void setChildrenAffectedByBackwardPositionalRules(); |
373 | void setDescendantsAffectedByBackwardPositionalRules(); |
374 | void setChildrenAffectedByPropertyBasedBackwardPositionalRules(); |
375 | void setAffectsNextSiblingElementStyle() { setFlag(AffectsNextSiblingElementStyle); } |
376 | void setStyleIsAffectedByPreviousSibling() { setFlag(StyleIsAffectedByPreviousSibling); } |
377 | void setChildIndex(unsigned); |
378 | |
379 | WEBCORE_EXPORT AtomicString computeInheritedLanguage() const; |
380 | Locale& locale() const; |
381 | |
382 | virtual void accessKeyAction(bool /*sendToAnyEvent*/) { } |
383 | |
384 | virtual bool isURLAttribute(const Attribute&) const { return false; } |
385 | virtual bool attributeContainsURL(const Attribute& attribute) const { return isURLAttribute(attribute); } |
386 | virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const; |
387 | virtual bool isHTMLContentAttribute(const Attribute&) const { return false; } |
388 | |
389 | WEBCORE_EXPORT URL getURLAttribute(const QualifiedName&) const; |
390 | URL getNonEmptyURLAttribute(const QualifiedName&) const; |
391 | |
392 | virtual const AtomicString& imageSourceURL() const; |
393 | virtual String target() const { return String(); } |
394 | |
395 | static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); } |
396 | virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone); |
397 | virtual RefPtr<Element> focusAppearanceUpdateTarget(); |
398 | virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal); |
399 | virtual void blur(); |
400 | |
401 | WEBCORE_EXPORT String innerHTML() const; |
402 | WEBCORE_EXPORT String outerHTML() const; |
403 | WEBCORE_EXPORT ExceptionOr<void> setInnerHTML(const String&); |
404 | WEBCORE_EXPORT ExceptionOr<void> setOuterHTML(const String&); |
405 | WEBCORE_EXPORT String innerText(); |
406 | WEBCORE_EXPORT String outerText(); |
407 | |
408 | virtual String title() const; |
409 | |
410 | const AtomicString& pseudo() const; |
411 | WEBCORE_EXPORT void setPseudo(const AtomicString&); |
412 | |
413 | LayoutSize minimumSizeForResizing() const; |
414 | void setMinimumSizeForResizing(const LayoutSize&); |
415 | |
416 | // Use Document::registerForDocumentActivationCallbacks() to subscribe to these |
417 | virtual void prepareForDocumentSuspension() { } |
418 | virtual void resumeFromDocumentSuspension() { } |
419 | |
420 | // Use Document::registerForMediaVolumeCallbacks() to subscribe to this |
421 | virtual void mediaVolumeDidChange() { } |
422 | |
423 | // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this. |
424 | virtual void privateBrowsingStateDidChange() { } |
425 | |
426 | virtual void willBecomeFullscreenElement(); |
427 | virtual void ancestorWillEnterFullscreen() { } |
428 | virtual void didBecomeFullscreenElement() { } |
429 | virtual void willStopBeingFullscreenElement() { } |
430 | |
431 | #if ENABLE(VIDEO_TRACK) |
432 | virtual void captionPreferencesChanged() { } |
433 | #endif |
434 | |
435 | bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); } |
436 | void finishParsingChildren() override; |
437 | void beginParsingChildren() final; |
438 | |
439 | WEBCORE_EXPORT PseudoElement* beforePseudoElement() const; |
440 | WEBCORE_EXPORT PseudoElement* afterPseudoElement() const; |
441 | bool childNeedsShadowWalker() const; |
442 | void didShadowTreeAwareChildrenChange(); |
443 | |
444 | virtual bool matchesValidPseudoClass() const; |
445 | virtual bool matchesInvalidPseudoClass() const; |
446 | virtual bool matchesReadWritePseudoClass() const; |
447 | virtual bool matchesIndeterminatePseudoClass() const; |
448 | virtual bool matchesDefaultPseudoClass() const; |
449 | WEBCORE_EXPORT ExceptionOr<bool> matches(const String& selectors); |
450 | WEBCORE_EXPORT ExceptionOr<Element*> closest(const String& selectors); |
451 | virtual bool shouldAppearIndeterminate() const; |
452 | |
453 | WEBCORE_EXPORT DOMTokenList& classList(); |
454 | |
455 | DatasetDOMStringMap& dataset(); |
456 | |
457 | #if ENABLE(VIDEO) |
458 | virtual bool isMediaElement() const { return false; } |
459 | #endif |
460 | |
461 | virtual bool isFormControlElement() const { return false; } |
462 | virtual bool isSpinButtonElement() const { return false; } |
463 | virtual bool isTextFormControlElement() const { return false; } |
464 | virtual bool isTextField() const { return false; } |
465 | virtual bool isOptionalFormControl() const { return false; } |
466 | virtual bool isRequiredFormControl() const { return false; } |
467 | virtual bool isInRange() const { return false; } |
468 | virtual bool isOutOfRange() const { return false; } |
469 | virtual bool isFrameElementBase() const { return false; } |
470 | virtual bool isUploadButton() const { return false; } |
471 | virtual bool isSliderContainerElement() const { return false; } |
472 | |
473 | bool canContainRangeEndPoint() const override; |
474 | |
475 | // Used for disabled form elements; if true, prevents mouse events from being dispatched |
476 | // to event listeners, and prevents DOMActivate events from being sent at all. |
477 | virtual bool isDisabledFormControl() const { return false; } |
478 | |
479 | virtual bool childShouldCreateRenderer(const Node&) const; |
480 | |
481 | bool hasPendingResources() const; |
482 | void setHasPendingResources(); |
483 | void clearHasPendingResources(); |
484 | virtual void buildPendingResource() { }; |
485 | |
486 | bool hasCSSAnimation() const; |
487 | void setHasCSSAnimation(); |
488 | void clearHasCSSAnimation(); |
489 | |
490 | #if ENABLE(FULLSCREEN_API) |
491 | WEBCORE_EXPORT bool containsFullScreenElement() const; |
492 | void setContainsFullScreenElement(bool); |
493 | void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool); |
494 | WEBCORE_EXPORT virtual void webkitRequestFullscreen(); |
495 | #endif |
496 | |
497 | #if ENABLE(POINTER_EVENTS) |
498 | ExceptionOr<void> setPointerCapture(int32_t); |
499 | ExceptionOr<void> releasePointerCapture(int32_t); |
500 | bool hasPointerCapture(int32_t); |
501 | #endif |
502 | |
503 | #if ENABLE(POINTER_LOCK) |
504 | WEBCORE_EXPORT void requestPointerLock(); |
505 | #endif |
506 | |
507 | bool isSpellCheckingEnabled() const; |
508 | |
509 | bool hasID() const; |
510 | bool hasClass() const; |
511 | bool hasName() const; |
512 | const SpaceSplitString& classNames() const; |
513 | |
514 | IntPoint savedLayerScrollPosition() const; |
515 | void setSavedLayerScrollPosition(const IntPoint&); |
516 | |
517 | bool dispatchMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType, int clickCount = 0, Element* relatedTarget = nullptr); |
518 | bool dispatchWheelEvent(const PlatformWheelEvent&); |
519 | bool dispatchKeyEvent(const PlatformKeyboardEvent&); |
520 | void dispatchSimulatedClick(Event* underlyingEvent, SimulatedClickMouseEventOptions = SendNoEvents, SimulatedClickVisualOptions = ShowPressedLook); |
521 | void dispatchFocusInEvent(const AtomicString& eventType, RefPtr<Element>&& oldFocusedElement); |
522 | void dispatchFocusOutEvent(const AtomicString& eventType, RefPtr<Element>&& newFocusedElement); |
523 | virtual void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, FocusDirection); |
524 | virtual void dispatchBlurEvent(RefPtr<Element>&& newFocusedElement); |
525 | void dispatchWebKitImageReadyEventForTesting(); |
526 | |
527 | WEBCORE_EXPORT bool dispatchMouseForceWillBegin(); |
528 | |
529 | virtual void willRecalcStyle(Style::Change); |
530 | virtual void didRecalcStyle(Style::Change); |
531 | virtual void willResetComputedStyle(); |
532 | virtual void willAttachRenderers(); |
533 | virtual void didAttachRenderers(); |
534 | virtual void willDetachRenderers(); |
535 | virtual void didDetachRenderers(); |
536 | virtual Optional<ElementStyle> resolveCustomStyle(const RenderStyle& parentStyle, const RenderStyle* shadowHostStyle); |
537 | |
538 | LayoutRect absoluteEventHandlerBounds(bool& includesFixedPositionElements) override; |
539 | |
540 | const RenderStyle* existingComputedStyle() const; |
541 | const RenderStyle* renderOrDisplayContentsStyle() const; |
542 | |
543 | void setBeforePseudoElement(Ref<PseudoElement>&&); |
544 | void setAfterPseudoElement(Ref<PseudoElement>&&); |
545 | void clearBeforePseudoElement(); |
546 | void clearAfterPseudoElement(); |
547 | void resetComputedStyle(); |
548 | void resetStyleRelations(); |
549 | void clearHoverAndActiveStatusBeforeDetachingRenderer(); |
550 | |
551 | WEBCORE_EXPORT URL absoluteLinkURL() const; |
552 | |
553 | #if ENABLE(TOUCH_EVENTS) |
554 | bool allowsDoubleTapGesture() const override; |
555 | #endif |
556 | |
557 | StyleResolver& styleResolver(); |
558 | ElementStyle resolveStyle(const RenderStyle* parentStyle); |
559 | |
560 | // Invalidates the style of a single element. Style is resolved lazily. |
561 | // Descendant elements are resolved as needed, for example if an inherited property changes. |
562 | // This should be called whenever an element changes in a manner that can affect its style. |
563 | void invalidateStyle(); |
564 | |
565 | // As above but also call RenderElement::setStyle with StyleDifference::RecompositeLayer flag for |
566 | // the element even when the style doesn't change. This is mostly needed by the animation code. |
567 | WEBCORE_EXPORT void invalidateStyleAndLayerComposition(); |
568 | |
569 | // Invalidate the element and all its descendants. This is used when there is some sort of change |
570 | // in the tree that may affect the style of any of the descendants and we don't know how to optimize |
571 | // the case to limit the scope. This is expensive and should be avoided. |
572 | void invalidateStyleForSubtree(); |
573 | |
574 | // Invalidates renderers for the element and all its descendants causing them to be torn down |
575 | // and rebuild during style resolution. Style is also recomputed. This is used in code dealing with |
576 | // custom (not style based) renderers. This is expensive and should be avoided. |
577 | // Elements newly added to the tree are also in this state. |
578 | void invalidateStyleAndRenderersForSubtree(); |
579 | |
580 | void invalidateStyleInternal(); |
581 | void invalidateStyleForSubtreeInternal(); |
582 | |
583 | bool hasDisplayContents() const; |
584 | void storeDisplayContentsStyle(std::unique_ptr<RenderStyle>); |
585 | |
586 | using ContainerNode::setAttributeEventListener; |
587 | void setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value); |
588 | |
589 | #if ENABLE(INTERSECTION_OBSERVER) |
590 | IntersectionObserverData& ensureIntersectionObserverData(); |
591 | IntersectionObserverData* intersectionObserverData(); |
592 | #endif |
593 | |
594 | #if ENABLE(RESIZE_OBSERVER) |
595 | ResizeObserverData& ensureResizeObserverData(); |
596 | ResizeObserverData* resizeObserverData(); |
597 | #endif |
598 | |
599 | Element* findAnchorElementForLink(String& outAnchorName); |
600 | |
601 | ExceptionOr<Ref<WebAnimation>> animate(JSC::ExecState&, JSC::Strong<JSC::JSObject>&&, Optional<Variant<double, KeyframeAnimationOptions>>&&); |
602 | Vector<RefPtr<WebAnimation>> getAnimations(); |
603 | |
604 | ElementIdentifier createElementIdentifier(); |
605 | |
606 | #if ENABLE(POINTER_EVENTS) |
607 | OptionSet<TouchAction> computedTouchActions() const; |
608 | #if ENABLE(OVERFLOW_SCROLLING_TOUCH) |
609 | ScrollingNodeID nearestScrollingNodeIDUsingTouchOverflowScrolling() const; |
610 | #endif |
611 | #endif |
612 | |
613 | protected: |
614 | Element(const QualifiedName&, Document&, ConstructionType); |
615 | |
616 | InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) override; |
617 | void removedFromAncestor(RemovalType, ContainerNode&) override; |
618 | void childrenChanged(const ChildChange&) override; |
619 | void removeAllEventListeners() final; |
620 | virtual void parserDidSetAttributes(); |
621 | |
622 | void clearTabIndexExplicitlyIfNeeded(); |
623 | void setTabIndexExplicitly(int); |
624 | |
625 | // classAttributeChanged() exists to share code between |
626 | // parseAttribute (called via setAttribute()) and |
627 | // svgAttributeChanged (called when element.className.baseValue is set) |
628 | void classAttributeChanged(const AtomicString& newClassString); |
629 | |
630 | void addShadowRoot(Ref<ShadowRoot>&&); |
631 | |
632 | static ExceptionOr<void> mergeWithNextTextNode(Text&); |
633 | |
634 | #if ENABLE(CSS_TYPED_OM) |
635 | StylePropertyMap* attributeStyleMap(); |
636 | void setAttributeStyleMap(Ref<StylePropertyMap>&&); |
637 | #endif |
638 | |
639 | private: |
640 | Frame* documentFrameWithNonNullView() const; |
641 | |
642 | bool isTextNode() const; |
643 | |
644 | bool isUserActionElementInActiveChain() const; |
645 | bool isUserActionElementActive() const; |
646 | bool isUserActionElementFocused() const; |
647 | bool isUserActionElementHovered() const; |
648 | |
649 | virtual void didAddUserAgentShadowRoot(ShadowRoot&) { } |
650 | |
651 | void didAddAttribute(const QualifiedName&, const AtomicString&); |
652 | void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue); |
653 | void didModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue); |
654 | void didRemoveAttribute(const QualifiedName&, const AtomicString& oldValue); |
655 | |
656 | void synchronizeAttribute(const QualifiedName&) const; |
657 | void synchronizeAttribute(const AtomicString& localName) const; |
658 | |
659 | void updateName(const AtomicString& oldName, const AtomicString& newName); |
660 | void updateNameForTreeScope(TreeScope&, const AtomicString& oldName, const AtomicString& newName); |
661 | void updateNameForDocument(HTMLDocument&, const AtomicString& oldName, const AtomicString& newName); |
662 | |
663 | enum class NotifyObservers { No, Yes }; |
664 | void updateId(const AtomicString& oldId, const AtomicString& newId, NotifyObservers = NotifyObservers::Yes); |
665 | void updateIdForTreeScope(TreeScope&, const AtomicString& oldId, const AtomicString& newId, NotifyObservers = NotifyObservers::Yes); |
666 | |
667 | enum HTMLDocumentNamedItemMapsUpdatingCondition { AlwaysUpdateHTMLDocumentNamedItemMaps, UpdateHTMLDocumentNamedItemMapsOnlyIfDiffersFromNameAttribute }; |
668 | void updateIdForDocument(HTMLDocument&, const AtomicString& oldId, const AtomicString& newId, HTMLDocumentNamedItemMapsUpdatingCondition); |
669 | void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue); |
670 | |
671 | ExceptionOr<Node*> insertAdjacent(const String& where, Ref<Node>&& newChild); |
672 | |
673 | void scrollByUnits(int units, ScrollGranularity); |
674 | |
675 | NodeType nodeType() const final; |
676 | bool childTypeAllowed(NodeType) const final; |
677 | |
678 | enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute, InSynchronizationOfLazyAttribute }; |
679 | void setAttributeInternal(unsigned index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute); |
680 | void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute); |
681 | void removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute); |
682 | |
683 | LayoutRect absoluteEventBounds(bool& boundsIncludeAllDescendantElements, bool& includesFixedPositionElements); |
684 | LayoutRect absoluteEventBoundsOfElementAndDescendants(bool& includesFixedPositionElements); |
685 | |
686 | #if ENABLE(TREE_DEBUGGING) |
687 | void formatForDebugger(char* buffer, unsigned length) const override; |
688 | #endif |
689 | |
690 | #if ENABLE(INTERSECTION_OBSERVER) |
691 | void disconnectFromIntersectionObservers(); |
692 | #endif |
693 | |
694 | #if ENABLE(RESIZE_OBSERVER) |
695 | void disconnectFromResizeObservers(); |
696 | #endif |
697 | |
698 | // The cloneNode function is private so that non-virtual cloneElementWith/WithoutChildren are used instead. |
699 | Ref<Node> cloneNodeInternal(Document&, CloningOperation) override; |
700 | virtual Ref<Element> cloneElementWithoutAttributesAndChildren(Document&); |
701 | |
702 | void removeShadowRoot(); |
703 | |
704 | const RenderStyle& resolveComputedStyle(); |
705 | const RenderStyle& resolvePseudoElementStyle(PseudoId); |
706 | |
707 | bool rareDataStyleAffectedByEmpty() const; |
708 | bool rareDataStyleAffectedByFocusWithin() const; |
709 | bool rareDataChildrenAffectedByHover() const; |
710 | bool rareDataStyleAffectedByActive() const; |
711 | bool rareDataChildrenAffectedByDrag() const; |
712 | bool rareDataChildrenAffectedByLastChildRules() const; |
713 | bool rareDataChildrenAffectedByForwardPositionalRules() const; |
714 | bool rareDataDescendantsAffectedByForwardPositionalRules() const; |
715 | bool rareDataChildrenAffectedByBackwardPositionalRules() const; |
716 | bool rareDataDescendantsAffectedByBackwardPositionalRules() const; |
717 | bool rareDataChildrenAffectedByPropertyBasedBackwardPositionalRules() const; |
718 | unsigned rareDataChildIndex() const; |
719 | |
720 | SpellcheckAttributeState spellcheckAttributeState() const; |
721 | |
722 | void createUniqueElementData(); |
723 | |
724 | ElementRareData* elementRareData() const; |
725 | ElementRareData& ensureElementRareData(); |
726 | |
727 | void detachAllAttrNodesFromElement(); |
728 | void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value); |
729 | |
730 | // Anyone thinking of using this should call document instead of ownerDocument. |
731 | void ownerDocument() const = delete; |
732 | |
733 | void attachAttributeNodeIfNeeded(Attr&); |
734 | |
735 | QualifiedName m_tagName; |
736 | RefPtr<ElementData> m_elementData; |
737 | }; |
738 | |
739 | inline bool Node::hasAttributes() const |
740 | { |
741 | return is<Element>(*this) && downcast<Element>(*this).hasAttributes(); |
742 | } |
743 | |
744 | inline NamedNodeMap* Node::attributes() const |
745 | { |
746 | return is<Element>(*this) ? &downcast<Element>(*this).attributes() : nullptr; |
747 | } |
748 | |
749 | inline Element* Node::parentElement() const |
750 | { |
751 | ContainerNode* parent = parentNode(); |
752 | return is<Element>(parent) ? downcast<Element>(parent) : nullptr; |
753 | } |
754 | |
755 | inline const Element* Element::rootElement() const |
756 | { |
757 | if (isConnected()) |
758 | return document().documentElement(); |
759 | |
760 | const Element* highest = this; |
761 | while (highest->parentElement()) |
762 | highest = highest->parentElement(); |
763 | return highest; |
764 | } |
765 | |
766 | inline bool Element::hasAttributeWithoutSynchronization(const QualifiedName& name) const |
767 | { |
768 | ASSERT(fastAttributeLookupAllowed(name)); |
769 | return elementData() && findAttributeByName(name); |
770 | } |
771 | |
772 | inline const AtomicString& Element::attributeWithoutSynchronization(const QualifiedName& name) const |
773 | { |
774 | if (elementData()) { |
775 | if (const Attribute* attribute = findAttributeByName(name)) |
776 | return attribute->value(); |
777 | } |
778 | return nullAtom(); |
779 | } |
780 | |
781 | inline bool Element::hasAttributesWithoutUpdate() const |
782 | { |
783 | return elementData() && !elementData()->isEmpty(); |
784 | } |
785 | |
786 | inline const AtomicString& Element::idForStyleResolution() const |
787 | { |
788 | return hasID() ? elementData()->idForStyleResolution() : nullAtom(); |
789 | } |
790 | |
791 | inline const AtomicString& Element::getIdAttribute() const |
792 | { |
793 | if (hasID()) |
794 | return elementData()->findAttributeByName(HTMLNames::idAttr)->value(); |
795 | return nullAtom(); |
796 | } |
797 | |
798 | inline const AtomicString& Element::getNameAttribute() const |
799 | { |
800 | if (hasName()) |
801 | return elementData()->findAttributeByName(HTMLNames::nameAttr)->value(); |
802 | return nullAtom(); |
803 | } |
804 | |
805 | inline void Element::setIdAttribute(const AtomicString& value) |
806 | { |
807 | setAttributeWithoutSynchronization(HTMLNames::idAttr, value); |
808 | } |
809 | |
810 | inline const SpaceSplitString& Element::classNames() const |
811 | { |
812 | ASSERT(hasClass()); |
813 | ASSERT(elementData()); |
814 | return elementData()->classNames(); |
815 | } |
816 | |
817 | inline unsigned Element::attributeCount() const |
818 | { |
819 | ASSERT(elementData()); |
820 | return elementData()->length(); |
821 | } |
822 | |
823 | inline const Attribute& Element::attributeAt(unsigned index) const |
824 | { |
825 | ASSERT(elementData()); |
826 | return elementData()->attributeAt(index); |
827 | } |
828 | |
829 | inline const Attribute* Element::findAttributeByName(const QualifiedName& name) const |
830 | { |
831 | ASSERT(elementData()); |
832 | return elementData()->findAttributeByName(name); |
833 | } |
834 | |
835 | inline bool Element::hasID() const |
836 | { |
837 | return elementData() && elementData()->hasID(); |
838 | } |
839 | |
840 | inline bool Element::hasClass() const |
841 | { |
842 | return elementData() && elementData()->hasClass(); |
843 | } |
844 | |
845 | inline bool Element::hasName() const |
846 | { |
847 | return elementData() && elementData()->hasName(); |
848 | } |
849 | |
850 | inline UniqueElementData& Element::ensureUniqueElementData() |
851 | { |
852 | if (!elementData() || !elementData()->isUnique()) |
853 | createUniqueElementData(); |
854 | return static_cast<UniqueElementData&>(*m_elementData); |
855 | } |
856 | |
857 | inline bool shouldIgnoreAttributeCase(const Element& element) |
858 | { |
859 | return element.isHTMLElement() && element.document().isHTMLDocument(); |
860 | } |
861 | |
862 | inline void Element::setHasFocusWithin(bool flag) |
863 | { |
864 | if (hasFocusWithin() == flag) |
865 | return; |
866 | setFlag(flag, HasFocusWithin); |
867 | if (styleAffectedByFocusWithin()) |
868 | invalidateStyleForSubtree(); |
869 | } |
870 | |
871 | template<typename... QualifiedNames> |
872 | inline const AtomicString& Element::getAttribute(const QualifiedName& name, const QualifiedNames&... names) const |
873 | { |
874 | const AtomicString& value = getAttribute(name); |
875 | if (!value.isNull()) |
876 | return value; |
877 | return getAttribute(names...); |
878 | } |
879 | |
880 | } // namespace WebCore |
881 | |
882 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Element) |
883 | static bool isType(const WebCore::Node& node) { return node.isElementNode(); } |
884 | static bool isType(const WebCore::EventTarget& target) { return is<WebCore::Node>(target) && isType(downcast<WebCore::Node>(target)); } |
885 | SPECIALIZE_TYPE_TRAITS_END() |
886 | |