From 8fb979148dccbbad148ae2b7dd66496044ca3b22 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 4 Oct 2019 21:14:59 +0200 Subject: [PATCH] LibHTML: Add support for This was pleasantly trivial to implement with the new support for presentational hints. :^) --- Libraries/LibHTML/DOM/HTMLFontElement.cpp | 23 +++++++++++++++++++++++ Libraries/LibHTML/DOM/HTMLFontElement.h | 11 +++++++++++ Libraries/LibHTML/Makefile.shared | 1 + Libraries/LibHTML/Parser/HTMLParser.cpp | 5 ++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Libraries/LibHTML/DOM/HTMLFontElement.cpp create mode 100644 Libraries/LibHTML/DOM/HTMLFontElement.h diff --git a/Libraries/LibHTML/DOM/HTMLFontElement.cpp b/Libraries/LibHTML/DOM/HTMLFontElement.cpp new file mode 100644 index 0000000000..56ff2e8848 --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLFontElement.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +HTMLFontElement::HTMLFontElement(Document& document, const String& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLFontElement::~HTMLFontElement() +{ +} + +void HTMLFontElement::apply_presentational_hints(StyleProperties& style) const +{ + for_each_attribute([&](auto& name, auto& value) { + if (name == "color") { + auto color = Color::from_string(value); + if (color.has_value()) + style.set_property("color", ColorStyleValue::create(color.value())); + } + }); +} diff --git a/Libraries/LibHTML/DOM/HTMLFontElement.h b/Libraries/LibHTML/DOM/HTMLFontElement.h new file mode 100644 index 0000000000..b8bdb863ca --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLFontElement.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +class HTMLFontElement : public HTMLElement { +public: + HTMLFontElement(Document&, const String& tag_name); + virtual ~HTMLFontElement() override; + + virtual void apply_presentational_hints(StyleProperties&) const override; +}; diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared index 3dc2a55276..3427f2bd06 100644 --- a/Libraries/LibHTML/Makefile.shared +++ b/Libraries/LibHTML/Makefile.shared @@ -11,6 +11,7 @@ LIBHTML_OBJS = \ DOM/HTMLStyleElement.o \ DOM/HTMLTitleElement.o \ DOM/HTMLBodyElement.o \ + DOM/HTMLFontElement.o \ DOM/Document.o \ DOM/Text.o \ CSS/Selector.o \ diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp index 7c5e568fd8..4d48f0b82e 100644 --- a/Libraries/LibHTML/Parser/HTMLParser.cpp +++ b/Libraries/LibHTML/Parser/HTMLParser.cpp @@ -3,8 +3,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -26,6 +27,8 @@ static NonnullRefPtr create_element(Document& document, const String& t return adopt(*new HTMLHeadElement(document, tag_name)); if (lowercase_tag_name == "body") return adopt(*new HTMLBodyElement(document, tag_name)); + if (lowercase_tag_name == "font") + return adopt(*new HTMLFontElement(document, tag_name)); if (lowercase_tag_name == "hr") return adopt(*new HTMLHRElement(document, tag_name)); if (lowercase_tag_name == "style")