diff options
author | Andreas Kling <kling@serenityos.org> | 2020-11-22 15:53:01 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-22 15:56:27 +0100 |
commit | 5aeab9878ebb3b9749be633e9d5812a3181141ca (patch) | |
tree | d36c2af3ff959b79ce7886a57a78357015078936 /Libraries | |
parent | f358f2255fec7228b7ddf510936a2b7a150e509e (diff) | |
download | serenity-5aeab9878ebb3b9749be633e9d5812a3181141ca.zip |
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!)
Diffstat (limited to 'Libraries')
109 files changed, 854 insertions, 871 deletions
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index a164f3046c..f084378cd1 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 412fa7c3d0..dd85754ec2 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 227e357204..ec781aee6d 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 c0b40984b3..0f1db911bf 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 472d53da07..8622fea9ca 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 0814bd0bf6..7e3f0ab8d2 100644 --- a/Libraries/LibWeb/DOM/Comment.cpp +++ b/Libraries/LibWeb/DOM/Comment.cpp @@ -25,7 +25,7 @@ */ #include <LibWeb/DOM/Comment.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/TextNode.h> namespace Web::DOM { diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 0a1fe0e506..c7b00c14ee 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -54,7 +54,7 @@ #include <LibWeb/HTML/HTMLTitleElement.h> #include <LibWeb/InProcessWebView.h> #include <LibWeb/Layout/BlockFormattingContext.h> -#include <LibWeb/Layout/LayoutDocument.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> #include <LibWeb/Layout/LayoutTreeBuilder.h> #include <LibWeb/Namespace.h> #include <LibWeb/Origin.h> @@ -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<LayoutNode> layout_nodes; + NonnullRefPtrVector<Layout::Node> 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<LayoutDocument>(tree_builder.build(*this)); + Layout::LayoutTreeBuilder tree_builder; + m_layout_root = static_ptr_cast<Layout::InitialContainingBlockBox>(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<LayoutNode> Document::create_layout_node(const CSS::StyleProperties*) +RefPtr<Layout::Node> 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<const LayoutDocument*>(Node::layout_node()); + return static_cast<const Layout::InitialContainingBlockBox*>(Node::layout_node()); } -LayoutDocument* Document::layout_node() +Layout::InitialContainingBlockBox* Document::layout_node() { - return static_cast<LayoutDocument*>(Node::layout_node()); + return static_cast<Layout::InitialContainingBlockBox*>(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 c3d4dc523c..cb400bd6e2 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override; void tear_down_layout_tree(); @@ -244,7 +244,7 @@ private: RefPtr<Window> m_window; - RefPtr<LayoutDocument> m_layout_root; + RefPtr<Layout::InitialContainingBlockBox> m_layout_root; Optional<Color> m_link_color; Optional<Color> m_active_link_color; diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 51b77ea9f7..7e0ab56d8f 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -34,14 +34,14 @@ #include <LibWeb/DOM/Text.h> #include <LibWeb/Dump.h> #include <LibWeb/HTML/Parser/HTMLDocumentParser.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutInline.h> -#include <LibWeb/Layout/LayoutListItem.h> -#include <LibWeb/Layout/LayoutTable.h> -#include <LibWeb/Layout/LayoutTableCell.h> -#include <LibWeb/Layout/LayoutTableRow.h> -#include <LibWeb/Layout/LayoutTableRowGroup.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/InlineNode.h> #include <LibWeb/Layout/LayoutTreeBuilder.h> +#include <LibWeb/Layout/ListItemBox.h> +#include <LibWeb/Layout/TableBox.h> +#include <LibWeb/Layout/TableCellBox.h> +#include <LibWeb/Layout/TableRowBox.h> +#include <LibWeb/Layout/TableRowGroupBox.h> namespace Web::DOM { @@ -112,7 +112,7 @@ bool Element::has_class(const FlyString& class_name) const return false; } -RefPtr<LayoutNode> Element::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> Element::create_layout_node(const CSS::StyleProperties* parent_style) { auto style = document().style_resolver().resolve_style(*this, parent_style); const_cast<Element&>(*this).m_resolved_style = style; @@ -125,26 +125,26 @@ RefPtr<LayoutNode> 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 467ca8263e..d9b704f841 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -33,7 +33,7 @@ #include <LibWeb/DOM/ParentNode.h> #include <LibWeb/DOM/TagNames.h> #include <LibWeb/HTML/AttributeNames.h> -#include <LibWeb/Layout/LayoutNode.h> +#include <LibWeb/Layout/Node.h> #include <LibWeb/QualifiedName.h> namespace Web::DOM { @@ -82,8 +82,8 @@ public: void recompute_style(); - LayoutNodeWithStyle* layout_node() { return static_cast<LayoutNodeWithStyle*>(Node::layout_node()); } - const LayoutNodeWithStyle* layout_node() const { return static_cast<const LayoutNodeWithStyle*>(Node::layout_node()); } + Layout::NodeWithStyle* layout_node() { return static_cast<Layout::NodeWithStyle*>(Node::layout_node()); } + const Layout::NodeWithStyle* layout_node() const { return static_cast<const Layout::NodeWithStyle*>(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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + RefPtr<Layout::Node> 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 c81bebf7b8..318e8ebf98 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -39,11 +39,11 @@ #include <LibWeb/DOM/EventListener.h> #include <LibWeb/DOM/Node.h> #include <LibWeb/HTML/HTMLAnchorElement.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutInline.h> -#include <LibWeb/Layout/LayoutNode.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> +#include <LibWeb/Layout/InlineNode.h> +#include <LibWeb/Layout/Node.h> +#include <LibWeb/Layout/TextNode.h> //#define EVENT_DEBUG @@ -105,7 +105,7 @@ void Node::set_text_content(const String& content) document().invalidate_layout(); } -RefPtr<LayoutNode> Node::create_layout_node(const CSS::StyleProperties*) +RefPtr<Layout::Node> 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>, LayoutNode* layout_node) const +void Node::set_layout_node(Badge<Layout::Node>, 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 9b2573c3fc..a415b17d4b 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -84,7 +84,7 @@ public: RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true); void remove_all_children(); - virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style); + virtual RefPtr<Layout::Node> 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>, LayoutNode*) const; + void set_layout_node(Badge<Layout::Node>, 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<LayoutNode> m_layout_node; + mutable WeakPtr<Layout::Node> 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 043998538e..a0c6ba9dab 100644 --- a/Libraries/LibWeb/DOM/Text.cpp +++ b/Libraries/LibWeb/DOM/Text.cpp @@ -25,7 +25,7 @@ */ #include <LibWeb/DOM/Text.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/TextNode.h> namespace Web::DOM { @@ -38,9 +38,9 @@ Text::~Text() { } -RefPtr<LayoutNode> Text::create_layout_node(const CSS::StyleProperties*) +RefPtr<Layout::Node> 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 8ba78b7179..1b73543974 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override; }; } diff --git a/Libraries/LibWeb/Dump.cpp b/Libraries/LibWeb/Dump.cpp index d2eb66758a..5318fd7200 100644 --- a/Libraries/LibWeb/Dump.cpp +++ b/Libraries/LibWeb/Dump.cpp @@ -37,9 +37,9 @@ #include <LibWeb/DOM/Text.h> #include <LibWeb/Dump.h> #include <LibWeb/HTML/HTMLTemplateElement.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutNode.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/Node.h> +#include <LibWeb/Layout/TextNode.h> #include <stdio.h> 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<LayoutBox>(layout_node); + auto& layout_box = downcast<Layout::Box>(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<const LayoutBlock&>(layout_node).children_are_inline()) { - auto& block = static_cast<const LayoutBlock&>(layout_node); + if (layout_node.is_block() && static_cast<const Layout::BlockBox&>(layout_node).children_are_inline()) { + auto& block = static_cast<const Layout::BlockBox&>(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<const LayoutText&>(fragment.layout_node()); + auto& layout_text = static_cast<const Layout::TextNode&>(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 6bb1594837..df0164a6f0 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 ed56031c91..741752a4d0 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 9774430ca5..3d7e7e5eec 100644 --- a/Libraries/LibWeb/HTML/HTMLBRElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLBRElement.cpp @@ -25,7 +25,7 @@ */ #include <LibWeb/HTML/HTMLBRElement.h> -#include <LibWeb/Layout/LayoutBreak.h> +#include <LibWeb/Layout/BreakNode.h> namespace Web::HTML { @@ -38,9 +38,9 @@ HTMLBRElement::~HTMLBRElement() { } -RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const CSS::StyleProperties*) +RefPtr<Layout::Node> 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 1529e35634..8a6cd81641 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override; }; } diff --git a/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp b/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp index ab41c20f26..911a8940bd 100644 --- a/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLBlinkElement.cpp @@ -28,7 +28,7 @@ #include <LibWeb/CSS/StyleProperties.h> #include <LibWeb/CSS/StyleValue.h> #include <LibWeb/HTML/HTMLBlinkElement.h> -#include <LibWeb/Layout/LayoutNode.h> +#include <LibWeb/Layout/Node.h> namespace Web::HTML { diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp index a30c9a3ed5..bbad3a0657 100644 --- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp @@ -30,7 +30,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/CanvasRenderingContext2D.h> #include <LibWeb/HTML/HTMLCanvasElement.h> -#include <LibWeb/Layout/LayoutCanvas.h> +#include <LibWeb/Layout/CanvasBox.h> namespace Web::HTML { @@ -55,12 +55,12 @@ unsigned HTMLCanvasElement::height() const return attribute(HTML::AttributeNames::height).to_uint().value_or(150); } -RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> 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 75f9b17008..4bcb8b0914 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override; RefPtr<Gfx::Bitmap> m_bitmap; RefPtr<CanvasRenderingContext2D> m_context; diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp index edf35366df..bb364a19a3 100644 --- a/Libraries/LibWeb/HTML/HTMLElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLElement.cpp @@ -27,7 +27,7 @@ #include <AK/StringBuilder.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLElement.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/TextNode.h> namespace Web::HTML { @@ -117,10 +117,10 @@ String HTMLElement::inner_text() if (!layout_node()) return text_content(); - Function<void(const LayoutNode&)> recurse = [&](auto& node) { + Function<void(const Layout::Node&)> recurse = [&](auto& node) { for (auto* child = node.first_child(); child; child = child->next_sibling()) { if (child->is_text()) - builder.append(downcast<LayoutText>(*child).text_for_rendering()); + builder.append(downcast<Layout::TextNode>(*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 8577f364d3..115783b747 100644 --- a/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -35,8 +35,7 @@ #include <LibWeb/HTML/HTMLIFrameElement.h> #include <LibWeb/HTML/Parser/HTMLDocumentParser.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutFrame.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/FrameBox.h> #include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Origin.h> #include <LibWeb/Page/Frame.h> @@ -52,10 +51,10 @@ HTMLIFrameElement::~HTMLIFrameElement() { } -RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> 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 71c0746b0c..f3f96d40fb 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> 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 9d9439d0ce..d78f911fcf 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -31,7 +31,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Event.h> #include <LibWeb/HTML/HTMLImageElement.h> -#include <LibWeb/Layout/LayoutImage.h> +#include <LibWeb/Layout/ImageBox.h> #include <LibWeb/Loader/ResourceLoader.h> 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<LayoutNode> HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> 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 011296ad93..a07762bd63 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -53,7 +53,7 @@ private: void animate(); - virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> 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 3ab1443e6e..70e87f7eb8 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -31,9 +31,9 @@ #include <LibWeb/HTML/HTMLFormElement.h> #include <LibWeb/HTML/HTMLInputElement.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutButton.h> -#include <LibWeb/Layout/LayoutCheckBox.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/ButtonBox.h> +#include <LibWeb/Layout/CheckBox.h> +#include <LibWeb/Layout/WidgetBox.h> #include <LibWeb/Page/Frame.h> namespace Web::HTML { @@ -47,7 +47,7 @@ HTMLInputElement::~HTMLInputElement() { } -void HTMLInputElement::did_click_button(Badge<LayoutButton>) +void HTMLInputElement::did_click_button(Badge<Layout::ButtonBox>) { dispatch_event(DOM::Event::create("click")); @@ -60,7 +60,7 @@ void HTMLInputElement::did_click_button(Badge<LayoutButton>) } } -RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style) { ASSERT(document().page()); auto& page = *document().page(); @@ -74,15 +74,15 @@ RefPtr<LayoutNode> 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<GUI::TextBox>(); text_box.set_text(value()); text_box.on_change = [this] { - auto& widget = downcast<LayoutWidget>(layout_node())->widget(); + auto& widget = downcast<Layout::WidgetBox>(layout_node())->widget(); const_cast<HTMLInputElement*>(this)->set_attribute(HTML::AttributeNames::value, static_cast<const GUI::TextBox&>(widget).text()); }; int text_width = Gfx::Font::default_font().width(value()); @@ -93,7 +93,7 @@ RefPtr<LayoutNode> 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 1ff40da6f6..84e0ecf1c1 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> 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<LayoutButton>); + void did_click_button(Badge<Layout::ButtonBox>); private: bool m_checked { false }; diff --git a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index e5f7ab2fd5..4a3d0a11d4 100644 --- a/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -30,7 +30,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Event.h> #include <LibWeb/HTML/HTMLObjectElement.h> -#include <LibWeb/Layout/LayoutImage.h> +#include <LibWeb/Layout/ImageBox.h> #include <LibWeb/Loader/ResourceLoader.h> 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<LayoutNode> HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> 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<LayoutNode> 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 967ada32cc..7497604623 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> 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 2580f80b4e..88fe767009 100644 --- a/Libraries/LibWeb/InProcessWebView.cpp +++ b/Libraries/LibWeb/InProcessWebView.cpp @@ -46,10 +46,10 @@ #include <LibWeb/HTML/HTMLImageElement.h> #include <LibWeb/HTML/Parser/HTMLDocumentParser.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutBreak.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutNode.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/BreakNode.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> +#include <LibWeb/Layout/Node.h> +#include <LibWeb/Layout/TextNode.h> #include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Page/EventHandler.h> #include <LibWeb/Page/Frame.h> @@ -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<LayoutText>(*first_layout_node)) + if (is<Layout::TextNode>(*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<LayoutText>(*layout_node)) + for (const Layout::Node* layout_node = first_layout_node; layout_node; layout_node = layout_node->next_in_pre_order()) { + if (is<Layout::TextNode>(*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<LayoutText>(*last_layout_node)) - last_layout_node_index_in_node = downcast<LayoutText>(*last_layout_node).text_for_rendering().length() - 1; + if (is<Layout::TextNode>(*last_layout_node)) + last_layout_node_index_in_node = downcast<Layout::TextNode>(*last_layout_node).text_for_rendering().length() - 1; layout_root->set_selection({ { first_layout_node, 0 }, { last_layout_node, last_layout_node_index_in_node } }); update(); @@ -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<LayoutDocument*>(document()->layout_node()); + return const_cast<Layout::InitialContainingBlockBox*>(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 e84778a2a5..7194836b9d 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 index b3b85ed931..54799bcbb4 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.cpp +++ b/Libraries/LibWeb/Layout/BlockBox.cpp @@ -28,40 +28,40 @@ #include <LibWeb/CSS/StyleResolver.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/Dump.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutInline.h> -#include <LibWeb/Layout/LayoutReplaced.h> -#include <LibWeb/Layout/LayoutText.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> +#include <LibWeb/Layout/InlineNode.h> +#include <LibWeb/Layout/ReplacedBox.h> +#include <LibWeb/Layout/TextNode.h> +#include <LibWeb/Layout/WidgetBox.h> #include <math.h> -namespace Web { +namespace Web::Layout { -LayoutBlock::LayoutBlock(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBox(document, node, move(style)) +BlockBox::BlockBox(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> 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<LayoutBox>(fragment.layout_node()) && downcast<LayoutBox>(fragment.layout_node()).stacking_context()) + if (is<Box>(fragment.layout_node()) && downcast<Box>(fragment.layout_node()).stacking_context()) continue; if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) { if (fragment.layout_node().is_block()) - return downcast<LayoutBlock>(fragment.layout_node()).hit_test(position, type); + return downcast<BlockBox>(fragment.layout_node()).hit_test(position, type); return { fragment.layout_node(), fragment.text_index_at(position.x()) }; } if (fragment.absolute_rect().top() <= position.y()) @@ -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<CSS::StyleProperties> LayoutBlock::style_for_anonymous_block() const +NonnullRefPtr<CSS::StyleProperties> BlockBox::style_for_anonymous_block() const { auto new_style = CSS::StyleProperties::create(); @@ -131,7 +131,7 @@ NonnullRefPtr<CSS::StyleProperties> 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 index 7e5c4341c2..4234dcd39a 100644 --- a/Libraries/LibWeb/Layout/LayoutBlock.h +++ b/Libraries/LibWeb/Layout/BlockBox.h @@ -26,35 +26,35 @@ #pragma once -#include <LibWeb/Layout/LayoutBox.h> +#include <LibWeb/Layout/Box.h> #include <LibWeb/Layout/LineBox.h> -namespace Web { +namespace Web::Layout { -class LayoutBlock : public LayoutBox { +class BlockBox : public Box { public: - LayoutBlock(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutBlock() override; + BlockBox(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); + 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<LayoutBlock>(LayoutNode::previous_sibling()); } - const LayoutBlock* previous_sibling() const { return downcast<LayoutBlock>(LayoutNode::previous_sibling()); } - LayoutBlock* next_sibling() { return downcast<LayoutBlock>(LayoutNode::next_sibling()); } - const LayoutBlock* next_sibling() const { return downcast<LayoutBlock>(LayoutNode::next_sibling()); } + BlockBox* previous_sibling() { return downcast<BlockBox>(Node::previous_sibling()); } + const BlockBox* previous_sibling() const { return downcast<BlockBox>(Node::previous_sibling()); } + BlockBox* next_sibling() { return downcast<BlockBox>(Node::next_sibling()); } + const BlockBox* next_sibling() const { return downcast<BlockBox>(Node::next_sibling()); } template<typename Callback> void for_each_fragment(Callback); template<typename Callback> 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<typename Callback> -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<typename Callback> -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 3c22fc1d52..5f1483e043 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -26,18 +26,18 @@ #include <LibWeb/CSS/Length.h> #include <LibWeb/DOM/Node.h> +#include <LibWeb/Layout/BlockBox.h> #include <LibWeb/Layout/BlockFormattingContext.h> +#include <LibWeb/Layout/Box.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> #include <LibWeb/Layout/InlineFormattingContext.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutBox.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutListItem.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/ListItemBox.h> +#include <LibWeb/Layout/WidgetBox.h> #include <LibWeb/Page/Frame.h> 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<LayoutReplaced>(box); + // FIXME: This should not be done *by* ReplacedBox + auto& replaced = downcast<ReplacedBox>(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<LayoutReplaced>(box).calculate_height(); + // FIXME: This should not be done *by* ReplacedBox + auto height = downcast<ReplacedBox>(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<LayoutBox>([&](auto& box) { + context_box().for_each_in_subtree_of_type<Box>([&](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<LayoutListItem>(box)) - downcast<LayoutListItem>(box).layout_marker(); + if (is<ListItemBox>(box)) + downcast<ListItemBox>(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<LayoutBox>(box).width()); + content_width = max(content_width, downcast<Box>(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<LayoutBlock>(); + auto* relevant_sibling = box.previous_sibling_of_type<Layout::BlockBox>(); 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<LayoutDocument>(context_box()); + auto& icb = downcast<Layout::InitialContainingBlockBox>(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<LayoutBox>([&](auto& child) { + icb.for_each_child_of_type<Box>([&](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<LayoutWidget>([&](auto& widget) { + icb.for_each_in_subtree_of_type<Layout::WidgetBox>([&](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<LayoutBox>([&](auto& box) { + context_box().for_each_in_subtree_of_type<Box>([&](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 88b2773ecd..6b58129899 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 index 2935363896..09d3ea4bbe 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/Box.cpp @@ -27,13 +27,13 @@ #include <LibGUI/Painter.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLBodyElement.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutBox.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/Box.h> #include <LibWeb/Page/Frame.h> -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<LayoutBox>(child) && downcast<LayoutBox>(child).stacking_context()) + if (is<Box>(child) && downcast<Box>(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<LayoutBox>(*ancestor); + auto& ancestor_box = downcast<Box>(*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 index f5e971e6b0..0354938e05 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.h +++ b/Libraries/LibWeb/Layout/Box.h @@ -28,13 +28,13 @@ #include <AK/OwnPtr.h> #include <LibGfx/Rect.h> -#include <LibWeb/Layout/LayoutNode.h> #include <LibWeb/Layout/LineBox.h> +#include <LibWeb/Layout/Node.h> #include <LibWeb/Painting/StackingContext.h> -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<CSS::StyleProperties> style) - : LayoutNodeWithStyleAndBoxModelMetrics(document, node, move(style)) + Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> 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 1cd0ac430d..0a1702d93c 100644 --- a/Libraries/LibWeb/Layout/BoxModelMetrics.cpp +++ b/Libraries/LibWeb/Layout/BoxModelMetrics.cpp @@ -26,9 +26,9 @@ #include <LibWeb/Layout/BoxModelMetrics.h> -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 5e56433436..f5b5bed30c 100644 --- a/Libraries/LibWeb/Layout/BoxModelMetrics.h +++ b/Libraries/LibWeb/Layout/BoxModelMetrics.h @@ -29,7 +29,7 @@ #include <LibGfx/Size.h> #include <LibWeb/CSS/LengthBox.h> -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 index 5fd401892f..0a230a9873 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 <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutBreak.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/BreakNode.h> -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 index 076c675109..07ecb6926f 100644 --- a/Libraries/LibWeb/Layout/LayoutBreak.h +++ b/Libraries/LibWeb/Layout/BreakNode.h @@ -27,25 +27,25 @@ #pragma once #include <LibWeb/HTML/HTMLBRElement.h> -#include <LibWeb/Layout/LayoutNode.h> +#include <LibWeb/Layout/Node.h> -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<HTML::HTMLBRElement>(*LayoutNode::dom_node()); } + const HTML::HTMLBRElement& dom_node() const { return downcast<HTML::HTMLBRElement>(*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 index d7533e63d6..4ceaa87e8d 100644 --- a/Libraries/LibWeb/Layout/LayoutButton.cpp +++ b/Libraries/LibWeb/Layout/ButtonBox.cpp @@ -29,21 +29,21 @@ #include <LibGfx/Font.h> #include <LibGfx/StylePainter.h> #include <LibWeb/DOM/Document.h> -#include <LibWeb/Layout/LayoutButton.h> +#include <LibWeb/Layout/ButtonBox.h> #include <LibWeb/Page/Frame.h> -namespace Web { +namespace Web::Layout { -LayoutButton::LayoutButton(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutReplaced(document, element, move(style)) +ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> 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<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned) +void ButtonBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned) { if (button != GUI::MouseButton::Left || !dom_node().enabled()) return; @@ -83,7 +83,7 @@ void LayoutButton::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, u frame().event_handler().set_mouse_event_tracking_layout_node(this); } -void LayoutButton::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned) +void ButtonBox::handle_mouseup(Badge<EventHandler>, 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<EventHandler>, const Gfx::IntPoint& posi protected_frame->event_handler().set_mouse_event_tracking_layout_node(nullptr); } -void LayoutButton::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned, unsigned) +void ButtonBox::handle_mousemove(Badge<EventHandler>, 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 index 5d6fa36b74..35cc336fc4 100644 --- a/Libraries/LibWeb/Layout/LayoutButton.h +++ b/Libraries/LibWeb/Layout/ButtonBox.h @@ -27,23 +27,23 @@ #pragma once #include <LibWeb/HTML/HTMLInputElement.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> -namespace Web { +namespace Web::Layout { -class LayoutButton : public LayoutReplaced { +class ButtonBox : public ReplacedBox { public: - LayoutButton(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutButton() override; + ButtonBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr<CSS::StyleProperties>); + 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<const HTML::HTMLInputElement&>(LayoutReplaced::dom_node()); } - HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(LayoutReplaced::dom_node()); } + const HTML::HTMLInputElement& dom_node() const { return static_cast<const HTML::HTMLInputElement&>(ReplacedBox::dom_node()); } + HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(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<EventHandler>, 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 index 9a5cca4c82..c1eb048ace 100644 --- a/Libraries/LibWeb/Layout/LayoutCanvas.cpp +++ b/Libraries/LibWeb/Layout/CanvasBox.cpp @@ -27,20 +27,20 @@ #include <LibGUI/Painter.h> #include <LibGfx/Font.h> #include <LibGfx/StylePainter.h> -#include <LibWeb/Layout/LayoutCanvas.h> +#include <LibWeb/Layout/CanvasBox.h> -namespace Web { +namespace Web::Layout { -LayoutCanvas::LayoutCanvas(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutReplaced(document, element, move(style)) +CanvasBox::CanvasBox(DOM::Document& document, HTML::HTMLCanvasElement& element, NonnullRefPtr<CSS::StyleProperties> 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 index 7f2d8220c2..16c1110724 100644 --- a/Libraries/LibWeb/Layout/LayoutCanvas.h +++ b/Libraries/LibWeb/Layout/CanvasBox.h @@ -27,27 +27,27 @@ #pragma once #include <LibWeb/HTML/HTMLCanvasElement.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> -namespace Web { +namespace Web::Layout { -class LayoutCanvas : public LayoutReplaced { +class CanvasBox : public ReplacedBox { public: - LayoutCanvas(DOM::Document&, HTML::HTMLCanvasElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutCanvas() override; + CanvasBox(DOM::Document&, HTML::HTMLCanvasElement&, NonnullRefPtr<CSS::StyleProperties>); + 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<const HTML::HTMLCanvasElement&>(LayoutReplaced::dom_node()); } + const HTML::HTMLCanvasElement& dom_node() const { return static_cast<const HTML::HTMLCanvasElement&>(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 index 6ba9f18585..a259e4f2d5 100644 --- a/Libraries/LibWeb/Layout/LayoutCheckBox.cpp +++ b/Libraries/LibWeb/Layout/CheckBox.cpp @@ -28,13 +28,13 @@ #include <LibGUI/Painter.h> #include <LibGfx/Font.h> #include <LibGfx/StylePainter.h> -#include <LibWeb/Layout/LayoutCheckBox.h> +#include <LibWeb/Layout/CheckBox.h> #include <LibWeb/Page/Frame.h> -namespace Web { +namespace Web::Layout { -LayoutCheckBox::LayoutCheckBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutReplaced(document, element, move(style)) +CheckBox::CheckBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> 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<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned) +void CheckBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned) { if (button != GUI::MouseButton::Left || !dom_node().enabled()) return; @@ -70,7 +70,7 @@ void LayoutCheckBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, frame().event_handler().set_mouse_event_tracking_layout_node(this); } -void LayoutCheckBox::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned) +void CheckBox::handle_mouseup(Badge<EventHandler>, 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<EventHandler>, const Gfx::IntPoint& po frame().event_handler().set_mouse_event_tracking_layout_node(nullptr); } -void LayoutCheckBox::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned, unsigned) +void CheckBox::handle_mousemove(Badge<EventHandler>, 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 index 1e4482a579..f078952a60 100644 --- a/Libraries/LibWeb/Layout/LayoutCheckBox.h +++ b/Libraries/LibWeb/Layout/CheckBox.h @@ -27,22 +27,22 @@ #pragma once #include <LibWeb/HTML/HTMLInputElement.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> -namespace Web { +namespace Web::Layout { -class LayoutCheckBox : public LayoutReplaced { +class CheckBox : public ReplacedBox { public: - LayoutCheckBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutCheckBox() override; + CheckBox(DOM::Document&, HTML::HTMLInputElement&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~CheckBox() override; virtual void paint(PaintContext&, PaintPhase) override; - const HTML::HTMLInputElement& dom_node() const { return static_cast<const HTML::HTMLInputElement&>(LayoutReplaced::dom_node()); } - HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(LayoutReplaced::dom_node()); } + const HTML::HTMLInputElement& dom_node() const { return static_cast<const HTML::HTMLInputElement&>(ReplacedBox::dom_node()); } + HTML::HTMLInputElement& dom_node() { return static_cast<HTML::HTMLInputElement&>(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<EventHandler>, 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 1b52502813..05059e90b7 100644 --- a/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -25,14 +25,14 @@ */ #include <LibWeb/Layout/BlockFormattingContext.h> +#include <LibWeb/Layout/Box.h> #include <LibWeb/Layout/FormattingContext.h> #include <LibWeb/Layout/InlineFormattingContext.h> -#include <LibWeb/Layout/LayoutBox.h> #include <LibWeb/Layout/TableFormattingContext.h> 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<LayoutBox>([&](auto& child) { + box.for_each_child_of_type<Box>([&](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 217b3af3aa..8885fb3ba2 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 index ccd3666c8a..fb475014e8 100644 --- a/Libraries/LibWeb/Layout/LayoutFrame.cpp +++ b/Libraries/LibWeb/Layout/FrameBox.cpp @@ -31,24 +31,24 @@ #include <LibGfx/StylePainter.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutFrame.h> +#include <LibWeb/Layout/FrameBox.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> #include <LibWeb/Page/Frame.h> //#define DEBUG_HIGHLIGHT_FOCUSED_FRAME -namespace Web { +namespace Web::Layout { -LayoutFrame::LayoutFrame(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutReplaced(document, element, move(style)) +FrameBox::FrameBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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<LayoutDocument*>(hosted_layout_tree)->paint_all_phases(context); + const_cast<Layout::InitialContainingBlockBox*>(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<int>()); diff --git a/Libraries/LibWeb/Layout/LayoutFrame.h b/Libraries/LibWeb/Layout/FrameBox.h index fa9be9bf1d..840430e4f6 100644 --- a/Libraries/LibWeb/Layout/LayoutFrame.h +++ b/Libraries/LibWeb/Layout/FrameBox.h @@ -27,29 +27,29 @@ #pragma once #include <LibWeb/HTML/HTMLIFrameElement.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> -namespace Web { +namespace Web::Layout { -class LayoutFrame final : public LayoutReplaced { +class FrameBox final : public ReplacedBox { public: - LayoutFrame(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutFrame() override; + FrameBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~FrameBox() override; virtual void paint(PaintContext&, PaintPhase) override; virtual void prepare_for_replaced_layout() override; - const HTML::HTMLIFrameElement& dom_node() const { return downcast<HTML::HTMLIFrameElement>(LayoutReplaced::dom_node()); } - HTML::HTMLIFrameElement& dom_node() { return downcast<HTML::HTMLIFrameElement>(LayoutReplaced::dom_node()); } + const HTML::HTMLIFrameElement& dom_node() const { return downcast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); } + HTML::HTMLIFrameElement& dom_node() { return downcast<HTML::HTMLIFrameElement>(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 index e3b89a0fc5..541dc7672a 100644 --- a/Libraries/LibWeb/Layout/LayoutImage.cpp +++ b/Libraries/LibWeb/Layout/ImageBox.cpp @@ -28,31 +28,31 @@ #include <LibGfx/Font.h> #include <LibGfx/ImageDecoder.h> #include <LibGfx/StylePainter.h> -#include <LibWeb/Layout/LayoutImage.h> +#include <LibWeb/Layout/ImageBox.h> -namespace Web { +namespace Web::Layout { -LayoutImage::LayoutImage(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style, const ImageLoader& image_loader) - : LayoutReplaced(document, element, move(style)) +ImageBox::ImageBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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<HTML::HTMLImageElement>(dom_node())) return !m_image_loader.has_image(); return false; } -void LayoutImage::set_visible_in_viewport(Badge<LayoutDocument>, bool visible_in_viewport) +void ImageBox::set_visible_in_viewport(Badge<Layout::InitialContainingBlockBox>, 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 index 3cbf29a19c..38a1f89cbe 100644 --- a/Libraries/LibWeb/Layout/LayoutImage.h +++ b/Libraries/LibWeb/Layout/ImageBox.h @@ -27,26 +27,26 @@ #pragma once #include <LibWeb/HTML/HTMLImageElement.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> -namespace Web { +namespace Web::Layout { -class LayoutImage : public LayoutReplaced { +class ImageBox : public ReplacedBox { public: - LayoutImage(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>, const ImageLoader&); - virtual ~LayoutImage() override; + ImageBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>, 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<const DOM::Element&>(LayoutReplaced::dom_node()); } + const DOM::Element& dom_node() const { return static_cast<const DOM::Element&>(ReplacedBox::dom_node()); } bool renders_as_alt_text() const; - void set_visible_in_viewport(Badge<LayoutDocument>, bool); + void set_visible_in_viewport(Badge<InitialContainingBlockBox>, 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 index 9a5b1b0632..320f0f770c 100644 --- a/Libraries/LibWeb/Layout/LayoutDocument.cpp +++ b/Libraries/LibWeb/Layout/InitialContainingBlockBox.cpp @@ -25,31 +25,31 @@ */ #include <LibWeb/Dump.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutImage.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/ImageBox.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> +#include <LibWeb/Layout/WidgetBox.h> #include <LibWeb/Page/Frame.h> #include <LibWeb/Painting/StackingContext.h> -namespace Web { +namespace Web::Layout { -LayoutDocument::LayoutDocument(DOM::Document& document, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBlock(document, &document, move(style)) +InitialContainingBlockBox::InitialContainingBlockBox(DOM::Document& document, NonnullRefPtr<CSS::StyleProperties> 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<StackingContext>(*this, nullptr)); - for_each_in_subtree_of_type<LayoutBox>([&](LayoutBox& box) { + for_each_in_subtree_of_type<Box>([&](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<Frame>, const Gfx::IntRect& a_viewport_rect) +void InitialContainingBlockBox::did_set_viewport_rect(Badge<Frame>, 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<LayoutImage>([&](auto& layout_image) { - const_cast<LayoutImage&>(layout_image).set_visible_in_viewport({}, viewport_rect.intersects(layout_image.absolute_rect())); + for_each_in_subtree_of_type<ImageBox>([&](auto& layout_image) { + const_cast<ImageBox&>(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 index 33e55b4f5b..a02834ee17 100644 --- a/Libraries/LibWeb/Layout/LayoutDocument.h +++ b/Libraries/LibWeb/Layout/InitialContainingBlockBox.h @@ -27,17 +27,17 @@ #pragma once #include <LibWeb/DOM/Document.h> -#include <LibWeb/Layout/LayoutBlock.h> +#include <LibWeb/Layout/BlockBox.h> -namespace Web { +namespace Web::Layout { -class LayoutDocument final : public LayoutBlock { +class InitialContainingBlockBox final : public BlockBox { public: - explicit LayoutDocument(DOM::Document&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutDocument() override; + explicit InitialContainingBlockBox(DOM::Document&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~InitialContainingBlockBox() override; - const DOM::Document& dom_node() const { return static_cast<const DOM::Document&>(*LayoutNode::dom_node()); } - virtual const char* class_name() const override { return "LayoutDocument"; } + const DOM::Document& dom_node() const { return static_cast<const DOM::Document&>(*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 5edcce8192..55219cbb1d 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -27,15 +27,15 @@ #include <LibWeb/CSS/Length.h> #include <LibWeb/DOM/Node.h> #include <LibWeb/Dump.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/Box.h> #include <LibWeb/Layout/InlineFormattingContext.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutBox.h> -#include <LibWeb/Layout/LayoutInline.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/InlineNode.h> +#include <LibWeb/Layout/ReplacedBox.h> 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<LayoutBlock>(context_box()); + auto& containing_block = downcast<BlockBox>(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<LayoutBox&>(downcast<LayoutBox>(fragment.layout_node())), layout_mode); + dimension_box_on_line(const_cast<Box&>(downcast<Box>(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<LayoutBlock>(context_box()); + auto& containing_block = downcast<BlockBox>(context_box()); if (box.is_replaced()) { - auto& replaced = const_cast<LayoutReplaced&>(downcast<LayoutReplaced>(box)); + auto& replaced = const_cast<ReplacedBox&>(downcast<ReplacedBox>(box)); replaced.set_width(replaced.calculate_width()); replaced.set_height(replaced.calculate_height()); return; } if (box.is_inline_block()) { - auto& inline_block = const_cast<LayoutBlock&>(downcast<LayoutBlock>(box)); + auto& inline_block = const_cast<BlockBox&>(downcast<BlockBox>(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 6534b6d6be..8c23a7f256 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 index ce77bc8631..8abfd4cab0 100644 --- a/Libraries/LibWeb/Layout/LayoutInline.cpp +++ b/Libraries/LibWeb/Layout/InlineNode.cpp @@ -25,18 +25,17 @@ */ #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutInline.h> +#include <LibWeb/Layout/InlineNode.h> -namespace Web { +namespace Web::Layout { -LayoutInline::LayoutInline(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutNodeWithStyleAndBoxModelMetrics(document, &element, move(style)) +InlineNode::InlineNode(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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 index 30bc455f15..f13dcc4494 100644 --- a/Libraries/LibWeb/Layout/LayoutInline.h +++ b/Libraries/LibWeb/Layout/InlineNode.h @@ -26,17 +26,15 @@ #pragma once -#include <LibWeb/Layout/LayoutBox.h> +#include <LibWeb/Layout/Box.h> -namespace Web { +namespace Web::Layout { -class LayoutBlock; - -class LayoutInline : public LayoutNodeWithStyleAndBoxModelMetrics { +class InlineNode : public NodeWithStyleAndBoxModelMetrics { public: - LayoutInline(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutInline() override; - virtual const char* class_name() const override { return "LayoutInline"; } + InlineNode(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + 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 e171a34c15..db0f8f2de1 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 <LibWeb/Layout/LayoutNode.h> #include <LibWeb/Layout/LayoutPosition.h> +#include <LibWeb/Layout/Node.h> -namespace Web { +namespace Web::Layout { LayoutRange LayoutRange::normalized() const { diff --git a/Libraries/LibWeb/Layout/LayoutPosition.h b/Libraries/LibWeb/Layout/LayoutPosition.h index fc5fb86e5d..fa132c7ee6 100644 --- a/Libraries/LibWeb/Layout/LayoutPosition.h +++ b/Libraries/LibWeb/Layout/LayoutPosition.h @@ -28,12 +28,12 @@ #include <AK/RefPtr.h> -namespace Web { +namespace Web::Layout { -class LayoutNode; +class Node; struct LayoutPosition { - RefPtr<LayoutNode> layout_node; + RefPtr<Node> layout_node; int index_in_node { 0 }; }; diff --git a/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp b/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp index 9848289260..83fd63de7a 100644 --- a/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp +++ b/Libraries/LibWeb/Layout/LayoutTreeBuilder.cpp @@ -26,18 +26,18 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/ParentNode.h> -#include <LibWeb/Layout/LayoutNode.h> -#include <LibWeb/Layout/LayoutTable.h> -#include <LibWeb/Layout/LayoutText.h> #include <LibWeb/Layout/LayoutTreeBuilder.h> +#include <LibWeb/Layout/Node.h> +#include <LibWeb/Layout/TableBox.h> +#include <LibWeb/Layout/TextNode.h> -namespace Web { +namespace Web::Layout { LayoutTreeBuilder::LayoutTreeBuilder() { } -static RefPtr<LayoutNode> create_layout_tree(DOM::Node& node, const CSS::StyleProperties* parent_style) +static RefPtr<Node> 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<LayoutNode> create_layout_tree(DOM::Node& node, const CSS::StylePr if (!node.has_children()) return layout_node; - NonnullRefPtrVector<LayoutNode> layout_children; + NonnullRefPtrVector<Node> layout_children; bool have_inline_children = false; bool have_noninline_children = false; @@ -63,7 +63,7 @@ static RefPtr<LayoutNode> 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<LayoutText>(layout_child) && downcast<LayoutText>(layout_child).text_for_style(*parent_style) == " ") + if (is<TextNode>(layout_child) && downcast<TextNode>(layout_child).text_for_style(*parent_style) == " ") continue; layout_node->inline_wrapper().append_child(layout_child); } else { @@ -77,7 +77,7 @@ static RefPtr<LayoutNode> create_layout_tree(DOM::Node& node, const CSS::StylePr return layout_node; } -RefPtr<LayoutNode> LayoutTreeBuilder::build(DOM::Node& node) +RefPtr<Node> LayoutTreeBuilder::build(DOM::Node& node) { if (!is<DOM::Document>(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 9a41ad0b0c..fe96b3db88 100644 --- a/Libraries/LibWeb/Layout/LayoutTreeBuilder.h +++ b/Libraries/LibWeb/Layout/LayoutTreeBuilder.h @@ -29,13 +29,13 @@ #include <AK/RefPtr.h> #include <LibWeb/Forward.h> -namespace Web { +namespace Web::Layout { class LayoutTreeBuilder { public: LayoutTreeBuilder(); - RefPtr<LayoutNode> build(DOM::Node&); + RefPtr<Node> build(DOM::Node&); }; } diff --git a/Libraries/LibWeb/Layout/LineBox.cpp b/Libraries/LibWeb/Layout/LineBox.cpp index bf2840faf8..99cc777fcb 100644 --- a/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Libraries/LibWeb/Layout/LineBox.cpp @@ -25,20 +25,20 @@ */ #include <AK/Utf8View.h> -#include <LibWeb/Layout/LayoutBox.h> -#include <LibWeb/Layout/LayoutNode.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/Box.h> #include <LibWeb/Layout/LineBox.h> +#include <LibWeb/Layout/Node.h> +#include <LibWeb/Layout/TextNode.h> #include <ctype.h> -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<LayoutBox>(layout_node)) - const_cast<LayoutBox&>(downcast<LayoutBox>(layout_node)).set_containing_line_box_fragment(m_fragments.last()); + if (is<Box>(layout_node)) + const_cast<Box&>(downcast<Box>(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 eeb177d638..242adf0007 100644 --- a/Libraries/LibWeb/Layout/LineBox.h +++ b/Libraries/LibWeb/Layout/LineBox.h @@ -30,7 +30,7 @@ #include <AK/Vector.h> #include <LibWeb/Layout/LineBoxFragment.h> -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<LineBoxFragment>& fragments() const { return m_fragments; } NonnullOwnPtrVector<LineBoxFragment>& 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<LineBoxFragment> m_fragments; float m_width { 0 }; }; diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 05332f8007..2c4be7f141 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -26,13 +26,13 @@ #include <AK/Utf8View.h> #include <LibGUI/Painter.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> #include <LibWeb/Layout/LineBoxFragment.h> +#include <LibWeb/Layout/TextNode.h> #include <LibWeb/Painting/PaintContext.h> #include <ctype.h> -namespace Web { +namespace Web::Layout { void LineBoxFragment::paint(PaintContext& context) { @@ -41,9 +41,8 @@ void LineBoxFragment::paint(PaintContext& context) return; } - if (is<LayoutText>(layout_node())) { - downcast<LayoutText>(layout_node()).paint_fragment(context, *this); - } + if (is<TextNode>(layout_node())) + downcast<TextNode>(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<LayoutText>(layout_node())) + if (!is<TextNode>(layout_node())) return {}; - return downcast<LayoutText>(layout_node()).text_for_rendering().substring_view(m_start, m_length); + return downcast<TextNode>(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<LayoutText>(layout_node()); + auto& layout_text = downcast<TextNode>(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 f2c71b4ff9..2c6662e8b4 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.h +++ b/Libraries/LibWeb/Layout/LineBoxFragment.h @@ -31,13 +31,13 @@ #include <LibGfx/Rect.h> #include <LibWeb/Forward.h> -namespace Web { +namespace Web::Layout { class LineBoxFragment : public Weakable<LineBoxFragment> { 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 index 5b8cc5165e..5e8f683c7f 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 <LibWeb/Layout/LayoutListItem.h> -#include <LibWeb/Layout/LayoutListItemMarker.h> +#include <LibWeb/Layout/ListItemBox.h> +#include <LibWeb/Layout/ListItemMarkerBox.h> -namespace Web { +namespace Web::Layout { -LayoutListItem::LayoutListItem(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBlock(document, &element, move(style)) +ListItemBox::ListItemBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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 index 2bb8dcb80f..d374ab609d 100644 --- a/Libraries/LibWeb/Layout/LayoutListItem.h +++ b/Libraries/LibWeb/Layout/ListItemBox.h @@ -27,28 +27,28 @@ #pragma once #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutBlock.h> +#include <LibWeb/Layout/BlockBox.h> -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<CSS::StyleProperties>); - virtual ~LayoutListItem() override; + ListItemBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + 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<LayoutListItemMarker> m_marker; + RefPtr<ListItemMarkerBox> 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 index bc51ccdbb3..332a73e5b7 100644 --- a/Libraries/LibWeb/Layout/LayoutListItemMarker.cpp +++ b/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp @@ -25,20 +25,20 @@ */ #include <LibGUI/Painter.h> -#include <LibWeb/Layout/LayoutListItemMarker.h> +#include <LibWeb/Layout/ListItemMarkerBox.h> -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 index 9ad8391408..e32528c99c 100644 --- a/Libraries/LibWeb/Layout/LayoutListItemMarker.h +++ b/Libraries/LibWeb/Layout/ListItemMarkerBox.h @@ -26,19 +26,19 @@ #pragma once -#include <LibWeb/Layout/LayoutBox.h> +#include <LibWeb/Layout/Box.h> -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 index 7fcf45e0b8..b843fbc3d5 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.cpp +++ b/Libraries/LibWeb/Layout/Node.cpp @@ -27,15 +27,15 @@ #include <LibGUI/Painter.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutNode.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> +#include <LibWeb/Layout/Node.h> +#include <LibWeb/Layout/ReplacedBox.h> #include <LibWeb/Page/Frame.h> -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<LayoutBlock>(*ancestor)) + while (ancestor && !is<BlockBox>(*ancestor)) ancestor = ancestor->parent(); - return downcast<LayoutBlock>(ancestor); + return downcast<BlockBox>(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<LayoutBlock>(ancestor) || ancestor->is_anonymous())) + while (ancestor && (!is<BlockBox>(ancestor) || ancestor->is_anonymous())) ancestor = ancestor->containing_block(); - return downcast<LayoutBlock>(ancestor); + return downcast<BlockBox>(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<LayoutBox>(child).stacking_context()) + if (child.is_box() && downcast<Box>(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<LayoutBox>(child) && downcast<LayoutBox>(child).stacking_context()) + if (is<Box>(child) && downcast<Box>(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<LayoutBox>(*this).absolute_position(); + return downcast<Box>(*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<CSS::StyleProperties> specified_style) - : LayoutNode(document, node) +NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> 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<MutableLayoutStyle&>(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<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned) +void Node::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned) { } -void LayoutNode::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned) +void Node::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned) { } -void LayoutNode::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned) +void Node::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint&, unsigned, unsigned) { } diff --git a/Libraries/LibWeb/Layout/LayoutNode.h b/Libraries/LibWeb/Layout/Node.h index d3fb8c5d16..93bac6ca39 100644 --- a/Libraries/LibWeb/Layout/LayoutNode.h +++ b/Libraries/LibWeb/Layout/Node.h @@ -38,7 +38,7 @@ #include <LibWeb/Painting/PaintContext.h> #include <LibWeb/TreeNode.h> -namespace Web { +namespace Web::Layout { enum class LayoutMode { Default, @@ -47,7 +47,7 @@ enum class LayoutMode { }; struct HitTestResult { - RefPtr<LayoutNode> layout_node; + RefPtr<Node> 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<LayoutNode> { +class Node : public TreeNode<Node> { 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<DOM::Document> m_document; RefPtr<DOM::Node> 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<CSS::StyleProperties>); + NodeWithStyle(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); 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<CSS::StyleProperties> style) - : LayoutNodeWithStyle(document, node, move(style)) + NodeWithStyleAndBoxModelMetrics(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> 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<const LayoutNodeWithStyle*>(this)->specified_style(); + return static_cast<const NodeWithStyle*>(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<const LayoutNodeWithStyle*>(this)->style(); + return static_cast<const NodeWithStyle*>(this)->style(); return parent()->style(); } -inline const LayoutNodeWithStyle* LayoutNode::parent() const +inline const NodeWithStyle* Node::parent() const { - return static_cast<const LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent()); + return static_cast<const NodeWithStyle*>(TreeNode<Node>::parent()); } -inline LayoutNodeWithStyle* LayoutNode::parent() +inline NodeWithStyle* Node::parent() { - return static_cast<LayoutNodeWithStyle*>(TreeNode<LayoutNode>::parent()); + return static_cast<NodeWithStyle*>(TreeNode<Node>::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 index 2e7e22bea5..340d96462c 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.cpp +++ b/Libraries/LibWeb/Layout/ReplacedBox.cpp @@ -25,23 +25,23 @@ */ #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/ReplacedBox.h> -namespace Web { +namespace Web::Layout { -LayoutReplaced::LayoutReplaced(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBox(document, &element, move(style)) +ReplacedBox::ReplacedBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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 index 14f461e773..aff5ccd5ca 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.h +++ b/Libraries/LibWeb/Layout/ReplacedBox.h @@ -27,17 +27,17 @@ #pragma once #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutBox.h> +#include <LibWeb/Layout/Box.h> -namespace Web { +namespace Web::Layout { -class LayoutReplaced : public LayoutBox { +class ReplacedBox : public Box { public: - LayoutReplaced(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutReplaced() override; + ReplacedBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~ReplacedBox() override; - const DOM::Element& dom_node() const { return downcast<DOM::Element>(*LayoutNode::dom_node()); } - DOM::Element& dom_node() { return downcast<DOM::Element>(*LayoutNode::dom_node()); } + const DOM::Element& dom_node() const { return downcast<DOM::Element>(*Node::dom_node()); } + DOM::Element& dom_node() { return downcast<DOM::Element>(*Node::dom_node()); } virtual bool is_replaced() const final { return true; } @@ -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 index b5ea0e63a9..8370d4b9bd 100644 --- a/Libraries/LibWeb/Layout/LayoutSVG.cpp +++ b/Libraries/LibWeb/Layout/SVGBox.cpp @@ -27,27 +27,27 @@ #include <LibGUI/Painter.h> #include <LibGfx/Font.h> #include <LibGfx/StylePainter.h> -#include <LibWeb/Layout/LayoutSVG.h> +#include <LibWeb/Layout/SVGBox.h> -namespace Web { +namespace Web::Layout { -LayoutSVG::LayoutSVG(DOM::Document& document, SVG::SVGElement& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutReplaced(document, element, move(style)) +SVGBox::SVGBox(DOM::Document& document, SVG::SVGElement& element, NonnullRefPtr<CSS::StyleProperties> 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 index 3ae7ae9cb4..cd289bb199 100644 --- a/Libraries/LibWeb/Layout/LayoutSVG.h +++ b/Libraries/LibWeb/Layout/SVGBox.h @@ -26,22 +26,22 @@ #pragma once -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> #include <LibWeb/SVG/SVGElement.h> #include <LibWeb/SVG/SVGGraphicsElement.h> -namespace Web { +namespace Web::Layout { -class LayoutSVG : public LayoutReplaced { +class SVGBox : public ReplacedBox { public: - LayoutSVG(DOM::Document&, SVG::SVGElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutSVG() override = default; + SVGBox(DOM::Document&, SVG::SVGElement&, NonnullRefPtr<CSS::StyleProperties>); + 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 index b85237aeea..be1f9541d4 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 <LibWeb/Layout/LayoutSVGGraphics.h> +#include <LibWeb/Layout/SVGGraphicsBox.h> -namespace Web { +namespace Web::Layout { -LayoutSVGGraphics::LayoutSVGGraphics(DOM::Document& document, SVG::SVGGraphicsElement& element, NonnullRefPtr<CSS::StyleProperties> properties) - : LayoutSVG(document, element, properties) +SVGGraphicsBox::SVGGraphicsBox(DOM::Document& document, SVG::SVGGraphicsElement& element, NonnullRefPtr<CSS::StyleProperties> 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<SVG::SVGGraphicsElement>(dom_node()); diff --git a/Libraries/LibWeb/Layout/LayoutSVGGraphics.h b/Libraries/LibWeb/Layout/SVGGraphicsBox.h index a6e3352752..686ea7adc0 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGGraphics.h +++ b/Libraries/LibWeb/Layout/SVGGraphicsBox.h @@ -26,21 +26,21 @@ #pragma once -#include <LibWeb/Layout/LayoutSVG.h> +#include <LibWeb/Layout/SVGBox.h> #include <LibWeb/SVG/SVGElement.h> #include <LibWeb/SVG/SVGGraphicsElement.h> -namespace Web { +namespace Web::Layout { -class LayoutSVGGraphics : public LayoutSVG { +class SVGGraphicsBox : public SVGBox { public: - LayoutSVGGraphics(DOM::Document&, SVG::SVGGraphicsElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutSVGGraphics() override = default; + SVGGraphicsBox(DOM::Document&, SVG::SVGGraphicsElement&, NonnullRefPtr<CSS::StyleProperties>); + 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 index f4f1225fac..87879043eb 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGPath.cpp +++ b/Libraries/LibWeb/Layout/SVGPathBox.cpp @@ -25,17 +25,17 @@ */ #include <LibGfx/Painter.h> -#include <LibWeb/Layout/LayoutSVGPath.h> +#include <LibWeb/Layout/SVGPathBox.h> #include <LibWeb/SVG/SVGPathElement.h> -namespace Web { +namespace Web::Layout { -LayoutSVGPath::LayoutSVGPath(DOM::Document& document, SVG::SVGPathElement& element, NonnullRefPtr<CSS::StyleProperties> properties) - : LayoutSVGGraphics(document, element, properties) +SVGPathBox::SVGPathBox(DOM::Document& document, SVG::SVGPathElement& element, NonnullRefPtr<CSS::StyleProperties> 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 index a378665a8c..0cc0717e1d 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGPath.h +++ b/Libraries/LibWeb/Layout/SVGPathBox.h @@ -26,22 +26,22 @@ #pragma once -#include <LibWeb/Layout/LayoutSVGGraphics.h> +#include <LibWeb/Layout/SVGGraphicsBox.h> -namespace Web { +namespace Web::Layout { -class LayoutSVGPath final : public LayoutSVGGraphics { +class SVGPathBox final : public SVGGraphicsBox { public: - LayoutSVGPath(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutSVGPath() override = default; + SVGPathBox(DOM::Document&, SVG::SVGPathElement&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~SVGPathBox() override = default; - SVG::SVGPathElement& dom_node() { return downcast<SVG::SVGPathElement>(LayoutSVGGraphics::dom_node()); } + SVG::SVGPathElement& dom_node() { return downcast<SVG::SVGPathElement>(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 index 23dde716a4..af4a038dbc 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 <LibWeb/Layout/LayoutSVGSVG.h> +#include <LibWeb/Layout/SVGSVGBox.h> -namespace Web { +namespace Web::Layout { -LayoutSVGSVG::LayoutSVGSVG(DOM::Document& document, SVG::SVGSVGElement& element, NonnullRefPtr<CSS::StyleProperties> properties) - : LayoutSVGGraphics(document, element, properties) +SVGSVGBox::SVGSVGBox(DOM::Document& document, SVG::SVGSVGElement& element, NonnullRefPtr<CSS::StyleProperties> 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 index 01fb4ea8be..a03d28d289 100644 --- a/Libraries/LibWeb/Layout/LayoutSVGSVG.h +++ b/Libraries/LibWeb/Layout/SVGSVGBox.h @@ -26,25 +26,25 @@ #pragma once -#include <LibWeb/Layout/LayoutSVGGraphics.h> +#include <LibWeb/Layout/SVGGraphicsBox.h> #include <LibWeb/SVG/SVGSVGElement.h> -namespace Web { +namespace Web::Layout { -class LayoutSVGSVG final : public LayoutSVGGraphics { +class SVGSVGBox final : public SVGGraphicsBox { public: - LayoutSVGSVG(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutSVGSVG() override = default; + SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~SVGSVGBox() override = default; - SVG::SVGSVGElement& dom_node() { return downcast<SVG::SVGSVGElement>(LayoutSVGGraphics::dom_node()); } + SVG::SVGSVGElement& dom_node() { return downcast<SVG::SVGSVGElement>(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 index a94e522c47..139a2d7011 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRow.cpp +++ b/Libraries/LibWeb/Layout/TableBox.cpp @@ -25,18 +25,16 @@ */ #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutTable.h> -#include <LibWeb/Layout/LayoutTableCell.h> -#include <LibWeb/Layout/LayoutTableRow.h> +#include <LibWeb/Layout/TableBox.h> -namespace Web { +namespace Web::Layout { -LayoutTableRow::LayoutTableRow(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBox(document, &element, move(style)) +TableBox::TableBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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 index b94874a0b1..a407980541 100644 --- a/Libraries/LibWeb/Layout/LayoutTable.h +++ b/Libraries/LibWeb/Layout/TableBox.h @@ -26,22 +26,22 @@ #pragma once -#include <LibWeb/Layout/LayoutBlock.h> +#include <LibWeb/Layout/BlockBox.h> -namespace Web { +namespace Web::Layout { -class LayoutTable final : public LayoutBlock { +class TableBox final : public Layout::BlockBox { public: - LayoutTable(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutTable() override; + TableBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + 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 index 27c9a2780d..b5edb41121 100644 --- a/Libraries/LibWeb/Layout/LayoutTableCell.cpp +++ b/Libraries/LibWeb/Layout/TableCellBox.cpp @@ -25,29 +25,29 @@ */ #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutTableCell.h> -#include <LibWeb/Layout/LayoutTableRow.h> +#include <LibWeb/Layout/TableCellBox.h> +#include <LibWeb/Layout/TableRowBox.h> -namespace Web { +namespace Web::Layout { -LayoutTableCell::LayoutTableCell(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBlock(document, &element, move(style)) +TableCellBox::TableCellBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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::Element>(*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<LayoutTableRow>()) + if (auto* row = first_ancestor_of_type<TableRowBox>()) return row->width(); return 0; } diff --git a/Libraries/LibWeb/Layout/LayoutTableCell.h b/Libraries/LibWeb/Layout/TableCellBox.h index 5ce5dc7462..e8eba520e3 100644 --- a/Libraries/LibWeb/Layout/LayoutTableCell.h +++ b/Libraries/LibWeb/Layout/TableCellBox.h @@ -26,28 +26,28 @@ #pragma once -#include <LibWeb/Layout/LayoutBlock.h> +#include <LibWeb/Layout/BlockBox.h> -namespace Web { +namespace Web::Layout { -class LayoutTableCell final : public LayoutBlock { +class TableCellBox final : public BlockBox { public: - LayoutTableCell(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutTableCell() override; + TableCellBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + virtual ~TableCellBox() override; - LayoutTableCell* next_cell() { return next_sibling_of_type<LayoutTableCell>(); } - const LayoutTableCell* next_cell() const { return next_sibling_of_type<LayoutTableCell>(); } + TableCellBox* next_cell() { return next_sibling_of_type<TableCellBox>(); } + const TableCellBox* next_cell() const { return next_sibling_of_type<TableCellBox>(); } 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 a23d301d19..71f85eb0ad 100644 --- a/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -26,19 +26,19 @@ #include <LibWeb/CSS/Length.h> #include <LibWeb/DOM/Node.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/Box.h> #include <LibWeb/Layout/InlineFormattingContext.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutBox.h> -#include <LibWeb/Layout/LayoutTable.h> -#include <LibWeb/Layout/LayoutTableCell.h> -#include <LibWeb/Layout/LayoutTableRow.h> -#include <LibWeb/Layout/LayoutTableRowGroup.h> +#include <LibWeb/Layout/TableBox.h> +#include <LibWeb/Layout/TableCellBox.h> #include <LibWeb/Layout/TableFormattingContext.h> +#include <LibWeb/Layout/TableRowBox.h> +#include <LibWeb/Layout/TableRowGroupBox.h> #include <LibWeb/Page/Frame.h> 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<LayoutTableRowGroup>([&](auto& box) { + context_box().for_each_child_of_type<TableRowGroupBox>([&](auto& box) { compute_width(box); auto column_count = box.column_count(); Vector<float> column_widths; column_widths.resize(column_count); - box.template for_each_child_of_type<LayoutTableRow>([&](auto& row) { + box.template for_each_child_of_type<TableRowBox>([&](auto& row) { calculate_column_widths(row, column_widths); }); float content_height = 0; - box.template for_each_child_of_type<LayoutTableRow>([&](auto& row) { + box.template for_each_child_of_type<TableRowBox>([&](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<float>& column_widths) +void TableFormattingContext::calculate_column_widths(Box& row, Vector<float>& column_widths) { size_t column_index = 0; - auto* table = row.first_ancestor_of_type<LayoutTable>(); + auto* table = row.first_ancestor_of_type<TableBox>(); bool use_auto_layout = !table || table->style().width().is_undefined_or_auto(); - row.for_each_child_of_type<LayoutTableCell>([&](auto& cell) { + row.for_each_child_of_type<TableCellBox>([&](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<floa }); } -void TableFormattingContext::layout_row(LayoutBox& row, Vector<float>& column_widths) +void TableFormattingContext::layout_row(Box& row, Vector<float>& column_widths) { size_t column_index = 0; float tallest_cell_height = 0; float content_width = 0; - auto* table = row.first_ancestor_of_type<LayoutTable>(); + auto* table = row.first_ancestor_of_type<TableBox>(); bool use_auto_layout = !table || table->style().width().is_undefined_or_auto(); - row.for_each_child_of_type<LayoutTableCell>([&](auto& cell) { + row.for_each_child_of_type<TableCellBox>([&](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 5ab4db75eb..f5a5cda164 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<float>& column_widths); - void layout_row(LayoutBox& row, Vector<float>& column_widths); + void calculate_column_widths(Box& row, Vector<float>& column_widths); + void layout_row(Box& row, Vector<float>& column_widths); }; } diff --git a/Libraries/LibWeb/Layout/LayoutTable.cpp b/Libraries/LibWeb/Layout/TableRowBox.cpp index 721aa7daa9..0bed4d507b 100644 --- a/Libraries/LibWeb/Layout/LayoutTable.cpp +++ b/Libraries/LibWeb/Layout/TableRowBox.cpp @@ -25,17 +25,16 @@ */ #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutTable.h> -#include <LibWeb/Layout/LayoutTableRow.h> +#include <LibWeb/Layout/TableRowBox.h> -namespace Web { +namespace Web::Layout { -LayoutTable::LayoutTable(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBlock(document, &element, move(style)) +TableRowBox::TableRowBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) + : Box(document, &element, move(style)) { } -LayoutTable::~LayoutTable() +TableRowBox::~TableRowBox() { } diff --git a/Libraries/LibWeb/Layout/LayoutTableRow.h b/Libraries/LibWeb/Layout/TableRowBox.h index a1855abe32..5870789d95 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRow.h +++ b/Libraries/LibWeb/Layout/TableRowBox.h @@ -26,24 +26,22 @@ #pragma once -#include <LibWeb/Layout/LayoutBox.h> +#include <LibWeb/Layout/Box.h> -namespace Web { +namespace Web::Layout { -class LayoutTableCell; - -class LayoutTableRow final : public LayoutBox { +class TableRowBox final : public Box { public: - LayoutTableRow(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutTableRow() override; + TableRowBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + 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 index c35b775634..f6ced13a33 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRowGroup.cpp +++ b/Libraries/LibWeb/Layout/TableRowGroupBox.cpp @@ -25,27 +25,27 @@ */ #include <LibWeb/DOM/Element.h> -#include <LibWeb/Layout/LayoutTableCell.h> -#include <LibWeb/Layout/LayoutTableRow.h> -#include <LibWeb/Layout/LayoutTableRowGroup.h> +#include <LibWeb/Layout/TableCellBox.h> +#include <LibWeb/Layout/TableRowBox.h> +#include <LibWeb/Layout/TableRowGroupBox.h> -namespace Web { +namespace Web::Layout { -LayoutTableRowGroup::LayoutTableRowGroup(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) - : LayoutBlock(document, &element, move(style)) +TableRowGroupBox::TableRowGroupBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> 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<LayoutTableRow>([&](auto& row) { + for_each_child_of_type<TableRowBox>([&](auto& row) { size_t row_column_count = 0; - row.template for_each_child_of_type<LayoutTableCell>([&](auto& cell) { + row.template for_each_child_of_type<TableCellBox>([&](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 index a07ced75cb..c887c77083 100644 --- a/Libraries/LibWeb/Layout/LayoutTableRowGroup.h +++ b/Libraries/LibWeb/Layout/TableRowGroupBox.h @@ -26,24 +26,24 @@ #pragma once -#include <LibWeb/Layout/LayoutBlock.h> +#include <LibWeb/Layout/BlockBox.h> -namespace Web { +namespace Web::Layout { -class LayoutTableRowGroup final : public LayoutBlock { +class TableRowGroupBox final : public BlockBox { public: - LayoutTableRowGroup(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); - virtual ~LayoutTableRowGroup() override; + TableRowGroupBox(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>); + 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 index b6d8e2b001..4030d40aa1 100644 --- a/Libraries/LibWeb/Layout/LayoutText.cpp +++ b/Libraries/LibWeb/Layout/TextNode.cpp @@ -30,20 +30,20 @@ #include <LibGUI/Painter.h> #include <LibGfx/Font.h> #include <LibWeb/DOM/Document.h> -#include <LibWeb/Layout/LayoutBlock.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/BlockBox.h> +#include <LibWeb/Layout/TextNode.h> #include <LibWeb/Page/Frame.h> #include <ctype.h> -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<typename Callback> -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 index 4b30426b84..cf15d391fe 100644 --- a/Libraries/LibWeb/Layout/LayoutText.h +++ b/Libraries/LibWeb/Layout/TextNode.h @@ -27,33 +27,33 @@ #pragma once #include <LibWeb/DOM/Text.h> -#include <LibWeb/Layout/LayoutNode.h> +#include <LibWeb/Layout/Node.h> -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<const DOM::Text&>(*LayoutNode::dom_node()); } + const DOM::Text& dom_node() const { return static_cast<const DOM::Text&>(*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<typename Callback> @@ -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 index a80394a8a9..c38aa50765 100644 --- a/Libraries/LibWeb/Layout/LayoutWidget.cpp +++ b/Libraries/LibWeb/Layout/WidgetBox.cpp @@ -31,13 +31,13 @@ #include <LibGfx/StylePainter.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/WidgetBox.h> #include <LibWeb/Page/Frame.h> -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<int>(); auto& page_view = static_cast<const InProcessWebView&>(frame().page()->client()); diff --git a/Libraries/LibWeb/Layout/LayoutWidget.h b/Libraries/LibWeb/Layout/WidgetBox.h index 90051f9810..0c5f734cd2 100644 --- a/Libraries/LibWeb/Layout/LayoutWidget.h +++ b/Libraries/LibWeb/Layout/WidgetBox.h @@ -26,14 +26,14 @@ #pragma once -#include <LibWeb/Layout/LayoutReplaced.h> +#include <LibWeb/Layout/ReplacedBox.h> -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 cbfb583109..7ee9eced5e 100644 --- a/Libraries/LibWeb/LayoutTreeModel.cpp +++ b/Libraries/LibWeb/LayoutTreeModel.cpp @@ -29,7 +29,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Element.h> #include <LibWeb/DOM/Text.h> -#include <LibWeb/Layout/LayoutText.h> +#include <LibWeb/Layout/TextNode.h> #include <ctype.h> #include <stdio.h> @@ -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<LayoutNode*>(parent.internal_data()); + auto& parent_node = *static_cast<Layout::Node*>(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<LayoutNode*>(index.internal_data()); + auto& node = *static_cast<Layout::Node*>(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<LayoutNode*>(index.internal_data()); + auto& node = *static_cast<Layout::Node*>(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<LayoutNode*>(index.internal_data()); + auto& node = *static_cast<Layout::Node*>(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<LayoutText>(node).text_for_rendering()).characters()); + return String::format("TextNode: %s", with_whitespace_collapsed(downcast<Layout::TextNode>(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 3d0e4ed85f..e7e310ab31 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -33,14 +33,14 @@ #include <LibWeb/HTML/HTMLIFrameElement.h> #include <LibWeb/HTML/HTMLImageElement.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutDocument.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> #include <LibWeb/Page/EventHandler.h> #include <LibWeb/Page/Frame.h> #include <LibWeb/UIEvents/MouseEvent.h> 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 e077a71ded..65acfbdbe1 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<LayoutNode> m_mouse_event_tracking_layout_node; + WeakPtr<Layout::Node> m_mouse_event_tracking_layout_node; }; } diff --git a/Libraries/LibWeb/Page/Frame.cpp b/Libraries/LibWeb/Page/Frame.cpp index f7b5a7ed78..c9e0a3e6cd 100644 --- a/Libraries/LibWeb/Page/Frame.cpp +++ b/Libraries/LibWeb/Page/Frame.cpp @@ -27,10 +27,10 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/HTMLAnchorElement.h> #include <LibWeb/InProcessWebView.h> -#include <LibWeb/Layout/LayoutBreak.h> -#include <LibWeb/Layout/LayoutDocument.h> -#include <LibWeb/Layout/LayoutText.h> -#include <LibWeb/Layout/LayoutWidget.h> +#include <LibWeb/Layout/BreakNode.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> +#include <LibWeb/Layout/TextNode.h> +#include <LibWeb/Layout/WidgetBox.h> #include <LibWeb/Page/Frame.h> namespace Web { @@ -137,7 +137,7 @@ void Frame::did_scroll(Badge<InProcessWebView>) return; if (!m_document->layout_node()) return; - m_document->layout_node()->for_each_in_subtree_of_type<LayoutWidget>([&](auto& layout_widget) { + m_document->layout_node()->for_each_in_subtree_of_type<Layout::WidgetBox>([&](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<LayoutBox>(layout_node)) { - auto& layout_box = downcast<LayoutBox>(layout_node); + if (is<Layout::Box>(layout_node)) { + auto& layout_box = downcast<Layout::Box>(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<LayoutText>(*selection.start().layout_node)) + if (!is<Layout::TextNode>(*selection.start().layout_node)) return ""; - return downcast<LayoutText>(*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<Layout::TextNode>(*selection.start().layout_node).text_for_rendering().substring(selection.start().index_in_node, selection.end().index_in_node - selection.start().index_in_node); } // Start node auto layout_node = selection.start().layout_node; - if (is<LayoutText>(*layout_node)) { - auto& text = downcast<LayoutText>(*layout_node).text_for_rendering(); + if (is<Layout::TextNode>(*layout_node)) { + auto& text = downcast<Layout::TextNode>(*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<LayoutText>(*layout_node)) - builder.append(downcast<LayoutText>(*layout_node).text_for_rendering()); - else if (is<LayoutBreak>(*layout_node) || is<LayoutBlock>(*layout_node)) + if (is<Layout::TextNode>(*layout_node)) + builder.append(downcast<Layout::TextNode>(*layout_node).text_for_rendering()); + else if (is<Layout::BreakNode>(*layout_node) || is<Layout::BlockBox>(*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<LayoutText>(*layout_node)) { - auto& text = downcast<LayoutText>(*layout_node).text_for_rendering(); + if (is<Layout::TextNode>(*layout_node)) { + auto& text = downcast<Layout::TextNode>(*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 4d27abacd8..daca00c597 100644 --- a/Libraries/LibWeb/Painting/StackingContext.cpp +++ b/Libraries/LibWeb/Painting/StackingContext.cpp @@ -26,13 +26,13 @@ #include <AK/QuickSort.h> #include <LibWeb/DOM/Node.h> -#include <LibWeb/Layout/LayoutBox.h> -#include <LibWeb/Layout/LayoutDocument.h> +#include <LibWeb/Layout/Box.h> +#include <LibWeb/Layout/InitialContainingBlockBox.h> #include <LibWeb/Painting/StackingContext.h> -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<LayoutDocument>(m_box).LayoutBlock::paint(context, phase); + downcast<InitialContainingBlockBox>(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<LayoutDocument>(m_box).LayoutBlock::hit_test(position, type); + result = downcast<InitialContainingBlockBox>(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 d7621c3829..7e2e11e2d9 100644 --- a/Libraries/LibWeb/Painting/StackingContext.h +++ b/Libraries/LibWeb/Painting/StackingContext.h @@ -27,26 +27,24 @@ #pragma once #include <AK/Vector.h> -#include <LibWeb/Layout/LayoutNode.h> +#include <LibWeb/Layout/Node.h> -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<StackingContext*> m_children; }; diff --git a/Libraries/LibWeb/SVG/SVGPathElement.cpp b/Libraries/LibWeb/SVG/SVGPathElement.cpp index 36a2ef2fb6..a0ec408fb3 100644 --- a/Libraries/LibWeb/SVG/SVGPathElement.cpp +++ b/Libraries/LibWeb/SVG/SVGPathElement.cpp @@ -29,7 +29,7 @@ #include <LibGfx/Path.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Event.h> -#include <LibWeb/Layout/LayoutSVGPath.h> +#include <LibWeb/Layout/SVGPathBox.h> #include <LibWeb/SVG/SVGPathElement.h> #include <ctype.h> @@ -430,12 +430,12 @@ SVGPathElement::SVGPathElement(DOM::Document& document, const QualifiedName& qua { } -RefPtr<LayoutNode> SVGPathElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> 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 922c92b690..bca0da456d 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> 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 0a0b2f75f3..cd5e1e6fbd 100644 --- a/Libraries/LibWeb/SVG/SVGSVGElement.cpp +++ b/Libraries/LibWeb/SVG/SVGSVGElement.cpp @@ -28,7 +28,7 @@ #include <LibWeb/CSS/StyleResolver.h> #include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Event.h> -#include <LibWeb/Layout/LayoutSVGSVG.h> +#include <LibWeb/Layout/SVGSVGBox.h> #include <LibWeb/SVG/SVGPathElement.h> #include <LibWeb/SVG/SVGSVGElement.h> #include <ctype.h> @@ -40,12 +40,12 @@ SVGSVGElement::SVGSVGElement(DOM::Document& document, const QualifiedName& quali { } -RefPtr<LayoutNode> SVGSVGElement::create_layout_node(const CSS::StyleProperties* parent_style) +RefPtr<Layout::Node> 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 82be0cada2..4478ebd617 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<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override; + virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override; unsigned width() const; unsigned height() const; |