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