mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Remove hand-rolled is_foo() helpers in Layout::Node classes
This commit is contained in:
parent
3bb0cb2202
commit
07dd73c351
Notes:
sideshowbarker
2024-07-19 00:15:49 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/07dd73c3510
31 changed files with 39 additions and 82 deletions
|
@ -44,6 +44,7 @@
|
|||
#include <LibWeb/Layout/TableRowBox.h>
|
||||
#include <LibWeb/Layout/TableRowGroupBox.h>
|
||||
#include <LibWeb/Layout/TreeBuilder.h>
|
||||
#include <LibWeb/Layout/WidgetBox.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
||||
|
@ -213,7 +214,7 @@ void Element::recompute_style()
|
|||
}
|
||||
|
||||
// Don't bother with style on widgets. NATIVE LOOK & FEEL BABY!
|
||||
if (layout_node()->is_widget())
|
||||
if (is<Layout::WidgetBox>(layout_node()))
|
||||
return;
|
||||
|
||||
auto diff = compute_style_difference(layout_node()->specified_style(), *style, document());
|
||||
|
|
|
@ -141,7 +141,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
|
|||
color_off = "\033[0m";
|
||||
}
|
||||
|
||||
if (!layout_node.is_box()) {
|
||||
if (!is<Layout::Box>(layout_node)) {
|
||||
builder.appendff("{}{}{} <{}{}{}>",
|
||||
nonbox_color_on,
|
||||
layout_node.class_name(),
|
||||
|
@ -205,7 +205,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
|
|||
builder.append("\n");
|
||||
}
|
||||
|
||||
if (layout_node.is_block() && static_cast<const Layout::BlockBox&>(layout_node).children_are_inline()) {
|
||||
if (is<Layout::BlockBox>(layout_node) && static_cast<const Layout::BlockBox&>(layout_node).children_are_inline()) {
|
||||
auto& block = static_cast<const Layout::BlockBox&>(layout_node);
|
||||
for (size_t line_box_index = 0; line_box_index < block.line_boxes().size(); ++line_box_index) {
|
||||
auto& line_box = block.line_boxes()[line_box_index];
|
||||
|
@ -231,7 +231,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
|
|||
fragment.start(),
|
||||
fragment.length(),
|
||||
enclosing_int_rect(fragment.absolute_rect()).to_string());
|
||||
if (fragment.layout_node().is_text()) {
|
||||
if (is<Layout::TextNode>(fragment.layout_node())) {
|
||||
for (size_t i = 0; i < indent; ++i)
|
||||
builder.append(" ");
|
||||
auto& layout_text = static_cast<const Layout::TextNode&>(fragment.layout_node());
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/HTMLAnchorElement.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/Layout/BreakNode.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -119,9 +120,9 @@ String HTMLElement::inner_text()
|
|||
|
||||
Function<void(const Layout::Node&)> recurse = [&](auto& node) {
|
||||
for (auto* child = node.first_child(); child; child = child->next_sibling()) {
|
||||
if (child->is_text())
|
||||
if (is<Layout::TextNode>(child))
|
||||
builder.append(downcast<Layout::TextNode>(*child).text_for_rendering());
|
||||
if (child->is_break())
|
||||
if (is<Layout::BreakNode>(child))
|
||||
builder.append('\n');
|
||||
recurse(*child);
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type
|
|||
if (is<Box>(fragment.layout_node()) && downcast<Box>(fragment.layout_node()).stacking_context())
|
||||
continue;
|
||||
if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) {
|
||||
if (fragment.layout_node().is_block())
|
||||
if (is<BlockBox>(fragment.layout_node()))
|
||||
return downcast<BlockBox>(fragment.layout_node()).hit_test(position, type);
|
||||
return { fragment.layout_node(), fragment.text_index_at(position.x()) };
|
||||
}
|
||||
|
|
|
@ -51,9 +51,6 @@ public:
|
|||
void for_each_fragment(Callback) const;
|
||||
|
||||
virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;
|
||||
|
||||
private:
|
||||
virtual bool is_block() const override { return true; }
|
||||
};
|
||||
|
||||
template<typename Callback>
|
||||
|
|
|
@ -48,7 +48,7 @@ BlockFormattingContext::~BlockFormattingContext()
|
|||
|
||||
bool BlockFormattingContext::is_initial() const
|
||||
{
|
||||
return context_box().is_initial_containing_block();
|
||||
return is<InitialContainingBlockBox>(context_box());
|
||||
}
|
||||
|
||||
void BlockFormattingContext::run(Box& box, LayoutMode layout_mode)
|
||||
|
@ -85,7 +85,7 @@ void BlockFormattingContext::run(Box& box, LayoutMode layout_mode)
|
|||
|
||||
void BlockFormattingContext::compute_width(Box& box)
|
||||
{
|
||||
if (box.is_replaced()) {
|
||||
if (is<ReplacedBox>(box)) {
|
||||
// FIXME: This should not be done *by* ReplacedBox
|
||||
auto& replaced = downcast<ReplacedBox>(box);
|
||||
replaced.prepare_for_replaced_layout();
|
||||
|
@ -414,7 +414,7 @@ void BlockFormattingContext::compute_width_for_absolutely_positioned_block(Box&
|
|||
|
||||
void BlockFormattingContext::compute_height(Box& box)
|
||||
{
|
||||
if (box.is_replaced()) {
|
||||
if (is<ReplacedBox>(box)) {
|
||||
compute_height_for_block_level_replaced_element_in_normal_flow(downcast<ReplacedBox>(box));
|
||||
return;
|
||||
}
|
||||
|
@ -471,9 +471,9 @@ void BlockFormattingContext::layout_block_level_children(Box& box, LayoutMode la
|
|||
layout_inside(child_box, layout_mode);
|
||||
compute_height(child_box);
|
||||
|
||||
if (child_box.is_replaced())
|
||||
if (is<ReplacedBox>(child_box))
|
||||
place_block_level_replaced_element_in_normal_flow(child_box, box);
|
||||
else if (child_box.is_block())
|
||||
else if (is<BlockBox>(child_box))
|
||||
place_block_level_non_replaced_element_in_normal_flow(child_box, box);
|
||||
|
||||
// FIXME: This should be factored differently. It's uncool that we mutate the tree *during* layout!
|
||||
|
|
|
@ -165,7 +165,7 @@ void Box::set_containing_line_box_fragment(LineBoxFragment& fragment)
|
|||
StackingContext* Box::enclosing_stacking_context()
|
||||
{
|
||||
for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) {
|
||||
if (!ancestor->is_box())
|
||||
if (!is<Box>(ancestor))
|
||||
continue;
|
||||
auto& ancestor_box = downcast<Box>(*ancestor);
|
||||
if (!ancestor_box.establishes_stacking_context())
|
||||
|
|
|
@ -112,8 +112,6 @@ protected:
|
|||
Vector<LineBox> m_line_boxes;
|
||||
|
||||
private:
|
||||
virtual bool is_box() const final { return true; }
|
||||
|
||||
Gfx::FloatPoint m_offset;
|
||||
Gfx::FloatSize m_size;
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ public:
|
|||
const HTML::HTMLBRElement& dom_node() const { return downcast<HTML::HTMLBRElement>(*Node::dom_node()); }
|
||||
|
||||
private:
|
||||
virtual bool is_break() const override { return true; }
|
||||
virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;
|
||||
};
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(ReplacedBox::dom_node()); }
|
||||
|
||||
private:
|
||||
virtual bool is_button() const override { return true; }
|
||||
virtual bool wants_mouse_events() const override { return true; }
|
||||
virtual void handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override;
|
||||
virtual void handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override;
|
||||
|
|
|
@ -40,9 +40,6 @@ public:
|
|||
virtual void paint(PaintContext&, PaintPhase) override;
|
||||
|
||||
const HTML::HTMLCanvasElement& dom_node() const { return static_cast<const HTML::HTMLCanvasElement&>(ReplacedBox::dom_node()); }
|
||||
|
||||
private:
|
||||
virtual bool is_canvas() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ public:
|
|||
HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(ReplacedBox::dom_node()); }
|
||||
|
||||
private:
|
||||
virtual bool is_check_box() const override { return true; }
|
||||
virtual bool wants_mouse_events() const override { return true; }
|
||||
virtual void handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override;
|
||||
virtual void handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override;
|
||||
|
|
|
@ -31,7 +31,10 @@
|
|||
#include <LibWeb/Layout/FormattingContext.h>
|
||||
#include <LibWeb/Layout/InlineFormattingContext.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Layout/TableBox.h>
|
||||
#include <LibWeb/Layout/TableCellBox.h>
|
||||
#include <LibWeb/Layout/TableFormattingContext.h>
|
||||
#include <LibWeb/Layout/TableRowBox.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
|
@ -55,7 +58,7 @@ bool FormattingContext::creates_block_formatting_context(const Box& box)
|
|||
return true;
|
||||
if (box.is_inline_block())
|
||||
return true;
|
||||
if (box.is_table_cell())
|
||||
if (is<TableCellBox>(box))
|
||||
return true;
|
||||
// FIXME: table-caption
|
||||
// FIXME: anonymous table cells
|
||||
|
@ -76,7 +79,7 @@ void FormattingContext::layout_inside(Box& box, LayoutMode layout_mode)
|
|||
context.run(box, layout_mode);
|
||||
return;
|
||||
}
|
||||
if (box.is_table()) {
|
||||
if (is<TableBox>(box)) {
|
||||
TableFormattingContext context(box, this);
|
||||
context.run(box, layout_mode);
|
||||
} else if (box.children_are_inline()) {
|
||||
|
|
|
@ -43,7 +43,6 @@ public:
|
|||
HTML::HTMLIFrameElement& dom_node() { return downcast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); }
|
||||
|
||||
private:
|
||||
virtual bool is_frame() const final { return true; }
|
||||
virtual void did_set_rect() override;
|
||||
};
|
||||
|
||||
|
|
|
@ -46,8 +46,6 @@ public:
|
|||
void set_visible_in_viewport(Badge<InitialContainingBlockBox>, bool);
|
||||
|
||||
private:
|
||||
virtual bool is_image() const override { return true; }
|
||||
|
||||
int preferred_width() const;
|
||||
int preferred_height() const;
|
||||
|
||||
|
|
|
@ -49,8 +49,6 @@ public:
|
|||
|
||||
void did_set_viewport_rect(Badge<Frame>, const Gfx::IntRect&);
|
||||
|
||||
virtual bool is_initial_containing_block() const override { return true; }
|
||||
|
||||
void build_stacking_context_tree();
|
||||
|
||||
void recompute_selection_states();
|
||||
|
|
|
@ -199,7 +199,7 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
|
|||
|
||||
void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_mode)
|
||||
{
|
||||
if (box.is_replaced()) {
|
||||
if (is<ReplacedBox>(box)) {
|
||||
auto& replaced = downcast<ReplacedBox>(box);
|
||||
replaced.set_width(compute_width_for_replaced_element(replaced));
|
||||
replaced.set_height(compute_height_for_replaced_element(replaced));
|
||||
|
|
|
@ -38,9 +38,6 @@ public:
|
|||
virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override;
|
||||
|
||||
virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;
|
||||
|
||||
private:
|
||||
virtual bool is_inline_node() const final { return true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ const Gfx::FloatRect LineBoxFragment::absolute_rect() const
|
|||
|
||||
int LineBoxFragment::text_index_at(float x) const
|
||||
{
|
||||
if (!layout_node().is_text())
|
||||
if (!is<TextNode>(layout_node()))
|
||||
return 0;
|
||||
auto& layout_text = downcast<TextNode>(layout_node());
|
||||
auto& font = layout_text.specified_style().font();
|
||||
|
@ -108,7 +108,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const
|
|||
auto selection = layout_node().root().selection().normalized();
|
||||
if (!selection.is_valid())
|
||||
return {};
|
||||
if (!layout_node().is_text())
|
||||
if (!is<TextNode>(layout_node()))
|
||||
return {};
|
||||
|
||||
const auto start_index = m_start;
|
||||
|
|
|
@ -41,8 +41,6 @@ public:
|
|||
void layout_marker();
|
||||
|
||||
private:
|
||||
virtual bool is_list_item() const override { return true; }
|
||||
|
||||
RefPtr<ListItemMarkerBox> m_marker;
|
||||
};
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Page/Frame.h>
|
||||
#include <typeinfo>
|
||||
|
||||
|
@ -56,7 +57,7 @@ Node::~Node()
|
|||
|
||||
bool Node::can_contain_boxes_with_position_absolute() const
|
||||
{
|
||||
return style().position() != CSS::Position::Static || is_initial_containing_block();
|
||||
return style().position() != CSS::Position::Static || is<InitialContainingBlockBox>(*this);
|
||||
}
|
||||
|
||||
const BlockBox* Node::containing_block() const
|
||||
|
@ -68,7 +69,7 @@ const BlockBox* Node::containing_block() const
|
|||
return downcast<BlockBox>(ancestor);
|
||||
};
|
||||
|
||||
if (is_text())
|
||||
if (is<TextNode>(*this))
|
||||
return nearest_block_ancestor();
|
||||
|
||||
auto position = style().position();
|
||||
|
@ -165,7 +166,7 @@ float Node::font_size() const
|
|||
|
||||
Gfx::FloatPoint Node::box_type_agnostic_position() const
|
||||
{
|
||||
if (is_box())
|
||||
if (is<Box>(*this))
|
||||
return downcast<Box>(*this).absolute_position();
|
||||
ASSERT(is_inline());
|
||||
Gfx::FloatPoint position;
|
||||
|
@ -303,4 +304,9 @@ String Node::class_name() const
|
|||
return demangle(typeid(*this).name());
|
||||
}
|
||||
|
||||
bool Node::is_inline_block() const
|
||||
{
|
||||
return is_inline() && is<BlockBox>(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -95,24 +95,6 @@ public:
|
|||
|
||||
String class_name() const;
|
||||
|
||||
virtual bool is_initial_containing_block() const { return false; }
|
||||
virtual bool is_text() const { return false; }
|
||||
virtual bool is_block() const { return false; }
|
||||
virtual bool is_replaced() const { return false; }
|
||||
virtual bool is_widget() const { return false; }
|
||||
virtual bool is_frame() const { return false; }
|
||||
virtual bool is_image() const { return false; }
|
||||
virtual bool is_canvas() const { return false; }
|
||||
virtual bool is_box() const { return false; }
|
||||
virtual bool is_table() const { return false; }
|
||||
virtual bool is_table_row() const { return false; }
|
||||
virtual bool is_table_cell() const { return false; }
|
||||
virtual bool is_table_row_group() const { return false; }
|
||||
virtual bool is_break() const { return false; }
|
||||
virtual bool is_check_box() const { return false; }
|
||||
virtual bool is_button() const { return false; }
|
||||
virtual bool is_list_item() const { return false; }
|
||||
virtual bool is_inline_node() const { return false; }
|
||||
bool has_style() const { return m_has_style; }
|
||||
|
||||
virtual bool can_have_children() const { return true; }
|
||||
|
@ -120,7 +102,7 @@ public:
|
|||
bool is_inline() const { return m_inline; }
|
||||
void set_inline(bool b) { m_inline = b; }
|
||||
|
||||
bool is_inline_block() const { return is_inline() && is_block(); }
|
||||
bool is_inline_block() const;
|
||||
|
||||
virtual bool wants_mouse_events() const { return false; }
|
||||
|
||||
|
|
|
@ -39,8 +39,6 @@ public:
|
|||
const DOM::Element& dom_node() const { return downcast<DOM::Element>(*Node::dom_node()); }
|
||||
DOM::Element& dom_node() { return downcast<DOM::Element>(*Node::dom_node()); }
|
||||
|
||||
virtual bool is_replaced() const final { return true; }
|
||||
|
||||
bool has_intrinsic_width() const { return m_has_intrinsic_width; }
|
||||
bool has_intrinsic_height() const { return m_has_intrinsic_height; }
|
||||
bool has_intrinsic_ratio() const { return m_has_intrinsic_ratio; }
|
||||
|
|
|
@ -34,9 +34,6 @@ class TableBox final : public Layout::BlockBox {
|
|||
public:
|
||||
TableBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual ~TableBox() override;
|
||||
|
||||
private:
|
||||
virtual bool is_table() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ public:
|
|||
size_t colspan() const;
|
||||
|
||||
private:
|
||||
virtual bool is_table_cell() const override { return true; }
|
||||
virtual float width_of_logical_containing_block() const override;
|
||||
};
|
||||
|
||||
|
|
|
@ -34,9 +34,6 @@ class TableRowBox final : public Box {
|
|||
public:
|
||||
TableRowBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual ~TableRowBox() override;
|
||||
|
||||
private:
|
||||
virtual bool is_table_row() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -36,9 +36,6 @@ public:
|
|||
virtual ~TableRowGroupBox() override;
|
||||
|
||||
size_t column_count() const;
|
||||
|
||||
private:
|
||||
virtual bool is_table_row_group() const override { return true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -43,8 +43,6 @@ public:
|
|||
const String& text_for_style(const CSS::StyleProperties&) const;
|
||||
const String& text_for_rendering() const { return m_text_for_rendering; }
|
||||
|
||||
virtual bool is_text() const final { return true; }
|
||||
|
||||
virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override;
|
||||
|
||||
virtual void split_into_lines(InlineFormattingContext&, LayoutMode) override;
|
||||
|
|
|
@ -38,8 +38,6 @@ public:
|
|||
GUI::Widget& widget() { return m_widget; }
|
||||
const GUI::Widget& widget() const { return m_widget; }
|
||||
|
||||
virtual bool is_widget() const final { return true; }
|
||||
|
||||
void update_widget();
|
||||
|
||||
private:
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/Layout/InitialContainingBlockBox.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
@ -119,14 +120,14 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole
|
|||
{
|
||||
auto& node = *static_cast<Layout::Node*>(index.internal_data());
|
||||
if (role == GUI::ModelRole::Icon) {
|
||||
if (node.is_initial_containing_block())
|
||||
if (is<Layout::InitialContainingBlockBox>(node))
|
||||
return m_document_icon;
|
||||
if (node.is_text())
|
||||
if (is<Layout::TextNode>(node))
|
||||
return m_text_icon;
|
||||
return m_element_icon;
|
||||
}
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
if (node.is_text())
|
||||
if (is<Layout::TextNode>(node))
|
||||
return String::format("TextNode: %s", with_whitespace_collapsed(downcast<Layout::TextNode>(node).text_for_rendering()).characters());
|
||||
StringBuilder builder;
|
||||
builder.append(node.class_name());
|
||||
|
|
|
@ -50,7 +50,7 @@ StackingContext::StackingContext(Box& box, StackingContext* parent)
|
|||
|
||||
void StackingContext::paint(PaintContext& context, PaintPhase phase)
|
||||
{
|
||||
if (!m_box.is_initial_containing_block()) {
|
||||
if (!is<InitialContainingBlockBox>(m_box)) {
|
||||
m_box.paint(context, phase);
|
||||
} else {
|
||||
// NOTE: InitialContainingBlockBox::paint() merely calls StackingContext::paint()
|
||||
|
@ -65,7 +65,7 @@ void StackingContext::paint(PaintContext& context, PaintPhase phase)
|
|||
HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
||||
{
|
||||
HitTestResult result;
|
||||
if (!m_box.is_initial_containing_block()) {
|
||||
if (!is<InitialContainingBlockBox>(m_box)) {
|
||||
result = m_box.hit_test(position, type);
|
||||
} else {
|
||||
// NOTE: InitialContainingBlockBox::hit_test() merely calls StackingContext::hit_test()
|
||||
|
|
Loading…
Reference in a new issue