Commit graph

527 commits

Author SHA1 Message Date
stelar7
469380d6bc LibWeb: Dont consider '-n-' a dashndashdigit-ident token 2022-05-08 16:29:06 +02:00
stelar7
5ca8e2a751 LibWeb: Dont try to fetch another token in an+b parsing
When parsing <ndash-dimension> <signless-integer>, we tried to parse
a new token from the stream instead of using the value we had already
extracted. This caused pages that used the syntax to crash.
2022-05-08 16:29:06 +02:00
Sam Atkins
56e8e0daa1 LibWeb: Remove TokenStream::position() and ::rewind_to_position() 2022-04-29 00:07:31 +02:00
Sam Atkins
2b3185955e LibWeb: Use StateTransaction for UnicodeRange parsing
...and change how the two parsing steps fit together.

The two steps were previously quite muddled. Both worked with the
TokenStream directly, and both were responsible for rewinding that
stream if there was an error. This is both confusing and also made it
impossible to replace the rewinding with StateTransactions.

This commit more clearly divides the work between the two functions: One
parses ComponentValues and produces a string, and the other parses that
string to produce the UnicodeRange. It also replaces manual rewinding
in the former with StateTransactions.
2022-04-29 00:07:31 +02:00
Sam Atkins
dc00657c4f LibWeb: Use StateTransaction in more places 2022-04-29 00:07:31 +02:00
Sam Atkins
f1bb3e5ce5 LibWeb: Use StateTransaction for supports-query parsing 2022-04-29 00:07:31 +02:00
Sam Atkins
dd5927edad LibWeb: Use StateTransaction for media-query parsing
This should be a bit easier to follow.

parse_media_query() no longer rewinds if the media query is invalid,
because it then interprets all the tokens as a "not all" query.
2022-04-29 00:07:31 +02:00
Sam Atkins
28278efafb LibWeb: Extract MediaType to/from_string() logic into functions 2022-04-29 00:07:31 +02:00
Sam Atkins
1f114eaebe LibWeb: Allow whitespace inside An+B again and use StateTransactions
I accidentally broke parsing of internal whitespace (eg `-3n + 7`
instead of `-3n+7`) when implementing `:nth-child(An+B of foo)`.
2022-04-29 00:07:31 +02:00
Sam Atkins
5c8ff96a94 LibWeb: Move variables in parse_a_n_plus_b_pattern() closer to usage
`a` and `b` had to be declared at the top of the function before since
they were used by the `make_return_value()` lambda. But now that
doesn't exist, we can move them to where they are used - or eliminate
them entirely.
2022-04-29 00:07:31 +02:00
Sam Atkins
f2d6bdce3f LibWeb: Handle trailing tokens outside of parse_a_n_plus_b_pattern()
parse_a_n_plus_b_pattern()'s job is to parse as much of the TokenStream
as it can as a An+B, and then stop. The caller can then deal with any
trailing tokens as it wishes.
2022-04-29 00:07:31 +02:00
Sam Atkins
d6ae08d023 LibWeb: Rename a local variable to not collide with a parameter 2022-04-29 00:07:31 +02:00
Sam Atkins
d784a8aaf0 LibWeb: Replace Result with ErrorOr in CSS Parser
...using a ParseErrorOr type alias.

This lets us replace a bunch of manual error-checking with TRY. :^)

I also replaced the ParsingResult::Done value with returning an
Optional. I wasn't happy with treating "Done" as an error when I first
wrote this, and this makes a clear distinction between the two.
2022-04-29 00:07:31 +02:00
Sam Atkins
761d29d647 LibWeb: Make CSS ParsingContext::m_url not Optional
This always has a value, so let's make that clearer.
2022-04-29 00:07:31 +02:00
Sam Atkins
ce5914230f LibWeb: Actually use BorderRadiusShorthandStyleValue
Somehow we were never actually using this before, but parsing the
property as a StyleValueList instead.
2022-04-18 21:30:51 +02:00
Sam Atkins
00782d9a59 LibWeb: Disallow trailing commas in transform function arguments 2022-04-18 14:16:28 +02:00
Sam Atkins
b3a6044fd8 LibWeb: Disallow non-whitespace tokens after "none" in transform
Before this, a declaration like `transform: none yellow 20;` would be
parsed as `transform: none;`. Now it's correctly rejected as invalid.
2022-04-18 14:16:28 +02:00
Sam Atkins
a52f6fb5b0 LibWeb: Use TransformFunctionMetadata when parsing their arguments
Now, the parser will reject a transform function if:
- There are too many arguments.
- There are too few arguments.
- An argument is the wrong type.
2022-04-18 14:16:28 +02:00
Sam Atkins
61ad39b110 LibWeb: Use generated TransformFunction enum and functions 2022-04-18 14:16:28 +02:00
Sam Atkins
7c91fda088 LibWeb: Allow multiple text-decoration-lines
The spec grammar for `text-decoration-line` is:

`none | [ underline || overline || line-through || blink ]`

Which means that it's either `none`, or any combination of the other
values. This patch makes that parse for `text-decoration-line` and
`text-decoration`, stores the results as a Vector, and adjusts
`paint_text_decoration()` to run as a loop over all the values that are
provided.

As noted, storing a Vector of values is a bit wasteful, as they could be
stored as flags in a single `u8`. But I was getting too confused trying
to do that in a nice way.
2022-04-14 21:54:10 +02:00
Sam Atkins
431a9938a8 LibWeb: Rename StyleRule -> Rule
This name is what's used in the spec, and is a little less confusing.
2022-04-12 23:03:46 +02:00
Sam Atkins
cf24dc2e0c LibWeb: Break friendship between CSS StyleRule and Parser
As before, this requires deviating from the spec slightly to create the
StyleRule fully-formed instead of creating it empty and then modifying
its internals.
2022-04-12 23:03:46 +02:00
Sam Atkins
d67e817d8e LibWeb: Break friendship between CSS Function and Parser
Again, this means deviating from the spec by creating a complete
Function in one go instead of creating it empty and then poking at its
internals.
2022-04-12 23:03:46 +02:00
Sam Atkins
128d08ecef LibWeb: Empend instead of Appending DeclarationOrAtRules 2022-04-12 23:03:46 +02:00
Sam Atkins
269810b954 LibWeb: Break friendship between CSS Declaration and Parser
This means deviating slightly from the spec in order to construct a
fully-initialized Declaration instead of creating an empty one and then
poking at its internals.

DeclarationOrAtRule should probably use a Variant, but for now, making
its Declaration member optional is quick and easy.
2022-04-12 23:03:46 +02:00
Sam Atkins
69496f4afd LibWeb: Make Declaration.m_name a FlyString 2022-04-12 23:03:46 +02:00
Sam Atkins
f235da27d9 LibWeb: Break friendship between CSS Block and Parser
This means deviating a little from the spec, so that we create a
complete Block in one go instead of creating an empty one and then
poking at its internals.
2022-04-12 23:03:46 +02:00
Sam Atkins
3e49036edf LibWeb: Move/rename StyleBlockRule to Parser::Block 2022-04-12 23:03:46 +02:00
Sam Atkins
e0b2ebcc7b LibWeb: Move/rename StyleFunctionRule to Parser::Function 2022-04-12 23:03:46 +02:00
Sam Atkins
c449cabae3 LibWeb: Move CSS Parser into new Web::CSS::Parser namespace
The goal here is to move the parser-internal classes into this namespace
so they can have more convenient names without causing collisions. The
Parser itself won't collide, and would be more convenient to just
remain `CSS::Parser`, but having a namespace and a class with the same
name makes C++ unhappy.
2022-04-12 23:03:46 +02:00
Simon Wanner
539adf5b9c LibWeb: Support WOFF in font-face 2022-04-09 23:48:18 +02:00
Sam Atkins
12b8570ce3 LibWeb: Understand the format() part of a @font-face's src
This is used to skip downloading fonts in formats that we don't support.
Currently we only support TTF as far as I am aware.

The parts of a `src` are in a fixed order, unusually, which makes the
parsing more nesty instead of loopy.
2022-04-07 21:20:14 +02:00
Sam Atkins
dbb0b68175 LibWeb: Disallow global CSS keywords in @font-face font-family 2022-04-07 21:20:14 +02:00
Sam Atkins
dbbd6d3508 LibWeb: Parse @font-face unicode-range descriptor 2022-04-07 21:20:14 +02:00
Sam Atkins
ef7d80ced2 LibWeb: Parse <urange> as CSS::UnicodeRange
Like, An+B, this is an old construct that does not fit well with modern
CSS syntax, so things get a bit hairy! We have to determine which
tokens match the grammar for `<urange>`, then turn those back into a
string, and then parse the string differently from normal. Thankfully
the spec describes in detail how to do that. :^)

This is not 100% correct, since we are not using the original source
text (referred to in the spec as the "representation") of the tokens,
but just converting them to strings in a manual, ad-hoc way.
Re-engineering the Tokenizer to keep that original text was too much of
a tangent for today. In any case, we do parse `U+4???`, `U+0-100`,
`U+1234`, and similar, so good enough for now!
2022-04-07 21:20:14 +02:00
Sam Atkins
802ccc210f LibWeb: Expose Declaration's internals with getters
This is more in line with our style of not accessing `m_foo` fields
directly.
2022-04-07 21:20:14 +02:00
Sam Atkins
611a209756 LibWeb: Rename StyleDeclarationRule -> Declaration
This is the term used in the CSS specs.
2022-04-07 21:20:14 +02:00
Sam Atkins
8b538b1578 LibWeb: Rename StyleComponentValueRule -> ComponentValue
"Component value" is the term used in the spec, and it doesn't conflict
 with any other types, so let's use the shorter name. :^)

Also, this doesn't need to be friends with the Parser any more.
2022-04-07 21:20:14 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Sam Atkins
cd199d9d06 LibWeb: Implement and use parse_a_style_blocks_contents() 2022-03-30 18:43:07 +02:00
Sam Atkins
6a0adbefc7 LibWeb: Tidy up StyleRule API
Constantly accessing private `m_foo` fields feels uncomfortable and
doesn't fit well with our code style.
2022-03-30 18:43:07 +02:00
Sam Atkins
75db8b1f86 LibWeb: Spec-comment consume_a_function() 2022-03-30 18:43:07 +02:00
Sam Atkins
512d1df1c4 LibWeb: Spec-comment consume_a_simple_block() 2022-03-30 18:43:07 +02:00
Sam Atkins
5a23965e93 LibWeb: Comment discrepancy from spec in consume_a_declaration()
We're calling this in a way that is incorrect, and so the algorithm's
assumption that the next token is an `<ident-token>` is wrong, and we
have to handle that failing. Ideally we would just stop calling this
incorrectly, but until then, let's actually document what is happening.
2022-03-30 18:43:07 +02:00
Sam Atkins
999cc51512 LibWeb: Spec-comment consume_a_component_value() 2022-03-30 18:43:07 +02:00
Sam Atkins
be86d19529 LIbWeb: Spec-comment consume_a_list_of_declarations() 2022-03-30 18:43:07 +02:00
Sam Atkins
e72f42bea1 LibWeb: Spec-comment consume_a_qualified_rule() 2022-03-30 18:43:07 +02:00
Sam Atkins
fe86718035 LibWeb: Spec-comment consume_an_at_rule() 2022-03-30 18:43:07 +02:00
Sam Atkins
d77de5ccec LibWeb: Spec-comment consume_a_list_of_rules() 2022-03-30 18:43:07 +02:00
Sam Atkins
a4f8056828 LibWeb: Spec-comment parse_a_comma_separated_list_of_component_values
The code had to change a bit to match. Previously, we appended an empty
sub-list immediately, but now we append it at the end. The difference
is that if there are no tokens, we now correctly return an empty
list-of-lists, instead of a list containing an empty list.
2022-03-30 18:43:07 +02:00