Commit Graph

76 Commits

Author SHA1 Message Date
Benjamin Otte
78223932c5 cssselector: Reintroduce GOT_MATCH
I removed it in 14f5ce7108 because I
thought it was unnecessary, but it wasn't. When we build a tree like
this:

.matches ─┬─ .doesntmatch
          └─ .alsodoesntmatch

We would get the changes for the .matches part returned. This is however
only right if that node of the tree contains results. If results only
exist with the child nodes (all of which don't match), then this part
should not match either.
2015-01-05 21:20:26 +01:00
Benjamin Otte
506639add1 cssselector: The if was the wrong way around
We want to keep matching as long as selectors are simple. Otherwise we'd
never be matching, because the first selector is always simple. Oops.
2015-01-05 21:20:26 +01:00
Benjamin Otte
3e9067ce1c cssselector: Reserve more bits for enum
Apparently some compilers make enums an int and then we get negative
values.

https://bugzilla.gnome.org/show_bug.cgi?id=741375
2014-12-11 12:47:54 +01:00
Benjamin Otte
14f5ce7108 cssselector: Rewrite change computation
We know that non-simple selectors cause a transition to the all matcher,
so just assume the all matcher from that point on.
2014-12-10 03:49:40 +01:00
Benjamin Otte
e2dddd62cf cssselector: Redo change verification
Instead of walking the selector tree, we walk the selectors.
2014-12-10 03:49:40 +01:00
Benjamin Otte
5885950018 cssselector: Implement tree_match() using foreach_matcher() 2014-12-10 03:49:40 +01:00
Benjamin Otte
ad74fd9d7f cssselector: Introduce a foreach_matcher vfunc
This vfunc iterates over all matchers of a selector and allows to write
functions like the match function in a generic way using foreach.
2014-12-10 03:49:40 +01:00
Benjamin Otte
8a8f34b2db cssselector: Add a match_one vfunc
It allows a default implementation of the match() and tree_match()
functions.
2014-12-10 03:49:40 +01:00
Benjamin Otte
cab05f2b63 cssselector: Introduce a few more default functions 2014-12-10 03:49:40 +01:00
Benjamin Otte
06b0b47d04 cssselector: Make specificity handling a vfunc
The new region selector tracks more than just one soimple selector, so
it requires some more advanced specificity tracking.

Technically, this is still not correct, because it will report the same
specificity for
  tab:sorted
and
  tab:sorted:sorted
(and the second selector will be printed as the first) but this is
regions, so meh.
2014-12-10 03:49:40 +01:00
Benjamin Otte
371a601858 cssselector: Remove unused variable
The variable is FALSE for every class now.
2014-12-10 03:49:40 +01:00
Benjamin Otte
73823181d3 cssselector: Handle region selector like any selector
Instead of doing the previous match magic itself, use the
DESCENDANT_FOR_REGION hack and let that one do the magic.
2014-12-10 03:49:40 +01:00
Benjamin Otte
284ccdac45 cssselector: Use simple class macro for * selector
As a side effect, the :not(*) selector needs to be renamed because the
macro chooses a different name for it.
2014-12-10 03:49:40 +01:00
Benjamin Otte
528691f5b3 cssselector: Introduce descendant matcher for regions
This is just a way to handle regions more conveniently. What this does
is to change the descendant matcher into a maybe-descendant matcher
whenever the current object we're parsing might be a region. Because "*"
might also refer to a region and not just a new element.

See testsuite/reftests/css-match-region-matches-star.ui for a testcase.
2014-12-10 03:49:40 +01:00
Benjamin Otte
8b3f25ab96 cssselector: Support :not() for position pseudoclasses
This is simple now that the latest commit used the macro and
autogenerates the SelectorClass to use.
2014-12-10 03:49:40 +01:00
Benjamin Otte
88f28aee4f cssselector: Use simple macro for position pseudoclass
This is possible now that the region-specific code is gone.
2014-12-10 03:49:40 +01:00
Benjamin Otte
28e80aa40b cssselector: Handle region flags during parse
When parsing a selector like
  tab:active
We used to create 2 selector objects, one for the region, and one for
the pseudoclass. Now, for convenience, we special-case region
pseudoclass parsing so that the active flag is added to the region
selector.

A side effect is that ":nth-child(1)" no longer works for regions.
Hopefully people didn't use this but used the saner ":first-child"
instead.
2014-12-10 03:49:40 +01:00
Benjamin Otte
272a0083a3 cssselector: Turn into a union
Instead of just keeping a gpointer data, make GtkCssSelector a union
that has actual proper members.
2014-12-10 03:49:39 +01:00
Benjamin Otte
03aabcff14 cssselector: Introduce a hash func per selector
This is unnecessary itself, but useful in preparation for further
commits.
2014-12-10 03:49:39 +01:00
Benjamin Otte
80a8b793e0 cssselector: Inline a function 2014-12-10 03:49:39 +01:00
Benjamin Otte
965da578c4 cssselector: Add none selector
We apparently didn't yet parse :not(*), so write a selector for this.
2014-11-25 19:31:23 +01:00
Benjamin Otte
8a3a617475 cssselector: Add initial support for :not()
:not() works for names, ids, classes and pseudoclasses based on states.

It does not yet work for positional pseudoclasses (like :last-child or
:even) as there is region madness going on with those.
2014-11-25 19:31:13 +01:00
Benjamin Otte
fd1eb92508 cssselector: Macroify simple selectors
This is in preparation for the next commits.
2014-11-25 19:19:12 +01:00
Benjamin Otte
36a2e7ca8e css: Add a :checked pseudoclass
https://bugzilla.gnome.org/show_bug.cgi?id=733967
2014-08-16 16:34:14 +02:00
Benjamin Otte
3747e0fc4e css: Make commented out debug code work again 2014-07-21 19:54:14 +02:00
Benjamin Otte
09a1d983d4 css: Add printing code for :visited and :link
Don't just crash when those states are encountered
2014-07-21 19:54:14 +02:00
Timm Bäder
9b1c943190 css parser: Add :link and :visited
... which are both to be used for links instead of the current
-GtkWidget-link-color and -GtkWidget-visited-link-color

https://bugzilla.gnome.org/show_bug.cgi?id=709629
2013-11-04 16:36:11 +01:00
Benjamin Otte
f239edaf9c css: Parse and print the new state flags 2012-12-18 18:25:41 +01:00
Matthias Clasen
df1d331713 update_type_references: Deal with type_refs_ht being NULL
This can apparently happen, and it was breaking make check
on my system, by causing it to throw  a critical out of
g_hash_table_iter_init from here.
2012-12-17 22:45:08 -05:00
Alexander Larsson
a1ee2b7b82 css: Speed up name matching
We use the new g_type_get_type_registration_serial() so that we can
cache and properly invalidate the result of g_type_from_name().

This bumps the glib requirement to 2.35.3 to get the new function.

https://bugzilla.gnome.org/show_bug.cgi?id=689847
2012-12-10 12:57:10 +01:00
Alexander Larsson
089eafb468 css: Clean up tree_match implementations
A bunch of repeated code is broken out into the helper
gtk_css_selector_tree_match_previous().
2012-12-10 12:28:44 +01:00
Alexander Larsson
eb4667b6e1 css: Do get_change directly on the tree without matching first
Rather than first collecting matches and then getting the change
for them we do the change collection directly on the tree. This
is about twice as fast.
2012-12-10 12:11:02 +01:00
Alexander Larsson
03c626bb15 css: Factor out some of the position matching code 2012-12-10 12:11:02 +01:00
Jasper St. Pierre
34318b9163 gtkcssselector: Fix build
destroy vs. free strikes again
2012-12-06 17:48:15 -05:00
Jasper St. Pierre
736ccb6ce1 gtkcssselector: Don't leak the hash table
We should probably free the memory we allocate. Sounds like a winning
strategy.
2012-12-06 17:39:09 -05:00
Alexander Larsson
3c421db473 css: Allocate the css tree in a single chunk
This gives us several advantages:

* Smaller struct on 64bit (32bit indexes vs 64bit pointers)
* Less overhead for allocation
* Less fragmentation
2012-11-30 14:53:30 +01:00
Alexander Larsson
2dbeabdc58 css: Fix leak of lists while building tree 2012-11-30 14:53:30 +01:00
Alexander Larsson
528e6032ae css: Add accessor functions for traversing css tree
This will let us later change how the tree is stored
2012-11-30 14:53:30 +01:00
Alexander Larsson
42716cb60f css: Add const to _gtk_css_selector_tree_match_all arg 2012-11-30 14:53:30 +01:00
Alexander Larsson
9b989a1427 css: Implement ruleset_get_change() with the tree
We traverse the tree on the matches instead of using
the linear selectors.
2012-11-30 14:53:30 +01:00
Alexander Larsson
146b6f3a93 css: Ensure the tree built is always the same
We add some "artificial" ordering to the otherwise unordered
tree nodes. This means the tree will be the same every time for the
same input. This is good because e.g. tree order affects the
reordering of the simple selectors, which may affect how
css providers are printed, which need to be consistent for
the css tests to work.
2012-11-30 14:53:30 +01:00
Alexander Larsson
3d5e8f98ec css: Use the tree to print css selectors 2012-11-30 14:53:30 +01:00
Alexander Larsson
6bec577771 css: Track the tree selector matches 2012-11-30 14:53:30 +01:00
Alexander Larsson
f678827918 css: Fix type of GtkCssSelectorRuleSetInfo match
The old type was a leftover from a previous version.
2012-11-30 14:53:30 +01:00
Alexander Larsson
6b85db7555 css: Track parent in the css tree nodes
This way we can reconstruct matched css rules
2012-11-30 14:53:30 +01:00
Alexander Larsson
0ede06d229 css: Fix up position with region tree matching
This was using the wrong result in case of a match (results from
the position, not the region. Also, the descendant checks were
wrong.
2012-11-30 14:53:30 +01:00
Alexander Larsson
d6932dd823 css: Don't reorder some selectors when building selector tree
When building the tree we generally reorder the selectors inside
the same simple selector in order to pick a good first selector
to balance the tree better. However, some kinds of selectors
can't really be reordered, even thought they are simple.

This is since the matching code for some types handle
the existance of a directly preceeding selector differently:

 REGION and ANY selectors look for a DESCENDANT previous
 POSITION selector look for a REGION previous
2012-11-30 14:53:30 +01:00
Alexander Larsson
63cb467e06 css: Fixed typo in PRINT_TREE debug code 2012-11-30 14:53:30 +01:00
Alexander Larsson
daefb12a23 css: Add GtkCssSelectorTree creation and matching
From a set of GtkCssSelectors and the rulesets they match to
we create a large decision tree that lets us efficitently match
against all the rules and return the set of matched rulesets.

The tree is created such that at each level we pick the initial rule[1]
in all the considered selectors for that level and use put the
one that is in most selectors in the node. All selectors matching that
are put in the previous part of the tree.
2012-11-30 14:53:29 +01:00
Alexander Larsson
3b4040d619 css: Track which selectors are "simple" 2012-11-30 14:53:29 +01:00