mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:37:34 +00:00
AK: Rename downcast<T> => verify_cast<T>
This makes it much clearer what this cast actually does: it will VERIFY that the thing we're casting is a T (using is<T>()).
This commit is contained in:
parent
6215a9c2cb
commit
ee3a73ddbb
61 changed files with 262 additions and 262 deletions
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue