From fd64e97c8afb46b5e152bd18d0376c2094c9f3f3 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 13 Jan 2020 20:33:15 +0100 Subject: [PATCH] LibDraw+LibHTML: Make link colors themeable Add "Link", "ActiveLink" and "VisitedLink" colors to the system theme definition, and implement support for them in LibHTML. Note that takes precedence over the system colors. Author style also takes precedence, since we only fetch the system color in case the CSS color is -libhtml-link. --- Base/res/themes/Dark.ini | 3 +++ Base/res/themes/Default.ini | 3 +++ Base/res/themes/Hotdog Stand.ini | 3 +++ Base/res/themes/Xmas.ini | 3 +++ Libraries/LibDraw/Palette.h | 4 ++++ Libraries/LibDraw/SystemTheme.cpp | 3 +++ Libraries/LibDraw/SystemTheme.h | 3 +++ Libraries/LibHTML/DOM/Document.cpp | 28 ++++++++++++++++++++++++++++ Libraries/LibHTML/DOM/Document.h | 12 ++++++------ 9 files changed, 56 insertions(+), 6 deletions(-) diff --git a/Base/res/themes/Dark.ini b/Base/res/themes/Dark.ini index 2130d03681b81af6916f6fda4851f8046e06f218..c74193e9a3db9dc07686e0d00e59c404bb07e4f8 100644 --- a/Base/res/themes/Dark.ini +++ b/Base/res/themes/Dark.ini @@ -31,3 +31,6 @@ Selection=#14141a SelectionText=white RubberBandFill=#8080803c RubberBandBorder=black +Link=#88c +ActiveLink=#c88 +VisitedLink=#c8c diff --git a/Base/res/themes/Default.ini b/Base/res/themes/Default.ini index da38dec0e1cb6eb8beddb6bb2fba1a40e41265f5..fff9f012cc2fb9059a267e003d94845fd1b5aeca 100644 --- a/Base/res/themes/Default.ini +++ b/Base/res/themes/Default.ini @@ -31,3 +31,6 @@ Selection=#84351a SelectionText=white RubberBandFill=#f4ca9e3c RubberBandBorder=#6e2209 +Link=blue +ActiveLink=red +VisitedLink=magenta diff --git a/Base/res/themes/Hotdog Stand.ini b/Base/res/themes/Hotdog Stand.ini index 65856c18230a7e1895a7e9d6c872afd927184f8b..7d879456b70e0ed06552ee8fb19b99123bbf3a33 100644 --- a/Base/res/themes/Hotdog Stand.ini +++ b/Base/res/themes/Hotdog Stand.ini @@ -31,3 +31,6 @@ Selection=black SelectionText=white RubberBandFill=#fad7653c RubberBandBorder=#f4ca9e +Link=blue +ActiveLink=red +VisitedLink=magenta diff --git a/Base/res/themes/Xmas.ini b/Base/res/themes/Xmas.ini index 7f19071cfc47ef592ae1c8882ed62222d3510751..20b27985b38c25c6efa545a421f6bcc3a59dee17 100644 --- a/Base/res/themes/Xmas.ini +++ b/Base/res/themes/Xmas.ini @@ -31,3 +31,6 @@ Selection=#84351a SelectionText=white RubberBandFill=#0466033c RubberBandBorder=#76943c +Link=blue +ActiveLink=red +VisitedLink=magenta diff --git a/Libraries/LibDraw/Palette.h b/Libraries/LibDraw/Palette.h index 52d375fdec2a95b1099b6d296c2c27f25f6b531a..501e59e82d3d906edd2a3623fd8060ced9387127 100644 --- a/Libraries/LibDraw/Palette.h +++ b/Libraries/LibDraw/Palette.h @@ -63,6 +63,10 @@ public: Color rubber_band_fill() const { return color(ColorRole::RubberBandFill); } Color rubber_band_border() const { return color(ColorRole::RubberBandBorder); } + Color link() const { return color(ColorRole::Link); } + Color active_link() const { return color(ColorRole::ActiveLink); } + Color visited_link() const { return color(ColorRole::VisitedLink); } + Color color(ColorRole role) const { return m_impl->color(role); } void set_color(ColorRole, Color); diff --git a/Libraries/LibDraw/SystemTheme.cpp b/Libraries/LibDraw/SystemTheme.cpp index f6a0ba508be42723b20aa2f595244ae2d37bf2d0..e352841baad3c41a6d5dddbac183aa44c63b8a90 100644 --- a/Libraries/LibDraw/SystemTheme.cpp +++ b/Libraries/LibDraw/SystemTheme.cpp @@ -74,6 +74,9 @@ RefPtr load_system_theme(const String& path) DO_COLOR(MenuSelectionText); DO_COLOR(RubberBandFill); DO_COLOR(RubberBandBorder); + DO_COLOR(Link); + DO_COLOR(ActiveLink); + DO_COLOR(VisitedLink); buffer->seal(); buffer->share_globally(); diff --git a/Libraries/LibDraw/SystemTheme.h b/Libraries/LibDraw/SystemTheme.h index 74d3d90c4484fbd068ad887468e7f9bd2479d849..d1528dfd37300c76b37c4e90f0f755b7444fdcbf 100644 --- a/Libraries/LibDraw/SystemTheme.h +++ b/Libraries/LibDraw/SystemTheme.h @@ -38,6 +38,9 @@ enum class ColorRole { SelectionText, RubberBandFill, RubberBandBorder, + Link, + ActiveLink, + VisitedLink, __Count, diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp index 80acf9713a56851666143f2c4da94e39e8e55699..dbaed1013da1d2d819b3e61daf017736170430f7 100644 --- a/Libraries/LibHTML/DOM/Document.cpp +++ b/Libraries/LibHTML/DOM/Document.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -275,3 +276,30 @@ Vector Document::get_elements_by_name(const String& name) const }); return elements; } + +Color Document::link_color() const +{ + if (m_link_color.has_value()) + return m_link_color.value(); + if (!frame()) + return Color::Blue; + return frame()->html_view()->palette().link(); +} + +Color Document::active_link_color() const +{ + if (m_active_link_color.has_value()) + return m_active_link_color.value(); + if (!frame()) + return Color::Red; + return frame()->html_view()->palette().active_link(); +} + +Color Document::visited_link_color() const +{ + if (m_visited_link_color.has_value()) + return m_visited_link_color.value(); + if (!frame()) + return Color::Magenta; + return frame()->html_view()->palette().visited_link(); +} diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h index 022be5ab0653af7c30d27b1042f8530bdc4c8d7e..c47ecf583c96b8aeba690dd4cb2950427e447dfb 100644 --- a/Libraries/LibHTML/DOM/Document.h +++ b/Libraries/LibHTML/DOM/Document.h @@ -64,13 +64,13 @@ public: Color background_color(const Palette&) const; RefPtr background_image() const; - Color link_color() const { return m_link_color; } + Color link_color() const; void set_link_color(Color); - Color active_link_color() const { return m_active_link_color; } + Color active_link_color() const; void set_active_link_color(Color); - Color visited_link_color() const { return m_visited_link_color; } + Color visited_link_color() const; void set_visited_link_color(Color); void layout(); @@ -105,9 +105,9 @@ private: RefPtr m_layout_root; - Color m_link_color { Color::Blue }; - Color m_active_link_color { Color::Red }; - Color m_visited_link_color { Color::Magenta }; + Optional m_link_color; + Optional m_active_link_color; + Optional m_visited_link_color; RefPtr m_style_update_timer;