Bug 151533 - [GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al. should not clobber state of cached GtkStyleContexts
Summary: [GTK] RenderThemeGtk::platformActiveSelectionBackgroundColor, et. al. should ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: Other
Hardware: PC Linux
: P2 Normal
Assignee: Michael Catanzaro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-21 11:27 PST by Michael Catanzaro
Modified: 2015-12-10 02:16 PST (History)
7 users (show)

See Also:


Attachments
Patch (2.60 KB, patch)
2015-11-21 11:50 PST, Michael Catanzaro
no flags Details | Formatted Diff | Diff
Patch (2.99 KB, patch)
2015-11-21 12:48 PST, Michael Catanzaro
no flags Details | Formatted Diff | Diff
Patch (41.70 KB, patch)
2015-12-09 10:47 PST, Michael Catanzaro
no flags Details | Formatted Diff | Diff
Patch (41.94 KB, patch)
2015-12-10 01:18 PST, Michael Catanzaro
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Catanzaro 2015-11-21 11:27:59 PST
platformActiveSelectionBackgroundColor(), platformInactiveSelectionBackgroundColor(), etc. are const functions intended only to return a color used for painting, but they also change the state of the cached GtkStyleContexts we use for GTK_TYPE_ENTRY and GTK_TYPE_TREE_VIEW. This could cause theme colors returned by those GtkStyleContexts to change unexpectedly.

At first I thought this was a regression I introduced in r192723, but it was actually introduced about a year ago.
Comment 1 Michael Catanzaro 2015-11-21 11:48:10 PST
(In reply to comment #0)
> This could cause theme colors returned by those GtkStyleContexts to change unexpectedly.

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.
Comment 2 Michael Catanzaro 2015-11-21 11:50:38 PST
Created attachment 266029 [details]
Patch
Comment 3 Michael Catanzaro 2015-11-21 12:48:03 PST
Created attachment 266031 [details]
Patch
Comment 4 WebKit Commit Bot 2015-11-22 00:50:46 PST
Comment on attachment 266031 [details]
Patch

Clearing flags on attachment: 266031

Committed r192727: <http://trac.webkit.org/changeset/192727>
Comment 5 WebKit Commit Bot 2015-11-22 00:50:49 PST
All reviewed patches have been landed.  Closing bug.
Comment 6 Carlos Garcia Campos 2015-11-22 02:49:01 PST
Reverted r192727 for reason:

It made the selections transparent again and broke /webkit2/WebKitWebView/snapshot

Committed r192731: <http://trac.webkit.org/changeset/192731>
Comment 7 Michael Catanzaro 2015-11-23 17:57:05 PST
(In reply to comment #1)
> (In reply to comment #0)
> > This could cause theme colors returned by those GtkStyleContexts to change unexpectedly.
> 
> 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.

I missed that this function is sometimes called with the GtkButton style context, so I see that this patch could affect the results of RenderThemeGtk::paintButton and RenderThemeGtk::paintMenuList (presumably for the better). But I frankly have no clue how it broke selections. I need to investigate closer.
Comment 8 Michael Catanzaro 2015-12-03 02:17:00 PST
(In reply to comment #7)
> I missed that this function is sometimes called with the GtkButton style
> context, so I see that this patch could affect the results of
> RenderThemeGtk::paintButton

This might be causing GNOME #758968
Comment 9 Michael Catanzaro 2015-12-09 10:47:27 PST
Created attachment 267022 [details]
Patch
Comment 10 Carlos Garcia Campos 2015-12-10 00:20:32 PST
Comment on attachment 267022 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=267022&action=review

Ok, let's try it out.

> Source/WebCore/rendering/RenderThemeGtk.cpp:398
> -    GtkStyleContext* context = 0;
> +    GRefPtr<GtkStyleContext> context = nullptr;

GRefPtr is already nullptr initialized.
Comment 11 Michael Catanzaro 2015-12-10 01:18:19 PST
Created attachment 267078 [details]
Patch
Comment 12 WebKit Commit Bot 2015-12-10 02:15:57 PST
Comment on attachment 267078 [details]
Patch

Clearing flags on attachment: 267078

Committed r193896: <http://trac.webkit.org/changeset/193896>
Comment 13 WebKit Commit Bot 2015-12-10 02:16:01 PST
All reviewed patches have been landed.  Closing bug.