From adfdfd6aba58f378b00319ac5fc6cdcf78b40a84 Mon Sep 17 00:00:00 2001 From: Tobias Christiansen Date: Sun, 16 May 2021 20:03:04 +0200 Subject: LibWeb: Deal with Boxes that have a background, border and -radius This hack allows for Boxes that have a background to be painted and a border to accurately paint their border-radii if needed. For that the box in with the background is drawn is extended to the bordered_rect. The border is later drawn over this regardless. Previously when drawing a Box that had all three, background, border and a border-radius, there could be some white between the filling and the border. --- Userland/Libraries/LibWeb/Layout/Box.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index f4f2c680aa..de85dde8c5 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -179,11 +179,11 @@ void Box::paint_background(PaintContext& context) if (is_body() && document().html_element()->should_use_body_background_properties()) return; + Gfx::IntRect background_rect; Color background_color = computed_values().background_color(); const Gfx::Bitmap* background_image = this->background_image() ? this->background_image()->bitmap() : nullptr; CSS::Repeat background_repeat_x = computed_values().background_repeat_x(); CSS::Repeat background_repeat_y = computed_values().background_repeat_y(); - auto background_rect = enclosing_int_rect(padded_rect); if (is_root_element()) { // CSS 2.1 Appendix E.2: If the element is a root element, paint the background over the entire canvas. @@ -201,6 +201,11 @@ void Box::paint_background(PaintContext& context) background_rect = enclosing_int_rect(padded_rect); } + // HACK: If the Box has a border, use the bordered_rect to paint the background. + // This way if we have a border-radius there will be no gap between the filling and actual border. + if (computed_values().border_top().width || computed_values().border_right().width || computed_values().border_bottom().width || computed_values().border_left().width) + background_rect = enclosing_int_rect(bordered_rect()); + // FIXME: some values should be relative to the height() if specified, but which? For now, all relative values are relative to the width. auto border_radius_data = normalized_border_radius_data(); auto top_left_radius = border_radius_data.top_left; -- cgit v1.2.3