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

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: Remove failure expected.txt. 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 if (options.hasFlatten() && options.flatten()) 72 if (options.hasFlatten() && options.flatten())
73 return GetDistributedNodesForBinding(); 73 return GetDistributedNodesForBinding();
74 return assigned_nodes_; 74 return assigned_nodes_;
75 } 75 }
76 76
77 const HeapVector<Member<Node>> 77 const HeapVector<Member<Node>>
78 HTMLSlotElement::GetDistributedNodesForBinding() { 78 HTMLSlotElement::GetDistributedNodesForBinding() {
79 DCHECK(!NeedsDistributionRecalc()); 79 DCHECK(!NeedsDistributionRecalc());
80 if (SupportsDistribution()) 80 if (SupportsDistribution())
81 return distributed_nodes_; 81 return distributed_nodes_;
82 return GetDistributedNodesOfSlotInDocument();
83 }
82 84
85 const HeapVector<Member<Node>>
86 HTMLSlotElement::GetDistributedNodesOfSlotInDocument() const {
83 // If a slot does not support distribution, its m_distributedNodes should not 87 // If a slot does not support distribution, its m_distributedNodes should not
84 // be used. Instead, calculate distribution manually here. This happens only 88 // 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. 89 // in a slot in non-shadow trees, so its assigned nodes are always empty.
86 HeapVector<Member<Node>> distributed_nodes; 90 HeapVector<Member<Node>> distributed_nodes;
87 Node* child = NodeTraversal::FirstChild(*this); 91 Node* child = NodeTraversal::FirstChild(*this);
88 while (child) { 92 while (child) {
89 if (!child->IsSlotable()) { 93 if (!child->IsSlotable()) {
90 child = NodeTraversal::NextSkippingChildren(*child, this); 94 child = NodeTraversal::NextSkippingChildren(*child, this);
91 continue; 95 continue;
92 } 96 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 129 }
126 130
127 void HTMLSlotElement::AppendDistributedNode(Node& node) { 131 void HTMLSlotElement::AppendDistributedNode(Node& node) {
128 size_t size = distributed_nodes_.size(); 132 size_t size = distributed_nodes_.size();
129 distributed_nodes_.push_back(&node); 133 distributed_nodes_.push_back(&node);
130 distributed_indices_.Set(&node, size); 134 distributed_indices_.Set(&node, size);
131 } 135 }
132 136
133 void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) { 137 void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) {
134 size_t index = distributed_nodes_.size(); 138 size_t index = distributed_nodes_.size();
135 distributed_nodes_.AppendVector(other.distributed_nodes_); 139
140 if (other.SupportsDistribution()) {
hayato 2017/05/12 03:19:09 Could you avoid if else here? It looks a functiona
kochi 2017/05/12 07:26:33 I see, having inconsistent distributed_nodes_ and
kochi 2017/05/12 07:53:14 Hmm, this function is called when resolving distri
141 distributed_nodes_.AppendVector(other.distributed_nodes_);
142 } else {
143 distributed_nodes_.AppendVector(
144 other.GetDistributedNodesOfSlotInDocument());
145 }
146
136 for (const auto& node : other.distributed_nodes_) 147 for (const auto& node : other.distributed_nodes_)
137 distributed_indices_.Set(node.Get(), index++); 148 distributed_indices_.Set(node.Get(), index++);
138 } 149 }
139 150
140 void HTMLSlotElement::ClearDistribution() { 151 void HTMLSlotElement::ClearDistribution() {
141 // TODO(hayato): Figure out when to call 152 // TODO(hayato): Figure out when to call
142 // lazyReattachDistributedNodesIfNeeded() 153 // lazyReattachDistributedNodesIfNeeded()
143 assigned_nodes_.clear(); 154 assigned_nodes_.clear();
144 distributed_nodes_.clear(); 155 distributed_nodes_.clear();
145 distributed_indices_.clear(); 156 distributed_indices_.clear();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 373
363 DEFINE_TRACE(HTMLSlotElement) { 374 DEFINE_TRACE(HTMLSlotElement) {
364 visitor->Trace(assigned_nodes_); 375 visitor->Trace(assigned_nodes_);
365 visitor->Trace(distributed_nodes_); 376 visitor->Trace(distributed_nodes_);
366 visitor->Trace(old_distributed_nodes_); 377 visitor->Trace(old_distributed_nodes_);
367 visitor->Trace(distributed_indices_); 378 visitor->Trace(distributed_indices_);
368 HTMLElement::Trace(visitor); 379 HTMLElement::Trace(visitor);
369 } 380 }
370 381
371 } // namespace blink 382 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698