summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/dom/node.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/dom/node.h')
-rw-r--r--chromium/third_party/blink/renderer/core/dom/node.h243
1 files changed, 143 insertions, 100 deletions
diff --git a/chromium/third_party/blink/renderer/core/dom/node.h b/chromium/third_party/blink/renderer/core/dom/node.h
index e2a2045833d..767e551efc4 100644
--- a/chromium/third_party/blink/renderer/core/dom/node.h
+++ b/chromium/third_party/blink/renderer/core/dom/node.h
@@ -27,7 +27,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_DOM_NODE_H_
#include "base/macros.h"
-#include "third_party/blink/public/platform/web_focus_type.h"
+#include "third_party/blink/public/mojom/input/focus_type.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/events/event_target.h"
#include "third_party/blink/renderer/core/dom/events/simulated_click_options.h"
@@ -80,12 +80,14 @@ class V8ScrollStateCallback;
class WebPluginContainerImpl;
struct PhysicalRect;
-const int kNodeStyleChangeShift = 19;
-const int kNodeCustomElementShift = 21;
+const int kDOMNodeTypeShift = 2;
+const int kElementNamespaceTypeShift = 4;
+const int kNodeStyleChangeShift = 17;
+const int kNodeCustomElementShift = 19;
// Values for kChildNeedsStyleRecalcFlag, controlling whether a node gets its
// style recalculated.
-enum StyleChangeType {
+enum StyleChangeType : uint32_t {
// This node does not need style recalculation.
kNoStyleChange = 0,
// This node needs style recalculation.
@@ -94,14 +96,12 @@ enum StyleChangeType {
kSubtreeStyleChange = 2 << kNodeStyleChangeShift,
};
-enum class CustomElementState {
+enum class CustomElementState : uint32_t {
// https://dom.spec.whatwg.org/#concept-element-custom-element-state
kUncustomized = 0,
kCustom = 1 << kNodeCustomElementShift,
kUndefined = 2 << kNodeCustomElementShift,
kFailed = 3 << kNodeCustomElementShift,
-
- kNotDefinedFlag = 2 << kNodeCustomElementShift,
};
enum class SlotChangeType {
@@ -260,7 +260,7 @@ class CORE_EXPORT Node : public EventTarget {
const AtomicString& lookupNamespaceURI(const String& prefix) const;
String textContent(bool convert_brs_to_newlines = false) const;
- void setTextContent(const String&);
+ virtual void setTextContent(const String&);
void textContent(StringOrTrustedScript& result);
virtual void setTextContent(const StringOrTrustedScript&, ExceptionState&);
@@ -269,13 +269,28 @@ class CORE_EXPORT Node : public EventTarget {
void SetComputedStyle(scoped_refptr<const ComputedStyle> computed_style);
// Other methods (not part of DOM)
+ ALWAYS_INLINE bool IsTextNode() const {
+ return GetDOMNodeType() == DOMNodeType::kText;
+ }
+ ALWAYS_INLINE bool IsContainerNode() const {
+ return GetFlag(kIsContainerFlag);
+ }
+ ALWAYS_INLINE bool IsElementNode() const {
+ return GetDOMNodeType() == DOMNodeType::kElement;
+ }
+ ALWAYS_INLINE bool IsDocumentFragment() const {
+ return GetDOMNodeType() == DOMNodeType::kDocumentFragment;
+ }
- bool IsElementNode() const { return GetFlag(kIsElementFlag); }
- bool IsContainerNode() const { return GetFlag(kIsContainerFlag); }
- bool IsTextNode() const { return GetFlag(kIsTextFlag); }
- bool IsHTMLElement() const { return GetFlag(kIsHTMLFlag); }
- bool IsMathMLElement() const { return GetFlag(kIsMathMLFlag); }
- bool IsSVGElement() const { return GetFlag(kIsSVGFlag); }
+ ALWAYS_INLINE bool IsHTMLElement() const {
+ return GetElementNamespaceType() == ElementNamespaceType::kHTML;
+ }
+ ALWAYS_INLINE bool IsMathMLElement() const {
+ return GetElementNamespaceType() == ElementNamespaceType::kMathML;
+ }
+ ALWAYS_INLINE bool IsSVGElement() const {
+ return GetElementNamespaceType() == ElementNamespaceType::kSVG;
+ }
DISABLE_CFI_PERF bool IsPseudoElement() const {
return GetPseudoId() != kPseudoIdNone;
@@ -335,7 +350,6 @@ class CORE_EXPORT Node : public EventTarget {
bool IsDocumentNode() const;
bool IsTreeScope() const;
- bool IsDocumentFragment() const { return GetFlag(kIsDocumentFragmentFlag); }
bool IsShadowRoot() const { return IsDocumentFragment() && IsTreeScope(); }
bool IsV0InsertionPoint() const { return GetFlag(kIsV0InsertionPointFlag); }
@@ -463,6 +477,10 @@ class CORE_EXPORT Node : public EventTarget {
// Propagates a dirty bit breadcrumb for this element up the ancestor chain.
void MarkAncestorsWithChildNeedsStyleRecalc();
+ // Traverses subtree (include pseudo elements and shadow trees) and
+ // invalidates nodes whose styles depend on font metrics (e.g., 'ex' unit).
+ void MarkSubtreeNeedsStyleRecalcForFontUpdates();
+
// Nodes which are not connected are style clean. Mark them for style recalc
// when inserting them into a document. This method was added as a light-
// weight alternative to SetNeedsStyleRecalc because using that method caused
@@ -574,7 +592,7 @@ class CORE_EXPORT Node : public EventTarget {
SetFlag(flag, kHasEventTargetDataFlag);
}
- virtual void SetFocused(bool flag, WebFocusType);
+ virtual void SetFocused(bool flag, mojom::blink::FocusType);
void SetHasFocusWithin(bool flag);
virtual void SetDragged(bool flag);
@@ -617,6 +635,11 @@ class CORE_EXPORT Node : public EventTarget {
return *tree_scope_;
}
+ // Returns the tree scope where this element originated.
+ // Use this when resolving element references for (CSS url(...)s and #id).
+ // This differs from GetTreeScope for shadow clones inside <svg:use/>.
+ TreeScope& OriginatingTreeScope() const;
+
bool InActiveDocument() const;
// Returns true if this node is connected to a document, false otherwise.
@@ -666,8 +689,8 @@ class CORE_EXPORT Node : public EventTarget {
// have one as well.
LayoutObject* GetLayoutObject() const {
return HasRareData()
- ? data_.rare_data_->GetNodeRenderingData()->GetLayoutObject()
- : data_.node_layout_data_->GetLayoutObject();
+ ? DataAsNodeRareData()->GetNodeRenderingData()->GetLayoutObject()
+ : DataAsNodeRenderingData()->GetLayoutObject();
}
void SetLayoutObject(LayoutObject*);
// Use these two methods with caution.
@@ -744,16 +767,20 @@ class CORE_EXPORT Node : public EventTarget {
//
// Blink notifies this callback regardless if the subtree of the node is a
// document tree or a floating subtree. Implementation can determine the type
- // of subtree by seeing insertionPoint->isConnected(). For a performance
+ // of subtree by seeing insertion_point->isConnected(). For a performance
// reason, notifications are delivered only to ContainerNode subclasses if the
- // insertionPoint is out of document.
+ // insertion_point is out of document.
//
- // There are another callback named didNotifySubtreeInsertionsToDocument(),
+ // There are another callback named DidNotifySubtreeInsertionsToDocument(),
// which is called after all the descendant is notified, if this node was
// inserted into the document tree. Only a few subclasses actually need
// this. To utilize this, the node should return
- // InsertionShouldCallDidNotifySubtreeInsertions from insertedInto().
+ // kInsertionShouldCallDidNotifySubtreeInsertions from InsertedInto().
//
+ // InsertedInto() implementations must not modify the DOM tree, and must not
+ // dispatch synchronous events. On the other hand,
+ // DidNotifySubtreeInsertionsToDocument() may modify the DOM tree, and may
+ // dispatch synchronous events.
enum InsertionNotificationRequest {
kInsertionDone,
kInsertionShouldCallDidNotifySubtreeInsertions
@@ -765,10 +792,12 @@ class CORE_EXPORT Node : public EventTarget {
// Notifies the node that it is no longer part of the tree.
//
- // This is a dual of insertedInto(), and is similar to the
+ // This is a dual of InsertedInto(), and is similar to the
// DOMNodeRemovedFromDocument DOM event, but does not require the overhead of
// event dispatching, and is called _after_ the node is removed from the tree.
//
+ // RemovedFrom() implementations must not modify the DOM tree, and must not
+ // dispatch synchronous events.
virtual void RemovedFrom(ContainerNode& insertion_point);
// FIXME(dominicc): This method is not debug-only--it is used by
@@ -826,10 +855,6 @@ class CORE_EXPORT Node : public EventTarget {
}
virtual void PostDispatchEventHandler(Event&, EventDispatchHandlingState*) {}
- // TODO(crbug.com/1013385): Remove DidPreventDefault. It is here as a
- // temporary fix for form double-submit.
- virtual void DidPreventDefault(const Event&) {}
-
void DispatchScopedEvent(Event&);
virtual void HandleLocalEvents(Event&);
@@ -838,13 +863,11 @@ class CORE_EXPORT Node : public EventTarget {
DispatchEventResult DispatchDOMActivateEvent(int detail,
Event& underlying_event);
- void DispatchSimulatedClick(Event* underlying_event,
+ void DispatchSimulatedClick(const Event* underlying_event,
SimulatedClickMouseEventOptions = kSendNoEvents,
SimulatedClickCreationScope =
SimulatedClickCreationScope::kFromUserAgent);
- void DispatchInputEvent();
-
// Perform the default action for an event.
virtual void DefaultEventHandler(Event&);
void UpdateHadKeyboardEvent(const Event&);
@@ -895,100 +918,128 @@ class CORE_EXPORT Node : public EventTarget {
return GetFlag(kHasDuplicateAttributes);
}
- void SetInDOMNodeRemovedHandler(bool flag) {
- SetFlag(flag, kInDOMNodeRemovedHandler);
- }
- bool InDOMNodeRemovedHandler() const {
- return GetFlag(kInDOMNodeRemovedHandler);
- }
-
bool IsEffectiveRootScroller() const;
+ virtual LayoutBox* AutoscrollBox();
+ virtual void StopAutoscroll();
+
// If the node is a plugin, then this returns its WebPluginContainer.
WebPluginContainerImpl* GetWebPluginContainer() const;
void Trace(Visitor*) override;
private:
- enum NodeFlags {
+ enum NodeFlags : uint32_t {
kHasRareDataFlag = 1,
// Node type flags. These never change once created.
- kIsTextFlag = 1 << 1,
- kIsContainerFlag = 1 << 2,
- kIsElementFlag = 1 << 3,
- kIsHTMLFlag = 1 << 4,
- kIsMathMLFlag = 1 << 5,
- kIsSVGFlag = 1 << 6,
- kIsDocumentFragmentFlag = 1 << 7,
- kIsV0InsertionPointFlag = 1 << 8,
+ kIsContainerFlag = 1 << 1,
+ kDOMNodeTypeMask = 0x3 << kDOMNodeTypeShift,
+ kElementNamespaceTypeMask = 0x3 << kElementNamespaceTypeShift,
+ kIsV0InsertionPointFlag = 1 << 6,
// Changes based on if the element should be treated like a link,
// ex. When setting the href attribute on an <a>.
- kIsLinkFlag = 1 << 9,
+ kIsLinkFlag = 1 << 7,
// Changes based on :hover, :active and :focus state.
- kIsUserActionElementFlag = 1 << 10,
+ kIsUserActionElementFlag = 1 << 8,
// Tree state flags. These change when the element is added/removed
// from a DOM tree.
- kIsConnectedFlag = 1 << 11,
- kIsInShadowTreeFlag = 1 << 12,
+ kIsConnectedFlag = 1 << 9,
+ kIsInShadowTreeFlag = 1 << 10,
// Set by the parser when the children are done parsing.
- kIsFinishedParsingChildrenFlag = 1 << 13,
+ kIsFinishedParsingChildrenFlag = 1 << 11,
// Flags related to recalcStyle.
- kHasCustomStyleCallbacksFlag = 1 << 14,
- kChildNeedsStyleInvalidationFlag = 1 << 15,
- kNeedsStyleInvalidationFlag = 1 << 16,
- kChildNeedsDistributionRecalcFlag = 1 << 17,
- kChildNeedsStyleRecalcFlag = 1 << 18,
- kStyleChangeMask =
- 1 << kNodeStyleChangeShift | 1 << (kNodeStyleChangeShift + 1),
+ kHasCustomStyleCallbacksFlag = 1 << 12,
+ kChildNeedsStyleInvalidationFlag = 1 << 13,
+ kNeedsStyleInvalidationFlag = 1 << 14,
+ kChildNeedsDistributionRecalcFlag = 1 << 15,
+ kChildNeedsStyleRecalcFlag = 1 << 16,
+ kStyleChangeMask = 0x3 << kNodeStyleChangeShift,
kCustomElementStateMask = 0x3 << kNodeCustomElementShift,
- kHasNameOrIsEditingTextFlag = 1 << 23,
- kHasEventTargetDataFlag = 1 << 24,
-
- kV0CustomElementFlag = 1 << 25,
- kV0CustomElementUpgradedFlag = 1 << 26,
+ kHasNameOrIsEditingTextFlag = 1 << 21,
+ kHasEventTargetDataFlag = 1 << 22,
- kNeedsReattachLayoutTree = 1 << 27,
- kChildNeedsReattachLayoutTree = 1 << 28,
+ kV0CustomElementFlag = 1 << 23,
+ kV0CustomElementUpgradedFlag = 1 << 24,
- kHasDuplicateAttributes = 1 << 29,
+ kNeedsReattachLayoutTree = 1 << 25,
+ kChildNeedsReattachLayoutTree = 1 << 26,
- // Temporary flag for some UseCounter items. crbug.com/859391.
- kInDOMNodeRemovedHandler = 1 << 30,
+ kHasDuplicateAttributes = 1 << 27,
- kForceReattachLayoutTree = 1 << 31,
+ kForceReattachLayoutTree = 1 << 28,
kDefaultNodeFlags = kIsFinishedParsingChildrenFlag,
- };
- // 0 bits remaining.
+ // 4 bits remaining.
+ };
- bool GetFlag(NodeFlags mask) const { return node_flags_ & mask; }
+ ALWAYS_INLINE bool GetFlag(NodeFlags mask) const {
+ return node_flags_ & mask;
+ }
void SetFlag(bool f, NodeFlags mask) {
node_flags_ = (node_flags_ & ~mask) | (-(int32_t)f & mask);
}
void SetFlag(NodeFlags mask) { node_flags_ |= mask; }
void ClearFlag(NodeFlags mask) { node_flags_ &= ~mask; }
+ enum class DOMNodeType : uint32_t {
+ kElement = 0,
+ kText = 1 << kDOMNodeTypeShift,
+ kDocumentFragment = 2 << kDOMNodeTypeShift,
+ kOther = 3 << kDOMNodeTypeShift,
+ };
+ ALWAYS_INLINE DOMNodeType GetDOMNodeType() const {
+ return static_cast<DOMNodeType>(node_flags_ & kDOMNodeTypeMask);
+ }
+
+ enum class ElementNamespaceType : uint32_t {
+ kHTML = 0,
+ kMathML = 1 << kElementNamespaceTypeShift,
+ kSVG = 2 << kElementNamespaceTypeShift,
+ kOther = 3 << kElementNamespaceTypeShift,
+ };
+ ALWAYS_INLINE ElementNamespaceType GetElementNamespaceType() const {
+ return static_cast<ElementNamespaceType>(node_flags_ &
+ kElementNamespaceTypeMask);
+ }
+
protected:
enum ConstructionType {
- kCreateOther = kIsFinishedParsingChildrenFlag,
- kCreateText = kDefaultNodeFlags | kIsTextFlag,
- kCreateContainer = kDefaultNodeFlags | kIsContainerFlag,
- kCreateElement = kCreateContainer | kIsElementFlag,
- kCreateShadowRoot =
- kCreateContainer | kIsDocumentFragmentFlag | kIsInShadowTreeFlag,
- kCreateDocumentFragment = kCreateContainer | kIsDocumentFragmentFlag,
- kCreateHTMLElement = kCreateElement | kIsHTMLFlag,
- kCreateMathMLElement = kCreateElement | kIsMathMLFlag,
- kCreateSVGElement = kCreateElement | kIsSVGFlag,
+ kCreateOther = kDefaultNodeFlags |
+ static_cast<NodeFlags>(DOMNodeType::kOther) |
+ static_cast<NodeFlags>(ElementNamespaceType::kOther),
+ kCreateText = kDefaultNodeFlags |
+ static_cast<NodeFlags>(DOMNodeType::kText) |
+ static_cast<NodeFlags>(ElementNamespaceType::kOther),
+ kCreateContainer = kDefaultNodeFlags | kIsContainerFlag |
+ static_cast<NodeFlags>(DOMNodeType::kOther) |
+ static_cast<NodeFlags>(ElementNamespaceType::kOther),
+ kCreateElement = kDefaultNodeFlags | kIsContainerFlag |
+ static_cast<NodeFlags>(DOMNodeType::kElement) |
+ static_cast<NodeFlags>(ElementNamespaceType::kOther),
+ kCreateDocumentFragment =
+ kDefaultNodeFlags | kIsContainerFlag |
+ static_cast<NodeFlags>(DOMNodeType::kDocumentFragment) |
+ static_cast<NodeFlags>(ElementNamespaceType::kOther),
+ kCreateShadowRoot = kCreateDocumentFragment | kIsInShadowTreeFlag,
+ kCreateHTMLElement = kDefaultNodeFlags | kIsContainerFlag |
+ static_cast<NodeFlags>(DOMNodeType::kElement) |
+ static_cast<NodeFlags>(ElementNamespaceType::kHTML),
+ kCreateMathMLElement =
+ kDefaultNodeFlags | kIsContainerFlag |
+ static_cast<NodeFlags>(DOMNodeType::kElement) |
+ static_cast<NodeFlags>(ElementNamespaceType::kMathML),
+ kCreateSVGElement = kDefaultNodeFlags | kIsContainerFlag |
+ static_cast<NodeFlags>(DOMNodeType::kElement) |
+ static_cast<NodeFlags>(ElementNamespaceType::kSVG),
kCreateDocument = kCreateContainer | kIsConnectedFlag,
kCreateV0InsertionPoint = kCreateHTMLElement | kIsV0InsertionPointFlag,
kCreateEditingText = kCreateText | kHasNameOrIsEditingTextFlag,
@@ -1009,7 +1060,7 @@ class CORE_EXPORT Node : public EventTarget {
NodeRareData* RareData() const {
SECURITY_DCHECK(HasRareData());
- return static_cast<NodeRareData*>(data_.rare_data_);
+ return DataAsNodeRareData();
}
NodeRareData& EnsureRareData() {
if (HasRareData())
@@ -1063,8 +1114,14 @@ class CORE_EXPORT Node : public EventTarget {
const HeapHashSet<Member<MutationObserverRegistration>>*
TransientMutationObserverRegistry();
- inline Node* TrustedTypesCheckForScriptNode(Node* child,
- ExceptionState&) const;
+ NodeRareData* DataAsNodeRareData() const {
+ DCHECK(HasRareData());
+ return reinterpret_cast<NodeRareData*>(data_.Get());
+ }
+ NodeRenderingData* DataAsNodeRenderingData() const {
+ DCHECK(!HasRareData());
+ return reinterpret_cast<NodeRenderingData*>(data_.Get());
+ }
uint32_t node_flags_;
Member<Node> parent_or_shadow_host_node_;
@@ -1072,13 +1129,7 @@ class CORE_EXPORT Node : public EventTarget {
Member<Node> previous_;
Member<Node> next_;
// When a node has rare data we move the layoutObject into the rare data.
- union DataUnion {
- DataUnion() : node_layout_data_(&NodeRenderingData::SharedEmptyData()) {}
- // LayoutObjects are fully owned by their DOM node. See LayoutObject's
- // LIFETIME documentation section.
- NodeRenderingData* node_layout_data_;
- NodeRareDataBase* rare_data_;
- } data_;
+ Member<NodeData> data_;
};
inline void Node::SetParentOrShadowHostNode(ContainerNode* parent) {
@@ -1094,14 +1145,6 @@ inline ContainerNode* Node::ParentOrShadowHostNode() const {
// Allow equality comparisons of Nodes by reference or pointer, interchangeably.
DEFINE_COMPARISON_OPERATORS_WITH_REFERENCES(Node)
-#define DEFINE_NODE_TYPE_CASTS(thisType, predicate) \
- DEFINE_TYPE_CASTS(thisType, Node, node, node->predicate, node.predicate)
-
-// This requires isClassName(const Node&).
-#define DEFINE_NODE_TYPE_CASTS_WITH_FUNCTION(thisType) \
- DEFINE_TYPE_CASTS(thisType, Node, node, Is##thisType(*node), \
- Is##thisType(node))
-
CORE_EXPORT std::ostream& operator<<(std::ostream&, const Node&);
CORE_EXPORT std::ostream& operator<<(std::ostream&, const Node*);