ソースを参照

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.
Andi Gallo 2 年 前
コミット
f489d85edd
1 ファイル変更19 行追加11 行削除
  1. 19 11
      Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp

+ 19 - 11
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<CSS::LineStyle, unsigned> 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)