[epiphany] Reader mode: Immediately apply settings when they change
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Reader mode: Immediately apply settings when they change
- Date: Thu, 30 Aug 2018 16:22:07 +0000 (UTC)
commit 7056faabb990ea29520ec02d749bd5166576dff2
Author: Adrian Perez de Castro <aperez igalia com>
Date: Thu Aug 9 00:17:14 2018 +0300
Reader mode: Immediately apply settings when they change
This is done by handling te GSettings::changed signal for the settings
that affect the reader view styling, and running a JavaScript snippet
which assignd the newly chosen settings to "document.body.className".
embed/ephy-web-view.c | 74 ++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 56 insertions(+), 18 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 3283e9fdf..6b7fbbc5a 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2688,6 +2688,54 @@ script_dialog_cb (WebKitWebView *web_view,
return TRUE;
}
+static const char *
+enum_nick (GType enum_type,
+ int value)
+{
+ GEnumClass *enum_class;
+ const GEnumValue *enum_value;
+ const char *nick = NULL;
+
+ enum_class = g_type_class_ref (enum_type);
+ enum_value = g_enum_get_value (enum_class, value);
+ if (enum_value)
+ nick = enum_value->value_nick;
+
+ g_type_class_unref (enum_class);
+ return nick;
+}
+
+static void
+reader_setting_changed_cb (GSettings *settings,
+ gchar *key,
+ EphyWebView *web_view)
+{
+ const gchar *font_style;
+ const gchar *color_scheme;
+ gchar *js_snippet;
+
+ if (!web_view->reader_active)
+ return;
+
+ font_style = enum_nick (EPHY_TYPE_PREFS_READER_FONT_STYLE,
+ g_settings_get_enum (settings,
+ EPHY_PREFS_READER_FONT_STYLE));
+ color_scheme = enum_nick (EPHY_TYPE_PREFS_READER_COLOR_SCHEME,
+ g_settings_get_enum (settings,
+ EPHY_PREFS_READER_COLOR_SCHEME));
+
+ js_snippet = g_strdup_printf ("document.body.className = '%s %s'",
+ font_style,
+ color_scheme);
+ webkit_web_view_run_javascript_in_world (WEBKIT_WEB_VIEW (web_view),
+ js_snippet,
+ ephy_embed_shell_get_guid (ephy_embed_shell_get_default ()),
+ NULL,
+ NULL,
+ NULL);
+ g_free (js_snippet);
+}
+
static void
ephy_web_view_init (EphyWebView *web_view)
{
@@ -2701,6 +2749,14 @@ ephy_web_view_init (EphyWebView *web_view)
web_view->history_service = ephy_embed_shell_get_global_history_service (ephy_embed_shell_get_default ());
web_view->history_service_cancellable = g_cancellable_new ();
+ g_signal_connect (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_FONT_STYLE,
+ G_CALLBACK (reader_setting_changed_cb),
+ web_view);
+
+ g_signal_connect (EPHY_SETTINGS_READER, "changed::" EPHY_PREFS_READER_COLOR_SCHEME,
+ G_CALLBACK (reader_setting_changed_cb),
+ web_view);
+
g_signal_connect (web_view, "decide-policy",
G_CALLBACK (decide_policy_cb),
NULL);
@@ -3631,24 +3687,6 @@ ephy_web_view_set_visit_type (EphyWebView *view, EphyHistoryPageVisitType visit_
}
-static const char *
-enum_nick (GType enum_type,
- int value)
-{
- GEnumClass *enum_class;
- const GEnumValue *enum_value;
- const char *nick = NULL;
-
- enum_class = g_type_class_ref (enum_type);
- enum_value = g_enum_get_value (enum_class, value);
- if (enum_value)
- nick = enum_value->value_nick;
-
- g_type_class_unref (enum_class);
- return nick;
-}
-
-
/**
* ephy_web_view_toggle_reader_mode:
* @view: an #EphyWebView
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]