From 2d783dbb7c6c0343b4850f3be935e893a1de5582 Mon Sep 17 00:00:00 2001 From: "TAMURA, Kent" Date: Wed, 4 Sep 2019 01:07:59 +0900 Subject: [PATCH] Update autofocus processing algorithm * Run focusing steps after an animation frame * Don't autofocus if the top-level document has focused area * Don't autofocus if one of ancestor document has a :target element Fixes #3551. Fixes #4645. --- source | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 117 insertions(+), 16 deletions(-) diff --git a/source b/source index 538ff5da70f..e6881c1c917 100644 --- a/source +++ b/source @@ -74520,9 +74520,15 @@ END:VCARD
+

Each Document has an autofocus candidates list, + initially empty.

+ +

Each Document has an autofocus processed flag boolean, initially + false.

+

When an element with the autofocus attribute specified - is inserted into a document, queue a - task on the user interaction task source to run the following steps:

+ is inserted into a document, run the + following steps:

  1. If the user has indicated (for example, by starting to type in a form control) that they @@ -74536,24 +74542,111 @@ END:VCARD

  2. If target's active sandboxing flag set has the sandboxed automatic features browsing context flag, then return.

  3. +
  4. Let topDocument be the active document of target's + browsing context's + top-level browsing context.

  5. +
  6. If target's origin is not the same as the origin of the node document of the currently - focused element in target's top-level browsing context, then + origin">same as the origin of topDocument, then return.

  7. + +
  8. If topDocument's autofocus processed flag is false, then + remove the element from topDocument's + autofocus candidates, and append the element to + topDocument's autofocus candidates.

  9. +
+ +

We do not check if an element is a focusable area before storing it + in the autofocus candidates list, because even if it is not a focusable area when it + is inserted, it could become one by the time flush autofocus candidates sees it.

+ +

To flush autofocus candidates for a document topDocument, run these + steps:

+ +
    +
  1. If topDocument's autofocus processed flag is true, then return.

  2. -
  3. If target's origin is not the same as the origin of the active document of - target's top-level browsing context, then return.

  4. +
  5. Let candidates be topDocument's autofocus + candidates.

  6. + +
  7. If candidates is empty, then + return.

  8. + +
  9. +

    If topDocument's focused area + is not topDocument itself, or topDocument's + URL's + fragment is not empty, then:

    + +
      +
    1. Empty candidates.

    2. -
    3. If the user agent has already reached the last step of this list of steps in response to - an element being inserted into a - Document whose top-level browsing context's active - document is the same as target's top-level browsing - context's active document, then return.

    4. +
    5. Set topDocument's autofocus processed flag to true.

    6. + +
    7. Return.

    8. +
    +
  10. + +
  11. +

    While candidates is not empty:

    -
  12. Run the focusing steps for the element. User agents may also change the - scrolling position of the document, or perform some other action that brings the element to the - user's attention.

  13. +
      +
    1. Let element be candidates[0].

    2. + +
    3. Let doc be element's node document.

    4. + +
    5. If doc is not fully active, then + remove element from candidates, and + continue.

    6. + +
    7. If doc's browsing context's + top-level browsing context is not same as topDocument's + browsing context, then + remove element from candidates, and + continue.

    8. + +
    9. +

      If doc's script-blocking style sheet counter is greater than 0, + then return.

      + +

      In this case, element is the currently-best candidate, but + doc is not ready for autofocusing. We'll try again next time flush + autofocus candidates is called.

      +
    10. + +
    11. Remove element from + candidates.

    12. + +
    13. Let inclusiveAncestorDocuments be a list consisting of + doc, plus the active documents of each of + doc's browsing context's + ancestor browsing contexts.

    14. + +
    15. If URL's + fragment of any Document in + inclusiveAncestorDocuments is not empty, then continue.

    16. + +
    17. +

      If element is a focusable area, then:

      + +
        +
      1. Empty candidates.

      2. + +
      3. Set topDocument's autofocus processed flag to true.

      4. + +
      5. Run the focusing steps for element.

      6. +
      + +

      Autofocus candidates can contain elements which are not focusable + areas. This can happen either because a non-focusable area element with an + autofocus attribute was inserted into a document and it never became focusable, or because the + element was focusable but its status changed while it was stored in autofocus + candidates.

      +
    18. +
    +

This handles the automatic focusing during document load. The methods of dialog elements also processes the autofocus attribute.

-

Focusing the control does not imply that the user agent has to focus the browser +

Focusing the element does not imply that the user agent has to focus the browser window if it has lost focus.

The autofocus IDL attribute must @@ -91215,6 +91308,14 @@ dictionary PromiseRejectionEventInit : EventInit {

  • For each fully active Document in docs, update the rendering or user interface of that Document and its browsing context to reflect the current state.

  • + +
  • For each fully active Document in docs, flush + autofocus candidates for that Document if its + browsing context is a + top-level browsing context.

  • +