summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.cpp17
-rw-r--r--Libraries/LibHTML/Layout/LayoutBlock.h1
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.cpp8
-rw-r--r--Libraries/LibHTML/Layout/LayoutNode.h2
-rw-r--r--Libraries/LibHTML/Layout/LayoutText.cpp17
-rw-r--r--Libraries/LibHTML/Layout/LayoutText.h1
-rw-r--r--Libraries/LibHTML/RenderingContext.h16
7 files changed, 62 insertions, 0 deletions
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp
index a910875f72..b0a9ff8ed5 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.cpp
+++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp
@@ -1,3 +1,4 @@
+#include <LibGUI/GPainter.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/Layout/LayoutBlock.h>
@@ -143,3 +144,19 @@ void LayoutBlock::compute_height()
if (height_length.is_absolute())
rect().set_height(height_length.to_px());
}
+
+void LayoutBlock::render(RenderingContext& context)
+{
+ LayoutNode::render(context);
+
+ // FIXME: position this properly
+ if (style_properties().string_or_fallback("display", "block") == "list-item") {
+ Rect bullet_rect {
+ rect().x() - 8,
+ rect().y() + 4,
+ 3,
+ 3
+ };
+ context.painter().fill_rect(bullet_rect, Color::Black);
+ }
+}
diff --git a/Libraries/LibHTML/Layout/LayoutBlock.h b/Libraries/LibHTML/Layout/LayoutBlock.h
index 61b9de2a70..575e73430b 100644
--- a/Libraries/LibHTML/Layout/LayoutBlock.h
+++ b/Libraries/LibHTML/Layout/LayoutBlock.h
@@ -12,6 +12,7 @@ public:
virtual const char* class_name() const override { return "LayoutBlock"; }
virtual void layout() override;
+ virtual void render(RenderingContext&) override;
virtual LayoutNode& inline_wrapper() override;
diff --git a/Libraries/LibHTML/Layout/LayoutNode.cpp b/Libraries/LibHTML/Layout/LayoutNode.cpp
index 0b7dc8bc68..e4500008f1 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.cpp
+++ b/Libraries/LibHTML/Layout/LayoutNode.cpp
@@ -26,3 +26,11 @@ const LayoutBlock* LayoutNode::containing_block() const
}
return nullptr;
}
+
+void LayoutNode::render(RenderingContext& context)
+{
+ // TODO: render our background and border
+ for_each_child([&](auto& child) {
+ child.render(context);
+ });
+}
diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h
index a531922420..7803b5fcc8 100644
--- a/Libraries/LibHTML/Layout/LayoutNode.h
+++ b/Libraries/LibHTML/Layout/LayoutNode.h
@@ -5,6 +5,7 @@
#include <LibDraw/Rect.h>
#include <LibHTML/CSS/StyleProperties.h>
#include <LibHTML/Layout/ComputedStyle.h>
+#include <LibHTML/RenderingContext.h>
#include <LibHTML/TreeNode.h>
class Node;
@@ -44,6 +45,7 @@ public:
virtual bool is_inline() const { return false; }
virtual void layout();
+ virtual void render(RenderingContext&);
const LayoutBlock* containing_block() const;
diff --git a/Libraries/LibHTML/Layout/LayoutText.cpp b/Libraries/LibHTML/Layout/LayoutText.cpp
index 2976194428..5d4aa1a367 100644
--- a/Libraries/LibHTML/Layout/LayoutText.cpp
+++ b/Libraries/LibHTML/Layout/LayoutText.cpp
@@ -1,6 +1,7 @@
#include <AK/StringBuilder.h>
#include <LibCore/CDirIterator.h>
#include <LibDraw/Font.h>
+#include <LibGUI/GPainter.h>
#include <LibHTML/Layout/LayoutBlock.h>
#include <LibHTML/Layout/LayoutText.h>
#include <ctype.h>
@@ -216,3 +217,19 @@ void LayoutText::layout()
rect().set_right(last_run.pos.x() + m_font->width(last_run.text));
rect().set_bottom(last_run.pos.y() + m_font->glyph_height());
}
+
+void LayoutText::render(RenderingContext& context)
+{
+ auto& painter = context.painter();
+ painter.set_font(*m_font);
+
+ for (auto& run : m_runs) {
+ Rect rect {
+ run.pos.x(),
+ run.pos.y(),
+ m_font->width(run.text),
+ m_font->glyph_height()
+ };
+ painter.draw_text(rect, run.text);
+ }
+}
diff --git a/Libraries/LibHTML/Layout/LayoutText.h b/Libraries/LibHTML/Layout/LayoutText.h
index 8a16237d9b..48ea4841df 100644
--- a/Libraries/LibHTML/Layout/LayoutText.h
+++ b/Libraries/LibHTML/Layout/LayoutText.h
@@ -17,6 +17,7 @@ public:
virtual const char* class_name() const override { return "LayoutText"; }
virtual bool is_text() const final { return true; }
virtual void layout() override;
+ virtual void render(RenderingContext&) override;
struct Run {
Point pos;
diff --git a/Libraries/LibHTML/RenderingContext.h b/Libraries/LibHTML/RenderingContext.h
new file mode 100644
index 0000000000..2e50ed82a5
--- /dev/null
+++ b/Libraries/LibHTML/RenderingContext.h
@@ -0,0 +1,16 @@
+#pragma once
+
+class GPainter;
+
+class RenderingContext {
+public:
+ explicit RenderingContext(GPainter& painter)
+ : m_painter(painter)
+ {
+ }
+
+ GPainter& painter() const { return m_painter; }
+
+private:
+ GPainter& m_painter;
+};