diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-10-06 10:11:54 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-06 10:11:54 +0200 |
commit | 83a6474d82a6ea516ab67eedabca1fe1f1dc29a3 (patch) | |
tree | f72ae20d4249fcb63f84c219b0a2217c499fe7e0 /Libraries/LibHTML | |
parent | 772718b8d8d543082bc29d326b874573aa12e351 (diff) | |
download | serenity-83a6474d82a6ea516ab67eedabca1fe1f1dc29a3.zip |
LibHTML: Parse link, alink and vlink in <body> and pass to Document
This patch adds HTMLBodyElement::parse_attribute() where we extract the
link colors and stash them away on Document.
Diffstat (limited to 'Libraries/LibHTML')
-rw-r--r-- | Libraries/LibHTML/DOM/Document.cpp | 17 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/Document.h | 13 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLBodyElement.cpp | 18 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLBodyElement.h | 1 |
4 files changed, 48 insertions, 1 deletions
diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp index eaf005eb2a..c884a00dd1 100644 --- a/Libraries/LibHTML/DOM/Document.cpp +++ b/Libraries/LibHTML/DOM/Document.cpp @@ -99,7 +99,7 @@ Color Document::background_color() const if (!background_color.has_value() || !background_color.value()->is_color()) return Color::White; - return background_color.value()->to_color(); + return background_color.value()->to_color(*this); } URL Document::complete_url(const String& string) const @@ -130,3 +130,18 @@ RefPtr<LayoutNode> Document::create_layout_node(const StyleResolver&, const Styl { return adopt(*new LayoutDocument(*this, StyleProperties::create())); } + +void Document::set_link_color(Color color) +{ + m_link_color = color; +} + +void Document::set_active_link_color(Color color) +{ + m_active_link_color = color; +} + +void Document::set_visited_link_color(Color color) +{ + m_visited_link_color = color; +} diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h index 7a13f813c6..6124736571 100644 --- a/Libraries/LibHTML/DOM/Document.h +++ b/Libraries/LibHTML/DOM/Document.h @@ -54,6 +54,15 @@ public: Color background_color() const; + Color link_color() const { return m_link_color; } + void set_link_color(Color); + + Color active_link_color() const { return m_active_link_color; } + void set_active_link_color(Color); + + Color visited_link_color() const { return m_visited_link_color; } + void set_visited_link_color(Color); + private: virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_properties) const override; @@ -62,4 +71,8 @@ private: RefPtr<Node> m_hovered_node; WeakPtr<Frame> m_frame; URL m_url; + + Color m_link_color { Color::Blue }; + Color m_active_link_color { Color::Red }; + Color m_visited_link_color { Color::Magenta }; }; diff --git a/Libraries/LibHTML/DOM/HTMLBodyElement.cpp b/Libraries/LibHTML/DOM/HTMLBodyElement.cpp index e993ce470e..14a0b9b234 100644 --- a/Libraries/LibHTML/DOM/HTMLBodyElement.cpp +++ b/Libraries/LibHTML/DOM/HTMLBodyElement.cpp @@ -1,5 +1,6 @@ #include <LibHTML/CSS/StyleProperties.h> #include <LibHTML/CSS/StyleValue.h> +#include <LibHTML/DOM/Document.h> #include <LibHTML/DOM/HTMLBodyElement.h> HTMLBodyElement::HTMLBodyElement(Document& document, const String& tag_name) @@ -25,3 +26,20 @@ void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const } }); } + +void HTMLBodyElement::parse_attribute(const String& name, const String& value) +{ + if (name == "link") { + auto color = Color::from_string(value); + if (color.has_value()) + document().set_link_color(color.value()); + } else if (name == "alink") { + auto color = Color::from_string(value); + if (color.has_value()) + document().set_active_link_color(color.value()); + } else if (name == "vlink") { + auto color = Color::from_string(value); + if (color.has_value()) + document().set_visited_link_color(color.value()); + } +} diff --git a/Libraries/LibHTML/DOM/HTMLBodyElement.h b/Libraries/LibHTML/DOM/HTMLBodyElement.h index 2c3a5b3f62..b00a12fc9d 100644 --- a/Libraries/LibHTML/DOM/HTMLBodyElement.h +++ b/Libraries/LibHTML/DOM/HTMLBodyElement.h @@ -7,5 +7,6 @@ public: HTMLBodyElement(Document&, const String& tag_name); virtual ~HTMLBodyElement() override; + virtual void parse_attribute(const String&, const String&) override; virtual void apply_presentational_hints(StyleProperties&) const override; }; |