Esempio n. 1
0
bool HTMLSlotElement::findHostChildWithSameSlotName() const {
  ShadowRoot* root = containingShadowRoot();
  DCHECK(root);
  DCHECK(root->isV1());
  SlotAssignment& assignment = root->ensureSlotAssignment();
  return assignment.findHostChildBySlotName(name());
}
Esempio n. 2
0
void HTMLSlotElement::removedFrom(ContainerNode* insertionPoint) {
  // `removedFrom` is called after the node is removed from the tree.
  // That means:
  // 1. If this slot is still in a tree scope, it means the slot has been in a
  // shadow tree. An inclusive shadow-including ancestor of the shadow host was
  // originally removed from its parent.
  // 2. Or (this slot is now not in a tree scope), this slot's inclusive
  // ancestor was orginally removed from its parent (== insertion point). This
  // slot and the originally removed node was in the same tree.

  ShadowRoot* root = containingShadowRootBeforeRemoved(*this, *insertionPoint);
  if (root) {
    if (ElementShadow* rootOwner = root->owner())
      rootOwner->setNeedsDistributionRecalc();
  }

  // Since this insertion point is no longer visible from the shadow subtree, it
  // need to clean itself up.
  clearDistribution();

  if (root && root->isV1() && root == insertionPoint->treeScope().rootNode()) {
    // This slot was in a shadow tree and got disconnected from the shadow root.
    root->ensureSlotAssignment().slotRemoved(*this);
  }

  HTMLElement::removedFrom(insertionPoint);
}
bool InsertionPoint::canBeActive() const
{
ShadowRoot* shadowRoot = containingShadowRoot();
if (!shadowRoot)
    return false;
if (shadowRoot->isV1())
    return false;
return !Traversal<InsertionPoint>::firstAncestor(*this);
}
Esempio n. 4
0
bool HTMLSlotElement::hasAssignedNodesSlow() const {
  ShadowRoot* root = containingShadowRoot();
  DCHECK(root);
  DCHECK(root->isV1());
  SlotAssignment& assignment = root->ensureSlotAssignment();
  if (assignment.findSlotByName(name()) != this)
    return false;
  return assignment.findHostChildBySlotName(name());
}
Esempio n. 5
0
void HTMLSlotElement::enqueueSlotChangeEvent() {
  if (!m_slotchangeEventEnqueued) {
    Microtask::enqueueMicrotask(WTF::bind(
        &HTMLSlotElement::dispatchSlotChangeEvent, wrapPersistent(this)));
    m_slotchangeEventEnqueued = true;
  }

  ShadowRoot* root = containingShadowRoot();
  DCHECK(root);
  DCHECK(root->isV1());
  root->owner()->setNeedsDistributionRecalc();
  // Check slotchange recursively since this slotchange may cause another
  // slotchange.
  checkSlotChange();
}
Esempio n. 6
0
Node::InsertionNotificationRequest HTMLSlotElement::insertedInto(
    ContainerNode* insertionPoint) {
  HTMLElement::insertedInto(insertionPoint);
  ShadowRoot* root = containingShadowRoot();
  if (root) {
    DCHECK(root->owner());
    root->owner()->setNeedsDistributionRecalc();
    // Relevant DOM Standard: https://dom.spec.whatwg.org/#concept-node-insert
    // - 6.4:  Run assign slotables for a tree with node's tree and a set
    // containing each inclusive descendant of node that is a slot.
    if (root->isV1() && !wasInShadowTreeBeforeInserted(*this, *insertionPoint))
      root->ensureSlotAssignment().slotAdded(*this);
  }

  // We could have been distributed into in a detached subtree, make sure to
  // clear the distribution when inserted again to avoid cycles.
  clearDistribution();

  return InsertionDone;
}