LibWeb: Add fast_is<T> helpers for Navigable & TraversableNavigable

This commit is contained in:
Andreas Kling 2025-04-18 10:25:56 +02:00 committed by Andreas Kling
commit 0e490e3352
Notes: github-actions[bot] 2025-04-18 12:47:37 +00:00
3 changed files with 9 additions and 6 deletions

View file

@ -99,11 +99,6 @@ Vector<GC::Root<Navigable>> Navigable::child_navigables() const
return results; return results;
} }
bool Navigable::is_traversable() const
{
return is<TraversableNavigable>(*this);
}
bool Navigable::is_ancestor_of(GC::Ref<Navigable> other) const bool Navigable::is_ancestor_of(GC::Ref<Navigable> other) const
{ {
for (auto ancestor = other->parent(); ancestor; ancestor = ancestor->parent()) { for (auto ancestor = other->parent(); ancestor; ancestor = ancestor->parent()) {

View file

@ -52,7 +52,7 @@ public:
Vector<GC::Root<Navigable>> child_navigables() const; Vector<GC::Root<Navigable>> child_navigables() const;
bool is_traversable() const; virtual bool is_traversable() const { return false; }
String const& id() const { return m_id; } String const& id() const { return m_id; }
GC::Ptr<Navigable> parent() const { return m_parent; } GC::Ptr<Navigable> parent() const { return m_parent; }
@ -188,6 +188,9 @@ public:
bool has_pending_navigations() const { return !m_pending_navigations.is_empty(); } bool has_pending_navigations() const { return !m_pending_navigations.is_empty(); }
template<typename T>
bool fast_is() const = delete;
protected: protected:
explicit Navigable(GC::Ref<Page>); explicit Navigable(GC::Ref<Page>);

View file

@ -120,6 +120,8 @@ public:
private: private:
TraversableNavigable(GC::Ref<Page>); TraversableNavigable(GC::Ref<Page>);
virtual bool is_traversable() const override { return true; }
virtual void visit_edges(Cell::Visitor&) override; virtual void visit_edges(Cell::Visitor&) override;
// FIXME: Fix spec typo cancelation --> cancellation // FIXME: Fix spec typo cancelation --> cancellation
@ -175,4 +177,7 @@ struct BrowsingContextAndDocument {
WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(GC::Ref<Page> page); WebIDL::ExceptionOr<BrowsingContextAndDocument> create_a_new_top_level_browsing_context_and_document(GC::Ref<Page> page);
void finalize_a_same_document_navigation(GC::Ref<TraversableNavigable> traversable, GC::Ref<Navigable> target_navigable, GC::Ref<SessionHistoryEntry> target_entry, GC::Ptr<SessionHistoryEntry> entry_to_replace, HistoryHandlingBehavior, UserNavigationInvolvement); void finalize_a_same_document_navigation(GC::Ref<TraversableNavigable> traversable, GC::Ref<Navigable> target_navigable, GC::Ref<SessionHistoryEntry> target_entry, GC::Ptr<SessionHistoryEntry> entry_to_replace, HistoryHandlingBehavior, UserNavigationInvolvement);
template<>
inline bool Navigable::fast_is<TraversableNavigable>() const { return is_traversable(); }
} }