From 90a60b2a0dc740b8b0093b07ca0a41e70ba8d83a Mon Sep 17 00:00:00 2001 From: Takayoshi Kochi Date: Tue, 15 May 2018 00:27:08 +0900 Subject: [PATCH] Remove "control group" concept from the focus model The control group concept existed to give special focus behavior to elements, treating them on par with Documents in terms of allowing focus to shift inside of them. However, this was never implemented in user agents. This change removes the control group concept, instead using Document directly. This allows some simplifications, e.g. because the first focusable area of a non-empty Document is always the Document's viewport. The change uncovered some areas of the spec that were potentially wrong or unclear when considering focus around documents. We will follow up on that in https://github.com/whatwg/html/issues/3675. But for now we keep the same algorithms, just without s. Fixes #2171. --- source | 245 +++++++++++++++++++-------------------------------------- 1 file changed, 79 insertions(+), 166 deletions(-) diff --git a/source b/source index 4e03b7a8056..883c8ad01b1 100644 --- a/source +++ b/source @@ -57198,17 +57198,16 @@ interface HTMLDialogElement : HTMLElement {
    -
  1. If for some reason subject is not a control group owner object - at this point, or if it is inert, return.

  2. +
  3. If subject is inert, return.

  4. -

    Let control be the first non-inert focusable area in - subject's control group whose DOM anchor has an Let control be the first descendant element of subject, in tree + order, that is not inert and has the autofocus attribute specified.

    If there isn't one, then let control be the first non-inert - focusable area in subject's control group.

    + descendant element of subject, in tree order.

    If there isn't one of those either, then let control be subject.

    @@ -72240,6 +72239,10 @@ END:VCARD nested browsing context's active document, and all nodes in that Document, must be marked as inert.

    +

    An element + is expressly inert if it is inert and its node document is + not inert.

    +

    A Document document is blocked by a modal dialog subject if subject is the topmost dialog element in document's top layer. While document is so blocked, every node @@ -72539,103 +72542,36 @@ END:VCARD


    -

    The following create control groups: - -

      - -
    • Document object that have browsing - contexts.
    • - -
    • dialog elements that have an open - attribute specified and that are being rendered.
    • - -
    - -

    The corresponding Document object or dialog element is the created - control group's owner object. (There - is always a 1-to-1 mapping of control groups to control group owner objects.)

    - -

    Each focusable area belongs to a single control group as follows. If - the DOM anchor of a focusable area is a control group - owner object, then that focusable area belongs to that control group - owner object's control group. Otherwise, the focusable area - belongs to its DOM anchor's nearest ancestor control group owner - object's control group.

    +

    One focusable area in each Document is designated the focused + area of the document. Which control is so designated changes over time, based on algorithms + in this specification. If a Document has no focusable area, it has no + focused area.

    + -
    -

    Thus:

    - -
      -
    • A viewport always belongs to the control group of the - Document for which the viewport was created.

    • - -
    • An input control belongs to the control group of its nearest - ancestor dialog or Document.

    • - -
    • An image map's shapes belong to the nearest ancestor dialog or - Document of the img elements (not the area elements - — this means one area element might create multiple shapes in different - control groups).

    • -
    -
    - -

    It is possible for a control group to be empty, i.e. for it to have - no focusable areas.

    - -
    - -

    An element - is expressly inert if it is inert and its nearest ancestor control - group owner object is not inert.

    - -
    -

    In a page with no dialog elements, all elements that are inert are - expressly inert, and vice-versa.

    - -

    Inside an inert dialog element, all descendant elements are not - expressly inert, even if they are inert.

    - -

    A dialog element is expressly inert if it is inert and - not nested inside another inert dialog.

    -
    - -
    - -

    One focusable area in each non-empty control group is designated the - focused area of the control group. Which control is so designated changes over time, - based on algorithms in this specification. If a control group is empty, it has no focused area.

    - -

    Focusable areas in control groups +

    Focusable areas in a Document are ordered relative to the tree order of their DOM - anchors. Focusable areas with the same DOM anchor in a - control group are ordered relative to their CSS box's relative positions in a pre-order, - depth-first traversal of the box tree.

    + anchors. Focusable areas with the same DOM + anchor in a Document are ordered relative to their CSS boxes' relative + positions in a pre-order, depth-first traversal of the box tree.


    The currently focused area of a top-level browsing context at any particular time is - the focusable area or dialog returned by this algorithm:

    + the focusable area returned by this algorithm:

    1. Let candidate be the Document of the top-level browsing context.

    2. -
    3. - -

      If candidate has a non-empty control group, and the - designated focused area of the control group is a browsing context - container with a non-null nested browsing context, then let - candidate be the active document of that browsing context - container's nested browsing context, and redo this step.

      +
    4. If the designated focused area of the document is a browsing context + container with a non-null nested browsing context, then let + candidate be the active document of that browsing context + container's nested browsing context, and redo this step.

    5. -

      Otherwise, if candidate has a non-empty control group, let - candidate be the designated focused area of the control - group.

      - - +
    6. If candidate has a focused + area, set candidate to candidate's focused area.

    7. Return candidate.

    8. @@ -72649,8 +72585,8 @@ END:VCARD
      -

      The focus chain of a focusable area or control group owner - object subject is the ordered list constructed as follows:

      +

      The focus chain of a focusable area subject is the ordered + list constructed as follows:

        @@ -72673,12 +72609,7 @@ END:VCARD
      1. -

        If current object is a focusable area, let current - object be that focusable area's control group's owner object, and return to the step labeled - loop.

        - -

        Otherwise, if current object is a Document in a nested browsing +

        If current object is a Document in a nested browsing context, let current object be its browsing context container, and return to the step labeled loop.

        @@ -72880,10 +72811,8 @@ END:VCARD
      2. -

        If new focus target is neither a dialog element that has an - open attribute specified and that is being - rendered (i.e. that is a control group owner object), nor a focusable - area, then run the first matching set of steps from the following list:

        +

        If new focus target is not a focusable area, then run the first + matching set of steps from the following list:

        @@ -72957,22 +72886,11 @@ END:VCARD
      3. -

        If new focus target is a control group owner - object that is not a focusable area, and its control group is not empty, - then designate new focus target as the focused area of the control - group, and redo this step.

        - -

        Otherwise, if new focus target is a browsing context container with +

        If new focus target is a browsing context container with non-null nested browsing context, then let new focus target be the nested browsing context's active document, and redo this step.

        -

        A dialog element can be both a control group owner - object and a focusable area, if it has both an open attribute specified and a tabindex attribute specified and is being - rendered.

        -
      4. If new focus target is a focusable area and its DOM @@ -72993,8 +72911,8 @@ END:VCARD

      -

      User agents must immediately run the focusing steps for a focusable area, - dialog, or browsing context candidate whenever the +

      User agents must immediately run the focusing steps for a + focusable area or browsing context candidate whenever the user attempts to move the focus to candidate.

      The unfocusing steps for an object old focus target that is @@ -73027,9 +72945,7 @@ END:VCARD

    9. If old focus target is a focusable area, then let new - focus target be the first focusable area of its control group - (if the control group owner object is a Document, this will always be - a viewport).

      + focus target be its Document's viewport.

      Otherwise, let new focus target be null.

      @@ -73052,33 +72968,28 @@ END:VCARD
      -

      When a focusable area is added to an empty control group, it must be designated - the focused area of the control group.

      - -

      Focus fixup rule: When the designated focused area of a control group is removed from that control group in - some way (e.g. it stops being a focusable area, it is removed from the DOM, it - becomes expressly inert, etc), and the control group is still not - empty: designate the first non-inert focusable area in that - control group to be the new focused area of the control group, if any; - if they are all inert, then designate the first focusable area in that - control group to be the new focused area of the control group regardless - of inertness. If such a removal instead results in the control - group being empty, then there is simply no longer a focused area of the control - group.

      +

      When a focusable area is added to an empty Document, it must be + designated the focused area of the document.

      + +

      Focus fixup rule: When the designated focused area of the document is removed from that Document in some + way (e.g. it stops being a focusable area, it is removed from the DOM, it becomes + expressly inert, etc.), and the Document is still not empty: designate + the Document's viewport to be the new focused area of the + document. If such a removal instead results in the Document being empty, then + there is simply no longer a focused area of the document.

      For example, this might happen because an element is removed from its Document, or has a hidden attribute added. It might also happen to an input element when the element gets disabled.

      -

      In a Document without dialog elements, whose focused area is a button element, - removing, disabling, or hiding that button would cause the page's new focused area to be the viewport of the - Document. This would, in turn, be reflected through the activeElement API as the body - element.

      +

      In a Document whose focused area is a button element, removing, disabling, or hiding + that button would cause the page's new focused + area to be the viewport of the Document. This would, in turn, + be reflected through the activeElement API as + the body element.


      @@ -73157,11 +73068,7 @@ END:VCARD
    10. If entry is a focusable area: designate entry as the - focused area of the control group.

      - -

      It is possible for entry to be both a dialog - element and a focusable area, in which case it is its own control group - owner object.

      + focused area of the document.

    11. @@ -73275,14 +73182,14 @@ END:VCARD
    12. -

      If candidate has a non-empty control group, and the - designated focused area of the control group is a browsing context +

      If candidate is non-empty, and the + designated focused area of the document is a browsing context container with a non-null nested browsing context, and the active document of that browsing context container's nested browsing context is target, then return true.

      -

      Otherwise, if candidate has a non-empty control group, and the - designated focused area of the control group is a browsing context +

      Otherwise, if candidate is non-empty, and the + designated focused area of the document is a browsing context container with a non-null nested browsing context, then let candidate be the active document of that browsing context container's nested browsing context, and redo this step.

      @@ -73297,12 +73204,13 @@ END:VCARD

      Sequential focus navigation

      -

      Each control group has a sequential focus navigation order, which orders some - or all of the focusable areas in the control group +

      Each Document has a sequential focus navigation order, which orders some + or all of the focusable areas in the Document relative to each other. The order in the sequential focus navigation order does not - have to be related to the order in the control group itself. If a focusable area is - omitted from the sequential focus navigation order of its control group, then - it is unreachable via sequential focus navigation.

      + have to be related to the tree order in the Document itself. If a + focusable area is omitted from the sequential focus navigation order + of its Document, then it is unreachable via sequential focus + navigation.

      There can also be a sequential focus navigation starting point. It is initially unset. The user agent may set it when the user indicates that it should be moved.

      @@ -73341,9 +73249,9 @@ END:VCARD

      Loop: Let selection mechanism be sequential if the starting point is a browsing context or if starting point is in its - control group's sequential focus navigation order.

      + Document's sequential focus navigation order.

      -

      Otherwise, starting point is not in its control group's +

      Otherwise, starting point is not in its Document's sequential focus navigation order; let selection mechanism be DOM.

      @@ -73416,12 +73324,16 @@ END:VCARD starting point is a browsing context - Let candidate be the first suitable sequentially focusable area in starting point's active document's control group, if any; or else null - Let candidate be the last suitable sequentially focusable area in starting point's active document's control group, if any; or else null + Let candidate be the first suitable sequentially focusable area + in starting point's active document, if any; or else null + Let candidate be the last suitable sequentially focusable area + in starting point's active document, if any; or else null selection mechanism is DOM - Let candidate be the first suitable sequentially focusable area in the home control group following starting point, if any; or else null - Let candidate be the last suitable sequentially focusable area in the home control group preceding starting point, if any; or else null + Let candidate be the first suitable sequentially focusable area + in the home document following starting point, if any; or else null + Let candidate be the last suitable sequentially focusable area + in the home document preceding starting point, if any; or else null selection mechanism is sequential Let candidate be the first suitable sequentially focusable area in the home sequential focus navigation order following starting point, if any; or else null @@ -73429,17 +73341,18 @@ END:VCARD -

      A suitable sequentially focusable area is a focusable area whose DOM - anchor is not inert and that is in its control group's sequential - focus navigation order.

      +

      A suitable sequentially focusable area is a focusable area whose + DOM anchor is not inert and that is in its Document's + sequential focus navigation order.

      -

      The home control group is the control group to which starting point belongs.

      +

      The home document is the Document to which starting point + belongs.

      The home sequential focus navigation order is the sequential focus navigation order to which starting point belongs.

      The home sequential focus navigation order is the home - control group's sequential focus navigation order, but is only used when the + document's sequential focus navigation order, but is only used when the starting point is in that sequential focus navigation order (when it's not, selection mechanism will be DOM).

      @@ -73577,8 +73490,8 @@ END:VCARD
      1. Let candidate be this Document object.

      2. -
      3. If candidate has a non-empty control group, then set - candidate to the designated focused area of the control group.

      4. +
      5. If candidate is not empty, then set candidate to the designated + focused area of the document.

      6. If candidate is a focusable area, then set candidate to candidate's DOM anchor.