mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
LibWeb: Apply rules for parsing a legacy color value
This commit is contained in:
parent
bc54560e59
commit
500552df54
5 changed files with 21 additions and 9 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/HTML/HTMLBodyElement.h>
|
#include <LibWeb/HTML/HTMLBodyElement.h>
|
||||||
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
#include <LibWeb/HTML/Window.h>
|
#include <LibWeb/HTML/Window.h>
|
||||||
#include <LibWeb/Layout/Node.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) {
|
for_each_attribute([&](auto& name, auto& value) {
|
||||||
if (name.equals_ignoring_ascii_case("bgcolor"sv)) {
|
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())
|
if (color.has_value())
|
||||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
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)) {
|
} 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())
|
if (color.has_value())
|
||||||
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
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)) {
|
} 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);
|
HTMLElement::parse_attribute(name, value);
|
||||||
if (name.equals_ignoring_ascii_case("link"sv)) {
|
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())
|
if (color.has_value())
|
||||||
document().set_link_color(color.value());
|
document().set_link_color(color.value());
|
||||||
} else if (name.equals_ignoring_ascii_case("alink"sv)) {
|
} 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())
|
if (color.has_value())
|
||||||
document().set_active_link_color(color.value());
|
document().set_active_link_color(color.value());
|
||||||
} else if (name.equals_ignoring_ascii_case("vlink"sv)) {
|
} 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())
|
if (color.has_value())
|
||||||
document().set_visited_link_color(color.value());
|
document().set_visited_link_color(color.value());
|
||||||
} else if (name.equals_ignoring_ascii_case("background"sv)) {
|
} else if (name.equals_ignoring_ascii_case("background"sv)) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <LibWeb/CSS/StyleProperties.h>
|
#include <LibWeb/CSS/StyleProperties.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||||
#include <LibWeb/HTML/HTMLFontElement.h>
|
#include <LibWeb/HTML/HTMLFontElement.h>
|
||||||
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -30,7 +31,8 @@ void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) co
|
||||||
{
|
{
|
||||||
for_each_attribute([&](auto& name, auto& value) {
|
for_each_attribute([&](auto& name, auto& value) {
|
||||||
if (name.equals_ignoring_ascii_case("color"sv)) {
|
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())
|
if (color.has_value())
|
||||||
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <LibWeb/CSS/StyleProperties.h>
|
#include <LibWeb/CSS/StyleProperties.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||||
#include <LibWeb/HTML/HTMLMarqueeElement.h>
|
#include <LibWeb/HTML/HTMLMarqueeElement.h>
|
||||||
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
@ -31,7 +32,8 @@ void HTMLMarqueeElement::apply_presentational_hints(CSS::StyleProperties& style)
|
||||||
HTMLElement::apply_presentational_hints(style);
|
HTMLElement::apply_presentational_hints(style);
|
||||||
for_each_attribute([&](auto& name, auto& value) {
|
for_each_attribute([&](auto& name, auto& value) {
|
||||||
if (name == HTML::AttributeNames::bgcolor) {
|
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())
|
if (color.has_value())
|
||||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& styl
|
||||||
{
|
{
|
||||||
for_each_attribute([&](auto& name, auto& value) {
|
for_each_attribute([&](auto& name, auto& value) {
|
||||||
if (name == HTML::AttributeNames::bgcolor) {
|
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())
|
if (color.has_value())
|
||||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -55,7 +55,8 @@ void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) c
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (name == HTML::AttributeNames::bgcolor) {
|
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())
|
if (color.has_value())
|
||||||
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()).release_value_but_fixme_should_propagate_errors());
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue