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

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: fix for comments. 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 GetDistributedNodesInNonShadowTree();
83 }
82 84
83 // If a slot does not support distribution, its m_distributedNodes should not 85 const HeapVector<Member<Node>>
86 HTMLSlotElement::GetDistributedNodesInNonShadowTree() const {
87 // If a slot does not support distribution, its distributed_nodes_ 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 }
93 if (isHTMLSlotElement(child)) { 97 if (isHTMLSlotElement(child)) {
(...skipping 31 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
136 for (const auto& node : other.distributed_nodes_) 140 const HeapVector<Member<Node>>& other_distributed_nodes =
hayato 2017/05/16 04:22:32 Avoid this temporary vector being allocated. It lo
hayato 2017/05/16 04:26:44 Ah, it is a reference, and being used in L145. Ign
kochi 2017/05/16 06:06:21 Acknowledged.
141 other.SupportsDistribution() ? other.distributed_nodes_
142 : other.GetDistributedNodesInNonShadowTree();
hayato 2017/05/16 04:22:32 As I mentioned before, I prefer more logical name
kochi 2017/05/16 06:06:21 I thought "InNonShadowTree()" is logical in that i
143 distributed_nodes_.AppendVector(other_distributed_nodes);
144
145 for (const auto& node : other_distributed_nodes)
137 distributed_indices_.Set(node.Get(), index++); 146 distributed_indices_.Set(node.Get(), index++);
138 } 147 }
139 148
140 void HTMLSlotElement::ClearDistribution() { 149 void HTMLSlotElement::ClearDistribution() {
141 // TODO(hayato): Figure out when to call 150 // TODO(hayato): Figure out when to call
142 // lazyReattachDistributedNodesIfNeeded() 151 // lazyReattachDistributedNodesIfNeeded()
143 assigned_nodes_.clear(); 152 assigned_nodes_.clear();
144 distributed_nodes_.clear(); 153 distributed_nodes_.clear();
145 distributed_indices_.clear(); 154 distributed_indices_.clear();
146 } 155 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 373
365 DEFINE_TRACE(HTMLSlotElement) { 374 DEFINE_TRACE(HTMLSlotElement) {
366 visitor->Trace(assigned_nodes_); 375 visitor->Trace(assigned_nodes_);
367 visitor->Trace(distributed_nodes_); 376 visitor->Trace(distributed_nodes_);
368 visitor->Trace(old_distributed_nodes_); 377 visitor->Trace(old_distributed_nodes_);
369 visitor->Trace(distributed_indices_); 378 visitor->Trace(distributed_indices_);
370 HTMLElement::Trace(visitor); 379 HTMLElement::Trace(visitor);
371 } 380 }
372 381
373 } // namespace blink 382 } // namespace blink
OLDNEW
« 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