From 0c07c2d73df9862b28fc1efe2971ee2c08a948e1 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 11 Sep 2018 17:14:55 +0200 Subject: [PATCH] Manage slot manipulation centrally and special case replace operations This is an attempt at fixing https://github.com/w3c/webcomponents/issues/764. I first wrote an algorithm that combined the operations done by remove and insert. I then used that for replace and replace all. I then abstracted it to avoid duplication. I'm a little worried that this is not correct as this delays assigning slotables to a slot quite a bit, which I think might be observable in some cases. --- dom.bs | 66 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/dom.bs b/dom.bs index bd8bfb874..b3d25e914 100644 --- a/dom.bs +++ b/dom.bs @@ -2203,6 +2203,36 @@ steps:
  • If slot is non-null, then run assign slotables for slot. +

    To update slots, given removedNodes, parent, and +addedNodes, run these steps: + +

      +
    1. +

      For each removedNode in removedNodes: + +

        +
      1. If removedNode is assigned, then run + assign slotables for removedNode's assigned slot. + +

      2. If removedNode has an inclusive descendant that is a slot, then + run assign slotables for a tree with removedNode. +

      + +
    2. If parent's root is a shadow root and + parent is a slot whose assigned nodes is the empty list, then run + signal a slot change for parent. + +

    3. Run assign slotables for a tree with parent's root. + +

    4. +

      For each addedNode in addedNodes: + +

        +
      1. If parent is a shadow host and addedNode is a + slotable, then assign a slot for addedNode. +

      +
    +
    Signaling slot change

    Each unit of related similar-origin browsing contexts has a @@ -2382,17 +2412,11 @@ before a child, with an optional suppress observers flag, run

  • Otherwise, insert node into parent's children before child's index. -

  • If parent is a shadow host and node is a - slotable, then assign a slot for node. -

  • If node is a {{Text}} node, run the child text content change steps for parent. -
  • If parent's root is a shadow root, and - parent is a slot whose assigned nodes is the empty list, - then run signal a slot change for parent. - -

  • Run assign slotables for a tree with node's root. +

  • If the suppress observers flag is unset, then update slots with « », + parent, and « node ».

  • For each shadow-including inclusive descendant inclusiveDescendant of @@ -2422,7 +2446,7 @@ before a child, with an optional suppress observers flag, run

  • -
  • If suppress observers flag is unset, then queue a tree mutation record for +

  • If the suppress observers flag is unset, then queue a tree mutation record for parent with nodes, « », previousSibling, and child. @@ -2541,6 +2565,9 @@ within a parent, run these steps:

  • Insert node into parent before reference child with the suppress observers flag set. +

  • Update slots with « removedNodes », parent, and + « nodes ». +

  • Queue a tree mutation record for parent with nodes, removedNodes, previousSibling, and reference child. @@ -2574,6 +2601,9 @@ To replace all with a

  • If node is not null, then insert node into parent before null with the suppress observers flag set. +

  • If the suppress observers flag is unset, then update slots with + « removedNodes », parent, and « addedNodes ». +

  • Queue a tree mutation record for parent with addedNodes, removedNodes, null, and null. @@ -2634,20 +2664,8 @@ with an optional suppress observers flag, run these steps:

  • Remove node from its parent's children. -
  • If node is assigned, then run assign slotables for - node's assigned slot. - -

  • If parent's root is a shadow root, and - parent is a slot whose assigned nodes is the empty list, - then run signal a slot change for parent. - -

  • If node has an inclusive descendant that is a slot, then: - -

      -
    1. Run assign slotables for a tree with parent's root. - -

    2. Run assign slotables for a tree with node's root. -

    +
  • If the suppress observers flag is unset, then update slots with + « node », parent, and « ».

  • Run the removing steps with node and parent. @@ -2683,7 +2701,7 @@ with an optional suppress observers flag, run these steps: source is registered to node's registered observer list. -

  • If suppress observers flag is unset, then queue a tree mutation record for +

  • If the suppress observers flag is unset, then queue a tree mutation record for parent with « », « node », oldPreviousSibling, and oldNextSibling.