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

Side by Side Diff: third_party/WebKit/Source/core/dom/shadow/FlatTreeTraversal.cpp

Issue 2836753002: Rebuild layout tree in flat tree order. (Closed)
Patch Set: Rebased 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 * * Neither the name of Google Inc. nor the names of its 10 * * Neither the name of Google Inc. nor the names of its
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 ? insertion_point.FirstDistributedNode() 99 ? insertion_point.FirstDistributedNode()
100 : insertion_point.LastDistributedNode())) 100 : insertion_point.LastDistributedNode()))
101 return found; 101 return found;
102 DCHECK(isHTMLShadowElement(insertion_point) || 102 DCHECK(isHTMLShadowElement(insertion_point) ||
103 (isHTMLContentElement(insertion_point) && 103 (isHTMLContentElement(insertion_point) &&
104 !insertion_point.HasChildren())); 104 !insertion_point.HasChildren()));
105 } 105 }
106 return nullptr; 106 return nullptr;
107 } 107 }
108 108
109 static HTMLSlotElement* FinalDestinationSlotFor(const Node& node) {
110 HTMLSlotElement* slot = node.AssignedSlot();
111 if (!slot)
112 return nullptr;
113 for (HTMLSlotElement* next = slot->AssignedSlot(); next;
114 next = next->AssignedSlot()) {
115 slot = next;
116 }
117 return slot;
118 }
119
120 // TODO(hayato): This may return a wrong result for a node which is not in a 109 // TODO(hayato): This may return a wrong result for a node which is not in a
121 // document flat tree. See FlatTreeTraversalTest's redistribution test for 110 // document flat tree. See FlatTreeTraversalTest's redistribution test for
122 // details. 111 // details.
123 Node* FlatTreeTraversal::TraverseSiblings(const Node& node, 112 Node* FlatTreeTraversal::TraverseSiblings(const Node& node,
124 TraversalDirection direction) { 113 TraversalDirection direction) {
125 if (node.IsChildOfV1ShadowHost()) 114 if (node.IsChildOfV1ShadowHost())
126 return TraverseSiblingsForV1HostChild(node, direction); 115 return TraverseSiblingsForV1HostChild(node, direction);
127 116
128 if (ShadowWhereNodeCanBeDistributedForV0(node)) 117 if (ShadowWhereNodeCanBeDistributedForV0(node))
129 return TraverseSiblingsForV0Distribution(node, direction); 118 return TraverseSiblingsForV0Distribution(node, direction);
(...skipping 25 matching lines...) Expand all
155 DCHECK(assigned_insertion_point); 144 DCHECK(assigned_insertion_point);
156 return TraverseSiblings(*assigned_insertion_point, direction); 145 return TraverseSiblings(*assigned_insertion_point, direction);
157 } 146 }
158 } 147 }
159 return nullptr; 148 return nullptr;
160 } 149 }
161 150
162 Node* FlatTreeTraversal::TraverseSiblingsForV1HostChild( 151 Node* FlatTreeTraversal::TraverseSiblingsForV1HostChild(
163 const Node& node, 152 const Node& node,
164 TraversalDirection direction) { 153 TraversalDirection direction) {
165 HTMLSlotElement* slot = FinalDestinationSlotFor(node); 154 HTMLSlotElement* slot = node.FinalDestinationSlot();
166 if (!slot) 155 if (!slot)
167 return nullptr; 156 return nullptr;
168 if (Node* sibling_in_distributed_nodes = 157 if (Node* sibling_in_distributed_nodes =
169 (direction == kTraversalDirectionForward 158 (direction == kTraversalDirectionForward
170 ? slot->DistributedNodeNextTo(node) 159 ? slot->DistributedNodeNextTo(node)
171 : slot->DistributedNodePreviousTo(node))) 160 : slot->DistributedNodePreviousTo(node)))
172 return sibling_in_distributed_nodes; 161 return sibling_in_distributed_nodes;
173 return TraverseSiblings(*slot, direction); 162 return TraverseSiblings(*slot, direction);
174 } 163 }
175 164
(...skipping 12 matching lines...) Expand all
188 177
189 ContainerNode* FlatTreeTraversal::TraverseParent( 178 ContainerNode* FlatTreeTraversal::TraverseParent(
190 const Node& node, 179 const Node& node,
191 ParentTraversalDetails* details) { 180 ParentTraversalDetails* details) {
192 // TODO(hayato): Stop this hack for a pseudo element because a pseudo element 181 // TODO(hayato): Stop this hack for a pseudo element because a pseudo element
193 // is not a child of its parentOrShadowHostNode() in a flat tree. 182 // is not a child of its parentOrShadowHostNode() in a flat tree.
194 if (node.IsPseudoElement()) 183 if (node.IsPseudoElement())
195 return node.ParentOrShadowHostNode(); 184 return node.ParentOrShadowHostNode();
196 185
197 if (node.IsChildOfV1ShadowHost()) { 186 if (node.IsChildOfV1ShadowHost()) {
198 HTMLSlotElement* slot = FinalDestinationSlotFor(node); 187 HTMLSlotElement* slot = node.FinalDestinationSlot();
199 if (!slot) 188 if (!slot)
200 return nullptr; 189 return nullptr;
201 return TraverseParent(*slot); 190 return TraverseParent(*slot);
202 } 191 }
203 192
204 Element* parent = node.parentElement(); 193 Element* parent = node.parentElement();
205 if (parent && isHTMLSlotElement(parent)) { 194 if (parent && isHTMLSlotElement(parent)) {
206 HTMLSlotElement& slot = toHTMLSlotElement(*parent); 195 HTMLSlotElement& slot = toHTMLSlotElement(*parent);
207 if (slot.SupportsDistribution()) { 196 if (slot.SupportsDistribution()) {
208 if (!slot.AssignedNodes().IsEmpty()) 197 if (!slot.AssignedNodes().IsEmpty())
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 383
395 Node& FlatTreeTraversal::LastWithinOrSelf(const Node& node) { 384 Node& FlatTreeTraversal::LastWithinOrSelf(const Node& node) {
396 AssertPrecondition(node); 385 AssertPrecondition(node);
397 Node* last_descendant = LastWithin(node); 386 Node* last_descendant = LastWithin(node);
398 Node& result = last_descendant ? *last_descendant : const_cast<Node&>(node); 387 Node& result = last_descendant ? *last_descendant : const_cast<Node&>(node);
399 AssertPostcondition(&result); 388 AssertPostcondition(&result);
400 return result; 389 return result;
401 } 390 }
402 391
403 } // namespace blink 392 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Node.cpp ('k') | third_party/WebKit/Source/core/dom/shadow/InsertionPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698