Commit Graph

113 Commits

Author SHA1 Message Date
Benjamin Otte
e1cd996617 selector: Inlcude : sign when reporting errors 2019-04-12 19:34:28 +02:00
Benjamin Otte
e0a01ba174 css: Redo for new parser
This commit is still way too big, but I couldn't make it smaller.

It transitions the old CSS parser to the new parser. CSS parsing is now
tokenized, everything else is probably still buggy.
2019-04-12 19:34:28 +02:00
Benjamin Otte
7f99c1e588 cssparser: Split integer gettig into has/consume functions
We can't try to get an integer because ultimately integer getters
support the same shenanigans that numbers and percentages do with calc()
and whatnot.
2019-04-12 19:34:28 +02:00
Benjamin Otte
dce8c11b07 cssparser: Drop _gtk_css_parser_has_prefix()
Replace it with has_ident/has_function. The old function is a typical
string matching API, not a tokenizing one.
2019-04-12 19:34:28 +02:00
Benjamin Otte
7ccec19501 parser: Get rid of _gtk_css_parser_is_eof()
Use gtk_css_parser_has_token() instead.
2019-04-12 19:34:28 +02:00
Benjamin Otte
684b6459f1 cssparser: Get rid of _gtk_css_parser_begins_with()
Replace it with calls to gtk_css_parser_has_token().
2019-04-12 19:34:28 +02:00
Matthias Clasen
a8531605db Some more interning
This avoids more strdups at startup.
2017-11-18 08:18:11 -05:00
Matthias Clasen
4209c1762d Support the new state in CSS selectors
Make :focus(visible) match the new state.
2017-10-25 17:59:00 -04:00
Benjamin Otte
8549e62d85 Add default return values to switch statements
We are using g_assert_not_reached() without doing anything, assuming it
aborts the program. In release builds however, it is ignored.
2017-10-24 18:21:03 +02:00
Matthias Clasen
d3198536a4 Drop support for deprecated pseudo-classes
We no longer have any of those.
2017-09-17 17:04:16 -04:00
Daniel Boles
79bbd4aca5 cssselector: Ensure we do not index out of bounds
This would only happen if the last element was deprecated, but it should
be avoided anyway.

CID 1388852 (#1 of 1): Out-of-bounds read (OVERRUN)
12. overrun-local: Overrunning array pseudo_classes of 16 32-byte
elements at element index 16 (byte offset 512) using index i + 1U (which
evaluates to 16).
2017-08-01 20:17:02 +01:00
Timm Bäder
b52966a318 cssselector: Stop parsing deprecated selectors 2017-03-02 15:16:08 +01:00
Daniel Boles
a1239a9a6a CssSelector: Fix warning for bad pseudo-class name
It was "Missing name of pseudo-class", but the real problem is exactly
the opposite: we /have/ been given a name, but it is not a valid one.
Change it to "Invalid name of pseudo-class" to minimise confusion.
2017-02-18 21:01:38 +00:00
Benjamin Otte
9b9b475f0a API: stylecontext: Remove regions 2016-10-16 18:17:21 +02:00
Benjamin Otte
35c96c2c1f Add braces to appease gcc
-ftrack-macro-expansion=0 doesn't like if statements without braces when
evaluating indentation levels.
2016-08-25 23:02:27 +02:00
Matthias Clasen
6108c646c5 cssselector: Don't invoke undefined behavior
Avoid undefined behavior in the calculation of some
hash values. Found by gcc's undefined behavior sanitizer.
2016-02-26 15:52:19 -05:00
Benjamin Otte
d48d3b359c cssselector: Remove type references
We don't use types anymore.
2016-02-05 23:47:48 +01:00
Benjamin Otte
e8fca5bbbe cssmatcher: Remove type argument from name matcher
We no longer use types when matching names.
2016-02-05 23:43:05 +01:00
Matthias Clasen
33bb1af277 css: Privately export a function to get pseudoclass names
This function centralizes the mapping for widget states
to pseudoclass names in one place, for easier maintenance.
2016-01-24 10:59:46 -05:00
Matthias Clasen
eb09bee492 css: Deprecate :sorted pseudo class
This was used with regions in GtkTreeView, and is not used
anymore, so deprecate it.
2015-12-27 18:37:19 -05:00
Matthias Clasen
f3069d7e94 css: Redo the pseudo class deprecation warnings
Putting the deprecated class behind the official variant does
not work for the case of :focus and :focused - we were matching
:focus and leave a dangling 'ed'. So, put the deprecated classes
before the official variant, and explicitly mark them as deprecated.
2015-12-27 17:32:11 -05:00
Matthias Clasen
b3dbf3f41c Drop the :dnd syntax altogether
This was only introduced a few weeks ago. We don't need to keep
this around, now that we support the proper CSS syntax.
2015-12-25 22:58:28 -05:00
Matthias Clasen
c998fae5ac Add deprecation warnings for pseudo states
Emit a deprecation error in the cases where we have
a CSS name for a custom pseudo class.
2015-12-25 22:58:28 -05:00
Matthias Clasen
158dbbc88f Use CSS syntax for drop highlighting
I hadn't noticed the :drop() pseudo state in the CSS4 Selectors
spec when I added this a while ago. This commit renames
GTK_STATE_FLAG_DND to GTK_STATE_FLAG_DROP_ACTIVE and adds
:drop(active) as equivalent to the :dnd pseudo state.
2015-12-25 22:58:28 -05:00
Matthias Clasen
6f889e832c css: Support CSS names for pseudo states
What we call :insensitive is called :disabled in CSS, and
:inconsistent is :indeterminate. Recognize these names, but
still support the old ones.
2015-12-21 08:26:58 -05:00
Matthias Clasen
cbde3ee01f css: Add a :dnd pseudoclass
This will be used for drag highlighting.
2015-12-02 23:23:36 -05:00
Benjamin Otte
e3ddbc544c cssselector: Print name and any selector first
When printing a "compound selector", make sure the name and universal
selectors are printed at the beginning and class, id, etc. selectors are
printed last.
2015-10-27 20:12:38 +01:00
Benjamin Otte
24dde6346a API: cssselector: Stop supporting regions
The namespace that belonged to regions is supposed to be used for
CssNode names.
2015-10-22 16:42:46 +02:00
Benjamin Otte
385fda80b4 cssmatcher: Marshal name to matcher
... and use it in the node matcher.

Also rename function from _gtk_css_matcher_get_type() to
_gtk_css_matcher_get_name().
2015-10-22 16:35:14 +02:00
Chun-wei Fan
ac62479c9e Fix Visual Studio Build Since a080cb4
The patch did not check for Visual Studio 2008 correctly, plus it
would break the build on later Visual Studio versions, as it should
be __popcnt(), not __popcount().  Fix that.
2015-09-23 23:24:36 +08:00
Emmanuele Bassi
a080cb40b9 Improve compiler detection for __builtin_popcount()
The popcount builtin was added in GCC after version 4.2 (which is what
some *BSDs are using), which means we need to be more specific when
using it than just asking for GCC.

While we're at it, we can improve the compiler detection, and use a
builtin popcount on Clang ≥ 3.1 and MSVC 2008.

https://bugzilla.gnome.org/show_bug.cgi?id=755455
2015-09-23 13:58:50 +01:00
Matthias Clasen
83d68ea107 css selector: Use a builtin to count bits 2015-09-12 11:24:43 -04:00
Matthias Clasen
11d3582333 css selector: Take advantage of interned strings
We know these strings are interned, no need to use strcmp or
g_str_hash for hem.
2015-09-12 11:24:42 -04:00
Matthias Clasen
a9481cb410 match_all: Only allocate an array when needed
My statistics show that more than half of all calls end up
with 0 matches, so we can avoid some overhead by not allocating
an array at all in this case.
2015-09-09 11:17:13 -04:00
Matthias Clasen
117b50f8fb Optimize gtk_css_selector_match_all
We are dealing with really short lists here.
95% are < 10 matches, and the longest I've been able to record was 19.
So just do away with the hash table and do sorted insertion in
the array directly.
2015-09-09 11:17:13 -04:00
Matthias Clasen
0e86278fcc css selector: Use the quarks we have
Unless I'm missing something, there is no reason to go from
quarks back to strings to implement hasing or comparison.
2015-09-09 06:32:47 -04:00
Benjamin Otte
69e396ea0a cssselector: Report finer granularity for position changes 2015-07-06 15:33:50 +02:00
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