Commit graph

22 commits

Author SHA1 Message Date
Sam Atkins
e2c32a6c65 Everywhere: Use my shiny new serenityos.org email :^) 2021-09-03 12:22:36 +02:00
Sam Atkins
6034fc0ee6 LibWeb: Make CSS 'An+B' parsing spec-compliant
Parsing this pattern from CSS tokens turns out to be slightly crazy, but
thankfully well documented in the spec.

The spec lists the cases in order of simple -> complicated, but this
would cause problems in code, since `<n-dimension> <signed-.integer>`
would never by reached, as `<n-dimension>` comes before. Instead, I
have grouped them by their first token.

Also renamed the NthChildPattern class to ANPlusBPattern, to match spec
terminology.
2021-07-31 00:18:11 +02:00
Sam Atkins
8d0ff98eff LibWeb: Parse CSS selectors according to the spec
The spec does not directly tell us how to parse selectors, so there are
likely some bugs here, but I've used the spec language where possible.
This is very much based on the previous selector parsing code.

Any parse error inside a selector makes the entire SelectorList
invalid, so nothing is returned.
2021-07-31 00:18:11 +02:00
Sam Atkins
6ea5d03f43 LibWeb: Bring Selector terminology in line with the CSS spec
- CompoundSelector -> *deleted*
- ComplexSelector -> CompoundSelector
- Relation -> Combinator

Our Selector is really a ComplexSelector, but only the Parser and
SelectorEngine need to know that, so keeping it named Selector makes it
more understandable for users.

Our CompoundSelector is really a CompoundSelectorAndCombinator.
Combining the two makes sense in our codebase, but the accurate name is
so long that I think it makes the code less readable.

Renamed some Combinators to also match the spec terminology:

- AdjacentSibling -> NextSibling
- GeneralSibling -> SubsequentSibling

The previous names are somewhat ambiguous, so hopefully this is clearer.
2021-07-31 00:18:11 +02:00
Sam Atkins
ffc81cbfad LibWeb: Use Selectors instead of a String for :not() selectors
Rather than parsing the selector every time we want to check it, we
now parse it once at the beginning.

A bonus effect of this is that we now support a selector list in
:not(), instead of just a single selector, though only when using
the new parser.
2021-07-14 13:31:00 +02:00
Sam Atkins
776b1f4548 LibWeb: Make CSS::Selector reference counted
The end goal is to make the PseudoClass::not_selector be a Selector
instead of a String that is repeatedly re-parsed. But since Selector
contains a Vector of ComplexSelectors, which each have a Vector of
SimpleSelectors, it's probably a good idea to not be passing them
around by value anyway. :^)
2021-07-14 13:31:00 +02:00
Sam Atkins
8cae79cc8d LibWeb: Add 'PseudoElement' as a CSS SimpleSelector::Type
Same reasoning again! This is the last one.

While I was at it, I added the two remaining CSS2.2 pseudo-elements,
::first-line and ::first-letter. All 4 are handled in the new CSS
parser, including with the compatibility single-colon syntax. I have
not added support to the old parser.
2021-07-14 13:31:00 +02:00
Sam Atkins
4af7d41879 LibWeb: Add 'PseudoClass' as a CSS SimpleSelector::Type
Same reasoning as the previous commit.
2021-07-14 13:31:00 +02:00
Sam Atkins
96b2356cbb LibWeb: Add 'Attribute' as a CSS SimpleSelector::Type
Previously, SimpleSelectors optionally had Attribute-selector data
as well as their main type. Now, they're either one or the other,
which better matches the spec, and makes parsing and matching more
straightforward.
2021-07-14 13:31:00 +02:00
Sam Atkins
dadcb46344 LibWeb: Convert CSS Dump, Selector, & SelectorEngine to east const 2021-07-14 13:31:00 +02:00
Sam Atkins
7fefe34797 LibWeb: Add remaining CSS AttributeMatchTypes
This adds:
- ContainsString     [att*=val]
- StartsWithSegment  [att|=val]
- StartsWithString   [att^=val]
- EndsWithString     [att$=val]

Renamed AttributeMatchType::Contains to ::ContainsWord for clarity.
2021-07-11 23:19:56 +02:00
Sam Atkins
a558916e1f LibWeb: Make CSS selector parsing use StyleComponentValueRules
Also added some pseudo-classes that were handled in the deprecated
parser:
- :disabled
- :enabled
- :checked
- :nth-child
- :nth-last-child
- :not
2021-07-11 23:19:56 +02:00
Paul Irwin
5eb65286b6 LibWeb: Support :active pseudo-class for hyperlinks, :focus possibly
Adds support for the :active pseudo-class for hyperlinks (<a> tags
only).

Also, since it was very similar to :focus and an element having a
focused state was already implemented, I went ahead and implemented
that pseudo-class too, although I cannot come up with a working
example to validate it.
2021-06-25 01:02:29 +02:00
Tobias Christiansen
1ab82afee6 LibWeb: Add :not pseudoclass to the CSS parser
The selector given in the :not() is stored in the SimpleSelector as a
String.
2021-05-24 22:10:08 +01:00
Tobias Christiansen
b53dac6e88 LibWeb: Add support for more pseudoclasses
:disabled, :enabled and :checked are now parsed and matched. There
surely are more nuances to consider.
2021-05-24 02:14:11 +04:30
miere43
c4bd4cbd76 LibWeb: Implement :nth-last-child pseudo-class 2021-05-11 21:17:16 +01:00
miere43
aa83539d7b LibWeb: Implement :nth-child pseudo-class 2021-05-09 11:24:04 +02:00
stelar7
55446172cb LibWeb: Add selector support to the new CSSParser
This is stolen from the old parser, but it seems to parse fine :^)
2021-04-30 08:52:36 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Andreas Kling
1d065aa51b LibWeb: Support the :last-of-type CSS selector :^) 2021-04-06 13:06:42 +02:00
Andreas Kling
0eb9a9dd13 LibWeb: Support the :first-of-type CSS selector :^) 2021-04-06 13:06:42 +02:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Renamed from Libraries/LibWeb/CSS/Selector.h (Browse further)