mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibWeb: Stop clipping the root element's background
This commit is contained in:
parent
5413716802
commit
93ae57114d
Notes:
github-actions[bot]
2025-07-04 15:20:13 +00:00
Author: https://github.com/Psychpsyo
Commit: 93ae57114d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4978
Reviewed-by: https://github.com/AtkinsSJ ✅
6 changed files with 56 additions and 17 deletions
|
@ -91,7 +91,8 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box,
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayListRecorderStateSaver state { display_list_recorder };
|
DisplayListRecorderStateSaver state { display_list_recorder };
|
||||||
if (resolved_background.needs_text_clip) {
|
bool is_root_element = paintable_box.layout_node().is_root_element();
|
||||||
|
if (resolved_background.needs_text_clip && !is_root_element) {
|
||||||
auto display_list = compute_text_clip_paths(context, paintable_box, resolved_background.background_rect.location());
|
auto display_list = compute_text_clip_paths(context, paintable_box, resolved_background.background_rect.location());
|
||||||
auto rect = context.rounded_device_rect(resolved_background.background_rect);
|
auto rect = context.rounded_device_rect(resolved_background.background_rect);
|
||||||
display_list_recorder.add_mask(move(display_list), rect.to_type<int>());
|
display_list_recorder.add_mask(move(display_list), rect.to_type<int>());
|
||||||
|
@ -104,6 +105,11 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box,
|
||||||
|
|
||||||
auto const& color_box = resolved_background.color_box;
|
auto const& color_box = resolved_background.color_box;
|
||||||
|
|
||||||
|
if (is_root_element) {
|
||||||
|
display_list_recorder.fill_rect(
|
||||||
|
context.enclosing_device_rect(color_box.rect).to_type<int>(),
|
||||||
|
resolved_background.color);
|
||||||
|
} else {
|
||||||
display_list_recorder.fill_rect_with_rounded_corners(
|
display_list_recorder.fill_rect_with_rounded_corners(
|
||||||
context.rounded_device_rect(color_box.rect).to_type<int>(),
|
context.rounded_device_rect(color_box.rect).to_type<int>(),
|
||||||
resolved_background.color,
|
resolved_background.color,
|
||||||
|
@ -111,6 +117,7 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box,
|
||||||
color_box.radii.top_right.as_corner(context),
|
color_box.radii.top_right.as_corner(context),
|
||||||
color_box.radii.bottom_right.as_corner(context),
|
color_box.radii.bottom_right.as_corner(context),
|
||||||
color_box.radii.bottom_left.as_corner(context));
|
color_box.radii.bottom_left.as_corner(context));
|
||||||
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
DevicePixels top { 0 };
|
DevicePixels top { 0 };
|
||||||
|
@ -141,14 +148,16 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box,
|
||||||
|
|
||||||
CSSPixelRect const& css_clip_rect = clip_box.rect;
|
CSSPixelRect const& css_clip_rect = clip_box.rect;
|
||||||
auto clip_rect = context.rounded_device_rect(css_clip_rect);
|
auto clip_rect = context.rounded_device_rect(css_clip_rect);
|
||||||
|
ScopedCornerRadiusClip corner_clip { context, context.rounded_device_rect(css_clip_rect), clip_box.radii, CornerClip::Outside, !is_root_element };
|
||||||
|
if (!is_root_element) {
|
||||||
display_list_recorder.add_clip_rect(clip_rect.to_type<int>());
|
display_list_recorder.add_clip_rect(clip_rect.to_type<int>());
|
||||||
ScopedCornerRadiusClip corner_clip { context, context.rounded_device_rect(css_clip_rect), clip_box.radii };
|
|
||||||
|
|
||||||
if (layer.clip == CSS::BackgroundBox::BorderBox) {
|
if (layer.clip == CSS::BackgroundBox::BorderBox) {
|
||||||
// Shrink the effective clip rect if to account for the bits the borders will definitely paint over
|
// Shrink the effective clip rect if to account for the bits the borders will definitely paint over
|
||||||
// (if they all have alpha == 255).
|
// (if they all have alpha == 255).
|
||||||
clip_rect.shrink(clip_shrink.top, clip_shrink.right, clip_shrink.bottom, clip_shrink.left);
|
clip_rect.shrink(clip_shrink.top, clip_shrink.right, clip_shrink.bottom, clip_shrink.left);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto const& image = *layer.background_image;
|
auto const& image = *layer.background_image;
|
||||||
auto image_rect = layer.image_rect;
|
auto image_rect = layer.image_rect;
|
||||||
|
|
|
@ -10,9 +10,12 @@
|
||||||
|
|
||||||
namespace Web::Painting {
|
namespace Web::Painting {
|
||||||
|
|
||||||
ScopedCornerRadiusClip::ScopedCornerRadiusClip(PaintContext& context, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip)
|
ScopedCornerRadiusClip::ScopedCornerRadiusClip(PaintContext& context, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip, bool do_apply)
|
||||||
: m_context(context)
|
: m_context(context)
|
||||||
{
|
{
|
||||||
|
m_do_apply = do_apply;
|
||||||
|
if (!do_apply)
|
||||||
|
return;
|
||||||
CornerRadii const corner_radii {
|
CornerRadii const corner_radii {
|
||||||
.top_left = border_radii.top_left.as_corner(context),
|
.top_left = border_radii.top_left.as_corner(context),
|
||||||
.top_right = border_radii.top_right.as_corner(context),
|
.top_right = border_radii.top_right.as_corner(context),
|
||||||
|
@ -28,7 +31,7 @@ ScopedCornerRadiusClip::ScopedCornerRadiusClip(PaintContext& context, DevicePixe
|
||||||
|
|
||||||
ScopedCornerRadiusClip::~ScopedCornerRadiusClip()
|
ScopedCornerRadiusClip::~ScopedCornerRadiusClip()
|
||||||
{
|
{
|
||||||
if (!m_has_radius)
|
if (!m_has_radius && m_do_apply)
|
||||||
return;
|
return;
|
||||||
m_context.display_list_recorder().restore();
|
m_context.display_list_recorder().restore();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ enum class CornerClip {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScopedCornerRadiusClip {
|
struct ScopedCornerRadiusClip {
|
||||||
ScopedCornerRadiusClip(PaintContext& context, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside);
|
ScopedCornerRadiusClip(PaintContext& context, DevicePixelRect const& border_rect, BorderRadiiData const& border_radii, CornerClip corner_clip = CornerClip::Outside, bool do_apply = true);
|
||||||
|
|
||||||
~ScopedCornerRadiusClip();
|
~ScopedCornerRadiusClip();
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ struct ScopedCornerRadiusClip {
|
||||||
private:
|
private:
|
||||||
PaintContext& m_context;
|
PaintContext& m_context;
|
||||||
bool m_has_radius { false };
|
bool m_has_radius { false };
|
||||||
|
bool m_do_apply;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
6
Tests/LibWeb/Ref/expected/css/backgrounds/black.html
Normal file
6
Tests/LibWeb/Ref/expected/css/backgrounds/black.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<link rel="match" href="../../../expected/css/backgrounds/black.html" />
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
/* black square */
|
||||||
|
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCA1LjEuOBtp6qgAAAC2ZVhJZklJKgAIAAAABQAaAQUAAQAAAEoAAAAbAQUAAQAAAFIAAAAoAQMAAQAAAAMAAAAxAQIAEAAAAFoAAABphwQAAQAAAGoAAAAAAAAAo5MAAOgDAACjkwAA6AMAAFBhaW50Lk5FVCA1LjEuOAADAACQBwAEAAAAMDIzMAGgAwABAAAAAQAAAAWgBAABAAAAlAAAAAAAAAACAAEAAgAEAAAAUjk4AAIABwAEAAAAMDEwMAAAAAC6HzhD+YwuiQAAAA5JREFUKFNjGAUkAwYGAAE2AAFjw6IYAAAAAElFTkSuQmCC);
|
||||||
|
background-clip: text;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
THIS SHOULD NOT BE VISIBLE
|
||||||
|
<!-- to force the background-image to load -->
|
||||||
|
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCA1LjEuOBtp6qgAAAC2ZVhJZklJKgAIAAAABQAaAQUAAQAAAEoAAAAbAQUAAQAAAFIAAAAoAQMAAQAAAAMAAAAxAQIAEAAAAFoAAABphwQAAQAAAGoAAAAAAAAAo5MAAOgDAACjkwAA6AMAAFBhaW50Lk5FVCA1LjEuOAADAACQBwAEAAAAMDIzMAGgAwABAAAAAQAAAAWgBAABAAAAlAAAAAAAAAACAAEAAgAEAAAAUjk4AAIABwAEAAAAMDEwMAAAAAC6HzhD+YwuiQAAAA5JREFUKFNjGAUkAwYGAAE2AAFjw6IYAAAAAElFTkSuQmCC" alt="">
|
|
@ -0,0 +1,8 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<link rel="match" href="../../../expected/css/backgrounds/black.html" />
|
||||||
|
<style>
|
||||||
|
html {
|
||||||
|
background-color: black;
|
||||||
|
border-radius: 100px;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Add table
Add a link
Reference in a new issue