mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb: Map hr
width attribute to the width dimension property
This commit is contained in:
parent
45a3360a62
commit
4c3101e021
Notes:
github-actions[bot]
2024-10-02 09:28:38 +00:00
Author: https://github.com/tcl3
Commit: 4c3101e021
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1591
4 changed files with 41 additions and 0 deletions
3
Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt
Normal file
3
Tests/LibWeb/Text/expected/HTML/dimension-attributes.txt
Normal file
|
@ -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
|
21
Tests/LibWeb/Text/input/HTML/dimension-attributes.html
Normal file
21
Tests/LibWeb/Text/input/HTML/dimension-attributes.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const tests = [
|
||||
{ elementName: "hr", attribute: "width", mappedProperty: "width" },
|
||||
];
|
||||
const values = ["100", " 00110 ", "120."];
|
||||
|
||||
for (const { elementName, attribute, mappedProperty } of tests) {
|
||||
const element = document.createElement(elementName);
|
||||
document.body.appendChild(element);
|
||||
const style = document.defaultView.getComputedStyle(element);
|
||||
for (const value of values) {
|
||||
element[attribute] = value;
|
||||
println(`Test ${elementName}.${attribute} = "${value}" maps to ${mappedProperty}: ${style[mappedProperty]}`);
|
||||
}
|
||||
element.remove();
|
||||
}
|
||||
});
|
||||
</script>
|
|
@ -6,7 +6,10 @@
|
|||
|
||||
#include <LibWeb/Bindings/HTMLHRElementPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
#include <LibWeb/HTML/HTMLHRElement.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue