| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "core/probe/CoreProbes.h" | 44 #include "core/probe/CoreProbes.h" |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 | 47 |
| 48 using namespace HTMLNames; | 48 using namespace HTMLNames; |
| 49 | 49 |
| 50 inline HTMLSlotElement::HTMLSlotElement(Document& document) | 50 inline HTMLSlotElement::HTMLSlotElement(Document& document) |
| 51 : HTMLElement(slotTag, document) { | 51 : HTMLElement(slotTag, document) { |
| 52 UseCounter::Count(document, UseCounter::kHTMLSlotElement); | 52 UseCounter::Count(document, UseCounter::kHTMLSlotElement); |
| 53 SetHasCustomStyleCallbacks(); | 53 SetHasCustomStyleCallbacks(); |
| 54 // TODO(kochi): This is required for slot fallback contents to be matched |
| 55 // against ::slotted() pseudo element in a document tree. Remove this once |
| 56 // Shadow DOM V0 code is removed. |
| 57 document.SetShadowCascadeOrder(ShadowCascadeOrder::kShadowCascadeV1); |
| 54 } | 58 } |
| 55 | 59 |
| 56 DEFINE_NODE_FACTORY(HTMLSlotElement); | 60 DEFINE_NODE_FACTORY(HTMLSlotElement); |
| 57 | 61 |
| 58 // static | 62 // static |
| 59 AtomicString HTMLSlotElement::NormalizeSlotName(const AtomicString& name) { | 63 AtomicString HTMLSlotElement::NormalizeSlotName(const AtomicString& name) { |
| 60 return (name.IsNull() || name.IsEmpty()) ? g_empty_atom : name; | 64 return (name.IsNull() || name.IsEmpty()) ? g_empty_atom : name; |
| 61 } | 65 } |
| 62 | 66 |
| 67 // static |
| 68 HTMLSlotElement* HTMLSlotElement::FindFallbackSlotElementFor( |
| 69 const Element& element) { |
| 70 // Check if |element| is a fallback content. |
| 71 Element* parent = element.parentElement(); |
| 72 if (!parent || !isHTMLSlotElement(parent) || |
| 73 !toHTMLSlotElement(parent)->AssignedNodes().IsEmpty()) |
| 74 return nullptr; |
| 75 |
| 76 // At this point, |parent| is an immediate parent of element, which is |
| 77 // a <slot> with empty assigned nodes. This slot is one of the following: |
| 78 // (1) doesn't have any slot in ancestor. |
| 79 // (2) have a slot in ancestor which is assigned to another slot. |
| 80 // (3) have a slot in ancestor which has assigned nodes. |
| 81 // In cases (1) and (2), this slot is a fallback content. |
| 82 // In case (3), this slot is not a fallback content. |
| 83 HTMLSlotElement* slot = toHTMLSlotElement(parent); |
| 84 while ((parent = parent->parentElement())) { |
| 85 if (!isHTMLSlotElement(parent)) |
| 86 continue; |
| 87 if (!toHTMLSlotElement(parent)->AssignedNodes().IsEmpty()) |
| 88 return nullptr; |
| 89 slot = toHTMLSlotElement(parent); |
| 90 if (slot->AssignedSlot()) |
| 91 break; |
| 92 } |
| 93 return slot; |
| 94 } |
| 95 |
| 63 const HeapVector<Member<Node>>& HTMLSlotElement::AssignedNodes() { | 96 const HeapVector<Member<Node>>& HTMLSlotElement::AssignedNodes() { |
| 64 DCHECK(!NeedsDistributionRecalc()); | 97 DCHECK(!NeedsDistributionRecalc()); |
| 65 DCHECK(IsInShadowTree() || assigned_nodes_.IsEmpty()); | 98 DCHECK(IsInShadowTree() || assigned_nodes_.IsEmpty()); |
| 66 return assigned_nodes_; | 99 return assigned_nodes_; |
| 67 } | 100 } |
| 68 | 101 |
| 69 const HeapVector<Member<Node>> HTMLSlotElement::assignedNodesForBinding( | 102 const HeapVector<Member<Node>> HTMLSlotElement::assignedNodesForBinding( |
| 70 const AssignedNodesOptions& options) { | 103 const AssignedNodesOptions& options) { |
| 71 UpdateDistribution(); | 104 UpdateDistribution(); |
| 72 if (options.hasFlatten() && options.flatten()) | 105 if (options.hasFlatten() && options.flatten()) |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 395 |
| 363 DEFINE_TRACE(HTMLSlotElement) { | 396 DEFINE_TRACE(HTMLSlotElement) { |
| 364 visitor->Trace(assigned_nodes_); | 397 visitor->Trace(assigned_nodes_); |
| 365 visitor->Trace(distributed_nodes_); | 398 visitor->Trace(distributed_nodes_); |
| 366 visitor->Trace(old_distributed_nodes_); | 399 visitor->Trace(old_distributed_nodes_); |
| 367 visitor->Trace(distributed_indices_); | 400 visitor->Trace(distributed_indices_); |
| 368 HTMLElement::Trace(visitor); | 401 HTMLElement::Trace(visitor); |
| 369 } | 402 } |
| 370 | 403 |
| 371 } // namespace blink | 404 } // namespace blink |
| OLD | NEW |