Przeglądaj źródła

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.
Andreas Kling 5 lat temu
rodzic
commit
fffc5896d8
33 zmienionych plików z 38 dodań i 43 usunięć
  1. 1 1
      Libraries/LibWeb/Layout/LayoutBlock.cpp
  2. 1 1
      Libraries/LibWeb/Layout/LayoutBlock.h
  3. 1 1
      Libraries/LibWeb/Layout/LayoutBox.h
  4. 1 1
      Libraries/LibWeb/Layout/LayoutBreak.cpp
  5. 1 1
      Libraries/LibWeb/Layout/LayoutBreak.h
  6. 1 1
      Libraries/LibWeb/Layout/LayoutCanvas.cpp
  7. 1 1
      Libraries/LibWeb/Layout/LayoutCanvas.h
  8. 1 1
      Libraries/LibWeb/Layout/LayoutFrame.cpp
  9. 1 1
      Libraries/LibWeb/Layout/LayoutFrame.h
  10. 1 1
      Libraries/LibWeb/Layout/LayoutImage.cpp
  11. 1 1
      Libraries/LibWeb/Layout/LayoutImage.h
  12. 1 1
      Libraries/LibWeb/Layout/LayoutInline.cpp
  13. 1 1
      Libraries/LibWeb/Layout/LayoutInline.h
  14. 1 1
      Libraries/LibWeb/Layout/LayoutListItem.cpp
  15. 1 1
      Libraries/LibWeb/Layout/LayoutListItem.h
  16. 2 2
      Libraries/LibWeb/Layout/LayoutNode.cpp
  17. 5 5
      Libraries/LibWeb/Layout/LayoutNode.h
  18. 1 1
      Libraries/LibWeb/Layout/LayoutReplaced.cpp
  19. 1 1
      Libraries/LibWeb/Layout/LayoutReplaced.h
  20. 1 1
      Libraries/LibWeb/Layout/LayoutSVG.cpp
  21. 1 4
      Libraries/LibWeb/Layout/LayoutSVG.h
  22. 1 1
      Libraries/LibWeb/Layout/LayoutTable.cpp
  23. 1 3
      Libraries/LibWeb/Layout/LayoutTable.h
  24. 1 1
      Libraries/LibWeb/Layout/LayoutTableCell.cpp
  25. 1 1
      Libraries/LibWeb/Layout/LayoutTableCell.h
  26. 1 1
      Libraries/LibWeb/Layout/LayoutTableRow.cpp
  27. 1 1
      Libraries/LibWeb/Layout/LayoutTableRow.h
  28. 1 1
      Libraries/LibWeb/Layout/LayoutTableRowGroup.cpp
  29. 1 1
      Libraries/LibWeb/Layout/LayoutTableRowGroup.h
  30. 1 1
      Libraries/LibWeb/Layout/LayoutText.cpp
  31. 1 1
      Libraries/LibWeb/Layout/LayoutText.h
  32. 1 1
      Libraries/LibWeb/Layout/LayoutWidget.cpp
  33. 1 1
      Libraries/LibWeb/Layout/LayoutWidget.h

+ 1 - 1
Libraries/LibWeb/Layout/LayoutBlock.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutBlock.h

@@ -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"; }

+ 1 - 1
Libraries/LibWeb/Layout/LayoutBox.h

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutBreak.cpp

@@ -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);

+ 1 - 1
Libraries/LibWeb/Layout/LayoutBreak.h

@@ -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()); }

+ 1 - 1
Libraries/LibWeb/Layout/LayoutCanvas.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutCanvas.h

@@ -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;

+ 1 - 1
Libraries/LibWeb/Layout/LayoutFrame.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutFrame.h

@@ -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;

+ 1 - 1
Libraries/LibWeb/Layout/LayoutImage.cpp

@@ -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)
 {

+ 1 - 1
Libraries/LibWeb/Layout/LayoutImage.h

@@ -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;

+ 1 - 1
Libraries/LibWeb/Layout/LayoutInline.cpp

@@ -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);

+ 1 - 1
Libraries/LibWeb/Layout/LayoutInline.h

@@ -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"; }
 };

+ 1 - 1
Libraries/LibWeb/Layout/LayoutListItem.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutListItem.h

@@ -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;

+ 2 - 2
Libraries/LibWeb/Layout/LayoutNode.cpp

@@ -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))
 {

+ 5 - 5
Libraries/LibWeb/Layout/LayoutNode.h

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutReplaced.cpp

@@ -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.

+ 1 - 1
Libraries/LibWeb/Layout/LayoutReplaced.h

@@ -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()); }

+ 1 - 1
Libraries/LibWeb/Layout/LayoutSVG.cpp

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

+ 1 - 4
Libraries/LibWeb/Layout/LayoutSVG.h

@@ -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;

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTable.cpp

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

+ 1 - 3
Libraries/LibWeb/Layout/LayoutTable.h

@@ -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;

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTableCell.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTableCell.h

@@ -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>(); }

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTableRow.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTableRow.h

@@ -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);

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTableRowGroup.cpp

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

+ 1 - 1
Libraries/LibWeb/Layout/LayoutTableRowGroup.h

@@ -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;

+ 1 - 1
Libraries/LibWeb/Layout/LayoutText.cpp

@@ -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);

+ 1 - 1
Libraries/LibWeb/Layout/LayoutText.h

@@ -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()); }

+ 1 - 1
Libraries/LibWeb/Layout/LayoutWidget.cpp

@@ -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)
 {

+ 1 - 1
Libraries/LibWeb/Layout/LayoutWidget.h

@@ -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; }