mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:18:13 +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:
parent
f6497b64ac
commit
02b316fd5c
64 changed files with 1307 additions and 602 deletions
|
@ -12,7 +12,7 @@
|
|||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/Layout/ButtonBox.h>
|
||||
#include <LibWeb/Layout/Label.h>
|
||||
#include <LibWeb/Painting/Paintable.h>
|
||||
#include <LibWeb/Painting/ButtonPaintable.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
|
@ -31,21 +31,6 @@ void ButtonBox::prepare_for_replaced_layout()
|
|||
set_intrinsic_height(font().glyph_height());
|
||||
}
|
||||
|
||||
void ButtonBox::paint(PaintContext& context, Painting::PaintPhase phase)
|
||||
{
|
||||
if (!is_visible())
|
||||
return;
|
||||
|
||||
LabelableNode::paint(context, phase);
|
||||
|
||||
if (phase == Painting::PaintPhase::Foreground) {
|
||||
auto text_rect = enclosing_int_rect(m_paint_box->absolute_rect());
|
||||
if (m_being_pressed)
|
||||
text_rect.translate_by(1, 1);
|
||||
context.painter().draw_text(text_rect, dom_node().value(), font(), Gfx::TextAlignment::Center, computed_values().color());
|
||||
}
|
||||
}
|
||||
|
||||
void ButtonBox::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint&, unsigned button, unsigned)
|
||||
{
|
||||
if (button != GUI::MouseButton::Primary || !dom_node().enabled())
|
||||
|
@ -121,4 +106,9 @@ void ButtonBox::handle_associated_label_mousemove(Badge<Label>, bool is_inside_n
|
|||
set_needs_display();
|
||||
}
|
||||
|
||||
OwnPtr<Painting::Paintable> ButtonBox::create_paintable() const
|
||||
{
|
||||
return Painting::ButtonPaintable::create(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue