Changeset 232338 in webkit


Ignore:
Timestamp:
May 30, 2018 11:41:41 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Hardcoded text color in input fields
https://bugs.webkit.org/show_bug.cgi?id=126907

Patch by Carlos Eduardo Ramalho <cadubentzen@gmail.com> on 2018-05-30
Reviewed by Carlos Garcia Campos.

Set text color in input fields to foreground theme color.
Also, set "window.background" as base GtkStyleContext to mimic
GTK applications and fix some theme bugs.

No new tests required. ManualTests/gtk/theme.html already covers it.

  • platform/gtk/RenderThemeGadget.cpp:

(WebCore::baseStyleContext): Added.
(WebCore::RenderThemeGadget::RenderThemeGadget):
Use "window.background" GtkStyleContext instead of
null parent for RenderThemeGadgets.

  • rendering/RenderThemeGtk.cpp:

(WebCore::RenderThemeGtk::adjustButtonStyle const):
Set color as foreground theme color.
(WebCore::RenderThemeGtk::adjustTextFieldStyle const): Ditto.
(WebCore::RenderThemeGtk::adjustTextAreaStyle const): Ditto.
(WebCore::RenderThemeGtk::adjustSearchFieldStyle const): Ditto.

  • rendering/RenderThemeGtk.h: adjustTextAreaStyle() overriden.
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r232337 r232338  
     12018-05-30  Carlos Eduardo Ramalho  <cadubentzen@gmail.com>
     2
     3        [GTK] Hardcoded text color in input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=126907
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Set text color in input fields to foreground theme color.
     9        Also, set "window.background" as base GtkStyleContext to mimic
     10        GTK applications and fix some theme bugs.
     11
     12        No new tests required. ManualTests/gtk/theme.html already covers it.
     13
     14        * platform/gtk/RenderThemeGadget.cpp:
     15        (WebCore::baseStyleContext): Added.
     16        (WebCore::RenderThemeGadget::RenderThemeGadget):
     17        Use "window.background" GtkStyleContext instead of
     18        null parent for RenderThemeGadgets.
     19        * rendering/RenderThemeGtk.cpp:
     20        (WebCore::RenderThemeGtk::adjustButtonStyle const):
     21        Set color as foreground theme color.
     22        (WebCore::RenderThemeGtk::adjustTextFieldStyle const): Ditto.
     23        (WebCore::RenderThemeGtk::adjustTextAreaStyle const): Ditto.
     24        (WebCore::RenderThemeGtk::adjustSearchFieldStyle const): Ditto.
     25        * rendering/RenderThemeGtk.h: adjustTextAreaStyle() overriden.
     26
    1272018-05-30  Yusuke Suzuki  <utatane.tea@gmail.com>
    228
  • trunk/Source/WebCore/platform/gtk/RenderThemeGadget.cpp

    r223728 r232338  
    3131#include "FloatRect.h"
    3232#include "GRefPtrGtk.h"
     33#include <mutex>
    3334
    3435namespace WebCore {
     
    7374}
    7475
     76static GtkStyleContext* baseStyleContext()
     77{
     78    // Leaking here on purpose for it not to be destroyed unsafely at exit time.
     79    static GtkStyleContext* baseContext;
     80    static std::once_flag onceFlag;
     81
     82    std::call_once(onceFlag, []() {
     83        GRefPtr<GtkWidgetPath> path = adoptGRef(gtk_widget_path_new());
     84        gtk_widget_path_append_type(path.get(), GTK_TYPE_WINDOW);
     85        gtk_widget_path_iter_set_object_name(path.get(), -1, "window");
     86        gtk_widget_path_iter_add_class(path.get(), -1, GTK_STYLE_CLASS_BACKGROUND);
     87
     88        baseContext = gtk_style_context_new();
     89        gtk_style_context_set_path(baseContext, path.get());
     90        gtk_style_context_set_parent(baseContext, nullptr);
     91    });
     92
     93    return baseContext;
     94}
     95
    7596RenderThemeGadget::RenderThemeGadget(const RenderThemeGadget::Info& info, RenderThemeGadget* parent, const Vector<RenderThemeGadget::Info> siblings, unsigned position)
    7697{
     
    83104    } else
    84105        appendElementToPath(path.get(), info);
    85     m_context = createStyleContext(path.get(), parent ? parent->context() : nullptr);
     106    m_context = createStyleContext(path.get(), parent ? parent->context() : baseStyleContext());
    86107}
    87108
  • trunk/Source/WebCore/rendering/RenderThemeGtk.cpp

    r231557 r232338  
    494494#endif // GTK_CHECK_VERSION(3, 20, 0)
    495495
    496 void RenderThemeGtk::adjustButtonStyle(StyleResolver&, RenderStyle& style, const Element*) const
    497 {
     496enum StyleColorType { StyleColorBackground, StyleColorForeground };
     497
     498#if GTK_CHECK_VERSION(3, 20, 0)
     499static Color styleColor(RenderThemePart themePart, GtkStateFlags state, StyleColorType colorType)
     500{
     501    RenderThemeGadget* gadget = nullptr;
     502    switch (themePart) {
     503    default:
     504        ASSERT_NOT_REACHED();
     505        FALLTHROUGH;
     506    case Entry:
     507        gadget = &static_cast<RenderThemeEntry&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Entry)).entry();
     508        break;
     509    case EntrySelection:
     510        gadget = static_cast<RenderThemeEntry&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::SelectedEntry)).selection();
     511        break;
     512    case ListBox:
     513        gadget = &static_cast<RenderThemeListView&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::ListView)).treeview();
     514        break;
     515    case Button:
     516        gadget = &static_cast<RenderThemeButton&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Button)).button();
     517        break;
     518    }
     519
     520    ASSERT(gadget);
     521    gadget->setState(state);
     522    return colorType == StyleColorBackground ? gadget->backgroundColor() : gadget->color();
     523}
     524#else
     525static Color styleColor(RenderThemePart themePart, GtkStateFlags state, StyleColorType colorType)
     526{
     527    GRefPtr<GtkStyleContext> context = createStyleContext(themePart);
     528    gtk_style_context_set_state(context.get(), state);
     529
     530    GdkRGBA gdkRGBAColor;
     531    if (colorType == StyleColorBackground)
     532        gtk_style_context_get_background_color(context.get(), state, &gdkRGBAColor);
     533    else
     534        gtk_style_context_get_color(context.get(), state, &gdkRGBAColor);
     535    return gdkRGBAColor;
     536}
     537#endif // GTK_CHECK_VERSION(3, 20, 0)
     538
     539void RenderThemeGtk::adjustButtonStyle(StyleResolver&, RenderStyle& style, const Element* element) const
     540{
     541    if (element)
     542        style.setColor(styleColor(Button, element->isDisabledFormControl() ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL, StyleColorForeground));
    498543    // Some layout tests check explicitly that buttons ignore line-height.
    499544    if (style.appearance() == PushButtonPart)
     
    946991void RenderThemeGtk::adjustTextFieldStyle(StyleResolver&, RenderStyle& style, const Element* element) const
    947992{
     993    if (element)
     994        style.setColor(styleColor(Entry, element->isDisabledFormControl() ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL, StyleColorForeground));
     995
    948996    if (!is<HTMLInputElement>(element) || !shouldHaveSpinButton(downcast<HTMLInputElement>(*element)))
    949997        return;
     
    10811129}
    10821130#endif
     1131
     1132void RenderThemeGtk::adjustTextAreaStyle(StyleResolver&, RenderStyle& style, const Element* element) const
     1133{
     1134    if (element)
     1135        style.setColor(styleColor(Entry, element->isDisabledFormControl() ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL, StyleColorForeground));
     1136}
    10831137
    10841138bool RenderThemeGtk::paintTextArea(const RenderObject& o, const PaintInfo& i, const FloatRect& r)
     
    12011255#endif // GTK_CHECK_VERSION(3, 20, 0)
    12021256
    1203 void RenderThemeGtk::adjustSearchFieldStyle(StyleResolver&, RenderStyle& style, const Element*) const
    1204 {
     1257void RenderThemeGtk::adjustSearchFieldStyle(StyleResolver&, RenderStyle& style, const Element* element) const
     1258{
     1259    if (element)
     1260        style.setColor(styleColor(Entry, element->isDisabledFormControl() ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL, StyleColorForeground));
    12051261    // We cannot give a proper rendering when border radius is active, unfortunately.
    12061262    style.resetBorderRadius();
     
    16741730}
    16751731
    1676 enum StyleColorType { StyleColorBackground, StyleColorForeground };
    1677 
    1678 #if GTK_CHECK_VERSION(3, 20, 0)
    1679 static Color styleColor(RenderThemePart themePart, GtkStateFlags state, StyleColorType colorType)
    1680 {
    1681     RenderThemeGadget* gadget = nullptr;
    1682     switch (themePart) {
    1683     default:
    1684         ASSERT_NOT_REACHED();
    1685         FALLTHROUGH;
    1686     case Entry:
    1687         gadget = &static_cast<RenderThemeEntry&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Entry)).entry();
    1688         break;
    1689     case EntrySelection:
    1690         gadget = static_cast<RenderThemeEntry&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::SelectedEntry)).selection();
    1691         break;
    1692     case ListBox:
    1693         gadget = &static_cast<RenderThemeListView&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::ListView)).treeview();
    1694         break;
    1695     case Button:
    1696         gadget = &static_cast<RenderThemeButton&>(RenderThemeWidget::getOrCreate(RenderThemeWidget::Type::Button)).button();
    1697         break;
    1698     }
    1699 
    1700     ASSERT(gadget);
    1701     gadget->setState(state);
    1702     return colorType == StyleColorBackground ? gadget->backgroundColor() : gadget->color();
    1703 }
    1704 #else
    1705 static Color styleColor(RenderThemePart themePart, GtkStateFlags state, StyleColorType colorType)
    1706 {
    1707     GRefPtr<GtkStyleContext> context = createStyleContext(themePart);
    1708     gtk_style_context_set_state(context.get(), state);
    1709 
    1710     GdkRGBA gdkRGBAColor;
    1711     if (colorType == StyleColorBackground)
    1712         gtk_style_context_get_background_color(context.get(), state, &gdkRGBAColor);
    1713     else
    1714         gtk_style_context_get_color(context.get(), state, &gdkRGBAColor);
    1715     return gdkRGBAColor;
    1716 }
    1717 #endif // GTK_CHECK_VERSION(3, 20, 0)
    1718 
    17191732Color RenderThemeGtk::platformActiveSelectionBackgroundColor() const
    17201733{
  • trunk/Source/WebCore/rendering/RenderThemeGtk.h

    r231557 r232338  
    119119    void adjustTextFieldStyle(StyleResolver&, RenderStyle&, const Element*) const override;
    120120    bool paintTextField(const RenderObject&, const PaintInfo&, const FloatRect&) override;
     121
     122    void adjustTextAreaStyle(StyleResolver&, RenderStyle&, const Element*) const override;
    121123    bool paintTextArea(const RenderObject&, const PaintInfo&, const FloatRect&) override;
    122124
Note: See TracChangeset for help on using the changeset viewer.