<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[224776] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/224776">224776</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-11-13 13:42:54 -0800 (Mon, 13 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[GTK] Automatically adjust font size when gtk-xft-dpi changes
https://bugs.webkit.org/show_bug.cgi?id=142673

Patch by Gabriel Ivascu <givascu@igalia.com> on 2017-11-13
Reviewed by Michael Catanzaro.

Source/WebCore:

* platform/PlatformScreen.h:
* platform/gtk/PlatformScreenGtk.cpp:
(WebCore::gtkXftDPIChangedCallback):
(WebCore::setScreenDPIObserverHandler):
* platform/wpe/PlatformScreenWPE.cpp:
(WebCore::setScreenDPIObserverHandler):

Source/WebKit:

* UIProcess/API/glib/WebKitSettings.cpp:
(webKitSettingsDispose):
(webKitSettingsConstructed):
(webkit_settings_class_init):

Tools:

* TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp:
(testWebKitSettings):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformPlatformScreenh">trunk/Source/WebCore/platform/PlatformScreen.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkPlatformScreenGtkcpp">trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformwpePlatformScreenWPEcpp">trunk/Source/WebCore/platform/wpe/PlatformScreenWPE.cpp</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIglibWebKitSettingscpp">trunk/Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitGLibTestWebKitSettingscpp">trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Source/WebCore/ChangeLog      2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2017-11-13  Gabriel Ivascu  <givascu@igalia.com>
+
+        [GTK] Automatically adjust font size when gtk-xft-dpi changes
+        https://bugs.webkit.org/show_bug.cgi?id=142673
+
+        Reviewed by Michael Catanzaro.
+
+        * platform/PlatformScreen.h:
+        * platform/gtk/PlatformScreenGtk.cpp:
+        (WebCore::gtkXftDPIChangedCallback):
+        (WebCore::setScreenDPIObserverHandler):
+        * platform/wpe/PlatformScreenWPE.cpp:
+        (WebCore::setScreenDPIObserverHandler):
+
</ins><span class="cx"> 2017-11-13  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r224763.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformPlatformScreenh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/PlatformScreen.h (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/PlatformScreen.h   2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Source/WebCore/platform/PlatformScreen.h      2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -25,6 +25,10 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#if USE(GLIB)
+#include <wtf/Function.h>
+#endif
+
</ins><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx"> OBJC_CLASS NSScreen;
</span><span class="cx"> OBJC_CLASS NSWindow;
</span><span class="lines">@@ -60,6 +64,7 @@
</span><span class="cx"> bool screenHasInvertedColors();
</span><span class="cx"> #if USE(GLIB)
</span><span class="cx"> double screenDPI();
</span><ins>+void setScreenDPIObserverHandler(Function<void()>&&);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> FloatRect screenRect(Widget*);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkPlatformScreenGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp  2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp     2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include <cmath>
</span><span class="cx"> #include <gtk/gtk.h>
</span><ins>+#include <wtf/Optional.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -112,6 +113,32 @@
</span><span class="cx">     return cachedDpi;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static std::optional<Function<void()>> screenDPIObserverHandler;
+
+static void gtkXftDPIChangedCallback()
+{
+    if (screenDPIObserverHandler)
+        (*screenDPIObserverHandler)();
+}
+
+void setScreenDPIObserverHandler(Function<void()>&& handler)
+{
+    static GtkSettings* gtkSettings = gtk_settings_get_default();
+    static unsigned long gtkXftDpiChangedHandlerID = 0;
+
+    if (!handler) {
+        if (gtkSettings && gtkXftDpiChangedHandlerID) {
+            g_signal_handler_disconnect(gtkSettings, gtkXftDpiChangedHandlerID);
+            gtkXftDpiChangedHandlerID = 0;
+        }
+        return;
+    }
+
+    screenDPIObserverHandler = WTFMove(handler);
+    if (gtkSettings && !gtkXftDpiChangedHandlerID)
+        gtkXftDpiChangedHandlerID = g_signal_connect(gtkSettings, "notify::gtk-xft-dpi", G_CALLBACK(gtkXftDPIChangedCallback), nullptr);
+}
+
</ins><span class="cx"> static GdkScreen* getScreen(GtkWidget* widget)
</span><span class="cx"> {
</span><span class="cx">     return gtk_widget_has_screen(widget) ? gtk_widget_get_screen(widget) : gdk_screen_get_default();
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformwpePlatformScreenWPEcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/wpe/PlatformScreenWPE.cpp (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/wpe/PlatformScreenWPE.cpp  2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Source/WebCore/platform/wpe/PlatformScreenWPE.cpp     2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -60,6 +60,11 @@
</span><span class="cx">     return 96;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void setScreenDPIObserverHandler(Function<void()>&&)
+{
+    notImplemented();
+}
+
</ins><span class="cx"> FloatRect screenRect(Widget*)
</span><span class="cx"> {
</span><span class="cx">     notImplemented();
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Source/WebKit/ChangeLog       2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2017-11-13  Gabriel Ivascu  <givascu@igalia.com>
+
+        [GTK] Automatically adjust font size when gtk-xft-dpi changes
+        https://bugs.webkit.org/show_bug.cgi?id=142673
+
+        Reviewed by Michael Catanzaro.
+
+        * UIProcess/API/glib/WebKitSettings.cpp:
+        (webKitSettingsDispose):
+        (webKitSettingsConstructed):
+        (webkit_settings_class_init):
+
</ins><span class="cx"> 2017-11-13  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Implement "Service Worker Has No Pending Events" / "Update Service Worker Extended Events Set" algorithms
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIglibWebKitSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp        2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitSettings.cpp   2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -79,6 +79,7 @@
</span><span class="cx">     CString userAgent;
</span><span class="cx">     bool allowModalDialogs { false };
</span><span class="cx">     bool zoomTextOnly { false };
</span><ins>+    double screenDpi { 96 };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -158,12 +159,38 @@
</span><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+static void webKitSettingsDispose(GObject* object)
+{
+    WebCore::setScreenDPIObserverHandler(nullptr);
+    G_OBJECT_CLASS(webkit_settings_parent_class)->dispose(object);
+}
+
</ins><span class="cx"> static void webKitSettingsConstructed(GObject* object)
</span><span class="cx"> {
</span><span class="cx">     G_OBJECT_CLASS(webkit_settings_parent_class)->constructed(object);
</span><span class="cx"> 
</span><del>-    WebPreferences* prefs = WEBKIT_SETTINGS(object)->priv->preferences.get();
</del><ins>+    WebKitSettings* settings = WEBKIT_SETTINGS(object);
+    WebPreferences* prefs = settings->priv->preferences.get();
</ins><span class="cx">     prefs->setShouldRespectImageOrientation(true);
</span><ins>+
+    settings->priv->screenDpi = WebCore::screenDPI();
+    WebCore::setScreenDPIObserverHandler([settings]() {
+        auto newScreenDpi = WebCore::screenDPI();
+        if (newScreenDpi == settings->priv->screenDpi)
+            return;
+
+        auto scalingFactor = newScreenDpi / settings->priv->screenDpi;
+        auto prevFontSize = settings->priv->preferences->defaultFontSize();
+        auto prevMonospaceFontSize = settings->priv->preferences->defaultFixedFontSize();
+
+        settings->priv->preferences->setDefaultFontSize(std::round(prevFontSize * scalingFactor));
+        g_object_notify(G_OBJECT(settings), "default-font-size");
+
+        settings->priv->preferences->setDefaultFixedFontSize(std::round(prevMonospaceFontSize * scalingFactor));
+        g_object_notify(G_OBJECT(settings), "default-monospace-font-size");
+
+        settings->priv->screenDpi = newScreenDpi;
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static void webKitSettingsSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
</span><span class="lines">@@ -512,6 +539,7 @@
</span><span class="cx"> {
</span><span class="cx">     GObjectClass* gObjectClass = G_OBJECT_CLASS(klass);
</span><span class="cx">     gObjectClass->constructed = webKitSettingsConstructed;
</span><ins>+    gObjectClass->dispose = webKitSettingsDispose;
</ins><span class="cx">     gObjectClass->set_property = webKitSettingsSetProperty;
</span><span class="cx">     gObjectClass->get_property = webKitSettingsGetProperty;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Tools/ChangeLog       2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-11-13  Gabriel Ivascu  <givascu@igalia.com>
+
+        [GTK] Automatically adjust font size when gtk-xft-dpi changes
+        https://bugs.webkit.org/show_bug.cgi?id=142673
+
+        Reviewed by Michael Catanzaro.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp:
+        (testWebKitSettings):
+
</ins><span class="cx"> 2017-11-13  Jonathan Bedard  <jbedard@apple.com>
</span><span class="cx"> 
</span><span class="cx">         check-webkit-style cannot construct valid iOS version without an iOS SDK
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitGLibTestWebKitSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp (224775 => 224776)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp        2017-11-13 21:41:55 UTC (rev 224775)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp   2017-11-13 21:42:54 UTC (rev 224776)
</span><span class="lines">@@ -168,6 +168,31 @@
</span><span class="cx">     // At 96 DPI, 8 pixels is 6 points and 24 pixels is 18 points.
</span><span class="cx">     g_assert_cmpuint(webkit_settings_font_size_to_points(8), ==, 6);
</span><span class="cx">     g_assert_cmpuint(webkit_settings_font_size_to_points(24), ==, 18);
</span><ins>+
+    // Test font size on DPI change. The font size value in pixels should scale
+    // accordingly, while the font size value in points should remain the same.
+    if (gtkSettings) {
+        // At 96 DPI, 20 pixels is 15 points.
+        webkit_settings_set_default_font_size(settings, 20);
+        g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_font_size(settings)), ==, 15);
+        // At 96 DPI, 16 pixels is 12 points.
+        webkit_settings_set_default_monospace_font_size(settings, 16);
+        g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_monospace_font_size(settings)), ==, 12);
+
+        // Set DPI to 120. The scaling factor is 120 / 96 == 1.25.
+        g_object_set(gtkSettings, "gtk-xft-dpi", 120 * 1024, nullptr);
+        g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 25);
+        g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_font_size(settings)), ==, 15);
+        g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 20);
+        g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_monospace_font_size(settings)), ==, 12);
+
+        // Set DPI back to 96. The scaling factor is 96 / 120 == 0.8.
+        g_object_set(gtkSettings, "gtk-xft-dpi", 96 * 1024, nullptr);
+        g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 20);
+        g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_font_size(settings)), ==, 15);
+        g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 16);
+        g_assert_cmpuint(webkit_settings_font_size_to_points(webkit_settings_get_default_monospace_font_size(settings)), ==, 12);
+    }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     // Default charset is "iso-8859-1".
</span></span></pre>
</div>
</div>

</body>
</html>