From 5aeab9878ebb3b9749be633e9d5812a3181141ca Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 22 Nov 2020 15:53:01 +0100 Subject: [PATCH] LibWeb: Rename LayoutNode classes and move them into Layout namespace Bring the names of various boxes closer to spec language. This should hopefully make things easier to understand and hack on. :^) Some notable changes: - LayoutNode -> Layout::Node - LayoutBox -> Layout::Box - LayoutBlock -> Layout::BlockBox - LayoutReplaced -> Layout::ReplacedBox - LayoutDocument -> Layout::InitialContainingBlockBox - LayoutText -> Layout::TextNode - LayoutInline -> Layout::InlineNode Note that this is not strictly a "box tree" as we also hang inline/text nodes in the same tree, and they don't generate boxes. (Instead, they contribute line box fragments to their containing block!) --- Applications/Browser/InspectorWidget.cpp | 2 +- Applications/Browser/Tab.cpp | 8 +-- Applications/Spreadsheet/HelpWindow.cpp | 2 +- Libraries/LibWeb/CMakeLists.txt | 48 ++++++------- Libraries/LibWeb/CSS/Length.cpp | 2 +- Libraries/LibWeb/CSS/Length.h | 10 +-- Libraries/LibWeb/CSS/StyleProperties.cpp | 2 +- Libraries/LibWeb/CSS/StyleProperties.h | 2 +- Libraries/LibWeb/DOM/Comment.cpp | 2 +- Libraries/LibWeb/DOM/Document.cpp | 22 +++--- Libraries/LibWeb/DOM/Document.h | 8 +-- Libraries/LibWeb/DOM/Element.cpp | 36 +++++----- Libraries/LibWeb/DOM/Element.h | 8 +-- Libraries/LibWeb/DOM/Node.cpp | 14 ++-- Libraries/LibWeb/DOM/Node.h | 10 +-- Libraries/LibWeb/DOM/Text.cpp | 6 +- Libraries/LibWeb/DOM/Text.h | 2 +- Libraries/LibWeb/Dump.cpp | 16 ++--- Libraries/LibWeb/Dump.h | 2 +- Libraries/LibWeb/Forward.h | 21 +++--- Libraries/LibWeb/HTML/HTMLBRElement.cpp | 6 +- Libraries/LibWeb/HTML/HTMLBRElement.h | 2 +- Libraries/LibWeb/HTML/HTMLBlinkElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLCanvasElement.cpp | 6 +- Libraries/LibWeb/HTML/HTMLCanvasElement.h | 4 +- Libraries/LibWeb/HTML/HTMLElement.cpp | 6 +- Libraries/LibWeb/HTML/HTMLIFrameElement.cpp | 7 +- Libraries/LibWeb/HTML/HTMLIFrameElement.h | 2 +- Libraries/LibWeb/HTML/HTMLImageElement.cpp | 6 +- Libraries/LibWeb/HTML/HTMLImageElement.h | 2 +- Libraries/LibWeb/HTML/HTMLInputElement.cpp | 18 ++--- Libraries/LibWeb/HTML/HTMLInputElement.h | 4 +- Libraries/LibWeb/HTML/HTMLObjectElement.cpp | 6 +- Libraries/LibWeb/HTML/HTMLObjectElement.h | 2 +- Libraries/LibWeb/InProcessWebView.cpp | 28 ++++---- Libraries/LibWeb/InProcessWebView.h | 4 +- .../Layout/{LayoutBlock.cpp => BlockBox.cpp} | 40 +++++------ .../Layout/{LayoutBlock.h => BlockBox.h} | 32 ++++----- .../LibWeb/Layout/BlockFormattingContext.cpp | 52 +++++++------- .../LibWeb/Layout/BlockFormattingContext.h | 14 ++-- .../LibWeb/Layout/{LayoutBox.cpp => Box.cpp} | 46 ++++++------ .../LibWeb/Layout/{LayoutBox.h => Box.h} | 14 ++-- Libraries/LibWeb/Layout/BoxModelMetrics.cpp | 8 +-- Libraries/LibWeb/Layout/BoxModelMetrics.h | 8 +-- .../Layout/{LayoutBreak.cpp => BreakNode.cpp} | 14 ++-- .../Layout/{LayoutBreak.h => BreakNode.h} | 20 +++--- .../{LayoutButton.cpp => ButtonBox.cpp} | 22 +++--- .../Layout/{LayoutButton.h => ButtonBox.h} | 20 +++--- .../{LayoutCanvas.cpp => CanvasBox.cpp} | 16 ++--- .../Layout/{LayoutCanvas.h => CanvasBox.h} | 18 ++--- .../{LayoutCheckBox.cpp => CheckBox.cpp} | 20 +++--- .../Layout/{LayoutCheckBox.h => CheckBox.h} | 20 +++--- Libraries/LibWeb/Layout/FormattingContext.cpp | 12 ++-- Libraries/LibWeb/Layout/FormattingContext.h | 12 ++-- .../Layout/{LayoutFrame.cpp => FrameBox.cpp} | 24 +++---- .../Layout/{LayoutFrame.h => FrameBox.h} | 20 +++--- .../Layout/{LayoutImage.cpp => ImageBox.cpp} | 24 +++---- .../Layout/{LayoutImage.h => ImageBox.h} | 20 +++--- ...ment.cpp => InitialContainingBlockBox.cpp} | 36 +++++----- ...Document.h => InitialContainingBlockBox.h} | 18 ++--- .../LibWeb/Layout/InlineFormattingContext.cpp | 22 +++--- .../LibWeb/Layout/InlineFormattingContext.h | 4 +- .../{LayoutInline.cpp => InlineNode.cpp} | 11 ++- .../Layout/{LayoutInline.h => InlineNode.h} | 14 ++-- Libraries/LibWeb/Layout/LayoutPosition.cpp | 4 +- Libraries/LibWeb/Layout/LayoutPosition.h | 6 +- Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp | 16 ++--- Libraries/LibWeb/Layout/LayoutTreeBuilder.h | 4 +- Libraries/LibWeb/Layout/LineBox.cpp | 18 ++--- Libraries/LibWeb/Layout/LineBox.h | 8 +-- Libraries/LibWeb/Layout/LineBoxFragment.cpp | 27 ++++--- Libraries/LibWeb/Layout/LineBoxFragment.h | 8 +-- .../{LayoutListItem.cpp => ListItemBox.cpp} | 16 ++--- .../{LayoutListItem.h => ListItemBox.h} | 20 +++--- ...stItemMarker.cpp => ListItemMarkerBox.cpp} | 12 ++-- ...utListItemMarker.h => ListItemMarkerBox.h} | 12 ++-- .../Layout/{LayoutNode.cpp => Node.cpp} | 70 +++++++++---------- .../LibWeb/Layout/{LayoutNode.h => Node.h} | 70 +++++++++---------- .../{LayoutReplaced.cpp => ReplacedBox.cpp} | 18 ++--- .../{LayoutReplaced.h => ReplacedBox.h} | 22 +++--- .../Layout/{LayoutSVG.cpp => SVGBox.cpp} | 20 +++--- .../LibWeb/Layout/{LayoutSVG.h => SVGBox.h} | 12 ++-- ...youtSVGGraphics.cpp => SVGGraphicsBox.cpp} | 14 ++-- .../{LayoutSVGGraphics.h => SVGGraphicsBox.h} | 14 ++-- .../{LayoutSVGPath.cpp => SVGPathBox.cpp} | 16 ++--- .../Layout/{LayoutSVGPath.h => SVGPathBox.h} | 14 ++-- .../{LayoutSVGSVG.cpp => SVGSVGBox.cpp} | 22 +++--- .../Layout/{LayoutSVGSVG.h => SVGSVGBox.h} | 16 ++--- .../{LayoutTableRow.cpp => TableBox.cpp} | 12 ++-- .../Layout/{LayoutTable.h => TableBox.h} | 16 ++--- .../{LayoutTableCell.cpp => TableCellBox.cpp} | 18 ++--- .../{LayoutTableCell.h => TableCellBox.h} | 20 +++--- .../LibWeb/Layout/TableFormattingContext.cpp | 32 ++++----- .../LibWeb/Layout/TableFormattingContext.h | 6 +- .../{LayoutTable.cpp => TableRowBox.cpp} | 11 ++- .../{LayoutTableRow.h => TableRowBox.h} | 18 +++-- ...TableRowGroup.cpp => TableRowGroupBox.cpp} | 20 +++--- ...youtTableRowGroup.h => TableRowGroupBox.h} | 16 ++--- .../Layout/{LayoutText.cpp => TextNode.cpp} | 24 +++---- .../Layout/{LayoutText.h => TextNode.h} | 22 +++--- .../{LayoutWidget.cpp => WidgetBox.cpp} | 16 ++--- .../Layout/{LayoutWidget.h => WidgetBox.h} | 16 ++--- Libraries/LibWeb/LayoutTreeModel.cpp | 12 ++-- Libraries/LibWeb/Page/EventHandler.cpp | 24 +++---- Libraries/LibWeb/Page/EventHandler.h | 8 +-- Libraries/LibWeb/Page/Frame.cpp | 32 ++++----- Libraries/LibWeb/Painting/StackingContext.cpp | 18 ++--- Libraries/LibWeb/Painting/StackingContext.h | 12 ++-- Libraries/LibWeb/SVG/SVGPathElement.cpp | 6 +- Libraries/LibWeb/SVG/SVGPathElement.h | 2 +- Libraries/LibWeb/SVG/SVGSVGElement.cpp | 6 +- Libraries/LibWeb/SVG/SVGSVGElement.h | 2 +- Services/WebContent/PageHost.cpp | 4 +- Services/WebContent/PageHost.h | 2 +- 114 files changed, 863 insertions(+), 880 deletions(-) rename Libraries/LibWeb/Layout/{LayoutBlock.cpp => BlockBox.cpp} (78%) rename Libraries/LibWeb/Layout/{LayoutBlock.h => BlockBox.h} (68%) rename Libraries/LibWeb/Layout/{LayoutBox.cpp => Box.cpp} (90%) rename Libraries/LibWeb/Layout/{LayoutBox.h => Box.h} (90%) rename Libraries/LibWeb/Layout/{LayoutBreak.cpp => BreakNode.cpp} (80%) rename Libraries/LibWeb/Layout/{LayoutBreak.h => BreakNode.h} (74%) rename Libraries/LibWeb/Layout/{LayoutButton.cpp => ButtonBox.cpp} (82%) rename Libraries/LibWeb/Layout/{LayoutButton.h => ButtonBox.h} (80%) rename Libraries/LibWeb/Layout/{LayoutCanvas.cpp => CanvasBox.cpp} (83%) rename Libraries/LibWeb/Layout/{LayoutCanvas.h => CanvasBox.h} (77%) rename Libraries/LibWeb/Layout/{LayoutCheckBox.cpp => CheckBox.cpp} (80%) rename Libraries/LibWeb/Layout/{LayoutCheckBox.h => CheckBox.h} (79%) rename Libraries/LibWeb/Layout/{LayoutFrame.cpp => FrameBox.cpp} (83%) rename Libraries/LibWeb/Layout/{LayoutFrame.h => FrameBox.h} (77%) rename Libraries/LibWeb/Layout/{LayoutImage.cpp => ImageBox.cpp} (86%) rename Libraries/LibWeb/Layout/{LayoutImage.h => ImageBox.h} (76%) rename Libraries/LibWeb/Layout/{LayoutDocument.cpp => InitialContainingBlockBox.cpp} (74%) rename Libraries/LibWeb/Layout/{LayoutDocument.h => InitialContainingBlockBox.h} (79%) rename Libraries/LibWeb/Layout/{LayoutInline.cpp => InlineNode.cpp} (82%) rename Libraries/LibWeb/Layout/{LayoutInline.h => InlineNode.h} (80%) rename Libraries/LibWeb/Layout/{LayoutListItem.cpp => ListItemBox.cpp} (81%) rename Libraries/LibWeb/Layout/{LayoutListItem.h => ListItemBox.h} (75%) rename Libraries/LibWeb/Layout/{LayoutListItemMarker.cpp => ListItemMarkerBox.cpp} (85%) rename Libraries/LibWeb/Layout/{LayoutListItemMarker.h => ListItemMarkerBox.h} (83%) rename Libraries/LibWeb/Layout/{LayoutNode.cpp => Node.cpp} (79%) rename Libraries/LibWeb/Layout/{LayoutNode.h => Node.h} (77%) rename Libraries/LibWeb/Layout/{LayoutReplaced.cpp => ReplacedBox.cpp} (91%) rename Libraries/LibWeb/Layout/{LayoutReplaced.h => ReplacedBox.h} (81%) rename Libraries/LibWeb/Layout/{LayoutSVG.cpp => SVGBox.cpp} (72%) rename Libraries/LibWeb/Layout/{LayoutSVG.h => SVGBox.h} (84%) rename Libraries/LibWeb/Layout/{LayoutSVGGraphics.cpp => SVGGraphicsBox.cpp} (80%) rename Libraries/LibWeb/Layout/{LayoutSVGGraphics.h => SVGGraphicsBox.h} (77%) rename Libraries/LibWeb/Layout/{LayoutSVGPath.cpp => SVGPathBox.cpp} (86%) rename Libraries/LibWeb/Layout/{LayoutSVGPath.h => SVGPathBox.h} (81%) rename Libraries/LibWeb/Layout/{LayoutSVGSVG.cpp => SVGSVGBox.cpp} (70%) rename Libraries/LibWeb/Layout/{LayoutSVGSVG.h => SVGSVGBox.h} (78%) rename Libraries/LibWeb/Layout/{LayoutTableRow.cpp => TableBox.cpp} (80%) rename Libraries/LibWeb/Layout/{LayoutTable.h => TableBox.h} (77%) rename Libraries/LibWeb/Layout/{LayoutTableCell.cpp => TableCellBox.cpp} (77%) rename Libraries/LibWeb/Layout/{LayoutTableCell.h => TableCellBox.h} (71%) rename Libraries/LibWeb/Layout/{LayoutTable.cpp => TableRowBox.cpp} (86%) rename Libraries/LibWeb/Layout/{LayoutTableRow.h => TableRowBox.h} (76%) rename Libraries/LibWeb/Layout/{LayoutTableRowGroup.cpp => TableRowGroupBox.cpp} (75%) rename Libraries/LibWeb/Layout/{LayoutTableRowGroup.h => TableRowGroupBox.h} (76%) rename Libraries/LibWeb/Layout/{LayoutText.cpp => TextNode.cpp} (92%) rename Libraries/LibWeb/Layout/{LayoutText.h => TextNode.h} (77%) rename Libraries/LibWeb/Layout/{LayoutWidget.cpp => WidgetBox.cpp} (86%) rename Libraries/LibWeb/Layout/{LayoutWidget.h => WidgetBox.h} (80%) diff --git a/Applications/Browser/InspectorWidget.cpp b/Applications/Browser/InspectorWidget.cpp index f1557a40454..63ab08116ea 100644 --- a/Applications/Browser/InspectorWidget.cpp +++ b/Applications/Browser/InspectorWidget.cpp @@ -68,7 +68,7 @@ InspectorWidget::InspectorWidget() m_layout_tree_view = top_tab_widget.add_tab("Layout"); m_layout_tree_view->on_selection = [this](auto& index) { - auto* node = static_cast(index.internal_data()); + auto* node = static_cast(index.internal_data()); set_inspected_node(node->dom_node()); }; diff --git a/Applications/Browser/Tab.cpp b/Applications/Browser/Tab.cpp index 9b431e99662..abd5f1c1d97 100644 --- a/Applications/Browser/Tab.cpp +++ b/Applications/Browser/Tab.cpp @@ -52,10 +52,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/Applications/Spreadsheet/HelpWindow.cpp b/Applications/Spreadsheet/HelpWindow.cpp index 65bda5393ea..32369ff73b7 100644 --- a/Applications/Spreadsheet/HelpWindow.cpp +++ b/Applications/Spreadsheet/HelpWindow.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include namespace Spreadsheet { diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index a164f3046c9..f084378cd1b 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -133,39 +133,39 @@ set(SOURCES HTML/Parser/StackOfOpenElements.cpp HighResolutionTime/Performance.cpp InProcessWebView.cpp + Layout/BlockBox.cpp Layout/BlockFormattingContext.cpp + Layout/Box.cpp Layout/BoxModelMetrics.cpp + Layout/BreakNode.cpp + Layout/ButtonBox.cpp + Layout/CanvasBox.cpp + Layout/CheckBox.cpp Layout/FormattingContext.cpp + Layout/FrameBox.cpp + Layout/ImageBox.cpp + Layout/InitialContainingBlockBox.cpp Layout/InlineFormattingContext.cpp - Layout/LayoutBlock.cpp - Layout/LayoutBox.cpp - Layout/LayoutBreak.cpp - Layout/LayoutButton.cpp - Layout/LayoutCanvas.cpp - Layout/LayoutCheckBox.cpp - Layout/LayoutDocument.cpp - Layout/LayoutFrame.cpp - Layout/LayoutImage.cpp - Layout/LayoutInline.cpp - Layout/LayoutListItem.cpp - Layout/LayoutListItemMarker.cpp - Layout/LayoutNode.cpp + Layout/InlineNode.cpp Layout/LayoutPosition.cpp - Layout/LayoutReplaced.cpp - Layout/LayoutSVG.cpp - Layout/LayoutSVGGraphics.cpp - Layout/LayoutSVGPath.cpp - Layout/LayoutSVGSVG.cpp - Layout/LayoutTable.cpp - Layout/LayoutTableCell.cpp - Layout/LayoutTableRow.cpp - Layout/LayoutTableRowGroup.cpp - Layout/LayoutText.cpp Layout/LayoutTreeBuilder.cpp - Layout/LayoutWidget.cpp Layout/LineBox.cpp Layout/LineBoxFragment.cpp + Layout/ListItemBox.cpp + Layout/ListItemMarkerBox.cpp + Layout/Node.cpp + Layout/ReplacedBox.cpp + Layout/SVGBox.cpp + Layout/SVGGraphicsBox.cpp + Layout/SVGPathBox.cpp + Layout/SVGSVGBox.cpp + Layout/TableBox.cpp + Layout/TableCellBox.cpp Layout/TableFormattingContext.cpp + Layout/TableRowBox.cpp + Layout/TableRowGroupBox.cpp + Layout/TextNode.cpp + Layout/WidgetBox.cpp LayoutTreeModel.cpp Loader/FrameLoader.cpp Loader/ImageLoader.cpp diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp index 412fa7c3d09..dd85754ec22 100644 --- a/Libraries/LibWeb/CSS/Length.cpp +++ b/Libraries/LibWeb/CSS/Length.cpp @@ -31,7 +31,7 @@ namespace Web::CSS { -float Length::relative_length_to_px(const LayoutNode& layout_node) const +float Length::relative_length_to_px(const Layout::Node& layout_node) const { switch (m_type) { case Type::Ex: diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h index 227e357204d..ec781aee6d2 100644 --- a/Libraries/LibWeb/CSS/Length.h +++ b/Libraries/LibWeb/CSS/Length.h @@ -68,7 +68,7 @@ public: static Length make_auto() { return Length(0, Type::Auto); } static Length make_px(float value) { return Length(value, Type::Px); } - Length resolved(const Length& fallback_for_undefined, const LayoutNode& layout_node, float reference_for_percent) const + Length resolved(const Length& fallback_for_undefined, const Layout::Node& layout_node, float reference_for_percent) const { if (is_undefined()) return fallback_for_undefined; @@ -79,12 +79,12 @@ public: return *this; } - Length resolved_or_auto(const LayoutNode& layout_node, float reference_for_percent) const + Length resolved_or_auto(const Layout::Node& layout_node, float reference_for_percent) const { return resolved(make_auto(), layout_node, reference_for_percent); } - Length resolved_or_zero(const LayoutNode& layout_node, float reference_for_percent) const + Length resolved_or_zero(const Layout::Node& layout_node, float reference_for_percent) const { return resolved(make_px(0), layout_node, reference_for_percent); } @@ -117,7 +117,7 @@ public: } float raw_value() const { return m_value; } - ALWAYS_INLINE float to_px(const LayoutNode& layout_node) const + ALWAYS_INLINE float to_px(const Layout::Node& layout_node) const { if (is_relative()) return relative_length_to_px(layout_node); @@ -155,7 +155,7 @@ public: } private: - float relative_length_to_px(const LayoutNode&) const; + float relative_length_to_px(const Layout::Node&) const; const char* unit_name() const; diff --git a/Libraries/LibWeb/CSS/StyleProperties.cpp b/Libraries/LibWeb/CSS/StyleProperties.cpp index c0b40984b37..0f1db911bf0 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -173,7 +173,7 @@ void StyleProperties::load_font() const FontCache::the().set({ font_family, font_weight }, *m_font); } -float StyleProperties::line_height(const LayoutNode& layout_node) const +float StyleProperties::line_height(const Layout::Node& layout_node) const { auto line_height_length = length_or_fallback(CSS::PropertyID::LineHeight, Length::make_auto()); if (line_height_length.is_absolute()) diff --git a/Libraries/LibWeb/CSS/StyleProperties.h b/Libraries/LibWeb/CSS/StyleProperties.h index 472d53da070..8622fea9ca0 100644 --- a/Libraries/LibWeb/CSS/StyleProperties.h +++ b/Libraries/LibWeb/CSS/StyleProperties.h @@ -72,7 +72,7 @@ public: return *m_font; } - float line_height(const LayoutNode&) const; + float line_height(const Layout::Node&) const; bool operator==(const StyleProperties&) const; bool operator!=(const StyleProperties& other) const { return !(*this == other); } diff --git a/Libraries/LibWeb/DOM/Comment.cpp b/Libraries/LibWeb/DOM/Comment.cpp index 0814bd0bf6d..7e3f0ab8d2f 100644 --- a/Libraries/LibWeb/DOM/Comment.cpp +++ b/Libraries/LibWeb/DOM/Comment.cpp @@ -25,7 +25,7 @@ */ #include -#include +#include namespace Web::DOM { diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 0a1fe0e506b..c7b00c14ee1 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -54,7 +54,7 @@ #include #include #include -#include +#include #include #include #include @@ -271,7 +271,7 @@ void Document::tear_down_layout_tree() // Gather up all the layout nodes in a vector and detach them from parents // while the vector keeps them alive. - NonnullRefPtrVector layout_nodes; + NonnullRefPtrVector layout_nodes; m_layout_root->for_each_in_subtree([&](auto& layout_node) { layout_nodes.append(layout_node); @@ -347,12 +347,12 @@ void Document::layout() return; if (!m_layout_root) { - LayoutTreeBuilder tree_builder; - m_layout_root = static_ptr_cast(tree_builder.build(*this)); + Layout::LayoutTreeBuilder tree_builder; + m_layout_root = static_ptr_cast(tree_builder.build(*this)); } Layout::BlockFormattingContext root_formatting_context(*m_layout_root); - root_formatting_context.run(LayoutMode::Default); + root_formatting_context.run(Layout::LayoutMode::Default); m_layout_root->set_needs_display(); @@ -380,9 +380,9 @@ void Document::update_layout() layout(); } -RefPtr Document::create_layout_node(const CSS::StyleProperties*) +RefPtr Document::create_layout_node(const CSS::StyleProperties*) { - return adopt(*new LayoutDocument(*this, CSS::StyleProperties::create())); + return adopt(*new Layout::InitialContainingBlockBox(*this, CSS::StyleProperties::create())); } void Document::set_link_color(Color color) @@ -400,14 +400,14 @@ void Document::set_visited_link_color(Color color) m_visited_link_color = color; } -const LayoutDocument* Document::layout_node() const +const Layout::InitialContainingBlockBox* Document::layout_node() const { - return static_cast(Node::layout_node()); + return static_cast(Node::layout_node()); } -LayoutDocument* Document::layout_node() +Layout::InitialContainingBlockBox* Document::layout_node() { - return static_cast(Node::layout_node()); + return static_cast(Node::layout_node()); } void Document::set_inspected_node(Node* node) diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index c3d4dc523c4..cb400bd6e22 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -125,8 +125,8 @@ public: virtual bool is_child_allowed(const Node&) const override; - const LayoutDocument* layout_node() const; - LayoutDocument* layout_node(); + const Layout::InitialContainingBlockBox* layout_node() const; + Layout::InitialContainingBlockBox* layout_node(); void schedule_style_update(); @@ -212,7 +212,7 @@ public: private: explicit Document(const URL&); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; void tear_down_layout_tree(); @@ -244,7 +244,7 @@ private: RefPtr m_window; - RefPtr m_layout_root; + RefPtr m_layout_root; Optional m_link_color; Optional m_active_link_color; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 51b77ea9f76..7e0ab56d8fb 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -34,14 +34,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include +#include +#include +#include +#include namespace Web::DOM { @@ -112,7 +112,7 @@ bool Element::has_class(const FlyString& class_name) const return false; } -RefPtr Element::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr Element::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); const_cast(*this).m_resolved_style = style; @@ -125,26 +125,26 @@ RefPtr Element::create_layout_node(const CSS::StyleProperties* paren return nullptr; if (display == CSS::Display::Block) - return adopt(*new LayoutBlock(document(), this, move(style))); + return adopt(*new Layout::BlockBox(document(), this, move(style))); if (display == CSS::Display::Inline) { if (style->float_().value_or(CSS::Float::None) != CSS::Float::None) - return adopt(*new LayoutBlock(document(), this, move(style))); - return adopt(*new LayoutInline(document(), *this, move(style))); + return adopt(*new Layout::BlockBox(document(), this, move(style))); + return adopt(*new Layout::InlineNode(document(), *this, move(style))); } if (display == CSS::Display::ListItem) - return adopt(*new LayoutListItem(document(), *this, move(style))); + return adopt(*new Layout::ListItemBox(document(), *this, move(style))); if (display == CSS::Display::Table) - return adopt(*new LayoutTable(document(), *this, move(style))); + return adopt(*new Layout::TableBox(document(), *this, move(style))); if (display == CSS::Display::TableRow) - return adopt(*new LayoutTableRow(document(), *this, move(style))); + return adopt(*new Layout::TableRowBox(document(), *this, move(style))); if (display == CSS::Display::TableCell) - return adopt(*new LayoutTableCell(document(), *this, move(style))); + return adopt(*new Layout::TableCellBox(document(), *this, move(style))); if (display == CSS::Display::TableRowGroup || display == CSS::Display::TableHeaderGroup || display == CSS::Display::TableFooterGroup) - return adopt(*new LayoutTableRowGroup(document(), *this, move(style))); + return adopt(*new Layout::TableRowGroupBox(document(), *this, move(style))); if (display == CSS::Display::InlineBlock) { - auto inline_block = adopt(*new LayoutBlock(document(), this, move(style))); + auto inline_block = adopt(*new Layout::BlockBox(document(), this, move(style))); inline_block->set_inline(true); return inline_block; } @@ -206,7 +206,7 @@ void Element::recompute_style() if (style->display() == CSS::Display::None) return; // We need a new layout tree here! - LayoutTreeBuilder tree_builder; + Layout::LayoutTreeBuilder tree_builder; tree_builder.build(*this); return; } diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index 467ca8263e7..d9b704f8412 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include namespace Web::DOM { @@ -82,8 +82,8 @@ public: void recompute_style(); - LayoutNodeWithStyle* layout_node() { return static_cast(Node::layout_node()); } - const LayoutNodeWithStyle* layout_node() const { return static_cast(Node::layout_node()); } + Layout::NodeWithStyle* layout_node() { return static_cast(Node::layout_node()); } + const Layout::NodeWithStyle* layout_node() const { return static_cast(Node::layout_node()); } String name() const { return attribute(HTML::AttributeNames::name); } @@ -97,7 +97,7 @@ public: virtual bool is_focusable() const { return false; } protected: - RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; private: Attribute* find_attribute(const FlyString& name); diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index c81bebf7b82..318e8ebf98b 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -39,11 +39,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include //#define EVENT_DEBUG @@ -105,7 +105,7 @@ void Node::set_text_content(const String& content) document().invalidate_layout(); } -RefPtr Node::create_layout_node(const CSS::StyleProperties*) +RefPtr Node::create_layout_node(const CSS::StyleProperties*) { return nullptr; } @@ -230,7 +230,7 @@ void Node::removed_last_ref() delete this; } -void Node::set_layout_node(Badge, LayoutNode* layout_node) const +void Node::set_layout_node(Badge, Layout::Node* layout_node) const { if (layout_node) m_layout_node = layout_node->make_weak_ptr(); diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 9b2573c3fce..a415b17d4be 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -84,7 +84,7 @@ public: RefPtr insert_before(NonnullRefPtr node, RefPtr child, bool notify = true); void remove_all_children(); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style); + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style); virtual FlyString node_name() const = 0; @@ -115,10 +115,10 @@ public: virtual void removed_from(Node&) { } virtual void children_changed() { } - const LayoutNode* layout_node() const { return m_layout_node; } - LayoutNode* layout_node() { return m_layout_node; } + const Layout::Node* layout_node() const { return m_layout_node; } + Layout::Node* layout_node() { return m_layout_node; } - void set_layout_node(Badge, LayoutNode*) const; + void set_layout_node(Badge, Layout::Node*) const; virtual bool is_child_allowed(const Node&) const { return true; } @@ -138,7 +138,7 @@ protected: Node(Document&, NodeType); Document* m_document { nullptr }; - mutable WeakPtr m_layout_node; + mutable WeakPtr m_layout_node; NodeType m_type { NodeType::INVALID }; bool m_needs_style_update { true }; }; diff --git a/Libraries/LibWeb/DOM/Text.cpp b/Libraries/LibWeb/DOM/Text.cpp index 043998538e3..a0c6ba9dabe 100644 --- a/Libraries/LibWeb/DOM/Text.cpp +++ b/Libraries/LibWeb/DOM/Text.cpp @@ -25,7 +25,7 @@ */ #include -#include +#include namespace Web::DOM { @@ -38,9 +38,9 @@ Text::~Text() { } -RefPtr Text::create_layout_node(const CSS::StyleProperties*) +RefPtr Text::create_layout_node(const CSS::StyleProperties*) { - return adopt(*new LayoutText(document(), *this)); + return adopt(*new Layout::TextNode(document(), *this)); } } diff --git a/Libraries/LibWeb/DOM/Text.h b/Libraries/LibWeb/DOM/Text.h index 8ba78b7179d..1b73543974d 100644 --- a/Libraries/LibWeb/DOM/Text.h +++ b/Libraries/LibWeb/DOM/Text.h @@ -42,7 +42,7 @@ public: virtual FlyString node_name() const override { return "#text"; } private: - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; }; } diff --git a/Libraries/LibWeb/Dump.cpp b/Libraries/LibWeb/Dump.cpp index d2eb66758a3..5318fd7200f 100644 --- a/Libraries/LibWeb/Dump.cpp +++ b/Libraries/LibWeb/Dump.cpp @@ -37,9 +37,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include namespace Web { @@ -80,7 +80,7 @@ void dump_tree(const DOM::Node& node) --indent; } -void dump_tree(const LayoutNode& layout_node) +void dump_tree(const Layout::Node& layout_node) { static size_t indent = 0; for (size_t i = 0; i < indent; ++i) @@ -117,7 +117,7 @@ void dump_tree(const LayoutNode& layout_node) if (!layout_node.is_box()) { dbgprintf("%s {\033[33m%s\033[0m%s}\n", layout_node.class_name(), tag_name.characters(), identifier.characters()); } else { - auto& layout_box = downcast(layout_node); + auto& layout_box = downcast(layout_node); dbgprintf("%s {\033[34m%s\033[0m%s} at (%g,%g) size %gx%g", layout_box.class_name(), tag_name.characters(), @@ -150,8 +150,8 @@ void dump_tree(const LayoutNode& layout_node) dbgprintf("\n"); } - if (layout_node.is_block() && static_cast(layout_node).children_are_inline()) { - auto& block = static_cast(layout_node); + if (layout_node.is_block() && static_cast(layout_node).children_are_inline()) { + auto& block = static_cast(layout_node); for (size_t i = 0; i < indent; ++i) dbgprintf(" "); dbgprintf(" Line boxes (%d):\n", block.line_boxes().size()); @@ -174,7 +174,7 @@ void dump_tree(const LayoutNode& layout_node) if (fragment.layout_node().is_text()) { for (size_t i = 0; i < indent; ++i) dbgprintf(" "); - auto& layout_text = static_cast(fragment.layout_node()); + auto& layout_text = static_cast(fragment.layout_node()); auto fragment_text = layout_text.text_for_rendering().substring(fragment.start(), fragment.length()); dbgprintf(" text: \"%s\"\n", fragment_text.characters()); } diff --git a/Libraries/LibWeb/Dump.h b/Libraries/LibWeb/Dump.h index 6bb15948377..df0164a6f0b 100644 --- a/Libraries/LibWeb/Dump.h +++ b/Libraries/LibWeb/Dump.h @@ -31,7 +31,7 @@ namespace Web { void dump_tree(const DOM::Node&); -void dump_tree(const LayoutNode&); +void dump_tree(const Layout::Node&); void dump_sheet(const CSS::StyleSheet&); void dump_rule(const CSS::StyleRule&); void dump_selector(const CSS::Selector&); diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index ed56031c91d..741752a4d0e 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -26,10 +26,6 @@ #pragma once -namespace Web { -enum class LayoutMode; -} - namespace Web::CSS { class Selector; class StyleProperties; @@ -151,9 +147,18 @@ class SVGSVGElement; } namespace Web::Layout { +enum class LayoutMode; +class BlockBox; class BlockFormattingContext; +class Box; +class ButtonBox; +class CheckBox; +class InitialContainingBlockBox; class FormattingContext; class InlineFormattingContext; +class Node; +class NodeWithStyle; +class ReplacedBox; } namespace Web { @@ -161,14 +166,6 @@ class EventHandler; class Frame; class FrameLoader; class InProcessWebView; -class LayoutBlock; -class LayoutBox; -class LayoutButton; -class LayoutCheckBox; -class LayoutDocument; -class LayoutNode; -class LayoutNodeWithStyle; -class LayoutReplaced; class LineBox; class LineBoxFragment; class LoadRequest; diff --git a/Libraries/LibWeb/HTML/HTMLBRElement.cpp b/Libraries/LibWeb/HTML/HTMLBRElement.cpp index 9774430ca56..3d7e7e5eec2 100644 --- a/Libraries/LibWeb/HTML/HTMLBRElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLBRElement.cpp @@ -25,7 +25,7 @@ */ #include -#include +#include namespace Web::HTML { @@ -38,9 +38,9 @@ HTMLBRElement::~HTMLBRElement() { } -RefPtr HTMLBRElement::create_layout_node(const CSS::StyleProperties*) +RefPtr HTMLBRElement::create_layout_node(const CSS::StyleProperties*) { - return adopt(*new LayoutBreak(document(), *this)); + return adopt(*new Layout::BreakNode(document(), *this)); } } diff --git a/Libraries/LibWeb/HTML/HTMLBRElement.h b/Libraries/LibWeb/HTML/HTMLBRElement.h index 1529e356341..8a6cd816414 100644 --- a/Libraries/LibWeb/HTML/HTMLBRElement.h +++ b/Libraries/LibWeb/HTML/HTMLBRElement.h @@ -37,7 +37,7 @@ public: HTMLBRElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~HTMLBRElement() override; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; }; } diff --git a/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp b/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp index ab41c20f262..911a8940bd5 100644 --- a/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace Web::HTML { diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index a30c9a3ed58..bbad3a06579 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include namespace Web::HTML { @@ -55,12 +55,12 @@ unsigned HTMLCanvasElement::height() const return attribute(HTML::AttributeNames::height).to_uint().value_or(150); } -RefPtr HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); if (style->display() == CSS::Display::None) return nullptr; - return adopt(*new LayoutCanvas(document(), *this, move(style))); + return adopt(*new Layout::CanvasBox(document(), *this, move(style))); } CanvasRenderingContext2D* HTMLCanvasElement::get_context(String type) diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Libraries/LibWeb/HTML/HTMLCanvasElement.h index 75f9b17008e..4bcb8b09140 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.h +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.h @@ -32,8 +32,6 @@ namespace Web::HTML { -class LayoutDocument; - class HTMLCanvasElement final : public HTMLElement { public: using WrapperType = Bindings::HTMLCanvasElementWrapper; @@ -51,7 +49,7 @@ public: unsigned height() const; private: - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; RefPtr m_bitmap; RefPtr m_context; diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp index edf35366df0..bb364a19a35 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include namespace Web::HTML { @@ -117,10 +117,10 @@ String HTMLElement::inner_text() if (!layout_node()) return text_content(); - Function recurse = [&](auto& node) { + Function recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { if (child->is_text()) - builder.append(downcast(*child).text_for_rendering()); + builder.append(downcast(*child).text_for_rendering()); if (child->is_break()) builder.append('\n'); recurse(*child); diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 8577f364d35..115783b747c 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -35,8 +35,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -52,10 +51,10 @@ HTMLIFrameElement::~HTMLIFrameElement() { } -RefPtr HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); - return adopt(*new LayoutFrame(document(), *this, move(style))); + return adopt(*new Layout::FrameBox(document(), *this, move(style))); } void HTMLIFrameElement::document_did_attach_to_frame(Frame& frame) diff --git a/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Libraries/LibWeb/HTML/HTMLIFrameElement.h index 71c0746b0c5..f3f96d40fbd 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.h +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.h @@ -37,7 +37,7 @@ public: HTMLIFrameElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~HTMLIFrameElement() override; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; Frame* content_frame() { return m_content_frame; } const Frame* content_frame() const { return m_content_frame; } diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 9d9439d0cef..d78f911fcf0 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include namespace Web::HTML { @@ -83,12 +83,12 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu m_image_loader.load(document().complete_url(value)); } -RefPtr HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); if (style->display() == CSS::Display::None) return nullptr; - return adopt(*new LayoutImage(document(), *this, move(style), m_image_loader)); + return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader)); } const Gfx::Bitmap* HTMLImageElement::bitmap() const diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.h b/Libraries/LibWeb/HTML/HTMLImageElement.h index 011296ad938..a07762bd631 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -53,7 +53,7 @@ private: void animate(); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; ImageLoader m_image_loader; }; diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 3ab1443e6e7..70e87f7eb88 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -31,9 +31,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include namespace Web::HTML { @@ -47,7 +47,7 @@ HTMLInputElement::~HTMLInputElement() { } -void HTMLInputElement::did_click_button(Badge) +void HTMLInputElement::did_click_button(Badge) { dispatch_event(DOM::Event::create("click")); @@ -60,7 +60,7 @@ void HTMLInputElement::did_click_button(Badge) } } -RefPtr HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style) { ASSERT(document().page()); auto& page = *document().page(); @@ -74,15 +74,15 @@ RefPtr HTMLInputElement::create_layout_node(const CSS::StyleProperti return nullptr; if (type().equals_ignoring_case("submit") || type().equals_ignoring_case("button")) - return adopt(*new LayoutButton(document(), *this, move(style))); + return adopt(*new Layout::ButtonBox(document(), *this, move(style))); if (type() == "checkbox") - return adopt(*new LayoutCheckBox(document(), *this, move(style))); + return adopt(*new Layout::CheckBox(document(), *this, move(style))); auto& text_box = page_view.add(); text_box.set_text(value()); text_box.on_change = [this] { - auto& widget = downcast(layout_node())->widget(); + auto& widget = downcast(layout_node())->widget(); const_cast(this)->set_attribute(HTML::AttributeNames::value, static_cast(widget).text()); }; int text_width = Gfx::Font::default_font().width(value()); @@ -93,7 +93,7 @@ RefPtr HTMLInputElement::create_layout_node(const CSS::StyleProperti text_width = Gfx::Font::default_font().glyph_width('x') * size.value(); } text_box.set_relative_rect(0, 0, text_width + 20, 20); - return adopt(*new LayoutWidget(document(), *this, text_box)); + return adopt(*new Layout::WidgetBox(document(), *this, text_box)); } void HTMLInputElement::set_checked(bool checked) diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index 1ff40da6f6f..84e0ecf1c1c 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -37,7 +37,7 @@ public: HTMLInputElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~HTMLInputElement() override; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; String type() const { return attribute(HTML::AttributeNames::type); } String value() const { return attribute(HTML::AttributeNames::value); } @@ -48,7 +48,7 @@ public: bool enabled() const; - void did_click_button(Badge); + void did_click_button(Badge); private: bool m_checked { false }; diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index e5f7ab2fd5c..4a3d0a11d4f 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include namespace Web::HTML { @@ -61,7 +61,7 @@ void HTMLObjectElement::parse_attribute(const FlyString& name, const String& val m_image_loader.load(document().complete_url(value)); } -RefPtr HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style) { if (m_should_show_fallback_content) return HTMLElement::create_layout_node(parent_style); @@ -70,7 +70,7 @@ RefPtr HTMLObjectElement::create_layout_node(const CSS::StylePropert if (style->display() == CSS::Display::None) return nullptr; if (m_image_loader.has_image()) - return adopt(*new LayoutImage(document(), *this, move(style), m_image_loader)); + return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader)); return nullptr; } diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Libraries/LibWeb/HTML/HTMLObjectElement.h index 967ada32cc7..74976046237 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -46,7 +46,7 @@ public: String type() const { return attribute(HTML::AttributeNames::type); } private: - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; ImageLoader m_image_loader; bool m_should_show_fallback_content { false }; diff --git a/Libraries/LibWeb/InProcessWebView.cpp b/Libraries/LibWeb/InProcessWebView.cpp index 2580f80b4e2..88fe7670090 100644 --- a/Libraries/LibWeb/InProcessWebView.cpp +++ b/Libraries/LibWeb/InProcessWebView.cpp @@ -46,10 +46,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -89,21 +89,21 @@ void InProcessWebView::select_all() if (!layout_root) return; - const LayoutNode* first_layout_node = layout_root; + const Layout::Node* first_layout_node = layout_root; for (;;) { auto* next = first_layout_node->next_in_pre_order(); if (!next) break; first_layout_node = next; - if (is(*first_layout_node)) + if (is(*first_layout_node)) break; } - const LayoutNode* last_layout_node = first_layout_node; + const Layout::Node* last_layout_node = first_layout_node; - for (const LayoutNode* layout_node = first_layout_node; layout_node; layout_node = layout_node->next_in_pre_order()) { - if (is(*layout_node)) + for (const Layout::Node* layout_node = first_layout_node; layout_node; layout_node = layout_node->next_in_pre_order()) { + if (is(*layout_node)) last_layout_node = layout_node; } @@ -111,8 +111,8 @@ void InProcessWebView::select_all() ASSERT(last_layout_node); int last_layout_node_index_in_node = 0; - if (is(*last_layout_node)) - last_layout_node_index_in_node = downcast(*last_layout_node).text_for_rendering().length() - 1; + if (is(*last_layout_node)) + last_layout_node_index_in_node = downcast(*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(); @@ -369,16 +369,16 @@ bool InProcessWebView::load(const URL& url) return page().main_frame().loader().load(url, FrameLoader::Type::Navigation); } -const LayoutDocument* InProcessWebView::layout_root() const +const Layout::InitialContainingBlockBox* InProcessWebView::layout_root() const { return document() ? document()->layout_node() : nullptr; } -LayoutDocument* InProcessWebView::layout_root() +Layout::InitialContainingBlockBox* InProcessWebView::layout_root() { if (!document()) return nullptr; - return const_cast(document()->layout_node()); + return const_cast(document()->layout_node()); } void InProcessWebView::page_did_request_scroll_into_view(const Gfx::IntRect& rect) diff --git a/Libraries/LibWeb/InProcessWebView.h b/Libraries/LibWeb/InProcessWebView.h index e84778a2a54..7194836b9d4 100644 --- a/Libraries/LibWeb/InProcessWebView.h +++ b/Libraries/LibWeb/InProcessWebView.h @@ -51,8 +51,8 @@ public: void set_document(DOM::Document*); - const LayoutDocument* layout_root() const; - LayoutDocument* layout_root(); + const Layout::InitialContainingBlockBox* layout_root() const; + Layout::InitialContainingBlockBox* layout_root(); void reload(); bool load(const URL&); diff --git a/Libraries/LibWeb/Layout/LayoutBlock.cpp b/Libraries/LibWeb/Layout/BlockBox.cpp similarity index 78% rename from Libraries/LibWeb/Layout/LayoutBlock.cpp rename to Libraries/LibWeb/Layout/BlockBox.cpp index b3b85ed9310..54799bcbb45 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.cpp +++ b/Libraries/LibWeb/Layout/BlockBox.cpp @@ -28,40 +28,40 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include -namespace Web { +namespace Web::Layout { -LayoutBlock::LayoutBlock(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) - : LayoutBox(document, node, move(style)) +BlockBox::BlockBox(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) + : Box(document, node, move(style)) { } -LayoutBlock::~LayoutBlock() +BlockBox::~BlockBox() { } -LayoutNode& LayoutBlock::inline_wrapper() +Node& BlockBox::inline_wrapper() { if (!last_child() || !last_child()->is_block() || last_child()->dom_node() != nullptr) { - append_child(adopt(*new LayoutBlock(document(), nullptr, style_for_anonymous_block()))); + append_child(adopt(*new BlockBox(document(), nullptr, style_for_anonymous_block()))); last_child()->set_children_are_inline(true); } return *last_child(); } -void LayoutBlock::paint(PaintContext& context, PaintPhase phase) +void BlockBox::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; - LayoutBox::paint(context, phase); + Box::paint(context, phase); // FIXME: Inline backgrounds etc. if (phase == PaintPhase::Foreground) { @@ -94,19 +94,19 @@ void LayoutBlock::paint(PaintContext& context, PaintPhase phase) } } -HitTestResult LayoutBlock::hit_test(const Gfx::IntPoint& position, HitTestType type) const +HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type) const { if (!children_are_inline()) - return LayoutBox::hit_test(position, type); + return Box::hit_test(position, type); HitTestResult last_good_candidate; for (auto& line_box : m_line_boxes) { for (auto& fragment : line_box.fragments()) { - if (is(fragment.layout_node()) && downcast(fragment.layout_node()).stacking_context()) + if (is(fragment.layout_node()) && downcast(fragment.layout_node()).stacking_context()) continue; if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) { if (fragment.layout_node().is_block()) - return downcast(fragment.layout_node()).hit_test(position, type); + return downcast(fragment.layout_node()).hit_test(position, type); return { fragment.layout_node(), fragment.text_index_at(position.x()) }; } if (fragment.absolute_rect().top() <= position.y()) @@ -119,7 +119,7 @@ HitTestResult LayoutBlock::hit_test(const Gfx::IntPoint& position, HitTestType t return { absolute_rect().contains(position.x(), position.y()) ? this : nullptr }; } -NonnullRefPtr LayoutBlock::style_for_anonymous_block() const +NonnullRefPtr BlockBox::style_for_anonymous_block() const { auto new_style = CSS::StyleProperties::create(); @@ -131,7 +131,7 @@ NonnullRefPtr LayoutBlock::style_for_anonymous_block() con return new_style; } -void LayoutBlock::split_into_lines(LayoutBlock& container, LayoutMode layout_mode) +void BlockBox::split_into_lines(BlockBox& container, LayoutMode layout_mode) { auto* line_box = &container.ensure_last_line_box(); if (layout_mode != LayoutMode::OnlyRequiredLineBreaks && line_box->width() > 0 && line_box->width() + width() > container.width()) { diff --git a/Libraries/LibWeb/Layout/LayoutBlock.h b/Libraries/LibWeb/Layout/BlockBox.h similarity index 68% rename from Libraries/LibWeb/Layout/LayoutBlock.h rename to Libraries/LibWeb/Layout/BlockBox.h index 7e5c4341c24..4234dcd39a1 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.h +++ b/Libraries/LibWeb/Layout/BlockBox.h @@ -26,35 +26,35 @@ #pragma once -#include +#include #include -namespace Web { +namespace Web::Layout { -class LayoutBlock : public LayoutBox { +class BlockBox : public Box { public: - LayoutBlock(DOM::Document&, DOM::Node*, NonnullRefPtr); - virtual ~LayoutBlock() override; + BlockBox(DOM::Document&, DOM::Node*, NonnullRefPtr); + virtual ~BlockBox() override; - virtual const char* class_name() const override { return "LayoutBlock"; } + virtual const char* class_name() const override { return "BlockBox"; } virtual void paint(PaintContext&, PaintPhase) override; - virtual LayoutNode& inline_wrapper() override; + virtual Node& inline_wrapper() override; virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override; - LayoutBlock* previous_sibling() { return downcast(LayoutNode::previous_sibling()); } - const LayoutBlock* previous_sibling() const { return downcast(LayoutNode::previous_sibling()); } - LayoutBlock* next_sibling() { return downcast(LayoutNode::next_sibling()); } - const LayoutBlock* next_sibling() const { return downcast(LayoutNode::next_sibling()); } + BlockBox* previous_sibling() { return downcast(Node::previous_sibling()); } + const BlockBox* previous_sibling() const { return downcast(Node::previous_sibling()); } + BlockBox* next_sibling() { return downcast(Node::next_sibling()); } + const BlockBox* next_sibling() const { return downcast(Node::next_sibling()); } template void for_each_fragment(Callback); template void for_each_fragment(Callback) const; - virtual void split_into_lines(LayoutBlock& container, LayoutMode) override; + virtual void split_into_lines(BlockBox& container, LayoutMode) override; private: virtual bool is_block() const override { return true; } @@ -63,7 +63,7 @@ private: }; template -void LayoutBlock::for_each_fragment(Callback callback) +void BlockBox::for_each_fragment(Callback callback) { for (auto& line_box : line_boxes()) { for (auto& fragment : line_box.fragments()) { @@ -74,7 +74,7 @@ void LayoutBlock::for_each_fragment(Callback callback) } template -void LayoutBlock::for_each_fragment(Callback callback) const +void BlockBox::for_each_fragment(Callback callback) const { for (auto& line_box : line_boxes()) { for (auto& fragment : line_box.fragments()) { @@ -86,6 +86,6 @@ void LayoutBlock::for_each_fragment(Callback callback) const } -AK_BEGIN_TYPE_TRAITS(Web::LayoutBlock) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_block(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::BlockBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_block(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 3c22fc1d529..5f1483e0434 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -26,18 +26,18 @@ #include #include +#include #include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include #include namespace Web::Layout { -BlockFormattingContext::BlockFormattingContext(LayoutBox& context_box) +BlockFormattingContext::BlockFormattingContext(Box& context_box) : FormattingContext(context_box) { } @@ -79,11 +79,11 @@ void BlockFormattingContext::run(LayoutMode layout_mode) layout_absolutely_positioned_descendants(); } -void BlockFormattingContext::compute_width(LayoutBox& box) +void BlockFormattingContext::compute_width(Box& box) { if (box.is_replaced()) { - // FIXME: This should not be done *by* LayoutReplaced - auto& replaced = downcast(box); + // FIXME: This should not be done *by* ReplacedBox + auto& replaced = downcast(box); replaced.prepare_for_replaced_layout(); auto width = replaced.calculate_width(); replaced.set_width(width); @@ -214,7 +214,7 @@ void BlockFormattingContext::compute_width(LayoutBox& box) box.box_model().padding.right = padding_right; } -void BlockFormattingContext::compute_width_for_absolutely_positioned_block(LayoutBox& box) +void BlockFormattingContext::compute_width_for_absolutely_positioned_block(Box& box) { auto& containing_block = context_box(); auto& style = box.style(); @@ -354,11 +354,11 @@ void BlockFormattingContext::compute_width_for_absolutely_positioned_block(Layou box.box_model().padding.right = padding_right; } -void BlockFormattingContext::compute_height(LayoutBox& box) +void BlockFormattingContext::compute_height(Box& box) { if (box.is_replaced()) { - // FIXME: This should not be done *by* LayoutReplaced - auto height = downcast(box).calculate_height(); + // FIXME: This should not be done *by* ReplacedBox + auto height = downcast(box).calculate_height(); box.set_height(height); return; } @@ -402,7 +402,7 @@ void BlockFormattingContext::layout_block_level_children(LayoutMode layout_mode) float content_height = 0; float content_width = 0; - context_box().for_each_in_subtree_of_type([&](auto& box) { + context_box().for_each_in_subtree_of_type([&](auto& box) { if (box.is_absolutely_positioned() || box.containing_block() != &context_box()) return IterationDecision::Continue; @@ -415,15 +415,15 @@ void BlockFormattingContext::layout_block_level_children(LayoutMode layout_mode) else if (box.is_block()) place_block_level_non_replaced_element_in_normal_flow(box); else - dbgln("FIXME: LayoutBlock::layout_contained_boxes doesn't know how to place a {}", box.class_name()); + dbgln("FIXME: Layout::BlockBox::layout_contained_boxes doesn't know how to place a {}", box.class_name()); // 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(box)) - downcast(box).layout_marker(); + if (is(box)) + downcast(box).layout_marker(); content_height = max(content_height, box.effective_offset().y() + box.height() + box.box_model().margin_box(box).bottom); - content_width = max(content_width, downcast(box).width()); + content_width = max(content_width, downcast(box).width()); return IterationDecision::Continue; }); @@ -436,7 +436,7 @@ void BlockFormattingContext::layout_block_level_children(LayoutMode layout_mode) context_box().set_height(content_height); } -void BlockFormattingContext::place_block_level_replaced_element_in_normal_flow(LayoutBox& box) +void BlockFormattingContext::place_block_level_replaced_element_in_normal_flow(Box& box) { auto& containing_block = context_box(); ASSERT(!containing_block.is_absolutely_positioned()); @@ -459,7 +459,7 @@ void BlockFormattingContext::place_block_level_replaced_element_in_normal_flow(L box.set_offset(x, y); } -void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_flow(LayoutBox& box) +void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_flow(Box& box) { auto zero_value = CSS::Length::make_px(0); auto& containing_block = context_box(); @@ -488,7 +488,7 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl // NOTE: Empty (0-height) preceding siblings have their margins collapsed with *their* preceding sibling, etc. float collapsed_bottom_margin_of_preceding_siblings = 0; - auto* relevant_sibling = box.previous_sibling_of_type(); + auto* relevant_sibling = box.previous_sibling_of_type(); while (relevant_sibling != nullptr) { if (!relevant_sibling->is_absolutely_positioned() && !relevant_sibling->is_floating()) { collapsed_bottom_margin_of_preceding_siblings = max(collapsed_bottom_margin_of_preceding_siblings, relevant_sibling->box_model().margin.bottom.to_px(*relevant_sibling)); @@ -523,7 +523,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m { auto viewport_rect = context_box().frame().viewport_rect(); - auto& icb = downcast(context_box()); + auto& icb = downcast(context_box()); icb.build_stacking_context_tree(); icb.set_width(viewport_rect.width()); @@ -535,7 +535,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m // FIXME: The ICB should have the height of the viewport. // Instead of auto-sizing the ICB, we should spill into overflow. float lowest_bottom = 0; - icb.for_each_child_of_type([&](auto& child) { + icb.for_each_child_of_type([&](auto& child) { lowest_bottom = max(lowest_bottom, child.absolute_rect().bottom()); }); icb.set_height(lowest_bottom); @@ -546,7 +546,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m // FIXME: This is a total hack. Make sure any GUI::Widgets are moved into place after layout. // We should stop embedding GUI::Widgets entirely, since that won't work out-of-process. - icb.for_each_in_subtree_of_type([&](auto& widget) { + icb.for_each_in_subtree_of_type([&](auto& widget) { widget.update_widget(); return IterationDecision::Continue; }); @@ -554,7 +554,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m void BlockFormattingContext::layout_absolutely_positioned_descendants() { - context_box().for_each_in_subtree_of_type([&](auto& box) { + context_box().for_each_in_subtree_of_type([&](auto& box) { if (box.is_absolutely_positioned() && box.containing_block() == &context_box()) { layout_absolutely_positioned_descendant(box); } @@ -562,7 +562,7 @@ void BlockFormattingContext::layout_absolutely_positioned_descendants() }); } -void BlockFormattingContext::layout_absolutely_positioned_descendant(LayoutBox& box) +void BlockFormattingContext::layout_absolutely_positioned_descendant(Box& box) { auto& containing_block = context_box(); auto& box_model = box.box_model(); diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Libraries/LibWeb/Layout/BlockFormattingContext.h index 88b2773ecd5..6b58129899e 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.h +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.h @@ -33,7 +33,7 @@ namespace Web::Layout { class BlockFormattingContext : public FormattingContext { public: - explicit BlockFormattingContext(LayoutBox& containing_block); + explicit BlockFormattingContext(Box& containing_block); ~BlockFormattingContext(); virtual void run(LayoutMode) override; @@ -41,21 +41,21 @@ public: bool is_initial() const; protected: - void compute_width(LayoutBox&); - void compute_height(LayoutBox&); + void compute_width(Box&); + void compute_height(Box&); private: - void compute_width_for_absolutely_positioned_block(LayoutBox&); + void compute_width_for_absolutely_positioned_block(Box&); void layout_initial_containing_block(LayoutMode); void layout_block_level_children(LayoutMode); void layout_inline_children(LayoutMode); void layout_absolutely_positioned_descendants(); - void place_block_level_replaced_element_in_normal_flow(LayoutBox&); - void place_block_level_non_replaced_element_in_normal_flow(LayoutBox&); + void place_block_level_replaced_element_in_normal_flow(Box&); + void place_block_level_non_replaced_element_in_normal_flow(Box&); - void layout_absolutely_positioned_descendant(LayoutBox&); + void layout_absolutely_positioned_descendant(Box&); }; } diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/Box.cpp similarity index 90% rename from Libraries/LibWeb/Layout/LayoutBox.cpp rename to Libraries/LibWeb/Layout/Box.cpp index 2935363896c..09d3ea4bbe9 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/Box.cpp @@ -27,13 +27,13 @@ #include #include #include -#include -#include +#include +#include #include -namespace Web { +namespace Web::Layout { -void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, const BorderData& border_data) +void Box::paint_border(PaintContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, const BorderData& border_data) { float width = border_data.width; if (width <= 0) @@ -162,7 +162,7 @@ void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatR } } -void LayoutBox::paint(PaintContext& context, PaintPhase phase) +void Box::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; @@ -206,7 +206,7 @@ void LayoutBox::paint(PaintContext& context, PaintPhase phase) paint_border(context, Edge::Bottom, bordered_rect, CSS::PropertyID::BorderBottomStyle, style().border_bottom()); } - LayoutNodeWithStyleAndBoxModelMetrics::paint(context, phase); + Layout::NodeWithStyleAndBoxModelMetrics::paint(context, phase); if (phase == PaintPhase::Overlay && dom_node() && document().inspected_node() == dom_node()) { auto content_rect = absolute_rect(); @@ -228,14 +228,14 @@ void LayoutBox::paint(PaintContext& context, PaintPhase phase) } } -HitTestResult LayoutBox::hit_test(const Gfx::IntPoint& position, HitTestType type) const +HitTestResult Box::hit_test(const Gfx::IntPoint& position, HitTestType type) const { // FIXME: It would be nice if we could confidently skip over hit testing // parts of the layout tree, but currently we can't just check // m_rect.contains() since inline text rects can't be trusted.. HitTestResult result { absolute_rect().contains(position.x(), position.y()) ? this : nullptr }; for_each_child([&](auto& child) { - if (is(child) && downcast(child).stacking_context()) + if (is(child) && downcast(child).stacking_context()) return; auto child_result = child.hit_test(position, type); if (child_result.layout_node) @@ -244,22 +244,22 @@ HitTestResult LayoutBox::hit_test(const Gfx::IntPoint& position, HitTestType typ return result; } -void LayoutBox::set_needs_display() +void Box::set_needs_display() { if (!is_inline()) { frame().set_needs_display(enclosing_int_rect(absolute_rect())); return; } - LayoutNode::set_needs_display(); + Node::set_needs_display(); } -bool LayoutBox::is_body() const +bool Box::is_body() const { return dom_node() && dom_node() == document().body(); } -void LayoutBox::set_offset(const Gfx::FloatPoint& offset) +void Box::set_offset(const Gfx::FloatPoint& offset) { if (m_offset == offset) return; @@ -267,7 +267,7 @@ void LayoutBox::set_offset(const Gfx::FloatPoint& offset) did_set_rect(); } -void LayoutBox::set_size(const Gfx::FloatSize& size) +void Box::set_size(const Gfx::FloatSize& size) { if (m_size == size) return; @@ -275,14 +275,14 @@ void LayoutBox::set_size(const Gfx::FloatSize& size) did_set_rect(); } -Gfx::FloatPoint LayoutBox::effective_offset() const +Gfx::FloatPoint Box::effective_offset() const { if (m_containing_line_box_fragment) return m_containing_line_box_fragment->offset(); return m_offset; } -const Gfx::FloatRect LayoutBox::absolute_rect() const +const Gfx::FloatRect Box::absolute_rect() const { Gfx::FloatRect rect { effective_offset(), size() }; for (auto* block = containing_block(); block; block = block->containing_block()) { @@ -291,27 +291,27 @@ const Gfx::FloatRect LayoutBox::absolute_rect() const return rect; } -void LayoutBox::set_containing_line_box_fragment(LineBoxFragment& fragment) +void Box::set_containing_line_box_fragment(LineBoxFragment& fragment) { m_containing_line_box_fragment = fragment.make_weak_ptr(); } -StackingContext* LayoutBox::enclosing_stacking_context() +StackingContext* Box::enclosing_stacking_context() { for (auto* ancestor = parent(); ancestor; ancestor = ancestor->parent()) { if (!ancestor->is_box()) continue; - auto& ancestor_box = downcast(*ancestor); + auto& ancestor_box = downcast(*ancestor); if (!ancestor_box.establishes_stacking_context()) continue; ASSERT(ancestor_box.stacking_context()); return ancestor_box.stacking_context(); } - // We should always reach the LayoutDocument stacking context. + // We should always reach the Layout::InitialContainingBlockBox stacking context. ASSERT_NOT_REACHED(); } -bool LayoutBox::establishes_stacking_context() const +bool Box::establishes_stacking_context() const { if (!has_style()) return false; @@ -328,20 +328,20 @@ bool LayoutBox::establishes_stacking_context() const return false; } -LineBox& LayoutBox::ensure_last_line_box() +LineBox& Box::ensure_last_line_box() { if (m_line_boxes.is_empty()) return add_line_box(); return m_line_boxes.last(); } -LineBox& LayoutBox::add_line_box() +LineBox& Box::add_line_box() { m_line_boxes.append(LineBox()); return m_line_boxes.last(); } -float LayoutBox::width_of_logical_containing_block() const +float Box::width_of_logical_containing_block() const { auto* containing_block = this->containing_block(); ASSERT(containing_block); diff --git a/Libraries/LibWeb/Layout/LayoutBox.h b/Libraries/LibWeb/Layout/Box.h similarity index 90% rename from Libraries/LibWeb/Layout/LayoutBox.h rename to Libraries/LibWeb/Layout/Box.h index f5e971e6b0d..0354938e057 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.h +++ b/Libraries/LibWeb/Layout/Box.h @@ -28,13 +28,13 @@ #include #include -#include #include +#include #include -namespace Web { +namespace Web::Layout { -class LayoutBox : public LayoutNodeWithStyleAndBoxModelMetrics { +class Box : public NodeWithStyleAndBoxModelMetrics { public: const Gfx::FloatRect absolute_rect() const; @@ -80,8 +80,8 @@ public: virtual float width_of_logical_containing_block() const; protected: - LayoutBox(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) - : LayoutNodeWithStyleAndBoxModelMetrics(document, node, move(style)) + Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) + : NodeWithStyleAndBoxModelMetrics(document, node, move(style)) { } @@ -111,6 +111,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutBox) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_box(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::Box) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_box(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/BoxModelMetrics.cpp b/Libraries/LibWeb/Layout/BoxModelMetrics.cpp index 1cd0ac430d3..0a1702d93cb 100644 --- a/Libraries/LibWeb/Layout/BoxModelMetrics.cpp +++ b/Libraries/LibWeb/Layout/BoxModelMetrics.cpp @@ -26,9 +26,9 @@ #include -namespace Web { +namespace Web::Layout { -PixelBox BoxModelMetrics::margin_box(const LayoutNode& layout_node) const +PixelBox BoxModelMetrics::margin_box(const Node& layout_node) const { return { margin.top.to_px(layout_node) + border.top.to_px(layout_node) + padding.top.to_px(layout_node), @@ -38,7 +38,7 @@ PixelBox BoxModelMetrics::margin_box(const LayoutNode& layout_node) const }; } -PixelBox BoxModelMetrics::padding_box(const LayoutNode& layout_node) const +PixelBox BoxModelMetrics::padding_box(const Node& layout_node) const { return { padding.top.to_px(layout_node), @@ -48,7 +48,7 @@ PixelBox BoxModelMetrics::padding_box(const LayoutNode& layout_node) const }; } -PixelBox BoxModelMetrics::border_box(const LayoutNode& layout_node) const +PixelBox BoxModelMetrics::border_box(const Node& layout_node) const { return { border.top.to_px(layout_node) + padding.top.to_px(layout_node), diff --git a/Libraries/LibWeb/Layout/BoxModelMetrics.h b/Libraries/LibWeb/Layout/BoxModelMetrics.h index 5e564334360..f5b5bed30ca 100644 --- a/Libraries/LibWeb/Layout/BoxModelMetrics.h +++ b/Libraries/LibWeb/Layout/BoxModelMetrics.h @@ -29,7 +29,7 @@ #include #include -namespace Web { +namespace Web::Layout { struct PixelBox { float top; @@ -45,9 +45,9 @@ public: CSS::LengthBox border; CSS::LengthBox offset; - PixelBox margin_box(const LayoutNode&) const; - PixelBox padding_box(const LayoutNode&) const; - PixelBox border_box(const LayoutNode&) const; + PixelBox margin_box(const Node&) const; + PixelBox padding_box(const Node&) const; + PixelBox border_box(const Node&) const; }; } diff --git a/Libraries/LibWeb/Layout/LayoutBreak.cpp b/Libraries/LibWeb/Layout/BreakNode.cpp similarity index 80% rename from Libraries/LibWeb/Layout/LayoutBreak.cpp rename to Libraries/LibWeb/Layout/BreakNode.cpp index 5fd401892f0..0a230a98731 100644 --- a/Libraries/LibWeb/Layout/LayoutBreak.cpp +++ b/Libraries/LibWeb/Layout/BreakNode.cpp @@ -24,22 +24,22 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include +#include -namespace Web { +namespace Web::Layout { -LayoutBreak::LayoutBreak(DOM::Document& document, HTML::HTMLBRElement& element) - : LayoutNodeWithStyleAndBoxModelMetrics(document, &element, CSS::StyleProperties::create()) +BreakNode::BreakNode(DOM::Document& document, HTML::HTMLBRElement& element) + : Layout::NodeWithStyleAndBoxModelMetrics(document, &element, CSS::StyleProperties::create()) { set_inline(true); } -LayoutBreak::~LayoutBreak() +BreakNode::~BreakNode() { } -void LayoutBreak::split_into_lines(LayoutBlock& block, LayoutMode) +void BreakNode::split_into_lines(BlockBox& block, LayoutMode) { block.add_line_box(); } diff --git a/Libraries/LibWeb/Layout/LayoutBreak.h b/Libraries/LibWeb/Layout/BreakNode.h similarity index 74% rename from Libraries/LibWeb/Layout/LayoutBreak.h rename to Libraries/LibWeb/Layout/BreakNode.h index 076c6751095..07ecb6926fc 100644 --- a/Libraries/LibWeb/Layout/LayoutBreak.h +++ b/Libraries/LibWeb/Layout/BreakNode.h @@ -27,25 +27,25 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutBreak final : public LayoutNodeWithStyleAndBoxModelMetrics { +class BreakNode final : public NodeWithStyleAndBoxModelMetrics { public: - LayoutBreak(DOM::Document&, HTML::HTMLBRElement&); - virtual ~LayoutBreak() override; + BreakNode(DOM::Document&, HTML::HTMLBRElement&); + virtual ~BreakNode() override; - const HTML::HTMLBRElement& dom_node() const { return downcast(*LayoutNode::dom_node()); } + const HTML::HTMLBRElement& dom_node() const { return downcast(*Node::dom_node()); } private: virtual bool is_break() const override { return true; } - virtual const char* class_name() const override { return "LayoutBreak"; } - virtual void split_into_lines(LayoutBlock&, LayoutMode) override; + virtual const char* class_name() const override { return "BreakNode"; } + virtual void split_into_lines(BlockBox&, LayoutMode) override; }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutBreak) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_break(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::BreakNode) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_break(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutButton.cpp b/Libraries/LibWeb/Layout/ButtonBox.cpp similarity index 82% rename from Libraries/LibWeb/Layout/LayoutButton.cpp rename to Libraries/LibWeb/Layout/ButtonBox.cpp index d7533e63d6a..4ceaa87e8da 100644 --- a/Libraries/LibWeb/Layout/LayoutButton.cpp +++ b/Libraries/LibWeb/Layout/ButtonBox.cpp @@ -29,21 +29,21 @@ #include #include #include -#include +#include #include -namespace Web { +namespace Web::Layout { -LayoutButton::LayoutButton(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr style) - : LayoutReplaced(document, element, move(style)) +ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr style) + : ReplacedBox(document, element, move(style)) { } -LayoutButton::~LayoutButton() +ButtonBox::~ButtonBox() { } -void LayoutButton::prepare_for_replaced_layout() +void ButtonBox::prepare_for_replaced_layout() { auto& font = specified_style().font(); set_intrinsic_width(font.width(dom_node().value()) + 20); @@ -53,12 +53,12 @@ void LayoutButton::prepare_for_replaced_layout() set_has_intrinsic_height(true); } -void LayoutButton::paint(PaintContext& context, PaintPhase phase) +void ButtonBox::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; - LayoutReplaced::paint(context, phase); + ReplacedBox::paint(context, phase); if (phase == PaintPhase::Foreground) { bool hovered = document().hovered_node() == &dom_node(); @@ -71,7 +71,7 @@ void LayoutButton::paint(PaintContext& context, PaintPhase phase) } } -void LayoutButton::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned) +void ButtonBox::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned) { if (button != GUI::MouseButton::Left || !dom_node().enabled()) return; @@ -83,7 +83,7 @@ void LayoutButton::handle_mousedown(Badge, const Gfx::IntPoint&, u frame().event_handler().set_mouse_event_tracking_layout_node(this); } -void LayoutButton::handle_mouseup(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) +void ButtonBox::handle_mouseup(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) { if (!m_tracking_mouse || button != GUI::MouseButton::Left || !dom_node().enabled()) return; @@ -102,7 +102,7 @@ void LayoutButton::handle_mouseup(Badge, const Gfx::IntPoint& posi protected_frame->event_handler().set_mouse_event_tracking_layout_node(nullptr); } -void LayoutButton::handle_mousemove(Badge, const Gfx::IntPoint& position, unsigned, unsigned) +void ButtonBox::handle_mousemove(Badge, const Gfx::IntPoint& position, unsigned, unsigned) { if (!m_tracking_mouse || !dom_node().enabled()) return; diff --git a/Libraries/LibWeb/Layout/LayoutButton.h b/Libraries/LibWeb/Layout/ButtonBox.h similarity index 80% rename from Libraries/LibWeb/Layout/LayoutButton.h rename to Libraries/LibWeb/Layout/ButtonBox.h index 5d6fa36b74e..35cc336fc47 100644 --- a/Libraries/LibWeb/Layout/LayoutButton.h +++ b/Libraries/LibWeb/Layout/ButtonBox.h @@ -27,23 +27,23 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutButton : public LayoutReplaced { +class ButtonBox : public ReplacedBox { public: - LayoutButton(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr); - virtual ~LayoutButton() override; + ButtonBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr); + virtual ~ButtonBox() override; virtual void prepare_for_replaced_layout() override; virtual void paint(PaintContext&, PaintPhase) override; - const HTML::HTMLInputElement& dom_node() const { return static_cast(LayoutReplaced::dom_node()); } - HTML::HTMLInputElement& dom_node() { return static_cast(LayoutReplaced::dom_node()); } + const HTML::HTMLInputElement& dom_node() const { return static_cast(ReplacedBox::dom_node()); } + HTML::HTMLInputElement& dom_node() { return static_cast(ReplacedBox::dom_node()); } private: - virtual const char* class_name() const override { return "LayoutButton"; } + virtual const char* class_name() const override { return "ButtonBox"; } virtual bool is_button() const override { return true; } virtual bool wants_mouse_events() const override { return true; } virtual void handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; @@ -56,6 +56,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutButton) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_button(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::ButtonBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_button(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutCanvas.cpp b/Libraries/LibWeb/Layout/CanvasBox.cpp similarity index 83% rename from Libraries/LibWeb/Layout/LayoutCanvas.cpp rename to Libraries/LibWeb/Layout/CanvasBox.cpp index 9a5cca4c82f..c1eb048ace7 100644 --- a/Libraries/LibWeb/Layout/LayoutCanvas.cpp +++ b/Libraries/LibWeb/Layout/CanvasBox.cpp @@ -27,20 +27,20 @@ #include #include #include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutCanvas::LayoutCanvas(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr style) - : LayoutReplaced(document, element, move(style)) +CanvasBox::CanvasBox(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr style) + : ReplacedBox(document, element, move(style)) { } -LayoutCanvas::~LayoutCanvas() +CanvasBox::~CanvasBox() { } -void LayoutCanvas::prepare_for_replaced_layout() +void CanvasBox::prepare_for_replaced_layout() { set_has_intrinsic_width(true); set_has_intrinsic_height(true); @@ -48,12 +48,12 @@ void LayoutCanvas::prepare_for_replaced_layout() set_intrinsic_height(dom_node().height()); } -void LayoutCanvas::paint(PaintContext& context, PaintPhase phase) +void CanvasBox::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; - LayoutReplaced::paint(context, phase); + ReplacedBox::paint(context, phase); if (phase == PaintPhase::Foreground) { // FIXME: This should be done at a different level. Also rect() does not include padding etc! diff --git a/Libraries/LibWeb/Layout/LayoutCanvas.h b/Libraries/LibWeb/Layout/CanvasBox.h similarity index 77% rename from Libraries/LibWeb/Layout/LayoutCanvas.h rename to Libraries/LibWeb/Layout/CanvasBox.h index 7f2d8220c22..16c1110724d 100644 --- a/Libraries/LibWeb/Layout/LayoutCanvas.h +++ b/Libraries/LibWeb/Layout/CanvasBox.h @@ -27,27 +27,27 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutCanvas : public LayoutReplaced { +class CanvasBox : public ReplacedBox { public: - LayoutCanvas(DOM::Document&, HTML::HTMLCanvasElement&, NonnullRefPtr); - virtual ~LayoutCanvas() override; + CanvasBox(DOM::Document&, HTML::HTMLCanvasElement&, NonnullRefPtr); + virtual ~CanvasBox() override; virtual void prepare_for_replaced_layout() override; virtual void paint(PaintContext&, PaintPhase) override; - const HTML::HTMLCanvasElement& dom_node() const { return static_cast(LayoutReplaced::dom_node()); } + const HTML::HTMLCanvasElement& dom_node() const { return static_cast(ReplacedBox::dom_node()); } private: - virtual const char* class_name() const override { return "LayoutCanvas"; } + virtual const char* class_name() const override { return "CanvasBox"; } virtual bool is_canvas() const override { return true; } }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutCanvas) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_canvas(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::CanvasBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_canvas(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutCheckBox.cpp b/Libraries/LibWeb/Layout/CheckBox.cpp similarity index 80% rename from Libraries/LibWeb/Layout/LayoutCheckBox.cpp rename to Libraries/LibWeb/Layout/CheckBox.cpp index 6ba9f18585d..a259e4f2d5e 100644 --- a/Libraries/LibWeb/Layout/LayoutCheckBox.cpp +++ b/Libraries/LibWeb/Layout/CheckBox.cpp @@ -28,13 +28,13 @@ #include #include #include -#include +#include #include -namespace Web { +namespace Web::Layout { -LayoutCheckBox::LayoutCheckBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr style) - : LayoutReplaced(document, element, move(style)) +CheckBox::CheckBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr style) + : ReplacedBox(document, element, move(style)) { set_has_intrinsic_width(true); set_has_intrinsic_height(true); @@ -42,23 +42,23 @@ LayoutCheckBox::LayoutCheckBox(DOM::Document& document, HTML::HTMLInputElement& set_intrinsic_height(13); } -LayoutCheckBox::~LayoutCheckBox() +CheckBox::~CheckBox() { } -void LayoutCheckBox::paint(PaintContext& context, PaintPhase phase) +void CheckBox::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; - LayoutReplaced::paint(context, phase); + ReplacedBox::paint(context, phase); if (phase == PaintPhase::Foreground) { Gfx::StylePainter::paint_check_box(context.painter(), enclosing_int_rect(absolute_rect()), context.palette(), dom_node().enabled(), dom_node().checked(), m_being_pressed); } } -void LayoutCheckBox::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned) +void CheckBox::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned) { if (button != GUI::MouseButton::Left || !dom_node().enabled()) return; @@ -70,7 +70,7 @@ void LayoutCheckBox::handle_mousedown(Badge, const Gfx::IntPoint&, frame().event_handler().set_mouse_event_tracking_layout_node(this); } -void LayoutCheckBox::handle_mouseup(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) +void CheckBox::handle_mouseup(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) { if (!m_tracking_mouse || button != GUI::MouseButton::Left || !dom_node().enabled()) return; @@ -87,7 +87,7 @@ void LayoutCheckBox::handle_mouseup(Badge, const Gfx::IntPoint& po frame().event_handler().set_mouse_event_tracking_layout_node(nullptr); } -void LayoutCheckBox::handle_mousemove(Badge, const Gfx::IntPoint& position, unsigned, unsigned) +void CheckBox::handle_mousemove(Badge, const Gfx::IntPoint& position, unsigned, unsigned) { if (!m_tracking_mouse || !dom_node().enabled()) return; diff --git a/Libraries/LibWeb/Layout/LayoutCheckBox.h b/Libraries/LibWeb/Layout/CheckBox.h similarity index 79% rename from Libraries/LibWeb/Layout/LayoutCheckBox.h rename to Libraries/LibWeb/Layout/CheckBox.h index 1e4482a5795..f078952a60f 100644 --- a/Libraries/LibWeb/Layout/LayoutCheckBox.h +++ b/Libraries/LibWeb/Layout/CheckBox.h @@ -27,22 +27,22 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutCheckBox : public LayoutReplaced { +class CheckBox : public ReplacedBox { public: - LayoutCheckBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr); - virtual ~LayoutCheckBox() override; + CheckBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr); + virtual ~CheckBox() override; virtual void paint(PaintContext&, PaintPhase) override; - const HTML::HTMLInputElement& dom_node() const { return static_cast(LayoutReplaced::dom_node()); } - HTML::HTMLInputElement& dom_node() { return static_cast(LayoutReplaced::dom_node()); } + const HTML::HTMLInputElement& dom_node() const { return static_cast(ReplacedBox::dom_node()); } + HTML::HTMLInputElement& dom_node() { return static_cast(ReplacedBox::dom_node()); } private: - virtual const char* class_name() const override { return "LayoutCheckBox"; } + virtual const char* class_name() const override { return "CheckBox"; } virtual bool is_check_box() const override { return true; } virtual bool wants_mouse_events() const override { return true; } virtual void handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; @@ -55,6 +55,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutCheckBox) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_check_box(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::CheckBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_check_box(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/FormattingContext.cpp b/Libraries/LibWeb/Layout/FormattingContext.cpp index 1b525028135..05059e90b76 100644 --- a/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -25,14 +25,14 @@ */ #include +#include #include #include -#include #include namespace Web::Layout { -FormattingContext::FormattingContext(LayoutBox& context_box) +FormattingContext::FormattingContext(Box& context_box) : m_context_box(context_box) { } @@ -41,7 +41,7 @@ FormattingContext::~FormattingContext() { } -void FormattingContext::layout_inside(LayoutBox& box, LayoutMode layout_mode) +void FormattingContext::layout_inside(Box& box, LayoutMode layout_mode) { if (box.is_table()) { TableFormattingContext context(box); @@ -55,7 +55,7 @@ void FormattingContext::layout_inside(LayoutBox& box, LayoutMode layout_mode) } } -static float greatest_child_width(const LayoutBox& box) +static float greatest_child_width(const Box& box) { float max_width = 0; if (box.children_are_inline()) { @@ -63,14 +63,14 @@ static float greatest_child_width(const LayoutBox& box) max_width = max(max_width, child.width()); } } else { - box.for_each_child_of_type([&](auto& child) { + box.for_each_child_of_type([&](auto& child) { max_width = max(max_width, child.width()); }); } return max_width; } -FormattingContext::ShrinkToFitResult FormattingContext::calculate_shrink_to_fit_widths(LayoutBox& box) +FormattingContext::ShrinkToFitResult FormattingContext::calculate_shrink_to_fit_widths(Box& box) { // Calculate the preferred width by formatting the content without breaking lines // other than where explicit line breaks occur. diff --git a/Libraries/LibWeb/Layout/FormattingContext.h b/Libraries/LibWeb/Layout/FormattingContext.h index 217b3af3aa3..8885fb3ba29 100644 --- a/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Libraries/LibWeb/Layout/FormattingContext.h @@ -34,23 +34,23 @@ class FormattingContext { public: virtual void run(LayoutMode) = 0; - LayoutBox& context_box() { return m_context_box; } - const LayoutBox& context_box() const { return m_context_box; } + Box& context_box() { return m_context_box; } + const Box& context_box() const { return m_context_box; } protected: - FormattingContext(LayoutBox&); + FormattingContext(Box&); virtual ~FormattingContext(); - static void layout_inside(LayoutBox&, LayoutMode); + static void layout_inside(Box&, LayoutMode); struct ShrinkToFitResult { float preferred_width { 0 }; float preferred_minimum_width { 0 }; }; - ShrinkToFitResult calculate_shrink_to_fit_widths(LayoutBox&); + ShrinkToFitResult calculate_shrink_to_fit_widths(Box&); - LayoutBox& m_context_box; + Box& m_context_box; }; } diff --git a/Libraries/LibWeb/Layout/LayoutFrame.cpp b/Libraries/LibWeb/Layout/FrameBox.cpp similarity index 83% rename from Libraries/LibWeb/Layout/LayoutFrame.cpp rename to Libraries/LibWeb/Layout/FrameBox.cpp index ccd3666c8ac..fb475014e85 100644 --- a/Libraries/LibWeb/Layout/LayoutFrame.cpp +++ b/Libraries/LibWeb/Layout/FrameBox.cpp @@ -31,24 +31,24 @@ #include #include #include -#include -#include +#include +#include #include //#define DEBUG_HIGHLIGHT_FOCUSED_FRAME -namespace Web { +namespace Web::Layout { -LayoutFrame::LayoutFrame(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutReplaced(document, element, move(style)) +FrameBox::FrameBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : ReplacedBox(document, element, move(style)) { } -LayoutFrame::~LayoutFrame() +FrameBox::~FrameBox() { } -void LayoutFrame::prepare_for_replaced_layout() +void FrameBox::prepare_for_replaced_layout() { ASSERT(dom_node().content_frame()); @@ -59,9 +59,9 @@ void LayoutFrame::prepare_for_replaced_layout() set_intrinsic_height(dom_node().attribute(HTML::AttributeNames::height).to_int().value_or(150)); } -void LayoutFrame::paint(PaintContext& context, PaintPhase phase) +void FrameBox::paint(PaintContext& context, PaintPhase phase) { - LayoutReplaced::paint(context, phase); + ReplacedBox::paint(context, phase); if (phase == PaintPhase::Foreground) { auto* hosted_document = dom_node().content_document(); @@ -78,7 +78,7 @@ void LayoutFrame::paint(PaintContext& context, PaintPhase phase) context.painter().translate(absolute_x(), absolute_y()); context.set_viewport_rect({ {}, dom_node().content_frame()->size() }); - const_cast(hosted_layout_tree)->paint_all_phases(context); + const_cast(hosted_layout_tree)->paint_all_phases(context); context.set_viewport_rect(old_viewport_rect); context.painter().restore(); @@ -91,9 +91,9 @@ void LayoutFrame::paint(PaintContext& context, PaintPhase phase) } } -void LayoutFrame::did_set_rect() +void FrameBox::did_set_rect() { - LayoutReplaced::did_set_rect(); + ReplacedBox::did_set_rect(); ASSERT(dom_node().content_frame()); dom_node().content_frame()->set_size(size().to_type()); diff --git a/Libraries/LibWeb/Layout/LayoutFrame.h b/Libraries/LibWeb/Layout/FrameBox.h similarity index 77% rename from Libraries/LibWeb/Layout/LayoutFrame.h rename to Libraries/LibWeb/Layout/FrameBox.h index fa9be9bf1df..840430e4f6e 100644 --- a/Libraries/LibWeb/Layout/LayoutFrame.h +++ b/Libraries/LibWeb/Layout/FrameBox.h @@ -27,29 +27,29 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutFrame final : public LayoutReplaced { +class FrameBox final : public ReplacedBox { public: - LayoutFrame(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutFrame() override; + FrameBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~FrameBox() override; virtual void paint(PaintContext&, PaintPhase) override; virtual void prepare_for_replaced_layout() override; - const HTML::HTMLIFrameElement& dom_node() const { return downcast(LayoutReplaced::dom_node()); } - HTML::HTMLIFrameElement& dom_node() { return downcast(LayoutReplaced::dom_node()); } + const HTML::HTMLIFrameElement& dom_node() const { return downcast(ReplacedBox::dom_node()); } + HTML::HTMLIFrameElement& dom_node() { return downcast(ReplacedBox::dom_node()); } private: virtual bool is_frame() const final { return true; } - virtual const char* class_name() const override { return "LayoutFrame"; } + virtual const char* class_name() const override { return "FrameBox"; } virtual void did_set_rect() override; }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutFrame) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_frame(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::FrameBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_frame(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutImage.cpp b/Libraries/LibWeb/Layout/ImageBox.cpp similarity index 86% rename from Libraries/LibWeb/Layout/LayoutImage.cpp rename to Libraries/LibWeb/Layout/ImageBox.cpp index e3b89a0fc51..541dc7672a2 100644 --- a/Libraries/LibWeb/Layout/LayoutImage.cpp +++ b/Libraries/LibWeb/Layout/ImageBox.cpp @@ -28,31 +28,31 @@ #include #include #include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutImage::LayoutImage(DOM::Document& document, DOM::Element& element, NonnullRefPtr style, const ImageLoader& image_loader) - : LayoutReplaced(document, element, move(style)) +ImageBox::ImageBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style, const ImageLoader& image_loader) + : ReplacedBox(document, element, move(style)) , m_image_loader(image_loader) { } -LayoutImage::~LayoutImage() +ImageBox::~ImageBox() { } -int LayoutImage::preferred_width() const +int ImageBox::preferred_width() const { return dom_node().attribute(HTML::AttributeNames::width).to_int().value_or(m_image_loader.width()); } -int LayoutImage::preferred_height() const +int ImageBox::preferred_height() const { return dom_node().attribute(HTML::AttributeNames::height).to_int().value_or(m_image_loader.height()); } -void LayoutImage::prepare_for_replaced_layout() +void ImageBox::prepare_for_replaced_layout() { if (!m_image_loader.has_loaded_or_failed()) { set_has_intrinsic_width(true); @@ -93,7 +93,7 @@ void LayoutImage::prepare_for_replaced_layout() } } -void LayoutImage::paint(PaintContext& context, PaintPhase phase) +void ImageBox::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; @@ -102,7 +102,7 @@ void LayoutImage::paint(PaintContext& context, PaintPhase phase) if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect()))) return; - LayoutReplaced::paint(context, phase); + ReplacedBox::paint(context, phase); if (phase == PaintPhase::Foreground) { if (renders_as_alt_text()) { @@ -119,14 +119,14 @@ void LayoutImage::paint(PaintContext& context, PaintPhase phase) } } -bool LayoutImage::renders_as_alt_text() const +bool ImageBox::renders_as_alt_text() const { if (is(dom_node())) return !m_image_loader.has_image(); return false; } -void LayoutImage::set_visible_in_viewport(Badge, bool visible_in_viewport) +void ImageBox::set_visible_in_viewport(Badge, bool visible_in_viewport) { m_image_loader.set_visible_in_viewport(visible_in_viewport); } diff --git a/Libraries/LibWeb/Layout/LayoutImage.h b/Libraries/LibWeb/Layout/ImageBox.h similarity index 76% rename from Libraries/LibWeb/Layout/LayoutImage.h rename to Libraries/LibWeb/Layout/ImageBox.h index 3cbf29a19cb..38a1f89cbe6 100644 --- a/Libraries/LibWeb/Layout/LayoutImage.h +++ b/Libraries/LibWeb/Layout/ImageBox.h @@ -27,26 +27,26 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutImage : public LayoutReplaced { +class ImageBox : public ReplacedBox { public: - LayoutImage(DOM::Document&, DOM::Element&, NonnullRefPtr, const ImageLoader&); - virtual ~LayoutImage() override; + ImageBox(DOM::Document&, DOM::Element&, NonnullRefPtr, const ImageLoader&); + virtual ~ImageBox() override; virtual void prepare_for_replaced_layout() override; virtual void paint(PaintContext&, PaintPhase) override; - const DOM::Element& dom_node() const { return static_cast(LayoutReplaced::dom_node()); } + const DOM::Element& dom_node() const { return static_cast(ReplacedBox::dom_node()); } bool renders_as_alt_text() const; - void set_visible_in_viewport(Badge, bool); + void set_visible_in_viewport(Badge, bool); private: - virtual const char* class_name() const override { return "LayoutImage"; } + virtual const char* class_name() const override { return "ImageBox"; } virtual bool is_image() const override { return true; } int preferred_width() const; @@ -57,6 +57,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutImage) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_image(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::ImageBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_image(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutDocument.cpp b/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp similarity index 74% rename from Libraries/LibWeb/Layout/LayoutDocument.cpp rename to Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp index 9a5b1b0632a..320f0f770c8 100644 --- a/Libraries/LibWeb/Layout/LayoutDocument.cpp +++ b/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp @@ -25,31 +25,31 @@ */ #include -#include -#include -#include +#include +#include +#include #include #include -namespace Web { +namespace Web::Layout { -LayoutDocument::LayoutDocument(DOM::Document& document, NonnullRefPtr style) - : LayoutBlock(document, &document, move(style)) +InitialContainingBlockBox::InitialContainingBlockBox(DOM::Document& document, NonnullRefPtr style) + : BlockBox(document, &document, move(style)) { } -LayoutDocument::~LayoutDocument() +InitialContainingBlockBox::~InitialContainingBlockBox() { } -void LayoutDocument::build_stacking_context_tree() +void InitialContainingBlockBox::build_stacking_context_tree() { if (stacking_context()) return; set_stacking_context(make(*this, nullptr)); - for_each_in_subtree_of_type([&](LayoutBox& box) { + for_each_in_subtree_of_type([&](Box& box) { if (&box == this) return IterationDecision::Continue; if (!box.establishes_stacking_context()) { @@ -63,16 +63,16 @@ void LayoutDocument::build_stacking_context_tree() }); } -void LayoutDocument::did_set_viewport_rect(Badge, const Gfx::IntRect& a_viewport_rect) +void InitialContainingBlockBox::did_set_viewport_rect(Badge, const Gfx::IntRect& a_viewport_rect) { Gfx::FloatRect viewport_rect(a_viewport_rect.x(), a_viewport_rect.y(), a_viewport_rect.width(), a_viewport_rect.height()); - for_each_in_subtree_of_type([&](auto& layout_image) { - const_cast(layout_image).set_visible_in_viewport({}, viewport_rect.intersects(layout_image.absolute_rect())); + for_each_in_subtree_of_type([&](auto& layout_image) { + const_cast(layout_image).set_visible_in_viewport({}, viewport_rect.intersects(layout_image.absolute_rect())); return IterationDecision::Continue; }); } -void LayoutDocument::paint_all_phases(PaintContext& context) +void InitialContainingBlockBox::paint_all_phases(PaintContext& context) { paint(context, PaintPhase::Background); paint(context, PaintPhase::Border); @@ -82,17 +82,17 @@ void LayoutDocument::paint_all_phases(PaintContext& context) paint(context, PaintPhase::Overlay); } -void LayoutDocument::paint(PaintContext& context, PaintPhase phase) +void InitialContainingBlockBox::paint(PaintContext& context, PaintPhase phase) { stacking_context()->paint(context, phase); } -HitTestResult LayoutDocument::hit_test(const Gfx::IntPoint& position, HitTestType type) const +HitTestResult InitialContainingBlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type) const { return stacking_context()->hit_test(position, type); } -void LayoutDocument::recompute_selection_states() +void InitialContainingBlockBox::recompute_selection_states() { SelectionState state = SelectionState::None; @@ -118,13 +118,13 @@ void LayoutDocument::recompute_selection_states() }); } -void LayoutDocument::set_selection(const LayoutRange& selection) +void InitialContainingBlockBox::set_selection(const LayoutRange& selection) { m_selection = selection; recompute_selection_states(); } -void LayoutDocument::set_selection_end(const LayoutPosition& position) +void InitialContainingBlockBox::set_selection_end(const LayoutPosition& position) { m_selection.set_end(position); recompute_selection_states(); diff --git a/Libraries/LibWeb/Layout/LayoutDocument.h b/Libraries/LibWeb/Layout/InitialContainingBlockBox.h similarity index 79% rename from Libraries/LibWeb/Layout/LayoutDocument.h rename to Libraries/LibWeb/Layout/InitialContainingBlockBox.h index 33e55b4f5ba..a02834ee17b 100644 --- a/Libraries/LibWeb/Layout/LayoutDocument.h +++ b/Libraries/LibWeb/Layout/InitialContainingBlockBox.h @@ -27,17 +27,17 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutDocument final : public LayoutBlock { +class InitialContainingBlockBox final : public BlockBox { public: - explicit LayoutDocument(DOM::Document&, NonnullRefPtr); - virtual ~LayoutDocument() override; + explicit InitialContainingBlockBox(DOM::Document&, NonnullRefPtr); + virtual ~InitialContainingBlockBox() override; - const DOM::Document& dom_node() const { return static_cast(*LayoutNode::dom_node()); } - virtual const char* class_name() const override { return "LayoutDocument"; } + const DOM::Document& dom_node() const { return static_cast(*Node::dom_node()); } + virtual const char* class_name() const override { return "InitialContainingBlockBox"; } void paint_all_phases(PaintContext&); virtual void paint(PaintContext&, PaintPhase) override; @@ -62,6 +62,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutDocument) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_root(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::InitialContainingBlockBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_root(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 5edcce81928..55219cbb1dc 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -27,15 +27,15 @@ #include #include #include +#include +#include #include -#include -#include -#include -#include +#include +#include namespace Web::Layout { -InlineFormattingContext::InlineFormattingContext(LayoutBox& containing_block) +InlineFormattingContext::InlineFormattingContext(Box& containing_block) : FormattingContext(containing_block) { } @@ -46,7 +46,7 @@ InlineFormattingContext::~InlineFormattingContext() void InlineFormattingContext::run(LayoutMode layout_mode) { - auto& containing_block = downcast(context_box()); + auto& containing_block = downcast(context_box()); ASSERT(containing_block.children_are_inline()); containing_block.line_boxes().clear(); @@ -129,7 +129,7 @@ void InlineFormattingContext::run(LayoutMode layout_mode) } if (fragment.layout_node().is_box()) - dimension_box_on_line(const_cast(downcast(fragment.layout_node())), layout_mode); + dimension_box_on_line(const_cast(downcast(fragment.layout_node())), layout_mode); float final_line_box_width = 0; for (auto& fragment : line_box.fragments()) @@ -149,19 +149,19 @@ void InlineFormattingContext::run(LayoutMode layout_mode) containing_block.set_height(content_height); } -void InlineFormattingContext::dimension_box_on_line(LayoutBox& box, LayoutMode layout_mode) +void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_mode) { - auto& containing_block = downcast(context_box()); + auto& containing_block = downcast(context_box()); if (box.is_replaced()) { - auto& replaced = const_cast(downcast(box)); + auto& replaced = const_cast(downcast(box)); replaced.set_width(replaced.calculate_width()); replaced.set_height(replaced.calculate_height()); return; } if (box.is_inline_block()) { - auto& inline_block = const_cast(downcast(box)); + auto& inline_block = const_cast(downcast(box)); if (inline_block.style().width().is_undefined_or_auto()) { auto result = calculate_shrink_to_fit_widths(inline_block); diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Libraries/LibWeb/Layout/InlineFormattingContext.h index 6534b6d6be4..8c23a7f2568 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -33,13 +33,13 @@ namespace Web::Layout { class InlineFormattingContext final : public FormattingContext { public: - InlineFormattingContext(LayoutBox& containing_block); + InlineFormattingContext(Box& containing_block); ~InlineFormattingContext(); virtual void run(LayoutMode) override; private: - void dimension_box_on_line(LayoutBox&, LayoutMode); + void dimension_box_on_line(Box&, LayoutMode); }; } diff --git a/Libraries/LibWeb/Layout/LayoutInline.cpp b/Libraries/LibWeb/Layout/InlineNode.cpp similarity index 82% rename from Libraries/LibWeb/Layout/LayoutInline.cpp rename to Libraries/LibWeb/Layout/InlineNode.cpp index ce77bc86312..8abfd4cab04 100644 --- a/Libraries/LibWeb/Layout/LayoutInline.cpp +++ b/Libraries/LibWeb/Layout/InlineNode.cpp @@ -25,18 +25,17 @@ */ #include -#include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutInline::LayoutInline(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutNodeWithStyleAndBoxModelMetrics(document, &element, move(style)) +InlineNode::InlineNode(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Layout::NodeWithStyleAndBoxModelMetrics(document, &element, move(style)) { set_inline(true); } -LayoutInline::~LayoutInline() +InlineNode::~InlineNode() { } diff --git a/Libraries/LibWeb/Layout/LayoutInline.h b/Libraries/LibWeb/Layout/InlineNode.h similarity index 80% rename from Libraries/LibWeb/Layout/LayoutInline.h rename to Libraries/LibWeb/Layout/InlineNode.h index 30bc455f159..f13dcc44945 100644 --- a/Libraries/LibWeb/Layout/LayoutInline.h +++ b/Libraries/LibWeb/Layout/InlineNode.h @@ -26,17 +26,15 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutBlock; - -class LayoutInline : public LayoutNodeWithStyleAndBoxModelMetrics { +class InlineNode : public NodeWithStyleAndBoxModelMetrics { public: - LayoutInline(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutInline() override; - virtual const char* class_name() const override { return "LayoutInline"; } + InlineNode(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~InlineNode() override; + virtual const char* class_name() const override { return "InlineNode"; } }; } diff --git a/Libraries/LibWeb/Layout/LayoutPosition.cpp b/Libraries/LibWeb/Layout/LayoutPosition.cpp index e171a34c15f..db0f8f2de19 100644 --- a/Libraries/LibWeb/Layout/LayoutPosition.cpp +++ b/Libraries/LibWeb/Layout/LayoutPosition.cpp @@ -24,10 +24,10 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include -namespace Web { +namespace Web::Layout { LayoutRange LayoutRange::normalized() const { diff --git a/Libraries/LibWeb/Layout/LayoutPosition.h b/Libraries/LibWeb/Layout/LayoutPosition.h index fc5fb86e5db..fa132c7ee66 100644 --- a/Libraries/LibWeb/Layout/LayoutPosition.h +++ b/Libraries/LibWeb/Layout/LayoutPosition.h @@ -28,12 +28,12 @@ #include -namespace Web { +namespace Web::Layout { -class LayoutNode; +class Node; struct LayoutPosition { - RefPtr layout_node; + RefPtr layout_node; int index_in_node { 0 }; }; diff --git a/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp b/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp index 98482892607..83fd63de7a5 100644 --- a/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp +++ b/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp @@ -26,18 +26,18 @@ #include #include -#include -#include -#include #include +#include +#include +#include -namespace Web { +namespace Web::Layout { LayoutTreeBuilder::LayoutTreeBuilder() { } -static RefPtr create_layout_tree(DOM::Node& node, const CSS::StyleProperties* parent_style) +static RefPtr create_layout_tree(DOM::Node& node, const CSS::StyleProperties* parent_style) { auto layout_node = node.create_layout_node(parent_style); if (!layout_node) @@ -46,7 +46,7 @@ static RefPtr create_layout_tree(DOM::Node& node, const CSS::StylePr if (!node.has_children()) return layout_node; - NonnullRefPtrVector layout_children; + NonnullRefPtrVector layout_children; bool have_inline_children = false; bool have_noninline_children = false; @@ -63,7 +63,7 @@ static RefPtr create_layout_tree(DOM::Node& node, const CSS::StylePr for (auto& layout_child : layout_children) { if (have_noninline_children && have_inline_children && layout_child.is_inline()) { - if (is(layout_child) && downcast(layout_child).text_for_style(*parent_style) == " ") + if (is(layout_child) && downcast(layout_child).text_for_style(*parent_style) == " ") continue; layout_node->inline_wrapper().append_child(layout_child); } else { @@ -77,7 +77,7 @@ static RefPtr create_layout_tree(DOM::Node& node, const CSS::StylePr return layout_node; } -RefPtr LayoutTreeBuilder::build(DOM::Node& node) +RefPtr LayoutTreeBuilder::build(DOM::Node& node) { if (!is(node) && node.has_children()) { dbg() << "FIXME: Support building partial layout trees."; diff --git a/Libraries/LibWeb/Layout/LayoutTreeBuilder.h b/Libraries/LibWeb/Layout/LayoutTreeBuilder.h index 9a41ad0b0ca..fe96b3db884 100644 --- a/Libraries/LibWeb/Layout/LayoutTreeBuilder.h +++ b/Libraries/LibWeb/Layout/LayoutTreeBuilder.h @@ -29,13 +29,13 @@ #include #include -namespace Web { +namespace Web::Layout { class LayoutTreeBuilder { public: LayoutTreeBuilder(); - RefPtr build(DOM::Node&); + RefPtr build(DOM::Node&); }; } diff --git a/Libraries/LibWeb/Layout/LineBox.cpp b/Libraries/LibWeb/Layout/LineBox.cpp index bf2840faf8c..99cc777fcb9 100644 --- a/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Libraries/LibWeb/Layout/LineBox.cpp @@ -25,20 +25,20 @@ */ #include -#include -#include -#include +#include #include +#include +#include #include -namespace Web { +namespace Web::Layout { -void LineBox::add_fragment(const LayoutNode& layout_node, int start, int length, int width, int height) +void LineBox::add_fragment(const Node& layout_node, int start, int length, int width, int height) { bool text_align_is_justify = layout_node.style().text_align() == CSS::TextAlign::Justify; if (!text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node) { - // The fragment we're adding is from the last LayoutNode on the line. - // Expand the last fragment instead of adding a new one with the same LayoutNode. + // The fragment we're adding is from the last Layout::Node on the line. + // Expand the last fragment instead of adding a new one with the same Layout::Node. m_fragments.last().m_length = (start - m_fragments.last().m_start) + length; m_fragments.last().set_width(m_fragments.last().width() + width); } else { @@ -46,8 +46,8 @@ void LineBox::add_fragment(const LayoutNode& layout_node, int start, int length, } m_width += width; - if (is(layout_node)) - const_cast(downcast(layout_node)).set_containing_line_box_fragment(m_fragments.last()); + if (is(layout_node)) + const_cast(downcast(layout_node)).set_containing_line_box_fragment(m_fragments.last()); } void LineBox::trim_trailing_whitespace() diff --git a/Libraries/LibWeb/Layout/LineBox.h b/Libraries/LibWeb/Layout/LineBox.h index eeb177d6380..242adf00072 100644 --- a/Libraries/LibWeb/Layout/LineBox.h +++ b/Libraries/LibWeb/Layout/LineBox.h @@ -30,7 +30,7 @@ #include #include -namespace Web { +namespace Web::Layout { class LineBox { public: @@ -38,7 +38,7 @@ public: float width() const { return m_width; } - void add_fragment(const LayoutNode& layout_node, int start, int length, int width, int height); + void add_fragment(const Node& layout_node, int start, int length, int width, int height); const NonnullOwnPtrVector& fragments() const { return m_fragments; } NonnullOwnPtrVector& fragments() { return m_fragments; } @@ -48,8 +48,8 @@ public: bool ends_in_whitespace() const; private: - friend class LayoutBlock; - friend class Layout::InlineFormattingContext; + friend class BlockBox; + friend class InlineFormattingContext; NonnullOwnPtrVector m_fragments; float m_width { 0 }; }; diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 05332f8007f..2c4be7f141c 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -26,13 +26,13 @@ #include #include -#include -#include +#include #include +#include #include #include -namespace Web { +namespace Web::Layout { void LineBoxFragment::paint(PaintContext& context) { @@ -41,9 +41,8 @@ void LineBoxFragment::paint(PaintContext& context) return; } - if (is(layout_node())) { - downcast(layout_node()).paint_fragment(context, *this); - } + if (is(layout_node())) + downcast(layout_node()).paint_fragment(context, *this); } bool LineBoxFragment::ends_in_whitespace() const @@ -61,9 +60,9 @@ bool LineBoxFragment::is_justifiable_whitespace() const StringView LineBoxFragment::text() const { - if (!is(layout_node())) + if (!is(layout_node())) return {}; - return downcast(layout_node()).text_for_rendering().substring_view(m_start, m_length); + return downcast(layout_node()).text_for_rendering().substring_view(m_start, m_length); } const Gfx::FloatRect LineBoxFragment::absolute_rect() const @@ -78,7 +77,7 @@ int LineBoxFragment::text_index_at(float x) const { if (!layout_node().is_text()) return 0; - auto& layout_text = downcast(layout_node()); + auto& layout_text = downcast(layout_node()); auto& font = layout_text.specified_style().font(); Utf8View view(text()); @@ -100,10 +99,10 @@ int LineBoxFragment::text_index_at(float x) const Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const { - if (layout_node().selection_state() == LayoutNode::SelectionState::None) + if (layout_node().selection_state() == Node::SelectionState::None) return {}; - if (layout_node().selection_state() == LayoutNode::SelectionState::Full) + if (layout_node().selection_state() == Node::SelectionState::Full) return absolute_rect(); auto selection = layout_node().root().selection().normalized(); @@ -116,7 +115,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const const auto end_index = m_start + m_length; auto text = this->text(); - if (layout_node().selection_state() == LayoutNode::SelectionState::StartAndEnd) { + if (layout_node().selection_state() == Node::SelectionState::StartAndEnd) { // we are in the start/end node (both the same) if (start_index > selection.end().index_in_node) return {}; @@ -137,7 +136,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const return rect; } - if (layout_node().selection_state() == LayoutNode::SelectionState::Start) { + if (layout_node().selection_state() == Node::SelectionState::Start) { // we are in the start node if (end_index < selection.start().index_in_node) return {}; @@ -153,7 +152,7 @@ Gfx::FloatRect LineBoxFragment::selection_rect(const Gfx::Font& font) const return rect; } - if (layout_node().selection_state() == LayoutNode::SelectionState::End) { + if (layout_node().selection_state() == Node::SelectionState::End) { // we are in the end node if (start_index > selection.end().index_in_node) return {}; diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.h b/Libraries/LibWeb/Layout/LineBoxFragment.h index f2c71b4ff9c..2c6662e8b45 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.h +++ b/Libraries/LibWeb/Layout/LineBoxFragment.h @@ -31,13 +31,13 @@ #include #include -namespace Web { +namespace Web::Layout { class LineBoxFragment : public Weakable { friend class LineBox; public: - LineBoxFragment(const LayoutNode& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size) + LineBoxFragment(const Node& layout_node, int start, int length, const Gfx::FloatPoint& offset, const Gfx::FloatSize& size) : m_layout_node(layout_node) , m_start(start) , m_length(length) @@ -46,7 +46,7 @@ public: { } - const LayoutNode& layout_node() const { return m_layout_node; } + const Node& layout_node() const { return m_layout_node; } int start() const { return m_start; } int length() const { return m_length; } const Gfx::FloatRect absolute_rect() const; @@ -72,7 +72,7 @@ public: Gfx::FloatRect selection_rect(const Gfx::Font&) const; private: - const LayoutNode& m_layout_node; + const Node& m_layout_node; int m_start { 0 }; int m_length { 0 }; Gfx::FloatPoint m_offset; diff --git a/Libraries/LibWeb/Layout/LayoutListItem.cpp b/Libraries/LibWeb/Layout/ListItemBox.cpp similarity index 81% rename from Libraries/LibWeb/Layout/LayoutListItem.cpp rename to Libraries/LibWeb/Layout/ListItemBox.cpp index 5b8cc5165e8..5e8f683c7fc 100644 --- a/Libraries/LibWeb/Layout/LayoutListItem.cpp +++ b/Libraries/LibWeb/Layout/ListItemBox.cpp @@ -24,21 +24,21 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include +#include -namespace Web { +namespace Web::Layout { -LayoutListItem::LayoutListItem(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutBlock(document, &element, move(style)) +ListItemBox::ListItemBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Layout::BlockBox(document, &element, move(style)) { } -LayoutListItem::~LayoutListItem() +ListItemBox::~ListItemBox() { } -void LayoutListItem::layout_marker() +void ListItemBox::layout_marker() { if (m_marker) { remove_child(*m_marker); @@ -49,7 +49,7 @@ void LayoutListItem::layout_marker() return; if (!m_marker) { - m_marker = adopt(*new LayoutListItemMarker(document())); + m_marker = adopt(*new ListItemMarkerBox(document())); if (first_child()) m_marker->set_inline(first_child()->is_inline()); append_child(*m_marker); diff --git a/Libraries/LibWeb/Layout/LayoutListItem.h b/Libraries/LibWeb/Layout/ListItemBox.h similarity index 75% rename from Libraries/LibWeb/Layout/LayoutListItem.h rename to Libraries/LibWeb/Layout/ListItemBox.h index 2bb8dcb80f2..d374ab609d9 100644 --- a/Libraries/LibWeb/Layout/LayoutListItem.h +++ b/Libraries/LibWeb/Layout/ListItemBox.h @@ -27,28 +27,28 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutListItemMarker; +class ListItemMarkerBox; -class LayoutListItem final : public LayoutBlock { +class ListItemBox final : public BlockBox { public: - LayoutListItem(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutListItem() override; + ListItemBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~ListItemBox() override; void layout_marker(); private: - virtual const char* class_name() const override { return "LayoutListItem"; } + virtual const char* class_name() const override { return "ListItemBox"; } virtual bool is_list_item() const override { return true; } - RefPtr m_marker; + RefPtr m_marker; }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutListItem) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_list_item(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::ListItemBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_list_item(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp b/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp similarity index 85% rename from Libraries/LibWeb/Layout/LayoutListItemMarker.cpp rename to Libraries/LibWeb/Layout/ListItemMarkerBox.cpp index bc51ccdbb34..332a73e5b7e 100644 --- a/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp +++ b/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp @@ -25,20 +25,20 @@ */ #include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutListItemMarker::LayoutListItemMarker(DOM::Document& document) - : LayoutBox(document, nullptr, CSS::StyleProperties::create()) +ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document) + : Box(document, nullptr, CSS::StyleProperties::create()) { } -LayoutListItemMarker::~LayoutListItemMarker() +ListItemMarkerBox::~ListItemMarkerBox() { } -void LayoutListItemMarker::paint(PaintContext& context, PaintPhase phase) +void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase) { if (phase != PaintPhase::Foreground) return; diff --git a/Libraries/LibWeb/Layout/LayoutListItemMarker.h b/Libraries/LibWeb/Layout/ListItemMarkerBox.h similarity index 83% rename from Libraries/LibWeb/Layout/LayoutListItemMarker.h rename to Libraries/LibWeb/Layout/ListItemMarkerBox.h index 9ad83914080..e32528c99ca 100644 --- a/Libraries/LibWeb/Layout/LayoutListItemMarker.h +++ b/Libraries/LibWeb/Layout/ListItemMarkerBox.h @@ -26,19 +26,19 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutListItemMarker final : public LayoutBox { +class ListItemMarkerBox final : public Box { public: - explicit LayoutListItemMarker(DOM::Document&); - virtual ~LayoutListItemMarker() override; + explicit ListItemMarkerBox(DOM::Document&); + virtual ~ListItemMarkerBox() override; virtual void paint(PaintContext&, PaintPhase) override; private: - virtual const char* class_name() const override { return "LayoutListItemMarker"; } + virtual const char* class_name() const override { return "ListItemMarkerBox"; } }; } diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/Node.cpp similarity index 79% rename from Libraries/LibWeb/Layout/LayoutNode.cpp rename to Libraries/LibWeb/Layout/Node.cpp index 7fcf45e0b82..b843fbc3d54 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/Node.cpp @@ -27,15 +27,15 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -namespace Web { +namespace Web::Layout { -LayoutNode::LayoutNode(DOM::Document& document, DOM::Node* node) +Node::Node(DOM::Document& document, DOM::Node* node) : m_document(document) , m_dom_node(node) { @@ -43,24 +43,24 @@ LayoutNode::LayoutNode(DOM::Document& document, DOM::Node* node) m_dom_node->set_layout_node({}, this); } -LayoutNode::~LayoutNode() +Node::~Node() { if (m_dom_node && m_dom_node->layout_node() == this) m_dom_node->set_layout_node({}, nullptr); } -bool LayoutNode::can_contain_boxes_with_position_absolute() const +bool Node::can_contain_boxes_with_position_absolute() const { return style().position() != CSS::Position::Static || is_root(); } -const LayoutBlock* LayoutNode::containing_block() const +const BlockBox* Node::containing_block() const { auto nearest_block_ancestor = [this] { auto* ancestor = parent(); - while (ancestor && !is(*ancestor)) + while (ancestor && !is(*ancestor)) ancestor = ancestor->parent(); - return downcast(ancestor); + return downcast(ancestor); }; if (is_text()) @@ -72,9 +72,9 @@ const LayoutBlock* LayoutNode::containing_block() const auto* ancestor = parent(); while (ancestor && !ancestor->can_contain_boxes_with_position_absolute()) ancestor = ancestor->parent(); - while (ancestor && (!is(ancestor) || ancestor->is_anonymous())) + while (ancestor && (!is(ancestor) || ancestor->is_anonymous())) ancestor = ancestor->containing_block(); - return downcast(ancestor); + return downcast(ancestor); } if (position == CSS::Position::Fixed) @@ -83,7 +83,7 @@ const LayoutBlock* LayoutNode::containing_block() const return nearest_block_ancestor(); } -void LayoutNode::paint(PaintContext& context, PaintPhase phase) +void Node::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; @@ -91,7 +91,7 @@ void LayoutNode::paint(PaintContext& context, PaintPhase phase) before_children_paint(context, phase); for_each_child([&](auto& child) { - if (child.is_box() && downcast(child).stacking_context()) + if (child.is_box() && downcast(child).stacking_context()) return; child.paint(context, phase); }); @@ -99,13 +99,13 @@ void LayoutNode::paint(PaintContext& context, PaintPhase phase) after_children_paint(context, phase); } -HitTestResult LayoutNode::hit_test(const Gfx::IntPoint& position, HitTestType type) const +HitTestResult Node::hit_test(const Gfx::IntPoint& position, HitTestType type) const { HitTestResult result; for_each_child([&](auto& child) { // Skip over children that establish their own stacking context. // The outer loop who called us will take care of those. - if (is(child) && downcast(child).stacking_context()) + if (is(child) && downcast(child).stacking_context()) return; auto child_result = child.hit_test(position, type); if (child_result.layout_node) @@ -114,38 +114,38 @@ HitTestResult LayoutNode::hit_test(const Gfx::IntPoint& position, HitTestType ty return result; } -const Frame& LayoutNode::frame() const +const Frame& Node::frame() const { ASSERT(document().frame()); return *document().frame(); } -Frame& LayoutNode::frame() +Frame& Node::frame() { ASSERT(document().frame()); return *document().frame(); } -const LayoutDocument& LayoutNode::root() const +const InitialContainingBlockBox& Node::root() const { ASSERT(document().layout_node()); return *document().layout_node(); } -LayoutDocument& LayoutNode::root() +InitialContainingBlockBox& Node::root() { ASSERT(document().layout_node()); return *document().layout_node(); } -void LayoutNode::split_into_lines(LayoutBlock& container, LayoutMode layout_mode) +void Node::split_into_lines(BlockBox& container, LayoutMode layout_mode) { for_each_child([&](auto& child) { child.split_into_lines(container, layout_mode); }); } -void LayoutNode::set_needs_display() +void Node::set_needs_display() { if (auto* block = containing_block()) { block->for_each_fragment([&](auto& fragment) { @@ -157,17 +157,17 @@ void LayoutNode::set_needs_display() } } -float LayoutNode::font_size() const +float Node::font_size() const { // FIXME: This doesn't work right for relative font-sizes auto length = specified_style().length_or_fallback(CSS::PropertyID::FontSize, CSS::Length(10, CSS::Length::Type::Px)); return length.raw_value(); } -Gfx::FloatPoint LayoutNode::box_type_agnostic_position() const +Gfx::FloatPoint Node::box_type_agnostic_position() const { if (is_box()) - return downcast(*this).absolute_position(); + return downcast(*this).absolute_position(); ASSERT(is_inline()); Gfx::FloatPoint position; if (auto* block = containing_block()) { @@ -182,14 +182,14 @@ Gfx::FloatPoint LayoutNode::box_type_agnostic_position() const return position; } -bool LayoutNode::is_floating() const +bool Node::is_floating() const { if (!has_style()) return false; return style().float_() != CSS::Float::None; } -bool LayoutNode::is_absolutely_positioned() const +bool Node::is_absolutely_positioned() const { if (!has_style()) return false; @@ -197,7 +197,7 @@ bool LayoutNode::is_absolutely_positioned() const return position == CSS::Position::Absolute || position == CSS::Position::Fixed; } -bool LayoutNode::is_fixed_position() const +bool Node::is_fixed_position() const { if (!has_style()) return false; @@ -205,15 +205,15 @@ bool LayoutNode::is_fixed_position() const return position == CSS::Position::Fixed; } -LayoutNodeWithStyle::LayoutNodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr specified_style) - : LayoutNode(document, node) +NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr specified_style) + : Node(document, node) , m_specified_style(move(specified_style)) { m_has_style = true; apply_style(*m_specified_style); } -void LayoutNodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) +void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style) { auto& style = static_cast(m_style); @@ -251,15 +251,15 @@ void LayoutNodeWithStyle::apply_style(const CSS::StyleProperties& specified_styl style.border_bottom().color = specified_style.color_or_fallback(CSS::PropertyID::BorderBottomColor, document(), Color::Transparent); } -void LayoutNode::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned, unsigned) +void Node::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned, unsigned) { } -void LayoutNode::handle_mouseup(Badge, const Gfx::IntPoint&, unsigned, unsigned) +void Node::handle_mouseup(Badge, const Gfx::IntPoint&, unsigned, unsigned) { } -void LayoutNode::handle_mousemove(Badge, const Gfx::IntPoint&, unsigned, unsigned) +void Node::handle_mousemove(Badge, const Gfx::IntPoint&, unsigned, unsigned) { } diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/Node.h similarity index 77% rename from Libraries/LibWeb/Layout/LayoutNode.h rename to Libraries/LibWeb/Layout/Node.h index d3fb8c5d164..93bac6ca398 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/Node.h @@ -38,7 +38,7 @@ #include #include -namespace Web { +namespace Web::Layout { enum class LayoutMode { Default, @@ -47,7 +47,7 @@ enum class LayoutMode { }; struct HitTestResult { - RefPtr layout_node; + RefPtr layout_node; int index_in_node { 0 }; enum InternalPosition { @@ -64,9 +64,9 @@ enum class HitTestType { TextCursor, // Clicking past the right/bottom edge of text will still hit the text }; -class LayoutNode : public TreeNode { +class Node : public TreeNode { public: - virtual ~LayoutNode(); + virtual ~Node(); virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const; @@ -80,8 +80,8 @@ public: const Frame& frame() const; Frame& frame(); - const LayoutDocument& root() const; - LayoutDocument& root(); + const InitialContainingBlockBox& root() const; + InitialContainingBlockBox& root(); virtual const char* class_name() const = 0; virtual bool is_root() const { return false; } @@ -130,23 +130,23 @@ public: bool is_absolutely_positioned() const; bool is_fixed_position() const; - const LayoutBlock* containing_block() const; + const BlockBox* containing_block() const; bool can_contain_boxes_with_position_absolute() const; - virtual LayoutNode& inline_wrapper() { return *this; } + virtual Node& inline_wrapper() { return *this; } const CSS::StyleProperties& specified_style() const; const ImmutableLayoutStyle& style() const; - LayoutNodeWithStyle* parent(); - const LayoutNodeWithStyle* parent() const; + NodeWithStyle* parent(); + const NodeWithStyle* parent() const; - void inserted_into(LayoutNode&) { } - void removed_from(LayoutNode&) { } + void inserted_into(Node&) { } + void removed_from(Node&) { } void children_changed() { } - virtual void split_into_lines(LayoutBlock& container, LayoutMode); + virtual void split_into_lines(BlockBox& container, LayoutMode); bool is_visible() const { return m_visible; } void set_visible(bool visible) { m_visible = visible; } @@ -162,20 +162,20 @@ public: enum class SelectionState { None, // No selection - Start, // Selection starts in this LayoutNode - End, // Selection ends in this LayoutNode - StartAndEnd, // Selection starts and ends in this LayoutNode - Full, // Selection starts before and ends after this LayoutNode + Start, // Selection starts in this Node + End, // Selection ends in this Node + StartAndEnd, // Selection starts and ends in this Node + Full, // Selection starts before and ends after this Node }; SelectionState selection_state() const { return m_selection_state; } void set_selection_state(SelectionState state) { m_selection_state = state; } protected: - LayoutNode(DOM::Document&, DOM::Node*); + Node(DOM::Document&, DOM::Node*); private: - friend class LayoutNodeWithStyle; + friend class NodeWithStyle; NonnullRefPtr m_document; RefPtr m_dom_node; @@ -187,9 +187,9 @@ private: SelectionState m_selection_state { SelectionState::None }; }; -class LayoutNodeWithStyle : public LayoutNode { +class NodeWithStyle : public Node { public: - virtual ~LayoutNodeWithStyle() override { } + virtual ~NodeWithStyle() override { } const CSS::StyleProperties& specified_style() const { return m_specified_style; } void set_specified_style(const CSS::StyleProperties& style) { m_specified_style = style; } @@ -199,7 +199,7 @@ public: void apply_style(const CSS::StyleProperties&); protected: - LayoutNodeWithStyle(DOM::Document&, DOM::Node*, NonnullRefPtr); + NodeWithStyle(DOM::Document&, DOM::Node*, NonnullRefPtr); private: LayoutStyle m_style; @@ -208,14 +208,14 @@ private: CSS::Position m_position; }; -class LayoutNodeWithStyleAndBoxModelMetrics : public LayoutNodeWithStyle { +class NodeWithStyleAndBoxModelMetrics : public NodeWithStyle { public: BoxModelMetrics& box_model() { return m_box_model; } const BoxModelMetrics& box_model() const { return m_box_model; } protected: - LayoutNodeWithStyleAndBoxModelMetrics(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) - : LayoutNodeWithStyle(document, node, move(style)) + NodeWithStyleAndBoxModelMetrics(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) + : NodeWithStyle(document, node, move(style)) { } @@ -223,32 +223,32 @@ private: BoxModelMetrics m_box_model; }; -inline const CSS::StyleProperties& LayoutNode::specified_style() const +inline const CSS::StyleProperties& Node::specified_style() const { if (m_has_style) - return static_cast(this)->specified_style(); + return static_cast(this)->specified_style(); return parent()->specified_style(); } -inline const ImmutableLayoutStyle& LayoutNode::style() const +inline const ImmutableLayoutStyle& Node::style() const { if (m_has_style) - return static_cast(this)->style(); + return static_cast(this)->style(); return parent()->style(); } -inline const LayoutNodeWithStyle* LayoutNode::parent() const +inline const NodeWithStyle* Node::parent() const { - return static_cast(TreeNode::parent()); + return static_cast(TreeNode::parent()); } -inline LayoutNodeWithStyle* LayoutNode::parent() +inline NodeWithStyle* Node::parent() { - return static_cast(TreeNode::parent()); + return static_cast(TreeNode::parent()); } } -AK_BEGIN_TYPE_TRAITS(Web::LayoutNodeWithStyle) -static bool is_type(const Web::LayoutNode& node) { return node.has_style(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::NodeWithStyle) +static bool is_type(const Web::Layout::Node& node) { return node.has_style(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutReplaced.cpp b/Libraries/LibWeb/Layout/ReplacedBox.cpp similarity index 91% rename from Libraries/LibWeb/Layout/LayoutReplaced.cpp rename to Libraries/LibWeb/Layout/ReplacedBox.cpp index 2e7e22bea54..340d96462c9 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.cpp +++ b/Libraries/LibWeb/Layout/ReplacedBox.cpp @@ -25,23 +25,23 @@ */ #include -#include -#include +#include +#include -namespace Web { +namespace Web::Layout { -LayoutReplaced::LayoutReplaced(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutBox(document, &element, move(style)) +ReplacedBox::ReplacedBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Box(document, &element, move(style)) { // FIXME: Allow non-inline replaced elements. set_inline(true); } -LayoutReplaced::~LayoutReplaced() +ReplacedBox::~ReplacedBox() { } -float LayoutReplaced::calculate_width() const +float ReplacedBox::calculate_width() const { // 10.3.2 [Inline,] replaced elements @@ -92,7 +92,7 @@ float LayoutReplaced::calculate_width() const return used_width; } -float LayoutReplaced::calculate_height() const +float ReplacedBox::calculate_height() const { // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, // 'inline-block' replaced elements in normal flow and floating replaced elements @@ -117,7 +117,7 @@ float LayoutReplaced::calculate_height() const return used_height; } -void LayoutReplaced::split_into_lines(LayoutBlock& container, LayoutMode) +void ReplacedBox::split_into_lines(Layout::BlockBox& container, LayoutMode) { // FIXME: This feels out of place. It would be nice if someone at a higher level // made sure we had usable geometry by the time we start splitting. diff --git a/Libraries/LibWeb/Layout/LayoutReplaced.h b/Libraries/LibWeb/Layout/ReplacedBox.h similarity index 81% rename from Libraries/LibWeb/Layout/LayoutReplaced.h rename to Libraries/LibWeb/Layout/ReplacedBox.h index 14f461e7733..aff5ccd5ca8 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.h +++ b/Libraries/LibWeb/Layout/ReplacedBox.h @@ -27,17 +27,17 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutReplaced : public LayoutBox { +class ReplacedBox : public Box { public: - LayoutReplaced(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutReplaced() override; + ReplacedBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~ReplacedBox() override; - const DOM::Element& dom_node() const { return downcast(*LayoutNode::dom_node()); } - DOM::Element& dom_node() { return downcast(*LayoutNode::dom_node()); } + const DOM::Element& dom_node() const { return downcast(*Node::dom_node()); } + DOM::Element& dom_node() { return downcast(*Node::dom_node()); } virtual bool is_replaced() const final { return true; } @@ -63,10 +63,10 @@ public: virtual void prepare_for_replaced_layout() { } protected: - virtual void split_into_lines(LayoutBlock& container, LayoutMode) override; + virtual void split_into_lines(Layout::BlockBox& container, LayoutMode) override; private: - virtual const char* class_name() const override { return "LayoutReplaced"; } + virtual const char* class_name() const override { return "ReplacedBox"; } bool m_has_intrinsic_width { false }; bool m_has_intrinsic_height { false }; @@ -78,6 +78,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutReplaced) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_replaced(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::ReplacedBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_replaced(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutSVG.cpp b/Libraries/LibWeb/Layout/SVGBox.cpp similarity index 72% rename from Libraries/LibWeb/Layout/LayoutSVG.cpp rename to Libraries/LibWeb/Layout/SVGBox.cpp index b5ea0e63a9a..8370d4b9bdf 100644 --- a/Libraries/LibWeb/Layout/LayoutSVG.cpp +++ b/Libraries/LibWeb/Layout/SVGBox.cpp @@ -27,27 +27,27 @@ #include #include #include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutSVG::LayoutSVG(DOM::Document& document, SVG::SVGElement& element, NonnullRefPtr style) - : LayoutReplaced(document, element, move(style)) +SVGBox::SVGBox(DOM::Document& document, SVG::SVGElement& element, NonnullRefPtr style) + : ReplacedBox(document, element, move(style)) { } -void LayoutSVG::before_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) +void SVGBox::before_children_paint(PaintContext& context, PaintPhase phase) { - LayoutNode::before_children_paint(context, phase); - if (phase != LayoutNode::PaintPhase::Foreground) + Node::before_children_paint(context, phase); + if (phase != PaintPhase::Foreground) return; context.svg_context().save(); } -void LayoutSVG::after_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) +void SVGBox::after_children_paint(PaintContext& context, PaintPhase phase) { - LayoutNode::after_children_paint(context, phase); - if (phase != LayoutNode::PaintPhase::Foreground) + Node::after_children_paint(context, phase); + if (phase != PaintPhase::Foreground) return; context.svg_context().restore(); } diff --git a/Libraries/LibWeb/Layout/LayoutSVG.h b/Libraries/LibWeb/Layout/SVGBox.h similarity index 84% rename from Libraries/LibWeb/Layout/LayoutSVG.h rename to Libraries/LibWeb/Layout/SVGBox.h index 3ae7ae9cb43..cd289bb1993 100644 --- a/Libraries/LibWeb/Layout/LayoutSVG.h +++ b/Libraries/LibWeb/Layout/SVGBox.h @@ -26,22 +26,22 @@ #pragma once -#include +#include #include #include -namespace Web { +namespace Web::Layout { -class LayoutSVG : public LayoutReplaced { +class SVGBox : public ReplacedBox { public: - LayoutSVG(DOM::Document&, SVG::SVGElement&, NonnullRefPtr); - virtual ~LayoutSVG() override = default; + SVGBox(DOM::Document&, SVG::SVGElement&, NonnullRefPtr); + virtual ~SVGBox() override = default; virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; virtual void after_children_paint(PaintContext& context, PaintPhase phase) override; private: - virtual const char* class_name() const override { return "LayoutSVG"; } + virtual const char* class_name() const override { return "SVGBox"; } }; } diff --git a/Libraries/LibWeb/Layout/LayoutSVGGraphics.cpp b/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp similarity index 80% rename from Libraries/LibWeb/Layout/LayoutSVGGraphics.cpp rename to Libraries/LibWeb/Layout/SVGGraphicsBox.cpp index b85237aeea3..be1f9541d48 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGGraphics.cpp +++ b/Libraries/LibWeb/Layout/SVGGraphicsBox.cpp @@ -24,19 +24,19 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include -namespace Web { +namespace Web::Layout { -LayoutSVGGraphics::LayoutSVGGraphics(DOM::Document& document, SVG::SVGGraphicsElement& element, NonnullRefPtr properties) - : LayoutSVG(document, element, properties) +SVGGraphicsBox::SVGGraphicsBox(DOM::Document& document, SVG::SVGGraphicsElement& element, NonnullRefPtr properties) + : SVGBox(document, element, properties) { } -void LayoutSVGGraphics::before_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) +void SVGGraphicsBox::before_children_paint(PaintContext& context, PaintPhase phase) { - LayoutSVG::before_children_paint(context, phase); - if (phase != LayoutNode::PaintPhase::Foreground) + SVGBox::before_children_paint(context, phase); + if (phase != PaintPhase::Foreground) return; auto& graphics_element = downcast(dom_node()); diff --git a/Libraries/LibWeb/Layout/LayoutSVGGraphics.h b/Libraries/LibWeb/Layout/SVGGraphicsBox.h similarity index 77% rename from Libraries/LibWeb/Layout/LayoutSVGGraphics.h rename to Libraries/LibWeb/Layout/SVGGraphicsBox.h index a6e33527523..686ea7adc01 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGGraphics.h +++ b/Libraries/LibWeb/Layout/SVGGraphicsBox.h @@ -26,21 +26,21 @@ #pragma once -#include +#include #include #include -namespace Web { +namespace Web::Layout { -class LayoutSVGGraphics : public LayoutSVG { +class SVGGraphicsBox : public SVGBox { public: - LayoutSVGGraphics(DOM::Document&, SVG::SVGGraphicsElement&, NonnullRefPtr); - virtual ~LayoutSVGGraphics() override = default; + SVGGraphicsBox(DOM::Document&, SVG::SVGGraphicsElement&, NonnullRefPtr); + virtual ~SVGGraphicsBox() override = default; - virtual void before_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) override; + virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; private: - virtual const char* class_name() const override { return "LayoutSVGGraphics"; } + virtual const char* class_name() const override { return "SVGGraphicsBox"; } }; } diff --git a/Libraries/LibWeb/Layout/LayoutSVGPath.cpp b/Libraries/LibWeb/Layout/SVGPathBox.cpp similarity index 86% rename from Libraries/LibWeb/Layout/LayoutSVGPath.cpp rename to Libraries/LibWeb/Layout/SVGPathBox.cpp index f4f1225fac7..87879043eb7 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGPath.cpp +++ b/Libraries/LibWeb/Layout/SVGPathBox.cpp @@ -25,17 +25,17 @@ */ #include -#include +#include #include -namespace Web { +namespace Web::Layout { -LayoutSVGPath::LayoutSVGPath(DOM::Document& document, SVG::SVGPathElement& element, NonnullRefPtr properties) - : LayoutSVGGraphics(document, element, properties) +SVGPathBox::SVGPathBox(DOM::Document& document, SVG::SVGPathElement& element, NonnullRefPtr properties) + : SVGGraphicsBox(document, element, properties) { } -void LayoutSVGPath::prepare_for_replaced_layout() +void SVGPathBox::prepare_for_replaced_layout() { auto& bounding_box = dom_node().get_path().bounding_box(); set_has_intrinsic_width(true); @@ -47,14 +47,14 @@ void LayoutSVGPath::prepare_for_replaced_layout() set_offset(bounding_box.top_left()); } -void LayoutSVGPath::paint(PaintContext& context, LayoutNode::PaintPhase phase) +void SVGPathBox::paint(PaintContext& context, PaintPhase phase) { if (!is_visible()) return; - LayoutSVGGraphics::paint(context, phase); + SVGGraphicsBox::paint(context, phase); - if (phase != LayoutNode::PaintPhase::Foreground) + if (phase != PaintPhase::Foreground) return; auto& path_element = dom_node(); diff --git a/Libraries/LibWeb/Layout/LayoutSVGPath.h b/Libraries/LibWeb/Layout/SVGPathBox.h similarity index 81% rename from Libraries/LibWeb/Layout/LayoutSVGPath.h rename to Libraries/LibWeb/Layout/SVGPathBox.h index a378665a8c9..0cc0717e1d6 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGPath.h +++ b/Libraries/LibWeb/Layout/SVGPathBox.h @@ -26,22 +26,22 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutSVGPath final : public LayoutSVGGraphics { +class SVGPathBox final : public SVGGraphicsBox { public: - LayoutSVGPath(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr); - virtual ~LayoutSVGPath() override = default; + SVGPathBox(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr); + virtual ~SVGPathBox() override = default; - SVG::SVGPathElement& dom_node() { return downcast(LayoutSVGGraphics::dom_node()); } + SVG::SVGPathElement& dom_node() { return downcast(SVGGraphicsBox::dom_node()); } virtual void prepare_for_replaced_layout() override; virtual void paint(PaintContext& context, PaintPhase phase) override; private: - virtual const char* class_name() const override { return "LayoutSVGPath"; } + virtual const char* class_name() const override { return "SVGPathBox"; } }; } diff --git a/Libraries/LibWeb/Layout/LayoutSVGSVG.cpp b/Libraries/LibWeb/Layout/SVGSVGBox.cpp similarity index 70% rename from Libraries/LibWeb/Layout/LayoutSVGSVG.cpp rename to Libraries/LibWeb/Layout/SVGSVGBox.cpp index 23dde716a4f..af4a038dbcd 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGSVG.cpp +++ b/Libraries/LibWeb/Layout/SVGSVGBox.cpp @@ -24,16 +24,16 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include -namespace Web { +namespace Web::Layout { -LayoutSVGSVG::LayoutSVGSVG(DOM::Document& document, SVG::SVGSVGElement& element, NonnullRefPtr properties) - : LayoutSVGGraphics(document, element, properties) +SVGSVGBox::SVGSVGBox(DOM::Document& document, SVG::SVGSVGElement& element, NonnullRefPtr properties) + : SVGGraphicsBox(document, element, properties) { } -void LayoutSVGSVG::prepare_for_replaced_layout() +void SVGSVGBox::prepare_for_replaced_layout() { set_has_intrinsic_width(true); set_has_intrinsic_height(true); @@ -41,21 +41,21 @@ void LayoutSVGSVG::prepare_for_replaced_layout() set_intrinsic_height(dom_node().height()); } -void LayoutSVGSVG::before_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) +void SVGSVGBox::before_children_paint(PaintContext& context, PaintPhase phase) { - if (phase != LayoutNode::PaintPhase::Foreground) + if (phase != PaintPhase::Foreground) return; if (!context.has_svg_context()) context.set_svg_context(SVGContext()); - LayoutSVGGraphics::before_children_paint(context, phase); + SVGGraphicsBox::before_children_paint(context, phase); } -void LayoutSVGSVG::after_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) +void SVGSVGBox::after_children_paint(PaintContext& context, PaintPhase phase) { - LayoutSVGGraphics::after_children_paint(context, phase); - if (phase != LayoutNode::PaintPhase::Foreground) + SVGGraphicsBox::after_children_paint(context, phase); + if (phase != PaintPhase::Foreground) return; } diff --git a/Libraries/LibWeb/Layout/LayoutSVGSVG.h b/Libraries/LibWeb/Layout/SVGSVGBox.h similarity index 78% rename from Libraries/LibWeb/Layout/LayoutSVGSVG.h rename to Libraries/LibWeb/Layout/SVGSVGBox.h index 01fb4ea8be8..a03d28d2891 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGSVG.h +++ b/Libraries/LibWeb/Layout/SVGSVGBox.h @@ -26,25 +26,25 @@ #pragma once -#include +#include #include -namespace Web { +namespace Web::Layout { -class LayoutSVGSVG final : public LayoutSVGGraphics { +class SVGSVGBox final : public SVGGraphicsBox { public: - LayoutSVGSVG(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr); - virtual ~LayoutSVGSVG() override = default; + SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr); + virtual ~SVGSVGBox() override = default; - SVG::SVGSVGElement& dom_node() { return downcast(LayoutSVGGraphics::dom_node()); } + SVG::SVGSVGElement& dom_node() { return downcast(SVGGraphicsBox::dom_node()); } virtual void prepare_for_replaced_layout() override; - virtual void before_children_paint(PaintContext& context, LayoutNode::PaintPhase phase) override; + virtual void before_children_paint(PaintContext& context, PaintPhase phase) override; virtual void after_children_paint(PaintContext& context, PaintPhase phase) override; private: - const char* class_name() const override { return "LayoutSVGSVG"; } + const char* class_name() const override { return "SVGSVGBox"; } }; } diff --git a/Libraries/LibWeb/Layout/LayoutTableRow.cpp b/Libraries/LibWeb/Layout/TableBox.cpp similarity index 80% rename from Libraries/LibWeb/Layout/LayoutTableRow.cpp rename to Libraries/LibWeb/Layout/TableBox.cpp index a94e522c476..139a2d70111 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRow.cpp +++ b/Libraries/LibWeb/Layout/TableBox.cpp @@ -25,18 +25,16 @@ */ #include -#include -#include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutTableRow::LayoutTableRow(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutBox(document, &element, move(style)) +TableBox::TableBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Layout::BlockBox(document, &element, move(style)) { } -LayoutTableRow::~LayoutTableRow() +TableBox::~TableBox() { } diff --git a/Libraries/LibWeb/Layout/LayoutTable.h b/Libraries/LibWeb/Layout/TableBox.h similarity index 77% rename from Libraries/LibWeb/Layout/LayoutTable.h rename to Libraries/LibWeb/Layout/TableBox.h index b94874a0b1c..a4079805414 100644 --- a/Libraries/LibWeb/Layout/LayoutTable.h +++ b/Libraries/LibWeb/Layout/TableBox.h @@ -26,22 +26,22 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutTable final : public LayoutBlock { +class TableBox final : public Layout::BlockBox { public: - LayoutTable(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutTable() override; + TableBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~TableBox() override; private: virtual bool is_table() const override { return true; } - virtual const char* class_name() const override { return "LayoutTable"; } + virtual const char* class_name() const override { return "TableBox"; } }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutTable) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_table(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::TableBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_table(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutTableCell.cpp b/Libraries/LibWeb/Layout/TableCellBox.cpp similarity index 77% rename from Libraries/LibWeb/Layout/LayoutTableCell.cpp rename to Libraries/LibWeb/Layout/TableCellBox.cpp index 27c9a2780d4..b5edb41121d 100644 --- a/Libraries/LibWeb/Layout/LayoutTableCell.cpp +++ b/Libraries/LibWeb/Layout/TableCellBox.cpp @@ -25,29 +25,29 @@ */ #include -#include -#include +#include +#include -namespace Web { +namespace Web::Layout { -LayoutTableCell::LayoutTableCell(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutBlock(document, &element, move(style)) +TableCellBox::TableCellBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Layout::BlockBox(document, &element, move(style)) { } -LayoutTableCell::~LayoutTableCell() +TableCellBox::~TableCellBox() { } -size_t LayoutTableCell::colspan() const +size_t TableCellBox::colspan() const { ASSERT(dom_node()); return downcast(*dom_node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1); } -float LayoutTableCell::width_of_logical_containing_block() const +float TableCellBox::width_of_logical_containing_block() const { - if (auto* row = first_ancestor_of_type()) + if (auto* row = first_ancestor_of_type()) return row->width(); return 0; } diff --git a/Libraries/LibWeb/Layout/LayoutTableCell.h b/Libraries/LibWeb/Layout/TableCellBox.h similarity index 71% rename from Libraries/LibWeb/Layout/LayoutTableCell.h rename to Libraries/LibWeb/Layout/TableCellBox.h index 5ce5dc7462e..e8eba520e36 100644 --- a/Libraries/LibWeb/Layout/LayoutTableCell.h +++ b/Libraries/LibWeb/Layout/TableCellBox.h @@ -26,28 +26,28 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutTableCell final : public LayoutBlock { +class TableCellBox final : public BlockBox { public: - LayoutTableCell(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutTableCell() override; + TableCellBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~TableCellBox() override; - LayoutTableCell* next_cell() { return next_sibling_of_type(); } - const LayoutTableCell* next_cell() const { return next_sibling_of_type(); } + TableCellBox* next_cell() { return next_sibling_of_type(); } + const TableCellBox* next_cell() const { return next_sibling_of_type(); } size_t colspan() const; private: virtual bool is_table_cell() const override { return true; } - virtual const char* class_name() const override { return "LayoutTableCell"; } + virtual const char* class_name() const override { return "TableCellBox"; } virtual float width_of_logical_containing_block() const override; }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutTableCell) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_table_cell(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::TableCellBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_table_cell(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Libraries/LibWeb/Layout/TableFormattingContext.cpp index a23d301d19a..71f85eb0ad3 100644 --- a/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -26,19 +26,19 @@ #include #include +#include +#include #include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include +#include #include namespace Web::Layout { -TableFormattingContext::TableFormattingContext(LayoutBox& context_box) +TableFormattingContext::TableFormattingContext(Box& context_box) : BlockFormattingContext(context_box) { } @@ -51,19 +51,19 @@ void TableFormattingContext::run(LayoutMode) { compute_width(context_box()); - context_box().for_each_child_of_type([&](auto& box) { + context_box().for_each_child_of_type([&](auto& box) { compute_width(box); auto column_count = box.column_count(); Vector column_widths; column_widths.resize(column_count); - box.template for_each_child_of_type([&](auto& row) { + box.template for_each_child_of_type([&](auto& row) { calculate_column_widths(row, column_widths); }); float content_height = 0; - box.template for_each_child_of_type([&](auto& row) { + box.template for_each_child_of_type([&](auto& row) { row.set_offset(0, content_height); layout_row(row, column_widths); content_height += row.height(); @@ -75,12 +75,12 @@ void TableFormattingContext::run(LayoutMode) compute_height(context_box()); } -void TableFormattingContext::calculate_column_widths(LayoutBox& row, Vector& column_widths) +void TableFormattingContext::calculate_column_widths(Box& row, Vector& column_widths) { size_t column_index = 0; - auto* table = row.first_ancestor_of_type(); + auto* table = row.first_ancestor_of_type(); bool use_auto_layout = !table || table->style().width().is_undefined_or_auto(); - row.for_each_child_of_type([&](auto& cell) { + row.for_each_child_of_type([&](auto& cell) { compute_width(cell); if (use_auto_layout) { layout_inside(cell, LayoutMode::OnlyRequiredLineBreaks); @@ -92,15 +92,15 @@ void TableFormattingContext::calculate_column_widths(LayoutBox& row, Vector& column_widths) +void TableFormattingContext::layout_row(Box& row, Vector& column_widths) { size_t column_index = 0; float tallest_cell_height = 0; float content_width = 0; - auto* table = row.first_ancestor_of_type(); + auto* table = row.first_ancestor_of_type(); bool use_auto_layout = !table || table->style().width().is_undefined_or_auto(); - row.for_each_child_of_type([&](auto& cell) { + row.for_each_child_of_type([&](auto& cell) { cell.set_offset(row.effective_offset().translated(content_width, 0)); // Layout the cell contents a second time, now that we know its final width. diff --git a/Libraries/LibWeb/Layout/TableFormattingContext.h b/Libraries/LibWeb/Layout/TableFormattingContext.h index 5ab4db75eb4..f5a5cda1647 100644 --- a/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -33,14 +33,14 @@ namespace Web::Layout { class TableFormattingContext final : public BlockFormattingContext { public: - explicit TableFormattingContext(LayoutBox& containing_block); + explicit TableFormattingContext(Box& containing_block); ~TableFormattingContext(); virtual void run(LayoutMode) override; private: - void calculate_column_widths(LayoutBox& row, Vector& column_widths); - void layout_row(LayoutBox& row, Vector& column_widths); + void calculate_column_widths(Box& row, Vector& column_widths); + void layout_row(Box& row, Vector& column_widths); }; } diff --git a/Libraries/LibWeb/Layout/LayoutTable.cpp b/Libraries/LibWeb/Layout/TableRowBox.cpp similarity index 86% rename from Libraries/LibWeb/Layout/LayoutTable.cpp rename to Libraries/LibWeb/Layout/TableRowBox.cpp index 721aa7daa97..0bed4d507b5 100644 --- a/Libraries/LibWeb/Layout/LayoutTable.cpp +++ b/Libraries/LibWeb/Layout/TableRowBox.cpp @@ -25,17 +25,16 @@ */ #include -#include -#include +#include -namespace Web { +namespace Web::Layout { -LayoutTable::LayoutTable(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutBlock(document, &element, move(style)) +TableRowBox::TableRowBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Box(document, &element, move(style)) { } -LayoutTable::~LayoutTable() +TableRowBox::~TableRowBox() { } diff --git a/Libraries/LibWeb/Layout/LayoutTableRow.h b/Libraries/LibWeb/Layout/TableRowBox.h similarity index 76% rename from Libraries/LibWeb/Layout/LayoutTableRow.h rename to Libraries/LibWeb/Layout/TableRowBox.h index a1855abe326..5870789d95c 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRow.h +++ b/Libraries/LibWeb/Layout/TableRowBox.h @@ -26,24 +26,22 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutTableCell; - -class LayoutTableRow final : public LayoutBox { +class TableRowBox final : public Box { public: - LayoutTableRow(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutTableRow() override; + TableRowBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~TableRowBox() override; private: virtual bool is_table_row() const override { return true; } - virtual const char* class_name() const override { return "LayoutTableRow"; } + virtual const char* class_name() const override { return "TableRowBox"; } }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutTableRow) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_table_row(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::TableRowBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_table_row(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutTableRowGroup.cpp b/Libraries/LibWeb/Layout/TableRowGroupBox.cpp similarity index 75% rename from Libraries/LibWeb/Layout/LayoutTableRowGroup.cpp rename to Libraries/LibWeb/Layout/TableRowGroupBox.cpp index c35b7756349..f6ced13a332 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRowGroup.cpp +++ b/Libraries/LibWeb/Layout/TableRowGroupBox.cpp @@ -25,27 +25,27 @@ */ #include -#include -#include -#include +#include +#include +#include -namespace Web { +namespace Web::Layout { -LayoutTableRowGroup::LayoutTableRowGroup(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) - : LayoutBlock(document, &element, move(style)) +TableRowGroupBox::TableRowGroupBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr style) + : Layout::BlockBox(document, &element, move(style)) { } -LayoutTableRowGroup::~LayoutTableRowGroup() +TableRowGroupBox::~TableRowGroupBox() { } -size_t LayoutTableRowGroup::column_count() const +size_t TableRowGroupBox::column_count() const { size_t table_column_count = 0; - for_each_child_of_type([&](auto& row) { + for_each_child_of_type([&](auto& row) { size_t row_column_count = 0; - row.template for_each_child_of_type([&](auto& cell) { + row.template for_each_child_of_type([&](auto& cell) { row_column_count += cell.colspan(); }); table_column_count = max(table_column_count, row_column_count); diff --git a/Libraries/LibWeb/Layout/LayoutTableRowGroup.h b/Libraries/LibWeb/Layout/TableRowGroupBox.h similarity index 76% rename from Libraries/LibWeb/Layout/LayoutTableRowGroup.h rename to Libraries/LibWeb/Layout/TableRowGroupBox.h index a07ced75cb0..c887c770830 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRowGroup.h +++ b/Libraries/LibWeb/Layout/TableRowGroupBox.h @@ -26,24 +26,24 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutTableRowGroup final : public LayoutBlock { +class TableRowGroupBox final : public BlockBox { public: - LayoutTableRowGroup(DOM::Document&, DOM::Element&, NonnullRefPtr); - virtual ~LayoutTableRowGroup() override; + TableRowGroupBox(DOM::Document&, DOM::Element&, NonnullRefPtr); + virtual ~TableRowGroupBox() override; size_t column_count() const; private: virtual bool is_table_row_group() const override { return true; } - virtual const char* class_name() const override { return "LayoutTableRowGroup"; } + virtual const char* class_name() const override { return "TableRowGroupBox"; } }; } -AK_BEGIN_TYPE_TRAITS(Web::LayoutTableRowGroup) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_table_row_group(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::TableRowGroupBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_table_row_group(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutText.cpp b/Libraries/LibWeb/Layout/TextNode.cpp similarity index 92% rename from Libraries/LibWeb/Layout/LayoutText.cpp rename to Libraries/LibWeb/Layout/TextNode.cpp index b6d8e2b001c..4030d40aa11 100644 --- a/Libraries/LibWeb/Layout/LayoutText.cpp +++ b/Libraries/LibWeb/Layout/TextNode.cpp @@ -30,20 +30,20 @@ #include #include #include -#include -#include +#include +#include #include #include -namespace Web { +namespace Web::Layout { -LayoutText::LayoutText(DOM::Document& document, DOM::Text& text) - : LayoutNode(document, &text) +TextNode::TextNode(DOM::Document& document, DOM::Text& text) + : Node(document, &text) { set_inline(true); } -LayoutText::~LayoutText() +TextNode::~TextNode() { } @@ -56,7 +56,7 @@ static bool is_all_whitespace(const StringView& string) return true; } -const String& LayoutText::text_for_style(const CSS::StyleProperties& style) const +const String& TextNode::text_for_style(const CSS::StyleProperties& style) const { static String one_space = " "; if (is_all_whitespace(dom_node().data())) { @@ -66,7 +66,7 @@ const String& LayoutText::text_for_style(const CSS::StyleProperties& style) cons return dom_node().data(); } -void LayoutText::paint_fragment(PaintContext& context, const LineBoxFragment& fragment) const +void TextNode::paint_fragment(PaintContext& context, const LineBoxFragment& fragment) const { auto& painter = context.painter(); painter.set_font(specified_style().font()); @@ -106,7 +106,7 @@ void LayoutText::paint_fragment(PaintContext& context, const LineBoxFragment& fr paint_cursor_if_needed(context, fragment); } -void LayoutText::paint_cursor_if_needed(PaintContext& context, const LineBoxFragment& fragment) const +void TextNode::paint_cursor_if_needed(PaintContext& context, const LineBoxFragment& fragment) const { if (!frame().is_focused_frame()) return; @@ -133,7 +133,7 @@ void LayoutText::paint_cursor_if_needed(PaintContext& context, const LineBoxFrag } template -void LayoutText::for_each_chunk(Callback callback, LayoutMode layout_mode, bool do_wrap_lines, bool do_wrap_breaks) const +void TextNode::for_each_chunk(Callback callback, LayoutMode layout_mode, bool do_wrap_lines, bool do_wrap_breaks) const { Utf8View view(m_text_for_rendering); if (view.is_empty()) @@ -185,7 +185,7 @@ void LayoutText::for_each_chunk(Callback callback, LayoutMode layout_mode, bool commit_chunk(view.end(), false, true); } -void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode layout_mode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks) +void TextNode::split_into_lines_by_rules(BlockBox& container, LayoutMode layout_mode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks) { auto& font = specified_style().font(); float space_width = font.glyph_width(' ') + font.glyph_spacing(); @@ -285,7 +285,7 @@ void LayoutText::split_into_lines_by_rules(LayoutBlock& container, LayoutMode la } } -void LayoutText::split_into_lines(LayoutBlock& container, LayoutMode layout_mode) +void TextNode::split_into_lines(BlockBox& container, LayoutMode layout_mode) { bool do_collapse = true; bool do_wrap_lines = true; diff --git a/Libraries/LibWeb/Layout/LayoutText.h b/Libraries/LibWeb/Layout/TextNode.h similarity index 77% rename from Libraries/LibWeb/Layout/LayoutText.h rename to Libraries/LibWeb/Layout/TextNode.h index 4b30426b847..cf15d391fed 100644 --- a/Libraries/LibWeb/Layout/LayoutText.h +++ b/Libraries/LibWeb/Layout/TextNode.h @@ -27,33 +27,33 @@ #pragma once #include -#include +#include -namespace Web { +namespace Web::Layout { class LineBoxFragment; -class LayoutText : public LayoutNode { +class TextNode : public Node { public: - LayoutText(DOM::Document&, DOM::Text&); - virtual ~LayoutText() override; + TextNode(DOM::Document&, DOM::Text&); + virtual ~TextNode() override; - const DOM::Text& dom_node() const { return static_cast(*LayoutNode::dom_node()); } + const DOM::Text& dom_node() const { return static_cast(*Node::dom_node()); } const String& text_for_style(const CSS::StyleProperties&) const; const String& text_for_rendering() const { return m_text_for_rendering; } - virtual const char* class_name() const override { return "LayoutText"; } + virtual const char* class_name() const override { return "TextNode"; } virtual bool is_text() const final { return true; } void paint_fragment(PaintContext&, const LineBoxFragment&) const; - virtual void split_into_lines(LayoutBlock& container, LayoutMode) override; + virtual void split_into_lines(BlockBox& container, LayoutMode) override; const CSS::StyleProperties& specified_style() const { return parent()->specified_style(); } private: - void split_into_lines_by_rules(LayoutBlock& container, LayoutMode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks); + void split_into_lines_by_rules(BlockBox& container, LayoutMode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks); void paint_cursor_if_needed(PaintContext&, const LineBoxFragment&) const; template @@ -64,6 +64,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutText) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_text(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::TextNode) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_text(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/Layout/LayoutWidget.cpp b/Libraries/LibWeb/Layout/WidgetBox.cpp similarity index 86% rename from Libraries/LibWeb/Layout/LayoutWidget.cpp rename to Libraries/LibWeb/Layout/WidgetBox.cpp index a80394a8a9d..c38aa507658 100644 --- a/Libraries/LibWeb/Layout/LayoutWidget.cpp +++ b/Libraries/LibWeb/Layout/WidgetBox.cpp @@ -31,13 +31,13 @@ #include #include #include -#include +#include #include -namespace Web { +namespace Web::Layout { -LayoutWidget::LayoutWidget(DOM::Document& document, DOM::Element& element, GUI::Widget& widget) - : LayoutReplaced(document, element, CSS::StyleProperties::create()) +WidgetBox::WidgetBox(DOM::Document& document, DOM::Element& element, GUI::Widget& widget) + : ReplacedBox(document, element, CSS::StyleProperties::create()) , m_widget(widget) { set_has_intrinsic_width(true); @@ -46,18 +46,18 @@ LayoutWidget::LayoutWidget(DOM::Document& document, DOM::Element& element, GUI:: set_intrinsic_height(widget.height()); } -LayoutWidget::~LayoutWidget() +WidgetBox::~WidgetBox() { widget().remove_from_parent(); } -void LayoutWidget::did_set_rect() +void WidgetBox::did_set_rect() { - LayoutReplaced::did_set_rect(); + ReplacedBox::did_set_rect(); update_widget(); } -void LayoutWidget::update_widget() +void WidgetBox::update_widget() { auto adjusted_widget_position = absolute_rect().location().to_type(); auto& page_view = static_cast(frame().page()->client()); diff --git a/Libraries/LibWeb/Layout/LayoutWidget.h b/Libraries/LibWeb/Layout/WidgetBox.h similarity index 80% rename from Libraries/LibWeb/Layout/LayoutWidget.h rename to Libraries/LibWeb/Layout/WidgetBox.h index 90051f98104..0c5f734cd24 100644 --- a/Libraries/LibWeb/Layout/LayoutWidget.h +++ b/Libraries/LibWeb/Layout/WidgetBox.h @@ -26,14 +26,14 @@ #pragma once -#include +#include -namespace Web { +namespace Web::Layout { -class LayoutWidget final : public LayoutReplaced { +class WidgetBox final : public ReplacedBox { public: - LayoutWidget(DOM::Document&, DOM::Element&, GUI::Widget&); - virtual ~LayoutWidget() override; + WidgetBox(DOM::Document&, DOM::Element&, GUI::Widget&); + virtual ~WidgetBox() override; GUI::Widget& widget() { return m_widget; } const GUI::Widget& widget() const { return m_widget; } @@ -43,7 +43,7 @@ public: void update_widget(); private: - virtual const char* class_name() const override { return "LayoutWidget"; } + virtual const char* class_name() const override { return "WidgetBox"; } virtual void did_set_rect() override; @@ -52,6 +52,6 @@ private: } -AK_BEGIN_TYPE_TRAITS(Web::LayoutWidget) -static bool is_type(const Web::LayoutNode& layout_node) { return layout_node.is_widget(); } +AK_BEGIN_TYPE_TRAITS(Web::Layout::WidgetBox) +static bool is_type(const Web::Layout::Node& layout_node) { return layout_node.is_widget(); } AK_END_TYPE_TRAITS() diff --git a/Libraries/LibWeb/LayoutTreeModel.cpp b/Libraries/LibWeb/LayoutTreeModel.cpp index cbfb583109c..7ee9eced5e4 100644 --- a/Libraries/LibWeb/LayoutTreeModel.cpp +++ b/Libraries/LibWeb/LayoutTreeModel.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -51,7 +51,7 @@ GUI::ModelIndex LayoutTreeModel::index(int row, int column, const GUI::ModelInde { if (!parent.is_valid()) return create_index(row, column, m_document->layout_node()); - auto& parent_node = *static_cast(parent.internal_data()); + auto& parent_node = *static_cast(parent.internal_data()); return create_index(row, column, parent_node.child_at_index(row)); } @@ -59,7 +59,7 @@ GUI::ModelIndex LayoutTreeModel::parent_index(const GUI::ModelIndex& index) cons { if (!index.is_valid()) return {}; - auto& node = *static_cast(index.internal_data()); + auto& node = *static_cast(index.internal_data()); if (!node.parent()) return {}; @@ -85,7 +85,7 @@ int LayoutTreeModel::row_count(const GUI::ModelIndex& index) const { if (!index.is_valid()) return 1; - auto& node = *static_cast(index.internal_data()); + auto& node = *static_cast(index.internal_data()); return node.child_count(); } @@ -117,7 +117,7 @@ static String with_whitespace_collapsed(const StringView& string) GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { - auto& node = *static_cast(index.internal_data()); + auto& node = *static_cast(index.internal_data()); if (role == GUI::ModelRole::Icon) { if (node.is_root()) return m_document_icon; @@ -127,7 +127,7 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole } if (role == GUI::ModelRole::Display) { if (node.is_text()) - return String::format("LayoutText: %s", with_whitespace_collapsed(downcast(node).text_for_rendering()).characters()); + return String::format("TextNode: %s", with_whitespace_collapsed(downcast(node).text_for_rendering()).characters()); StringBuilder builder; builder.append(node.class_name()); builder.append(' '); diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 3d0e4ed85f2..e7e310ab315 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -33,14 +33,14 @@ #include #include #include -#include +#include #include #include #include namespace Web { -static Gfx::IntPoint compute_mouse_event_offset(const Gfx::IntPoint& position, const LayoutNode& layout_node) +static Gfx::IntPoint compute_mouse_event_offset(const Gfx::IntPoint& position, const Layout::Node& layout_node) { auto top_left_of_layout_node = layout_node.box_type_agnostic_position(); return { @@ -58,14 +58,14 @@ EventHandler::~EventHandler() { } -const LayoutDocument* EventHandler::layout_root() const +const Layout::InitialContainingBlockBox* EventHandler::layout_root() const { if (!m_frame.document()) return nullptr; return m_frame.document()->layout_node(); } -LayoutDocument* EventHandler::layout_root() +Layout::InitialContainingBlockBox* EventHandler::layout_root() { if (!m_frame.document()) return nullptr; @@ -84,15 +84,15 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button bool handled_event = false; - auto result = layout_root()->hit_test(position, HitTestType::Exact); + auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact); if (result.layout_node && result.layout_node->wants_mouse_events()) { result.layout_node->handle_mouseup({}, position, button, modifiers); - // Things may have changed as a consequence of LayoutNode::handle_mouseup(). Hit test again. + // Things may have changed as a consequence of Layout::Node::handle_mouseup(). Hit test again. if (!layout_root()) return true; - result = layout_root()->hit_test(position, HitTestType::Exact); + result = layout_root()->hit_test(position, Layout::HitTestType::Exact); } if (result.layout_node && result.layout_node->dom_node()) { @@ -126,7 +126,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt NonnullRefPtr document = *m_frame.document(); - auto result = layout_root()->hit_test(position, HitTestType::Exact); + auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact); if (!result.layout_node) return false; @@ -193,7 +193,7 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt } } else { if (button == GUI::MouseButton::Left) { - auto result = layout_root()->hit_test(position, HitTestType::TextCursor); + auto result = layout_root()->hit_test(position, Layout::HitTestType::TextCursor); if (result.layout_node && result.layout_node->dom_node()) { m_frame.set_cursor_position(DOM::Position(*node, result.index_in_node)); layout_root()->set_selection({ { result.layout_node, result.index_in_node }, {} }); @@ -223,7 +223,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt bool hovered_node_changed = false; bool is_hovering_link = false; bool is_hovering_text = false; - auto result = layout_root()->hit_test(position, HitTestType::Exact); + auto result = layout_root()->hit_test(position, Layout::HitTestType::Exact); const HTML::HTMLAnchorElement* hovered_link_element = nullptr; if (result.layout_node) { @@ -258,7 +258,7 @@ bool EventHandler::handle_mousemove(const Gfx::IntPoint& position, unsigned butt return true; } if (m_in_mouse_selection) { - auto hit = layout_root()->hit_test(position, HitTestType::TextCursor); + auto hit = layout_root()->hit_test(position, Layout::HitTestType::TextCursor); if (hit.layout_node && hit.layout_node->dom_node()) { layout_root()->set_selection_end({ hit.layout_node, hit.index_in_node }); } @@ -368,7 +368,7 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin return false; } -void EventHandler::set_mouse_event_tracking_layout_node(LayoutNode* layout_node) +void EventHandler::set_mouse_event_tracking_layout_node(Layout::Node* layout_node) { if (layout_node) m_mouse_event_tracking_layout_node = layout_node->make_weak_ptr(); diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h index e077a71ded1..65acfbdbe1e 100644 --- a/Libraries/LibWeb/Page/EventHandler.h +++ b/Libraries/LibWeb/Page/EventHandler.h @@ -48,14 +48,14 @@ public: bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point); - void set_mouse_event_tracking_layout_node(LayoutNode*); + void set_mouse_event_tracking_layout_node(Layout::Node*); private: bool focus_next_element(); bool focus_previous_element(); - LayoutDocument* layout_root(); - const LayoutDocument* layout_root() const; + Layout::InitialContainingBlockBox* layout_root(); + const Layout::InitialContainingBlockBox* layout_root() const; void dump_selection(const char* event_name) const; @@ -63,7 +63,7 @@ private: bool m_in_mouse_selection { false }; - WeakPtr m_mouse_event_tracking_layout_node; + WeakPtr m_mouse_event_tracking_layout_node; }; } diff --git a/Libraries/LibWeb/Page/Frame.cpp b/Libraries/LibWeb/Page/Frame.cpp index f7b5a7ed780..c9e0a3e6cdc 100644 --- a/Libraries/LibWeb/Page/Frame.cpp +++ b/Libraries/LibWeb/Page/Frame.cpp @@ -27,10 +27,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace Web { @@ -137,7 +137,7 @@ void Frame::did_scroll(Badge) return; if (!m_document->layout_node()) return; - m_document->layout_node()->for_each_in_subtree_of_type([&](auto& layout_widget) { + m_document->layout_node()->for_each_in_subtree_of_type([&](auto& layout_widget) { layout_widget.update_widget(); return IterationDecision::Continue; }); @@ -165,8 +165,8 @@ void Frame::scroll_to_anchor(const String& fragment) auto& layout_node = *element->layout_node(); Gfx::FloatRect float_rect { layout_node.box_type_agnostic_position(), { (float)viewport_rect().width(), (float)viewport_rect().height() } }; - if (is(layout_node)) { - auto& layout_box = downcast(layout_node); + if (is(layout_node)) { + auto& layout_box = downcast(layout_node); auto padding_box = layout_box.box_model().padding_box(layout_box); float_rect.move_by(-padding_box.left, -padding_box.top); } @@ -227,24 +227,24 @@ String Frame::selected_text() const auto selection = layout_root->selection().normalized(); if (selection.start().layout_node == selection.end().layout_node) { - if (!is(*selection.start().layout_node)) + if (!is(*selection.start().layout_node)) return ""; - return downcast(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node); + return downcast(*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_node)) { - auto& text = downcast(*layout_node).text_for_rendering(); + if (is(*layout_node)) { + auto& text = downcast(*layout_node).text_for_rendering(); builder.append(text.substring(selection.start().index_in_node, text.length() - selection.start().index_in_node)); } // Middle nodes layout_node = layout_node->next_in_pre_order(); while (layout_node && layout_node != selection.end().layout_node) { - if (is(*layout_node)) - builder.append(downcast(*layout_node).text_for_rendering()); - else if (is(*layout_node) || is(*layout_node)) + if (is(*layout_node)) + builder.append(downcast(*layout_node).text_for_rendering()); + else if (is(*layout_node) || is(*layout_node)) builder.append('\n'); layout_node = layout_node->next_in_pre_order(); @@ -252,8 +252,8 @@ String Frame::selected_text() const // End node ASSERT(layout_node == selection.end().layout_node); - if (is(*layout_node)) { - auto& text = downcast(*layout_node).text_for_rendering(); + if (is(*layout_node)) { + auto& text = downcast(*layout_node).text_for_rendering(); builder.append(text.substring(0, selection.end().index_in_node)); } diff --git a/Libraries/LibWeb/Painting/StackingContext.cpp b/Libraries/LibWeb/Painting/StackingContext.cpp index 4d27abacd88..daca00c5971 100644 --- a/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Libraries/LibWeb/Painting/StackingContext.cpp @@ -26,13 +26,13 @@ #include #include -#include -#include +#include +#include #include -namespace Web { +namespace Web::Layout { -StackingContext::StackingContext(LayoutBox& box, StackingContext* parent) +StackingContext::StackingContext(Box& box, StackingContext* parent) : m_box(box) , m_parent(parent) { @@ -47,14 +47,14 @@ StackingContext::StackingContext(LayoutBox& box, StackingContext* parent) } } -void StackingContext::paint(PaintContext& context, LayoutNode::PaintPhase phase) +void StackingContext::paint(PaintContext& context, Node::PaintPhase phase) { if (!m_box.is_root()) { m_box.paint(context, phase); } else { - // NOTE: LayoutDocument::paint() merely calls StackingContext::paint() + // NOTE: InitialContainingBlockBox::paint() merely calls StackingContext::paint() // so we call its base class instead. - downcast(m_box).LayoutBlock::paint(context, phase); + downcast(m_box).BlockBox::paint(context, phase); } for (auto* child : m_children) { child->paint(context, phase); @@ -67,9 +67,9 @@ HitTestResult StackingContext::hit_test(const Gfx::IntPoint& position, HitTestTy if (!m_box.is_root()) { result = m_box.hit_test(position, type); } else { - // NOTE: LayoutDocument::hit_test() merely calls StackingContext::hit_test() + // NOTE: InitialContainingBlockBox::hit_test() merely calls StackingContext::hit_test() // so we call its base class instead. - result = downcast(m_box).LayoutBlock::hit_test(position, type); + result = downcast(m_box).BlockBox::hit_test(position, type); } for (auto* child : m_children) { diff --git a/Libraries/LibWeb/Painting/StackingContext.h b/Libraries/LibWeb/Painting/StackingContext.h index d7621c3829f..7e2e11e2d9e 100644 --- a/Libraries/LibWeb/Painting/StackingContext.h +++ b/Libraries/LibWeb/Painting/StackingContext.h @@ -27,26 +27,24 @@ #pragma once #include -#include +#include -namespace Web { - -class LayoutBox; +namespace Web::Layout { class StackingContext { public: - StackingContext(LayoutBox&, StackingContext* parent); + StackingContext(Box&, StackingContext* parent); StackingContext* parent() { return m_parent; } const StackingContext* parent() const { return m_parent; } - void paint(PaintContext&, LayoutNode::PaintPhase); + void paint(PaintContext&, Layout::Node::PaintPhase); HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const; void dump(int indent = 0) const; private: - LayoutBox& m_box; + Box& m_box; StackingContext* const m_parent { nullptr }; Vector m_children; }; diff --git a/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Libraries/LibWeb/SVG/SVGPathElement.cpp index 36a2ef2fb6b..a0ec408fb30 100644 --- a/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -430,12 +430,12 @@ SVGPathElement::SVGPathElement(DOM::Document& document, const QualifiedName& qua { } -RefPtr SVGPathElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr SVGPathElement::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); if (style->display() == CSS::Display::None) return nullptr; - return adopt(*new LayoutSVGPath(document(), *this, move(style))); + return adopt(*new Layout::SVGPathBox(document(), *this, move(style))); } void SVGPathElement::parse_attribute(const FlyString& name, const String& value) diff --git a/Libraries/LibWeb/SVG/SVGPathElement.h b/Libraries/LibWeb/SVG/SVGPathElement.h index 922c92b6908..bca0da456d5 100644 --- a/Libraries/LibWeb/SVG/SVGPathElement.h +++ b/Libraries/LibWeb/SVG/SVGPathElement.h @@ -109,7 +109,7 @@ public: SVGPathElement(DOM::Document&, const QualifiedName& qualified_name); virtual ~SVGPathElement() override = default; - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; virtual void parse_attribute(const FlyString& name, const String& value) override; diff --git a/Libraries/LibWeb/SVG/SVGSVGElement.cpp b/Libraries/LibWeb/SVG/SVGSVGElement.cpp index 0a0b2f75f37..cd5e1e6fbd1 100644 --- a/Libraries/LibWeb/SVG/SVGSVGElement.cpp +++ b/Libraries/LibWeb/SVG/SVGSVGElement.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,12 +40,12 @@ SVGSVGElement::SVGSVGElement(DOM::Document& document, const QualifiedName& quali { } -RefPtr SVGSVGElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr SVGSVGElement::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); if (style->display() == CSS::Display::None) return nullptr; - return adopt(*new LayoutSVGSVG(document(), *this, move(style))); + return adopt(*new Layout::SVGSVGBox(document(), *this, move(style))); } unsigned SVGSVGElement::width() const diff --git a/Libraries/LibWeb/SVG/SVGSVGElement.h b/Libraries/LibWeb/SVG/SVGSVGElement.h index 82be0cada22..4478ebd6174 100644 --- a/Libraries/LibWeb/SVG/SVGSVGElement.h +++ b/Libraries/LibWeb/SVG/SVGSVGElement.h @@ -37,7 +37,7 @@ public: SVGSVGElement(DOM::Document&, const QualifiedName& qualified_name); - virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr create_layout_node(const CSS::StyleProperties* parent_style) override; unsigned width() const; unsigned height() const; diff --git a/Services/WebContent/PageHost.cpp b/Services/WebContent/PageHost.cpp index f6603645ad1..a23cf0c764d 100644 --- a/Services/WebContent/PageHost.cpp +++ b/Services/WebContent/PageHost.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -66,7 +66,7 @@ void PageHost::set_palette_impl(const Gfx::PaletteImpl& impl) m_palette_impl = impl; } -Web::LayoutDocument* PageHost::layout_root() +Web::Layout::InitialContainingBlockBox* PageHost::layout_root() { auto* document = page().main_frame().document(); if (!document) diff --git a/Services/WebContent/PageHost.h b/Services/WebContent/PageHost.h index 6e3a9ec68e6..91db8debef4 100644 --- a/Services/WebContent/PageHost.h +++ b/Services/WebContent/PageHost.h @@ -67,7 +67,7 @@ private: explicit PageHost(ClientConnection&); - Web::LayoutDocument* layout_root(); + Web::Layout::InitialContainingBlockBox* layout_root(); void setup_palette(); ClientConnection& m_client;