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

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: tentative 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 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()); 78 DCHECK(!NeedsDistributionRecalc());
79 DCHECK(SupportsDistribution() || distributed_nodes_.IsEmpty());
80 if (SupportsDistribution()) 80 if (SupportsDistribution())
81 return distributed_nodes_; 81 return distributed_nodes_;
82 // If a slot does not support distribution, its distributed_nodes_ is not
83 // pre-calculated and empty. Instead, return fallback content for this slot.
84 // This happens only in a slot in non-shadow trees, so its assigned nodes
85 // are always empty.
86 return GetFallbackContent();
87 }
82 88
83 // If a slot does not support distribution, its m_distributedNodes should not 89 const HeapVector<Member<Node>>
84 // be used. Instead, calculate distribution manually here. This happens only 90 HTMLSlotElement::GetFallbackContent() const {
85 // in a slot in non-shadow trees, so its assigned nodes are always empty. 91 DCHECK(!SupportsDistribution() && distributed_nodes_.IsEmpty());
86 HeapVector<Member<Node>> distributed_nodes; 92 HeapVector<Member<Node>> distributed_nodes;
87 Node* child = NodeTraversal::FirstChild(*this); 93 Node* child = NodeTraversal::FirstChild(*this);
88 while (child) { 94 while (child) {
89 if (!child->IsSlotable()) { 95 if (!child->IsSlotable()) {
90 child = NodeTraversal::NextSkippingChildren(*child, this); 96 child = NodeTraversal::NextSkippingChildren(*child, this);
91 continue; 97 continue;
92 } 98 }
93 if (isHTMLSlotElement(child)) { 99 if (isHTMLSlotElement(child)) {
94 child = NodeTraversal::Next(*child, this); 100 child = NodeTraversal::Next(*child, this);
95 } else { 101 } else {
96 distributed_nodes.push_back(child); 102 distributed_nodes.push_back(child);
97 child = NodeTraversal::NextSkippingChildren(*child, this); 103 child = NodeTraversal::NextSkippingChildren(*child, this);
98 } 104 }
99 } 105 }
100 return distributed_nodes; 106 return distributed_nodes;
101 } 107 }
102 108
103 const HeapVector<Member<Node>>& HTMLSlotElement::GetDistributedNodes() {
104 DCHECK(!NeedsDistributionRecalc());
105 DCHECK(SupportsDistribution() || distributed_nodes_.IsEmpty());
106 return distributed_nodes_;
107 }
108
109 void HTMLSlotElement::AppendAssignedNode(Node& host_child) { 109 void HTMLSlotElement::AppendAssignedNode(Node& host_child) {
110 DCHECK(host_child.IsSlotable()); 110 DCHECK(host_child.IsSlotable());
111 assigned_nodes_.push_back(&host_child); 111 assigned_nodes_.push_back(&host_child);
112 } 112 }
113 113
114 void HTMLSlotElement::ResolveDistributedNodes() { 114 void HTMLSlotElement::ResolveDistributedNodes() {
115 for (auto& node : assigned_nodes_) { 115 for (auto& node : assigned_nodes_) {
116 DCHECK(node->IsSlotable()); 116 DCHECK(node->IsSlotable());
117 if (isHTMLSlotElement(*node)) 117 if (isHTMLSlotElement(*node))
118 AppendDistributedNodesFrom(toHTMLSlotElement(*node)); 118 AppendDistributedNodesFrom(toHTMLSlotElement(*node));
119 else 119 else
120 AppendDistributedNode(*node); 120 AppendDistributedNode(*node);
121 121
122 if (IsChildOfV1ShadowHost()) 122 if (IsChildOfV1ShadowHost())
123 ParentElementShadow()->SetNeedsDistributionRecalc(); 123 ParentElementShadow()->SetNeedsDistributionRecalc();
124 } 124 }
125 } 125 }
126 126
127 void HTMLSlotElement::AppendDistributedNode(Node& node) { 127 void HTMLSlotElement::AppendDistributedNode(Node& node) {
128 size_t size = distributed_nodes_.size(); 128 size_t size = distributed_nodes_.size();
129 distributed_nodes_.push_back(&node); 129 distributed_nodes_.push_back(&node);
130 distributed_indices_.Set(&node, size); 130 distributed_indices_.Set(&node, size);
131 } 131 }
132 132
133 void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) { 133 void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) {
134 size_t index = distributed_nodes_.size(); 134 size_t index = distributed_nodes_.size();
135 distributed_nodes_.AppendVector(other.distributed_nodes_); 135 const HeapVector<Member<Node>>& other_distributed_nodes =
136 for (const auto& node : other.distributed_nodes_) 136 SupportsDistribution() ? other.distributed_nodes_ :
137 other.GetFallbackContent();
138 distributed_nodes_.AppendVector(other_distributed_nodes);
139 for (const auto& node : other_distributed_nodes)
137 distributed_indices_.Set(node.Get(), index++); 140 distributed_indices_.Set(node.Get(), index++);
138 } 141 }
139 142
140 void HTMLSlotElement::ClearDistribution() { 143 void HTMLSlotElement::ClearDistribution() {
141 // TODO(hayato): Figure out when to call 144 // TODO(hayato): Figure out when to call
142 // lazyReattachDistributedNodesIfNeeded() 145 // lazyReattachDistributedNodesIfNeeded()
143 assigned_nodes_.clear(); 146 assigned_nodes_.clear();
144 distributed_nodes_.clear(); 147 distributed_nodes_.clear();
145 distributed_indices_.clear(); 148 distributed_indices_.clear();
146 } 149 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 379
377 DEFINE_TRACE(HTMLSlotElement) { 380 DEFINE_TRACE(HTMLSlotElement) {
378 visitor->Trace(assigned_nodes_); 381 visitor->Trace(assigned_nodes_);
379 visitor->Trace(distributed_nodes_); 382 visitor->Trace(distributed_nodes_);
380 visitor->Trace(old_distributed_nodes_); 383 visitor->Trace(old_distributed_nodes_);
381 visitor->Trace(distributed_indices_); 384 visitor->Trace(distributed_indices_);
382 HTMLElement::Trace(visitor); 385 HTMLElement::Trace(visitor);
383 } 386 }
384 387
385 } // namespace blink 388 } // 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