diff options
Diffstat (limited to 'Userland')
58 files changed, 254 insertions, 254 deletions
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index a00feabe78..f8cf9c9b49 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -479,7 +479,7 @@ GUI::TabWidget& BrowserWindow::tab_widget() 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) diff --git a/Userland/Applications/Browser/InspectorWidget.cpp b/Userland/Applications/Browser/InspectorWidget.cpp index 115f1ed281..3d1d8a3f82 100644 --- a/Userland/Applications/Browser/InspectorWidget.cpp +++ b/Userland/Applications/Browser/InspectorWidget.cpp @@ -22,7 +22,7 @@ void InspectorWidget::set_inspected_node(Web::DOM::Node* node) { m_document->set_inspected_node(node); 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()) { 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())); diff --git a/Userland/Applications/PixelPaint/main.cpp b/Userland/Applications/PixelPaint/main.cpp index bbce928522..9748e26038 100644 --- a/Userland/Applications/PixelPaint/main.cpp +++ b/Userland/Applications/PixelPaint/main.cpp @@ -68,7 +68,7 @@ int main(int argc, char** argv) auto current_image_editor = [&]() -> PixelPaint::ImageEditor* { if (!tab_widget.active_widget()) 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; @@ -552,14 +552,14 @@ int main(int argc, char** argv) }; 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.remove_tab(image_editor); }); }; 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); layer_list_widget.set_image(&image_editor.image()); layer_properties_widget.set_layer(nullptr); diff --git a/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp b/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp index e3b4111b8c..23999e4f0e 100644 --- a/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp +++ b/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp @@ -74,7 +74,7 @@ void ThreadStackWidget::refresh() void ThreadStackWidget::custom_event(Core::CustomEvent& event) { - auto& completion_event = downcast<CompletionEvent>(event); + auto& completion_event = verify_cast<CompletionEvent>(event); StringBuilder builder; diff --git a/Userland/Libraries/LibGUI/StackWidget.cpp b/Userland/Libraries/LibGUI/StackWidget.cpp index 84b375872d..1a618a51c6 100644 --- a/Userland/Libraries/LibGUI/StackWidget.cpp +++ b/Userland/Libraries/LibGUI/StackWidget.cpp @@ -54,7 +54,7 @@ void StackWidget::child_event(Core::ChildEvent& event) { if (!event.child() || !is<Widget>(*event.child())) return Widget::child_event(event); - auto& child = downcast<Widget>(*event.child()); + auto& child = verify_cast<Widget>(*event.child()); if (event.type() == Event::ChildAdded) { if (!m_active_widget) set_active_widget(&child); diff --git a/Userland/Libraries/LibGUI/TabWidget.cpp b/Userland/Libraries/LibGUI/TabWidget.cpp index 4f0572fefa..4017d22ce3 100644 --- a/Userland/Libraries/LibGUI/TabWidget.cpp +++ b/Userland/Libraries/LibGUI/TabWidget.cpp @@ -134,7 +134,7 @@ void TabWidget::child_event(Core::ChildEvent& event) { if (!event.child() || !is<Widget>(*event.child())) return Widget::child_event(event); - auto& child = downcast<Widget>(*event.child()); + auto& child = verify_cast<Widget>(*event.child()); if (event.type() == Event::ChildAdded) { if (!m_active_widget) set_active_widget(&child); diff --git a/Userland/Libraries/LibGUI/Widget.cpp b/Userland/Libraries/LibGUI/Widget.cpp index 30654a4cef..2b91f686d9 100644 --- a/Userland/Libraries/LibGUI/Widget.cpp +++ b/Userland/Libraries/LibGUI/Widget.cpp @@ -147,22 +147,22 @@ void Widget::child_event(Core::ChildEvent& event) if (event.type() == Event::ChildAdded) { if (event.child() && is<Widget>(*event.child()) && layout()) { 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 - layout()->add_widget(downcast<Widget>(*event.child())); + layout()->add_widget(verify_cast<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 (layout()) { if (event.child() && is<Widget>(*event.child())) - layout()->remove_widget(downcast<Widget>(*event.child())); + layout()->remove_widget(verify_cast<Widget>(*event.child())); else invalidate_layout(); } 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(); } 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) { if (!is<Widget>(children()[i])) continue; - auto& child = downcast<Widget>(children()[i]); + auto& child = verify_cast<Widget>(children()[i]); if (!child.is_visible()) continue; if (child.content_rect().contains(point)) diff --git a/Userland/Libraries/LibGUI/Widget.h b/Userland/Libraries/LibGUI/Widget.h index 38a3db98d4..647d75b279 100644 --- a/Userland/Libraries/LibGUI/Widget.h +++ b/Userland/Libraries/LibGUI/Widget.h @@ -245,7 +245,7 @@ public: { for_each_child([&](auto& child) { if (is<Widget>(child)) - return callback(downcast<Widget>(child)); + return callback(verify_cast<Widget>(child)); return IterationDecision::Continue; }); } @@ -370,13 +370,13 @@ private: inline Widget* Widget::parent_widget() { if (parent() && is<Widget>(*parent())) - return &downcast<Widget>(*parent()); + return &verify_cast<Widget>(*parent()); return nullptr; } inline const Widget* Widget::parent_widget() const { if (parent() && is<Widget>(*parent())) - return &downcast<const Widget>(*parent()); + return &verify_cast<const Widget>(*parent()); return nullptr; } } diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp index 5f13e32c16..50b1e1cc80 100644 --- a/Userland/Libraries/LibJS/Parser.cpp +++ b/Userland/Libraries/LibJS/Parser.cpp @@ -1691,7 +1691,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(bool for_l declarations.append(create_ast_node<VariableDeclarator>( { 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))); if (match(TokenType::Comma)) { diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp index 49580e31b1..a75590515c 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.cpp @@ -397,7 +397,7 @@ Optional<InstantiationError> AbstractMachine::allocate_all_initial_phase(Module module_instance.exports().append(ExportInstance { entry.name(), - move(address).downcast<FunctionAddress, TableAddress, MemoryAddress, GlobalAddress>(), + move(address).verify_cast<FunctionAddress, TableAddress, MemoryAddress, GlobalAddress>(), }); } }); diff --git a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp index 7115b0ba34..8de111ab1b 100644 --- a/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp +++ b/Userland/Libraries/LibWeb/Bindings/CSSStyleDeclarationWrapperCustom.cpp @@ -41,7 +41,7 @@ bool CSSStyleDeclarationWrapper::put(const JS::PropertyName& name, JS::Value val return false; ScopeGuard style_invalidation_guard = [&] { - auto& declaration = downcast<CSS::ElementInlineCSSStyleDeclaration>(impl()); + auto& declaration = verify_cast<CSS::ElementInlineCSSStyleDeclaration>(impl()); if (auto* element = declaration.element()) element->invalidate_style(); }; diff --git a/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp b/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp index 77b57cadda..eed54b961c 100644 --- a/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp @@ -164,163 +164,163 @@ namespace Web::Bindings { NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)) - 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)); } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h index ea9904de49..3c701ae228 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h @@ -36,9 +36,9 @@ public: { for (auto& rule : m_rules) if (rule.type() == CSSRule::Type::Style) { - callback(downcast<CSSStyleRule>(rule)); + callback(verify_cast<CSSStyleRule>(rule)); } 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()) import_rule.loaded_style_sheet()->for_each_effective_style_rule(callback); } @@ -49,7 +49,7 @@ public: { for (auto& rule : m_rules) 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()) { callback(import_rule); return true; diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index bd7e24ae60..7669a57f6f 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -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()) { if (!is<DOM::Element>(*ancestor)) 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 false; @@ -220,7 +220,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con VERIFY(component_list_index != 0); if (!element.parent() || !is<DOM::Element>(*element.parent())) 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: VERIFY(component_list_index != 0); if (auto* sibling = element.previous_element_sibling()) diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 0140059dcf..be62c097f0 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -278,11 +278,11 @@ Optional<float> StyleProperties::flex_grow_factor() const auto value = property(CSS::PropertyID::FlexGrow); if (!value.has_value()) 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 }; if (!value.value()->is_numeric()) return {}; - auto numeric = downcast<CSS::NumericStyleValue>(value.value().ptr()); + auto numeric = verify_cast<CSS::NumericStyleValue>(value.value().ptr()); return numeric->value(); } @@ -291,11 +291,11 @@ Optional<float> StyleProperties::flex_shrink_factor() const auto value = property(CSS::PropertyID::FlexShrink); if (!value.has_value()) 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 }; if (!value.value()->is_numeric()) return {}; - auto numeric = downcast<CSS::NumericStyleValue>(value.value().ptr()); + auto numeric = verify_cast<CSS::NumericStyleValue>(value.value().ptr()); return numeric->value(); } diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index f1c3d239e1..712c963f12 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -188,7 +188,7 @@ HTML::HTMLHtmlElement* Document::html_element() { auto* html = document_element(); if (is<HTML::HTMLHtmlElement>(html)) - return downcast<HTML::HTMLHtmlElement>(html); + return verify_cast<HTML::HTMLHtmlElement>(html); return nullptr; } @@ -423,7 +423,7 @@ static void update_style_recursively(DOM::Node& node) node.for_each_child([&](auto& child) { if (child.needs_style_update()) { if (is<Element>(child)) - downcast<Element>(child).recompute_style(); + verify_cast<Element>(child).recompute_style(); child.set_needs_style_update(false); } if (child.child_needs_style_update()) { @@ -836,7 +836,7 @@ ExceptionOr<NonnullRefPtr<Node>> Document::adopt_node_binding(NonnullRefPtr<Node if (is<ShadowRoot>(*node)) 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; adopt_node(*node); diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index dae0af495b..26f5e0af68 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -290,7 +290,7 @@ String Element::inner_html() const Function<void(const Node&)> recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { if (child->is_element()) { - auto& element = downcast<Element>(*child); + auto& element = verify_cast<Element>(*child); builder.append('<'); builder.append(element.local_name()); element.for_each_attribute([&](auto& name, auto& value) { @@ -311,7 +311,7 @@ String Element::inner_html() const builder.append('>'); } if (child->is_text()) { - auto& text = downcast<Text>(*child); + auto& text = verify_cast<Text>(*child); builder.append(escape_string(text.data(), false)); } // FIXME: Also handle Comment, ProcessingInstruction, DocumentType diff --git a/Userland/Libraries/LibWeb/DOM/Event.cpp b/Userland/Libraries/LibWeb/DOM/Event.cpp index 77dd356e40..73d0aaa305 100644 --- a/Userland/Libraries/LibWeb/DOM/Event.cpp +++ b/Userland/Libraries/LibWeb/DOM/Event.cpp @@ -18,11 +18,11 @@ void Event::append_to_path(EventTarget& invocation_target, RefPtr<EventTarget> s bool root_of_closed_tree = false; 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())) invocation_target_in_shadow_tree = true; 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(); } } diff --git a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp index 78eccef06a..c4d4133dc4 100644 --- a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp @@ -35,14 +35,14 @@ static EventTarget* retarget(EventTarget* left, [[maybe_unused]] EventTarget* ri if (!is<Node>(left)) return left; - auto* left_node = downcast<Node>(left); + auto* left_node = verify_cast<Node>(left); auto* left_root = left_node->root(); if (!is<ShadowRoot>(left_root)) return left; // FIXME: If right is a node and left’s 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(); } } @@ -76,7 +76,7 @@ bool EventDispatcher::inner_invoke(Event& event, Vector<EventTarget::EventListen RefPtr<Event> current_event; 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(); current_event = window_impl.current_event(); 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); 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(); window_impl.set_current_event(current_event); } @@ -162,7 +162,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr< target_override = target; } else { // 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; @@ -232,13 +232,13 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr< VERIFY(clear_targets_struct.has_value()); 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())) clear_targets = true; } 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())) clear_targets = true; } @@ -246,7 +246,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr< if (!clear_targets) { for (auto touch_target : clear_targets_struct.value().touch_target_list) { 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())) { clear_targets = true; break; diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index e84bca283e..058cd1f459 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -51,8 +51,8 @@ Node::~Node() const HTML::HTMLAnchorElement* Node::enclosing_link_element() const { for (auto* node = this; node; node = node->parent()) { - if (is<HTML::HTMLAnchorElement>(*node) && downcast<HTML::HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href)) - return downcast<HTML::HTMLAnchorElement>(node); + if (is<HTML::HTMLAnchorElement>(*node) && verify_cast<HTML::HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href)) + return verify_cast<HTML::HTMLAnchorElement>(node); } 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 { for (auto* node = this; node; node = node->parent()) { - if (is<HTML::HTMLElement>(*node) && downcast<HTML::HTMLElement>(*node).has_attribute(attribute)) - return downcast<HTML::HTMLElement>(node); + if (is<HTML::HTMLElement>(*node) && verify_cast<HTML::HTMLElement>(*node).has_attribute(attribute)) + return verify_cast<HTML::HTMLElement>(node); } return nullptr; } @@ -83,7 +83,7 @@ String Node::text_content() const void Node::set_text_content(const String& content) { if (is_text()) { - downcast<Text>(this)->set_data(content); + verify_cast<Text>(this)->set_data(content); } else { remove_all_children(); append_child(document().create_text_node(content)); @@ -123,9 +123,9 @@ String Node::child_text_content() const return String::empty(); StringBuilder builder; - downcast<ParentNode>(*this).for_each_child([&](auto& child) { + verify_cast<ParentNode>(*this).for_each_child([&](auto& child) { if (is<Text>(child)) - builder.append(downcast<Text>(child).text_content()); + builder.append(verify_cast<Text>(child).text_content()); }); return builder.build(); } @@ -142,7 +142,7 @@ Node* Node::shadow_including_root() { auto node_root = 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; } @@ -155,14 +155,14 @@ Element* Node::parent_element() { if (!parent() || !is<Element>(parent())) return nullptr; - return downcast<Element>(parent()); + return verify_cast<Element>(parent()); } const Element* Node::parent_element() const { if (!parent() || !is<Element>(parent())) return nullptr; - return downcast<Element>(parent()); + return verify_cast<Element>(parent()); } // 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<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>()) || (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"); @@ -209,7 +209,7 @@ void Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool supp { NonnullRefPtrVector<Node> nodes; if (is<DocumentFragment>(*node)) - nodes = downcast<DocumentFragment>(*node).child_nodes(); + nodes = verify_cast<DocumentFragment>(*node).child_nodes(); else nodes.append(node); @@ -369,7 +369,7 @@ ExceptionOr<NonnullRefPtr<Node>> Node::replace_child(NonnullRefPtr<Node> node, N if (is<Document>(this)) { 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>()) || (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"); @@ -411,7 +411,7 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co document = m_document; RefPtr<Node> copy; 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 element_copy = adopt_ref(*new Element(*document, move(qualified_name))); 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); } else if (is<Document>(this)) { - auto document_ = downcast<Document>(this); + auto document_ = verify_cast<Document>(this); auto document_copy = Document::create(document_->url()); document_copy->set_encoding(document_->encoding()); 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") copy = move(document_copy); } 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)); document_type_copy->set_name(document_type->name()); document_type_copy->set_public_id(document_type->public_id()); document_type_copy->set_system_id(document_type->system_id()); copy = move(document_type_copy); } 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())); copy = move(text_copy); } 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())); copy = move(comment_copy); } 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())); copy = move(processing_instruction_copy); } else { @@ -490,7 +490,7 @@ JS::Object* Node::create_wrapper(JS::GlobalObject& global_object) void Node::removed_last_ref() { if (is<Document>(*this)) { - downcast<Document>(*this).removed_last_ref(); + verify_cast<Document>(*this).removed_last_ref(); return; } m_deletion_has_begun = true; @@ -534,8 +534,8 @@ void Node::inserted() ParentNode* Node::parent_or_shadow_host() { if (is<ShadowRoot>(*this)) - return downcast<ShadowRoot>(*this).host(); - return downcast<ParentNode>(parent()); + return verify_cast<ShadowRoot>(*this).host(); + return verify_cast<ParentNode>(parent()); } 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 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 diff --git a/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h b/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h index ba38305342..c63b117a01 100644 --- a/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h +++ b/Userland/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h @@ -19,7 +19,7 @@ public: { for (auto* sibling = static_cast<NodeType*>(this)->previous_sibling(); sibling; sibling = sibling->previous_sibling()) { if (is<Element>(*sibling)) - return downcast<Element>(sibling); + return verify_cast<Element>(sibling); } return nullptr; } @@ -28,7 +28,7 @@ public: { for (auto* sibling = static_cast<NodeType*>(this)->next_sibling(); sibling; sibling = sibling->next_sibling()) { if (is<Element>(*sibling)) - return downcast<Element>(sibling); + return verify_cast<Element>(sibling); } 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()) { if (is<Element>(*node)) - return downcast<Element>(node); + return verify_cast<Element>(node); } return nullptr; } diff --git a/Userland/Libraries/LibWeb/DOM/Position.cpp b/Userland/Libraries/LibWeb/DOM/Position.cpp index e4dc8cd67c..fca20bc24a 100644 --- a/Userland/Libraries/LibWeb/DOM/Position.cpp +++ b/Userland/Libraries/LibWeb/DOM/Position.cpp @@ -34,7 +34,7 @@ bool Position::increment_offset() if (!is<DOM::Text>(*m_node)) return false; - auto& node = downcast<DOM::Text>(*m_node); + auto& node = verify_cast<DOM::Text>(*m_node); auto text = Utf8View(node.data()); 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)) return false; - auto& node = downcast<DOM::Text>(*m_node); + auto& node = verify_cast<DOM::Text>(*m_node); auto text = Utf8View(node.data()); 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)) return false; - auto& node = downcast<DOM::Text>(*m_node); + auto& node = verify_cast<DOM::Text>(*m_node); auto text = node.data(); return m_offset == text.length(); } diff --git a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp index de9b47db75..07dc13ed38 100644 --- a/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp +++ b/Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp @@ -19,7 +19,7 @@ ShadowRoot::ShadowRoot(Document& document, Element& host) EventTarget* ShadowRoot::get_parent(const Event& event) { 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) return nullptr; } diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.cpp b/Userland/Libraries/LibWeb/DOMTreeModel.cpp index ddd7479305..5857c78445 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeModel.cpp @@ -110,10 +110,10 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol } if (role == GUI::ModelRole::Display) { 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()) return node.node_name(); - auto& element = downcast<DOM::Element>(node); + auto& element = verify_cast<DOM::Element>(node); StringBuilder builder; builder.append('<'); builder.append(element.local_name()); diff --git a/Userland/Libraries/LibWeb/Dump.cpp b/Userland/Libraries/LibWeb/Dump.cpp index bcf3116aea..d30ca56b7d 100644 --- a/Userland/Libraries/LibWeb/Dump.cpp +++ b/Userland/Libraries/LibWeb/Dump.cpp @@ -40,19 +40,19 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node) for (int i = 0; i < indent; ++i) builder.append(" "); if (is<DOM::Element>(node)) { - builder.appendff("<{}", downcast<DOM::Element>(node).local_name()); - downcast<DOM::Element>(node).for_each_attribute([&](auto& name, auto& value) { + builder.appendff("<{}", verify_cast<DOM::Element>(node).local_name()); + verify_cast<DOM::Element>(node).for_each_attribute([&](auto& name, auto& value) { builder.appendff(" {}={}", name, value); }); builder.append(">\n"); } else if (is<DOM::Text>(node)) { - builder.appendff("\"{}\"\n", downcast<DOM::Text>(node).data()); + builder.appendff("\"{}\"\n", verify_cast<DOM::Text>(node).data()); } else { builder.appendff("{}\n", node.node_name()); } ++indent; - if (is<DOM::Element>(node) && downcast<DOM::Element>(node).shadow_root()) { - dump_tree(*downcast<DOM::Element>(node).shadow_root()); + if (is<DOM::Element>(node) && verify_cast<DOM::Element>(node).shadow_root()) { + dump_tree(*verify_cast<DOM::Element>(node).shadow_root()); } if (is<DOM::ParentNode>(node)) { if (!is<HTML::HTMLTemplateElement>(node)) { @@ -60,7 +60,7 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node) dump_tree(child); }); } else { - auto& template_element = downcast<HTML::HTMLTemplateElement>(node); + auto& template_element = verify_cast<HTML::HTMLTemplateElement>(node); 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()) tag_name = "(anonymous)"; 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 tag_name = layout_node.dom_node()->node_name(); String identifier = ""; 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; auto id = element.attribute(HTML::AttributeNames::id); 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.append("\n"); } else { - auto& box = downcast<Layout::Box>(layout_node); + auto& box = verify_cast<Layout::Box>(layout_node); builder.appendff("{}{}{} <{}{}{}{}> ", box_color_on, 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 { String name; String value; }; 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() }); }); 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()); switch (rule.type()) { 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; 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; default: VERIFY_NOT_REACHED(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp index 9d8ca1b5d6..599515d41f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -110,7 +110,7 @@ String HTMLElement::inner_text() Function<void(const Layout::Node&)> recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { 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)) builder.append('\n'); recurse(*child); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index fb104c377a..1d94ea1f90 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -98,7 +98,7 @@ void HTMLFormElement::submit_form(RefPtr<HTMLElement> submitter, bool from_submi Vector<URLQueryParam> parameters; 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)) parameters.append({ input.name(), input.value() }); return IterationDecision::Continue; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp index 16a1de0fba..379b1ed0a2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp @@ -30,7 +30,7 @@ void HTMLStyleElement::children_changed() StringBuilder builder; for_each_child([&](auto& 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()); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index ab63c2bd43..16e44a3078 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -84,7 +84,7 @@ RefPtr<HTMLTableSectionElement> HTMLTableElement::t_head() { for (auto* child = first_child(); child; child = child->next_sibling()) { 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) return table_section_element; } @@ -110,7 +110,7 @@ DOM::ExceptionOr<void> HTMLTableElement::set_t_head(HTMLTableSectionElement& the if (is<HTMLTableCaptionElement>(*child)) continue; 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) continue; } @@ -141,7 +141,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_head() if (is<HTMLTableCaptionElement>(*child)) continue; 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) continue; } @@ -168,7 +168,7 @@ RefPtr<HTMLTableSectionElement> HTMLTableElement::t_foot() { for (auto* child = first_child(); child; child = child->next_sibling()) { 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) return table_section_element; } @@ -228,7 +228,7 @@ NonnullRefPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body() if (!is<HTMLElement>(*child)) continue; 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) { // We have found an element which is a <tbody> we'll insert after this child_to_append_after = child->next_sibling(); diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 77e49a5155..cdf0e0a4f8 100644 --- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -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); 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. - return { downcast<HTMLTemplateElement>(last_template.element)->content(), nullptr }; + return { verify_cast<HTMLTemplateElement>(last_template.element)->content(), nullptr }; } if (!last_table.element) { VERIFY(m_parsing_fragment); @@ -428,7 +428,7 @@ HTMLDocumentParser::AdjustedInsertionLocation HTMLDocumentParser::find_appropria } 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; } @@ -497,7 +497,7 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token) if (token.is_start_tag() && token.tag_name() == HTML::TagNames::head) { auto element = insert_html_element(token); - m_head_element = downcast<HTMLHeadElement>(*element); + m_head_element = verify_cast<HTMLHeadElement>(*element); m_insertion_mode = InsertionMode::InHead; return; } @@ -512,7 +512,7 @@ void HTMLDocumentParser::handle_before_head(HTMLToken& token) } 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; process_using_the_rules_for(InsertionMode::InHead, token); return; @@ -583,7 +583,7 @@ void HTMLDocumentParser::handle_in_head(HTMLToken& token) if (token.is_start_tag() && token.tag_name() == HTML::TagNames::script) { auto adjusted_insertion_location = find_appropriate_place_for_inserting_node(); 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_non_blocking({}, false); @@ -706,7 +706,7 @@ DOM::Text* HTMLDocumentParser::find_character_insertion_node() if (adjusted_insertion_location.parent->is_document()) return nullptr; 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(), "")); adjusted_insertion_location.parent->append_child(new_text_node); return new_text_node; @@ -1268,7 +1268,7 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token) close_a_p_element(); auto element = insert_html_element(token); if (!m_stack_of_open_elements.contains(HTML::TagNames::template_)) - m_form_element = downcast<HTMLFormElement>(*element); + m_form_element = verify_cast<HTMLFormElement>(*element); return; } @@ -1877,7 +1877,7 @@ void HTMLDocumentParser::handle_text(HTMLToken& token) if (token.is_end_of_file()) { log_parse_error(); 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_insertion_mode = m_original_insertion_mode; 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. 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_insertion_mode = m_original_insertion_mode; // FIXME: Handle tokenizer insertion point stuff here. @@ -2289,7 +2289,7 @@ void HTMLDocumentParser::handle_in_table(HTMLToken& token) 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. 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()) { if (is<HTMLFormElement>(*form_candidate)) { - parser.m_form_element = downcast<HTMLFormElement>(*form_candidate); + parser.m_form_element = verify_cast<HTMLFormElement>(*form_candidate); break; } } diff --git a/Userland/Libraries/LibWeb/InProcessWebView.cpp b/Userland/Libraries/LibWeb/InProcessWebView.cpp index f7447e483f..0379e50dfb 100644 --- a/Userland/Libraries/LibWeb/InProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/InProcessWebView.cpp @@ -81,7 +81,7 @@ void InProcessWebView::select_all() int last_layout_node_index_in_node = 0; 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 } }); update(); diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp index 6682dbb8de..5867331aaa 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.cpp @@ -88,11 +88,11 @@ HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type HitTestResult last_good_candidate; for (auto& line_box : m_line_boxes) { 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; if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) { 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()) }; } if (fragment.absolute_rect().top() <= position.y()) diff --git a/Userland/Libraries/LibWeb/Layout/BlockBox.h b/Userland/Libraries/LibWeb/Layout/BlockBox.h index 4833d80519..edb70e8097 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockBox.h +++ b/Userland/Libraries/LibWeb/Layout/BlockBox.h @@ -21,10 +21,10 @@ public: virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override; - BlockBox* previous_sibling() { return downcast<BlockBox>(Node::previous_sibling()); } - const BlockBox* previous_sibling() const { return downcast<BlockBox>(Node::previous_sibling()); } - BlockBox* next_sibling() { return downcast<BlockBox>(Node::next_sibling()); } - const BlockBox* next_sibling() const { return downcast<BlockBox>(Node::next_sibling()); } + BlockBox* previous_sibling() { return verify_cast<BlockBox>(Node::previous_sibling()); } + const BlockBox* previous_sibling() const { return verify_cast<BlockBox>(Node::previous_sibling()); } + BlockBox* next_sibling() { return verify_cast<BlockBox>(Node::next_sibling()); } + const BlockBox* next_sibling() const { return verify_cast<BlockBox>(Node::next_sibling()); } template<typename Callback> void for_each_fragment(Callback); diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index f262a121a3..9e7a0f27e0 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -72,7 +72,7 @@ void BlockFormattingContext::compute_width(Box& box) if (is<ReplacedBox>(box)) { // FIXME: This should not be done *by* ReplacedBox - auto& replaced = downcast<ReplacedBox>(box); + auto& replaced = verify_cast<ReplacedBox>(box); replaced.prepare_for_replaced_layout(); compute_width_for_block_level_replaced_element_in_normal_flow(replaced); 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. float height = 0; if (is<ReplacedBox>(box)) { - height = compute_height_for_replaced_element(downcast<ReplacedBox>(box)); + height = compute_height_for_replaced_element(verify_cast<ReplacedBox>(box)); } else { if (box.computed_values().height().is_undefined_or_auto() || (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! // Instead, we should generate the marker box during the tree build. 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_width = max(content_width, downcast<Box>(child_box).width()); + content_width = max(content_width, verify_cast<Box>(child_box).width()); 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& icb = downcast<Layout::InitialContainingBlockBox>(context_box()); + auto& icb = verify_cast<Layout::InitialContainingBlockBox>(context_box()); icb.build_stacking_context_tree(); 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(); for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) { if (is<Box>(*ancestor)) { - auto offset = downcast<Box>(*ancestor).effective_offset(); + auto offset = verify_cast<Box>(*ancestor).effective_offset(); rect.translate_by(offset); } if (ancestor == &context_box) diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 398ffb4909..206746f161 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -50,7 +50,7 @@ void Box::paint(PaintContext& context, PaintPhase phase) 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()); } } @@ -347,7 +347,7 @@ StackingContext* Box::enclosing_stacking_context() for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { if (!is<Box>(ancestor)) continue; - auto& ancestor_box = downcast<Box>(*ancestor); + auto& ancestor_box = verify_cast<Box>(*ancestor); if (!ancestor_box.establishes_stacking_context()) continue; VERIFY(ancestor_box.stacking_context()); diff --git a/Userland/Libraries/LibWeb/Layout/BreakNode.h b/Userland/Libraries/LibWeb/Layout/BreakNode.h index 8e5d52c64c..873f55ae30 100644 --- a/Userland/Libraries/LibWeb/Layout/BreakNode.h +++ b/Userland/Libraries/LibWeb/Layout/BreakNode.h @@ -16,7 +16,7 @@ public: BreakNode(DOM::Document&, HTML::HTMLBRElement&); 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: virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index e701e0d692..824d7c049c 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -254,7 +254,7 @@ float FormattingContext::tentative_width_for_replaced_element(const ReplacedBox& void FormattingContext::compute_width_for_absolutely_positioned_element(Box& 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 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) { 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 compute_height_for_absolutely_positioned_non_replaced_element(box); } diff --git a/Userland/Libraries/LibWeb/Layout/FrameBox.h b/Userland/Libraries/LibWeb/Layout/FrameBox.h index 8646663550..d055bd07a1 100644 --- a/Userland/Libraries/LibWeb/Layout/FrameBox.h +++ b/Userland/Libraries/LibWeb/Layout/FrameBox.h @@ -19,8 +19,8 @@ public: virtual void paint(PaintContext&, PaintPhase) override; virtual void prepare_for_replaced_layout() override; - const HTML::HTMLIFrameElement& dom_node() const { return downcast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); } - HTML::HTMLIFrameElement& dom_node() { 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 verify_cast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); } private: virtual void did_set_rect() override; diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp index c1b0065002..dfb5bac7d8 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp @@ -60,7 +60,7 @@ void ImageBox::prepare_for_replaced_layout() } 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 alt = image_element.alt(); if (alt.is_empty()) @@ -88,7 +88,7 @@ void ImageBox::paint(PaintContext& context, PaintPhase phase) if (phase == PaintPhase::Foreground) { 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()); 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(); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 535541a97a..99669b26aa 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -75,7 +75,7 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode) containing_block().for_each_child([&](auto& child) { VERIFY(child.is_inline()); if (is<Box>(child) && child.is_absolutely_positioned()) { - layout_absolutely_positioned_element(downcast<Box>(child)); + layout_absolutely_positioned_element(verify_cast<Box>(child)); return; } @@ -181,14 +181,14 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode) void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_mode) { 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_height(compute_height_for_replaced_element(replaced)); return; } 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()) { auto result = calculate_shrink_to_fit_widths(inline_block); diff --git a/Userland/Libraries/LibWeb/Layout/LineBox.cpp b/Userland/Libraries/LibWeb/Layout/LineBox.cpp index 7d27d693f3..5f2a342dd9 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBox.cpp @@ -27,7 +27,7 @@ void LineBox::add_fragment(Node& layout_node, int start, int length, float width m_width += width; 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() diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 856e5849a0..325529e12e 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -41,7 +41,7 @@ StringView LineBoxFragment::text() const { if (!is<TextNode>(layout_node())) 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 @@ -56,7 +56,7 @@ int LineBoxFragment::text_index_at(float x) const { if (!is<TextNode>(layout_node())) return 0; - auto& layout_text = downcast<TextNode>(layout_node()); + auto& layout_text = verify_cast<TextNode>(layout_node()); auto& font = layout_text.font(); Utf8View view(text()); diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 3b167b6ba1..cbd3de1d43 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -150,7 +150,7 @@ void Node::set_needs_display() Gfx::FloatPoint Node::box_type_agnostic_position() const { if (is<Box>(*this)) - return downcast<Box>(*this).absolute_position(); + return verify_cast<Box>(*this).absolute_position(); VERIFY(is_inline()); Gfx::FloatPoint position; if (auto* block = containing_block()) { diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index ebd2405ea4..0dc6edeb7d 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -158,13 +158,13 @@ public: void for_each_child_in_paint_order(Callback callback) const { 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; if (!child.is_positioned()) callback(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; if (child.is_positioned()) callback(child); diff --git a/Userland/Libraries/LibWeb/Layout/ReplacedBox.h b/Userland/Libraries/LibWeb/Layout/ReplacedBox.h index 39e723c4f5..0cd01808fb 100644 --- a/Userland/Libraries/LibWeb/Layout/ReplacedBox.h +++ b/Userland/Libraries/LibWeb/Layout/ReplacedBox.h @@ -16,8 +16,8 @@ public: ReplacedBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); virtual ~ReplacedBox() override; - const DOM::Element& dom_node() const { return downcast<DOM::Element>(*Node::dom_node()); } - DOM::Element& dom_node() { 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 verify_cast<DOM::Element>(*Node::dom_node()); } bool has_intrinsic_width() const { return m_has_intrinsic_width; } bool has_intrinsic_height() const { return m_has_intrinsic_height; } diff --git a/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp b/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp index c00b28286d..3126330793 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp @@ -19,7 +19,7 @@ void SVGGraphicsBox::before_children_paint(PaintContext& context, PaintPhase pha if (phase != PaintPhase::Foreground) 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()) context.svg_context().set_fill_color(graphics_element.fill_color().value()); diff --git a/Userland/Libraries/LibWeb/Layout/SVGPathBox.h b/Userland/Libraries/LibWeb/Layout/SVGPathBox.h index 449971bbe7..3060238cb9 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGPathBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGPathBox.h @@ -16,7 +16,7 @@ public: SVGPathBox(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr<CSS::StyleProperties>); 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 paint(PaintContext& context, PaintPhase phase) override; diff --git a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h index ad4cbdafdd..241a7d3405 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h +++ b/Userland/Libraries/LibWeb/Layout/SVGSVGBox.h @@ -16,7 +16,7 @@ public: SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>); 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; diff --git a/Userland/Libraries/LibWeb/Layout/TableCellBox.cpp b/Userland/Libraries/LibWeb/Layout/TableCellBox.cpp index 4ded320186..761253794a 100644 --- a/Userland/Libraries/LibWeb/Layout/TableCellBox.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableCellBox.cpp @@ -28,7 +28,7 @@ size_t TableCellBox::colspan() const { if (!dom_node()) 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 diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index e03097e0d9..a9dfd44669 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -261,7 +261,7 @@ void TextNode::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint& positi { if (!parent() || !is<Label>(*parent())) 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); } @@ -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. 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); } @@ -281,7 +281,7 @@ void TextNode::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& positi { if (!parent() || !is<Label>(*parent())) 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) diff --git a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp index 7b2c1ce416..47fc97363a 100644 --- a/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/TreeBuilder.cpp @@ -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()) { - push_parent(downcast<NodeWithStyle>(*layout_node)); + push_parent(verify_cast<NodeWithStyle>(*layout_node)); if (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); }); pop_parent(); @@ -121,7 +121,7 @@ RefPtr<Node> TreeBuilder::build(DOM::Node& dom_node) if (dom_node.parent()) { // 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()) - m_parent_stack.prepend(downcast<NodeWithStyle>(ancestor)); + m_parent_stack.prepend(verify_cast<NodeWithStyle>(ancestor)); } create_layout_tree(dom_node); diff --git a/Userland/Libraries/LibWeb/LayoutTreeModel.cpp b/Userland/Libraries/LibWeb/LayoutTreeModel.cpp index 65d7f84d2b..8832e4ce2a 100644 --- a/Userland/Libraries/LibWeb/LayoutTreeModel.cpp +++ b/Userland/Libraries/LibWeb/LayoutTreeModel.cpp @@ -108,7 +108,7 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole } if (role == GUI::ModelRole::Display) { 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; builder.append(node.class_name()); builder.append(' '); @@ -117,7 +117,7 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole } else if (!node.dom_node()->is_element()) { builder.append(node.dom_node()->node_name()); } else { - auto& element = downcast<DOM::Element>(*node.dom_node()); + auto& element = verify_cast<DOM::Element>(*node.dom_node()); builder.append('<'); builder.append(element.local_name()); element.for_each_attribute([&](auto& name, auto& value) { diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index f979c97a34..89e3f836fa 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -277,7 +277,7 @@ void FrameLoader::resource_did_load() 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> 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()) diff --git a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp index da594353f2..17b5f47876 100644 --- a/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/Page/BrowsingContext.cpp @@ -165,7 +165,7 @@ void BrowsingContext::scroll_to_anchor(const String& fragment) auto candidates = document()->get_elements_by_name(fragment); for (auto& candidate : candidates->collect_matching_elements()) { if (is<HTML::HTMLAnchorElement>(*candidate)) { - element = downcast<HTML::HTMLAnchorElement>(*candidate); + element = verify_cast<HTML::HTMLAnchorElement>(*candidate); 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() } }; 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(); 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 (!is<Layout::TextNode>(*selection.start().layout_node)) 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 auto layout_node = selection.start().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)); } @@ -258,7 +258,7 @@ String BrowsingContext::selected_text() const layout_node = layout_node->next_in_pre_order(); while (layout_node && layout_node != selection.end().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)) builder.append('\n'); @@ -268,7 +268,7 @@ String BrowsingContext::selected_text() const // End node VERIFY(layout_node == selection.end().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)); } diff --git a/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp b/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp index a5d262ffd3..0fbb90a1a6 100644 --- a/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EditEventHandler.cpp @@ -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. void EditEventHandler::handle_delete(DOM::Range& range) { - auto* start = downcast<DOM::Text>(range.start_container()); - auto* end = downcast<DOM::Text>(range.end_container()); + auto* start = verify_cast<DOM::Text>(range.start_container()); + auto* end = verify_cast<DOM::Text>(range.end_container()); if (start == end) { StringBuilder builder; @@ -100,7 +100,7 @@ void EditEventHandler::handle_delete(DOM::Range& range) void EditEventHandler::handle_insert(DOM::Position position, u32 code_point) { if (is<DOM::Text>(*position.node())) { - auto& node = downcast<DOM::Text>(*position.node()); + auto& node = verify_cast<DOM::Text>(*position.node()); StringBuilder builder; builder.append(node.data().substring_view(0, position.offset())); diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index c5f61c058c..14d14d596d 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -158,7 +158,7 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button if (result.layout_node && result.layout_node->dom_node()) { RefPtr<DOM::Node> node = result.layout_node->dom_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 false; } @@ -202,7 +202,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt return false; 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 false; } @@ -219,7 +219,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt return true; 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()); 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()); @@ -299,7 +299,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt RefPtr<DOM::Node> node = result.layout_node->dom_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 false; } diff --git a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp index 7be1bfd14e..57c0dfdaca 100644 --- a/Userland/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Userland/Libraries/LibWeb/Painting/StackingContext.cpp @@ -107,7 +107,7 @@ HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestTy } else { // NOTE: InitialContainingBlockBox::hit_test() merely calls StackingContext::hit_test() // 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); diff --git a/Userland/Libraries/LibWeb/TreeNode.h b/Userland/Libraries/LibWeb/TreeNode.h index 58c56e8e31..7091ed3470 100644 --- a/Userland/Libraries/LibWeb/TreeNode.h +++ b/Userland/Libraries/LibWeb/TreeNode.h @@ -263,7 +263,7 @@ public: { for (auto* node = first_child(); node; node = node->next_sibling()) { 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()) { if (is<U>(*sibling)) - return &downcast<U>(*sibling); + return &verify_cast<U>(*sibling); } return nullptr; } @@ -300,7 +300,7 @@ public: { for (auto* sibling = previous_sibling(); sibling; sibling = sibling->previous_sibling()) { if (is<U>(*sibling)) - return &downcast<U>(*sibling); + return &verify_cast<U>(*sibling); } return nullptr; } @@ -322,7 +322,7 @@ public: { for (auto* child = first_child(); child; child = child->next_sibling()) { if (is<U>(*child)) - return &downcast<U>(*child); + return &verify_cast<U>(*child); } return nullptr; } @@ -332,7 +332,7 @@ public: { for (auto* child = last_child(); child; child = child->previous_sibling()) { if (is<U>(*child)) - return &downcast<U>(*child); + return &verify_cast<U>(*child); } return nullptr; } @@ -354,7 +354,7 @@ public: { for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { if (is<U>(*ancestor)) - return &downcast<U>(*ancestor); + return &verify_cast<U>(*ancestor); } return nullptr; } |