Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 569bafdafba6da329c22c4ef9437b1a95832b1b1
      
https://github.com/WebKit/WebKit/commit/569bafdafba6da329c22c4ef9437b1a95832b1b1
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-08-24 (Mon, 24 Aug 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-closedby-corner-cases-expected.txt
    R 
LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-closedby-corner-cases-expected.txt
    M Source/WebCore/dom/Element.cpp

  Log Message:
  -----------
  documentElement.focus() should move focus to the viewport instead of doing 
nothing
https://bugs.webkit.org/show_bug.cgi?id=322325
rdar://185567540

Reviewed by Ryosuke Niwa.

Element::focus() returns early for an element that is not programmatically
focusable. That is wrong for the document element, because the focusing steps
first substitute the focusable area:

    If new focus target is not a focusable area, then set new focus target to 
the
    result of getting the focusable area for new focus target, given focus 
trigger
    if it was passed.

and getting the focusable area has a clause for it:

    If focus target is the document element of its Document

    If focus target is the document element of its Document
        Return the Document's viewport.

https://html.spec.whatwg.org/multipage/interaction.html#get-the-focusable-area

The result is non-null, so the focusing steps proceed and focus moves to the
viewport. The spec makes this explicit in the note on blur(): "if you want to
focus the viewport, call the focus() method on the Document's document element."
We instead left the previously focused element focused.

The "element with one or more scrollable regions" clause of getting the 
focusable
area is still not implemented; only the document element case is handled here.

* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-closedby-corner-cases-expected.txt:
 Progression
* 
LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-closedby-corner-cases-expected.txt:
 Removed.
* Source/WebCore/dom/Element.cpp:
(WebCore::Element::focus):

Canonical link: https://commits.webkit.org/319730@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to