1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:07:34 +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 {
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))
{
}

View file

@ -33,7 +33,7 @@ namespace Web {
class LayoutBlock : public LayoutBox {
public:
LayoutBlock(DOM::Document&, const DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
LayoutBlock(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::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(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))
{
}

View file

@ -29,7 +29,7 @@
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())
{
set_inline(true);

View file

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

View file

@ -31,7 +31,7 @@
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))
{
}

View file

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

View file

@ -37,7 +37,7 @@
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))
{
}

View file

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

View file

@ -32,7 +32,7 @@
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))
, m_image_loader(image_loader)
{

View file

@ -33,7 +33,7 @@ namespace Web {
class LayoutImage : public LayoutReplaced {
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 void layout(LayoutMode = LayoutMode::Default) override;

View file

@ -30,7 +30,7 @@
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))
{
set_inline(true);

View file

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

View file

@ -29,7 +29,7 @@
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))
{
}

View file

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

View file

@ -35,7 +35,7 @@
namespace Web {
LayoutNode::LayoutNode(DOM::Document& document, const DOM::Node* node)
LayoutNode::LayoutNode(DOM::Document& document, 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(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)
, m_specified_style(move(specified_style))
{

View file

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

View file

@ -30,7 +30,7 @@
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))
{
// FIXME: Allow non-inline replaced elements.

View file

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

View file

@ -31,7 +31,7 @@
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))
{
}

View file

@ -26,17 +26,14 @@
#pragma once
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/Layout/LayoutReplaced.h>
#include <LibWeb/SVG/SVGSVGElement.h>
namespace Web {
class SVGSVGElement;
class LayoutSVG : public LayoutReplaced {
public:
LayoutSVG(DOM::Document&, const SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>);
LayoutSVG(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::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(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))
{
}

View file

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

View file

@ -30,7 +30,7 @@
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))
{
}

View file

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

View file

@ -31,7 +31,7 @@
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))
{
}

View file

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

View file

@ -31,7 +31,7 @@
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))
{
}

View file

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

View file

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

View file

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

View file

@ -36,7 +36,7 @@
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())
, m_widget(widget)
{

View file

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