From 4c1a7650765af9908c4108909ab341c2525f1807 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 10 May 2020 18:08:02 +0100 Subject: [PATCH] LibWeb: Add basic support for "border-style: {dotted,dashed}" --- Base/home/anon/www/borders.html | 44 +++++++++++++++++++++++++++ Libraries/LibWeb/Layout/LayoutBox.cpp | 25 +++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/Base/home/anon/www/borders.html b/Base/home/anon/www/borders.html index a5b841d7dd1..32447b0721d 100644 --- a/Base/home/anon/www/borders.html +++ b/Base/home/anon/www/borders.html @@ -3,6 +3,9 @@ CSS borders lookin' good @@ -102,5 +139,12 @@
double width solo
double style solo
double color solo
+
dotted (1px)
+
dotted (5px)
+
dotted (20px)
+
dashed (1px)
+
dashed (5px)
+
dashed (20px)
+
mixed
diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/LayoutBox.cpp index 7fe66dd9b09..e73e4900b60 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/LayoutBox.cpp @@ -106,6 +106,31 @@ void LayoutBox::paint_border(RenderingContext& context, Edge edge, const Gfx::Fl if (border_style.has_value()) { if (border_style.value()->to_string() == "dotted") line_style = Gfx::Painter::LineStyle::Dotted; + if (border_style.value()->to_string() == "dashed") + line_style = Gfx::Painter::LineStyle::Dashed; + } + + if (line_style != Gfx::Painter::LineStyle::Solid) { + switch (edge) { + case Edge::Top: + p1.move_by(int_width / 2, int_width / 2); + p2.move_by(-int_width / 2, int_width / 2); + break; + case Edge::Right: + p1.move_by(-int_width / 2, int_width / 2); + p2.move_by(-int_width / 2, -int_width / 2); + break; + case Edge::Bottom: + p1.move_by(int_width / 2, -int_width / 2); + p2.move_by(-int_width / 2, -int_width / 2); + break; + case Edge::Left: + p1.move_by(int_width / 2, int_width / 2); + p2.move_by(int_width / 2, -int_width / 2); + break; + } + context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, int_width, line_style); + return; } auto draw_line = [&](auto& p1, auto& p2) {