-
-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibWeb: Layout the fieldset's rendered legend
- Loading branch information
1 parent
01f4bbb
commit b190b04
Showing
9 changed files
with
224 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) 2024, Kostya Farber <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <LibWeb/Layout/LegendBox.h> | ||
#include <LibWeb/Painting/FieldSetPaintable.h> | ||
|
||
namespace Web::Painting { | ||
GC_DEFINE_ALLOCATOR(FieldSetPaintable); | ||
|
||
GC::Ref<FieldSetPaintable> FieldSetPaintable::create(Layout::FieldSetBox const& layout_box) | ||
{ | ||
return layout_box.heap().allocate<FieldSetPaintable>(layout_box); | ||
} | ||
|
||
FieldSetPaintable::FieldSetPaintable(Layout::FieldSetBox const& layout_box) | ||
: PaintableBox(layout_box) | ||
{ | ||
} | ||
|
||
Layout::FieldSetBox& FieldSetPaintable::layout_box() | ||
{ | ||
return static_cast<Layout::FieldSetBox&>(layout_node()); | ||
} | ||
|
||
Layout::FieldSetBox const& FieldSetPaintable::layout_box() const | ||
{ | ||
return static_cast<Layout::FieldSetBox const&>(layout_node()); | ||
} | ||
|
||
void FieldSetPaintable::paint(PaintContext& context, PaintPhase phase) const | ||
{ | ||
if (!is_visible()) | ||
return; | ||
|
||
if (phase != PaintPhase::Border) { | ||
PaintableBox::paint(context, phase); | ||
return; | ||
} | ||
|
||
if (!(layout_box().has_rendered_legend())) { | ||
PaintableBox::paint(context, phase); | ||
return; | ||
} | ||
|
||
auto& display_list_recorder = context.display_list_recorder(); | ||
|
||
auto const* legend_box = layout_box().first_child_of_type<Layout::LegendBox>(); | ||
auto const* const legend_paintable = legend_box->paintable_box(); | ||
|
||
auto legend_border_rect = context.rounded_device_rect(legend_paintable->absolute_border_box_rect()); | ||
auto fieldset_border_rect = context.rounded_device_rect(absolute_border_box_rect()); | ||
|
||
BordersData borders_data = BordersData { | ||
.top = CSS::BorderData(), | ||
.right = box_model().border.right == 0 ? CSS::BorderData() : computed_values().border_right(), | ||
.bottom = box_model().border.bottom == 0 ? CSS::BorderData() : computed_values().border_bottom(), | ||
.left = box_model().border.left == 0 ? CSS::BorderData() : computed_values().border_left(), | ||
}; | ||
|
||
paint_all_borders(display_list_recorder, fieldset_border_rect, normalized_border_radii_data().as_corners(context), borders_data.to_device_pixels(context)); | ||
|
||
auto top_border_data = box_model().border.top == 0 ? CSS::BorderData() : computed_values().border_top(); | ||
auto top_border = context.enclosing_device_pixels(top_border_data.width).value(); | ||
|
||
// if fieldset has a rendered legend, the top border is not | ||
// expected to be painted behind the border box of the legend | ||
DevicePixelRect left_segment = { | ||
fieldset_border_rect.x(), | ||
fieldset_border_rect.y(), | ||
legend_border_rect.x() - fieldset_border_rect.x(), | ||
top_border | ||
}; | ||
|
||
DevicePixelRect right_segment = { | ||
legend_border_rect.right(), | ||
fieldset_border_rect.y(), | ||
fieldset_border_rect.right() - legend_border_rect.right(), | ||
top_border | ||
}; | ||
|
||
BordersData top_border_only = BordersData { | ||
.top = top_border_data, | ||
.right = CSS::BorderData(), | ||
.bottom = CSS::BorderData(), | ||
.left = CSS::BorderData(), | ||
}; | ||
|
||
display_list_recorder.save(); | ||
display_list_recorder.add_clip_rect(left_segment.to_type<int>()); | ||
paint_all_borders(display_list_recorder, fieldset_border_rect, normalized_border_radii_data().as_corners(context), top_border_only.to_device_pixels(context)); | ||
display_list_recorder.restore(); | ||
|
||
display_list_recorder.save(); | ||
display_list_recorder.add_clip_rect(right_segment.to_type<int>()); | ||
paint_all_borders( | ||
display_list_recorder, | ||
fieldset_border_rect, | ||
normalized_border_radii_data().as_corners(context), | ||
top_border_only.to_device_pixels(context)); | ||
display_list_recorder.restore(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2024, Kostya Farber <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <LibWeb/Forward.h> | ||
#include <LibWeb/Layout/FieldSetBox.h> | ||
#include <LibWeb/Painting/PaintContext.h> | ||
#include <LibWeb/Painting/PaintableBox.h> | ||
|
||
namespace Web::Painting { | ||
|
||
class FieldSetPaintable final : public PaintableBox { | ||
GC_CELL(FieldSetPaintable, PaintableBox); | ||
GC_DECLARE_ALLOCATOR(FieldSetPaintable); | ||
|
||
public: | ||
static GC::Ref<FieldSetPaintable> create(Layout::FieldSetBox const&); | ||
|
||
virtual void paint(PaintContext&, PaintPhase) const override; | ||
|
||
private: | ||
Layout::FieldSetBox& layout_box(); | ||
Layout::FieldSetBox const& layout_box() const; | ||
|
||
explicit FieldSetPaintable(Layout::FieldSetBox const&); | ||
}; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
Tests/LibWeb/Layout/expected/fieldset-with-rendered-legend.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline | ||
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline | ||
BlockContainer <body> at (8,8) content-size 784x36.59375 children: not-inline | ||
FieldSetBox <fieldset> at (24,15.59375) content-size 752x17 [BFC] children: not-inline | ||
LegendBox <legend> at (26,1.5) content-size 36.328125x17 children: inline | ||
frag 0 from TextNode start: 0, length: 5, rect: [26,1.5 36.328125x17] baseline: 13.296875 | ||
"login" | ||
TextNode <#text> | ||
BlockContainer <(anonymous)> at (8,44.59375) content-size 784x0 children: inline | ||
TextNode <#text> | ||
|
||
ViewportPaintable (Viewport<#document>) [0,0 800x600] | ||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600] | ||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x36.59375] overflow: [8,1.5 784x51.09375] | ||
FieldSetPaintable (FieldSetBox<FIELDSET>) [10,8 780x36.59375] overflow: [12,1.5 776x51.09375] | ||
PaintableWithLines (LegendBox<LEGEND>) [24,1.5 40.328125x17] | ||
TextPaintable (TextNode<#text>) | ||
PaintableWithLines (BlockContainer(anonymous)) [8,44.59375 784x0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<fieldset><legend>login</legend></fieldset> |