AK: Rename downcast<T> => verify_cast<T>

This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
This commit is contained in:
Andreas Kling 2021-06-24 19:53:42 +02:00
parent 6215a9c2cb
commit ee3a73ddbb
Notes: sideshowbarker 2024-07-18 11:34:11 +09:00
61 changed files with 262 additions and 262 deletions

View file

@ -28,7 +28,7 @@ ALWAYS_INLINE bool is(InputType* input)
} }
template<typename OutputType, typename InputType> template<typename OutputType, typename InputType>
ALWAYS_INLINE CopyConst<InputType, OutputType>* downcast(InputType* input) ALWAYS_INLINE CopyConst<InputType, OutputType>* verify_cast(InputType* input)
{ {
static_assert(IsBaseOf<InputType, OutputType>); static_assert(IsBaseOf<InputType, OutputType>);
VERIFY(!input || is<OutputType>(*input)); VERIFY(!input || is<OutputType>(*input));
@ -36,7 +36,7 @@ ALWAYS_INLINE CopyConst<InputType, OutputType>* downcast(InputType* input)
} }
template<typename OutputType, typename InputType> template<typename OutputType, typename InputType>
ALWAYS_INLINE CopyConst<InputType, OutputType>& downcast(InputType& input) ALWAYS_INLINE CopyConst<InputType, OutputType>& verify_cast(InputType& input)
{ {
static_assert(IsBaseOf<InputType, OutputType>); static_assert(IsBaseOf<InputType, OutputType>);
VERIFY(is<OutputType>(input)); VERIFY(is<OutputType>(input));
@ -45,5 +45,5 @@ ALWAYS_INLINE CopyConst<InputType, OutputType>& downcast(InputType& input)
} }
using AK::downcast;
using AK::is; using AK::is;
using AK::verify_cast;

View file

@ -319,7 +319,7 @@ public:
} }
template<typename... NewTs> template<typename... NewTs>
Variant<NewTs...> downcast() && Variant<NewTs...> verify_cast() &&
{ {
Variant<NewTs...> instance { Variant<NewTs...>::invalid_index, Detail::VariantConstructTag {} }; Variant<NewTs...> instance { Variant<NewTs...>::invalid_index, Detail::VariantConstructTag {} };
visit([&](auto& value) { visit([&](auto& value) {
@ -331,7 +331,7 @@ public:
} }
template<typename... NewTs> template<typename... NewTs>
Variant<NewTs...> downcast() & Variant<NewTs...> verify_cast() &
{ {
Variant<NewTs...> instance { Variant<NewTs...>::invalid_index, Detail::VariantConstructTag {} }; Variant<NewTs...> instance { Variant<NewTs...>::invalid_index, Detail::VariantConstructTag {} };
visit([&](const auto& value) { visit([&](const auto& value) {

View file

@ -77,17 +77,17 @@ TEST_CASE(move_moves)
EXPECT(second_variant.has<NoCopy>()); EXPECT(second_variant.has<NoCopy>());
} }
TEST_CASE(downcast) TEST_CASE(verify_cast)
{ {
Variant<i8, i16, i32, i64> one_integer_to_rule_them_all { static_cast<i32>(42) }; Variant<i8, i16, i32, i64> one_integer_to_rule_them_all { static_cast<i32>(42) };
auto fake_integer = one_integer_to_rule_them_all.downcast<i8, i32>(); auto fake_integer = one_integer_to_rule_them_all.verify_cast<i8, i32>();
EXPECT(fake_integer.has<i32>()); EXPECT(fake_integer.has<i32>());
EXPECT(one_integer_to_rule_them_all.has<i32>()); EXPECT(one_integer_to_rule_them_all.has<i32>());
EXPECT_EQ(fake_integer.get<i32>(), 42); EXPECT_EQ(fake_integer.get<i32>(), 42);
EXPECT_EQ(one_integer_to_rule_them_all.get<i32>(), 42); EXPECT_EQ(one_integer_to_rule_them_all.get<i32>(), 42);
fake_integer = static_cast<i8>(60); fake_integer = static_cast<i8>(60);
one_integer_to_rule_them_all = fake_integer.downcast<i8, i16>().downcast<i8, i32, float>().downcast<i8, i16, i32, i64>(); one_integer_to_rule_them_all = fake_integer.verify_cast<i8, i16>().verify_cast<i8, i32, float>().verify_cast<i8, i16, i32, i64>();
EXPECT(fake_integer.has<i8>()); EXPECT(fake_integer.has<i8>());
EXPECT(one_integer_to_rule_them_all.has<i8>()); EXPECT(one_integer_to_rule_them_all.has<i8>());
EXPECT_EQ(fake_integer.get<i8>(), 60); EXPECT_EQ(fake_integer.get<i8>(), 60);

View file

@ -479,7 +479,7 @@ GUI::TabWidget& BrowserWindow::tab_widget()
Tab& BrowserWindow::active_tab() Tab& BrowserWindow::active_tab()
{ {
return downcast<Tab>(*tab_widget().active_widget()); return verify_cast<Tab>(*tab_widget().active_widget());
} }
void BrowserWindow::set_window_title_for_tab(Tab const& tab) void BrowserWindow::set_window_title_for_tab(Tab const& tab)

View file

@ -22,7 +22,7 @@ void InspectorWidget::set_inspected_node(Web::DOM::Node* node)
{ {
m_document->set_inspected_node(node); m_document->set_inspected_node(node);
if (node && node->is_element()) { if (node && node->is_element()) {
auto& element = downcast<Web::DOM::Element>(*node); auto& element = verify_cast<Web::DOM::Element>(*node);
if (element.specified_css_values()) { if (element.specified_css_values()) {
m_style_table_view->set_model(Web::StylePropertiesModel::create(*element.specified_css_values())); m_style_table_view->set_model(Web::StylePropertiesModel::create(*element.specified_css_values()));
m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(*element.computed_style())); m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(*element.computed_style()));

View file

@ -68,7 +68,7 @@ int main(int argc, char** argv)
auto current_image_editor = [&]() -> PixelPaint::ImageEditor* { auto current_image_editor = [&]() -> PixelPaint::ImageEditor* {
if (!tab_widget.active_widget()) if (!tab_widget.active_widget())
return nullptr; return nullptr;
return downcast<PixelPaint::ImageEditor>(tab_widget.active_widget()); return verify_cast<PixelPaint::ImageEditor>(tab_widget.active_widget());
}; };
Function<PixelPaint::ImageEditor&(NonnullRefPtr<PixelPaint::Image>)> create_new_editor; Function<PixelPaint::ImageEditor&(NonnullRefPtr<PixelPaint::Image>)> create_new_editor;
@ -552,14 +552,14 @@ int main(int argc, char** argv)
}; };
tab_widget.on_tab_close_click = [&](auto& widget) { tab_widget.on_tab_close_click = [&](auto& widget) {
auto& image_editor = downcast<PixelPaint::ImageEditor>(widget); auto& image_editor = verify_cast<PixelPaint::ImageEditor>(widget);
tab_widget.deferred_invoke([&](auto&) { tab_widget.deferred_invoke([&](auto&) {
tab_widget.remove_tab(image_editor); tab_widget.remove_tab(image_editor);
}); });
}; };
tab_widget.on_change = [&](auto& widget) { tab_widget.on_change = [&](auto& widget) {
auto& image_editor = downcast<PixelPaint::ImageEditor>(widget); auto& image_editor = verify_cast<PixelPaint::ImageEditor>(widget);
palette_widget.set_image_editor(image_editor); palette_widget.set_image_editor(image_editor);
layer_list_widget.set_image(&image_editor.image()); layer_list_widget.set_image(&image_editor.image());
layer_properties_widget.set_layer(nullptr); layer_properties_widget.set_layer(nullptr);

View file

@ -74,7 +74,7 @@ void ThreadStackWidget::refresh()
void ThreadStackWidget::custom_event(Core::CustomEvent& event) void ThreadStackWidget::custom_event(Core::CustomEvent& event)
{ {
auto& completion_event = downcast<CompletionEvent>(event); auto& completion_event = verify_cast<CompletionEvent>(event);
StringBuilder builder; StringBuilder builder;

View file

@ -54,7 +54,7 @@ void StackWidget::child_event(Core::ChildEvent& event)
{ {
if (!event.child() || !is<Widget>(*event.child())) if (!event.child() || !is<Widget>(*event.child()))
return Widget::child_event(event); return Widget::child_event(event);
auto& child = downcast<Widget>(*event.child()); auto& child = verify_cast<Widget>(*event.child());
if (event.type() == Event::ChildAdded) { if (event.type() == Event::ChildAdded) {
if (!m_active_widget) if (!m_active_widget)
set_active_widget(&child); set_active_widget(&child);

View file

@ -134,7 +134,7 @@ void TabWidget::child_event(Core::ChildEvent& event)
{ {
if (!event.child() || !is<Widget>(*event.child())) if (!event.child() || !is<Widget>(*event.child()))
return Widget::child_event(event); return Widget::child_event(event);
auto& child = downcast<Widget>(*event.child()); auto& child = verify_cast<Widget>(*event.child());
if (event.type() == Event::ChildAdded) { if (event.type() == Event::ChildAdded) {
if (!m_active_widget) if (!m_active_widget)
set_active_widget(&child); set_active_widget(&child);

View file

@ -147,22 +147,22 @@ void Widget::child_event(Core::ChildEvent& event)
if (event.type() == Event::ChildAdded) { if (event.type() == Event::ChildAdded) {
if (event.child() && is<Widget>(*event.child()) && layout()) { if (event.child() && is<Widget>(*event.child()) && layout()) {
if (event.insertion_before_child() && is<Widget>(event.insertion_before_child())) if (event.insertion_before_child() && is<Widget>(event.insertion_before_child()))
layout()->insert_widget_before(downcast<Widget>(*event.child()), downcast<Widget>(*event.insertion_before_child())); layout()->insert_widget_before(verify_cast<Widget>(*event.child()), verify_cast<Widget>(*event.insertion_before_child()));
else else
layout()->add_widget(downcast<Widget>(*event.child())); layout()->add_widget(verify_cast<Widget>(*event.child()));
} }
if (window() && event.child() && is<Widget>(*event.child())) if (window() && event.child() && is<Widget>(*event.child()))
window()->did_add_widget({}, downcast<Widget>(*event.child())); window()->did_add_widget({}, verify_cast<Widget>(*event.child()));
} }
if (event.type() == Event::ChildRemoved) { if (event.type() == Event::ChildRemoved) {
if (layout()) { if (layout()) {
if (event.child() && is<Widget>(*event.child())) if (event.child() && is<Widget>(*event.child()))
layout()->remove_widget(downcast<Widget>(*event.child())); layout()->remove_widget(verify_cast<Widget>(*event.child()));
else else
invalidate_layout(); invalidate_layout();
} }
if (window() && event.child() && is<Widget>(*event.child())) if (window() && event.child() && is<Widget>(*event.child()))
window()->did_remove_widget({}, downcast<Widget>(*event.child())); window()->did_remove_widget({}, verify_cast<Widget>(*event.child()));
update(); update();
} }
return Core::Object::child_event(event); return Core::Object::child_event(event);
@ -563,7 +563,7 @@ Widget* Widget::child_at(const Gfx::IntPoint& point) const
for (int i = children().size() - 1; i >= 0; --i) { for (int i = children().size() - 1; i >= 0; --i) {
if (!is<Widget>(children()[i])) if (!is<Widget>(children()[i]))
continue; continue;
auto& child = downcast<Widget>(children()[i]); auto& child = verify_cast<Widget>(children()[i]);
if (!child.is_visible()) if (!child.is_visible())
continue; continue;
if (child.content_rect().contains(point)) if (child.content_rect().contains(point))

View file

@ -245,7 +245,7 @@ public:
{ {
for_each_child([&](auto& child) { for_each_child([&](auto& child) {
if (is<Widget>(child)) if (is<Widget>(child))
return callback(downcast<Widget>(child)); return callback(verify_cast<Widget>(child));
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
} }
@ -370,13 +370,13 @@ private:
inline Widget* Widget::parent_widget() inline Widget* Widget::parent_widget()
{ {
if (parent() && is<Widget>(*parent())) if (parent() && is<Widget>(*parent()))
return &downcast<Widget>(*parent()); return &verify_cast<Widget>(*parent());
return nullptr; return nullptr;
} }
inline const Widget* Widget::parent_widget() const inline const Widget* Widget::parent_widget() const
{ {
if (parent() && is<Widget>(*parent())) if (parent() && is<Widget>(*parent()))
return &downcast<const Widget>(*parent()); return &verify_cast<const Widget>(*parent());
return nullptr; return nullptr;
} }
} }

View file

@ -1691,7 +1691,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(bool for_l
declarations.append(create_ast_node<VariableDeclarator>( declarations.append(create_ast_node<VariableDeclarator>(
{ m_state.current_token.filename(), rule_start.position(), position() }, { m_state.current_token.filename(), rule_start.position(), position() },
move(target).downcast<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>>(), move(target).verify_cast<NonnullRefPtr<Identifier>, NonnullRefPtr<BindingPattern>>(),
move(init))); move(init)));
if (match(TokenType::Comma)) { if (match(TokenType::Comma)) {

View file

@ -397,7 +397,7 @@ Optional<InstantiationError> AbstractMachine::allocate_all_initial_phase(Module
module_instance.exports().append(ExportInstance { module_instance.exports().append(ExportInstance {
entry.name(), entry.name(),
move(address).downcast<FunctionAddress, TableAddress, MemoryAddress, GlobalAddress>(), move(address).verify_cast<FunctionAddress, TableAddress, MemoryAddress, GlobalAddress>(),
}); });
} }
}); });

View file

@ -41,7 +41,7 @@ bool CSSStyleDeclarationWrapper::put(const JS::PropertyName& name, JS::Value val
return false; return false;
ScopeGuard style_invalidation_guard = [&] { ScopeGuard style_invalidation_guard = [&] {
auto& declaration = downcast<CSS::ElementInlineCSSStyleDeclaration>(impl()); auto& declaration = verify_cast<CSS::ElementInlineCSSStyleDeclaration>(impl());
if (auto* element = declaration.element()) if (auto* element = declaration.element())
element->invalidate_style(); element->invalidate_style();
}; };

View file

@ -164,163 +164,163 @@ namespace Web::Bindings {
NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node) NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node)
{ {
if (is<DOM::Document>(node)) if (is<DOM::Document>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::Document>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::Document>(node)));
if (is<DOM::DocumentType>(node)) if (is<DOM::DocumentType>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::DocumentType>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::DocumentType>(node)));
if (is<HTML::HTMLAnchorElement>(node)) if (is<HTML::HTMLAnchorElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLAnchorElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLAnchorElement>(node)));
if (is<HTML::HTMLAreaElement>(node)) if (is<HTML::HTMLAreaElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLAreaElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLAreaElement>(node)));
if (is<HTML::HTMLAudioElement>(node)) if (is<HTML::HTMLAudioElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLAudioElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLAudioElement>(node)));
if (is<HTML::HTMLBaseElement>(node)) if (is<HTML::HTMLBaseElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLBaseElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLBaseElement>(node)));
if (is<HTML::HTMLBodyElement>(node)) if (is<HTML::HTMLBodyElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLBodyElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLBodyElement>(node)));
if (is<HTML::HTMLBRElement>(node)) if (is<HTML::HTMLBRElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLBRElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLBRElement>(node)));
if (is<HTML::HTMLButtonElement>(node)) if (is<HTML::HTMLButtonElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLButtonElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLButtonElement>(node)));
if (is<HTML::HTMLCanvasElement>(node)) if (is<HTML::HTMLCanvasElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLCanvasElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLCanvasElement>(node)));
if (is<HTML::HTMLDataElement>(node)) if (is<HTML::HTMLDataElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDataElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDataElement>(node)));
if (is<HTML::HTMLDataListElement>(node)) if (is<HTML::HTMLDataListElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDataListElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDataListElement>(node)));
if (is<HTML::HTMLDetailsElement>(node)) if (is<HTML::HTMLDetailsElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDetailsElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDetailsElement>(node)));
if (is<HTML::HTMLDialogElement>(node)) if (is<HTML::HTMLDialogElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDialogElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDialogElement>(node)));
if (is<HTML::HTMLDirectoryElement>(node)) if (is<HTML::HTMLDirectoryElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDirectoryElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDirectoryElement>(node)));
if (is<HTML::HTMLDivElement>(node)) if (is<HTML::HTMLDivElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDivElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDivElement>(node)));
if (is<HTML::HTMLDListElement>(node)) if (is<HTML::HTMLDListElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLDListElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLDListElement>(node)));
if (is<HTML::HTMLEmbedElement>(node)) if (is<HTML::HTMLEmbedElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLEmbedElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLEmbedElement>(node)));
if (is<HTML::HTMLFieldSetElement>(node)) if (is<HTML::HTMLFieldSetElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLFieldSetElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLFieldSetElement>(node)));
if (is<HTML::HTMLFontElement>(node)) if (is<HTML::HTMLFontElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLFontElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLFontElement>(node)));
if (is<HTML::HTMLFormElement>(node)) if (is<HTML::HTMLFormElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLFormElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLFormElement>(node)));
if (is<HTML::HTMLFrameElement>(node)) if (is<HTML::HTMLFrameElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLFrameElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLFrameElement>(node)));
if (is<HTML::HTMLFrameSetElement>(node)) if (is<HTML::HTMLFrameSetElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLFrameSetElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLFrameSetElement>(node)));
if (is<HTML::HTMLHeadElement>(node)) if (is<HTML::HTMLHeadElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLHeadElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLHeadElement>(node)));
if (is<HTML::HTMLHeadingElement>(node)) if (is<HTML::HTMLHeadingElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLHeadingElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLHeadingElement>(node)));
if (is<HTML::HTMLHRElement>(node)) if (is<HTML::HTMLHRElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLHRElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLHRElement>(node)));
if (is<HTML::HTMLHtmlElement>(node)) if (is<HTML::HTMLHtmlElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLHtmlElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLHtmlElement>(node)));
if (is<HTML::HTMLIFrameElement>(node)) if (is<HTML::HTMLIFrameElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLIFrameElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLIFrameElement>(node)));
if (is<HTML::HTMLImageElement>(node)) if (is<HTML::HTMLImageElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLImageElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLImageElement>(node)));
if (is<HTML::HTMLInputElement>(node)) if (is<HTML::HTMLInputElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLInputElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLInputElement>(node)));
if (is<HTML::HTMLLabelElement>(node)) if (is<HTML::HTMLLabelElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLLabelElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLLabelElement>(node)));
if (is<HTML::HTMLLegendElement>(node)) if (is<HTML::HTMLLegendElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLLegendElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLLegendElement>(node)));
if (is<HTML::HTMLLIElement>(node)) if (is<HTML::HTMLLIElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLLIElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLLIElement>(node)));
if (is<HTML::HTMLLinkElement>(node)) if (is<HTML::HTMLLinkElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLLinkElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLLinkElement>(node)));
if (is<HTML::HTMLMapElement>(node)) if (is<HTML::HTMLMapElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLMapElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLMapElement>(node)));
if (is<HTML::HTMLMarqueeElement>(node)) if (is<HTML::HTMLMarqueeElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLMarqueeElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLMarqueeElement>(node)));
if (is<HTML::HTMLMenuElement>(node)) if (is<HTML::HTMLMenuElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLMenuElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLMenuElement>(node)));
if (is<HTML::HTMLMetaElement>(node)) if (is<HTML::HTMLMetaElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLMetaElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLMetaElement>(node)));
if (is<HTML::HTMLMeterElement>(node)) if (is<HTML::HTMLMeterElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLMeterElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLMeterElement>(node)));
if (is<HTML::HTMLModElement>(node)) if (is<HTML::HTMLModElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLModElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLModElement>(node)));
if (is<HTML::HTMLObjectElement>(node)) if (is<HTML::HTMLObjectElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLObjectElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLObjectElement>(node)));
if (is<HTML::HTMLOListElement>(node)) if (is<HTML::HTMLOListElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLOListElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLOListElement>(node)));
if (is<HTML::HTMLOptGroupElement>(node)) if (is<HTML::HTMLOptGroupElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLOptGroupElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLOptGroupElement>(node)));
if (is<HTML::HTMLOptionElement>(node)) if (is<HTML::HTMLOptionElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLOptionElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLOptionElement>(node)));
if (is<HTML::HTMLOutputElement>(node)) if (is<HTML::HTMLOutputElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLOutputElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLOutputElement>(node)));
if (is<HTML::HTMLParagraphElement>(node)) if (is<HTML::HTMLParagraphElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLParagraphElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLParagraphElement>(node)));
if (is<HTML::HTMLParamElement>(node)) if (is<HTML::HTMLParamElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLParamElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLParamElement>(node)));
if (is<HTML::HTMLPictureElement>(node)) if (is<HTML::HTMLPictureElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLPictureElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLPictureElement>(node)));
if (is<HTML::HTMLPreElement>(node)) if (is<HTML::HTMLPreElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLPreElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLPreElement>(node)));
if (is<HTML::HTMLProgressElement>(node)) if (is<HTML::HTMLProgressElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLProgressElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLProgressElement>(node)));
if (is<HTML::HTMLQuoteElement>(node)) if (is<HTML::HTMLQuoteElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLQuoteElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLQuoteElement>(node)));
if (is<HTML::HTMLScriptElement>(node)) if (is<HTML::HTMLScriptElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLScriptElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLScriptElement>(node)));
if (is<HTML::HTMLSelectElement>(node)) if (is<HTML::HTMLSelectElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLSelectElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLSelectElement>(node)));
if (is<HTML::HTMLSlotElement>(node)) if (is<HTML::HTMLSlotElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLSlotElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLSlotElement>(node)));
if (is<HTML::HTMLSourceElement>(node)) if (is<HTML::HTMLSourceElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLSourceElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLSourceElement>(node)));
if (is<HTML::HTMLSpanElement>(node)) if (is<HTML::HTMLSpanElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLSpanElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLSpanElement>(node)));
if (is<HTML::HTMLStyleElement>(node)) if (is<HTML::HTMLStyleElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLStyleElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLStyleElement>(node)));
if (is<HTML::HTMLTableCaptionElement>(node)) if (is<HTML::HTMLTableCaptionElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTableCaptionElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTableCaptionElement>(node)));
if (is<HTML::HTMLTableCellElement>(node)) if (is<HTML::HTMLTableCellElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTableCellElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTableCellElement>(node)));
if (is<HTML::HTMLTableColElement>(node)) if (is<HTML::HTMLTableColElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTableColElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTableColElement>(node)));
if (is<HTML::HTMLTableElement>(node)) if (is<HTML::HTMLTableElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTableElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTableElement>(node)));
if (is<HTML::HTMLTableRowElement>(node)) if (is<HTML::HTMLTableRowElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTableRowElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTableRowElement>(node)));
if (is<HTML::HTMLTableSectionElement>(node)) if (is<HTML::HTMLTableSectionElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTableSectionElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTableSectionElement>(node)));
if (is<HTML::HTMLTemplateElement>(node)) if (is<HTML::HTMLTemplateElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTemplateElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTemplateElement>(node)));
if (is<HTML::HTMLTextAreaElement>(node)) if (is<HTML::HTMLTextAreaElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTextAreaElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTextAreaElement>(node)));
if (is<HTML::HTMLTimeElement>(node)) if (is<HTML::HTMLTimeElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTimeElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTimeElement>(node)));
if (is<HTML::HTMLTitleElement>(node)) if (is<HTML::HTMLTitleElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTitleElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTitleElement>(node)));
if (is<HTML::HTMLTrackElement>(node)) if (is<HTML::HTMLTrackElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLTrackElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLTrackElement>(node)));
if (is<HTML::HTMLUListElement>(node)) if (is<HTML::HTMLUListElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLUListElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLUListElement>(node)));
if (is<HTML::HTMLUnknownElement>(node)) if (is<HTML::HTMLUnknownElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLUnknownElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLUnknownElement>(node)));
if (is<HTML::HTMLVideoElement>(node)) if (is<HTML::HTMLVideoElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLVideoElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLVideoElement>(node)));
if (is<HTML::HTMLElement>(node)) if (is<HTML::HTMLElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<HTML::HTMLElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<HTML::HTMLElement>(node)));
if (is<SVG::SVGSVGElement>(node)) if (is<SVG::SVGSVGElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<SVG::SVGSVGElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<SVG::SVGSVGElement>(node)));
if (is<SVG::SVGPathElement>(node)) if (is<SVG::SVGPathElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<SVG::SVGPathElement>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<SVG::SVGPathElement>(node)));
if (is<DOM::Element>(node)) if (is<DOM::Element>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::Element>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::Element>(node)));
if (is<DOM::DocumentFragment>(node)) if (is<DOM::DocumentFragment>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::DocumentFragment>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::DocumentFragment>(node)));
if (is<DOM::Comment>(node)) if (is<DOM::Comment>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::Comment>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::Comment>(node)));
if (is<DOM::Text>(node)) if (is<DOM::Text>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::Text>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::Text>(node)));
if (is<DOM::CharacterData>(node)) if (is<DOM::CharacterData>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, downcast<DOM::CharacterData>(node))); return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::CharacterData>(node)));
return static_cast<NodeWrapper*>(wrap_impl(global_object, node)); return static_cast<NodeWrapper*>(wrap_impl(global_object, node));
} }

View file

@ -36,9 +36,9 @@ public:
{ {
for (auto& rule : m_rules) for (auto& rule : m_rules)
if (rule.type() == CSSRule::Type::Style) { if (rule.type() == CSSRule::Type::Style) {
callback(downcast<CSSStyleRule>(rule)); callback(verify_cast<CSSStyleRule>(rule));
} else if (rule.type() == CSSRule::Type::Import) { } else if (rule.type() == CSSRule::Type::Import) {
const auto& import_rule = downcast<CSSImportRule>(rule); const auto& import_rule = verify_cast<CSSImportRule>(rule);
if (import_rule.has_import_result()) if (import_rule.has_import_result())
import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback); import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback);
} }
@ -49,7 +49,7 @@ public:
{ {
for (auto& rule : m_rules) for (auto& rule : m_rules)
if (rule.type() == CSSRule::Type::Import) { if (rule.type() == CSSRule::Type::Import) {
auto& import_rule = downcast<CSSImportRule>(rule); auto& import_rule = verify_cast<CSSImportRule>(rule);
if (!import_rule.has_import_result()) { if (!import_rule.has_import_result()) {
callback(import_rule); callback(import_rule);
return true; return true;

View file

@ -212,7 +212,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con
for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) { for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) {
if (!is<DOM::Element>(*ancestor)) if (!is<DOM::Element>(*ancestor))
continue; continue;
if (matches(selector, component_list_index - 1, downcast<DOM::Element>(*ancestor))) if (matches(selector, component_list_index - 1, verify_cast<DOM::Element>(*ancestor)))
return true; return true;
} }
return false; return false;
@ -220,7 +220,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con
VERIFY(component_list_index != 0); VERIFY(component_list_index != 0);
if (!element.parent() || !is<DOM::Element>(*element.parent())) if (!element.parent() || !is<DOM::Element>(*element.parent()))
return false; return false;
return matches(selector, component_list_index - 1, downcast<DOM::Element>(*element.parent())); return matches(selector, component_list_index - 1, verify_cast<DOM::Element>(*element.parent()));
case CSS::Selector::ComplexSelector::Relation::AdjacentSibling: case CSS::Selector::ComplexSelector::Relation::AdjacentSibling:
VERIFY(component_list_index != 0); VERIFY(component_list_index != 0);
if (auto* sibling = element.previous_element_sibling()) if (auto* sibling = element.previous_element_sibling())

View file

@ -278,11 +278,11 @@ Optional<float> StyleProperties::flex_grow_factor() const
auto value = property(CSS::PropertyID::FlexGrow); auto value = property(CSS::PropertyID::FlexGrow);
if (!value.has_value()) if (!value.has_value())
return {}; return {};
if (value.value()->is_length() && downcast<CSS::LengthStyleValue>(value.value().ptr())->to_length().raw_value() == 0) if (value.value()->is_length() && verify_cast<CSS::LengthStyleValue>(value.value().ptr())->to_length().raw_value() == 0)
return { 0 }; return { 0 };
if (!value.value()->is_numeric()) if (!value.value()->is_numeric())
return {}; return {};
auto numeric = downcast<CSS::NumericStyleValue>(value.value().ptr()); auto numeric = verify_cast<CSS::NumericStyleValue>(value.value().ptr());
return numeric->value(); return numeric->value();
} }
@ -291,11 +291,11 @@ Optional<float> StyleProperties::flex_shrink_factor() const
auto value = property(CSS::PropertyID::FlexShrink); auto value = property(CSS::PropertyID::FlexShrink);
if (!value.has_value()) if (!value.has_value())
return {}; return {};
if (value.value()->is_length() && downcast<CSS::LengthStyleValue>(value.value().ptr())->to_length().raw_value() == 0) if (value.value()->is_length() && verify_cast<CSS::LengthStyleValue>(value.value().ptr())->to_length().raw_value() == 0)
return { 0 }; return { 0 };
if (!value.value()->is_numeric()) if (!value.value()->is_numeric())
return {}; return {};
auto numeric = downcast<CSS::NumericStyleValue>(value.value().ptr()); auto numeric = verify_cast<CSS::NumericStyleValue>(value.value().ptr());
return numeric->value(); return numeric->value();
} }

View file

@ -188,7 +188,7 @@ HTML::HTMLHtmlElement* Document::html_element()
{ {
auto* html = document_element(); auto* html = document_element();
if (is<HTML::HTMLHtmlElement>(html)) if (is<HTML::HTMLHtmlElement>(html))
return downcast<HTML::HTMLHtmlElement>(html); return verify_cast<HTML::HTMLHtmlElement>(html);
return nullptr; return nullptr;
} }
@ -423,7 +423,7 @@ static void update_style_recursively(DOM::Node& node)
node.for_each_child([&](auto& child) { node.for_each_child([&](auto& child) {
if (child.needs_style_update()) { if (child.needs_style_update()) {
if (is<Element>(child)) if (is<Element>(child))
downcast<Element>(child).recompute_style(); verify_cast<Element>(child).recompute_style();
child.set_needs_style_update(false); child.set_needs_style_update(false);
} }
if (child.child_needs_style_update()) { if (child.child_needs_style_update()) {
@ -836,7 +836,7 @@ ExceptionOr<NonnullRefPtr<Node>> Document::adopt_node_binding(NonnullRefPtr<Node
if (is<ShadowRoot>(*node)) if (is<ShadowRoot>(*node))
return DOM::HierarchyRequestError::create("Cannot adopt a shadow root into a document"); return DOM::HierarchyRequestError::create("Cannot adopt a shadow root into a document");
if (is<DocumentFragment>(*node) && downcast<DocumentFragment>(*node).host()) if (is<DocumentFragment>(*node) && verify_cast<DocumentFragment>(*node).host())
return node; return node;
adopt_node(*node); adopt_node(*node);

View file

@ -290,7 +290,7 @@ String Element::inner_html() const
Function<void(const Node&)> recurse = [&](auto& node) { Function<void(const Node&)> recurse = [&](auto& node) {
for (auto* child = node.first_child(); child; child = child->next_sibling()) { for (auto* child = node.first_child(); child; child = child->next_sibling()) {
if (child->is_element()) { if (child->is_element()) {
auto& element = downcast<Element>(*child); auto& element = verify_cast<Element>(*child);
builder.append('<'); builder.append('<');
builder.append(element.local_name()); builder.append(element.local_name());
element.for_each_attribute([&](auto& name, auto& value) { element.for_each_attribute([&](auto& name, auto& value) {
@ -311,7 +311,7 @@ String Element::inner_html() const
builder.append('>'); builder.append('>');
} }
if (child->is_text()) { if (child->is_text()) {
auto& text = downcast<Text>(*child); auto& text = verify_cast<Text>(*child);
builder.append(escape_string(text.data(), false)); builder.append(escape_string(text.data(), false));
} }
// FIXME: Also handle Comment, ProcessingInstruction, DocumentType // FIXME: Also handle Comment, ProcessingInstruction, DocumentType

View file

@ -18,11 +18,11 @@ void Event::append_to_path(EventTarget& invocation_target, RefPtr<EventTarget> s
bool root_of_closed_tree = false; bool root_of_closed_tree = false;
if (is<Node>(invocation_target)) { if (is<Node>(invocation_target)) {
auto& invocation_target_node = downcast<Node>(invocation_target); auto& invocation_target_node = verify_cast<Node>(invocation_target);
if (is<ShadowRoot>(invocation_target_node.root())) if (is<ShadowRoot>(invocation_target_node.root()))
invocation_target_in_shadow_tree = true; invocation_target_in_shadow_tree = true;
if (is<ShadowRoot>(invocation_target_node)) { if (is<ShadowRoot>(invocation_target_node)) {
auto& invocation_target_shadow_root = downcast<ShadowRoot>(invocation_target_node); auto& invocation_target_shadow_root = verify_cast<ShadowRoot>(invocation_target_node);
root_of_closed_tree = invocation_target_shadow_root.closed(); root_of_closed_tree = invocation_target_shadow_root.closed();
} }
} }

View file

@ -35,14 +35,14 @@ static EventTarget* retarget(EventTarget* left, [[maybe_unused]] EventTarget* ri
if (!is<Node>(left)) if (!is<Node>(left))
return left; return left;
auto* left_node = downcast<Node>(left); auto* left_node = verify_cast<Node>(left);
auto* left_root = left_node->root(); auto* left_root = left_node->root();
if (!is<ShadowRoot>(left_root)) if (!is<ShadowRoot>(left_root))
return left; return left;
// FIXME: If right is a node and lefts root is a shadow-including inclusive ancestor of right, return left. // FIXME: If right is a node and lefts root is a shadow-including inclusive ancestor of right, return left.
auto* left_shadow_root = downcast<ShadowRoot>(left_root); auto* left_shadow_root = verify_cast<ShadowRoot>(left_root);
left = left_shadow_root->host(); left = left_shadow_root->host();
} }
} }
@ -76,7 +76,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListen
RefPtr<Event> current_event; RefPtr<Event> current_event;
if (is<Bindings::WindowObject>(global)) { if (is<Bindings::WindowObject>(global)) {
auto& bindings_window_global = downcast<Bindings::WindowObject>(global); auto& bindings_window_global = verify_cast<Bindings::WindowObject>(global);
auto& window_impl = bindings_window_global.impl(); auto& window_impl = bindings_window_global.impl();
current_event = window_impl.current_event(); current_event = window_impl.current_event();
if (!invocation_target_in_shadow_tree) if (!invocation_target_in_shadow_tree)
@ -97,7 +97,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListen
event.set_in_passive_listener(false); event.set_in_passive_listener(false);
if (is<Bindings::WindowObject>(global)) { if (is<Bindings::WindowObject>(global)) {
auto& bindings_window_global = downcast<Bindings::WindowObject>(global); auto& bindings_window_global = verify_cast<Bindings::WindowObject>(global);
auto& window_impl = bindings_window_global.impl(); auto& window_impl = bindings_window_global.impl();
window_impl.set_current_event(current_event); window_impl.set_current_event(current_event);
} }
@ -162,7 +162,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr<
target_override = target; target_override = target;
} else { } else {
// NOTE: This can be done because legacy_target_override is only set for events targeted at Window. // NOTE: This can be done because legacy_target_override is only set for events targeted at Window.
target_override = downcast<Window>(*target).document(); target_override = verify_cast<Window>(*target).document();
} }
RefPtr<EventTarget> activation_target; RefPtr<EventTarget> activation_target;
@ -232,13 +232,13 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr<
VERIFY(clear_targets_struct.has_value()); VERIFY(clear_targets_struct.has_value());
if (is<Node>(clear_targets_struct.value().shadow_adjusted_target.ptr())) { if (is<Node>(clear_targets_struct.value().shadow_adjusted_target.ptr())) {
auto& shadow_adjusted_target_node = downcast<Node>(*clear_targets_struct.value().shadow_adjusted_target); auto& shadow_adjusted_target_node = verify_cast<Node>(*clear_targets_struct.value().shadow_adjusted_target);
if (is<ShadowRoot>(shadow_adjusted_target_node.root())) if (is<ShadowRoot>(shadow_adjusted_target_node.root()))
clear_targets = true; clear_targets = true;
} }
if (!clear_targets && is<Node>(clear_targets_struct.value().related_target.ptr())) { if (!clear_targets && is<Node>(clear_targets_struct.value().related_target.ptr())) {
auto& related_target_node = downcast<Node>(*clear_targets_struct.value().related_target); auto& related_target_node = verify_cast<Node>(*clear_targets_struct.value().related_target);
if (is<ShadowRoot>(related_target_node.root())) if (is<ShadowRoot>(related_target_node.root()))
clear_targets = true; clear_targets = true;
} }
@ -246,7 +246,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr<
if (!clear_targets) { if (!clear_targets) {
for (auto touch_target : clear_targets_struct.value().touch_target_list) { for (auto touch_target : clear_targets_struct.value().touch_target_list) {
if (is<Node>(*touch_target.ptr())) { if (is<Node>(*touch_target.ptr())) {
auto& touch_target_node = downcast<Node>(*touch_target.ptr()); auto& touch_target_node = verify_cast<Node>(*touch_target.ptr());
if (is<ShadowRoot>(touch_target_node.root())) { if (is<ShadowRoot>(touch_target_node.root())) {
clear_targets = true; clear_targets = true;
break; break;

View file

@ -51,8 +51,8 @@ Node::~Node()
const HTML::HTMLAnchorElement* Node::enclosing_link_element() const const HTML::HTMLAnchorElement* Node::enclosing_link_element() const
{ {
for (auto* node = this; node; node = node->parent()) { for (auto* node = this; node; node = node->parent()) {
if (is<HTML::HTMLAnchorElement>(*node) && downcast<HTML::HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href)) if (is<HTML::HTMLAnchorElement>(*node) && verify_cast<HTML::HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href))
return downcast<HTML::HTMLAnchorElement>(node); return verify_cast<HTML::HTMLAnchorElement>(node);
} }
return nullptr; return nullptr;
} }
@ -65,8 +65,8 @@ const HTML::HTMLElement* Node::enclosing_html_element() const
const HTML::HTMLElement* Node::enclosing_html_element_with_attribute(const FlyString& attribute) const const HTML::HTMLElement* Node::enclosing_html_element_with_attribute(const FlyString& attribute) const
{ {
for (auto* node = this; node; node = node->parent()) { for (auto* node = this; node; node = node->parent()) {
if (is<HTML::HTMLElement>(*node) && downcast<HTML::HTMLElement>(*node).has_attribute(attribute)) if (is<HTML::HTMLElement>(*node) && verify_cast<HTML::HTMLElement>(*node).has_attribute(attribute))
return downcast<HTML::HTMLElement>(node); return verify_cast<HTML::HTMLElement>(node);
} }
return nullptr; return nullptr;
} }
@ -83,7 +83,7 @@ String Node::text_content() const
void Node::set_text_content(const String& content) void Node::set_text_content(const String& content)
{ {
if (is_text()) { if (is_text()) {
downcast<Text>(this)->set_data(content); verify_cast<Text>(this)->set_data(content);
} else { } else {
remove_all_children(); remove_all_children();
append_child(document().create_text_node(content)); append_child(document().create_text_node(content));
@ -123,9 +123,9 @@ String Node::child_text_content() const
return String::empty(); return String::empty();
StringBuilder builder; StringBuilder builder;
downcast<ParentNode>(*this).for_each_child([&](auto& child) { verify_cast<ParentNode>(*this).for_each_child([&](auto& child) {
if (is<Text>(child)) if (is<Text>(child))
builder.append(downcast<Text>(child).text_content()); builder.append(verify_cast<Text>(child).text_content());
}); });
return builder.build(); return builder.build();
} }
@ -142,7 +142,7 @@ Node* Node::shadow_including_root()
{ {
auto node_root = root(); auto node_root = root();
if (is<ShadowRoot>(node_root)) if (is<ShadowRoot>(node_root))
return downcast<ShadowRoot>(node_root)->host()->shadow_including_root(); return verify_cast<ShadowRoot>(node_root)->host()->shadow_including_root();
return node_root; return node_root;
} }
@ -155,14 +155,14 @@ Element* Node::parent_element()
{ {
if (!parent() || !is<Element>(parent())) if (!parent() || !is<Element>(parent()))
return nullptr; return nullptr;
return downcast<Element>(parent()); return verify_cast<Element>(parent());
} }
const Element* Node::parent_element() const const Element* Node::parent_element() const
{ {
if (!parent() || !is<Element>(parent())) if (!parent() || !is<Element>(parent()))
return nullptr; return nullptr;
return downcast<Element>(parent()); return verify_cast<Element>(parent());
} }
// https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity // https://dom.spec.whatwg.org/#concept-node-ensure-pre-insertion-validity
@ -187,7 +187,7 @@ ExceptionOr<void> Node::ensure_pre_insertion_validity(NonnullRefPtr<Node> node,
if (is<Document>(this)) { if (is<Document>(this)) {
if (is<DocumentFragment>(*node)) { if (is<DocumentFragment>(*node)) {
auto node_element_child_count = downcast<DocumentFragment>(*node).child_element_count(); auto node_element_child_count = verify_cast<DocumentFragment>(*node).child_element_count();
if ((node_element_child_count > 1 || node->has_child_of_type<Text>()) if ((node_element_child_count > 1 || node->has_child_of_type<Text>())
|| (node_element_child_count == 1 && (has_child_of_type<Element>() || is<DocumentType>(child.ptr()) /* FIXME: or child is non-null and a doctype is following child. */))) { || (node_element_child_count == 1 && (has_child_of_type<Element>() || is<DocumentType>(child.ptr()) /* FIXME: or child is non-null and a doctype is following child. */))) {
return DOM::HierarchyRequestError::create("Invalid node type for insertion"); return DOM::HierarchyRequestError::create("Invalid node type for insertion");
@ -209,7 +209,7 @@ void Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool supp
{ {
NonnullRefPtrVector<Node> nodes; NonnullRefPtrVector<Node> nodes;
if (is<DocumentFragment>(*node)) if (is<DocumentFragment>(*node))
nodes = downcast<DocumentFragment>(*node).child_nodes(); nodes = verify_cast<DocumentFragment>(*node).child_nodes();
else else
nodes.append(node); nodes.append(node);
@ -369,7 +369,7 @@ ExceptionOr<NonnullRefPtr<Node>> Node::replace_child(NonnullRefPtr<Node> node, N
if (is<Document>(this)) { if (is<Document>(this)) {
if (is<DocumentFragment>(*node)) { if (is<DocumentFragment>(*node)) {
auto node_element_child_count = downcast<DocumentFragment>(*node).child_element_count(); auto node_element_child_count = verify_cast<DocumentFragment>(*node).child_element_count();
if ((node_element_child_count > 1 || node->has_child_of_type<Text>()) if ((node_element_child_count > 1 || node->has_child_of_type<Text>())
|| (node_element_child_count == 1 && (first_child_of_type<Element>() != child /* FIXME: or a doctype is following child. */))) { || (node_element_child_count == 1 && (first_child_of_type<Element>() != child /* FIXME: or a doctype is following child. */))) {
return DOM::HierarchyRequestError::create("Invalid node type for insertion"); return DOM::HierarchyRequestError::create("Invalid node type for insertion");
@ -411,7 +411,7 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co
document = m_document; document = m_document;
RefPtr<Node> copy; RefPtr<Node> copy;
if (is<Element>(this)) { if (is<Element>(this)) {
auto& element = *downcast<Element>(this); auto& element = *verify_cast<Element>(this);
auto qualified_name = QualifiedName(element.local_name(), element.prefix(), element.namespace_()); auto qualified_name = QualifiedName(element.local_name(), element.prefix(), element.namespace_());
auto element_copy = adopt_ref(*new Element(*document, move(qualified_name))); auto element_copy = adopt_ref(*new Element(*document, move(qualified_name)));
element.for_each_attribute([&](auto& name, auto& value) { element.for_each_attribute([&](auto& name, auto& value) {
@ -419,7 +419,7 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co
}); });
copy = move(element_copy); copy = move(element_copy);
} else if (is<Document>(this)) { } else if (is<Document>(this)) {
auto document_ = downcast<Document>(this); auto document_ = verify_cast<Document>(this);
auto document_copy = Document::create(document_->url()); auto document_copy = Document::create(document_->url());
document_copy->set_encoding(document_->encoding()); document_copy->set_encoding(document_->encoding());
document_copy->set_content_type(document_->content_type()); document_copy->set_content_type(document_->content_type());
@ -428,22 +428,22 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co
// FIXME: Set type ("xml" or "html") // FIXME: Set type ("xml" or "html")
copy = move(document_copy); copy = move(document_copy);
} else if (is<DocumentType>(this)) { } else if (is<DocumentType>(this)) {
auto document_type = downcast<DocumentType>(this); auto document_type = verify_cast<DocumentType>(this);
auto document_type_copy = adopt_ref(*new DocumentType(*document)); auto document_type_copy = adopt_ref(*new DocumentType(*document));
document_type_copy->set_name(document_type->name()); document_type_copy->set_name(document_type->name());
document_type_copy->set_public_id(document_type->public_id()); document_type_copy->set_public_id(document_type->public_id());
document_type_copy->set_system_id(document_type->system_id()); document_type_copy->set_system_id(document_type->system_id());
copy = move(document_type_copy); copy = move(document_type_copy);
} else if (is<Text>(this)) { } else if (is<Text>(this)) {
auto text = downcast<Text>(this); auto text = verify_cast<Text>(this);
auto text_copy = adopt_ref(*new Text(*document, text->data())); auto text_copy = adopt_ref(*new Text(*document, text->data()));
copy = move(text_copy); copy = move(text_copy);
} else if (is<Comment>(this)) { } else if (is<Comment>(this)) {
auto comment = downcast<Comment>(this); auto comment = verify_cast<Comment>(this);
auto comment_copy = adopt_ref(*new Comment(*document, comment->data())); auto comment_copy = adopt_ref(*new Comment(*document, comment->data()));
copy = move(comment_copy); copy = move(comment_copy);
} else if (is<ProcessingInstruction>(this)) { } else if (is<ProcessingInstruction>(this)) {
auto processing_instruction = downcast<ProcessingInstruction>(this); auto processing_instruction = verify_cast<ProcessingInstruction>(this);
auto processing_instruction_copy = adopt_ref(*new ProcessingInstruction(*document, processing_instruction->data(), processing_instruction->target())); auto processing_instruction_copy = adopt_ref(*new ProcessingInstruction(*document, processing_instruction->data(), processing_instruction->target()));
copy = move(processing_instruction_copy); copy = move(processing_instruction_copy);
} else { } else {
@ -490,7 +490,7 @@ JS::Object* Node::create_wrapper(JS::GlobalObject& global_object)
void Node::removed_last_ref() void Node::removed_last_ref()
{ {
if (is<Document>(*this)) { if (is<Document>(*this)) {
downcast<Document>(*this).removed_last_ref(); verify_cast<Document>(*this).removed_last_ref();
return; return;
} }
m_deletion_has_begun = true; m_deletion_has_begun = true;
@ -534,8 +534,8 @@ void Node::inserted()
ParentNode* Node::parent_or_shadow_host() ParentNode* Node::parent_or_shadow_host()
{ {
if (is<ShadowRoot>(*this)) if (is<ShadowRoot>(*this))
return downcast<ShadowRoot>(*this).host(); return verify_cast<ShadowRoot>(*this).host();
return downcast<ParentNode>(parent()); return verify_cast<ParentNode>(parent());
} }
NonnullRefPtrVector<Node> Node::child_nodes() const NonnullRefPtrVector<Node> Node::child_nodes() const
@ -595,7 +595,7 @@ u16 Node::compare_document_position(RefPtr<Node> other)
// https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor // https://dom.spec.whatwg.org/#concept-tree-host-including-inclusive-ancestor
bool Node::is_host_including_inclusive_ancestor_of(const Node& other) const bool Node::is_host_including_inclusive_ancestor_of(const Node& other) const
{ {
return is_inclusive_ancestor_of(other) || (is<DocumentFragment>(other.root()) && downcast<DocumentFragment>(other.root())->host() && is_inclusive_ancestor_of(*downcast<DocumentFragment>(other.root())->host().ptr())); return is_inclusive_ancestor_of(other) || (is<DocumentFragment>(other.root()) && verify_cast<DocumentFragment>(other.root())->host() && is_inclusive_ancestor_of(*verify_cast<DocumentFragment>(other.root())->host().ptr()));
} }
// https://dom.spec.whatwg.org/#dom-node-ownerdocument // https://dom.spec.whatwg.org/#dom-node-ownerdocument

View file

@ -19,7 +19,7 @@ public:
{ {
for (auto* sibling = static_cast<NodeType*>(this)->previous_sibling(); sibling; sibling = sibling->previous_sibling()) { for (auto* sibling = static_cast<NodeType*>(this)->previous_sibling(); sibling; sibling = sibling->previous_sibling()) {
if (is<Element>(*sibling)) if (is<Element>(*sibling))
return downcast<Element>(sibling); return verify_cast<Element>(sibling);
} }
return nullptr; return nullptr;
} }
@ -28,7 +28,7 @@ public:
{ {
for (auto* sibling = static_cast<NodeType*>(this)->next_sibling(); sibling; sibling = sibling->next_sibling()) { for (auto* sibling = static_cast<NodeType*>(this)->next_sibling(); sibling; sibling = sibling->next_sibling()) {
if (is<Element>(*sibling)) if (is<Element>(*sibling))
return downcast<Element>(sibling); return verify_cast<Element>(sibling);
} }
return nullptr; return nullptr;
} }
@ -37,7 +37,7 @@ public:
{ {
for (auto* node = static_cast<NodeType*>(this)->next_in_pre_order(); node; node = node->next_in_pre_order()) { for (auto* node = static_cast<NodeType*>(this)->next_in_pre_order(); node; node = node->next_in_pre_order()) {
if (is<Element>(*node)) if (is<Element>(*node))
return downcast<Element>(node); return verify_cast<Element>(node);
} }
return nullptr; return nullptr;
} }

View file

@ -34,7 +34,7 @@ bool Position::increment_offset()
if (!is<DOM::Text>(*m_node)) if (!is<DOM::Text>(*m_node))
return false; return false;
auto& node = downcast<DOM::Text>(*m_node); auto& node = verify_cast<DOM::Text>(*m_node);
auto text = Utf8View(node.data()); auto text = Utf8View(node.data());
for (auto iterator = text.begin(); !iterator.done(); ++iterator) { for (auto iterator = text.begin(); !iterator.done(); ++iterator) {
@ -53,7 +53,7 @@ bool Position::decrement_offset()
if (m_offset == 0 || !is<DOM::Text>(*m_node)) if (m_offset == 0 || !is<DOM::Text>(*m_node))
return false; return false;
auto& node = downcast<DOM::Text>(*m_node); auto& node = verify_cast<DOM::Text>(*m_node);
auto text = Utf8View(node.data()); auto text = Utf8View(node.data());
size_t last_smaller_offset = 0; size_t last_smaller_offset = 0;
@ -76,7 +76,7 @@ bool Position::offset_is_at_end_of_node() const
if (!is<DOM::Text>(*m_node)) if (!is<DOM::Text>(*m_node))
return false; return false;
auto& node = downcast<DOM::Text>(*m_node); auto& node = verify_cast<DOM::Text>(*m_node);
auto text = node.data(); auto text = node.data();
return m_offset == text.length(); return m_offset == text.length();
} }

View file

@ -19,7 +19,7 @@ ShadowRoot::ShadowRoot(Document& document, Element& host)
EventTarget* ShadowRoot::get_parent(const Event& event) EventTarget* ShadowRoot::get_parent(const Event& event)
{ {
if (!event.composed()) { if (!event.composed()) {
auto& events_first_invocation_target = downcast<Node>(*event.path().first().invocation_target); auto& events_first_invocation_target = verify_cast<Node>(*event.path().first().invocation_target);
if (events_first_invocation_target.root() == this) if (events_first_invocation_target.root() == this)
return nullptr; return nullptr;
} }

View file

@ -110,10 +110,10 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
} }
if (role == GUI::ModelRole::Display) { if (role == GUI::ModelRole::Display) {
if (node.is_text()) if (node.is_text())
return with_whitespace_collapsed(downcast<DOM::Text>(node).data()); return with_whitespace_collapsed(verify_cast<DOM::Text>(node).data());
if (!node.is_element()) if (!node.is_element())
return node.node_name(); return node.node_name();
auto& element = downcast<DOM::Element>(node); auto& element = verify_cast<DOM::Element>(node);
StringBuilder builder; StringBuilder builder;
builder.append('<'); builder.append('<');
builder.append(element.local_name()); builder.append(element.local_name());

View file

@ -40,19 +40,19 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node)
for (int i = 0; i < indent; ++i) for (int i = 0; i < indent; ++i)
builder.append(" "); builder.append(" ");
if (is<DOM::Element>(node)) { if (is<DOM::Element>(node)) {
builder.appendff("<{}", downcast<DOM::Element>(node).local_name()); builder.appendff("<{}", verify_cast<DOM::Element>(node).local_name());
downcast<DOM::Element>(node).for_each_attribute([&](auto& name, auto& value) { verify_cast<DOM::Element>(node).for_each_attribute([&](auto& name, auto& value) {
builder.appendff(" {}={}", name, value); builder.appendff(" {}={}", name, value);
}); });
builder.append(">\n"); builder.append(">\n");
} else if (is<DOM::Text>(node)) { } else if (is<DOM::Text>(node)) {
builder.appendff("\"{}\"\n", downcast<DOM::Text>(node).data()); builder.appendff("\"{}\"\n", verify_cast<DOM::Text>(node).data());
} else { } else {
builder.appendff("{}\n", node.node_name()); builder.appendff("{}\n", node.node_name());
} }
++indent; ++indent;
if (is<DOM::Element>(node) && downcast<DOM::Element>(node).shadow_root()) { if (is<DOM::Element>(node) && verify_cast<DOM::Element>(node).shadow_root()) {
dump_tree(*downcast<DOM::Element>(node).shadow_root()); dump_tree(*verify_cast<DOM::Element>(node).shadow_root());
} }
if (is<DOM::ParentNode>(node)) { if (is<DOM::ParentNode>(node)) {
if (!is<HTML::HTMLTemplateElement>(node)) { if (!is<HTML::HTMLTemplateElement>(node)) {
@ -60,7 +60,7 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node)
dump_tree(child); dump_tree(child);
}); });
} else { } else {
auto& template_element = downcast<HTML::HTMLTemplateElement>(node); auto& template_element = verify_cast<HTML::HTMLTemplateElement>(node);
dump_tree(template_element.content()); dump_tree(template_element.content());
} }
} }
@ -84,13 +84,13 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
if (layout_node.is_anonymous()) if (layout_node.is_anonymous())
tag_name = "(anonymous)"; tag_name = "(anonymous)";
else if (is<DOM::Element>(layout_node.dom_node())) else if (is<DOM::Element>(layout_node.dom_node()))
tag_name = downcast<DOM::Element>(*layout_node.dom_node()).local_name(); tag_name = verify_cast<DOM::Element>(*layout_node.dom_node()).local_name();
else else
tag_name = layout_node.dom_node()->node_name(); tag_name = layout_node.dom_node()->node_name();
String identifier = ""; String identifier = "";
if (layout_node.dom_node() && is<DOM::Element>(*layout_node.dom_node())) { if (layout_node.dom_node() && is<DOM::Element>(*layout_node.dom_node())) {
auto& element = downcast<DOM::Element>(*layout_node.dom_node()); auto& element = verify_cast<DOM::Element>(*layout_node.dom_node());
StringBuilder builder; StringBuilder builder;
auto id = element.attribute(HTML::AttributeNames::id); auto id = element.attribute(HTML::AttributeNames::id);
if (!id.is_empty()) { if (!id.is_empty()) {
@ -139,7 +139,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
builder.appendff(" @{:p}", &layout_node); builder.appendff(" @{:p}", &layout_node);
builder.append("\n"); builder.append("\n");
} else { } else {
auto& box = downcast<Layout::Box>(layout_node); auto& box = verify_cast<Layout::Box>(layout_node);
builder.appendff("{}{}{} <{}{}{}{}> ", builder.appendff("{}{}{} <{}{}{}{}> ",
box_color_on, box_color_on,
box.class_name().substring_view(13), box.class_name().substring_view(13),
@ -231,13 +231,13 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
} }
} }
if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && downcast<DOM::Element>(layout_node.dom_node())->specified_css_values()) { if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && verify_cast<DOM::Element>(layout_node.dom_node())->specified_css_values()) {
struct NameAndValue { struct NameAndValue {
String name; String name;
String value; String value;
}; };
Vector<NameAndValue> properties; Vector<NameAndValue> properties;
downcast<DOM::Element>(*layout_node.dom_node()).specified_css_values()->for_each_property([&](auto property_id, auto& value) { verify_cast<DOM::Element>(*layout_node.dom_node()).specified_css_values()->for_each_property([&](auto property_id, auto& value) {
properties.append({ CSS::string_from_property_id(property_id), value.to_string() }); properties.append({ CSS::string_from_property_id(property_id), value.to_string() });
}); });
quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; }); quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; });
@ -417,10 +417,10 @@ void dump_rule(StringBuilder& builder, const CSS::CSSRule& rule)
builder.appendff("{}:\n", rule.class_name()); builder.appendff("{}:\n", rule.class_name());
switch (rule.type()) { switch (rule.type()) {
case CSS::CSSRule::Type::Style: case CSS::CSSRule::Type::Style:
dump_style_rule(builder, downcast<const CSS::CSSStyleRule>(rule)); dump_style_rule(builder, verify_cast<const CSS::CSSStyleRule>(rule));
break; break;
case CSS::CSSRule::Type::Import: case CSS::CSSRule::Type::Import:
dump_import_rule(builder, downcast<const CSS::CSSImportRule>(rule)); dump_import_rule(builder, verify_cast<const CSS::CSSImportRule>(rule));
break; break;
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();

View file

@ -110,7 +110,7 @@ String HTMLElement::inner_text()
Function<void(const Layout::Node&)> recurse = [&](auto& node) { Function<void(const Layout::Node&)> recurse = [&](auto& node) {
for (auto* child = node.first_child(); child; child = child->next_sibling()) { for (auto* child = node.first_child(); child; child = child->next_sibling()) {
if (is<Layout::TextNode>(child)) if (is<Layout::TextNode>(child))
builder.append(downcast<Layout::TextNode>(*child).text_for_rendering()); builder.append(verify_cast<Layout::TextNode>(*child).text_for_rendering());
if (is<Layout::BreakNode>(child)) if (is<Layout::BreakNode>(child))
builder.append('\n'); builder.append('\n');
recurse(*child); recurse(*child);

View file

@ -98,7 +98,7 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi
Vector<URLQueryParam> parameters; Vector<URLQueryParam> parameters;
for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& node) { for_each_in_inclusive_subtree_of_type<HTMLInputElement>([&](auto& node) {
auto& input = downcast<HTMLInputElement>(node); auto& input = verify_cast<HTMLInputElement>(node);
if (!input.name().is_null() && (input.type() != "submit" || &input == submitter)) if (!input.name().is_null() && (input.type() != "submit" || &input == submitter))
parameters.append({ input.name(), input.value() }); parameters.append({ input.name(), input.value() });
return IterationDecision::Continue; return IterationDecision::Continue;

View file

@ -30,7 +30,7 @@ void HTMLStyleElement::children_changed()
StringBuilder builder; StringBuilder builder;
for_each_child([&](auto& child) { for_each_child([&](auto& child) {
if (is<DOM::Text>(child)) if (is<DOM::Text>(child))
builder.append(downcast<DOM::Text>(child).text_content()); builder.append(verify_cast<DOM::Text>(child).text_content());
}); });
m_css_loader.load_from_text(builder.to_string()); m_css_loader.load_from_text(builder.to_string());

View file

@ -84,7 +84,7 @@ RefPtr<HTMLTableSectionElement> HTMLTableElement::t_head()
{ {
for (auto* child = first_child(); child; child = child->next_sibling()) { for (auto* child = first_child(); child; child = child->next_sibling()) {
if (is<HTMLTableSectionElement>(*child)) { if (is<HTMLTableSectionElement>(*child)) {
auto table_section_element = &downcast<HTMLTableSectionElement>(*child); auto table_section_element = &verify_cast<HTMLTableSectionElement>(*child);
if (table_section_element->tag_name() == TagNames::thead) if (table_section_element->tag_name() == TagNames::thead)
return table_section_element; return table_section_element;
} }
@ -110,7 +110,7 @@ DOM::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement& the
if (is<HTMLTableCaptionElement>(*child)) if (is<HTMLTableCaptionElement>(*child))
continue; continue;
if (is<HTMLTableColElement>(*child)) { if (is<HTMLTableColElement>(*child)) {
auto table_col_element = &downcast<HTMLTableColElement>(*child); auto table_col_element = &verify_cast<HTMLTableColElement>(*child);
if (table_col_element->tag_name() == TagNames::colgroup) if (table_col_element->tag_name() == TagNames::colgroup)
continue; continue;
} }
@ -141,7 +141,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head()
if (is<HTMLTableCaptionElement>(*child)) if (is<HTMLTableCaptionElement>(*child))
continue; continue;
if (is<HTMLTableColElement>(*child)) { if (is<HTMLTableColElement>(*child)) {
auto table_col_element = &downcast<HTMLTableColElement>(*child); auto table_col_element = &verify_cast<HTMLTableColElement>(*child);
if (table_col_element->tag_name() == TagNames::colgroup) if (table_col_element->tag_name() == TagNames::colgroup)
continue; continue;
} }
@ -168,7 +168,7 @@ RefPtr<HTMLTableSectionElement> HTMLTableElement::t_foot()
{ {
for (auto* child = first_child(); child; child = child->next_sibling()) { for (auto* child = first_child(); child; child = child->next_sibling()) {
if (is<HTMLTableSectionElement>(*child)) { if (is<HTMLTableSectionElement>(*child)) {
auto table_section_element = &downcast<HTMLTableSectionElement>(*child); auto table_section_element = &verify_cast<HTMLTableSectionElement>(*child);
if (table_section_element->tag_name() == TagNames::tfoot) if (table_section_element->tag_name() == TagNames::tfoot)
return table_section_element; return table_section_element;
} }
@ -228,7 +228,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body()
if (!is<HTMLElement>(*child)) if (!is<HTMLElement>(*child))
continue; continue;
if (is<HTMLTableSectionElement>(*child)) { if (is<HTMLTableSectionElement>(*child)) {
auto table_section_element = &downcast<HTMLTableSectionElement>(*child); auto table_section_element = &verify_cast<HTMLTableSectionElement>(*child);
if (table_section_element->tag_name() == TagNames::tbody) { if (table_section_element->tag_name() == TagNames::tbody) {
// We have found an element which is a <tbody> we'll insert after this // We have found an element which is a <tbody> we'll insert after this
child_to_append_after = child->next_sibling(); child_to_append_after = child->next_sibling();

View file

@ -411,7 +411,7 @@ HTMLDocumentParser::AdjustedInsertionLocation HTMLDocumentParser::find_appropria
auto last_table = m_stack_of_open_elements.last_element_with_tag_name(HTML::TagNames::table); auto last_table = m_stack_of_open_elements.last_element_with_tag_name(HTML::TagNames::table);
if (last_template.element && (!last_table.element || last_template.index > last_table.index)) { if (last_template.element && (!last_table.element || last_template.index > last_table.index)) {
// This returns the template content, so no need to check the parent is a template. // This returns the template content, so no need to check the parent is a template.
return { downcast<HTMLTemplateElement>(last_template.element)->content(), nullptr }; return { verify_cast<HTMLTemplateElement>(last_template.element)->content(), nullptr };
} }
if (!last_table.element) { if (!last_table.element) {
VERIFY(m_parsing_fragment); VERIFY(m_parsing_fragment);
@ -428,7 +428,7 @@ HTMLDocumentParser::AdjustedInsertionLocation HTMLDocumentParser::find_appropria
} }
if (is<HTMLTemplateElement>(*adjusted_insertion_location.parent)) if (is<HTMLTemplateElement>(*adjusted_insertion_location.parent))
return { downcast<HTMLTemplateElement>(*adjusted_insertion_location.parent).content(), nullptr }; return { verify_cast<HTMLTemplateElement>(*adjusted_insertion_location.parent).content(), nullptr };
return adjusted_insertion_location; return adjusted_insertion_location;
} }
@ -497,7 +497,7 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token)
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::head) { if (token.is_start_tag() && token.tag_name() == HTML::TagNames::head) {
auto element = insert_html_element(token); auto element = insert_html_element(token);
m_head_element = downcast<HTMLHeadElement>(*element); m_head_element = verify_cast<HTMLHeadElement>(*element);
m_insertion_mode = InsertionMode::InHead; m_insertion_mode = InsertionMode::InHead;
return; return;
} }
@ -512,7 +512,7 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token)
} }
AnythingElse: AnythingElse:
m_head_element = downcast<HTMLHeadElement>(*insert_html_element(HTMLToken::make_start_tag(HTML::TagNames::head))); m_head_element = verify_cast<HTMLHeadElement>(*insert_html_element(HTMLToken::make_start_tag(HTML::TagNames::head)));
m_insertion_mode = InsertionMode::InHead; m_insertion_mode = InsertionMode::InHead;
process_using_the_rules_for(InsertionMode::InHead, token); process_using_the_rules_for(InsertionMode::InHead, token);
return; return;
@ -583,7 +583,7 @@ void HTMLDocumentParser::handle_in_head(HTMLToken& token)
if (token.is_start_tag() && token.tag_name() == HTML::TagNames::script) { if (token.is_start_tag() && token.tag_name() == HTML::TagNames::script) {
auto adjusted_insertion_location = find_appropriate_place_for_inserting_node(); auto adjusted_insertion_location = find_appropriate_place_for_inserting_node();
auto element = create_element_for(token, Namespace::HTML); auto element = create_element_for(token, Namespace::HTML);
auto& script_element = downcast<HTMLScriptElement>(*element); auto& script_element = verify_cast<HTMLScriptElement>(*element);
script_element.set_parser_document({}, document()); script_element.set_parser_document({}, document());
script_element.set_non_blocking({}, false); script_element.set_non_blocking({}, false);
@ -706,7 +706,7 @@ DOM::Text* HTMLDocumentParser::find_character_insertion_node()
if (adjusted_insertion_location.parent->is_document()) if (adjusted_insertion_location.parent->is_document())
return nullptr; return nullptr;
if (adjusted_insertion_location.parent->last_child() && adjusted_insertion_location.parent->last_child()->is_text()) if (adjusted_insertion_location.parent->last_child() && adjusted_insertion_location.parent->last_child()->is_text())
return downcast<DOM::Text>(adjusted_insertion_location.parent->last_child()); return verify_cast<DOM::Text>(adjusted_insertion_location.parent->last_child());
auto new_text_node = adopt_ref(*new DOM::Text(document(), "")); auto new_text_node = adopt_ref(*new DOM::Text(document(), ""));
adjusted_insertion_location.parent->append_child(new_text_node); adjusted_insertion_location.parent->append_child(new_text_node);
return new_text_node; return new_text_node;
@ -1268,7 +1268,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
close_a_p_element(); close_a_p_element();
auto element = insert_html_element(token); auto element = insert_html_element(token);
if (!m_stack_of_open_elements.contains(HTML::TagNames::template_)) if (!m_stack_of_open_elements.contains(HTML::TagNames::template_))
m_form_element = downcast<HTMLFormElement>(*element); m_form_element = verify_cast<HTMLFormElement>(*element);
return; return;
} }
@ -1877,7 +1877,7 @@ void HTMLDocumentParser::handle_text(HTMLToken& token)
if (token.is_end_of_file()) { if (token.is_end_of_file()) {
log_parse_error(); log_parse_error();
if (current_node().local_name() == HTML::TagNames::script) if (current_node().local_name() == HTML::TagNames::script)
downcast<HTMLScriptElement>(current_node()).set_already_started({}, true); verify_cast<HTMLScriptElement>(current_node()).set_already_started({}, true);
m_stack_of_open_elements.pop(); m_stack_of_open_elements.pop();
m_insertion_mode = m_original_insertion_mode; m_insertion_mode = m_original_insertion_mode;
process_using_the_rules_for(m_insertion_mode, token); process_using_the_rules_for(m_insertion_mode, token);
@ -1887,7 +1887,7 @@ void HTMLDocumentParser::handle_text(HTMLToken& token)
// Make sure the <script> element has up-to-date text content before preparing the script. // Make sure the <script> element has up-to-date text content before preparing the script.
flush_character_insertions(); flush_character_insertions();
NonnullRefPtr<HTMLScriptElement> script = downcast<HTMLScriptElement>(current_node()); NonnullRefPtr<HTMLScriptElement> script = verify_cast<HTMLScriptElement>(current_node());
m_stack_of_open_elements.pop(); m_stack_of_open_elements.pop();
m_insertion_mode = m_original_insertion_mode; m_insertion_mode = m_original_insertion_mode;
// FIXME: Handle tokenizer insertion point stuff here. // FIXME: Handle tokenizer insertion point stuff here.
@ -2289,7 +2289,7 @@ void HTMLDocumentParser::handle_in_table(HTMLToken& token)
return; return;
} }
m_form_element = downcast<HTMLFormElement>(*insert_html_element(token)); m_form_element = verify_cast<HTMLFormElement>(*insert_html_element(token));
// FIXME: See previous FIXME, as this is the same situation but for form. // FIXME: See previous FIXME, as this is the same situation but for form.
m_stack_of_open_elements.pop(); m_stack_of_open_elements.pop();
@ -3025,7 +3025,7 @@ NonnullRefPtrVector<DOM::Node> HTMLDocumentParser::parse_html_fragment(DOM::Elem
for (auto* form_candidate = &context_element; form_candidate; form_candidate = form_candidate->parent_element()) { for (auto* form_candidate = &context_element; form_candidate; form_candidate = form_candidate->parent_element()) {
if (is<HTMLFormElement>(*form_candidate)) { if (is<HTMLFormElement>(*form_candidate)) {
parser.m_form_element = downcast<HTMLFormElement>(*form_candidate); parser.m_form_element = verify_cast<HTMLFormElement>(*form_candidate);
break; break;
} }
} }

View file

@ -81,7 +81,7 @@ void InProcessWebView::select_all()
int last_layout_node_index_in_node = 0; int last_layout_node_index_in_node = 0;
if (is<Layout::TextNode>(*last_layout_node)) if (is<Layout::TextNode>(*last_layout_node))
last_layout_node_index_in_node = downcast<Layout::TextNode>(*last_layout_node).text_for_rendering().length() - 1; last_layout_node_index_in_node = verify_cast<Layout::TextNode>(*last_layout_node).text_for_rendering().length() - 1;
layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } }); layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } });
update(); update();

View file

@ -88,11 +88,11 @@ HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type
HitTestResult last_good_candidate; HitTestResult last_good_candidate;
for (auto& line_box : m_line_boxes) { for (auto& line_box : m_line_boxes) {
for (auto& fragment : line_box.fragments()) { for (auto& fragment : line_box.fragments()) {
if (is<Box>(fragment.layout_node()) && downcast<Box>(fragment.layout_node()).stacking_context()) if (is<Box>(fragment.layout_node()) && verify_cast<Box>(fragment.layout_node()).stacking_context())
continue; continue;
if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) { if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) {
if (is<BlockBox>(fragment.layout_node())) if (is<BlockBox>(fragment.layout_node()))
return downcast<BlockBox>(fragment.layout_node()).hit_test(position, type); return verify_cast<BlockBox>(fragment.layout_node()).hit_test(position, type);
return { fragment.layout_node(), fragment.text_index_at(position.x()) }; return { fragment.layout_node(), fragment.text_index_at(position.x()) };
} }
if (fragment.absolute_rect().top() <= position.y()) if (fragment.absolute_rect().top() <= position.y())

View file

@ -21,10 +21,10 @@ public:
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override; virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
BlockBox* previous_sibling() { return downcast<BlockBox>(Node::previous_sibling()); } BlockBox* previous_sibling() { return verify_cast<BlockBox>(Node::previous_sibling()); }
const BlockBox* previous_sibling() const { return downcast<BlockBox>(Node::previous_sibling()); } const BlockBox* previous_sibling() const { return verify_cast<BlockBox>(Node::previous_sibling()); }
BlockBox* next_sibling() { return downcast<BlockBox>(Node::next_sibling()); } BlockBox* next_sibling() { return verify_cast<BlockBox>(Node::next_sibling()); }
const BlockBox* next_sibling() const { return downcast<BlockBox>(Node::next_sibling()); } const BlockBox* next_sibling() const { return verify_cast<BlockBox>(Node::next_sibling()); }
template<typename Callback> template<typename Callback>
void for_each_fragment(Callback); void for_each_fragment(Callback);

View file

@ -72,7 +72,7 @@ void BlockFormattingContext::compute_width(Box& box)
if (is<ReplacedBox>(box)) { if (is<ReplacedBox>(box)) {
// FIXME: This should not be done *by* ReplacedBox // FIXME: This should not be done *by* ReplacedBox
auto& replaced = downcast<ReplacedBox>(box); auto& replaced = verify_cast<ReplacedBox>(box);
replaced.prepare_for_replaced_layout(); replaced.prepare_for_replaced_layout();
compute_width_for_block_level_replaced_element_in_normal_flow(replaced); compute_width_for_block_level_replaced_element_in_normal_flow(replaced);
return; return;
@ -304,7 +304,7 @@ float BlockFormattingContext::compute_theoretical_height(const Box& box)
// Then work out what the height is, based on box type and CSS properties. // Then work out what the height is, based on box type and CSS properties.
float height = 0; float height = 0;
if (is<ReplacedBox>(box)) { if (is<ReplacedBox>(box)) {
height = compute_height_for_replaced_element(downcast<ReplacedBox>(box)); height = compute_height_for_replaced_element(verify_cast<ReplacedBox>(box));
} else { } else {
if (box.computed_values().height().is_undefined_or_auto() if (box.computed_values().height().is_undefined_or_auto()
|| (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute())) { || (computed_values.height().is_percentage() && !containing_block.computed_values().height().is_absolute())) {
@ -410,10 +410,10 @@ void BlockFormattingContext::layout_block_level_children(Box& box, LayoutMode la
// FIXME: This should be factored differently. It's uncool that we mutate the tree *during* layout! // FIXME: This should be factored differently. It's uncool that we mutate the tree *during* layout!
// Instead, we should generate the marker box during the tree build. // Instead, we should generate the marker box during the tree build.
if (is<ListItemBox>(child_box)) if (is<ListItemBox>(child_box))
downcast<ListItemBox>(child_box).layout_marker(); verify_cast<ListItemBox>(child_box).layout_marker();
content_height = max(content_height, child_box.effective_offset().y() + child_box.height() + child_box.box_model().margin_box().bottom); content_height = max(content_height, child_box.effective_offset().y() + child_box.height() + child_box.box_model().margin_box().bottom);
content_width = max(content_width, downcast<Box>(child_box).width()); content_width = max(content_width, verify_cast<Box>(child_box).width());
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
@ -526,7 +526,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
{ {
auto viewport_rect = context_box().browsing_context().viewport_rect(); auto viewport_rect = context_box().browsing_context().viewport_rect();
auto& icb = downcast<Layout::InitialContainingBlockBox>(context_box()); auto& icb = verify_cast<Layout::InitialContainingBlockBox>(context_box());
icb.build_stacking_context_tree(); icb.build_stacking_context_tree();
icb.set_width(viewport_rect.width()); icb.set_width(viewport_rect.width());
@ -551,7 +551,7 @@ static Gfx::FloatRect rect_in_coordinate_space(const Box& box, const Box& contex
Gfx::FloatRect rect = box.margin_box_as_relative_rect(); Gfx::FloatRect rect = box.margin_box_as_relative_rect();
for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) { for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) {
if (is<Box>(*ancestor)) { if (is<Box>(*ancestor)) {
auto offset = downcast<Box>(*ancestor).effective_offset(); auto offset = verify_cast<Box>(*ancestor).effective_offset();
rect.translate_by(offset); rect.translate_by(offset);
} }
if (ancestor == &context_box) if (ancestor == &context_box)

View file

@ -50,7 +50,7 @@ void Box::paint(PaintContext& context, PaintPhase phase)
context.painter().draw_rect(enclosing_int_rect(content_rect), Color::Magenta); context.painter().draw_rect(enclosing_int_rect(content_rect), Color::Magenta);
} }
if (phase == PaintPhase::FocusOutline && dom_node() && dom_node()->is_element() && downcast<DOM::Element>(*dom_node()).is_focused()) { if (phase == PaintPhase::FocusOutline && dom_node() && dom_node()->is_element() && verify_cast<DOM::Element>(*dom_node()).is_focused()) {
context.painter().draw_rect(enclosing_int_rect(absolute_rect()), context.palette().focus_outline()); context.painter().draw_rect(enclosing_int_rect(absolute_rect()), context.palette().focus_outline());
} }
} }
@ -347,7 +347,7 @@ StackingContext* Box::enclosing_stacking_context()
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
if (!is<Box>(ancestor)) if (!is<Box>(ancestor))
continue; continue;
auto& ancestor_box = downcast<Box>(*ancestor); auto& ancestor_box = verify_cast<Box>(*ancestor);
if (!ancestor_box.establishes_stacking_context()) if (!ancestor_box.establishes_stacking_context())
continue; continue;
VERIFY(ancestor_box.stacking_context()); VERIFY(ancestor_box.stacking_context());

View file

@ -16,7 +16,7 @@ public:
BreakNode(DOM::Document&, HTML::HTMLBRElement&); BreakNode(DOM::Document&, HTML::HTMLBRElement&);
virtual ~BreakNode() override; virtual ~BreakNode() override;
const HTML::HTMLBRElement& dom_node() const { return downcast<HTML::HTMLBRElement>(*Node::dom_node()); } const HTML::HTMLBRElement& dom_node() const { return verify_cast<HTML::HTMLBRElement>(*Node::dom_node()); }
private: private:
virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override; virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;

View file

@ -254,7 +254,7 @@ float FormattingContext::tentative_width_for_replaced_element(const ReplacedBox&
void FormattingContext::compute_width_for_absolutely_positioned_element(Box& box) void FormattingContext::compute_width_for_absolutely_positioned_element(Box& box)
{ {
if (is<ReplacedBox>(box)) if (is<ReplacedBox>(box))
compute_width_for_absolutely_positioned_replaced_element(downcast<ReplacedBox>(box)); compute_width_for_absolutely_positioned_replaced_element(verify_cast<ReplacedBox>(box));
else else
compute_width_for_absolutely_positioned_non_replaced_element(box); compute_width_for_absolutely_positioned_non_replaced_element(box);
} }
@ -262,7 +262,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_element(Box& box
void FormattingContext::compute_height_for_absolutely_positioned_element(Box& box) void FormattingContext::compute_height_for_absolutely_positioned_element(Box& box)
{ {
if (is<ReplacedBox>(box)) if (is<ReplacedBox>(box))
compute_height_for_absolutely_positioned_replaced_element(downcast<ReplacedBox>(box)); compute_height_for_absolutely_positioned_replaced_element(verify_cast<ReplacedBox>(box));
else else
compute_height_for_absolutely_positioned_non_replaced_element(box); compute_height_for_absolutely_positioned_non_replaced_element(box);
} }

View file

@ -19,8 +19,8 @@ public:
virtual void paint(PaintContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
virtual void prepare_for_replaced_layout() override; virtual void prepare_for_replaced_layout() override;
const HTML::HTMLIFrameElement& dom_node() const { return downcast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); } const HTML::HTMLIFrameElement& dom_node() const { return verify_cast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); }
HTML::HTMLIFrameElement& dom_node() { return downcast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); } HTML::HTMLIFrameElement& dom_node() { return verify_cast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); }
private: private:
virtual void did_set_rect() override; virtual void did_set_rect() override;

View file

@ -60,7 +60,7 @@ void ImageBox::prepare_for_replaced_layout()
} }
if (renders_as_alt_text()) { if (renders_as_alt_text()) {
auto& image_element = downcast<HTML::HTMLImageElement>(dom_node()); auto& image_element = verify_cast<HTML::HTMLImageElement>(dom_node());
auto& font = Gfx::FontDatabase::default_font(); auto& font = Gfx::FontDatabase::default_font();
auto alt = image_element.alt(); auto alt = image_element.alt();
if (alt.is_empty()) if (alt.is_empty())
@ -88,7 +88,7 @@ void ImageBox::paint(PaintContext& context, PaintPhase phase)
if (phase == PaintPhase::Foreground) { if (phase == PaintPhase::Foreground) {
if (renders_as_alt_text()) { if (renders_as_alt_text()) {
auto& image_element = downcast<HTML::HTMLImageElement>(dom_node()); auto& image_element = verify_cast<HTML::HTMLImageElement>(dom_node());
context.painter().set_font(Gfx::FontDatabase::default_font()); context.painter().set_font(Gfx::FontDatabase::default_font());
Gfx::StylePainter::paint_frame(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), Gfx::FrameShape::Container, Gfx::FrameShadow::Sunken, 2); Gfx::StylePainter::paint_frame(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), Gfx::FrameShape::Container, Gfx::FrameShadow::Sunken, 2);
auto alt = image_element.alt(); auto alt = image_element.alt();

View file

@ -75,7 +75,7 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
containing_block().for_each_child([&](auto& child) { containing_block().for_each_child([&](auto& child) {
VERIFY(child.is_inline()); VERIFY(child.is_inline());
if (is<Box>(child) && child.is_absolutely_positioned()) { if (is<Box>(child) && child.is_absolutely_positioned()) {
layout_absolutely_positioned_element(downcast<Box>(child)); layout_absolutely_positioned_element(verify_cast<Box>(child));
return; return;
} }
@ -181,14 +181,14 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_mode) void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_mode)
{ {
if (is<ReplacedBox>(box)) { if (is<ReplacedBox>(box)) {
auto& replaced = downcast<ReplacedBox>(box); auto& replaced = verify_cast<ReplacedBox>(box);
replaced.set_width(compute_width_for_replaced_element(replaced)); replaced.set_width(compute_width_for_replaced_element(replaced));
replaced.set_height(compute_height_for_replaced_element(replaced)); replaced.set_height(compute_height_for_replaced_element(replaced));
return; return;
} }
if (box.is_inline_block()) { if (box.is_inline_block()) {
auto& inline_block = const_cast<BlockBox&>(downcast<BlockBox>(box)); auto& inline_block = const_cast<BlockBox&>(verify_cast<BlockBox>(box));
if (inline_block.computed_values().width().is_undefined_or_auto()) { if (inline_block.computed_values().width().is_undefined_or_auto()) {
auto result = calculate_shrink_to_fit_widths(inline_block); auto result = calculate_shrink_to_fit_widths(inline_block);

View file

@ -27,7 +27,7 @@ void LineBox::add_fragment(Node& layout_node, int start, int length, float width
m_width += width; m_width += width;
if (is<Box>(layout_node)) if (is<Box>(layout_node))
downcast<Box>(layout_node).set_containing_line_box_fragment(m_fragments.last()); verify_cast<Box>(layout_node).set_containing_line_box_fragment(m_fragments.last());
} }
void LineBox::trim_trailing_whitespace() void LineBox::trim_trailing_whitespace()

View file

@ -41,7 +41,7 @@ StringView LineBoxFragment::text() const
{ {
if (!is<TextNode>(layout_node())) if (!is<TextNode>(layout_node()))
return {}; return {};
return downcast<TextNode>(layout_node()).text_for_rendering().substring_view(m_start, m_length); return verify_cast<TextNode>(layout_node()).text_for_rendering().substring_view(m_start, m_length);
} }
const Gfx::FloatRect LineBoxFragment::absolute_rect() const const Gfx::FloatRect LineBoxFragment::absolute_rect() const
@ -56,7 +56,7 @@ int LineBoxFragment::text_index_at(float x) const
{ {
if (!is<TextNode>(layout_node())) if (!is<TextNode>(layout_node()))
return 0; return 0;
auto& layout_text = downcast<TextNode>(layout_node()); auto& layout_text = verify_cast<TextNode>(layout_node());
auto& font = layout_text.font(); auto& font = layout_text.font();
Utf8View view(text()); Utf8View view(text());

View file

@ -150,7 +150,7 @@ void Node::set_needs_display()
Gfx::FloatPoint Node::box_type_agnostic_position() const Gfx::FloatPoint Node::box_type_agnostic_position() const
{ {
if (is<Box>(*this)) if (is<Box>(*this))
return downcast<Box>(*this).absolute_position(); return verify_cast<Box>(*this).absolute_position();
VERIFY(is_inline()); VERIFY(is_inline());
Gfx::FloatPoint position; Gfx::FloatPoint position;
if (auto* block = containing_block()) { if (auto* block = containing_block()) {

View file

@ -158,13 +158,13 @@ public:
void for_each_child_in_paint_order(Callback callback) const void for_each_child_in_paint_order(Callback callback) const
{ {
for_each_child([&](auto& child) { for_each_child([&](auto& child) {
if (is<Box>(child) && downcast<Box>(child).stacking_context()) if (is<Box>(child) && verify_cast<Box>(child).stacking_context())
return; return;
if (!child.is_positioned()) if (!child.is_positioned())
callback(child); callback(child);
}); });
for_each_child([&](auto& child) { for_each_child([&](auto& child) {
if (is<Box>(child) && downcast<Box>(child).stacking_context()) if (is<Box>(child) && verify_cast<Box>(child).stacking_context())
return; return;
if (child.is_positioned()) if (child.is_positioned())
callback(child); callback(child);

View file

@ -16,8 +16,8 @@ public:
ReplacedBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); ReplacedBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~ReplacedBox() override; virtual ~ReplacedBox() override;
const DOM::Element& dom_node() const { return downcast<DOM::Element>(*Node::dom_node()); } const DOM::Element& dom_node() const { return verify_cast<DOM::Element>(*Node::dom_node()); }
DOM::Element& dom_node() { return downcast<DOM::Element>(*Node::dom_node()); } DOM::Element& dom_node() { return verify_cast<DOM::Element>(*Node::dom_node()); }
bool has_intrinsic_width() const { return m_has_intrinsic_width; } bool has_intrinsic_width() const { return m_has_intrinsic_width; }
bool has_intrinsic_height() const { return m_has_intrinsic_height; } bool has_intrinsic_height() const { return m_has_intrinsic_height; }

View file

@ -19,7 +19,7 @@ void SVGGraphicsBox::before_children_paint(PaintContext& context, PaintPhase pha
if (phase != PaintPhase::Foreground) if (phase != PaintPhase::Foreground)
return; return;
auto& graphics_element = downcast<SVG::SVGGraphicsElement>(dom_node()); auto& graphics_element = verify_cast<SVG::SVGGraphicsElement>(dom_node());
if (graphics_element.fill_color().has_value()) if (graphics_element.fill_color().has_value())
context.svg_context().set_fill_color(graphics_element.fill_color().value()); context.svg_context().set_fill_color(graphics_element.fill_color().value());

View file

@ -16,7 +16,7 @@ public:
SVGPathBox(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr<CSS::StyleProperties>); SVGPathBox(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~SVGPathBox() override = default; virtual ~SVGPathBox() override = default;
SVG::SVGPathElement& dom_node() { return downcast<SVG::SVGPathElement>(SVGGraphicsBox::dom_node()); } SVG::SVGPathElement& dom_node() { return verify_cast<SVG::SVGPathElement>(SVGGraphicsBox::dom_node()); }
virtual void prepare_for_replaced_layout() override; virtual void prepare_for_replaced_layout() override;
virtual void paint(PaintContext& context, PaintPhase phase) override; virtual void paint(PaintContext& context, PaintPhase phase) override;

View file

@ -16,7 +16,7 @@ public:
SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>); SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~SVGSVGBox() override = default; virtual ~SVGSVGBox() override = default;
SVG::SVGSVGElement& dom_node() { return downcast<SVG::SVGSVGElement>(SVGGraphicsBox::dom_node()); } SVG::SVGSVGElement& dom_node() { return verify_cast<SVG::SVGSVGElement>(SVGGraphicsBox::dom_node()); }
virtual void prepare_for_replaced_layout() override; virtual void prepare_for_replaced_layout() override;

View file

@ -28,7 +28,7 @@ size_t TableCellBox::colspan() const
{ {
if (!dom_node()) if (!dom_node())
return 1; return 1;
return downcast<DOM::Element>(*dom_node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1); return verify_cast<DOM::Element>(*dom_node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
} }
float TableCellBox::width_of_logical_containing_block() const float TableCellBox::width_of_logical_containing_block() const

View file

@ -261,7 +261,7 @@ void TextNode::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint& positi
{ {
if (!parent() || !is<Label>(*parent())) if (!parent() || !is<Label>(*parent()))
return; return;
downcast<Label>(*parent()).handle_mousedown_on_label({}, position, button); verify_cast<Label>(*parent()).handle_mousedown_on_label({}, position, button);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(this); browsing_context().event_handler().set_mouse_event_tracking_layout_node(this);
} }
@ -273,7 +273,7 @@ void TextNode::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position
// NOTE: Changing the state of the DOM node may run arbitrary JS, which could disappear this node. // NOTE: Changing the state of the DOM node may run arbitrary JS, which could disappear this node.
NonnullRefPtr protect = *this; NonnullRefPtr protect = *this;
downcast<Label>(*parent()).handle_mouseup_on_label({}, position, button); verify_cast<Label>(*parent()).handle_mouseup_on_label({}, position, button);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr); browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr);
} }
@ -281,7 +281,7 @@ void TextNode::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& positi
{ {
if (!parent() || !is<Label>(*parent())) if (!parent() || !is<Label>(*parent()))
return; return;
downcast<Label>(*parent()).handle_mousemove_on_label({}, position, button); verify_cast<Label>(*parent()).handle_mousemove_on_label({}, position, button);
} }
TextNode::ChunkIterator::ChunkIterator(StringView const& text, LayoutMode layout_mode, bool wrap_lines, bool wrap_breaks) TextNode::ChunkIterator::ChunkIterator(StringView const& text, LayoutMode layout_mode, bool wrap_lines, bool wrap_breaks)

View file

@ -103,13 +103,13 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node)
} }
} }
auto* shadow_root = is<DOM::Element>(dom_node) ? downcast<DOM::Element>(dom_node).shadow_root() : nullptr; auto* shadow_root = is<DOM::Element>(dom_node) ? verify_cast<DOM::Element>(dom_node).shadow_root() : nullptr;
if ((dom_node.has_children() || shadow_root) && layout_node->can_have_children()) { if ((dom_node.has_children() || shadow_root) && layout_node->can_have_children()) {
push_parent(downcast<NodeWithStyle>(*layout_node)); push_parent(verify_cast<NodeWithStyle>(*layout_node));
if (shadow_root) if (shadow_root)
create_layout_tree(*shadow_root); create_layout_tree(*shadow_root);
downcast<DOM::ParentNode>(dom_node).for_each_child([&](auto& dom_child) { verify_cast<DOM::ParentNode>(dom_node).for_each_child([&](auto& dom_child) {
create_layout_tree(dom_child); create_layout_tree(dom_child);
}); });
pop_parent(); pop_parent();
@ -121,7 +121,7 @@ RefPtr<Node> TreeBuilder::build(DOM::Node& dom_node)
if (dom_node.parent()) { if (dom_node.parent()) {
// We're building a partial layout tree, so start by building up the stack of parent layout nodes. // We're building a partial layout tree, so start by building up the stack of parent layout nodes.
for (auto* ancestor = dom_node.parent()->layout_node(); ancestor; ancestor = ancestor->parent()) for (auto* ancestor = dom_node.parent()->layout_node(); ancestor; ancestor = ancestor->parent())
m_parent_stack.prepend(downcast<NodeWithStyle>(ancestor)); m_parent_stack.prepend(verify_cast<NodeWithStyle>(ancestor));
} }
create_layout_tree(dom_node); create_layout_tree(dom_node);

View file

@ -108,7 +108,7 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole
} }
if (role == GUI::ModelRole::Display) { if (role == GUI::ModelRole::Display) {
if (is<Layout::TextNode>(node)) if (is<Layout::TextNode>(node))
return String::formatted("TextNode: {}", with_whitespace_collapsed(downcast<Layout::TextNode>(node).text_for_rendering())); return String::formatted("TextNode: {}", with_whitespace_collapsed(verify_cast<Layout::TextNode>(node).text_for_rendering()));
StringBuilder builder; StringBuilder builder;
builder.append(node.class_name()); builder.append(node.class_name());
builder.append(' '); builder.append(' ');
@ -117,7 +117,7 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole
} else if (!node.dom_node()->is_element()) { } else if (!node.dom_node()->is_element()) {
builder.append(node.dom_node()->node_name()); builder.append(node.dom_node()->node_name());
} else { } else {
auto& element = downcast<DOM::Element>(*node.dom_node()); auto& element = verify_cast<DOM::Element>(*node.dom_node());
builder.append('<'); builder.append('<');
builder.append(element.local_name()); builder.append(element.local_name());
element.for_each_attribute([&](auto& name, auto& value) { element.for_each_attribute([&](auto& name, auto& value) {

View file

@ -277,7 +277,7 @@ void FrameLoader::resource_did_load()
if (auto* host_element = browsing_context().host_element()) { if (auto* host_element = browsing_context().host_element()) {
// FIXME: Perhaps in the future we'll have a better common base class for <frame> and <iframe> // FIXME: Perhaps in the future we'll have a better common base class for <frame> and <iframe>
VERIFY(is<HTML::HTMLIFrameElement>(*host_element)); VERIFY(is<HTML::HTMLIFrameElement>(*host_element));
downcast<HTML::HTMLIFrameElement>(*host_element).nested_browsing_context_did_load({}); verify_cast<HTML::HTMLIFrameElement>(*host_element).nested_browsing_context_did_load({});
} }
if (auto* page = browsing_context().page()) if (auto* page = browsing_context().page())

View file

@ -165,7 +165,7 @@ void BrowsingContext::scroll_to_anchor(const String& fragment)
auto candidates = document()->get_elements_by_name(fragment); auto candidates = document()->get_elements_by_name(fragment);
for (auto& candidate : candidates->collect_matching_elements()) { for (auto& candidate : candidates->collect_matching_elements()) {
if (is<HTML::HTMLAnchorElement>(*candidate)) { if (is<HTML::HTMLAnchorElement>(*candidate)) {
element = downcast<HTML::HTMLAnchorElement>(*candidate); element = verify_cast<HTML::HTMLAnchorElement>(*candidate);
break; break;
} }
} }
@ -181,7 +181,7 @@ void BrowsingContext::scroll_to_anchor(const String& fragment)
Gfx::FloatRect float_rect { layout_node.box_type_agnostic_position(), { (float)viewport_rect().width(), (float)viewport_rect().height() } }; Gfx::FloatRect float_rect { layout_node.box_type_agnostic_position(), { (float)viewport_rect().width(), (float)viewport_rect().height() } };
if (is<Layout::Box>(layout_node)) { if (is<Layout::Box>(layout_node)) {
auto& layout_box = downcast<Layout::Box>(layout_node); auto& layout_box = verify_cast<Layout::Box>(layout_node);
auto padding_box = layout_box.box_model().padding_box(); auto padding_box = layout_box.box_model().padding_box();
float_rect.translate_by(-padding_box.left, -padding_box.top); float_rect.translate_by(-padding_box.left, -padding_box.top);
} }
@ -244,13 +244,13 @@ String BrowsingContext::selected_text() const
if (selection.start().layout_node == selection.end().layout_node) { if (selection.start().layout_node == selection.end().layout_node) {
if (!is<Layout::TextNode>(*selection.start().layout_node)) if (!is<Layout::TextNode>(*selection.start().layout_node))
return ""; return "";
return downcast<Layout::TextNode>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node); return verify_cast<Layout::TextNode>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node);
} }
// Start node // Start node
auto layout_node = selection.start().layout_node; auto layout_node = selection.start().layout_node;
if (is<Layout::TextNode>(*layout_node)) { if (is<Layout::TextNode>(*layout_node)) {
auto& text = downcast<Layout::TextNode>(*layout_node).text_for_rendering(); auto& text = verify_cast<Layout::TextNode>(*layout_node).text_for_rendering();
builder.append(text.substring(selection.start().index_in_node, text.length() - selection.start().index_in_node)); builder.append(text.substring(selection.start().index_in_node, text.length() - selection.start().index_in_node));
} }
@ -258,7 +258,7 @@ String BrowsingContext::selected_text() const
layout_node = layout_node->next_in_pre_order(); layout_node = layout_node->next_in_pre_order();
while (layout_node && layout_node != selection.end().layout_node) { while (layout_node && layout_node != selection.end().layout_node) {
if (is<Layout::TextNode>(*layout_node)) if (is<Layout::TextNode>(*layout_node))
builder.append(downcast<Layout::TextNode>(*layout_node).text_for_rendering()); builder.append(verify_cast<Layout::TextNode>(*layout_node).text_for_rendering());
else if (is<Layout::BreakNode>(*layout_node) || is<Layout::BlockBox>(*layout_node)) else if (is<Layout::BreakNode>(*layout_node) || is<Layout::BlockBox>(*layout_node))
builder.append('\n'); builder.append('\n');
@ -268,7 +268,7 @@ String BrowsingContext::selected_text() const
// End node // End node
VERIFY(layout_node == selection.end().layout_node); VERIFY(layout_node == selection.end().layout_node);
if (is<Layout::TextNode>(*layout_node)) { if (is<Layout::TextNode>(*layout_node)) {
auto& text = downcast<Layout::TextNode>(*layout_node).text_for_rendering(); auto& text = verify_cast<Layout::TextNode>(*layout_node).text_for_rendering();
builder.append(text.substring(0, selection.end().index_in_node)); builder.append(text.substring(0, selection.end().index_in_node));
} }

View file

@ -39,8 +39,8 @@ void EditEventHandler::handle_delete_character_after(const DOM::Position& cursor
// This method is quite convoluted but this is necessary to make editing feel intuitive. // This method is quite convoluted but this is necessary to make editing feel intuitive.
void EditEventHandler::handle_delete(DOM::Range& range) void EditEventHandler::handle_delete(DOM::Range& range)
{ {
auto* start = downcast<DOM::Text>(range.start_container()); auto* start = verify_cast<DOM::Text>(range.start_container());
auto* end = downcast<DOM::Text>(range.end_container()); auto* end = verify_cast<DOM::Text>(range.end_container());
if (start == end) { if (start == end) {
StringBuilder builder; StringBuilder builder;
@ -100,7 +100,7 @@ void EditEventHandler::handle_delete(DOM::Range& range)
void EditEventHandler::handle_insert(DOM::Position position, u32 code_point) void EditEventHandler::handle_insert(DOM::Position position, u32 code_point)
{ {
if (is<DOM::Text>(*position.node())) { if (is<DOM::Text>(*position.node())) {
auto& node = downcast<DOM::Text>(*position.node()); auto& node = verify_cast<DOM::Text>(*position.node());
StringBuilder builder; StringBuilder builder;
builder.append(node.data().substring_view(0, position.offset())); builder.append(node.data().substring_view(0, position.offset()));

View file

@ -158,7 +158,7 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
if (result.layout_node && result.layout_node->dom_node()) { if (result.layout_node && result.layout_node->dom_node()) {
RefPtr<DOM::Node> node = result.layout_node->dom_node(); RefPtr<DOM::Node> node = result.layout_node->dom_node();
if (is<HTML::HTMLIFrameElement>(*node)) { if (is<HTML::HTMLIFrameElement>(*node)) {
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).nested_browsing_context()) if (auto* subframe = verify_cast<HTML::HTMLIFrameElement>(*node).nested_browsing_context())
return subframe->event_handler().handle_mouseup(position.translated(compute_mouse_event_offset({}, *result.layout_node)), button, modifiers); return subframe->event_handler().handle_mouseup(position.translated(compute_mouse_event_offset({}, *result.layout_node)), button, modifiers);
return false; return false;
} }
@ -202,7 +202,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
return false; return false;
if (is<HTML::HTMLIFrameElement>(*node)) { if (is<HTML::HTMLIFrameElement>(*node)) {
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).nested_browsing_context()) if (auto* subframe = verify_cast<HTML::HTMLIFrameElement>(*node).nested_browsing_context())
return subframe->event_handler().handle_mousedown(position.translated(compute_mouse_event_offset({}, *result.layout_node)), button, modifiers); return subframe->event_handler().handle_mousedown(position.translated(compute_mouse_event_offset({}, *result.layout_node)), button, modifiers);
return false; return false;
} }
@ -219,7 +219,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
return true; return true;
if (button == GUI::MouseButton::Right && is<HTML::HTMLImageElement>(*node)) { if (button == GUI::MouseButton::Right && is<HTML::HTMLImageElement>(*node)) {
auto& image_element = downcast<HTML::HTMLImageElement>(*node); auto& image_element = verify_cast<HTML::HTMLImageElement>(*node);
auto image_url = image_element.document().complete_url(image_element.src()); auto image_url = image_element.document().complete_url(image_element.src());
if (auto* page = m_frame.page()) if (auto* page = m_frame.page())
page->client().page_did_request_image_context_menu(m_frame.to_top_level_position(position), image_url, "", modifiers, image_element.bitmap()); page->client().page_did_request_image_context_menu(m_frame.to_top_level_position(position), image_url, "", modifiers, image_element.bitmap());
@ -299,7 +299,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt
RefPtr<DOM::Node> node = result.layout_node->dom_node(); RefPtr<DOM::Node> node = result.layout_node->dom_node();
if (node && is<HTML::HTMLIFrameElement>(*node)) { if (node && is<HTML::HTMLIFrameElement>(*node)) {
if (auto* subframe = downcast<HTML::HTMLIFrameElement>(*node).nested_browsing_context()) if (auto* subframe = verify_cast<HTML::HTMLIFrameElement>(*node).nested_browsing_context())
return subframe->event_handler().handle_mousemove(position.translated(compute_mouse_event_offset({}, *result.layout_node)), buttons, modifiers); return subframe->event_handler().handle_mousemove(position.translated(compute_mouse_event_offset({}, *result.layout_node)), buttons, modifiers);
return false; return false;
} }

View file

@ -107,7 +107,7 @@ HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestTy
} else { } else {
// NOTE: InitialContainingBlockBox::hit_test() merely calls StackingContext::hit_test() // NOTE: InitialContainingBlockBox::hit_test() merely calls StackingContext::hit_test()
// so we call its base class instead. // so we call its base class instead.
result = downcast<InitialContainingBlockBox>(m_box).BlockBox::hit_test(position, type); result = verify_cast<InitialContainingBlockBox>(m_box).BlockBox::hit_test(position, type);
} }
int z_index = m_box.computed_values().z_index().value_or(0); int z_index = m_box.computed_values().z_index().value_or(0);

View file

@ -263,7 +263,7 @@ public:
{ {
for (auto* node = first_child(); node; node = node->next_sibling()) { for (auto* node = first_child(); node; node = node->next_sibling()) {
if (is<U>(node)) if (is<U>(node))
callback(downcast<U>(*node)); callback(verify_cast<U>(*node));
} }
} }
@ -284,7 +284,7 @@ public:
{ {
for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) { for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) {
if (is<U>(*sibling)) if (is<U>(*sibling))
return &downcast<U>(*sibling); return &verify_cast<U>(*sibling);
} }
return nullptr; return nullptr;
} }
@ -300,7 +300,7 @@ public:
{ {
for (auto* sibling = previous_sibling(); sibling; sibling = sibling->previous_sibling()) { for (auto* sibling = previous_sibling(); sibling; sibling = sibling->previous_sibling()) {
if (is<U>(*sibling)) if (is<U>(*sibling))
return &downcast<U>(*sibling); return &verify_cast<U>(*sibling);
} }
return nullptr; return nullptr;
} }
@ -322,7 +322,7 @@ public:
{ {
for (auto* child = first_child(); child; child = child->next_sibling()) { for (auto* child = first_child(); child; child = child->next_sibling()) {
if (is<U>(*child)) if (is<U>(*child))
return &downcast<U>(*child); return &verify_cast<U>(*child);
} }
return nullptr; return nullptr;
} }
@ -332,7 +332,7 @@ public:
{ {
for (auto* child = last_child(); child; child = child->previous_sibling()) { for (auto* child = last_child(); child; child = child->previous_sibling()) {
if (is<U>(*child)) if (is<U>(*child))
return &downcast<U>(*child); return &verify_cast<U>(*child);
} }
return nullptr; return nullptr;
} }
@ -354,7 +354,7 @@ public:
{ {
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
if (is<U>(*ancestor)) if (is<U>(*ancestor))
return &downcast<U>(*ancestor); return &verify_cast<U>(*ancestor);
} }
return nullptr; return nullptr;
} }