LibWeb: Update focus-related spec text

Corresponds to 03ab71775b

I've also split the `Document::has_focus()` method for clarity. Actually
implementing the "has focus steps" turns out to be quite involved so
I've left it for now.
This commit is contained in:
Sam Atkins 2025-04-11 16:29:06 +01:00 committed by Andreas Kling
commit 343df5d00f
Notes: github-actions[bot] 2025-04-18 09:08:26 +00:00
5 changed files with 22 additions and 18 deletions

View file

@ -2415,13 +2415,13 @@ String const& Document::compat_mode() const
// https://html.spec.whatwg.org/multipage/interaction.html#dom-documentorshadowroot-activeelement
void Document::update_active_element()
{
// 1. Let candidate be the DOM anchor of the focused area of this DocumentOrShadowRoot's node document.
// 1. Let candidate be this's node document's focused area's DOM anchor.
Node* candidate = focused_element();
// 2. Set candidate to the result of retargeting candidate against this DocumentOrShadowRoot.
// 2. Set candidate to the result of retargeting candidate against this.
candidate = as<Node>(retarget(candidate, this));
// 3. If candidate's root is not this DocumentOrShadowRoot, then return null.
// 3. If candidate's root is not this, then return null.
if (&candidate->root() != this) {
set_active_element(nullptr);
return;
@ -2449,7 +2449,6 @@ void Document::update_active_element()
// 7. Return null.
set_active_element(nullptr);
return;
}
void Document::set_focused_element(GC::Ptr<Element> element)
@ -3475,9 +3474,17 @@ DOMImplementation* Document::implementation()
return m_implementation;
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hasfocus
bool Document::has_focus_for_bindings() const
{
// The Document hasFocus() method steps are to return the result of running the has focus steps given this.
return has_focus();
}
// https://html.spec.whatwg.org/multipage/interaction.html#has-focus-steps
bool Document::has_focus() const
{
// FIXME: Return whether we actually have focus.
// FIXME: Implement this algorithm.
return true;
}

View file

@ -547,6 +547,7 @@ public:
void unregister_viewport_client(ViewportClient&);
void inform_all_viewport_clients_about_the_current_viewport_rect();
bool has_focus_for_bindings() const;
bool has_focus() const;
bool allow_focus() const;

View file

@ -33,7 +33,7 @@
interface Document : Node {
constructor();
boolean hasFocus();
[ImplementedAs=has_focus_for_bindings] boolean hasFocus();
[PutForwards=href, LegacyUnforgeable] readonly attribute Location? location;
attribute USVString domain;

View file

@ -26,29 +26,25 @@ GC::Ref<DOMStringMap> HTMLOrSVGElement<ElementBase>::dataset()
template<typename ElementBase>
void HTMLOrSVGElement<ElementBase>::focus()
{
// 1. If the allow focus steps given the element's node document return false, then return.
// 1. If the allow focus steps given this's node document return false, then return.
if (!static_cast<ElementBase*>(this)->document().allow_focus())
return;
// 2. Run the focusing steps for the element.
// 2. Run the focusing steps for this.
run_focusing_steps(static_cast<ElementBase*>(this));
// FIXME: 3. If the value of the focusVisible dictionary member of options is true, or is not present but in an implementation-defined way the user agent determines it would be best to do so, then indicate focus.
// FIXME: 3. If options["focusVisible"] is true, or does not exist but in an implementation-defined way the user agent determines it would be best to do so, then indicate focus.
// FIXME: 4. If the value of the preventScroll dictionary member of options is false,
// then scroll the element into view with scroll behavior "auto",
// block flow direction position set to an implementation-defined value,
// and inline base direction position set to an implementation-defined value.
// FIXME: 4. If options["preventScroll"] is false, then scroll a target into view given this, "auto", "center", and "center".
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
template<typename ElementBase>
void HTMLOrSVGElement<ElementBase>::blur()
{
// The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called.
// 1. The user agent should run the unfocusing steps given this.
// User agents may instead selectively or uniformly do nothing, for usability reasons.
run_unfocusing_steps(static_cast<ElementBase*>(this));
// User agents may selectively or uniformly ignore calls to this method for usability reasons.
}
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce

View file

@ -900,7 +900,7 @@ void Window::stop()
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
void Window::focus()
{
// 1. Let current be this Window object's navigable.
// 1. Let current be this's navigable.
auto current = navigable();
// 2. If current is null, then return.
@ -923,7 +923,7 @@ void Window::focus()
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-blur
void Window::blur()
{
// The blur() method steps are to do nothing.
// The Window blur() method steps are to do nothing.
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-locationbar