[GTK] Should use light theme unless website declares support for dark themes in color...
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Jan 2020 09:49:33 +0000 (09:49 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Jan 2020 09:49:33 +0000 (09:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197947

Reviewed by Michael Catanzaro.

.:

Do not define HAVE_OS_DARK_MODE_SUPPORT.

* Source/cmake/OptionsGTK.cmake:

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::useDarkAppearance const): Remove HAVE(OS_DARK_MODE_SUPPORT) because ENABLE(DARK_MODE_CSS)
guards should be enough.
* page/FrameView.cpp:
(WebCore::FrameView::updateBackgroundRecursively): Revert changes made in r244635.
* page/Page.cpp:
(WebCore::Page::effectiveAppearanceDidChange): Use ENABLE(DARK_MODE_CSS) instead of HAVE(OS_DARK_MODE_SUPPORT).
(WebCore::Page::useDarkAppearance const): Ditto.
* rendering/RenderThemeGtk.cpp:
(WebCore::RenderThemeGtk::systemColor const): Revert changes made in r244635.
* rendering/RenderThemeGtk.h:
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setUseDarkAppearanceInternal): Revert changes made in r244635.

Source/WebKit:

Handle the theme changes in the UI process, converting dark variant to the light one before sending the theme
name to the web process. The web process is still notified when a dark theme is in use, so that if website
prefers a dark color scheme it will be used, but the gtk theme that will be used for controls styling will
always be light.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const): Encode themeName.
(WebKit::WebPageCreationParameters::decode): Decode themeName.
* Shared/WebPageCreationParameters.h:
* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::themeName const): Get the theme name that should be used by the web process.
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(themeChanged): Call WebPageProxy::themeDidChange().
(applicationPreferDarkThemeChanged):
(webkitWebViewBaseSetToplevelOnScreenWindow): Use a different callback for the theme name change.
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
* UIProcess/WebPageProxy.h:
* UIProcess/gtk/WebPageProxyGtk.cpp:
(WebKit::WebPageProxy::themeDidChange): Send ThemeDidChange message to the web process with the theme name to use.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage): Initialize the theme name.
(WebKit::WebPage::effectiveAppearanceDidChange): Use this now for GTK port too.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in: Add ThemeDidChange message.
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::themeDidChange): Set the theme given name in gtk settings.
* WebProcess/gtk/WebProcessMainGtk.cpp:

Source/WTF:

Do not define HAVE_OS_DARK_MODE_SUPPORT for the GTK port.

* wtf/PlatformHave.h:

LayoutTests:

Rebaseline several tests for the new behavior.

* platform/gtk/css-dark-mode/color-scheme-priority-expected.txt: Added.
* platform/gtk/css-dark-mode/default-colors-expected.txt:
* platform/gtk/css-dark-mode/prefers-color-scheme-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@255342 268f45cc-cd09-0410-ab3c-d52691b4dbfc

30 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/platform/gtk/css-dark-mode/color-scheme-priority-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/css-dark-mode/default-colors-expected.txt
LayoutTests/platform/gtk/css-dark-mode/prefers-color-scheme-expected.txt
Source/WTF/ChangeLog
Source/WTF/wtf/PlatformHave.h
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/rendering/RenderThemeGtk.cpp
Source/WebCore/rendering/RenderThemeGtk.h
Source/WebCore/testing/InternalSettings.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit/UIProcess/PageClient.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/gtk/WebPageProxyGtk.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebPage/gtk/WebPageGtk.cpp
Source/WebKit/WebProcess/gtk/WebProcessMainGtk.cpp
Source/cmake/OptionsGTK.cmake

index fcbff5a..1e6fe50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-01-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Should use light theme unless website declares support for dark themes in color-schemes property
+        https://bugs.webkit.org/show_bug.cgi?id=197947
+
+        Reviewed by Michael Catanzaro.
+
+        Do not define HAVE_OS_DARK_MODE_SUPPORT.
+
+        * Source/cmake/OptionsGTK.cmake:
+
 2020-01-28  Don Olmstead  <don.olmstead@sony.com>
 
         [LFC][Integration] Build and enable on Windows
index 1cd45bf..6205aeb 100644 (file)
@@ -1,3 +1,16 @@
+2020-01-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Should use light theme unless website declares support for dark themes in color-schemes property
+        https://bugs.webkit.org/show_bug.cgi?id=197947
+
+        Reviewed by Michael Catanzaro.
+
+        Rebaseline several tests for the new behavior.
+
+        * platform/gtk/css-dark-mode/color-scheme-priority-expected.txt: Added.
+        * platform/gtk/css-dark-mode/default-colors-expected.txt:
+        * platform/gtk/css-dark-mode/prefers-color-scheme-expected.txt:
+
 2020-01-29  Megan Gardner  <megan_gardner@apple.com>
 
         Fix compositing/video/poster.html test by making blending image opque to deal with flakey failures.
diff --git a/LayoutTests/platform/gtk/css-dark-mode/color-scheme-priority-expected.txt b/LayoutTests/platform/gtk/css-dark-mode/color-scheme-priority-expected.txt
new file mode 100644 (file)
index 0000000..487b9f2
--- /dev/null
@@ -0,0 +1,5 @@
+
+PASS Element colors are correct in light color scheme with light and dark color scheme 
+PASS Dark color scheme enabled 
+FAIL Element colors are correct in dark color scheme with light and dark color scheme assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+
index 44f8b4f..63aa419 100644 (file)
@@ -2,9 +2,9 @@
 PASS Body text color is black, since the page isn't in dark mode 
 PASS View base background color is white, since the page isn't in dark mode 
 PASS Set dark appearance 
-FAIL Body text color is black, since the page hasn't set a supported color scheme assert_equals: expected "rgb(0, 0, 0)" but got "rgb(255, 255, 255)"
+PASS Body text color is black, since the page hasn't set a supported color scheme 
 PASS View base background color is white, since the page hasn't set a supported color scheme 
 PASS Set prefers-color-schemes: light dark on the body 
-PASS Body text color is white 
-FAIL View base background color is a dark grey assert_equals: expected "rgb(30, 30, 30)" but got "rgb(51, 57, 59)"
+FAIL Body text color is white assert_equals: expected "rgb(255, 255, 255)" but got "rgb(0, 0, 0)"
+FAIL View base background color is a dark grey assert_equals: expected "rgb(30, 30, 30)" but got "rgb(255, 255, 255)"
 
index a282533..02d00be 100644 (file)
@@ -2,6 +2,6 @@
 PASS Element colors are correct in light color scheme 
 PASS Element colors are correct in light color scheme with boolean context query 
 PASS Dark color scheme enabled 
-FAIL Element colors are correct in dark color scheme assert_equals: expected "rgb(0, 0, 0)" but got "rgb(255, 255, 255)"
-FAIL Element colors are correct in dark color scheme with boolean context query assert_equals: expected "rgb(0, 0, 0)" but got "rgb(255, 255, 255)"
+PASS Element colors are correct in dark color scheme 
+PASS Element colors are correct in dark color scheme with boolean context query 
 
index b330c08..282f15a 100644 (file)
@@ -1,3 +1,14 @@
+2020-01-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Should use light theme unless website declares support for dark themes in color-schemes property
+        https://bugs.webkit.org/show_bug.cgi?id=197947
+
+        Reviewed by Michael Catanzaro.
+
+        Do not define HAVE_OS_DARK_MODE_SUPPORT for the GTK port.
+
+        * wtf/PlatformHave.h:
+
 2020-01-28  Jonathan Bedard  <jbedard@apple.com>
 
         WebCore: Guard uneven corners in rounded rectangles
index 0a4667a..d13772a 100644 (file)
 #define HAVE_NSHTTPCOOKIESTORAGE__INITWITHIDENTIFIER_WITH_INACCURATE_NULLABILITY 1
 #endif
 
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(IOS) || PLATFORM(MACCATALYST) || PLATFORM(GTK)
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(IOS) || PLATFORM(MACCATALYST)
 #define HAVE_OS_DARK_MODE_SUPPORT 1
 #endif
 
index 584b18c..9287d7b 100644 (file)
@@ -1,3 +1,24 @@
+2020-01-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Should use light theme unless website declares support for dark themes in color-schemes property
+        https://bugs.webkit.org/show_bug.cgi?id=197947
+
+        Reviewed by Michael Catanzaro.
+
+        * dom/Document.cpp:
+        (WebCore::Document::useDarkAppearance const): Remove HAVE(OS_DARK_MODE_SUPPORT) because ENABLE(DARK_MODE_CSS)
+        guards should be enough.
+        * page/FrameView.cpp:
+        (WebCore::FrameView::updateBackgroundRecursively): Revert changes made in r244635.
+        * page/Page.cpp:
+        (WebCore::Page::effectiveAppearanceDidChange): Use ENABLE(DARK_MODE_CSS) instead of HAVE(OS_DARK_MODE_SUPPORT).
+        (WebCore::Page::useDarkAppearance const): Ditto.
+        * rendering/RenderThemeGtk.cpp:
+        (WebCore::RenderThemeGtk::systemColor const): Revert changes made in r244635.
+        * rendering/RenderThemeGtk.h:
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::setUseDarkAppearanceInternal): Revert changes made in r244635.
+
 2020-01-29  Sunny He  <sunny_he@apple.com>
 
         Nullptr crash when setting custom properties on detached style
index 795762c..773b16b 100644 (file)
@@ -7093,7 +7093,6 @@ bool Document::useSystemAppearance() const
 
 bool Document::useDarkAppearance(const RenderStyle* style) const
 {
-#if HAVE(OS_DARK_MODE_SUPPORT)
 #if ENABLE(DARK_MODE_CSS)
     OptionSet<ColorScheme> colorScheme;
 
@@ -7122,9 +7121,6 @@ bool Document::useDarkAppearance(const RenderStyle* style) const
     if (colorScheme.contains(ColorScheme::Dark))
         return pageUsesDarkAppearance;
 #endif
-#else
-    UNUSED_PARAM(style);
-#endif
 
     return false;
 }
index 7cca9f7..a3ab592 100644 (file)
@@ -3031,12 +3031,7 @@ void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
 void FrameView::updateBackgroundRecursively(const Optional<Color>& backgroundColor)
 {
 #if HAVE(OS_DARK_MODE_SUPPORT)
-#if PLATFORM(COCOA)
-    static const auto cssValueControlBackground = CSSValueAppleSystemControlBackground;
-#else
-    static const auto cssValueControlBackground = CSSValueWindow;
-#endif
-    Color baseBackgroundColor = backgroundColor.valueOr(RenderTheme::singleton().systemColor(cssValueControlBackground, styleColorOptions()));
+    Color baseBackgroundColor = backgroundColor.valueOr(RenderTheme::singleton().systemColor(CSSValueAppleSystemControlBackground, styleColorOptions()));
 #else
     Color baseBackgroundColor = backgroundColor.valueOr(Color::white);
 #endif
index cc71079..348ef55 100644 (file)
@@ -2733,7 +2733,7 @@ void Page::setUseSystemAppearance(bool value)
 
 void Page::effectiveAppearanceDidChange(bool useDarkAppearance, bool useElevatedUserInterfaceLevel)
 {
-#if HAVE(OS_DARK_MODE_SUPPORT)
+#if ENABLE(DARK_MODE_CSS)
     if (m_useDarkAppearance == useDarkAppearance && m_useElevatedUserInterfaceLevel == useElevatedUserInterfaceLevel)
         return;
 
@@ -2757,7 +2757,7 @@ void Page::effectiveAppearanceDidChange(bool useDarkAppearance, bool useElevated
 
 bool Page::useDarkAppearance() const
 {
-#if HAVE(OS_DARK_MODE_SUPPORT)
+#if ENABLE(DARK_MODE_CSS)
     FrameView* view = mainFrame().view();
     if (!view || !equalLettersIgnoringASCIICase(view->mediaType(), "screen"))
         return false;
index 07e7a32..1aba35b 100644 (file)
@@ -124,22 +124,6 @@ int RenderThemeGtk::sliderTickOffsetFromTrackCenter() const
 }
 #endif
 
-static void themeChangedCallback()
-{
-    Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
-}
-
-RenderThemeGtk::RenderThemeGtk()
-{
-    static bool themeMonitorInitialized = false;
-    if (!themeMonitorInitialized) {
-        GtkSettings* settings = gtk_settings_get_default();
-        g_signal_connect(settings, "notify::gtk-theme-name", G_CALLBACK(themeChangedCallback), nullptr);
-        g_signal_connect(settings, "notify::gtk-color-scheme", G_CALLBACK(themeChangedCallback), nullptr);
-        themeMonitorInitialized = true;
-    }
-}
-
 enum RenderThemePart {
     Entry,
     EntrySelection,
@@ -951,17 +935,6 @@ Color RenderThemeGtk::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::O
         return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
     case CSSValueGraytext:
         return styleColor(Entry, GTK_STATE_FLAG_INSENSITIVE, StyleColorForeground);
-    case CSSValueWebkitControlBackground:
-        return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorBackground);
-    case CSSValueWindow: {
-        // Only get window color from the theme in dark mode.
-        gboolean preferDarkTheme = FALSE;
-        if (auto* settings = gtk_settings_get_default())
-            g_object_get(settings, "gtk-application-prefer-dark-theme", &preferDarkTheme, nullptr);
-        if (preferDarkTheme)
-            return styleColor(Window, GTK_STATE_FLAG_ACTIVE, StyleColorBackground);
-        break;
-    }
     default:
         break;
     }
index 9f5bf24..87c3aad 100644 (file)
@@ -104,7 +104,6 @@ public:
     bool shouldHaveCapsLockIndicator(const HTMLInputElement&) const override;
 
 private:
-    RenderThemeGtk();
     virtual ~RenderThemeGtk();
 
     bool paintCheckbox(const RenderObject&, const PaintInfo&, const IntRect&) override;
index d5d67fa..96892ad 100644 (file)
 #include "SoupNetworkSession.h"
 #endif
 
-#if PLATFORM(GTK)
-#include <gtk/gtk.h>
-#endif
-
 namespace WebCore {
 
 InternalSettings::Backup::Backup(Settings& settings)
@@ -543,16 +539,6 @@ ExceptionOr<bool> InternalSettings::shouldDisplayTrackKind(const String& kind)
 
 void InternalSettings::setUseDarkAppearanceInternal(bool useDarkAppearance)
 {
-#if PLATFORM(GTK)
-    // GTK doesn't allow to change the theme from the web process, but tests need to do it, so
-    // we do it here only for tests.
-    if (auto* settings = gtk_settings_get_default()) {
-        gboolean preferDarkTheme;
-        g_object_get(settings, "gtk-application-prefer-dark-theme", &preferDarkTheme, nullptr);
-        if (preferDarkTheme != useDarkAppearance)
-            g_object_set(settings, "gtk-application-prefer-dark-theme", useDarkAppearance, nullptr);
-    }
-#endif
     ASSERT(m_page);
     m_page->effectiveAppearanceDidChange(useDarkAppearance, m_page->useElevatedUserInterfaceLevel());
 }
index 112511e..f50efc3 100644 (file)
@@ -1,3 +1,40 @@
+2020-01-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Should use light theme unless website declares support for dark themes in color-schemes property
+        https://bugs.webkit.org/show_bug.cgi?id=197947
+
+        Reviewed by Michael Catanzaro.
+
+        Handle the theme changes in the UI process, converting dark variant to the light one before sending the theme
+        name to the web process. The web process is still notified when a dark theme is in use, so that if website
+        prefers a dark color scheme it will be used, but the gtk theme that will be used for controls styling will
+        always be light.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const): Encode themeName.
+        (WebKit::WebPageCreationParameters::decode): Decode themeName.
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::themeName const): Get the theme name that should be used by the web process.
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (themeChanged): Call WebPageProxy::themeDidChange().
+        (applicationPreferDarkThemeChanged):
+        (webkitWebViewBaseSetToplevelOnScreenWindow): Use a different callback for the theme name change.
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/gtk/WebPageProxyGtk.cpp:
+        (WebKit::WebPageProxy::themeDidChange): Send ThemeDidChange message to the web process with the theme name to use.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage): Initialize the theme name.
+        (WebKit::WebPage::effectiveAppearanceDidChange): Use this now for GTK port too.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in: Add ThemeDidChange message.
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::themeDidChange): Set the theme given name in gtk settings.
+        * WebProcess/gtk/WebProcessMainGtk.cpp:
+
 2020-01-28  Timothy Horton  <timothy_horton@apple.com>
 
         Fix the build
index 6bfa99f..9085995 100644 (file)
@@ -142,6 +142,10 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << shouldCaptureVideoInUIProcess;
     encoder << shouldCaptureVideoInGPUProcess;
     encoder << shouldCaptureDisplayInUIProcess;
+
+#if PLATFORM(GTK)
+    encoder << themeName;
+#endif
 }
 
 Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
@@ -438,6 +442,11 @@ Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decod
     if (!decoder.decode(parameters.shouldCaptureDisplayInUIProcess))
         return WTF::nullopt;
 
+#if PLATFORM(GTK)
+    if (!decoder.decode(parameters.themeName))
+        return WTF::nullopt;
+#endif
+
     return parameters;
 }
 
index a855514..aa05714 100644 (file)
@@ -213,6 +213,10 @@ struct WebPageCreationParameters {
     bool shouldCaptureVideoInUIProcess { false };
     bool shouldCaptureVideoInGPUProcess { false };
     bool shouldCaptureDisplayInUIProcess { false };
+
+#if PLATFORM(GTK)
+    String themeName;
+#endif
 };
 
 } // namespace WebKit
index b1252da..8a6bda9 100644 (file)
@@ -583,4 +583,21 @@ void PageClientImpl::didChangeWebPageID() const
         webkitWebViewDidChangePageID(WEBKIT_WEB_VIEW(m_viewWidget));
 }
 
+String PageClientImpl::themeName() const
+{
+    if (auto* themeNameEnv = g_getenv("GTK_THEME")) {
+        String name = String::fromUTF8(themeNameEnv);
+        if (name.endsWith("-dark") || name.endsWith(":dark"))
+            return name.substring(0, name.length() - 5);
+        return name;
+    }
+
+    GUniqueOutPtr<char> themeNameSetting;
+    g_object_get(gtk_widget_get_settings(m_viewWidget), "gtk-theme-name", &themeNameSetting.outPtr(), nullptr);
+    String name = String::fromUTF8(themeNameSetting.get());
+    if (name.endsWith("-dark"))
+        return name.substring(0, name.length() - 5);
+    return name;
+}
+
 } // namespace WebKit
index 73ba2ea..b9ac761 100644 (file)
@@ -172,6 +172,8 @@ private:
 
     void didChangeWebPageID() const override;
 
+    String themeName() const override;
+
     // Members of PageClientImpl class
     GtkWidget* m_viewWidget;
     DefaultUndoController m_undoController;
index 0d58bb3..dc3ef85 100644 (file)
@@ -295,6 +295,11 @@ static gboolean toplevelWindowStateEvent(GtkWidget*, GdkEventWindowState* event,
 
 static void themeChanged(WebKitWebViewBase* webViewBase)
 {
+    webViewBase->priv->pageProxy->themeDidChange();
+}
+
+static void applicationPreferDarkThemeChanged(WebKitWebViewBase* webViewBase)
+{
     webViewBase->priv->pageProxy->effectiveAppearanceDidChange();
 }
 
@@ -374,7 +379,7 @@ static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webVie
     priv->themeChangedID =
         g_signal_connect_swapped(settings, "notify::gtk-theme-name", G_CALLBACK(themeChanged), webViewBase);
     priv->applicationPreferDarkThemeID =
-        g_signal_connect_swapped(settings, "notify::gtk-application-prefer-dark-theme", G_CALLBACK(themeChanged), webViewBase);
+        g_signal_connect_swapped(settings, "notify::gtk-application-prefer-dark-theme", G_CALLBACK(applicationPreferDarkThemeChanged), webViewBase);
 
     if (gtk_widget_get_realized(GTK_WIDGET(window)))
         gtk_widget_realize(GTK_WIDGET(webViewBase));
index 4a57d3d..51cdd20 100644 (file)
@@ -516,6 +516,10 @@ public:
 #endif
 
     virtual void didChangeWebPageID() const { }
+
+#if PLATFORM(GTK)
+    virtual String themeName() const = 0;
+#endif
 };
 
 } // namespace WebKit
index 985bdc9..00d499c 100644 (file)
@@ -7641,6 +7641,10 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
     parameters.shouldCaptureVideoInGPUProcess = m_process->processPool().configuration().shouldCaptureVideoInGPUProcess();
     parameters.shouldCaptureDisplayInUIProcess = m_process->processPool().configuration().shouldCaptureDisplayInUIProcess();
 
+#if PLATFORM(GTK)
+    parameters.themeName = pageClient().themeName();
+#endif
+
     return parameters;
 }
 
index c99fe0f..93d8ce4 100644 (file)
@@ -869,6 +869,7 @@ public:
 #if PLATFORM(GTK)
     PlatformViewWidget viewWidget();
     bool makeGLContextCurrent();
+    void themeDidChange();
 #endif
 
     const Optional<WebCore::Color>& backgroundColor() const { return m_backgroundColor; }
index 8ee86fa..e98b052 100644 (file)
@@ -184,4 +184,13 @@ void WebPageProxy::sendMessageToWebView(UserMessage&& message)
     sendMessageToWebViewWithReply(WTFMove(message), [](UserMessage&&) { });
 }
 
+void WebPageProxy::themeDidChange()
+{
+    if (!hasRunningProcess())
+        return;
+
+    send(Messages::WebPage::ThemeDidChange(pageClient().themeName()));
+    effectiveAppearanceDidChange();
+}
+
 } // namespace WebKit
index bd34106..e65361a 100644 (file)
@@ -593,6 +593,10 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters)
     setGapBetweenPages(parameters.gapBetweenPages);
     setPaginationLineGridEnabled(parameters.paginationLineGridEnabled);
 
+#if PLATFORM(GTK)
+    themeDidChange(WTFMove(parameters.themeName));
+#endif
+
     effectiveAppearanceDidChange(parameters.useDarkAppearance, parameters.useElevatedUserInterfaceLevel);
 
     if (parameters.isEditable)
@@ -4709,12 +4713,10 @@ void WebPage::setUseSystemAppearance(bool useSystemAppearance)
 
 #endif
 
-#if !PLATFORM(GTK)
 void WebPage::effectiveAppearanceDidChange(bool useDarkAppearance, bool useElevatedUserInterfaceLevel)
 {
     corePage()->effectiveAppearanceDidChange(useDarkAppearance, useElevatedUserInterfaceLevel);
 }
-#endif
 
 void WebPage::freezeLayerTreeDueToSwipeAnimation()
 {
index d540081..a275376 100644 (file)
@@ -796,6 +796,8 @@ public:
     void showEmojiPicker(WebCore::Frame&);
 
     void getCenterForZoomGesture(const WebCore::IntPoint& centerInViewCoordinates, CompletionHandler<void(WebCore::IntPoint&&)>&&);
+
+    void themeDidChange(String&&);
 #endif
 
     void didApplyStyle();
@@ -2044,6 +2046,10 @@ private:
 #endif
 
     String m_overriddenMediaType;
+
+#if PLATFORM(GTK)
+    String m_themeName;
+#endif
 };
 
 #if !PLATFORM(IOS_FAMILY)
index d61df80..e9ad60f 100644 (file)
@@ -506,6 +506,10 @@ GenerateSyntheticEditingCommand(enum:uint8_t WebKit::SyntheticEditingCommandType
 
     EffectiveAppearanceDidChange(bool useDarkAppearance, bool useElevatedUserInterfaceLevel);
 
+#if PLATFORM(GTK)
+    ThemeDidChange(String themeName)
+#endif
+
 #if PLATFORM(COCOA)
     RequestActiveNowPlayingSessionInfo(WebKit::CallbackID callbackID)
 #endif
index 89dc11b..8e86ed3 100644 (file)
@@ -157,11 +157,14 @@ void WebPage::showEmojiPicker(Frame& frame)
     sendWithAsyncReply(Messages::WebPageProxy::ShowEmojiPicker(frame.view()->contentsToRootView(frame.selection().absoluteCaretBounds())), WTFMove(completionHandler));
 }
 
-void WebPage::effectiveAppearanceDidChange(bool useDarkAppearance, bool useInactiveAppearance)
+void WebPage::themeDidChange(String&& themeName)
 {
-    if (auto* settings = gtk_settings_get_default())
-        g_object_set(settings, "gtk-application-prefer-dark-theme", useDarkAppearance, nullptr);
-    corePage()->effectiveAppearanceDidChange(useDarkAppearance, useInactiveAppearance);
+    if (m_themeName == themeName)
+        return;
+
+    m_themeName = WTFMove(themeName);
+    g_object_set(gtk_settings_get_default(), "gtk-theme-name", m_themeName.utf8().data(), nullptr);
+    Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
 }
 
 } // namespace WebKit
index 45f4d29..af66799 100644 (file)
@@ -53,6 +53,10 @@ public:
 #if (USE(COORDINATED_GRAPHICS) || USE(GSTREAMER_GL)) && PLATFORM(X11)
         XInitThreads();
 #endif
+
+        // Ignore the GTK_THEME environment variable, the theme is always set by the UI process now.
+        g_unsetenv("GTK_THEME");
+
         gtk_init(nullptr, nullptr);
 
         bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
index c72a892..52c4d1b 100644 (file)
@@ -210,7 +210,6 @@ set(GDK_LIBRARIES ${GDK3_LIBRARIES})
 set(GDK_INCLUDE_DIRS ${GDK3_INCLUDE_DIRS})
 
 SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_UNIX_PRINTING ${GTKUnixPrint_FOUND})
-SET_AND_EXPOSE_TO_BUILD(HAVE_OS_DARK_MODE_SUPPORT 1)
 
 if (USE_WPE_RENDERER)
     find_package(WPE 1.3.0)