From f489d85eddcc598993256e0db39ab6738051d0f3 Mon Sep 17 00:00:00 2001 From: Andi Gallo Date: Sun, 2 Jul 2023 09:58:36 +0000 Subject: [PATCH] LibWeb: Separate comparator for cell border specificity Add a cell border specificity comparator which preserves the winning border logic according to specification and makes it possible to sort borders by specificity. This will be important for handling the style of table cell corners in a way consistent with other browsers. --- .../LibWeb/Layout/TableFormattingContext.cpp | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 6d09cce8e4..9cdab596d7 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -857,9 +857,9 @@ void TableFormattingContext::position_cell_boxes() } } -static const CSS::BorderData& winning_border_style(const CSS::BorderData& a, const CSS::BorderData& b) +static bool border_is_less_specific(const CSS::BorderData& a, const CSS::BorderData& b) { - // Implements steps 1, 2 and 3 of border conflict resolution algorithm. + // Implements criteria for steps 1, 2 and 3 of border conflict resolution algorithm. static HashMap const line_style_score = { { CSS::LineStyle::Inset, 0 }, { CSS::LineStyle::Groove, 1 }, @@ -870,29 +870,37 @@ static const CSS::BorderData& winning_border_style(const CSS::BorderData& a, con { CSS::LineStyle::Solid, 6 }, { CSS::LineStyle::Double, 7 }, }; + if (a.line_style == CSS::LineStyle::Hidden) { - return a; + return false; } + if (b.line_style == CSS::LineStyle::Hidden) { - return b; + return true; } + if (a.line_style == CSS::LineStyle::None) { - return b; + return true; } if (b.line_style == CSS::LineStyle::None) { - return a; + return false; } if (a.width > b.width) { - return a; + return false; } else if (a.width < b.width) { - return b; + return true; } if (*line_style_score.get(a.line_style) > *line_style_score.get(b.line_style)) { - return a; + return false; } else if (*line_style_score.get(a.line_style) < *line_style_score.get(b.line_style)) { - return b; + return true; } - return a; + return false; +} + +static const CSS::BorderData& winning_border_style(const CSS::BorderData& a, const CSS::BorderData& b) +{ + return border_is_less_specific(a, b) ? b : a; } const CSS::BorderData& TableFormattingContext::border_data_conflicting_edge(TableFormattingContext::ConflictingEdge const& conflicting_edge)