[GTK] Hardcoded text color in input fields
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Apr 2019 05:51:01 +0000 (05:51 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 25 Apr 2019 05:51:01 +0000 (05:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126907

Reviewed by Michael Catanzaro.

.:

Set and expose to build HAVE_OS_DARK_MODE_SUPPORT=1.

* Source/cmake/OptionsGTK.cmake:

Source/WebCore:

Enable HAVE_OS_DARK_MODE_SUPPORT for GTK port to ensure that dark mode is used when Page::useDarkAppearance()
returns true. This patch reverts r232913, I'll reopen the bug, I think we need to find a better solution for
that.

* CMakeLists.txt: Add HAVE_OS_DARK_MODE_SUPPORT to FEATURE_DEFINES_WITH_SPACE_SEPARATOR if enabled.
* css/CSSDefaultStyleSheets.cpp: Ensure html{color:text} is used in simple style sheet when
HAVE_OS_DARK_MODE_SUPPORT is enabled.
* page/FrameView.cpp:
(WebCore::FrameView::updateBackgroundRecursively): Use CSSValueWindowframe to get the frame view background
color when HAVE_OS_DARK_MODE_SUPPORT is enabled for non-mac ports.
* platform/gtk/RenderThemeWidget.cpp:
(WebCore::RenderThemeWidget::getOrCreate): Create window widget.
(WebCore::RenderThemeWindow::RenderThemeWindow): Add window widget.
* platform/gtk/RenderThemeWidget.h:
* rendering/RenderThemeGtk.cpp:
(WebCore::RenderThemeGtk::disabledTextColor const): Always use the color from the theme for consistency with
other form controls.
(WebCore::RenderThemeGtk::systemColor const): Get the color from the theme for CSSValueText, CSSValueGraytext
and CSSValueWindowframe.
* rendering/RenderThemeGtk.h:

Source/WebKit:

Implement PageClient::effectiveAppearanceIsDark() for GTK port.

* UIProcess/API/gtk/PageClientImpl.cpp:
(WebKit::PageClientImpl::effectiveAppearanceIsDark const): Check if gtk-application-prefer-dark-theme setting is
enabled, or the theme name contains the -dark suffix or the GTK_THEME environment variable contains the :dark suffix.
* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(themeChanged): Notify the WebPageProxy that the theme has changed.
(webkitWebViewBaseSetToplevelOnScreenWindow): Connect to notify::gtk-application-prefer-dark-theme and notify::gtk-theme-name.
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::setUseDarkAppearance): Set gtk-application-prefer-dark-theme setting accordingly.

Source/WTF:

Define HAVE_OS_DARK_MODE_SUPPORT for GTK port.

* wtf/Platform.h:

Tools:

Add dark-mode command line option to MiniBrowser.

* MiniBrowser/gtk/main.c:
(main):

LayoutTests:

Remove expectations for tests that are passing again.

* platform/gtk/TestExpectations:

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

22 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/platform/gtk/TestExpectations
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/css/CSSDefaultStyleSheets.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/platform/gtk/RenderThemeWidget.cpp
Source/WebCore/platform/gtk/RenderThemeWidget.h
Source/WebCore/rendering/RenderThemeGtk.cpp
Source/WebCore/rendering/RenderThemeGtk.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp
Source/WebKit/UIProcess/API/gtk/PageClientImpl.h
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/gtk/WebPageGtk.cpp
Source/cmake/OptionsGTK.cmake
Tools/ChangeLog
Tools/MiniBrowser/gtk/main.c

index c22ae66..68406ba 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Hardcoded text color in input fields
+        https://bugs.webkit.org/show_bug.cgi?id=126907
+
+        Reviewed by Michael Catanzaro.
+
+        Set and expose to build HAVE_OS_DARK_MODE_SUPPORT=1.
+
+        * Source/cmake/OptionsGTK.cmake:
+
 2019-04-23  Don Olmstead  <don.olmstead@sony.com>
 
         [CMake][Win] Use target oriented design for WebKit
index 54c3303..e738df2 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Hardcoded text color in input fields
+        https://bugs.webkit.org/show_bug.cgi?id=126907
+
+        Reviewed by Michael Catanzaro.
+
+        Remove expectations for tests that are passing again.
+
+        * platform/gtk/TestExpectations:
+
 2019-04-24  Simon Fraser  <simon.fraser@apple.com>
 
         REGRESSION (r242132): Nested position:sticky elements move incorrectly
index 0ff1e74..bd3cc81 100644 (file)
@@ -1176,12 +1176,6 @@ webkit.org/b/186086 fast/text/font-collection.html [ ImageOnlyFailure ]
 # Test does not make sense for our platform
 webkit.org/b/181659 fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies.html [ Skip ]
 
-# When text input colors are set we do not style with GTK, so these reftests will fail
-webkit.org/b/186219 fast/forms/input-placeholder-text-indent.html [ ImageOnlyFailure ]
-webkit.org/b/186219 fast/forms/password-placeholder-text-security.html [ ImageOnlyFailure ]
-webkit.org/b/186219 fast/forms/placeholder-with-positioned-element.html [ ImageOnlyFailure ]
-webkit.org/b/186219 fast/forms/textarea-placeholder-wrapping.html [ ImageOnlyFailure ]
-
 # This seems to be testing Apple-specific behavior?
 css3/color-filters/color-filter-ignore-semantic.html [ ImageOnlyFailure ]
 
index c38d272..21f5ab9 100644 (file)
@@ -1,3 +1,14 @@
+2019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Hardcoded text color in input fields
+        https://bugs.webkit.org/show_bug.cgi?id=126907
+
+        Reviewed by Michael Catanzaro.
+
+        Define HAVE_OS_DARK_MODE_SUPPORT for GTK port.
+
+        * wtf/Platform.h:
+
 2019-04-24  Tim Horton  <timothy_horton@apple.com>
 
         Clean up WKActionSheetAssistant's use of LaunchServices
index 5927cef..13faf61 100644 (file)
 #endif
 #endif
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(GTK)
 #define HAVE_OS_DARK_MODE_SUPPORT 1
 #endif
 
index e92b9c7..2a83ee0 100644 (file)
@@ -1682,6 +1682,10 @@ if (USE_LIBWEBRTC)
     )
 endif ()
 
+if (HAVE_OS_DARK_MODE_SUPPORT)
+    set(FEATURE_DEFINES_WITH_SPACE_SEPARATOR "${FEATURE_DEFINES_WITH_SPACE_SEPARATOR} HAVE_OS_DARK_MODE_SUPPORT")
+endif ()
+
 set(WebCoreTestSupport_PRIVATE_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/mock"
     "${WEBCORE_DIR}/testing"
index b9f94e7..3f7176f 100644 (file)
@@ -1,3 +1,31 @@
+2019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Hardcoded text color in input fields
+        https://bugs.webkit.org/show_bug.cgi?id=126907
+
+        Reviewed by Michael Catanzaro.
+
+        Enable HAVE_OS_DARK_MODE_SUPPORT for GTK port to ensure that dark mode is used when Page::useDarkAppearance()
+        returns true. This patch reverts r232913, I'll reopen the bug, I think we need to find a better solution for
+        that.
+
+        * CMakeLists.txt: Add HAVE_OS_DARK_MODE_SUPPORT to FEATURE_DEFINES_WITH_SPACE_SEPARATOR if enabled.
+        * css/CSSDefaultStyleSheets.cpp: Ensure html{color:text} is used in simple style sheet when
+        HAVE_OS_DARK_MODE_SUPPORT is enabled.
+        * page/FrameView.cpp:
+        (WebCore::FrameView::updateBackgroundRecursively): Use CSSValueWindowframe to get the frame view background
+        color when HAVE_OS_DARK_MODE_SUPPORT is enabled for non-mac ports.
+        * platform/gtk/RenderThemeWidget.cpp:
+        (WebCore::RenderThemeWidget::getOrCreate): Create window widget.
+        (WebCore::RenderThemeWindow::RenderThemeWindow): Add window widget.
+        * platform/gtk/RenderThemeWidget.h:
+        * rendering/RenderThemeGtk.cpp:
+        (WebCore::RenderThemeGtk::disabledTextColor const): Always use the color from the theme for consistency with
+        other form controls.
+        (WebCore::RenderThemeGtk::systemColor const): Get the color from the theme for CSSValueText, CSSValueGraytext
+        and CSSValueWindowframe.
+        * rendering/RenderThemeGtk.h:
+
 2019-04-24  Zalan Bujtas  <zalan@apple.com>
 
         Regression (r244291): Broken API Test AutoLayoutRenderingProgressRelativeOrdering
index b8069d6..c44cebc 100644 (file)
@@ -81,8 +81,8 @@ StyleSheetContents* CSSDefaultStyleSheets::colorInputStyleSheet;
 #endif
 
 // FIXME: It would be nice to use some mechanism that guarantees this is in sync with the real UA stylesheet.
-#if PLATFORM(MAC)
-// The only difference in the simple style sheet for macOS is the addition of html{color:text}.
+#if HAVE(OS_DARK_MODE_SUPPORT)
+// The only difference in the simple style sheet for dark mode is the addition of html{color:text}.
 static const char* simpleUserAgentStyleSheet = "html,body,div{display:block}html{color:text}head{display:none}body{margin:8px}div:focus,span:focus,a:focus{outline:auto 5px -webkit-focus-ring-color}a:any-link{color:-webkit-link;text-decoration:underline}a:any-link:active{color:-webkit-activelink}";
 #else
 static const char* simpleUserAgentStyleSheet = "html,body,div{display:block}head{display:none}body{margin:8px}div:focus,span:focus,a:focus{outline:auto 5px -webkit-focus-ring-color}a:any-link{color:-webkit-link;text-decoration:underline}a:any-link:active{color:-webkit-activelink}";
index 398438a..7a7b72e 100644 (file)
@@ -3000,8 +3000,13 @@ void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
 
 void FrameView::updateBackgroundRecursively(const Optional<Color>& backgroundColor)
 {
-#if HAVE(OS_DARK_MODE_SUPPORT) && ENABLE(DARK_MODE_CSS)
-    Color baseBackgroundColor = backgroundColor.valueOr(RenderTheme::singleton().systemColor(CSSValueAppleSystemControlBackground, styleColorOptions()));
+#if HAVE(OS_DARK_MODE_SUPPORT)
+#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
+    static const auto cssValueControlBackground = CSSValueAppleSystemControlBackground;
+#else
+    static const auto cssValueControlBackground = CSSValueWindowframe;
+#endif
+    Color baseBackgroundColor = backgroundColor.valueOr(RenderTheme::singleton().systemColor(cssValueControlBackground, styleColorOptions()));
 #else
     Color baseBackgroundColor = backgroundColor.valueOr(Color::white);
 #endif
index b72c107..0d1726d 100644 (file)
@@ -85,6 +85,8 @@ RenderThemeWidget& RenderThemeWidget::getOrCreate(Type widgetType)
             return std::make_unique<RenderThemeListView>();
         case RenderThemeWidget::Type::Icon:
             return std::make_unique<RenderThemeIcon>();
+        case RenderThemeWidget::Type::Window:
+            return std::make_unique<RenderThemeWindow>();
         }
         ASSERT_NOT_REACHED();
         return nullptr;
@@ -293,6 +295,11 @@ RenderThemeIcon::RenderThemeIcon()
 {
 }
 
+RenderThemeWindow::RenderThemeWindow()
+    : m_window(RenderThemeGadget::create({ RenderThemeGadget::Type::Generic, "window", { "background" } }))
+{
+}
+
 } // namepsace WebCore
 
 #endif // GTK_CHECK_VERSION(3, 20, 0)
index 5daab0d..a6686db 100644 (file)
@@ -59,6 +59,7 @@ public:
         IndeterminateProgressBar,
         ListView,
         Icon,
+        Window,
     };
     static RenderThemeWidget& getOrCreate(Type);
     static void clearCache();
@@ -233,6 +234,18 @@ private:
     std::unique_ptr<RenderThemeGadget> m_icon;
 };
 
+class RenderThemeWindow final : public RenderThemeWidget {
+public:
+    RenderThemeWindow();
+    ~RenderThemeWindow() = default;
+
+    RenderThemeGadget& window() const { return *m_window; }
+
+private:
+    std::unique_ptr<RenderThemeGadget> m_window;
+
+};
+
 } // namespace WebCore
 
 #endif // GTK_CHECK_VERSION(3, 20, 0)
index b25966c..a6dbb55 100644 (file)
@@ -167,6 +167,9 @@ enum RenderThemePart {
 #if ENABLE(VIDEO)
     MediaButton,
 #endif
+#if GTK_CHECK_VERSION(3, 20, 0)
+    Window,
+#endif
 };
 
 #if !GTK_CHECK_VERSION(3, 20, 0)
@@ -926,15 +929,6 @@ bool RenderThemeGtk::paintMenuListButtonDecorations(const RenderBox& object, con
     return paintMenuList(object, info, rect);
 }
 
-bool RenderThemeGtk::isControlStyled(const RenderStyle& style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const
-{
-    // To avoid rendering issues with dark themes, if text input elements have color styling, we don't style them with GTK.
-    if ((style.appearance() == TextFieldPart || style.appearance() == TextAreaPart || style.appearance() == SearchFieldPart) && style.color() != RenderStyle::initialColor())
-        return true;
-
-    return RenderTheme::isControlStyled(style, border, background, backgroundColor);
-}
-
 #if GTK_CHECK_VERSION(3, 20, 0)
 
 static IntSize spinButtonSize()
@@ -1706,6 +1700,9 @@ static Color styleColor(RenderThemePart themePart, GtkStateFlags state, StyleCol
     case Button:
         gadget = &static_cast<RenderThemeButton&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Button)).button();
         break;
+    case Window:
+        gadget = &static_cast<RenderThemeWindow&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Window)).window();
+        break;
     }
 
     ASSERT(gadget);
@@ -1767,6 +1764,11 @@ Color RenderThemeGtk::platformInactiveListBoxSelectionForegroundColor(OptionSet<
     return styleColor(ListBox, GTK_STATE_FLAG_SELECTED, StyleColorForeground);
 }
 
+Color RenderThemeGtk::disabledTextColor(const Color&, const Color&) const
+{
+    return styleColor(Entry, GTK_STATE_FLAG_INSENSITIVE, StyleColorForeground);
+}
+
 Color RenderThemeGtk::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::Options> options) const
 {
     switch (cssValueId) {
@@ -1774,6 +1776,14 @@ Color RenderThemeGtk::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::O
         return styleColor(Button, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
     case CSSValueCaptiontext:
         return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
+    case CSSValueText:
+        return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
+    case CSSValueGraytext:
+        return styleColor(Entry, GTK_STATE_FLAG_INSENSITIVE, StyleColorForeground);
+#if GTK_CHECK_VERSION(3, 20, 0)
+    case CSSValueWindowframe:
+        return styleColor(Window, GTK_STATE_FLAG_ACTIVE, StyleColorBackground);
+#endif
     default:
         return RenderTheme::systemColor(cssValueId, options);
     }
index 097f941..967b8f7 100644 (file)
@@ -81,6 +81,8 @@ public:
     Color platformInactiveListBoxSelectionBackgroundColor(OptionSet<StyleColor::Options>) const override;
     Color platformInactiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options>) const override;
 
+    Color disabledTextColor(const Color&, const Color&) const override;
+
     Seconds caretBlinkInterval() const override;
 
     void platformColorsDidChange() override;
@@ -168,8 +170,6 @@ private:
 #endif
 #endif
 
-    bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer&, const Color&) const override;
-
     Seconds animationRepeatIntervalForProgressBar(RenderProgress&) const override;
     Seconds animationDurationForProgressBar(RenderProgress&) const override;
     void adjustProgressBarStyle(StyleResolver&, RenderStyle&, const Element*) const override;
index 56c8ab7..859560f 100644 (file)
@@ -1,3 +1,23 @@
+2019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Hardcoded text color in input fields
+        https://bugs.webkit.org/show_bug.cgi?id=126907
+
+        Reviewed by Michael Catanzaro.
+
+        Implement PageClient::effectiveAppearanceIsDark() for GTK port.
+
+        * UIProcess/API/gtk/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::effectiveAppearanceIsDark const): Check if gtk-application-prefer-dark-theme setting is
+        enabled, or the theme name contains the -dark suffix or the GTK_THEME environment variable contains the :dark suffix.
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (themeChanged): Notify the WebPageProxy that the theme has changed.
+        (webkitWebViewBaseSetToplevelOnScreenWindow): Connect to notify::gtk-application-prefer-dark-theme and notify::gtk-theme-name.
+        * WebProcess/WebPage/WebPage.cpp:
+        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
+        (WebKit::WebPage::setUseDarkAppearance): Set gtk-application-prefer-dark-theme setting accordingly.
+
 2019-04-24  Zalan Bujtas  <zalan@apple.com>
 
         Regression (r244291): Broken API Test AutoLayoutRenderingProgressRelativeOrdering
index b9e8285..a0adb13 100644 (file)
@@ -533,4 +533,23 @@ void PageClientImpl::requestDOMPasteAccess(const IntRect&, const String&, Comple
     completionHandler(WebCore::DOMPasteAccessResponse::DeniedForGesture);
 }
 
+bool PageClientImpl::effectiveAppearanceIsDark() const
+{
+    auto* settings = gtk_widget_get_settings(m_viewWidget);
+    gboolean preferDarkTheme;
+    g_object_get(settings, "gtk-application-prefer-dark-theme", &preferDarkTheme, nullptr);
+    if (preferDarkTheme)
+        return true;
+
+    GUniqueOutPtr<char> themeName;
+    g_object_get(settings, "gtk-theme-name", &themeName.outPtr(), nullptr);
+    if (g_str_has_suffix(themeName.get(), "-dark"))
+        return true;
+
+    if (auto* themeNameEnv = g_getenv("GTK_THEME"))
+        return g_str_has_suffix(themeNameEnv, ":dark");
+
+    return false;
+}
+
 } // namespace WebKit
index 916dd49..a690c82 100644 (file)
@@ -162,6 +162,8 @@ private:
 
     WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return WebCore::UserInterfaceLayoutDirection::LTR; }
 
+    bool effectiveAppearanceIsDark() const override;
+
     // Members of PageClientImpl class
     GtkWidget* m_viewWidget;
     DefaultUndoController m_undoController;
index a9619d1..816f0fa 100644 (file)
@@ -183,6 +183,8 @@ struct _WebKitWebViewBasePrivate {
     unsigned long toplevelFocusOutEventID { 0 };
     unsigned long toplevelWindowStateEventID { 0 };
     unsigned long toplevelWindowRealizedID { 0 };
+    unsigned long themeChangedID { 0 };
+    unsigned long applicationPreferDarkThemeID { 0 };
 
     // View State.
     OptionSet<ActivityState::Flag> activityState;
@@ -265,6 +267,11 @@ static gboolean toplevelWindowStateEvent(GtkWidget*, GdkEventWindowState* event,
     return FALSE;
 }
 
+static void themeChanged(WebKitWebViewBase* webViewBase)
+{
+    webViewBase->priv->pageProxy->effectiveAppearanceDidChange();
+}
+
 static void toplevelWindowRealized(WebKitWebViewBase* webViewBase)
 {
     gtk_widget_realize(GTK_WIDGET(webViewBase));
@@ -298,6 +305,17 @@ static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webVie
         g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelWindowRealizedID);
         priv->toplevelWindowRealizedID = 0;
     }
+    if (priv->themeChangedID || priv->applicationPreferDarkThemeID) {
+        auto* settings = gtk_widget_get_settings(GTK_WIDGET(priv->toplevelOnScreenWindow));
+        if (priv->themeChangedID) {
+            g_signal_handler_disconnect(settings, priv->themeChangedID);
+            priv->themeChangedID = 0;
+        }
+        if (priv->applicationPreferDarkThemeID) {
+            g_signal_handler_disconnect(settings, priv->applicationPreferDarkThemeID);
+            priv->applicationPreferDarkThemeID = 0;
+        }
+    }
 
     priv->toplevelOnScreenWindow = window;
 
@@ -326,6 +344,12 @@ static void webkitWebViewBaseSetToplevelOnScreenWindow(WebKitWebViewBase* webVie
     priv->toplevelWindowStateEventID =
         g_signal_connect(priv->toplevelOnScreenWindow, "window-state-event", G_CALLBACK(toplevelWindowStateEvent), webViewBase);
 
+    auto* settings = gtk_widget_get_settings(GTK_WIDGET(priv->toplevelOnScreenWindow));
+    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);
+
     if (gtk_widget_get_realized(GTK_WIDGET(window)))
         gtk_widget_realize(GTK_WIDGET(webViewBase));
     else
index 3e52838..e667474 100644 (file)
@@ -4610,10 +4610,12 @@ void WebPage::setUseSystemAppearance(bool useSystemAppearance)
 
 #endif
 
+#if !PLATFORM(GTK)
 void WebPage::setUseDarkAppearance(bool useDarkAppearance)
 {
     corePage()->setUseDarkAppearance(useDarkAppearance);
 }
+#endif
 
 void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
 {
index 261db5c..b46699f 100644 (file)
@@ -195,4 +195,11 @@ void WebPage::collapseSelectionInFrame(uint64_t frameID)
     frame->coreFrame()->selection().setBase(selection.extent(), selection.affinity());
 }
 
+void WebPage::setUseDarkAppearance(bool useDarkAppearance)
+{
+    if (auto* settings = gtk_settings_get_default())
+        g_object_set(settings, "gtk-application-prefer-dark-theme", useDarkAppearance, nullptr);
+    corePage()->setUseDarkAppearance(useDarkAppearance);
+}
+
 } // namespace WebKit
index 07b9b7f..aa9a79f 100644 (file)
@@ -192,6 +192,7 @@ set(GDK_INCLUDE_DIRS ${GDK3_INCLUDE_DIRS})
 
 SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_GESTURES ${GTK3_SUPPORTS_GESTURES})
 SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_UNIX_PRINTING ${GTKUnixPrint_FOUND})
+SET_AND_EXPOSE_TO_BUILD(HAVE_OS_DARK_MODE_SUPPORT 1)
 
 set(glib_components gio gio-unix gobject gthread gmodule)
 find_package(GLIB 2.36 REQUIRED COMPONENTS ${glib_components})
index 41f3707..ad921a5 100644 (file)
@@ -1,3 +1,15 @@
+2019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Hardcoded text color in input fields
+        https://bugs.webkit.org/show_bug.cgi?id=126907
+
+        Reviewed by Michael Catanzaro.
+
+        Add dark-mode command line option to MiniBrowser.
+
+        * MiniBrowser/gtk/main.c:
+        (main):
+
 2019-04-24  Zalan Bujtas  <zalan@apple.com>
 
         Regression (r244291): Broken API Test AutoLayoutRenderingProgressRelativeOrdering
index a9a3c1e..e39aac3 100644 (file)
@@ -52,6 +52,7 @@ static const char *contentFilter;
 static const char *cookiesFile;
 static const char *cookiesPolicy;
 static const char *proxy;
+static gboolean darkMode;
 
 typedef enum {
     MINI_BROWSER_ERROR_INVALID_ABOUT_PATH
@@ -103,6 +104,7 @@ static const GOptionEntry commandLineOptions[] =
 {
     { "bg-color", 0, 0, G_OPTION_ARG_CALLBACK, parseBackgroundColor, "Background color", NULL },
     { "editor-mode", 'e', 0, G_OPTION_ARG_NONE, &editorMode, "Run in editor mode", NULL },
+    { "dark-mode", 'd', 0, G_OPTION_ARG_NONE, &darkMode, "Run in dark mode", NULL },
     { "session-file", 's', 0, G_OPTION_ARG_FILENAME, &sessionFile, "Session file", "FILE" },
     { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, "Set the size and position of the window (WIDTHxHEIGHT+X+Y)", "GEOMETRY" },
     { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullScreen, "Set the window to full-screen mode", NULL },
@@ -584,6 +586,8 @@ int main(int argc, char *argv[])
         webkit_web_context_set_tls_errors_policy(webContext, WEBKIT_TLS_ERRORS_POLICY_IGNORE);
 
     BrowserWindow *mainWindow = BROWSER_WINDOW(browser_window_new(NULL, webContext));
+    if (darkMode)
+        g_object_set(gtk_widget_get_settings(GTK_WIDGET(mainWindow)), "gtk-application-prefer-dark-theme", TRUE, NULL);
     if (fullScreen)
         gtk_window_fullscreen(GTK_WINDOW(mainWindow));
     else if (geometry)