From 543dd54a1d1077b287e9c6538b57a147d2a0e693 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 22 Feb 2021 18:52:58 +0100 Subject: [PATCH] LibWeb: Add bordered_rect() and padded_rect() helpers in Layout::Box --- Userland/Libraries/LibWeb/Layout/Box.cpp | 13 ++----------- Userland/Libraries/LibWeb/Layout/Box.h | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index 869804e1e8..190340f13c 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -43,11 +43,7 @@ void Box::paint(PaintContext& context, PaintPhase phase) if (is_fixed_position()) context.painter().translate(context.scroll_offset()); - Gfx::FloatRect padded_rect; - padded_rect.set_x(absolute_x() - box_model().padding.left); - padded_rect.set_width(width() + box_model().padding.left + box_model().padding.right); - padded_rect.set_y(absolute_y() - box_model().padding.top); - padded_rect.set_height(height() + box_model().padding.top + box_model().padding.bottom); + auto padded_rect = this->padded_rect(); if (phase == PaintPhase::Background && !is_body()) { context.painter().fill_rect(enclosing_int_rect(padded_rect), computed_values().background_color()); @@ -57,12 +53,7 @@ void Box::paint(PaintContext& context, PaintPhase phase) } if (phase == PaintPhase::Border) { - Gfx::FloatRect bordered_rect; - bordered_rect.set_x(padded_rect.x() - box_model().border.left); - bordered_rect.set_width(padded_rect.width() + box_model().border.left + box_model().border.right); - bordered_rect.set_y(padded_rect.y() - box_model().border.top); - bordered_rect.set_height(padded_rect.height() + box_model().border.top + box_model().border.bottom); - + auto bordered_rect = this->bordered_rect(); Painting::paint_border(context, Painting::BorderEdge::Left, bordered_rect, computed_values()); Painting::paint_border(context, Painting::BorderEdge::Right, bordered_rect, computed_values()); Painting::paint_border(context, Painting::BorderEdge::Top, bordered_rect, computed_values()); diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index b35b561134..41d061fddd 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -52,6 +52,27 @@ public: float width() const { return m_size.width(); } float height() const { return m_size.height(); } + Gfx::FloatRect padded_rect() const + { + Gfx::FloatRect rect; + rect.set_x(absolute_x() - box_model().padding.left); + rect.set_width(width() + box_model().padding.left + box_model().padding.right); + rect.set_y(absolute_y() - box_model().padding.top); + rect.set_height(height() + box_model().padding.top + box_model().padding.bottom); + return rect; + } + + Gfx::FloatRect bordered_rect() const + { + auto padded_rect = this->padded_rect(); + Gfx::FloatRect rect; + rect.set_x(padded_rect.x() - box_model().border.left); + rect.set_width(padded_rect.width() + box_model().border.left + box_model().border.right); + rect.set_y(padded_rect.y() - box_model().border.top); + rect.set_height(padded_rect.height() + box_model().border.top + box_model().border.bottom); + return rect; + } + float margin_box_width() const { auto margin_box = box_model().margin_box();