summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShannon Booth <shannon.ml.booth@gmail.com>2023-05-28 15:06:12 +1200
committerAndreas Kling <kling@serenityos.org>2023-05-28 13:24:37 +0200
commit500552df5415291e486f517881d7785d7080df73 (patch)
tree078cafe71fa43a038ca6a9eb1746147c68ed5166
parentbc54560e5942c9ff4b9049c034ad09a9f8446fb6 (diff)
downloadserenity-500552df5415291e486f517881d7785d7080df73.zip
LibWeb: Apply rules for parsing a legacy color value
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLBodyElement.cpp16
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLFontElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMarqueeElement.cpp4
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp3
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp3
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 <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)) {
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 <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());
}
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 <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());
}
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;