mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:05:08 +00:00
LibWeb/HTML: Port Window.focus() to IDL
This commit is contained in:
parent
b59505aba5
commit
56550b6ec0
3 changed files with 21 additions and 24 deletions
|
@ -952,7 +952,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
|||
define_native_function(realm, "clearTimeout", clear_timeout, 1, attr);
|
||||
define_native_function(realm, "requestAnimationFrame", request_animation_frame, 1, attr);
|
||||
define_native_function(realm, "cancelAnimationFrame", cancel_animation_frame, 1, attr);
|
||||
define_native_function(realm, "focus", focus, 0, attr);
|
||||
|
||||
define_native_function(realm, "queueMicrotask", queue_microtask, 1, attr);
|
||||
|
||||
|
@ -1067,6 +1066,25 @@ JS::NonnullGCPtr<History> Window::history() const
|
|||
return associated_document().history();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
|
||||
void Window::focus()
|
||||
{
|
||||
// 1. Let current be this Window object's navigable.
|
||||
auto* current = browsing_context();
|
||||
|
||||
// 2. If current is null, then return.
|
||||
if (!current)
|
||||
return;
|
||||
|
||||
// 3. Run the focusing steps with current.
|
||||
// FIXME: We should pass in the browsing context itself instead of the active document, however the focusing steps don't currently accept browsing contexts.
|
||||
// Passing in a browsing context always makes it resolve to its active document for focus, so this is fine for now.
|
||||
run_focusing_steps(current->active_document());
|
||||
|
||||
// FIXME: 4. If current is a top-level traversable, user agents are encouraged to trigger some sort of notification to
|
||||
// indicate to the user that the page is attempting to gain focus.
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/window-object.html#dom-frames
|
||||
JS::NonnullGCPtr<WindowProxy> Window::frames() const
|
||||
{
|
||||
|
@ -1615,28 +1633,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::cancel_idle_callback)
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::focus)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
|
||||
// 1. Let current be this Window object's browsing context.
|
||||
auto* current = impl->browsing_context();
|
||||
|
||||
// 2. If current is null, then return.
|
||||
if (!current)
|
||||
return JS::js_undefined();
|
||||
|
||||
// 3. Run the focusing steps with current.
|
||||
// FIXME: We should pass in the browsing context itself instead of the active document, however the focusing steps don't currently accept browsing contexts.
|
||||
// Passing in a browsing context always makes it resolve to its active document for focus, so this is fine for now.
|
||||
run_focusing_steps(current->active_document());
|
||||
|
||||
// FIXME: 4. If current is a top-level browsing context, user agents are encouraged to trigger some sort of notification to indicate to the user that the page is attempting to gain focus.
|
||||
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/window-object.html#number-of-document-tree-child-browsing-contexts
|
||||
size_t Window::document_tree_child_browsing_context_count() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue