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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp

Issue 2842263004: Fix assignedNodes({flatten:true}) to return fallback content in document tree (Closed)
Patch Set: Rename GetDistributedNodes to GetDistributedNodesExcludingFallback Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved. 2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 const HeapVector<Member<Node>>& HTMLSlotElement::AssignedNodes() { 63 const HeapVector<Member<Node>>& HTMLSlotElement::AssignedNodes() {
64 DCHECK(!NeedsDistributionRecalc()); 64 DCHECK(!NeedsDistributionRecalc());
65 DCHECK(IsInShadowTree() || assigned_nodes_.IsEmpty()); 65 DCHECK(IsInShadowTree() || assigned_nodes_.IsEmpty());
66 return assigned_nodes_; 66 return assigned_nodes_;
67 } 67 }
68 68
69 const HeapVector<Member<Node>> HTMLSlotElement::assignedNodesForBinding( 69 const HeapVector<Member<Node>> HTMLSlotElement::assignedNodesForBinding(
70 const AssignedNodesOptions& options) { 70 const AssignedNodesOptions& options) {
71 UpdateDistribution(); 71 UpdateDistribution();
72 if (options.hasFlatten() && options.flatten()) 72 if (options.hasFlatten() && options.flatten())
73 return GetDistributedNodesForBinding(); 73 return GetDistributedNodes();
74 return assigned_nodes_; 74 return assigned_nodes_;
75 } 75 }
76 76
77 const HeapVector<Member<Node>> 77 const HeapVector<Member<Node>> HTMLSlotElement::GetDistributedNodes() const {
78 HTMLSlotElement::GetDistributedNodesForBinding() {
79 DCHECK(!NeedsDistributionRecalc());
hayato 2017/05/18 06:58:25 Don't remove DCHECK(). DCHECK() is important and s
kochi 2017/05/18 07:21:49 The only user of GetDistributedNodesForBinding() w
hayato 2017/05/19 04:05:36 Okay. Since it is now private, it can be acceptabl
80 if (SupportsDistribution()) 78 if (SupportsDistribution())
81 return distributed_nodes_; 79 return distributed_nodes_;
82 80 // If a slot does not support distribution, its distributed_nodes_ should not
83 // If a slot does not support distribution, its m_distributedNodes should not
84 // be used. Instead, calculate distribution manually here. This happens only 81 // be used. Instead, calculate distribution manually here. This happens only
85 // in a slot in non-shadow trees, so its assigned nodes are always empty. 82 // in a slot in non-shadow trees, so its assigned nodes are always empty.
86 HeapVector<Member<Node>> distributed_nodes; 83 HeapVector<Member<Node>> distributed_nodes;
87 Node* child = NodeTraversal::FirstChild(*this); 84 Node* child = NodeTraversal::FirstChild(*this);
88 while (child) { 85 while (child) {
89 if (!child->IsSlotable()) { 86 if (!child->IsSlotable()) {
90 child = NodeTraversal::NextSkippingChildren(*child, this); 87 child = NodeTraversal::NextSkippingChildren(*child, this);
91 continue; 88 continue;
92 } 89 }
93 if (isHTMLSlotElement(child)) { 90 if (isHTMLSlotElement(child)) {
94 child = NodeTraversal::Next(*child, this); 91 child = NodeTraversal::Next(*child, this);
95 } else { 92 } else {
96 distributed_nodes.push_back(child); 93 distributed_nodes.push_back(child);
97 child = NodeTraversal::NextSkippingChildren(*child, this); 94 child = NodeTraversal::NextSkippingChildren(*child, this);
98 } 95 }
99 } 96 }
100 return distributed_nodes; 97 return distributed_nodes;
101 } 98 }
102 99
103 const HeapVector<Member<Node>>& HTMLSlotElement::GetDistributedNodes() { 100 const HeapVector<Member<Node>>&
101 HTMLSlotElement::GetDistributedNodesExcludingFallback() {
hayato 2017/05/18 06:58:25 GetDistributedNodesExcludingFallback doesn't sound
kochi 2017/05/18 07:21:49 Hmm, then |distributed_nodes_| is a misnomer. I'm
hayato 2017/05/19 04:05:36 We are adding fallback content to distributed_node
kochi 2017/05/19 04:14:21 Ah, sorry. I was misunderstanding. Let me rework.
104 DCHECK(!NeedsDistributionRecalc()); 102 DCHECK(!NeedsDistributionRecalc());
105 DCHECK(SupportsDistribution() || distributed_nodes_.IsEmpty()); 103 DCHECK(SupportsDistribution() || distributed_nodes_.IsEmpty());
106 return distributed_nodes_; 104 return distributed_nodes_;
107 } 105 }
108 106
109 void HTMLSlotElement::AppendAssignedNode(Node& host_child) { 107 void HTMLSlotElement::AppendAssignedNode(Node& host_child) {
110 DCHECK(host_child.IsSlotable()); 108 DCHECK(host_child.IsSlotable());
111 assigned_nodes_.push_back(&host_child); 109 assigned_nodes_.push_back(&host_child);
112 } 110 }
113 111
(...skipping 11 matching lines...) Expand all
125 } 123 }
126 124
127 void HTMLSlotElement::AppendDistributedNode(Node& node) { 125 void HTMLSlotElement::AppendDistributedNode(Node& node) {
128 size_t size = distributed_nodes_.size(); 126 size_t size = distributed_nodes_.size();
129 distributed_nodes_.push_back(&node); 127 distributed_nodes_.push_back(&node);
130 distributed_indices_.Set(&node, size); 128 distributed_indices_.Set(&node, size);
131 } 129 }
132 130
133 void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) { 131 void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) {
134 size_t index = distributed_nodes_.size(); 132 size_t index = distributed_nodes_.size();
135 distributed_nodes_.AppendVector(other.distributed_nodes_); 133
136 for (const auto& node : other.distributed_nodes_) 134 const HeapVector<Member<Node>>& other_distributed_nodes =
135 other.GetDistributedNodes();
136 distributed_nodes_.AppendVector(other_distributed_nodes);
137
138 for (const auto& node : other_distributed_nodes)
137 distributed_indices_.Set(node.Get(), index++); 139 distributed_indices_.Set(node.Get(), index++);
138 } 140 }
139 141
140 void HTMLSlotElement::ClearDistribution() { 142 void HTMLSlotElement::ClearDistribution() {
141 // TODO(hayato): Figure out when to call 143 // TODO(hayato): Figure out when to call
142 // lazyReattachDistributedNodesIfNeeded() 144 // lazyReattachDistributedNodesIfNeeded()
143 assigned_nodes_.clear(); 145 assigned_nodes_.clear();
144 distributed_nodes_.clear(); 146 distributed_nodes_.clear();
145 distributed_indices_.clear(); 147 distributed_indices_.clear();
146 } 148 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 378
377 DEFINE_TRACE(HTMLSlotElement) { 379 DEFINE_TRACE(HTMLSlotElement) {
378 visitor->Trace(assigned_nodes_); 380 visitor->Trace(assigned_nodes_);
379 visitor->Trace(distributed_nodes_); 381 visitor->Trace(distributed_nodes_);
380 visitor->Trace(old_distributed_nodes_); 382 visitor->Trace(old_distributed_nodes_);
381 visitor->Trace(distributed_indices_); 383 visitor->Trace(distributed_indices_);
382 HTMLElement::Trace(visitor); 384 HTMLElement::Trace(visitor);
383 } 385 }
384 386
385 } // namespace blink 387 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698