Commit 76a81eb4 authored by Hayato Ito's avatar Hayato Ito Committed by Commit Bot

Refactor HTMLSlotElement to clarify which parts are related to Incremental Shadow DOM

No behavior change.

Bug: 776656
Change-Id: Ib5b7d88edd3752828f83d13b1e7a026cbd5a9aa9
Reviewed-on: https://chromium-review.googlesource.com/989525
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: default avatarTakayoshi Kochi <kochi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548023}
parent f66e263a
......@@ -201,6 +201,7 @@ void HTMLSlotElement::AppendAssignedNode(Node& host_child) {
}
void HTMLSlotElement::RecalcDistributedNodes() {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
for (auto& node : assigned_nodes_) {
DCHECK(node->IsSlotable());
if (HTMLSlotElement* slot =
......@@ -216,12 +217,14 @@ void HTMLSlotElement::RecalcDistributedNodes() {
}
void HTMLSlotElement::AppendDistributedNode(Node& node) {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
size_t size = distributed_nodes_.size();
distributed_nodes_.push_back(&node);
distributed_indices_.Set(&node, size);
}
void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
size_t index = distributed_nodes_.size();
distributed_nodes_.AppendVector(other.distributed_nodes_);
for (const auto& node : other.distributed_nodes_)
......@@ -233,6 +236,12 @@ void HTMLSlotElement::ClearAssignedNodes() {
assigned_nodes_.clear();
}
void HTMLSlotElement::ClearAssignedNodesAndFlatTreeChildren() {
DCHECK(RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
assigned_nodes_.clear();
flat_tree_children_.clear();
}
void HTMLSlotElement::RecalcFlatTreeChildren() {
DCHECK(RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
DCHECK(SupportsAssignment());
......@@ -252,12 +261,14 @@ void HTMLSlotElement::RecalcFlatTreeChildren() {
}
void HTMLSlotElement::ClearDistribution() {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
assigned_nodes_.clear();
distributed_nodes_.clear();
distributed_indices_.clear();
}
void HTMLSlotElement::SaveAndClearDistribution() {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
old_distributed_nodes_.swap(distributed_nodes_);
ClearDistribution();
}
......@@ -449,7 +460,11 @@ void HTMLSlotElement::RemovedFrom(ContainerNode* insertion_point) {
// This slot was in a shadow tree and got disconnected from the shadow tree
insertion_point->ContainingShadowRoot()->GetSlotAssignment().DidRemoveSlot(
*this);
ClearDistribution();
if (RuntimeEnabledFeatures::IncrementalShadowDOMEnabled()) {
ClearAssignedNodesAndFlatTreeChildren();
} else {
ClearDistribution();
}
}
HTMLElement::RemovedFrom(insertion_point);
......@@ -484,6 +499,7 @@ void HTMLSlotElement::DidRecalcStyle(StyleRecalcChange change) {
}
void HTMLSlotElement::UpdateDistributedNodesWithFallback() {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
if (!distributed_nodes_.IsEmpty())
return;
for (auto& child : NodeTraversal::ChildrenOf(*this)) {
......@@ -536,6 +552,7 @@ void HTMLSlotElement::LazyReattachNodesByDynamicProgramming(
}
void HTMLSlotElement::LazyReattachDistributedNodesIfNeeded() {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
// TODO(hayato): Move this probe to a better place.
probe::didPerformSlotDistribution(this);
......
......@@ -64,35 +64,11 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
return nodes.IsEmpty() ? nullptr : nodes.back().Get();
}
Node* FirstDistributedNode() const {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
DCHECK(SupportsAssignment());
return distributed_nodes_.IsEmpty() ? nullptr
: distributed_nodes_.front().Get();
}
Node* LastDistributedNode() const {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
DCHECK(SupportsAssignment());
return distributed_nodes_.IsEmpty() ? nullptr
: distributed_nodes_.back().Get();
}
Node* AssignedNodeNextTo(const Node&) const;
Node* AssignedNodePreviousTo(const Node&) const;
Node* DistributedNodeNextTo(const Node&) const;
Node* DistributedNodePreviousTo(const Node&) const;
void AppendAssignedNode(Node&);
void RecalcDistributedNodes();
void AppendDistributedNode(Node&);
void AppendDistributedNodesFrom(const HTMLSlotElement& other);
void UpdateDistributedNodesWithFallback();
void LazyReattachDistributedNodesIfNeeded();
void AttachLayoutTree(AttachContext&) final;
void DetachLayoutTree(const AttachContext& = AttachContext()) final;
void RebuildDistributedChildrenLayoutTrees(WhitespaceAttacher&);
......@@ -108,9 +84,6 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
bool HasAssignedNodesSlow() const;
bool FindHostChildWithSameSlotName() const;
void ClearDistribution();
void SaveAndClearDistribution();
bool SupportsAssignment() const { return IsInV1ShadowTree(); }
void CheckFallbackAfterInsertedIntoShadowTree();
......@@ -122,10 +95,6 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
void DispatchSlotChangeEvent();
void ClearSlotChangeEventEnqueued() { slotchange_event_enqueued_ = false; }
// For Incremental Shadow DOM
void ClearAssignedNodes();
void RecalcFlatTreeChildren();
static AtomicString NormalizeSlotName(const AtomicString&);
// For User-Agent Shadow DOM
......@@ -134,6 +103,34 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
virtual void Trace(blink::Visitor*);
// For Incremental Shadow DOM
void ClearAssignedNodes();
void RecalcFlatTreeChildren();
// For Non-Incremental Shadow DOM
void RecalcDistributedNodes();
void AppendDistributedNode(Node&);
void AppendDistributedNodesFrom(const HTMLSlotElement& other);
void UpdateDistributedNodesWithFallback();
void LazyReattachDistributedNodesIfNeeded();
void ClearDistribution();
void SaveAndClearDistribution();
Node* DistributedNodeNextTo(const Node&) const;
Node* DistributedNodePreviousTo(const Node&) const;
Node* FirstDistributedNode() const {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
DCHECK(SupportsAssignment());
return distributed_nodes_.IsEmpty() ? nullptr
: distributed_nodes_.front().Get();
}
Node* LastDistributedNode() const {
DCHECK(!RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
DCHECK(SupportsAssignment());
return distributed_nodes_.IsEmpty() ? nullptr
: distributed_nodes_.back().Get();
}
private:
HTMLSlotElement(Document&);
......@@ -160,7 +157,10 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
const HeapVector<Member<Node>>& GetDistributedNodes();
void ClearAssignedNodesAndFlatTreeChildren();
HeapVector<Member<Node>> assigned_nodes_;
bool slotchange_event_enqueued_ = false;
// For IncrementalShadowDOM
HeapVector<Member<Node>> flat_tree_children_;
......@@ -170,8 +170,6 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
HeapVector<Member<Node>> old_distributed_nodes_;
HeapHashMap<Member<const Node>, size_t> distributed_indices_;
bool slotchange_event_enqueued_ = false;
// TODO(hayato): Move this to more appropriate directory (e.g. platform/wtf)
// if there are more than one usages.
template <typename Container, typename LCSTable, typename BacktrackTable>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment