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 <body link="foo" alink="bar" vlink="baz"> 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.
This commit is contained in:
Andreas Kling 2020-01-13 20:33:15 +01:00
parent 3b2f20ed4d
commit fd64e97c8a
Notes: sideshowbarker 2024-07-19 10:04:18 +09:00
9 changed files with 56 additions and 6 deletions

View file

@ -31,3 +31,6 @@ Selection=#14141a
SelectionText=white SelectionText=white
RubberBandFill=#8080803c RubberBandFill=#8080803c
RubberBandBorder=black RubberBandBorder=black
Link=#88c
ActiveLink=#c88
VisitedLink=#c8c

View file

@ -31,3 +31,6 @@ Selection=#84351a
SelectionText=white SelectionText=white
RubberBandFill=#f4ca9e3c RubberBandFill=#f4ca9e3c
RubberBandBorder=#6e2209 RubberBandBorder=#6e2209
Link=blue
ActiveLink=red
VisitedLink=magenta

View file

@ -31,3 +31,6 @@ Selection=black
SelectionText=white SelectionText=white
RubberBandFill=#fad7653c RubberBandFill=#fad7653c
RubberBandBorder=#f4ca9e RubberBandBorder=#f4ca9e
Link=blue
ActiveLink=red
VisitedLink=magenta

View file

@ -31,3 +31,6 @@ Selection=#84351a
SelectionText=white SelectionText=white
RubberBandFill=#0466033c RubberBandFill=#0466033c
RubberBandBorder=#76943c RubberBandBorder=#76943c
Link=blue
ActiveLink=red
VisitedLink=magenta

View file

@ -63,6 +63,10 @@ public:
Color rubber_band_fill() const { return color(ColorRole::RubberBandFill); } Color rubber_band_fill() const { return color(ColorRole::RubberBandFill); }
Color rubber_band_border() const { return color(ColorRole::RubberBandBorder); } 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); } Color color(ColorRole role) const { return m_impl->color(role); }
void set_color(ColorRole, Color); void set_color(ColorRole, Color);

View file

@ -74,6 +74,9 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
DO_COLOR(MenuSelectionText); DO_COLOR(MenuSelectionText);
DO_COLOR(RubberBandFill); DO_COLOR(RubberBandFill);
DO_COLOR(RubberBandBorder); DO_COLOR(RubberBandBorder);
DO_COLOR(Link);
DO_COLOR(ActiveLink);
DO_COLOR(VisitedLink);
buffer->seal(); buffer->seal();
buffer->share_globally(); buffer->share_globally();

View file

@ -38,6 +38,9 @@ enum class ColorRole {
SelectionText, SelectionText,
RubberBandFill, RubberBandFill,
RubberBandBorder, RubberBandBorder,
Link,
ActiveLink,
VisitedLink,
__Count, __Count,

View file

@ -12,6 +12,7 @@
#include <LibHTML/DOM/HTMLHtmlElement.h> #include <LibHTML/DOM/HTMLHtmlElement.h>
#include <LibHTML/DOM/HTMLTitleElement.h> #include <LibHTML/DOM/HTMLTitleElement.h>
#include <LibHTML/Frame.h> #include <LibHTML/Frame.h>
#include <LibHTML/HtmlView.h>
#include <LibHTML/Layout/LayoutDocument.h> #include <LibHTML/Layout/LayoutDocument.h>
#include <LibHTML/Layout/LayoutTreeBuilder.h> #include <LibHTML/Layout/LayoutTreeBuilder.h>
#include <stdio.h> #include <stdio.h>
@ -275,3 +276,30 @@ Vector<const Element*> Document::get_elements_by_name(const String& name) const
}); });
return elements; 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();
}

View file

@ -64,13 +64,13 @@ public:
Color background_color(const Palette&) const; Color background_color(const Palette&) const;
RefPtr<GraphicsBitmap> background_image() const; RefPtr<GraphicsBitmap> background_image() const;
Color link_color() const { return m_link_color; } Color link_color() const;
void set_link_color(Color); 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); 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 set_visited_link_color(Color);
void layout(); void layout();
@ -105,9 +105,9 @@ private:
RefPtr<LayoutDocument> m_layout_root; RefPtr<LayoutDocument> m_layout_root;
Color m_link_color { Color::Blue }; Optional<Color> m_link_color;
Color m_active_link_color { Color::Red }; Optional<Color> m_active_link_color;
Color m_visited_link_color { Color::Magenta }; Optional<Color> m_visited_link_color;
RefPtr<CTimer> m_style_update_timer; RefPtr<CTimer> m_style_update_timer;