mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-29 20:59:00 +00:00
LibWeb: Apply presentational hints for the HTMLHRElement color attribute
This commit is contained in:
parent
83c4e22247
commit
c217057cfd
Notes:
github-actions[bot]
2025-02-18 11:07:44 +00:00
Author: https://github.com/tcl3
Commit: c217057cfd
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3610
3 changed files with 49 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
||||||
|
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +8,8 @@
|
||||||
#include <LibWeb/Bindings/HTMLHRElementPrototype.h>
|
#include <LibWeb/Bindings/HTMLHRElementPrototype.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/CSS/ComputedProperties.h>
|
#include <LibWeb/CSS/ComputedProperties.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||||
#include <LibWeb/HTML/HTMLHRElement.h>
|
#include <LibWeb/HTML/HTMLHRElement.h>
|
||||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
|
@ -33,12 +36,28 @@ bool HTMLHRElement::is_presentational_hint(FlyString const& name) const
|
||||||
if (Base::is_presentational_hint(name))
|
if (Base::is_presentational_hint(name))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return first_is_one_of(name, HTML::AttributeNames::width);
|
return first_is_one_of(name, HTML::AttributeNames::color, HTML::AttributeNames::noshade, HTML::AttributeNames::width);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLHRElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
void HTMLHRElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||||
{
|
{
|
||||||
for_each_attribute([&](auto& name, auto& value) {
|
for_each_attribute([&](auto& name, auto& value) {
|
||||||
|
// https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2
|
||||||
|
if (name == HTML::AttributeNames::color || name == HTML::AttributeNames::noshade) {
|
||||||
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderTopStyle, CSS::CSSKeywordValue::create(CSS::Keyword::Solid));
|
||||||
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderRightStyle, CSS::CSSKeywordValue::create(CSS::Keyword::Solid));
|
||||||
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderBottomStyle, CSS::CSSKeywordValue::create(CSS::Keyword::Solid));
|
||||||
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::BorderLeftStyle, CSS::CSSKeywordValue::create(CSS::Keyword::Solid));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:attr-hr-color-3
|
||||||
|
// 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,
|
||||||
|
// the user agent is expected to treat the attribute as a presentational hint setting the element's 'color' property to the resulting color.
|
||||||
|
if (name == HTML::AttributeNames::color) {
|
||||||
|
if (auto parsed_value = parse_legacy_color_value(value); parsed_value.has_value()) {
|
||||||
|
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Color, CSS::CSSColorValue::create_from_color(*parsed_value));
|
||||||
|
}
|
||||||
|
}
|
||||||
// https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:maps-to-the-dimension-property
|
// https://html.spec.whatwg.org/multipage/rendering.html#the-hr-element-2:maps-to-the-dimension-property
|
||||||
if (name == HTML::AttributeNames::width) {
|
if (name == HTML::AttributeNames::width) {
|
||||||
if (auto parsed_value = parse_dimension_value(value)) {
|
if (auto parsed_value = parse_dimension_value(value)) {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset=utf-8>
|
||||||
|
<style>
|
||||||
|
.hr {
|
||||||
|
color: gray;
|
||||||
|
border-style: inset;
|
||||||
|
border-width: 1px;
|
||||||
|
margin: 0.5em auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.green {
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-inset {
|
||||||
|
border-style: solid;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<div class='hr'></div>
|
||||||
|
<div class='hr no-inset'></div>
|
||||||
|
<div class='hr no-inset'></div>
|
||||||
|
<div class='hr green no-inset'></div>
|
|
@ -0,0 +1,7 @@
|
||||||
|
<!doctype html>
|
||||||
|
<meta charset=utf-8>
|
||||||
|
<link rel=match href="../../../../../../expected/wpt-import/html/rendering/non-replaced-elements/the-hr-element-0/color-ref.html">
|
||||||
|
<hr>
|
||||||
|
<hr color="">
|
||||||
|
<hr color=transparent>
|
||||||
|
<hr color=green>
|
Loading…
Add table
Add a link
Reference in a new issue