1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:28:10 +00:00

LibWeb: Rename LayoutNode::render() to paint()

"Paint" matches what we call this in the rest of the system. Let's not
confuse things by mixing paint/render/draw all the time. I'm guilty of
this in more places..

Also rename RenderingContext => PaintContext.
This commit is contained in:
Andreas Kling 2020-06-18 21:35:44 +02:00
parent dec0cd3755
commit 8c82d26668
26 changed files with 49 additions and 49 deletions

View file

@ -60,7 +60,7 @@ class Node;
class Origin; class Origin;
class Page; class Page;
class PageClient; class PageClient;
class RenderingContext; class PaintContext;
class Resource; class Resource;
class ResourceLoader; class ResourceLoader;
class Selector; class Selector;

View file

@ -660,12 +660,12 @@ void LayoutBlock::compute_height()
} }
} }
void LayoutBlock::render(RenderingContext& context, PaintPhase phase) void LayoutBlock::paint(PaintContext& context, PaintPhase phase)
{ {
if (!is_visible()) if (!is_visible())
return; return;
LayoutBox::render(context, phase); LayoutBox::paint(context, phase);
// FIXME: Inline backgrounds etc. // FIXME: Inline backgrounds etc.
if (phase == PaintPhase::Foreground) { if (phase == PaintPhase::Foreground) {

View file

@ -41,7 +41,7 @@ public:
virtual const char* class_name() const override { return "LayoutBlock"; } virtual const char* class_name() const override { return "LayoutBlock"; }
virtual void layout(LayoutMode = LayoutMode::Default) override; virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
virtual LayoutNode& inline_wrapper() override; virtual LayoutNode& inline_wrapper() override;

View file

@ -33,7 +33,7 @@
namespace Web { namespace Web {
void LayoutBox::paint_border(RenderingContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id) void LayoutBox::paint_border(PaintContext& context, Edge edge, const Gfx::FloatRect& rect, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id)
{ {
auto border_width = style().property(width_property_id); auto border_width = style().property(width_property_id);
if (!border_width.has_value()) if (!border_width.has_value())
@ -186,7 +186,7 @@ void LayoutBox::paint_border(RenderingContext& context, Edge edge, const Gfx::Fl
} }
} }
void LayoutBox::render(RenderingContext& context, PaintPhase phase) void LayoutBox::paint(PaintContext& context, PaintPhase phase)
{ {
if (!is_visible()) if (!is_visible())
return; return;
@ -230,7 +230,7 @@ void LayoutBox::render(RenderingContext& context, PaintPhase phase)
paint_border(context, Edge::Bottom, bordered_rect, CSS::PropertyID::BorderBottomStyle, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomWidth); paint_border(context, Edge::Bottom, bordered_rect, CSS::PropertyID::BorderBottomStyle, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomWidth);
} }
LayoutNodeWithStyleAndBoxModelMetrics::render(context, phase); LayoutNodeWithStyleAndBoxModelMetrics::paint(context, phase);
if (phase == PaintPhase::Overlay && node() && document().inspected_node() == node()) if (phase == PaintPhase::Overlay && node() && document().inspected_node() == node())
context.painter().draw_rect(enclosing_int_rect(absolute_rect()), Color::Magenta); context.painter().draw_rect(enclosing_int_rect(absolute_rect()), Color::Magenta);

View file

@ -67,7 +67,7 @@ public:
void set_stacking_context(NonnullOwnPtr<StackingContext> context) { m_stacking_context = move(context); } void set_stacking_context(NonnullOwnPtr<StackingContext> context) { m_stacking_context = move(context); }
StackingContext* enclosing_stacking_context(); StackingContext* enclosing_stacking_context();
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
protected: protected:
LayoutBox(const Node* node, NonnullRefPtr<StyleProperties> style) LayoutBox(const Node* node, NonnullRefPtr<StyleProperties> style)
@ -86,7 +86,7 @@ private:
Bottom, Bottom,
Left, Left,
}; };
void paint_border(RenderingContext&, Edge, const Gfx::FloatRect&, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id); void paint_border(PaintContext&, Edge, const Gfx::FloatRect&, CSS::PropertyID style_property_id, CSS::PropertyID color_property_id, CSS::PropertyID width_property_id);
Gfx::FloatPoint m_offset; Gfx::FloatPoint m_offset;
Gfx::FloatSize m_size; Gfx::FloatSize m_size;

View file

@ -49,12 +49,12 @@ void LayoutCanvas::layout(LayoutMode layout_mode)
LayoutReplaced::layout(layout_mode); LayoutReplaced::layout(layout_mode);
} }
void LayoutCanvas::render(RenderingContext& context, PaintPhase phase) void LayoutCanvas::paint(PaintContext& context, PaintPhase phase)
{ {
if (!is_visible()) if (!is_visible())
return; return;
LayoutReplaced::render(context, phase); LayoutReplaced::paint(context, phase);
if (phase == PaintPhase::Foreground) { if (phase == PaintPhase::Foreground) {
// FIXME: This should be done at a different level. Also rect() does not include padding etc! // FIXME: This should be done at a different level. Also rect() does not include padding etc!

View file

@ -39,7 +39,7 @@ public:
virtual ~LayoutCanvas() override; virtual ~LayoutCanvas() override;
virtual void layout(LayoutMode = LayoutMode::Default) override; virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
const HTMLCanvasElement& node() const { return static_cast<const HTMLCanvasElement&>(LayoutReplaced::node()); } const HTMLCanvasElement& node() const { return static_cast<const HTMLCanvasElement&>(LayoutReplaced::node()); }

View file

@ -100,17 +100,17 @@ void LayoutDocument::did_set_viewport_rect(Badge<Frame>, const Gfx::IntRect& a_v
}); });
} }
void LayoutDocument::paint_all_phases(RenderingContext& context) void LayoutDocument::paint_all_phases(PaintContext& context)
{ {
render(context, PaintPhase::Background); paint(context, PaintPhase::Background);
render(context, PaintPhase::Border); paint(context, PaintPhase::Border);
render(context, PaintPhase::Foreground); paint(context, PaintPhase::Foreground);
render(context, PaintPhase::Overlay); paint(context, PaintPhase::Overlay);
} }
void LayoutDocument::render(RenderingContext& context, PaintPhase phase) void LayoutDocument::paint(PaintContext& context, PaintPhase phase)
{ {
stacking_context()->render(context, phase); stacking_context()->paint(context, phase);
} }
} }

View file

@ -40,9 +40,9 @@ public:
virtual const char* class_name() const override { return "LayoutDocument"; } virtual const char* class_name() const override { return "LayoutDocument"; }
virtual void layout(LayoutMode = LayoutMode::Default) override; virtual void layout(LayoutMode = LayoutMode::Default) override;
void paint_all_phases(RenderingContext&); void paint_all_phases(PaintContext&);
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
const LayoutRange& selection() const { return m_selection; } const LayoutRange& selection() const { return m_selection; }
LayoutRange& selection() { return m_selection; } LayoutRange& selection() { return m_selection; }

View file

@ -59,9 +59,9 @@ void LayoutFrame::layout(LayoutMode layout_mode)
LayoutReplaced::layout(layout_mode); LayoutReplaced::layout(layout_mode);
} }
void LayoutFrame::render(RenderingContext& context, PaintPhase phase) void LayoutFrame::paint(PaintContext& context, PaintPhase phase)
{ {
LayoutReplaced::render(context, phase); LayoutReplaced::paint(context, phase);
if (phase == PaintPhase::Foreground) { if (phase == PaintPhase::Foreground) {
auto* hosted_document = node().hosted_document(); auto* hosted_document = node().hosted_document();

View file

@ -36,7 +36,7 @@ public:
LayoutFrame(const Element&, NonnullRefPtr<StyleProperties>); LayoutFrame(const Element&, NonnullRefPtr<StyleProperties>);
virtual ~LayoutFrame() override; virtual ~LayoutFrame() override;
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
virtual void layout(LayoutMode) override; virtual void layout(LayoutMode) override;
const HTMLIFrameElement& node() const { return static_cast<const HTMLIFrameElement&>(LayoutReplaced::node()); } const HTMLIFrameElement& node() const { return static_cast<const HTMLIFrameElement&>(LayoutReplaced::node()); }

View file

@ -77,7 +77,7 @@ void LayoutImage::layout(LayoutMode layout_mode)
LayoutReplaced::layout(layout_mode); LayoutReplaced::layout(layout_mode);
} }
void LayoutImage::render(RenderingContext& context, PaintPhase phase) void LayoutImage::paint(PaintContext& context, PaintPhase phase)
{ {
if (!is_visible()) if (!is_visible())
return; return;
@ -86,7 +86,7 @@ void LayoutImage::render(RenderingContext& context, PaintPhase phase)
if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect()))) if (!context.viewport_rect().intersects(enclosing_int_rect(absolute_rect())))
return; return;
LayoutReplaced::render(context, phase); LayoutReplaced::paint(context, phase);
if (phase == PaintPhase::Foreground) { if (phase == PaintPhase::Foreground) {
if (renders_as_alt_text()) { if (renders_as_alt_text()) {

View file

@ -39,7 +39,7 @@ public:
virtual ~LayoutImage() override; virtual ~LayoutImage() override;
virtual void layout(LayoutMode = LayoutMode::Default) override; virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
const Element& node() const { return static_cast<const Element&>(LayoutReplaced::node()); } const Element& node() const { return static_cast<const Element&>(LayoutReplaced::node()); }

View file

@ -38,7 +38,7 @@ LayoutListItemMarker::~LayoutListItemMarker()
{ {
} }
void LayoutListItemMarker::render(RenderingContext& context, PaintPhase phase) void LayoutListItemMarker::paint(PaintContext& context, PaintPhase phase)
{ {
if (phase != PaintPhase::Foreground) if (phase != PaintPhase::Foreground)
return; return;

View file

@ -35,7 +35,7 @@ public:
LayoutListItemMarker(); LayoutListItemMarker();
virtual ~LayoutListItemMarker() override; virtual ~LayoutListItemMarker() override;
virtual void render(RenderingContext&, PaintPhase) override; virtual void paint(PaintContext&, PaintPhase) override;
private: private:
virtual const char* class_name() const override { return "LayoutListItemMarker"; } virtual const char* class_name() const override { return "LayoutListItemMarker"; }

View file

@ -89,7 +89,7 @@ const LayoutBlock* LayoutNode::containing_block() const
return nearest_block_ancestor(); return nearest_block_ancestor();
} }
void LayoutNode::render(RenderingContext& context, PaintPhase phase) void LayoutNode::paint(PaintContext& context, PaintPhase phase)
{ {
if (!is_visible()) if (!is_visible())
return; return;
@ -97,7 +97,7 @@ void LayoutNode::render(RenderingContext& context, PaintPhase phase)
for_each_child([&](auto& child) { for_each_child([&](auto& child) {
if (child.is_box() && to<LayoutBox>(child).stacking_context()) if (child.is_box() && to<LayoutBox>(child).stacking_context())
return; return;
child.render(context, phase); child.paint(context, phase);
}); });
} }

View file

@ -34,7 +34,7 @@
#include <LibWeb/Forward.h> #include <LibWeb/Forward.h>
#include <LibWeb/Layout/BoxModelMetrics.h> #include <LibWeb/Layout/BoxModelMetrics.h>
#include <LibWeb/Layout/LayoutPosition.h> #include <LibWeb/Layout/LayoutPosition.h>
#include <LibWeb/RenderingContext.h> #include <LibWeb/Painting/PaintContext.h>
#include <LibWeb/TreeNode.h> #include <LibWeb/TreeNode.h>
namespace Web { namespace Web {
@ -178,7 +178,7 @@ public:
Foreground, Foreground,
Overlay, Overlay,
}; };
virtual void render(RenderingContext&, PaintPhase); virtual void paint(PaintContext&, PaintPhase);
bool is_absolutely_positioned() const; bool is_absolutely_positioned() const;
bool is_fixed_position() const; bool is_fixed_position() const;

View file

@ -65,7 +65,7 @@ const String& LayoutText::text_for_style(const StyleProperties& style) const
return node().data(); return node().data();
} }
void LayoutText::render_fragment(RenderingContext& context, const LineBoxFragment& fragment) const void LayoutText::render_fragment(PaintContext& context, const LineBoxFragment& fragment) const
{ {
auto& painter = context.painter(); auto& painter = context.painter();
painter.set_font(style().font()); painter.set_font(style().font());

View file

@ -46,7 +46,7 @@ public:
virtual const char* class_name() const override { return "LayoutText"; } virtual const char* class_name() const override { return "LayoutText"; }
virtual bool is_text() const final { return true; } virtual bool is_text() const final { return true; }
void render_fragment(RenderingContext&, const LineBoxFragment&) const; void render_fragment(PaintContext&, const LineBoxFragment&) const;
virtual void split_into_lines(LayoutBlock& container, LayoutMode) override; virtual void split_into_lines(LayoutBlock& container, LayoutMode) override;

View file

@ -29,12 +29,12 @@
#include <LibWeb/Layout/LayoutDocument.h> #include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/LayoutText.h> #include <LibWeb/Layout/LayoutText.h>
#include <LibWeb/Layout/LineBoxFragment.h> #include <LibWeb/Layout/LineBoxFragment.h>
#include <LibWeb/RenderingContext.h> #include <LibWeb/Painting/PaintContext.h>
#include <ctype.h> #include <ctype.h>
namespace Web { namespace Web {
void LineBoxFragment::render(RenderingContext& context) void LineBoxFragment::render(PaintContext& context)
{ {
for (auto* ancestor = layout_node().parent(); ancestor; ancestor = ancestor->parent()) { for (auto* ancestor = layout_node().parent(); ancestor; ancestor = ancestor->parent()) {
if (!ancestor->is_visible()) if (!ancestor->is_visible())

View file

@ -60,7 +60,7 @@ public:
float absolute_x() const { return absolute_rect().x(); } float absolute_x() const { return absolute_rect().x(); }
void render(RenderingContext&); void render(PaintContext&);
bool ends_in_whitespace() const; bool ends_in_whitespace() const;
bool is_justifiable_whitespace() const; bool is_justifiable_whitespace() const;

View file

@ -47,17 +47,17 @@ StackingContext::StackingContext(LayoutBox& box, StackingContext* parent)
} }
} }
void StackingContext::render(RenderingContext& context, LayoutNode::PaintPhase phase) void StackingContext::paint(PaintContext& context, LayoutNode::PaintPhase phase)
{ {
if (!m_box.is_root()) { if (!m_box.is_root()) {
m_box.render(context, phase); m_box.paint(context, phase);
} else { } else {
// NOTE: LayoutDocument::render() merely calls StackingContext::render() // NOTE: LayoutDocument::paint() merely calls StackingContext::paint()
// so we call its base class instead. // so we call its base class instead.
to<LayoutDocument>(m_box).LayoutBlock::render(context, phase); to<LayoutDocument>(m_box).LayoutBlock::paint(context, phase);
} }
for (auto* child : m_children) { for (auto* child : m_children) {
child->render(context, phase); child->paint(context, phase);
} }
} }

View file

@ -40,7 +40,7 @@ public:
StackingContext* parent() { return m_parent; } StackingContext* parent() { return m_parent; }
const StackingContext* parent() const { return m_parent; } const StackingContext* parent() const { return m_parent; }
void render(RenderingContext&, LayoutNode::PaintPhase); void paint(PaintContext&, LayoutNode::PaintPhase);
void dump(int indent = 0) const; void dump(int indent = 0) const;

View file

@ -47,7 +47,7 @@
#include <LibWeb/Layout/LayoutNode.h> #include <LibWeb/Layout/LayoutNode.h>
#include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/PageView.h> #include <LibWeb/PageView.h>
#include <LibWeb/RenderingContext.h> #include <LibWeb/Painting/PaintContext.h>
#include <stdio.h> #include <stdio.h>
//#define SELECTION_DEBUG //#define SELECTION_DEBUG
@ -207,7 +207,7 @@ void PageView::paint_event(GUI::PaintEvent& event)
painter.translate(frame_thickness(), frame_thickness()); painter.translate(frame_thickness(), frame_thickness());
painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value()); painter.translate(-horizontal_scrollbar().value(), -vertical_scrollbar().value());
RenderingContext context(painter, palette(), { horizontal_scrollbar().value(), vertical_scrollbar().value() }); PaintContext context(painter, palette(), { horizontal_scrollbar().value(), vertical_scrollbar().value() });
context.set_should_show_line_box_borders(m_should_show_line_box_borders); context.set_should_show_line_box_borders(m_should_show_line_box_borders);
context.set_viewport_rect(viewport_rect_in_content_coordinates()); context.set_viewport_rect(viewport_rect_in_content_coordinates());
layout_root()->paint_all_phases(context); layout_root()->paint_all_phases(context);

View file

@ -32,9 +32,9 @@
namespace Web { namespace Web {
class RenderingContext { class PaintContext {
public: public:
explicit RenderingContext(Gfx::Painter& painter, const Palette& palette, const Gfx::IntPoint& scroll_offset) explicit PaintContext(Gfx::Painter& painter, const Palette& palette, const Gfx::IntPoint& scroll_offset)
: m_painter(painter) : m_painter(painter)
, m_palette(palette) , m_palette(palette)
, m_scroll_offset(scroll_offset) , m_scroll_offset(scroll_offset)

View file

@ -86,7 +86,7 @@ void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
painter.draw_tiled_bitmap(content_rect, *background_bitmap); painter.draw_tiled_bitmap(content_rect, *background_bitmap);
} }
Web::RenderingContext context(painter, palette(), Gfx::IntPoint()); Web::PaintContext context(painter, palette(), Gfx::IntPoint());
context.set_viewport_rect(content_rect); context.set_viewport_rect(content_rect);
layout_root->paint_all_phases(context); layout_root->paint_all_phases(context);
} }