[evolution] Add an option to specify minimum font size for WebKitGTK
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Add an option to specify minimum font size for WebKitGTK
- Date: Fri, 5 Jun 2020 08:49:13 +0000 (UTC)
commit cc6c26ec7c1736ac4f654afa2978226ce168bd91
Author: Milan Crha <mcrha redhat com>
Date: Fri Jun 5 10:49:17 2020 +0200
Add an option to specify minimum font size for WebKitGTK
Evolution used to force some minimum font size in the code, but it
was removed to be able to properly show <small>, <xsmall> and such
texts in the web views. Unfortunately, it also means that if the sender
keeps such small font it can be hard to read to the recipient, thus
let's add the option, thus the user can set it up to his/her needs.
data/org.gnome.evolution.shell.gschema.xml.in | 5 ++
src/e-util/e-web-view.c | 89 ++++++++++++++++++++++++++-
src/e-util/e-web-view.h | 5 ++
src/mail/mail-config.ui | 88 +++++++++++++++++++-------
src/modules/mail/em-mailer-prefs.c | 10 +++
src/modules/webkit-editor/e-webkit-editor.c | 63 ++++++++++++++++++-
6 files changed, 234 insertions(+), 26 deletions(-)
---
diff --git a/data/org.gnome.evolution.shell.gschema.xml.in b/data/org.gnome.evolution.shell.gschema.xml.in
index e982c9f7eb..2512a02169 100644
--- a/data/org.gnome.evolution.shell.gschema.xml.in
+++ b/data/org.gnome.evolution.shell.gschema.xml.in
@@ -130,6 +130,11 @@
<_summary>Prefix of the URI to use to search the web with selected text.</_summary>
<_description>The prefix of a URL to be used for searches on the web. The actual text selection is
escaped and appended to this string. The URI should start with https://.</_description>
</key>
+ <key name="webkit-minimum-font-size" type="i">
+ <default>0</default>
+ <_summary>Minimum font size to be used by WebKitGTK</_summary>
+ <_description>The minimum font size in pixels used to display text in WebKitGTK. This setting controls
the absolute smallest size. Values other than 0 can potentially break page layouts. Negative values are
treated as 0.</_description>
+ </key>
<child name="window" schema="org.gnome.evolution.window"/>
</schema>
</schemalist>
diff --git a/src/e-util/e-web-view.c b/src/e-util/e-web-view.c
index 5c422c641c..b0fd84f078 100644
--- a/src/e-util/e-web-view.c
+++ b/src/e-util/e-web-view.c
@@ -99,6 +99,8 @@ struct _EWebViewPrivate {
gchar *last_popup_iframe_id;
gchar *last_popup_element_id;
gchar *last_popup_link_uri;
+
+ gint minimum_font_size;
};
struct _AsyncContext {
@@ -118,6 +120,7 @@ enum {
PROP_DISABLE_SAVE_TO_DISK,
PROP_HAS_SELECTION,
PROP_NEED_INPUT,
+ PROP_MINIMUM_FONT_SIZE,
PROP_OPEN_PROXY,
PROP_PASTE_TARGET_LIST,
PROP_PRINT_PROXY,
@@ -962,6 +965,12 @@ web_view_set_property (GObject *object,
g_value_get_boolean (value));
return;
+ case PROP_MINIMUM_FONT_SIZE:
+ e_web_view_set_minimum_font_size (
+ E_WEB_VIEW (object),
+ g_value_get_int (value));
+ return;
+
case PROP_OPEN_PROXY:
e_web_view_set_open_proxy (
E_WEB_VIEW (object),
@@ -1034,6 +1043,12 @@ web_view_get_property (GObject *object,
g_value_set_boolean (value, e_web_view_has_selection (E_WEB_VIEW (object)));
return;
+ case PROP_MINIMUM_FONT_SIZE:
+ g_value_set_int (
+ value, e_web_view_get_minimum_font_size (
+ E_WEB_VIEW (object)));
+ return;
+
case PROP_NEED_INPUT:
g_value_set_boolean (
value, e_web_view_get_need_input (
@@ -1500,9 +1515,9 @@ web_view_constructed (GObject *object)
WebKitSettings *web_settings;
WebKitUserContentManager *manager;
EWebView *web_view = E_WEB_VIEW (object);
-#ifndef G_OS_WIN32
GSettings *settings;
+#ifndef G_OS_WIN32
settings = e_util_ref_settings ("org.gnome.desktop.lockdown");
g_settings_bind (
@@ -1518,6 +1533,15 @@ web_view_constructed (GObject *object)
g_object_unref (settings);
#endif
+ settings = e_util_ref_settings ("org.gnome.evolution.shell");
+
+ g_settings_bind (
+ settings, "webkit-minimum-font-size",
+ object, "minimum-font-size",
+ G_SETTINGS_BIND_GET);
+
+ g_clear_object (&settings);
+
g_signal_connect_object (webkit_web_view_get_context (WEBKIT_WEB_VIEW (web_view)),
"initialize-web-extensions",
G_CALLBACK (e_web_view_initialize_web_extensions_cb), web_view, 0);
@@ -2211,6 +2235,16 @@ e_web_view_class_init (EWebViewClass *class)
FALSE,
G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_MINIMUM_FONT_SIZE,
+ g_param_spec_int (
+ "minimum-font-size",
+ "Minimum Font Size",
+ NULL,
+ G_MININT, G_MAXINT, 0,
+ G_PARAM_READWRITE));
+
g_object_class_install_property (
object_class,
PROP_NEED_INPUT,
@@ -3557,7 +3591,9 @@ e_web_view_update_fonts_settings (GSettings *font_settings,
WebKitSettings *
e_web_view_get_default_webkit_settings (void)
{
- return webkit_settings_new_with_settings (
+ WebKitSettings *settings;
+
+ settings = webkit_settings_new_with_settings (
"auto-load-images", TRUE,
"default-charset", "utf-8",
"enable-html5-database", FALSE,
@@ -3572,6 +3608,55 @@ e_web_view_get_default_webkit_settings (void)
"enable-smooth-scrolling", FALSE,
"media-playback-allows-inline", FALSE,
NULL);
+
+ e_web_view_utils_apply_minimum_font_size (settings);
+
+ return settings;
+}
+
+void
+e_web_view_utils_apply_minimum_font_size (WebKitSettings *wk_settings)
+{
+ GSettings *settings;
+ gint value;
+
+ g_return_if_fail (WEBKIT_IS_SETTINGS (wk_settings));
+
+ settings = e_util_ref_settings ("org.gnome.evolution.shell");
+ value = g_settings_get_int (settings, "webkit-minimum-font-size");
+ g_clear_object (&settings);
+
+ if (value < 0)
+ value = 0;
+
+ if (webkit_settings_get_minimum_font_size (wk_settings) != (guint32) value)
+ webkit_settings_set_minimum_font_size (wk_settings, value);
+}
+
+gint
+e_web_view_get_minimum_font_size (EWebView *web_view)
+{
+ g_return_val_if_fail (E_IS_WEB_VIEW (web_view), -1);
+
+ return web_view->priv->minimum_font_size;
+}
+
+void
+e_web_view_set_minimum_font_size (EWebView *web_view,
+ gint pixels)
+{
+ g_return_if_fail (E_IS_WEB_VIEW (web_view));
+
+ if (web_view->priv->minimum_font_size != pixels) {
+ WebKitSettings *wk_settings;
+
+ web_view->priv->minimum_font_size = pixels;
+
+ wk_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (web_view));
+ e_web_view_utils_apply_minimum_font_size (wk_settings);
+
+ g_object_notify (G_OBJECT (web_view), "minimum-font-size");
+ }
}
GCancellable *
diff --git a/src/e-util/e-web-view.h b/src/e-util/e-web-view.h
index 3f50a0434f..1bde0cd00f 100644
--- a/src/e-util/e-web-view.h
+++ b/src/e-util/e-web-view.h
@@ -127,6 +127,11 @@ GtkWidget * e_web_view_new (void);
WebKitSettings *
e_web_view_get_default_webkit_settings
(void);
+void e_web_view_utils_apply_minimum_font_size
+ (WebKitSettings *wk_settings);
+gint e_web_view_get_minimum_font_size(EWebView *web_view);
+void e_web_view_set_minimum_font_size(EWebView *web_view,
+ gint pixels);
GCancellable * e_web_view_get_cancellable (EWebView *web_view);
void e_web_view_register_content_request_for_scheme
(EWebView *web_view,
diff --git a/src/mail/mail-config.ui b/src/mail/mail-config.ui
index c880c2bb4a..7639044267 100644
--- a/src/mail/mail-config.ui
+++ b/src/mail/mail-config.ui
@@ -158,29 +158,8 @@
<property name="page_increment">1</property>
</object>
<object class="GtkAdjustment" id="adjustment2">
- <property name="upper">30000</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="adjustment3">
- <property name="lower">1</property>
- <property name="upper">100</property>
- <property name="value">5</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="adjustment4">
- <property name="upper">65535</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="adjustment5">
- <property name="upper">65535</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="adjustment6">
- <property name="upper">65535</property>
+ <property name="lower">0</property>
+ <property name="upper">1024</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
@@ -1881,6 +1860,69 @@
<property name="y_options"/>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label445">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Minimum Font _Size:</property>
+ <property name="use_underline">True</property>
+ <property name="justify">right</property>
+ <property name="mnemonic_widget">minFontSize</property>
+ <property name="xalign">1</property>
+ </object>
+ <packing>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="minfontsize-hbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkSpinButton" id="minFontSize">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="adjustment">adjustment2</property>
+ <property name="climb_rate">1</property>
+ <property name="digits">0</property>
+ <property name="numeric">True</property>
+ <property name="update_policy">if-valid</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label446">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" comments="Translators: This is
part of 'Minimum Font Size: [ spin button ] (in pixels)'">(in pixels)</property>
+ <property name="use_underline">False</property>
+ <property name="justify">left</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="bottom_attach">3</property>
+ <property name="x_options"/>
+ <property name="y_options"/>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/src/modules/mail/em-mailer-prefs.c b/src/modules/mail/em-mailer-prefs.c
index 2c9bac40a1..3d7b9ac757 100644
--- a/src/modules/mail/em-mailer-prefs.c
+++ b/src/modules/mail/em-mailer-prefs.c
@@ -1790,6 +1790,16 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs,
gtk_container_add (GTK_CONTAINER (prefs), toplevel);
g_object_unref (settings);
+
+ settings = e_util_ref_settings ("org.gnome.evolution.shell");
+
+ widget = e_builder_get_widget (prefs->priv->builder, "minFontSize");
+ g_settings_bind (
+ settings, "webkit-minimum-font-size",
+ widget, "value",
+ G_SETTINGS_BIND_DEFAULT);
+
+ g_object_unref (settings);
}
GtkWidget *
diff --git a/src/modules/webkit-editor/e-webkit-editor.c b/src/modules/webkit-editor/e-webkit-editor.c
index 4bd12bdccd..711acb6a3f 100644
--- a/src/modules/webkit-editor/e-webkit-editor.c
+++ b/src/modules/webkit-editor/e-webkit-editor.c
@@ -70,7 +70,8 @@ enum {
PROP_MAGIC_LINKS,
PROP_MAGIC_SMILEYS,
PROP_UNICODE_SMILEYS,
- PROP_WRAP_QUOTED_TEXT_IN_REPLIES
+ PROP_WRAP_QUOTED_TEXT_IN_REPLIES,
+ PROP_MINIMUM_FONT_SIZE
};
struct _EWebKitEditorPrivate {
@@ -158,6 +159,8 @@ struct _EWebKitEditorPrivate {
gboolean is_malfunction;
GError *last_error;
+
+ gint minimum_font_size;
};
static const GdkRGBA black = { 0, 0, 0, 1 };
@@ -4035,6 +4038,32 @@ webkit_editor_get_wrap_quoted_text_in_replies (EWebKitEditor *wk_editor)
return wk_editor->priv->wrap_quoted_text_in_replies;
}
+static gint
+webkit_editor_get_minimum_font_size (EWebKitEditor *wk_editor)
+{
+ g_return_val_if_fail (E_IS_WEBKIT_EDITOR (wk_editor), -1);
+
+ return wk_editor->priv->minimum_font_size;
+}
+
+static void
+webkit_editor_set_minimum_font_size (EWebKitEditor *wk_editor,
+ gint pixels)
+{
+ g_return_if_fail (E_IS_WEBKIT_EDITOR (wk_editor));
+
+ if (wk_editor->priv->minimum_font_size != pixels) {
+ WebKitSettings *wk_settings;
+
+ wk_editor->priv->minimum_font_size = pixels;
+
+ wk_settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (wk_editor));
+ e_web_view_utils_apply_minimum_font_size (wk_settings);
+
+ g_object_notify (G_OBJECT (wk_editor), "minimum-font-size");
+ }
+}
+
static void
e_webkit_editor_initialize_web_extensions_cb (WebKitWebContext *web_context,
gpointer user_data)
@@ -4120,6 +4149,8 @@ webkit_editor_constructed (GObject *object)
webkit_settings_set_enable_write_console_messages_to_stdout (web_settings,
e_util_get_webkit_developer_mode_enabled ());
webkit_settings_set_enable_developer_extras (web_settings, e_util_get_webkit_developer_mode_enabled
());
+ e_web_view_utils_apply_minimum_font_size (web_settings);
+
settings = e_util_ref_settings ("org.gnome.evolution.mail");
g_settings_bind (
@@ -4149,6 +4180,15 @@ webkit_editor_constructed (GObject *object)
g_object_unref (settings);
+ settings = e_util_ref_settings ("org.gnome.evolution.shell");
+
+ g_settings_bind (
+ settings, "webkit-minimum-font-size",
+ wk_editor, "minimum-font-size",
+ G_SETTINGS_BIND_GET);
+
+ g_clear_object (&settings);
+
webkit_web_view_load_html (WEBKIT_WEB_VIEW (wk_editor), "", "evo-file:///");
}
@@ -4472,6 +4512,12 @@ webkit_editor_set_property (GObject *object,
E_WEBKIT_EDITOR (object),
g_value_get_boxed (value));
return;
+
+ case PROP_MINIMUM_FONT_SIZE:
+ webkit_editor_set_minimum_font_size (
+ E_WEBKIT_EDITOR (object),
+ g_value_get_int (value));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -4701,6 +4747,11 @@ webkit_editor_get_property (GObject *object,
webkit_editor_get_last_error (
E_WEBKIT_EDITOR (object)));
return;
+
+ case PROP_MINIMUM_FONT_SIZE:
+ g_value_set_int (value,
+ webkit_editor_get_minimum_font_size (E_WEBKIT_EDITOR (object)));
+ return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -5477,6 +5528,16 @@ e_webkit_editor_class_init (EWebKitEditorClass *class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_MINIMUM_FONT_SIZE,
+ g_param_spec_int (
+ "minimum-font-size",
+ "Minimum Font Size",
+ NULL,
+ G_MININT, G_MAXINT, 0,
+ G_PARAM_READWRITE));
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]