summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-12-03 19:30:48 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-03 21:46:01 +0100
commitf35b406dfb2be5efb9e99c38972f4f3c93088203 (patch)
treea457b2a0cad9d0852386cbf47c56b18155c91ca0
parentc189897e29bfa65bdaaac08c8a2035e91d612216 (diff)
downloadserenity-f35b406dfb2be5efb9e99c38972f4f3c93088203.zip
LibWeb: Virtualize Layout::Node::paint_fragment()
LineBoxFragment no longer needs to care what type of layout node a fragment refers to during paint, it can just call paint_fragment(). :^)
-rw-r--r--Libraries/LibWeb/Layout/InlineNode.h2
-rw-r--r--Libraries/LibWeb/Layout/LineBoxFragment.cpp7
-rw-r--r--Libraries/LibWeb/Layout/Node.h1
-rw-r--r--Libraries/LibWeb/Layout/TextNode.h2
4 files changed, 4 insertions, 8 deletions
diff --git a/Libraries/LibWeb/Layout/InlineNode.h b/Libraries/LibWeb/Layout/InlineNode.h
index 91a74a9caa..a140339599 100644
--- a/Libraries/LibWeb/Layout/InlineNode.h
+++ b/Libraries/LibWeb/Layout/InlineNode.h
@@ -36,7 +36,7 @@ public:
virtual ~InlineNode() override;
virtual const char* class_name() const override { return "InlineNode"; }
- void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const;
+ virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override;
virtual void split_into_lines(BlockBox& containing_block, LayoutMode) override;
diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Libraries/LibWeb/Layout/LineBoxFragment.cpp
index 8e589469ff..af24ce2c38 100644
--- a/Libraries/LibWeb/Layout/LineBoxFragment.cpp
+++ b/Libraries/LibWeb/Layout/LineBoxFragment.cpp
@@ -29,7 +29,6 @@
#include <LibWeb/Layout/InitialContainingBlockBox.h>
#include <LibWeb/Layout/LineBoxFragment.h>
#include <LibWeb/Layout/TextNode.h>
-#include <LibWeb/Layout/InlineNode.h>
#include <LibWeb/Painting/PaintContext.h>
#include <ctype.h>
@@ -42,11 +41,7 @@ void LineBoxFragment::paint(PaintContext& context, PaintPhase phase)
return;
}
- if (is<InlineNode>(layout_node()))
- downcast<InlineNode>(layout_node()).paint_fragment(context, *this, phase);
-
- if (is<TextNode>(layout_node()))
- downcast<TextNode>(layout_node()).paint_fragment(context, *this, phase);
+ layout_node().paint_fragment(context, *this, phase);
}
bool LineBoxFragment::ends_in_whitespace() const
diff --git a/Libraries/LibWeb/Layout/Node.h b/Libraries/LibWeb/Layout/Node.h
index 27809be760..07968f1e34 100644
--- a/Libraries/LibWeb/Layout/Node.h
+++ b/Libraries/LibWeb/Layout/Node.h
@@ -127,6 +127,7 @@ public:
virtual void before_children_paint(PaintContext&, PaintPhase) {};
virtual void paint(PaintContext&, PaintPhase);
+ virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const { }
virtual void after_children_paint(PaintContext&, PaintPhase) {};
bool is_floating() const;
diff --git a/Libraries/LibWeb/Layout/TextNode.h b/Libraries/LibWeb/Layout/TextNode.h
index 298acfd58a..389cf0f3e8 100644
--- a/Libraries/LibWeb/Layout/TextNode.h
+++ b/Libraries/LibWeb/Layout/TextNode.h
@@ -46,7 +46,7 @@ public:
virtual const char* class_name() const override { return "TextNode"; }
virtual bool is_text() const final { return true; }
- void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const;
+ virtual void paint_fragment(PaintContext&, const LineBoxFragment&, PaintPhase) const override;
virtual void split_into_lines(BlockBox& container, LayoutMode) override;