1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:27:35 +00:00

LibWeb: Make layout tree have non-const pointers to the DOM

Const pointers into the DOM was a nice idea, but in practice, there are
too many situations where the layout tree wants to some non-const thing
to the DOM.
This commit is contained in:
Andreas Kling 2020-07-28 19:48:57 +02:00
parent a4eadeb80d
commit fffc5896d8
33 changed files with 38 additions and 43 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -33,7 +33,7 @@ namespace Web {
class LayoutImage : public LayoutReplaced { class LayoutImage : public LayoutReplaced {
public: public:
LayoutImage(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>, const ImageLoader&); LayoutImage(DOM::Document&, DOM::Element&, NonnullRefPtr<CSS::StyleProperties>, const ImageLoader&);
virtual ~LayoutImage() override; virtual ~LayoutImage() override;
virtual void layout(LayoutMode = LayoutMode::Default) override; virtual void layout(LayoutMode = LayoutMode::Default) override;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -53,7 +53,7 @@ public:
bool is_anonymous() const { return !m_node; } bool is_anonymous() const { return !m_node; }
const DOM::Node* node() const { return m_node; } const DOM::Node* node() const { return m_node; }
DOM::Node* node() { return const_cast<DOM::Node*>(m_node); } DOM::Node* node() { return m_node; }
DOM::Document& document() { return m_document; } DOM::Document& document() { return m_document; }
const DOM::Document& document() const { return m_document; } const DOM::Document& document() const { return m_document; }
@ -195,13 +195,13 @@ public:
float font_size() const; float font_size() const;
protected: protected:
LayoutNode(DOM::Document&, const DOM::Node*); LayoutNode(DOM::Document&, DOM::Node*);
private: private:
friend class LayoutNodeWithStyle; friend class LayoutNodeWithStyle;
DOM::Document& m_document; DOM::Document& m_document;
const DOM::Node* m_node { nullptr }; DOM::Node* m_node { nullptr };
bool m_inline { false }; bool m_inline { false };
bool m_has_style { false }; bool m_has_style { false };
@ -221,7 +221,7 @@ public:
void apply_style(const CSS::StyleProperties&); void apply_style(const CSS::StyleProperties&);
protected: protected:
LayoutNodeWithStyle(DOM::Document&, const DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); LayoutNodeWithStyle(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
private: private:
LayoutStyle m_style; LayoutStyle m_style;
@ -237,7 +237,7 @@ public:
const BoxModelMetrics& box_model() const { return m_box_model; } const BoxModelMetrics& box_model() const { return m_box_model; }
protected: protected:
LayoutNodeWithStyleAndBoxModelMetrics(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style) LayoutNodeWithStyleAndBoxModelMetrics(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutNodeWithStyle(document, node, move(style)) : LayoutNodeWithStyle(document, node, move(style))
{ {
} }

View file

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

View file

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

View file

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

View file

@ -26,17 +26,14 @@
#pragma once #pragma once
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/Layout/LayoutReplaced.h> #include <LibWeb/Layout/LayoutReplaced.h>
#include <LibWeb/SVG/SVGSVGElement.h> #include <LibWeb/SVG/SVGSVGElement.h>
namespace Web { namespace Web {
class SVGSVGElement;
class LayoutSVG : public LayoutReplaced { class LayoutSVG : public LayoutReplaced {
public: public:
LayoutSVG(DOM::Document&, const SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>); LayoutSVG(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutSVG() override = default; virtual ~LayoutSVG() override = default;
virtual void layout(LayoutMode = LayoutMode::Default) override; virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void paint(PaintContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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