1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:37:35 +00:00

LibWeb+WebContent: Add set_preferred_color_scheme IPC call

This allows the owner of a WebView to override whether to use a dark
theme or not, instead of just using the system theme's IsDark property.
This commit is contained in:
Sam Atkins 2021-10-26 17:00:10 +01:00 committed by Linus Groh
parent c8550da9c5
commit 53edaa3b26
11 changed files with 44 additions and 0 deletions

View file

@ -51,6 +51,13 @@ String InProcessWebView::selected_text() const
return page().focused_context().selected_text();
}
void InProcessWebView::set_preferred_color_scheme(CSS::PreferredColorScheme color_scheme)
{
m_preferred_color_scheme = color_scheme;
if (auto* document = page().top_level_browsing_context().active_document())
document->invalidate_style();
}
void InProcessWebView::page_did_layout()
{
VERIFY(layout_root());

View file

@ -40,6 +40,7 @@ public:
AK::URL url() const;
void set_preferred_color_scheme(CSS::PreferredColorScheme);
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
String selected_text() const;
@ -65,6 +66,7 @@ private:
// ^Web::PageClient
virtual Gfx::Palette palette() const override { return GUI::AbstractScrollableWidget::palette(); }
virtual Gfx::IntRect screen_rect() const override { return GUI::Desktop::the().rect(); }
virtual CSS::PreferredColorScheme preferred_color_scheme() const override { return m_preferred_color_scheme; }
virtual void page_did_change_title(const String&) override;
virtual void page_did_set_document_in_top_level_browsing_context(DOM::Document*) override;
virtual void page_did_start_loading(const AK::URL&) override;
@ -95,6 +97,7 @@ private:
bool m_should_show_line_box_borders { false };
NonnullOwnPtr<Page> m_page;
CSS::PreferredColorScheme m_preferred_color_scheme { CSS::PreferredColorScheme::Auto };
};
}

View file

@ -489,4 +489,9 @@ void OutOfProcessWebView::set_content_filters(Vector<String> filters)
client().async_set_content_filters(filters);
}
void OutOfProcessWebView::set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme)
{
client().async_set_preferred_color_scheme(color_scheme);
}
}

View file

@ -9,6 +9,7 @@
#include <AK/URL.h>
#include <LibGUI/AbstractScrollableWidget.h>
#include <LibGUI/Widget.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/WebViewHooks.h>
namespace Web {
@ -52,6 +53,7 @@ public:
String dump_layout_tree();
void set_content_filters(Vector<String>);
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);

View file

@ -56,6 +56,11 @@ Gfx::IntRect Page::screen_rect() const
return m_client.screen_rect();
}
CSS::PreferredColorScheme Page::preferred_color_scheme() const
{
return m_client.preferred_color_scheme();
}
bool Page::handle_mousewheel(const Gfx::IntPoint& position, unsigned button, unsigned modifiers, int wheel_delta)
{
return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta);

View file

@ -16,6 +16,7 @@
#include <LibGfx/Forward.h>
#include <LibGfx/Palette.h>
#include <LibGfx/StandardCursor.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/Forward.h>
namespace Web {
@ -56,6 +57,7 @@ public:
Gfx::Palette palette() const;
Gfx::IntRect screen_rect() const;
CSS::PreferredColorScheme preferred_color_scheme() const;
bool is_same_origin_policy_enabled() const { return m_same_origin_policy_enabled; }
void set_same_origin_policy_enabled(bool b) { m_same_origin_policy_enabled = b; }
@ -74,6 +76,7 @@ class PageClient {
public:
virtual Gfx::Palette palette() const = 0;
virtual Gfx::IntRect screen_rect() const = 0;
virtual CSS::PreferredColorScheme preferred_color_scheme() const = 0;
virtual void page_did_set_document_in_top_level_browsing_context(DOM::Document*) { }
virtual void page_did_change_title(const String&) { }
virtual void page_did_start_loading(const AK::URL&) { }