mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
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:
parent
609d568776
commit
343df5d00f
Notes:
github-actions[bot]
2025-04-18 09:08:26 +00:00
Author: https://github.com/AtkinsSJ
Commit: 343df5d00f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4324
5 changed files with 22 additions and 18 deletions
|
@ -2415,13 +2415,13 @@ String const& Document::compat_mode() const
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-documentorshadowroot-activeelement
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-documentorshadowroot-activeelement
|
||||||
void Document::update_active_element()
|
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();
|
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));
|
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) {
|
if (&candidate->root() != this) {
|
||||||
set_active_element(nullptr);
|
set_active_element(nullptr);
|
||||||
return;
|
return;
|
||||||
|
@ -2449,7 +2449,6 @@ void Document::update_active_element()
|
||||||
|
|
||||||
// 7. Return null.
|
// 7. Return null.
|
||||||
set_active_element(nullptr);
|
set_active_element(nullptr);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::set_focused_element(GC::Ptr<Element> element)
|
void Document::set_focused_element(GC::Ptr<Element> element)
|
||||||
|
@ -3475,9 +3474,17 @@ DOMImplementation* Document::implementation()
|
||||||
return m_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
|
bool Document::has_focus() const
|
||||||
{
|
{
|
||||||
// FIXME: Return whether we actually have focus.
|
// FIXME: Implement this algorithm.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -547,6 +547,7 @@ public:
|
||||||
void unregister_viewport_client(ViewportClient&);
|
void unregister_viewport_client(ViewportClient&);
|
||||||
void inform_all_viewport_clients_about_the_current_viewport_rect();
|
void inform_all_viewport_clients_about_the_current_viewport_rect();
|
||||||
|
|
||||||
|
bool has_focus_for_bindings() const;
|
||||||
bool has_focus() const;
|
bool has_focus() const;
|
||||||
|
|
||||||
bool allow_focus() const;
|
bool allow_focus() const;
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
interface Document : Node {
|
interface Document : Node {
|
||||||
constructor();
|
constructor();
|
||||||
|
|
||||||
boolean hasFocus();
|
[ImplementedAs=has_focus_for_bindings] boolean hasFocus();
|
||||||
|
|
||||||
[PutForwards=href, LegacyUnforgeable] readonly attribute Location? location;
|
[PutForwards=href, LegacyUnforgeable] readonly attribute Location? location;
|
||||||
attribute USVString domain;
|
attribute USVString domain;
|
||||||
|
|
|
@ -26,29 +26,25 @@ GC::Ref<DOMStringMap> HTMLOrSVGElement<ElementBase>::dataset()
|
||||||
template<typename ElementBase>
|
template<typename ElementBase>
|
||||||
void HTMLOrSVGElement<ElementBase>::focus()
|
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())
|
if (!static_cast<ElementBase*>(this)->document().allow_focus())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// 2. Run the focusing steps for the element.
|
// 2. Run the focusing steps for this.
|
||||||
run_focusing_steps(static_cast<ElementBase*>(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,
|
// FIXME: 4. If options["preventScroll"] is false, then scroll a target into view given this, "auto", "center", and "center".
|
||||||
// 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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
|
||||||
template<typename ElementBase>
|
template<typename ElementBase>
|
||||||
void HTMLOrSVGElement<ElementBase>::blur()
|
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));
|
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
|
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
|
||||||
|
|
|
@ -900,7 +900,7 @@ void Window::stop()
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
|
||||||
void Window::focus()
|
void Window::focus()
|
||||||
{
|
{
|
||||||
// 1. Let current be this Window object's navigable.
|
// 1. Let current be this's navigable.
|
||||||
auto current = navigable();
|
auto current = navigable();
|
||||||
|
|
||||||
// 2. If current is null, then return.
|
// 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
|
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-blur
|
||||||
void 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
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-locationbar
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue