OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/shadow/SlotScopedTraversal.h" | 5 #include "core/dom/shadow/SlotScopedTraversal.h" |
6 | 6 |
7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
8 #include "core/dom/ElementTraversal.h" | 8 #include "core/dom/ElementTraversal.h" |
9 #include "core/html/HTMLSlotElement.h" | 9 #include "core/html/HTMLSlotElement.h" |
10 | 10 |
11 namespace blink { | 11 namespace blink { |
12 | 12 |
13 HTMLSlotElement* SlotScopedTraversal::findScopeOwnerSlot( | 13 HTMLSlotElement* SlotScopedTraversal::findScopeOwnerSlot( |
14 const Element& current) { | 14 const Element& current) { |
15 if (Element* nearestAncestorAssignedToSlot = | 15 if (Element* nearestAncestorAssignedToSlot = |
16 SlotScopedTraversal::nearestAncestorAssignedToSlot(current)) | 16 SlotScopedTraversal::nearestAncestorAssignedToSlot(current)) |
17 return nearestAncestorAssignedToSlot->assignedSlot(); | 17 return nearestAncestorAssignedToSlot->assignedSlot(); |
18 return nullptr; | 18 return nullptr; |
19 } | 19 } |
20 | 20 |
21 Element* SlotScopedTraversal::nearestAncestorAssignedToSlot( | 21 Element* SlotScopedTraversal::nearestAncestorAssignedToSlot( |
22 const Element& current) { | 22 const Element& current) { |
23 // nearestAncestorAssignedToSlot returns an ancestor element of current which
is directly assigned to a slot. | 23 // nearestAncestorAssignedToSlot returns an ancestor element of current which |
| 24 // is directly assigned to a slot. |
24 Element* element = const_cast<Element*>(¤t); | 25 Element* element = const_cast<Element*>(¤t); |
25 for (; element; element = element->parentElement()) { | 26 for (; element; element = element->parentElement()) { |
26 if (element->assignedSlot()) | 27 if (element->assignedSlot()) |
27 break; | 28 break; |
28 } | 29 } |
29 return element; | 30 return element; |
30 } | 31 } |
31 | 32 |
32 Element* SlotScopedTraversal::next(const Element& current) { | 33 Element* SlotScopedTraversal::next(const Element& current) { |
33 // current.assignedSlot returns a slot only when current is assigned explicitl
y | 34 // current.assignedSlot returns a slot only when current is assigned |
34 // If current is assigned to a slot, return a descendant of current, which is
in the assigned scope of the same slot as current. | 35 // explicitly |
| 36 // If current is assigned to a slot, return a descendant of current, which is |
| 37 // in the assigned scope of the same slot as current. |
35 HTMLSlotElement* slot = current.assignedSlot(); | 38 HTMLSlotElement* slot = current.assignedSlot(); |
36 Element* nearestAncestorAssignedToSlot = | 39 Element* nearestAncestorAssignedToSlot = |
37 SlotScopedTraversal::nearestAncestorAssignedToSlot(current); | 40 SlotScopedTraversal::nearestAncestorAssignedToSlot(current); |
38 if (slot) { | 41 if (slot) { |
39 if (Element* next = ElementTraversal::next(current, ¤t)) | 42 if (Element* next = ElementTraversal::next(current, ¤t)) |
40 return next; | 43 return next; |
41 } else { | 44 } else { |
42 // If current is in assigned scope, find an assigned ancestor. | 45 // If current is in assigned scope, find an assigned ancestor. |
43 DCHECK(nearestAncestorAssignedToSlot); | 46 DCHECK(nearestAncestorAssignedToSlot); |
44 if (Element* next = | 47 if (Element* next = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } | 84 } |
82 } | 85 } |
83 return nullptr; | 86 return nullptr; |
84 } | 87 } |
85 | 88 |
86 bool SlotScopedTraversal::isSlotScoped(const Element& current) { | 89 bool SlotScopedTraversal::isSlotScoped(const Element& current) { |
87 return SlotScopedTraversal::nearestAncestorAssignedToSlot(current); | 90 return SlotScopedTraversal::nearestAncestorAssignedToSlot(current); |
88 } | 91 } |
89 | 92 |
90 } // namespace blink | 93 } // namespace blink |
OLD | NEW |