Changeset 244635 in webkit


Ignore:
Timestamp:
Apr 24, 2019 10:51:01 PM (5 years ago)
Author:
Carlos Garcia Campos
Message:

[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:

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:
Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r244541 r244635  
     12019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Set and expose to build HAVE_OS_DARK_MODE_SUPPORT=1.
     9
     10        * Source/cmake/OptionsGTK.cmake:
     11
    1122019-04-23  Don Olmstead  <don.olmstead@sony.com>
    213
  • trunk/LayoutTests/ChangeLog

    r244630 r244635  
     12019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Remove expectations for tests that are passing again.
     9
     10        * platform/gtk/TestExpectations:
     11
    1122019-04-24  Simon Fraser  <simon.fraser@apple.com>
    213
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r244629 r244635  
    11771177webkit.org/b/181659 fast/canvas/webgl/simulated-vertexAttrib0-invalid-indicies.html [ Skip ]
    11781178
    1179 # When text input colors are set we do not style with GTK, so these reftests will fail
    1180 webkit.org/b/186219 fast/forms/input-placeholder-text-indent.html [ ImageOnlyFailure ]
    1181 webkit.org/b/186219 fast/forms/password-placeholder-text-security.html [ ImageOnlyFailure ]
    1182 webkit.org/b/186219 fast/forms/placeholder-with-positioned-element.html [ ImageOnlyFailure ]
    1183 webkit.org/b/186219 fast/forms/textarea-placeholder-wrapping.html [ ImageOnlyFailure ]
    1184 
    11851179# This seems to be testing Apple-specific behavior?
    11861180css3/color-filters/color-filter-ignore-semantic.html [ ImageOnlyFailure ]
  • trunk/Source/WTF/ChangeLog

    r244600 r244635  
     12019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Define HAVE_OS_DARK_MODE_SUPPORT for GTK port.
     9
     10        * wtf/Platform.h:
     11
    1122019-04-24  Tim Horton  <timothy_horton@apple.com>
    213
  • trunk/Source/WTF/wtf/Platform.h

    r244600 r244635  
    14171417#endif
    14181418
    1419 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
     1419#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(GTK)
    14201420#define HAVE_OS_DARK_MODE_SUPPORT 1
    14211421#endif
  • trunk/Source/WebCore/CMakeLists.txt

    r244582 r244635  
    16831683endif ()
    16841684
     1685if (HAVE_OS_DARK_MODE_SUPPORT)
     1686    set(FEATURE_DEFINES_WITH_SPACE_SEPARATOR "${FEATURE_DEFINES_WITH_SPACE_SEPARATOR} HAVE_OS_DARK_MODE_SUPPORT")
     1687endif ()
     1688
    16851689set(WebCoreTestSupport_PRIVATE_INCLUDE_DIRECTORIES
    16861690    "${WEBCORE_DIR}/platform/mock"
  • trunk/Source/WebCore/ChangeLog

    r244633 r244635  
     12019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Enable HAVE_OS_DARK_MODE_SUPPORT for GTK port to ensure that dark mode is used when Page::useDarkAppearance()
     9        returns true. This patch reverts r232913, I'll reopen the bug, I think we need to find a better solution for
     10        that.
     11
     12        * CMakeLists.txt: Add HAVE_OS_DARK_MODE_SUPPORT to FEATURE_DEFINES_WITH_SPACE_SEPARATOR if enabled.
     13        * css/CSSDefaultStyleSheets.cpp: Ensure html{color:text} is used in simple style sheet when
     14        HAVE_OS_DARK_MODE_SUPPORT is enabled.
     15        * page/FrameView.cpp:
     16        (WebCore::FrameView::updateBackgroundRecursively): Use CSSValueWindowframe to get the frame view background
     17        color when HAVE_OS_DARK_MODE_SUPPORT is enabled for non-mac ports.
     18        * platform/gtk/RenderThemeWidget.cpp:
     19        (WebCore::RenderThemeWidget::getOrCreate): Create window widget.
     20        (WebCore::RenderThemeWindow::RenderThemeWindow): Add window widget.
     21        * platform/gtk/RenderThemeWidget.h:
     22        * rendering/RenderThemeGtk.cpp:
     23        (WebCore::RenderThemeGtk::disabledTextColor const): Always use the color from the theme for consistency with
     24        other form controls.
     25        (WebCore::RenderThemeGtk::systemColor const): Get the color from the theme for CSSValueText, CSSValueGraytext
     26        and CSSValueWindowframe.
     27        * rendering/RenderThemeGtk.h:
     28
    1292019-04-24  Zalan Bujtas  <zalan@apple.com>
    230
  • trunk/Source/WebCore/css/CSSDefaultStyleSheets.cpp

    r244440 r244635  
    8282
    8383// FIXME: It would be nice to use some mechanism that guarantees this is in sync with the real UA stylesheet.
    84 #if PLATFORM(MAC)
    85 // The only difference in the simple style sheet for macOS is the addition of html{color:text}.
     84#if HAVE(OS_DARK_MODE_SUPPORT)
     85// The only difference in the simple style sheet for dark mode is the addition of html{color:text}.
    8686static 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}";
    8787#else
  • trunk/Source/WebCore/page/FrameView.cpp

    r244633 r244635  
    30013001void FrameView::updateBackgroundRecursively(const Optional<Color>& backgroundColor)
    30023002{
    3003 #if HAVE(OS_DARK_MODE_SUPPORT) && ENABLE(DARK_MODE_CSS)
    3004     Color baseBackgroundColor = backgroundColor.valueOr(RenderTheme::singleton().systemColor(CSSValueAppleSystemControlBackground, styleColorOptions()));
     3003#if HAVE(OS_DARK_MODE_SUPPORT)
     3004#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
     3005    static const auto cssValueControlBackground = CSSValueAppleSystemControlBackground;
     3006#else
     3007    static const auto cssValueControlBackground = CSSValueWindowframe;
     3008#endif
     3009    Color baseBackgroundColor = backgroundColor.valueOr(RenderTheme::singleton().systemColor(cssValueControlBackground, styleColorOptions()));
    30053010#else
    30063011    Color baseBackgroundColor = backgroundColor.valueOr(Color::white);
  • trunk/Source/WebCore/platform/gtk/RenderThemeWidget.cpp

    r241654 r244635  
    8686        case RenderThemeWidget::Type::Icon:
    8787            return std::make_unique<RenderThemeIcon>();
     88        case RenderThemeWidget::Type::Window:
     89            return std::make_unique<RenderThemeWindow>();
    8890        }
    8991        ASSERT_NOT_REACHED();
     
    294296}
    295297
     298RenderThemeWindow::RenderThemeWindow()
     299    : m_window(RenderThemeGadget::create({ RenderThemeGadget::Type::Generic, "window", { "background" } }))
     300{
     301}
     302
    296303} // namepsace WebCore
    297304
  • trunk/Source/WebCore/platform/gtk/RenderThemeWidget.h

    r217702 r244635  
    6060        ListView,
    6161        Icon,
     62        Window,
    6263    };
    6364    static RenderThemeWidget& getOrCreate(Type);
     
    234235};
    235236
     237class RenderThemeWindow final : public RenderThemeWidget {
     238public:
     239    RenderThemeWindow();
     240    ~RenderThemeWindow() = default;
     241
     242    RenderThemeGadget& window() const { return *m_window; }
     243
     244private:
     245    std::unique_ptr<RenderThemeGadget> m_window;
     246
     247};
     248
    236249} // namespace WebCore
    237250
  • trunk/Source/WebCore/rendering/RenderThemeGtk.cpp

    r240437 r244635  
    168168    MediaButton,
    169169#endif
     170#if GTK_CHECK_VERSION(3, 20, 0)
     171    Window,
     172#endif
    170173};
    171174
     
    927930}
    928931
    929 bool RenderThemeGtk::isControlStyled(const RenderStyle& style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const
    930 {
    931     // To avoid rendering issues with dark themes, if text input elements have color styling, we don't style them with GTK.
    932     if ((style.appearance() == TextFieldPart || style.appearance() == TextAreaPart || style.appearance() == SearchFieldPart) && style.color() != RenderStyle::initialColor())
    933         return true;
    934 
    935     return RenderTheme::isControlStyled(style, border, background, backgroundColor);
    936 }
    937 
    938932#if GTK_CHECK_VERSION(3, 20, 0)
    939933
     
    17071701        gadget = &static_cast<RenderThemeButton&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Button)).button();
    17081702        break;
     1703    case Window:
     1704        gadget = &static_cast<RenderThemeWindow&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Window)).window();
     1705        break;
    17091706    }
    17101707
     
    17681765}
    17691766
     1767Color RenderThemeGtk::disabledTextColor(const Color&, const Color&) const
     1768{
     1769    return styleColor(Entry, GTK_STATE_FLAG_INSENSITIVE, StyleColorForeground);
     1770}
     1771
    17701772Color RenderThemeGtk::systemColor(CSSValueID cssValueId, OptionSet<StyleColor::Options> options) const
    17711773{
     
    17751777    case CSSValueCaptiontext:
    17761778        return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
     1779    case CSSValueText:
     1780        return styleColor(Entry, GTK_STATE_FLAG_ACTIVE, StyleColorForeground);
     1781    case CSSValueGraytext:
     1782        return styleColor(Entry, GTK_STATE_FLAG_INSENSITIVE, StyleColorForeground);
     1783#if GTK_CHECK_VERSION(3, 20, 0)
     1784    case CSSValueWindowframe:
     1785        return styleColor(Window, GTK_STATE_FLAG_ACTIVE, StyleColorBackground);
     1786#endif
    17771787    default:
    17781788        return RenderTheme::systemColor(cssValueId, options);
  • trunk/Source/WebCore/rendering/RenderThemeGtk.h

    r232913 r244635  
    8181    Color platformInactiveListBoxSelectionBackgroundColor(OptionSet<StyleColor::Options>) const override;
    8282    Color platformInactiveListBoxSelectionForegroundColor(OptionSet<StyleColor::Options>) const override;
     83
     84    Color disabledTextColor(const Color&, const Color&) const override;
    8385
    8486    Seconds caretBlinkInterval() const override;
     
    169171#endif
    170172
    171     bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer&, const Color&) const override;
    172 
    173173    Seconds animationRepeatIntervalForProgressBar(RenderProgress&) const override;
    174174    Seconds animationDurationForProgressBar(RenderProgress&) const override;
  • trunk/Source/WebKit/ChangeLog

    r244633 r244635  
     12019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Implement PageClient::effectiveAppearanceIsDark() for GTK port.
     9
     10        * UIProcess/API/gtk/PageClientImpl.cpp:
     11        (WebKit::PageClientImpl::effectiveAppearanceIsDark const): Check if gtk-application-prefer-dark-theme setting is
     12        enabled, or the theme name contains the -dark suffix or the GTK_THEME environment variable contains the :dark suffix.
     13        * UIProcess/API/gtk/PageClientImpl.h:
     14        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     15        (themeChanged): Notify the WebPageProxy that the theme has changed.
     16        (webkitWebViewBaseSetToplevelOnScreenWindow): Connect to notify::gtk-application-prefer-dark-theme and notify::gtk-theme-name.
     17        * WebProcess/WebPage/WebPage.cpp:
     18        * WebProcess/WebPage/gtk/WebPageGtk.cpp:
     19        (WebKit::WebPage::setUseDarkAppearance): Set gtk-application-prefer-dark-theme setting accordingly.
     20
    1212019-04-24  Zalan Bujtas  <zalan@apple.com>
    222
  • trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.cpp

    r243847 r244635  
    534534}
    535535
     536bool PageClientImpl::effectiveAppearanceIsDark() const
     537{
     538    auto* settings = gtk_widget_get_settings(m_viewWidget);
     539    gboolean preferDarkTheme;
     540    g_object_get(settings, "gtk-application-prefer-dark-theme", &preferDarkTheme, nullptr);
     541    if (preferDarkTheme)
     542        return true;
     543
     544    GUniqueOutPtr<char> themeName;
     545    g_object_get(settings, "gtk-theme-name", &themeName.outPtr(), nullptr);
     546    if (g_str_has_suffix(themeName.get(), "-dark"))
     547        return true;
     548
     549    if (auto* themeNameEnv = g_getenv("GTK_THEME"))
     550        return g_str_has_suffix(themeNameEnv, ":dark");
     551
     552    return false;
     553}
     554
    536555} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/API/gtk/PageClientImpl.h

    r243847 r244635  
    163163    WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return WebCore::UserInterfaceLayoutDirection::LTR; }
    164164
     165    bool effectiveAppearanceIsDark() const override;
     166
    165167    // Members of PageClientImpl class
    166168    GtkWidget* m_viewWidget;
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r244500 r244635  
    184184    unsigned long toplevelWindowStateEventID { 0 };
    185185    unsigned long toplevelWindowRealizedID { 0 };
     186    unsigned long themeChangedID { 0 };
     187    unsigned long applicationPreferDarkThemeID { 0 };
    186188
    187189    // View State.
     
    266268}
    267269
     270static void themeChanged(WebKitWebViewBase* webViewBase)
     271{
     272    webViewBase->priv->pageProxy->effectiveAppearanceDidChange();
     273}
     274
    268275static void toplevelWindowRealized(WebKitWebViewBase* webViewBase)
    269276{
     
    298305        g_signal_handler_disconnect(priv->toplevelOnScreenWindow, priv->toplevelWindowRealizedID);
    299306        priv->toplevelWindowRealizedID = 0;
     307    }
     308    if (priv->themeChangedID || priv->applicationPreferDarkThemeID) {
     309        auto* settings = gtk_widget_get_settings(GTK_WIDGET(priv->toplevelOnScreenWindow));
     310        if (priv->themeChangedID) {
     311            g_signal_handler_disconnect(settings, priv->themeChangedID);
     312            priv->themeChangedID = 0;
     313        }
     314        if (priv->applicationPreferDarkThemeID) {
     315            g_signal_handler_disconnect(settings, priv->applicationPreferDarkThemeID);
     316            priv->applicationPreferDarkThemeID = 0;
     317        }
    300318    }
    301319
     
    326344    priv->toplevelWindowStateEventID =
    327345        g_signal_connect(priv->toplevelOnScreenWindow, "window-state-event", G_CALLBACK(toplevelWindowStateEvent), webViewBase);
     346
     347    auto* settings = gtk_widget_get_settings(GTK_WIDGET(priv->toplevelOnScreenWindow));
     348    priv->themeChangedID =
     349        g_signal_connect_swapped(settings, "notify::gtk-theme-name", G_CALLBACK(themeChanged), webViewBase);
     350    priv->applicationPreferDarkThemeID =
     351        g_signal_connect_swapped(settings, "notify::gtk-application-prefer-dark-theme", G_CALLBACK(themeChanged), webViewBase);
    328352
    329353    if (gtk_widget_get_realized(GTK_WIDGET(window)))
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r244633 r244635  
    46114611#endif
    46124612
     4613#if !PLATFORM(GTK)
    46134614void WebPage::setUseDarkAppearance(bool useDarkAppearance)
    46144615{
    46154616    corePage()->setUseDarkAppearance(useDarkAppearance);
    46164617}
     4618#endif
    46174619
    46184620void WebPage::beginPrinting(uint64_t frameID, const PrintInfo& printInfo)
  • trunk/Source/WebKit/WebProcess/WebPage/gtk/WebPageGtk.cpp

    r244212 r244635  
    196196}
    197197
     198void WebPage::setUseDarkAppearance(bool useDarkAppearance)
     199{
     200    if (auto* settings = gtk_settings_get_default())
     201        g_object_set(settings, "gtk-application-prefer-dark-theme", useDarkAppearance, nullptr);
     202    corePage()->setUseDarkAppearance(useDarkAppearance);
     203}
     204
    198205} // namespace WebKit
  • trunk/Source/cmake/OptionsGTK.cmake

    r243481 r244635  
    193193SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_GESTURES ${GTK3_SUPPORTS_GESTURES})
    194194SET_AND_EXPOSE_TO_BUILD(HAVE_GTK_UNIX_PRINTING ${GTKUnixPrint_FOUND})
     195SET_AND_EXPOSE_TO_BUILD(HAVE_OS_DARK_MODE_SUPPORT 1)
    195196
    196197set(glib_components gio gio-unix gobject gthread gmodule)
  • trunk/Tools/ChangeLog

    r244633 r244635  
     12019-04-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add dark-mode command line option to MiniBrowser.
     9
     10        * MiniBrowser/gtk/main.c:
     11        (main):
     12
    1132019-04-24  Zalan Bujtas  <zalan@apple.com>
    214
  • trunk/Tools/MiniBrowser/gtk/main.c

    r244583 r244635  
    5353static const char *cookiesPolicy;
    5454static const char *proxy;
     55static gboolean darkMode;
    5556
    5657typedef enum {
     
    104105    { "bg-color", 0, 0, G_OPTION_ARG_CALLBACK, parseBackgroundColor, "Background color", NULL },
    105106    { "editor-mode", 'e', 0, G_OPTION_ARG_NONE, &editorMode, "Run in editor mode", NULL },
     107    { "dark-mode", 'd', 0, G_OPTION_ARG_NONE, &darkMode, "Run in dark mode", NULL },
    106108    { "session-file", 's', 0, G_OPTION_ARG_FILENAME, &sessionFile, "Session file", "FILE" },
    107109    { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, "Set the size and position of the window (WIDTHxHEIGHT+X+Y)", "GEOMETRY" },
     
    585587
    586588    BrowserWindow *mainWindow = BROWSER_WINDOW(browser_window_new(NULL, webContext));
     589    if (darkMode)
     590        g_object_set(gtk_widget_get_settings(GTK_WIDGET(mainWindow)), "gtk-application-prefer-dark-theme", TRUE, NULL);
    587591    if (fullScreen)
    588592        gtk_window_fullscreen(GTK_WINDOW(mainWindow));
Note: See TracChangeset for help on using the changeset viewer.