From 68e57efbd02b496857016522e664875fa20fe956 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 | 67 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/dom.bs b/dom.bs index 2a7c77e0..ff8cefaf 100644 --- a/dom.bs +++ b/dom.bs @@ -2279,6 +2279,36 @@ steps:
  • If slot is non-null, then run assign slottables 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 similar-origin window agent has signal slots @@ -2432,14 +2462,8 @@ 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 - slottable, then assign a slot for node. - -

  • 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 slottables 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 @@ -2469,7 +2493,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.

  • Run the children changed steps for parent. @@ -2559,6 +2583,9 @@ within a parent, run these steps:

  • Insert node into parent before referenceChild 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 referenceChild. @@ -2585,6 +2612,9 @@ within a parent, run these steps:

  • If node is non-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 ». +

  • If either addedNodes or removedNodes is not empty, then queue a tree mutation record for parent with addedNodes, removedNodes, null, and null. @@ -2649,21 +2679,8 @@ indicated in the remove algorithm below.

  • Remove node from its parent's children. -

  • If node is assigned, then run assign slottables 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 slottables for a tree with parent's root. - -

    2. Run assign slottables for a tree with node. -

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

  • Run the removing steps with node and parent. @@ -2701,7 +2718,7 @@ indicated in the remove algorithm below. 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.