Skip to content
Permalink
Browse files
[GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al.…
… should not clobber state of cached GtkStyleContexts

https://bugs.webkit.org/show_bug.cgi?id=151533

Reviewed by Carlos Garcia Campos.

platformActiveSelectionBackgroundColor(), platformInactiveSelectionBackgroundColor(), etc.
are const functions intended only to return a color used for painting, but since r174929
they also change the state of the cached style contexts we use for GTK_TYPE_ENTRY and
GTK_TYPE_TREE_VIEW. That's wrong; those style contexts should not have any state set. This
could cause theme colors returned by those GtkStyleContexts to change unexpectedly,
depending on whether the state is explicitly set before each use, or whether the theme
actually uses the states.

This didn't cause any regression only because every place using these style contexts
explicitly sets the state of the style contexts before use. In fact, the GtkTreeView style
context is not used anywhere else, and the GtkEntry style context is only used in
paintTextField, which does set the state before use (and then reverts it using
save/restore), so this cannot have broken anything in practice. But it's a landmine waiting
for the next programmer to trip it.

Fix this with a gtk_style_context_save()/gtk_style_context_restore() pair.

* rendering/RenderThemeGtk.cpp:
(WebCore::styleColor):


Canonical link: https://commits.webkit.org/169689@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192727 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Michael Catanzaro committed Nov 22, 2015
1 parent 16c7f16 commit 3136918b9899c9ad16462a287045fb1cd45313ac
Showing with 30 additions and 2 deletions.
  1. +27 −0 Source/WebCore/ChangeLog
  2. +3 −2 Source/WebCore/rendering/RenderThemeGtk.cpp
@@ -1,3 +1,30 @@
2015-11-22 Michael Catanzaro <mcatanzaro@igalia.com>

[GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al. should not clobber state of cached GtkStyleContexts
https://bugs.webkit.org/show_bug.cgi?id=151533

Reviewed by Carlos Garcia Campos.

platformActiveSelectionBackgroundColor(), platformInactiveSelectionBackgroundColor(), etc.
are const functions intended only to return a color used for painting, but since r174929
they also change the state of the cached style contexts we use for GTK_TYPE_ENTRY and
GTK_TYPE_TREE_VIEW. That's wrong; those style contexts should not have any state set. This
could cause theme colors returned by those GtkStyleContexts to change unexpectedly,
depending on whether the state is explicitly set before each use, or whether the theme
actually uses the states.

This didn't cause any regression only because every place using these style contexts
explicitly sets the state of the style contexts before use. In fact, the GtkTreeView style
context is not used anywhere else, and the GtkEntry style context is only used in
paintTextField, which does set the state before use (and then reverts it using
save/restore), so this cannot have broken anything in practice. But it's a landmine waiting
for the next programmer to trip it.

Fix this with a gtk_style_context_save()/gtk_style_context_restore() pair.

* rendering/RenderThemeGtk.cpp:
(WebCore::styleColor):

2015-11-21 Myles C. Maxfield <mmaxfield@apple.com>

Tiny cleanup in ComplexTextController::collectComplexTextRuns()
@@ -1348,16 +1348,17 @@ enum StyleColorType { StyleColorBackground, StyleColorForeground };

static Color styleColor(GType widgetType, GtkStateFlags state, StyleColorType colorType)
{

GtkStyleContext* context = getStyleContext(widgetType);
// Recent GTK+ versions (> 3.14) require to explicitly set the state before getting the color.
gtk_style_context_save(context);
gtk_style_context_set_state(context, state);

GdkRGBA gdkRGBAColor;
if (colorType == StyleColorBackground)
gtk_style_context_get_background_color(context, gtk_style_context_get_state(context), &gdkRGBAColor);
else
gtk_style_context_get_color(context, gtk_style_context_get_state(context), &gdkRGBAColor);

gtk_style_context_restore(context);
return gdkRGBAColor;
}

0 comments on commit 3136918

Please sign in to comment.