LibWeb: Apply rules for parsing a legacy color value

This commit is contained in:
Shannon Booth 2023-05-28 15:06:12 +12:00 committed by Andreas Kling
parent bc54560e59
commit 500552df54
Notes: sideshowbarker 2024-07-17 01:27:18 +09:00
5 changed files with 21 additions and 9 deletions

View file

@ -9,6 +9,7 @@
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLBodyElement.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Layout/Node.h>
@ -33,11 +34,13 @@ void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) co
{
for_each_attribute([&](auto& name, auto& value) {
if (name.equals_ignoring_ascii_case("bgcolor"sv)) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
} else if (name.equals_ignoring_ascii_case("text"sv)) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-2
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
} else if (name.equals_ignoring_ascii_case("background"sv)) {
@ -51,15 +54,18 @@ void HTMLBodyElement::parse_attribute(DeprecatedFlyString const& name, Deprecate
{
HTMLElement::parse_attribute(name, value);
if (name.equals_ignoring_ascii_case("link"sv)) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-3
auto color = parse_legacy_color_value(value);
if (color.has_value())
document().set_link_color(color.value());
} else if (name.equals_ignoring_ascii_case("alink"sv)) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-5
auto color = parse_legacy_color_value(value);
if (color.has_value())
document().set_active_link_color(color.value());
} else if (name.equals_ignoring_ascii_case("vlink"sv)) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#the-page:rules-for-parsing-a-legacy-colour-value-4
auto color = parse_legacy_color_value(value);
if (color.has_value())
document().set_visited_link_color(color.value());
} else if (name.equals_ignoring_ascii_case("background"sv)) {

View file

@ -8,6 +8,7 @@
#include <LibWeb/CSS/StyleProperties.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/HTML/HTMLFontElement.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
namespace Web::HTML {
@ -30,7 +31,8 @@ void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) co
{
for_each_attribute([&](auto& name, auto& value) {
if (name.equals_ignoring_ascii_case("color"sv)) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
}

View file

@ -8,6 +8,7 @@
#include <LibWeb/CSS/StyleProperties.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/HTML/HTMLMarqueeElement.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
namespace Web::HTML {
@ -31,7 +32,8 @@ void HTMLMarqueeElement::apply_presentational_hints(CSS::StyleProperties& style)
HTMLElement::apply_presentational_hints(style);
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::bgcolor) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#the-marquee-element-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
}

View file

@ -33,7 +33,8 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
{
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::bgcolor) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
return;

View file

@ -55,7 +55,8 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
return;
}
if (name == HTML::AttributeNames::bgcolor) {
auto color = Color::from_string(value);
// https://html.spec.whatwg.org/multipage/rendering.html#tables-2:rules-for-parsing-a-legacy-colour-value
auto color = parse_legacy_color_value(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
return;