Пример #1
0
static void flattenAssignedNodes(Vector<Node*>& nodes, const HTMLSlotElement& slot)
{
    auto* assignedNodes = slot.assignedNodes();
    if (!assignedNodes) {
        for (Node* child = slot.firstChild(); child; child = child->nextSibling()) {
            if (is<HTMLSlotElement>(*child))
                flattenAssignedNodes(nodes, downcast<HTMLSlotElement>(*child));
            else if (is<Text>(*child) || is<Element>(*child))
                nodes.append(child);
        }
        return;
    }
    for (Node* node : *assignedNodes) {
        if (is<HTMLSlotElement>(*node))
            flattenAssignedNodes(nodes, downcast<HTMLSlotElement>(*node));
        else
            nodes.append(node);
    }
}
Пример #2
0
Element* SlotScopedTraversal::next(const Element& current) {
  Element* nearestInclusiveAncestorAssignedToSlot =
      SlotScopedTraversal::nearestInclusiveAncestorAssignedToSlot(current);
  DCHECK(nearestInclusiveAncestorAssignedToSlot);
  // Search within children of an element which is assigned to a slot.
  if (Element* next = nextSkippingChildrenOfShadowHost(
          current, *nearestInclusiveAncestorAssignedToSlot))
    return next;

  // Seek to the next element assigned to the same slot.
  HTMLSlotElement* slot =
      nearestInclusiveAncestorAssignedToSlot->assignedSlot();
  DCHECK(slot);
  const HeapVector<Member<Node>>& assignedNodes = slot->assignedNodes();
  size_t currentIndex =
      assignedNodes.find(*nearestInclusiveAncestorAssignedToSlot);
  DCHECK_NE(currentIndex, kNotFound);
  for (++currentIndex; currentIndex < assignedNodes.size(); ++currentIndex) {
    if (assignedNodes[currentIndex]->isElementNode())
      return toElement(assignedNodes[currentIndex]);
  }
  return nullptr;
}