1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:27:43 +00:00

LibWeb: Let Paintable perform the painting

This patch adds a bunch of Paintable subclasses, each corresponding to
the Layout::Node subclasses that had a paint() override. All painting
logic is moved from layout nodes into their corresponding paintables.

Paintables are now created by asking a Layout::Box to produce one:

    static NonnullOwnPtr<Paintable> Layout::Box::create_paintable()

Note that inline nodes still have their painting logic. Since they
are not boxes, and all paintables have a corresponding box, we'll need
to come up with some other solution for them.
This commit is contained in:
Andreas Kling 2022-03-10 14:02:25 +01:00
parent f6497b64ac
commit 02b316fd5c
64 changed files with 1307 additions and 602 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,7 +12,7 @@
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/Layout/CheckBox.h>
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Painting/Paintable.h>
#include <LibWeb/Painting/CheckBoxPaintable.h>
namespace Web::Layout {
@ -27,18 +27,6 @@ CheckBox::~CheckBox()
{
}
void CheckBox::paint(PaintContext& context, Painting::PaintPhase phase)
{
if (!is_visible())
return;
LabelableNode::paint(context, phase);
if (phase == Painting::PaintPhase::Foreground) {
Gfx::StylePainter::paint_check_box(context.painter(), enclosing_int_rect(m_paint_box->absolute_rect()), context.palette(), dom_node().enabled(), dom_node().checked(), m_being_pressed);
}
}
void CheckBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned)
{
if (button != GUI::MouseButton::Primary || !dom_node().enabled())
@ -120,4 +108,9 @@ void CheckBox::handle_associated_label_mousemove(Badge<Label>, bool is_inside_no
set_needs_display();
}
OwnPtr<Painting::Paintable> CheckBox::create_paintable() const
{
return Painting::CheckBoxPaintable::create(*this);
}
}