From 4c3101e021e323b487e8ab10026a14fdf40fa2f0 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Tue, 1 Oct 2024 17:19:10 +0100 Subject: [PATCH] LibWeb: Map `hr` width attribute to the width dimension property --- .../expected/HTML/dimension-attributes.txt | 3 +++ .../Text/input/HTML/dimension-attributes.html | 21 +++++++++++++++++++ .../Libraries/LibWeb/HTML/HTMLHRElement.cpp | 15 +++++++++++++ .../Libraries/LibWeb/HTML/HTMLHRElement.h | 2 ++ 4 files changed, 41 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt create mode 100644 Tests/LibWeb/Text/input/HTML/dimension-attributes.html diff --git a/Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt b/Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt new file mode 100644 index 00000000000..8a0f341ff1e --- /dev/null +++ b/Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt @@ -0,0 +1,3 @@ +Test hr.width = "100" maps to width: 100px +Test hr.width = " 00110 " maps to width: 110px +Test hr.width = "120." maps to width: 120px diff --git a/Tests/LibWeb/Text/input/HTML/dimension-attributes.html b/Tests/LibWeb/Text/input/HTML/dimension-attributes.html new file mode 100644 index 00000000000..b4e81573132 --- /dev/null +++ b/Tests/LibWeb/Text/input/HTML/dimension-attributes.html @@ -0,0 +1,21 @@ + + + diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp index 4ad79b1e2d3..deaee9cd1c6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.cpp @@ -6,7 +6,10 @@ #include #include +#include +#include #include +#include namespace Web::HTML { @@ -25,4 +28,16 @@ void HTMLHRElement::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLHRElement); } +void HTMLHRElement::apply_presentational_hints(CSS::StyleProperties& style) const +{ + for_each_attribute([&](auto& name, auto& value) { + // https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:maps-to-the-dimension-property + if (name == HTML::AttributeNames::width) { + if (auto parsed_value = parse_dimension_value(value)) { + style.set_property(CSS::PropertyID::Width, *parsed_value); + } + } + }); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h index 17b8f9da4ae..e770e309c5a 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLHRElement.h @@ -25,6 +25,8 @@ private: HTMLHRElement(DOM::Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; + + virtual void apply_presentational_hints(CSS::StyleProperties&) const override; }; }