mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:57:35 +00:00
LibWeb: Add bordered_rect() and padded_rect() helpers in Layout::Box
This commit is contained in:
parent
21371bf6ee
commit
543dd54a1d
2 changed files with 23 additions and 11 deletions
|
@ -43,11 +43,7 @@ void Box::paint(PaintContext& context, PaintPhase phase)
|
||||||
if (is_fixed_position())
|
if (is_fixed_position())
|
||||||
context.painter().translate(context.scroll_offset());
|
context.painter().translate(context.scroll_offset());
|
||||||
|
|
||||||
Gfx::FloatRect padded_rect;
|
auto padded_rect = this->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);
|
|
||||||
|
|
||||||
if (phase == PaintPhase::Background && !is_body()) {
|
if (phase == PaintPhase::Background && !is_body()) {
|
||||||
context.painter().fill_rect(enclosing_int_rect(padded_rect), computed_values().background_color());
|
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) {
|
if (phase == PaintPhase::Border) {
|
||||||
Gfx::FloatRect bordered_rect;
|
auto bordered_rect = this->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);
|
|
||||||
|
|
||||||
Painting::paint_border(context, Painting::BorderEdge::Left, bordered_rect, computed_values());
|
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::Right, bordered_rect, computed_values());
|
||||||
Painting::paint_border(context, Painting::BorderEdge::Top, bordered_rect, computed_values());
|
Painting::paint_border(context, Painting::BorderEdge::Top, bordered_rect, computed_values());
|
||||||
|
|
|
@ -52,6 +52,27 @@ public:
|
||||||
float width() const { return m_size.width(); }
|
float width() const { return m_size.width(); }
|
||||||
float height() const { return m_size.height(); }
|
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
|
float margin_box_width() const
|
||||||
{
|
{
|
||||||
auto margin_box = box_model().margin_box();
|
auto margin_box = box_model().margin_box();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue