Commit graph

351 commits

Author SHA1 Message Date
Andreas Kling
72bacba97b LibWeb: Make CSSStyleDeclaration GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
12042f0757 LibWeb: Make CSSRule and all its subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
5d60212076 LibWeb: Make StyleSheet and CSSStyleSheet GC-allocated 2022-09-06 00:27:09 +02:00
martinfalisse
f8e82da4b4 LibWeb: Handle unknown values in grid-template-*
This commit fixes a bug found when passing exotic values in the
grid-template-columns (or grid-template-rows) which are not yet
supported.

The bug seems to have been something like:
grid-template-columns: 0 minmax(0, calc(10px - var(--some-color)));
2022-08-26 12:48:57 +02:00
martinfalisse
7bb3a8d646 LibWeb: Parse grid-column and grid-row CSS values 2022-08-25 13:47:48 +02:00
martinfalisse
44d08b81b7 LibWeb: Parse grid-column-start and related CSS properties
Parse grid-column-start, end, and the equivalent for rows.
2022-08-25 13:47:48 +02:00
martinfalisse
92a00648b1 LibWeb: Parse grid-template-columns and grid-template-rows
Add functionality to begin parsing grid-template-columns and
grid-template-rows. There are still things to be added, like parsing
functions, but I would say a couple of the major points are already
adressed like length, percentage, and flexible-length.
2022-08-25 13:47:48 +02:00
MacDue
3a1f8d714a LibWeb: Parse double-position linear-gradient() color stops
The only accepted syntax for these seems to be
<color> <length percentage> <length percentage>, no other order.

But that's just gathered from looking at other browsers as though
these are supported by all major browsers, they don't appear in
the W3C spec.
2022-08-23 01:02:49 +02:00
MacDue
f9a685437f LibWeb: Parse repeating-linear-gradient()
Including `-webkit-repeating-linear-gradient()`
2022-08-18 15:58:05 +02:00
MacDue
361fc56632 LibWeb: Don't allow mixed commas/no commas in rect() css values
This fixes the clip-rect-comma-002, clip-rect-comma-003, and
clip-rect-comma-004 web platform tests.
2022-08-08 14:03:29 +02:00
Tom
b4dd477644 LibWeb: Parse rect style value
Add ability to parse a rect when it is used as the value of a style
property.
2022-08-07 22:40:11 +02:00
MacDue
ca2e345cdc LibWeb: Support -webkit-linear-gradient() correctly
The -webkit version of linear-gradient does not include the `to`
before a <side or corner>. The angles of the <side or corner>
for the webkit version are also opposite that of the standard one.

So for the standard: linear-gradient(to left, red, blue)
The webkit version is: -webkit-linear-gradient(right, red, blue)

Adding the `to` in the -webkit version is invalid, omitting it in
the standard one is also invalid.
2022-08-07 20:47:31 +02:00
MacDue
b5febe538c LibWeb: Parse the -webkit-progress-bar/value pseudo elements
These will be needed for styling progress bars, sadly this can
only be done with these non-standard selectors. These are, hovever,
in use on real sites such as https://rpcs3.net/compatibility.
2022-07-23 01:45:49 +02:00
Sam Atkins
094ba6525f LibWeb: Allow calc() inside CSS transform functions :^)
As noted, we should probably handle calc() parsing as part of parsing
other values. eg, any `<length>` can be a `calc()` that returns a
length, but we currently have to manually handle that everywhere that
doesn't use the `Parser::parse_css_value(ComponentValue)` method.
2022-07-21 16:36:08 +02:00
MacDue
ae6c0258a4 LibWeb: Parse the linear-gradient() CSS function
This should parse linear-gradient()s as defined in the W3 spec
https://drafts.csswg.org/css-images/#linear-gradients.

Note: This currently cannot parse multi-position color stops,
these are shown on MDN and work in Firefox and Chrome, though do
not seem to be defined in the spec.

See: https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient#gradient_with_multi-position_color_stops

P.s. This also allows -webkit-linear-gradient for compatibility.
2022-07-17 20:11:38 +01:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
DexesTTP
7ceeb74535 AK: Use an enum instead of a bool for String::replace(all_occurences)
This commit has no behavior changes.

In particular, this does not fix any of the wrong uses of the previous
default parameter (which used to be 'false', meaning "only replace the
first occurence in the string"). It simply replaces the default uses by
String::replace(..., ReplaceMode::FirstOnly), leaving them incorrect.
2022-07-06 11:12:45 +02:00
MacDue
b652546a16 LibWeb: Fix parsing of background-size: contain/cover
The lack of the commit() before returning the x_value here meant,
that in parse_background_value() the token stream would be one token
behind after parsing the background-size. This led to it to returning
null, after it sees the unexpected 'second' contain / cover token.

With this change all of backgrounds.html is working again.
2022-06-26 22:04:20 +01:00
CodeforEvolution
a02ee29af9 LibWeb/CSS: Check for NULL block statement when parsing font-face rule
This prevents font-face rules without a block statement from crashing
LibWeb during CSS parsing.

The issue was discovered by Lubrsi during CSS parser fuzzing. :)
Fixes #14141.
2022-06-23 19:14:24 +01:00
Thomas Fach-Pedersen
019e3a342d LibWeb: Parse rgb and hsl functions according to CSS Module Level 4
Implement parsing of rgb(..) and hsl(..) in both the modern level 4
syntax without commas, and the legacy syntax with commas.

The parser accepts non-integer numbers but rounds to integer values
for now.
2022-06-15 19:10:43 +01:00
Idan Horowitz
34e193afa6 LibWeb: Reject invalid background-repeat values instead of crashing 2022-06-03 19:14:22 +01:00
Karol Kosek
a232395b77 LibWeb: Check recursively if CSS functions contain var() or attr()
Previously, `var()` inside functions like `rgb()` wasn't resolved.

This will set the background color for badges in the New category on
https://ports.serenityos.net. :^)
2022-06-02 22:31:41 +02:00
stelar7
fa05c99b22 LibWeb: Commit transaction after parsing '+'?† n <signed-integer> 2022-05-08 16:29:06 +02:00
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