Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp

Issue 2460813002: Make slots in non-shadow trees participate in a flat tree (Closed)
Patch Set: update expectation Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
index 21250c6778eb177957f7c271565fd89c43ac5f69..fa40b92faffe18c27fb4c67dfe67fbe4188eb9fd 100644
--- a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
@@ -68,18 +68,20 @@ const HeapVector<Member<Node>> HTMLSlotElement::assignedNodesForBinding(
const AssignedNodesOptions& options) {
updateDistribution();
if (options.hasFlatten() && options.flatten())
- return getDistributedNodes();
+ return getDistributedNodesForBinding();
return m_assignedNodes;
}
-void HTMLSlotElement::updateDistributedNodesManually() {
- DCHECK(!supportsDistribution());
- // A slot is unlikely to be used outside of a shadow tree.
- // We do not need to optimize this case in most cases.
- // TODO(hayato): If this path causes a performance issue, we should move
- // ShadowRoot::m_slotAssignment into TreeScopreRareData-ish and
- // update the distribution code so it considers a document tree too.
- clearDistribution();
+const HeapVector<Member<Node>>
+HTMLSlotElement::getDistributedNodesForBinding() {
+ DCHECK(!needsDistributionRecalc());
+ if (supportsDistribution())
+ return m_distributedNodes;
+
+ // If a slot does not support distribution, its m_distributedNodes should not
+ // be used. Instead, calculate distribution manually here. This happens only
+ // in a slot in non-shadow trees, so its assigned nodes are always empty.
+ HeapVector<Member<Node>> distributedNodes;
Node* child = NodeTraversal::firstChild(*this);
while (child) {
if (!child->isSlotable()) {
@@ -89,18 +91,16 @@ void HTMLSlotElement::updateDistributedNodesManually() {
if (isHTMLSlotElement(child)) {
child = NodeTraversal::next(*child, this);
} else {
- m_distributedNodes.append(child);
+ distributedNodes.append(child);
child = NodeTraversal::nextSkippingChildren(*child, this);
}
}
+ return distributedNodes;
}
const HeapVector<Member<Node>>& HTMLSlotElement::getDistributedNodes() {
DCHECK(!needsDistributionRecalc());
- // m_distributedNodes of slots in non-shadow trees are not updated in recalc
- // distribution flow.
- if (!supportsDistribution())
- updateDistributedNodesManually();
+ DCHECK(supportsDistribution() || m_distributedNodes.isEmpty());
return m_distributedNodes;
}
@@ -156,6 +156,7 @@ void HTMLSlotElement::dispatchSlotChangeEvent() {
}
Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const {
+ DCHECK(supportsDistribution());
const auto& it = m_distributedIndices.find(&node);
if (it == m_distributedIndices.end())
return nullptr;
@@ -166,6 +167,7 @@ Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const {
}
Node* HTMLSlotElement::distributedNodePreviousTo(const Node& node) const {
+ DCHECK(supportsDistribution());
const auto& it = m_distributedIndices.find(&node);
if (it == m_distributedIndices.end())
return nullptr;
@@ -180,18 +182,20 @@ AtomicString HTMLSlotElement::name() const {
}
void HTMLSlotElement::attachLayoutTree(const AttachContext& context) {
- for (auto& node : getDistributedNodes()) {
- if (node->needsAttach())
- node->attachLayoutTree(context);
+ if (supportsDistribution()) {
+ for (auto& node : m_distributedNodes) {
+ if (node->needsAttach())
+ node->attachLayoutTree(context);
+ }
}
-
HTMLElement::attachLayoutTree(context);
}
void HTMLSlotElement::detachLayoutTree(const AttachContext& context) {
- for (auto& node : m_distributedNodes)
- node->lazyReattachIfAttached();
-
+ if (supportsDistribution()) {
+ for (auto& node : m_distributedNodes)
+ node->lazyReattachIfAttached();
+ }
HTMLElement::detachLayoutTree(context);
}
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698