mirror of
https://github.com/RGBCube/serenity
synced 2025-07-02 22:42:08 +00:00
LibWeb: Implement BrowsingContext::currently_focused_area()
This is "currently focused area of a top level browsing context" from the HTML spec.
This commit is contained in:
parent
83523cabda
commit
1165a94624
2 changed files with 32 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/BrowsingContextContainer.h>
|
||||
#include <LibWeb/HTML/EventLoop/EventLoop.h>
|
||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||
#include <LibWeb/Layout/BreakNode.h>
|
||||
|
@ -362,4 +363,33 @@ bool BrowsingContext::has_a_rendering_opportunity() const
|
|||
return true;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#currently-focused-area-of-a-top-level-browsing-context
|
||||
RefPtr<DOM::Node> BrowsingContext::currently_focused_area()
|
||||
{
|
||||
// 1. If topLevelBC does not have system focus, then return null.
|
||||
if (!is_focused_context())
|
||||
return nullptr;
|
||||
|
||||
// 2. Let candidate be topLevelBC's active document.
|
||||
auto* candidate = active_document();
|
||||
|
||||
// 3. While candidate's focused area is a browsing context container with a non-null nested browsing context:
|
||||
// set candidate to the active document of that browsing context container's nested browsing context.
|
||||
while (candidate->focused_element()
|
||||
&& is<HTML::BrowsingContextContainer>(candidate->focused_element())
|
||||
&& static_cast<HTML::BrowsingContextContainer&>(*candidate->focused_element()).nested_browsing_context()) {
|
||||
candidate = static_cast<HTML::BrowsingContextContainer&>(*candidate->focused_element()).nested_browsing_context()->active_document();
|
||||
}
|
||||
|
||||
// 4. If candidate's focused area is non-null, set candidate to candidate's focused area.
|
||||
if (candidate->focused_element()) {
|
||||
// NOTE: We return right away here instead of assigning to candidate,
|
||||
// since that would require compromising type safety.
|
||||
return candidate->focused_element();
|
||||
}
|
||||
|
||||
// 5. Return candidate.
|
||||
return candidate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue