mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
LibWeb: Add API for finding Navigable with a given active document
This will be used to look up a document's node navigable. It might be nice to have a direct pointer from Document to its Navigable, but at the moment I don't understand the algorithms well enough to maintain that linkage.
This commit is contained in:
parent
f09aaf826f
commit
6e416284b9
2 changed files with 25 additions and 2 deletions
|
@ -13,9 +13,21 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
Navigable::Navigable() = default;
|
||||
static HashTable<Navigable*>& all_navigables()
|
||||
{
|
||||
static HashTable<Navigable*> set;
|
||||
return set;
|
||||
}
|
||||
|
||||
Navigable::~Navigable() = default;
|
||||
Navigable::Navigable()
|
||||
{
|
||||
all_navigables().set(this);
|
||||
}
|
||||
|
||||
Navigable::~Navigable()
|
||||
{
|
||||
all_navigables().remove(this);
|
||||
}
|
||||
|
||||
void Navigable::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
|
@ -26,6 +38,15 @@ void Navigable::visit_edges(Cell::Visitor& visitor)
|
|||
visitor.visit(m_container);
|
||||
}
|
||||
|
||||
JS::GCPtr<Navigable> Navigable::navigable_with_active_document(JS::NonnullGCPtr<DOM::Document> document)
|
||||
{
|
||||
for (auto* navigable : all_navigables()) {
|
||||
if (navigable->active_document() == document)
|
||||
return navigable;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-sequences.html#nav-document
|
||||
JS::GCPtr<DOM::Document> Navigable::active_document()
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue