Skip to content

Commit 0e470d5

Browse files
tcl3awesomekling
authored andcommitted
LibWeb: Apply presentational hints for the HTMLHRElement align attribute
1 parent c217057 commit 0e470d5

File tree

3 files changed

+69
-1
lines changed
  • Libraries/LibWeb/HTML
  • Tests/LibWeb/Ref
    • expected/wpt-import/html/rendering/non-replaced-elements/the-hr-element-0
    • input/wpt-import/html/rendering/non-replaced-elements/the-hr-element-0

3 files changed

+69
-1
lines changed

Libraries/LibWeb/HTML/HTMLHRElement.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bool HTMLHRElement::is_presentational_hint(FlyString const& name) const
3636
if (Base::is_presentational_hint(name))
3737
return true;
3838

39-
return first_is_one_of(name, HTML::AttributeNames::color, HTML::AttributeNames::noshade, HTML::AttributeNames::width);
39+
return first_is_one_of(name, HTML::AttributeNames::align, HTML::AttributeNames::color, HTML::AttributeNames::noshade, HTML::AttributeNames::width);
4040
}
4141

4242
void HTMLHRElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
@@ -50,6 +50,19 @@ void HTMLHRElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties>
5050
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftStyle, CSS::CSSKeywordValue::create(CSS::Keyword::Solid));
5151
}
5252

53+
if (name == HTML::AttributeNames::align) {
54+
if (value.equals_ignoring_ascii_case("left"sv)) {
55+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, CSS::LengthStyleValue::create(CSS::Length::make_px(0)));
56+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
57+
} else if (value.equals_ignoring_ascii_case("right"sv)) {
58+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
59+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, CSS::LengthStyleValue::create(CSS::Length::make_px(0)));
60+
} else if (value.equals_ignoring_ascii_case("center"sv)) {
61+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
62+
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
63+
}
64+
}
65+
5366
// https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:attr-hr-color-3
5467
// When an hr element has a color attribute, its value is expected to be parsed using the rules for parsing a legacy color value, and if that does not return failure,
5568
// the user agent is expected to treat the attribute as a presentational hint setting the element's 'color' property to the resulting color.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
<!doctype html>
3+
<meta charset=utf-8>
4+
<style>
5+
.hr {
6+
color: gray;
7+
border-style: inset;
8+
border-width: 1px;
9+
margin: 0.5em auto;
10+
width: 100px;
11+
}
12+
13+
.left {
14+
margin-left: 0;
15+
}
16+
17+
.right {
18+
margin-right: 0;
19+
}
20+
</style>
21+
<div class='hr'></div>
22+
<div class='hr left'></div>
23+
<div class='hr'></div>
24+
<div class='hr right'></div>
25+
<div class='hr'></div>
26+
27+
<div class='hr'></div>
28+
<div class='hr left'></div>
29+
<div class='hr'></div>
30+
<div class='hr right'></div>
31+
<div class='hr'></div>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<meta charset="utf-8">
3+
<link rel="match" href="../../../../../../expected/wpt-import/html/rendering/non-replaced-elements/the-hr-element-0/align-ref.html">
4+
<style>
5+
hr {
6+
width: 100px;
7+
}
8+
</style>
9+
10+
<hr align=>
11+
<hr align=left>
12+
<hr align=center>
13+
<hr align=right>
14+
<hr align=foobar>
15+
16+
<script>
17+
// Test the IDL attribute
18+
const values = ['', 'left', 'center', 'right', 'foobar'];
19+
values.forEach(value => {
20+
const hr = document.createElement('hr');
21+
hr.align = value;
22+
document.body.appendChild(hr);
23+
});
24+
</script>

0 commit comments

Comments
 (0)