diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 60ffa47d088..b1ed19014ed 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -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(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) @@ -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; } diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index d5ad75a9b4e..3ebc852e840 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -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; diff --git a/Libraries/LibWeb/DOM/Document.idl b/Libraries/LibWeb/DOM/Document.idl index 9915ae7d6bc..6a0fb053561 100644 --- a/Libraries/LibWeb/DOM/Document.idl +++ b/Libraries/LibWeb/DOM/Document.idl @@ -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; diff --git a/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp b/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp index 9c843f21854..1c272e60505 100644 --- a/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp @@ -26,29 +26,25 @@ GC::Ref HTMLOrSVGElement::dataset() template void HTMLOrSVGElement::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(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(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 void HTMLOrSVGElement::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(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 diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp index a6e6d6181be..3baff34016a 100644 --- a/Libraries/LibWeb/HTML/Window.cpp +++ b/Libraries/LibWeb/HTML/Window.cpp @@ -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