LibWeb: Add more fast_is<T> helpers for DOM::Node subclasses

This commit is contained in:
Andreas Kling 2025-04-18 10:27:59 +02:00
parent 9dda0fa662
commit 0f2dd7039c
10 changed files with 68 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -144,6 +144,8 @@ public:
virtual bool is_svg_style_element() const { return false; }
virtual bool is_svg_svg_element() const { return false; }
virtual bool is_svg_use_element() const { return false; }
virtual bool is_svg_a_element() const { return false; }
virtual bool is_svg_foreign_object_element() const { return false; }
bool in_a_document_tree() const;
@ -158,10 +160,13 @@ public:
virtual bool is_html_element() const { return false; }
virtual bool is_html_html_element() const { return false; }
virtual bool is_html_anchor_element() const { return false; }
virtual bool is_html_area_element() const { return false; }
virtual bool is_html_base_element() const { return false; }
virtual bool is_html_body_element() const { return false; }
virtual bool is_html_head_element() const { return false; }
virtual bool is_html_input_element() const { return false; }
virtual bool is_html_link_element() const { return false; }
virtual bool is_html_media_element() const { return false; }
virtual bool is_html_progress_element() const { return false; }
virtual bool is_html_script_element() const { return false; }
virtual bool is_html_style_element() const { return false; }
@ -170,6 +175,7 @@ public:
virtual bool is_html_table_section_element() const { return false; }
virtual bool is_html_table_row_element() const { return false; }
virtual bool is_html_table_cell_element() const { return false; }
virtual bool is_html_title_element() const { return false; }
virtual bool is_html_br_element() const { return false; }
virtual bool is_html_button_element() const { return false; }
virtual bool is_html_slot_element() const { return false; }
@ -178,6 +184,8 @@ public:
virtual bool is_html_form_element() const { return false; }
virtual bool is_html_image_element() const { return false; }
virtual bool is_html_iframe_element() const { return false; }
virtual bool is_html_frameset_element() const { return false; }
virtual bool is_html_fieldset_element() const { return false; }
virtual bool is_navigable_container() const { return false; }
virtual bool is_lazy_loading() const { return false; }

View file

@ -25,6 +25,8 @@ public:
private:
HTMLAreaElement(DOM::Document&, DOM::QualifiedName);
virtual bool is_html_area_element() const override { return true; }
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
@ -59,3 +61,8 @@ private:
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLAreaElement>() const { return is_html_area_element(); }
}

View file

@ -54,7 +54,14 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual bool is_html_fieldset_element() const override { return true; }
GC::Ptr<DOM::HTMLCollection> m_elements;
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLFieldSetElement>() const { return is_html_fieldset_element(); }
}

View file

@ -24,6 +24,8 @@ public:
private:
HTMLFrameSetElement(DOM::Document&, DOM::QualifiedName);
virtual bool is_html_frameset_element() const override { return true; }
virtual void adjust_computed_style(CSS::ComputedProperties&) override;
virtual void initialize(JS::Realm&) override;
@ -37,3 +39,8 @@ private:
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLFrameSetElement>() const { return is_html_frameset_element(); }
}

View file

@ -20,7 +20,13 @@ public:
private:
HTMLHeadElement(DOM::Document&, DOM::QualifiedName);
virtual bool is_html_head_element() const final { return true; }
virtual void initialize(JS::Realm&) override;
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLHeadElement>() const { return is_html_head_element(); }
}

View file

@ -69,3 +69,8 @@ private:
void run_iframe_load_event_steps(HTML::HTMLIFrameElement&);
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLIFrameElement>() const { return is_html_iframe_element(); }
}

View file

@ -182,6 +182,8 @@ protected:
private:
friend SourceElementSelector;
virtual bool is_html_media_element() const final { return true; }
struct EntireResource { };
using ByteRange = Variant<EntireResource>; // FIXME: This will need to include "until end" and an actual byte range.
@ -324,3 +326,8 @@ private:
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLMediaElement>() const { return is_html_media_element(); }
}

View file

@ -23,8 +23,14 @@ public:
private:
HTMLTitleElement(DOM::Document&, DOM::QualifiedName);
virtual bool is_html_title_element() const override { return true; }
virtual void initialize(JS::Realm&) override;
virtual void children_changed(ChildrenChangedMetadata const*) override;
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<HTML::HTMLTitleElement>() const { return is_html_title_element(); }
}

View file

@ -31,6 +31,8 @@ private:
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
virtual bool is_svg_a_element() const override { return true; }
// ^DOM::Element
virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value, Optional<FlyString> const& namespace_) override;
virtual i32 default_tab_index_value() const override;
@ -39,3 +41,8 @@ private:
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<SVG::SVGAElement>() const { return is_svg_a_element(); }
}

View file

@ -28,6 +28,8 @@ public:
private:
SVGForeignObjectElement(DOM::Document& document, DOM::QualifiedName qualified_name);
virtual bool is_svg_foreign_object_element() const override { return true; }
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
@ -41,3 +43,8 @@ private:
};
}
namespace Web::DOM {
template<>
inline bool Node::fast_is<SVG::SVGForeignObjectElement>() const { return is_svg_foreign_object_element(); }
}