1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:17:44 +00:00

LibWeb: Move DOM classes into the Web::DOM namespace

LibWeb keeps growing and the Web namespace is filling up fast.
Let's put DOM stuff into Web::DOM, just like we already started doing
with SVG stuff in Web::SVG.
This commit is contained in:
Andreas Kling 2020-07-26 19:37:56 +02:00
parent 96d13f75cf
commit 11ff9d0f17
178 changed files with 516 additions and 523 deletions

View file

@ -38,7 +38,7 @@
namespace Web {
LayoutBlock::LayoutBlock(Document& document, const Node* node, NonnullRefPtr<StyleProperties> style)
LayoutBlock::LayoutBlock(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> style)
: LayoutBox(document, node, move(style))
{
}

View file

@ -31,11 +31,9 @@
namespace Web {
class Element;
class LayoutBlock : public LayoutBox {
public:
LayoutBlock(Document&, const Node*, NonnullRefPtr<StyleProperties>);
LayoutBlock(DOM::Document&, const DOM::Node*, NonnullRefPtr<StyleProperties>);
virtual ~LayoutBlock() override;
virtual const char* class_name() const override { return "LayoutBlock"; }

View file

@ -71,7 +71,7 @@ public:
virtual void paint(PaintContext&, PaintPhase) override;
protected:
LayoutBox(Document& document, const Node* node, NonnullRefPtr<StyleProperties> style)
LayoutBox(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> style)
: LayoutNodeWithStyleAndBoxModelMetrics(document, node, move(style))
{
}

View file

@ -29,7 +29,7 @@
namespace Web {
LayoutBreak::LayoutBreak(Document& document, const HTMLBRElement& element)
LayoutBreak::LayoutBreak(DOM::Document& document, const HTMLBRElement& element)
: LayoutNodeWithStyleAndBoxModelMetrics(document, &element, StyleProperties::create())
{
set_inline(true);

View file

@ -33,7 +33,7 @@ namespace Web {
class LayoutBreak final : public LayoutNodeWithStyleAndBoxModelMetrics {
public:
LayoutBreak(Document&, const HTMLBRElement&);
LayoutBreak(DOM::Document&, const HTMLBRElement&);
virtual ~LayoutBreak() override;
const HTMLBRElement& node() const { return downcast<HTMLBRElement>(*LayoutNode::node()); }

View file

@ -31,7 +31,7 @@
namespace Web {
LayoutCanvas::LayoutCanvas(Document& document, const HTMLCanvasElement& element, NonnullRefPtr<StyleProperties> style)
LayoutCanvas::LayoutCanvas(DOM::Document& document, const HTMLCanvasElement& element, NonnullRefPtr<StyleProperties> style)
: LayoutReplaced(document, element, move(style))
{
}

View file

@ -35,7 +35,7 @@ class HTMLCanvasElement;
class LayoutCanvas : public LayoutReplaced {
public:
LayoutCanvas(Document&, const HTMLCanvasElement&, NonnullRefPtr<StyleProperties>);
LayoutCanvas(DOM::Document&, const HTMLCanvasElement&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutCanvas() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View file

@ -33,7 +33,7 @@
namespace Web {
LayoutDocument::LayoutDocument(Document& document, NonnullRefPtr<StyleProperties> style)
LayoutDocument::LayoutDocument(DOM::Document& document, NonnullRefPtr<StyleProperties> style)
: LayoutBlock(document, &document, move(style))
{
}

View file

@ -33,10 +33,10 @@ namespace Web {
class LayoutDocument final : public LayoutBlock {
public:
explicit LayoutDocument(Document&, NonnullRefPtr<StyleProperties>);
explicit LayoutDocument(DOM::Document&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutDocument() override;
const Document& node() const { return static_cast<const Document&>(*LayoutNode::node()); }
const DOM::Document& node() const { return static_cast<const DOM::Document&>(*LayoutNode::node()); }
virtual const char* class_name() const override { return "LayoutDocument"; }
virtual void layout(LayoutMode = LayoutMode::Default) override;

View file

@ -37,7 +37,7 @@
namespace Web {
LayoutFrame::LayoutFrame(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutFrame::LayoutFrame(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutReplaced(document, element, move(style))
{
}

View file

@ -33,7 +33,7 @@ namespace Web {
class LayoutFrame final : public LayoutReplaced {
public:
LayoutFrame(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutFrame(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutFrame() override;
virtual void paint(PaintContext&, PaintPhase) override;

View file

@ -32,7 +32,7 @@
namespace Web {
LayoutImage::LayoutImage(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style, const ImageLoader& image_loader)
LayoutImage::LayoutImage(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style, const ImageLoader& image_loader)
: LayoutReplaced(document, element, move(style))
, m_image_loader(image_loader)
{

View file

@ -35,13 +35,13 @@ class HTMLImageElement;
class LayoutImage : public LayoutReplaced {
public:
LayoutImage(Document&, const Element&, NonnullRefPtr<StyleProperties>, const ImageLoader&);
LayoutImage(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>, const ImageLoader&);
virtual ~LayoutImage() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void paint(PaintContext&, PaintPhase) override;
const Element& node() const { return static_cast<const Element&>(LayoutReplaced::node()); }
const DOM::Element& node() const { return static_cast<const DOM::Element&>(LayoutReplaced::node()); }
bool renders_as_alt_text() const;

View file

@ -30,7 +30,7 @@
namespace Web {
LayoutInline::LayoutInline(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutInline::LayoutInline(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutNodeWithStyleAndBoxModelMetrics(document, &element, move(style))
{
set_inline(true);

View file

@ -34,7 +34,7 @@ class LayoutBlock;
class LayoutInline : public LayoutNodeWithStyleAndBoxModelMetrics {
public:
LayoutInline(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutInline(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutInline() override;
virtual const char* class_name() const override { return "LayoutInline"; }
};

View file

@ -29,7 +29,7 @@
namespace Web {
LayoutListItem::LayoutListItem(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutListItem::LayoutListItem(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View file

@ -35,7 +35,7 @@ class LayoutListItemMarker;
class LayoutListItem final : public LayoutBlock {
public:
LayoutListItem(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutListItem(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutListItem() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View file

@ -29,7 +29,7 @@
namespace Web {
LayoutListItemMarker::LayoutListItemMarker(Document& document)
LayoutListItemMarker::LayoutListItemMarker(DOM::Document& document)
: LayoutBox(document, nullptr, StyleProperties::create())
{
}

View file

@ -32,7 +32,7 @@ namespace Web {
class LayoutListItemMarker final : public LayoutBox {
public:
explicit LayoutListItemMarker(Document&);
explicit LayoutListItemMarker(DOM::Document&);
virtual ~LayoutListItemMarker() override;
virtual void paint(PaintContext&, PaintPhase) override;

View file

@ -35,7 +35,7 @@
namespace Web {
LayoutNode::LayoutNode(Document& document, const Node* node)
LayoutNode::LayoutNode(DOM::Document& document, const DOM::Node* node)
: m_document(document)
, m_node(node)
{
@ -208,7 +208,7 @@ bool LayoutNode::is_fixed_position() const
return position == CSS::Position::Fixed;
}
LayoutNodeWithStyle::LayoutNodeWithStyle(Document& document, const Node* node, NonnullRefPtr<StyleProperties> specified_style)
LayoutNodeWithStyle::LayoutNodeWithStyle(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> specified_style)
: LayoutNode(document, node)
, m_specified_style(move(specified_style))
{

View file

@ -53,11 +53,11 @@ public:
virtual HitTestResult hit_test(const Gfx::IntPoint&) const;
bool is_anonymous() const { return !m_node; }
const Node* node() const { return m_node; }
Node* node() { return const_cast<Node*>(m_node); }
const DOM::Node* node() const { return m_node; }
DOM::Node* node() { return const_cast<DOM::Node*>(m_node); }
Document& document() { return m_document; }
const Document& document() const { return m_document; }
DOM::Document& document() { return m_document; }
const DOM::Document& document() const { return m_document; }
const Frame& frame() const;
Frame& frame();
@ -196,13 +196,13 @@ public:
float font_size() const;
protected:
LayoutNode(Document&, const Node*);
LayoutNode(DOM::Document&, const DOM::Node*);
private:
friend class LayoutNodeWithStyle;
Document& m_document;
const Node* m_node { nullptr };
DOM::Document& m_document;
const DOM::Node* m_node { nullptr };
bool m_inline { false };
bool m_has_style { false };
@ -222,7 +222,7 @@ public:
void apply_style(const StyleProperties&);
protected:
LayoutNodeWithStyle(Document&, const Node*, NonnullRefPtr<StyleProperties>);
LayoutNodeWithStyle(DOM::Document&, const DOM::Node*, NonnullRefPtr<StyleProperties>);
private:
LayoutStyle m_style;
@ -238,7 +238,7 @@ public:
const BoxModelMetrics& box_model() const { return m_box_model; }
protected:
LayoutNodeWithStyleAndBoxModelMetrics(Document& document, const Node* node, NonnullRefPtr<StyleProperties> style)
LayoutNodeWithStyleAndBoxModelMetrics(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> style)
: LayoutNodeWithStyle(document, node, move(style))
{
}

View file

@ -30,7 +30,7 @@
namespace Web {
LayoutReplaced::LayoutReplaced(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutReplaced::LayoutReplaced(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutBox(document, &element, move(style))
{
// FIXME: Allow non-inline replaced elements.

View file

@ -33,11 +33,11 @@ namespace Web {
class LayoutReplaced : public LayoutBox {
public:
LayoutReplaced(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutReplaced(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutReplaced() override;
const Element& node() const { return downcast<Element>(*LayoutNode::node()); }
Element& node() { return downcast<Element>(*LayoutNode::node()); }
const DOM::Element& node() const { return downcast<DOM::Element>(*LayoutNode::node()); }
DOM::Element& node() { return downcast<DOM::Element>(*LayoutNode::node()); }
virtual bool is_replaced() const final { return true; }

View file

@ -31,7 +31,7 @@
namespace Web {
LayoutSVG::LayoutSVG(Document& document, const SVG::SVGSVGElement& element, NonnullRefPtr<StyleProperties> style)
LayoutSVG::LayoutSVG(DOM::Document& document, const SVG::SVGSVGElement& element, NonnullRefPtr<StyleProperties> style)
: LayoutReplaced(document, element, move(style))
{
}

View file

@ -36,7 +36,7 @@ class SVGSVGElement;
class LayoutSVG : public LayoutReplaced {
public:
LayoutSVG(Document&, const SVG::SVGSVGElement&, NonnullRefPtr<StyleProperties>);
LayoutSVG(DOM::Document&, const SVG::SVGSVGElement&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutSVG() override = default;
virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void paint(PaintContext&, PaintPhase) override;

View file

@ -30,7 +30,7 @@
namespace Web {
LayoutTable::LayoutTable(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTable::LayoutTable(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View file

@ -34,7 +34,7 @@ class LayoutTableRow;
class LayoutTable final : public LayoutBlock {
public:
LayoutTable(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutTable(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutTable() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View file

@ -30,7 +30,7 @@
namespace Web {
LayoutTableCell::LayoutTableCell(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTableCell::LayoutTableCell(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}
@ -42,7 +42,7 @@ LayoutTableCell::~LayoutTableCell()
size_t LayoutTableCell::colspan() const
{
ASSERT(node());
return downcast<Element>(*node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
return downcast<DOM::Element>(*node()).attribute(HTML::AttributeNames::colspan).to_uint().value_or(1);
}
float LayoutTableCell::width_of_logical_containing_block() const

View file

@ -32,7 +32,7 @@ namespace Web {
class LayoutTableCell final : public LayoutBlock {
public:
LayoutTableCell(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutTableCell(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutTableCell() override;
LayoutTableCell* next_cell() { return next_sibling_of_type<LayoutTableCell>(); }

View file

@ -31,7 +31,7 @@
namespace Web {
LayoutTableRow::LayoutTableRow(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTableRow::LayoutTableRow(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutBox(document, &element, move(style))
{
}

View file

@ -34,7 +34,7 @@ class LayoutTableCell;
class LayoutTableRow final : public LayoutBox {
public:
LayoutTableRow(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutTableRow(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutTableRow() override;
void layout_row(const Vector<float>& column_widths);

View file

@ -31,7 +31,7 @@
namespace Web {
LayoutTableRowGroup::LayoutTableRowGroup(Document& document, const Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTableRowGroup::LayoutTableRowGroup(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View file

@ -32,7 +32,7 @@ namespace Web {
class LayoutTableRowGroup final : public LayoutBlock {
public:
LayoutTableRowGroup(Document&, const Element&, NonnullRefPtr<StyleProperties>);
LayoutTableRowGroup(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutTableRowGroup() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View file

@ -36,7 +36,7 @@
namespace Web {
LayoutText::LayoutText(Document& document, const Text& text)
LayoutText::LayoutText(DOM::Document& document, const DOM::Text& text)
: LayoutNode(document, &text)
{
set_inline(true);

View file

@ -35,10 +35,10 @@ class LineBoxFragment;
class LayoutText : public LayoutNode {
public:
LayoutText(Document&, const Text&);
LayoutText(DOM::Document&, const DOM::Text&);
virtual ~LayoutText() override;
const Text& node() const { return static_cast<const Text&>(*LayoutNode::node()); }
const DOM::Text& node() const { return static_cast<const DOM::Text&>(*LayoutNode::node()); }
const String& text_for_style(const StyleProperties&) const;
const String& text_for_rendering() const { return m_text_for_rendering; }

View file

@ -37,7 +37,7 @@ LayoutTreeBuilder::LayoutTreeBuilder()
{
}
static RefPtr<LayoutNode> create_layout_tree(Node& node, const StyleProperties* parent_style)
static RefPtr<LayoutNode> create_layout_tree(DOM::Node& node, const StyleProperties* parent_style)
{
auto layout_node = node.create_layout_node(parent_style);
if (!layout_node)
@ -50,7 +50,7 @@ static RefPtr<LayoutNode> create_layout_tree(Node& node, const StyleProperties*
bool have_inline_children = false;
bool have_noninline_children = false;
downcast<ParentNode>(node).for_each_child([&](Node& child) {
downcast<DOM::ParentNode>(node).for_each_child([&](DOM::Node& child) {
auto layout_child = create_layout_tree(child, &layout_node->specified_style());
if (!layout_child)
return;
@ -77,9 +77,9 @@ static RefPtr<LayoutNode> create_layout_tree(Node& node, const StyleProperties*
return layout_node;
}
RefPtr<LayoutNode> LayoutTreeBuilder::build(Node& node)
RefPtr<LayoutNode> LayoutTreeBuilder::build(DOM::Node& node)
{
if (!is<Document>(node) && node.has_children()) {
if (!is<DOM::Document>(node) && node.has_children()) {
dbg() << "FIXME: Support building partial layout trees.";
return nullptr;
}

View file

@ -27,17 +27,15 @@
#pragma once
#include <AK/RefPtr.h>
#include <LibWeb/Forward.h>
namespace Web {
class Node;
class LayoutNode;
class LayoutTreeBuilder {
public:
LayoutTreeBuilder();
RefPtr<LayoutNode> build(Node&);
RefPtr<LayoutNode> build(DOM::Node&);
};
}

View file

@ -36,7 +36,7 @@
namespace Web {
LayoutWidget::LayoutWidget(Document& document, const Element& element, GUI::Widget& widget)
LayoutWidget::LayoutWidget(DOM::Document& document, const DOM::Element& element, GUI::Widget& widget)
: LayoutReplaced(document, element, StyleProperties::create())
, m_widget(widget)
{

View file

@ -32,7 +32,7 @@ namespace Web {
class LayoutWidget final : public LayoutReplaced {
public:
LayoutWidget(Document&, const Element&, GUI::Widget&);
LayoutWidget(DOM::Document&, const DOM::Element&, GUI::Widget&);
virtual ~LayoutWidget() override;
GUI::Widget& widget() { return m_widget; }