Commit Graph

418 Commits

Author SHA1 Message Date
Benjamin Otte
73b3b9ee94 stylecontext: Rename function and export it.
The name now better reflects what it does, since GtkCssComputedValues
was renamed to GtkCssStyle, too.
2015-01-20 01:23:18 +01:00
Benjamin Otte
dbb8d1dd07 stylecontext: Keep track of the CSS ID
This is necessary since we do the new caching and need to distinguish
between styles with different IDs.

Fixes various test cases.
2015-01-20 01:07:13 +01:00
Benjamin Otte
cbabb2e6ff stylecontext: Fix FALSE/TRUE mixup
Introduced in e649c8773f. It's obviously
the root node right there.
2015-01-19 02:19:59 +01:00
Benjamin Otte
0fef59b486 stylecontext: Be more graceful when save() isn't matched with restore()
Instead of asserting, just print a g_warning() and try to work around
the problem.
I hope that g_warning() isn't too spammy for people that are hit with
it.

Also clarify the docs that not restore()ing after a save() is a bad
idea.

https://bugzilla.gnome.org/show_bug.cgi?id=743101
2015-01-19 01:12:50 +01:00
Benjamin Otte
e649c8773f stylecontext: Explicitly specify root node
When creating the query path, explicitly specify if it's for a root node
or for a child. Relying on gtk_style_context_is_saved() is unreliable
(for example when updating the cache).
2015-01-19 01:12:50 +01:00
Benjamin Otte
d0ed29d58d stylecontext: Remove a bunch of return_if_fail()s
They're gonna be in the way when refactoring and we can live without
them.
2015-01-17 02:25:40 +01:00
Benjamin Otte
63f7a36ae0 stylecontext: Do not transition from the default style
This gets rid of a bunch of awkward transitions. It's not a perfect
solution to the problem of "should we transition from this state" but it
gets rid of the ugliest offenders.
2015-01-17 02:25:40 +01:00
Benjamin Otte
cec5815a0d stylecontext: Stop animations on manual invalidation
If a gtk_style_context_invalidate() is called on a widget's style
context (which nobody should ever do, sheesh!) and we're animating, stop
the animations.

Fixes crashers in Nautilus.
2015-01-10 14:25:40 +01:00
Benjamin Otte
29984c5282 stylecontext: Handle theme changes for cached styles
We need to clear the cache manually on full revalidates because
_gtk_css_change_for_child() will clear the full revalidation flags.
And then gtk_style_context_update_cache() will not do the right thing
(which is to clear itself).
2015-01-07 18:06:59 +01:00
Benjamin Otte
bc07a540c7 stylecontext: Rename GtkStyleInfo to GtkCssNode 2015-01-07 15:44:53 +01:00
Benjamin Otte
2664082549 stylecontext: update_animating() properly
Because we can switch from animating to non-animating pretty much
anywhere, do the check for animations unconditionally instead of trying
to cram it into the correct if path (and failing).
2015-01-07 14:26:48 +01:00
Benjamin Otte
fe33ee426a stylecontext: Add a parent style cache
We now cache the results of lookups on the parent GtkCssStyle. This
allows sharing styles between widgets (recursively). However, this
only works if the styles can't potentially depend on siblings -
neither directly via sibling selectors or via position pseudo-classes
like :first-child.
Unfortunately, Adwaita currently uses first-child a lot, and in
particular for labels, which are the most common widgets.

The big benefits of this change are both less CPU - due to not needing
to compute styles again - and less memory usage - due to sharing of
the styles between widgets. Here's some nonscientific numbers I
collected while pondering the usefulness of this patch:

                    glade   glade   widget
                    demo    demo    factory
                    runtime styles  styles
Adwaita before      19.1s   5800    1150
Adwaita now         18.9s   3800     970
Adwaita hacked now  14.5s   3100     910
simple before       11.3s   5800    1150
simple now          10.8s   1300     590

Adwaita: Adwaita as provided by GTK
Adwaita hacked: Adwaita with the first/last-child for GtkLabel removed
simple: A 250 lines simple GTK theme I use for testing
before: This patch not applied
now: this patch applied

glade demo runtime: Starting glade opening a large file and closing it
glade demo styles: GtkCssStaticStyle objects after opening glade with
                   the large file as per inspector
widget factory styles: GtkCssStaticStyle objects after startup as per
                       inspector
2015-01-07 14:26:48 +01:00
Benjamin Otte
27285f1f0f cssstyle: Have a default style
This way we can initialize the default style info with a style and
ddon't need to special case NULL everywhere.
2015-01-07 14:26:48 +01:00
Benjamin Otte
ef9aa8b0ae stylecontext: Use correct parent on updates
Previously we looked at the save/restore state when determining the
parent. This is wrong in the case where we're updating the cache though.

So we now save the parent in the style info.
2015-01-07 14:26:48 +01:00
Benjamin Otte
89b5d15415 stylecontext: Fix cache updating
After the parent changes in commit
3a337156d1 we need to refresh the cached
styles after the current style. After all, they now depend on the base
style.
2015-01-07 14:26:48 +01:00
Benjamin Otte
730f429168 cssstaticstyle: Handle relevant change
Relevant change is returned from style lookups, so keep is with the
object that holds those values.
2015-01-07 14:26:48 +01:00
Benjamin Otte
ad199e4cf9 stylecontext: Use correct parent style for lookups
After 3a337156d1 style lookups still used
the parent context's style as the parent style, even though after a
gtk_style_context_save() the root style of the style context is the
proper parent.

Testcase attached.
2015-01-07 14:26:48 +01:00
Benjamin Otte
26f36ef8ae cssnodedeclaration: Store the GType of the node 2015-01-07 14:26:48 +01:00
Benjamin Otte
cd056adb2f cssstaticstyle: Move function
And with that move, GtkCssStaticStyle is immutable.
2015-01-07 14:26:47 +01:00
Benjamin Otte
8b823d7e13 cssstaticstyle: Move function
We want the new() return values to be immutable, so we have to move the
code that modifes them.
2015-01-07 14:26:47 +01:00
Benjamin Otte
b7be202089 stylecontext: Refactor update_properties()
It now always returns a new instance.
2015-01-07 14:26:47 +01:00
Benjamin Otte
7406ec84bc stylecontext: Simplify function
Instead of computing the changes manually everywhere from the parent
changes, just pass in the parent changes.
2015-01-07 14:26:47 +01:00
Benjamin Otte
c0af2d6fa6 stylecontext: Simplify code
Compute the differences only once and not in both if branches.
2015-01-07 14:26:47 +01:00
Benjamin Otte
7493e814a9 cssanimatedstyle: Apply animation values after creation
This makes GtkCssAnimatedStyle immutable.
2015-01-07 14:26:47 +01:00
Benjamin Otte
a3bf910585 cssanimatedstyle: Make advancing the style return a new style
This is another step towards making CssStyles immutable.
2015-01-07 14:26:47 +01:00
Benjamin Otte
b53d5d0643 stylecontext: Fold a function into only caller 2015-01-07 14:26:47 +01:00
Benjamin Otte
f3f021106d cssanimatedstyle: Avoid creating animation
... when no animation exists.

This makes the function name kinda wrong, but I'm not sure what else to
call it.
2015-01-07 14:26:47 +01:00
Benjamin Otte
980923c761 cssanimatedstyle: Merge two functions 2015-01-07 14:26:47 +01:00
Benjamin Otte
0bab285fe0 stylecontext: Make build_properties create the style 2015-01-07 14:26:47 +01:00
Benjamin Otte
79f7392109 stylecontext: Make static styles static
Instead of keeping an animated style everywhere, we replace it with the
static style when nothing gets animated.

Apart from making the code cleaner, this gets rid of a bunch of animated
style values that do nothing but wrap a static style.
2015-01-07 14:26:47 +01:00
Benjamin Otte
db36ee36a6 stylecontext: Split function 2015-01-07 14:26:47 +01:00
Benjamin Otte
85dd685b3f stylecontext: Only look up stuff in the cache that can be in the cache
Only saved styles are stored in the cache so we should look only those
up there.
2015-01-07 14:26:47 +01:00
Benjamin Otte
77b876fad3 stylecontext: don't unset the current style info when clearing cache
Instead, do it manually.
2015-01-07 14:26:47 +01:00
Benjamin Otte
270e73bfcc stylecontext: Always pass the static style
... to build_properties.
There is always one available, so we can insist on that one.

This simplifies a bunch of code.
2015-01-07 14:26:47 +01:00
Benjamin Otte
c7e9489e3e stylecontext: Use a static style when saved
The only style that is animated is the style of the unsaved primary
node. So there's no need to create animated style objects for the other
ones.

There is a bunch of ugliness in the code currently. Further commits are
expected to fix them.
2015-01-07 14:26:47 +01:00
Benjamin Otte
4168e0385e cssstyle: Split into GtkCssStyle and GtkCssAnimatedStyle
GtkCssStyle is the base class to be used for all types of styles that do
exist.

GtkCssAnimatedStyle is the only implementation so far, that is exactly a
copy/paste of the old GtkCssStyle code.
2015-01-07 14:26:46 +01:00
Benjamin Otte
572f46067f cssstyle: Rename GtkCssComputedValues => GtkCssStyle
This is literally just renaming of the object (and the associated source
files). No other changes are in there.
2015-01-07 14:26:46 +01:00
Jasper St. Pierre
5a41f63426 gtkstylecontext: Don't try to emit a signal when finalizing 2014-12-28 18:13:34 -08:00
Benjamin Otte
1cb3734924 stylecontext: Make sure we always clear the cache when the CSS changes
After b49c7c3421 we were no longer doing a
full revalidate after GTK_CSS_CHANGE_SOURCE changes.

This fixes spurious failures of widgets not properly updating when
changing the theme.
2014-12-13 03:45:08 +01:00
Benjamin Otte
b49c7c3421 styleprovider: Fold get_change() vfunc into lookup() 2014-12-10 03:49:40 +01:00
Jasper St. Pierre
9c7a5f5efa gtkstylecontext: Optimize GtkStyleContext usage 2014-11-26 18:10:55 -08:00
Jasper St. Pierre
eba317228f gtkstylecontext: Add an optional warning when misusing GtkStyleContext
This allows someone to quickly debug more performance issues with
G_DEBUG=fatal-warnings.
2014-11-25 11:07:31 -08:00
Matthias Clasen
4590501854 Properly update the style cascade on screen change
GtkStyleContext was not properly handling the style cascade when
setting a screen, causing the inspector global CSS to affect the
inspector window, even though the inspector is using a different
screen now.
2014-10-24 16:23:07 -04:00
Benjamin Otte
433c20e59d styleproperties: Remove header where it's not used 2014-10-24 21:31:40 +02:00
Benjamin Otte
8abc6e06b2 css: Add "-gtk-icon-source: builtin"
... and make it the default. This takes over the meaning from "none" for
this property in that it draws the fallback builtin image.
"none" now literally means no image will be drawn.
2014-10-21 05:53:19 +02:00
Benjamin Otte
7eb3b6c71f stylecontext: fix icon-source extents computation
for the builtin image or invalid matrix case. We used to return invalid
memory in those cases. And that was not good.
2014-10-21 05:53:19 +02:00
Benjamin Otte
a3995d8c86 stylecontext: Handle querying the wrong state better
When a getter function (like get_color()) is called and the passed in
state doesn't match the current state returned via get_state(), we used
to do a trick: We called save()/set_state() on the context before
getting the values.

Unfortunately, since 3a337156d1 this
has the unfortunate side effect that it also creates a child element.
This breaks various old codebases (spinbutton has been fixed in
998feeb2bc, Webkit is fixed in
https://bugs.webkit.org/show_bug.cgi?id=137803 ) unfortunately.

So instead, look up the values manually ensuring that no child element
is created but the correct state is used.
2014-10-21 03:03:28 +02:00
Benjamin Otte
caf709bb81 stylecontext: Return a ref in lookup_values_for_state
This will be necessary when we stop caching values for lookups with the
"wrong" state.
2014-10-21 03:03:28 +02:00
Benjamin Otte
4cc4e18d56 stylecontext: Don't copy CSS values on context_save()
Keeping them is a bad idea now where the widget paths are actually
changed by a save(). And almost all of the time, state or style classes
will be changed anyway.

Looking them up again is just a hash table lookup anyway.
2014-10-21 03:03:28 +02:00
Benjamin Otte
57cafc277b stylecontext: Use node declaration in hash
Don't use the StyleInfo anymore.
2014-10-21 03:03:28 +02:00