From 500552df5415291e486f517881d7785d7080df73 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 28 May 2023 15:06:12 +1200 Subject: LibWeb: Apply rules for parsing a legacy color value --- Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp | 16 +++++++++++----- Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp | 4 +++- Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp | 4 +++- Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp | 3 ++- Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp | 3 ++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp index e206ee08fe..096a5bb1b1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -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)) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp index 9eefb37610..a02322129f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp @@ -8,6 +8,7 @@ #include #include #include +#include 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()); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp index 573bf8b637..5f9fe1d9d1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp @@ -8,6 +8,7 @@ #include #include #include +#include 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()); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index 7a7b759f34..fa11cbf663 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -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; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index c538dc85bf..e5344c15e2 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -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; -- cgit v1.2.3