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

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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 return GetDistributedNodesWithFallback();
81 }
82
83 const HeapVector<Member<Node>>
84 HTMLSlotElement::GetDistributedNodesWithFallback() const {
hayato 2017/05/16 07:50:07 The concept of DistributedNodes includes Fallback
80 if (SupportsDistribution()) 85 if (SupportsDistribution())
81 return distributed_nodes_; 86 return distributed_nodes_;
82 87 // 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 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 =
141 other.GetDistributedNodesWithFallback();
142 distributed_nodes_.AppendVector(other_distributed_nodes);
143
144 for (const auto& node : other_distributed_nodes)
137 distributed_indices_.Set(node.Get(), index++); 145 distributed_indices_.Set(node.Get(), index++);
138 } 146 }
139 147
140 void HTMLSlotElement::ClearDistribution() { 148 void HTMLSlotElement::ClearDistribution() {
141 // TODO(hayato): Figure out when to call 149 // TODO(hayato): Figure out when to call
142 // lazyReattachDistributedNodesIfNeeded() 150 // lazyReattachDistributedNodesIfNeeded()
143 assigned_nodes_.clear(); 151 assigned_nodes_.clear();
144 distributed_nodes_.clear(); 152 distributed_nodes_.clear();
145 distributed_indices_.clear(); 153 distributed_indices_.clear();
146 } 154 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 384
377 DEFINE_TRACE(HTMLSlotElement) { 385 DEFINE_TRACE(HTMLSlotElement) {
378 visitor->Trace(assigned_nodes_); 386 visitor->Trace(assigned_nodes_);
379 visitor->Trace(distributed_nodes_); 387 visitor->Trace(distributed_nodes_);
380 visitor->Trace(old_distributed_nodes_); 388 visitor->Trace(old_distributed_nodes_);
381 visitor->Trace(distributed_indices_); 389 visitor->Trace(distributed_indices_);
382 HTMLElement::Trace(visitor); 390 HTMLElement::Trace(visitor);
383 } 391 }
384 392
385 } // namespace blink 393 } // 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