Commit Graph

927 Commits

Author SHA1 Message Date
Andreas Kling
b98a2be96b LibWeb: Ignore window-forwarded document.body.onfoo in detached DOM
Normally, assigning to e.g document.body.onload will forward to
window.onload. However, in a detached DOM tree, there is no associated
window, so we have nowhere to forward to, making this a no-op.

The bulk of this change is making Document::window() return a nullable
pointer, as documents created by DOMParser or DOMImplementation do not
have an associated window object, and so must be able to return null
from here.
2024-03-11 18:29:10 +01:00
Shannon Booth
9ce8189f21 Everywhere: Use unqualified AK::URL
Now possible in LibWeb now that there is no longer a Web::URL.
2024-02-25 08:54:31 +01:00
Tommy van der Vorst
1c7ec9c770 LibWeb: Ignore repeat(auto-fit/auto-fill, auto) as it is not allowed 2024-02-11 17:51:50 +01:00
Bastian Neumann
7cd489d6aa LibWeb: Remove early continue in size parsing
Step 5 of parsing was always skipped because step 4 continues.

Running step 5 causes some of the denominators to be 0 and causes
divide by zero error in CSSPixelFraction.

SVG Image with height of 0 will cause divide by zero error when
calculating intrinsic aspect ratio of SVGDecoderImageData.

We also get a divide by zero error in AlignContent::SpaceBetween of the
FlexFormatingContext.

During auto track stretching in GridFormatingContext there is a
possibility for count_of_auto_max_sizing_tracks to stay 0.
2024-01-20 15:22:25 +01:00
Aliaksandr Kalenik
a22ef086f5 LibWeb/CSS: Support calc() in grid placement values
Fixes reduction in https://github.com/SerenityOS/serenity/issues/22802
but does not result in visual improvement on https://kotlinlang.org/
2024-01-17 17:26:55 +01:00
Shannon Booth
d95461ebe1 LibWeb: Allow 'center' in 3-value background-positions
The grammar which we implemented did not match the spec, resulting in us
rejecting background positions which contained 'center' position
keywords.

Fixes: #22401
2024-01-10 23:27:28 +01:00
Bastiaan van der Plaat
675b242e84 LibWeb: Add missing CSS Transforms Module Level 2 functions 2024-01-10 09:48:25 +01:00
Bastiaan van der Plaat
c443f80137 LibWeb: Allow percentages on CSS transform scale functions 2024-01-10 09:48:25 +01:00
Bastian Neumann
7d63b8b95f LibWeb/CSS: Remove nullpointer dereference in Parser
On platinenmacher.tech there is a document without a window. During
size attribute parsing the window pointer is dereferenced which
causes a crash. This checks for the window to be actually there
before dereferencing.
2024-01-09 18:38:16 +00:00
Shannon Booth
5b9a0e3fe7 LibWeb: Allow reordering of keywords in CSS positions
As the spec points out:
> Note that a pair of keywords can be reordered while a combination of
> keyword and length or percentage cannot. So center left is valid while
> 50% left is not.

This was a bug in our implementation of alternative 2 of css-values-3,
resulting in the following CSS failing to be parsed:

`background-position: center right;`

This commit fixes the issue as part of an update of the parsing to
css-values-4. As far as I can tell, the grammar is equivalent - but
simpler to implement due to the lack of optional values.

The fix for this issue is also as part of alternative 2 parsing in the
new grammar.

Progress towards: #22401
2024-01-09 13:37:35 +00:00
Andreas Kling
5b7a8891a6 LibWeb: Implement calc() value equality check in a more efficient way
Instead of serializing two calc() values to String and then comparing
those strings, we can now compare calc() values by actually traversing
their internal CalculationNode tree.

This makes style recomputation faster on pages with lots of calc()
values since it's now much cheaper to check whether a property with
some calc() value actually changed.
2024-01-09 14:15:27 +01:00
implicitfield
c994326d5a LibWeb/CSS: Improve parsing of length percentage values for transforms 2024-01-09 14:15:05 +01:00
Aliaksandr Kalenik
cfcc459140 LibWeb: Fix grid line name placement when repeat() is used
Before this change, parsed grid-template-columns/grid-template-rows
were represented as two lists: line names and track sizes. The problem
with this approach is that it erases the relationship between tracks
and their names, which results in unnecessarily complicated code that
restores this data (incorrectly if repeat() is involved) during layout.
This change solves that by representing line definitions as a list of
sizes and names in the order they were defined.

Visual progression https://genius.com/
2024-01-05 13:21:09 +01:00
Sam Atkins
4ee3090a7d LibWeb: Remove duplicate check for unitless lengths and zero
We call `parse_dimension()` immediately after this, which already deals
with lengths that have no unit. Also the comment here is woefully
outdated.
2023-12-30 20:11:24 +01:00
Sam Atkins
8b69f41bcd LibWeb: Remove old parse_length(ComponentValue const&) method 2023-12-30 20:11:24 +01:00
Sam Atkins
0811a39392 LibWeb: Use new parse_length() in filter parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
e0875b99cc LibWeb: Use new parse_length() in shadow parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
306acf43c4 LibWeb: Convert parse_source_size_value() to TokenStream 2023-12-30 20:11:24 +01:00
Sam Atkins
a76f29e56b LibWeb: Allow creating a TokenStream from a single token
This is quite niche, but lets us convert parsing methods to accepting
TokenStream, while still being able to call them when we just have a
lone token. Specifically we'll use this in the next commit, but it's
likely to also be useful as a stop-gap measure when converting more
parsing methods.
2023-12-30 20:11:24 +01:00
Sam Atkins
2f5379bc9b LibWeb: Use parse_length() for rect() parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
8200fdeddc LibWeb: Use parse_length_percentage() for border-radius parsing 2023-12-30 20:11:24 +01:00
Sam Atkins
30a11dc133 LibWeb: Use parsing helpers in parse_media_feature_value() 2023-12-30 20:11:24 +01:00
Sam Atkins
12bcd029ff LibWeb: Use parse_length_percentage() for radial-gradient radii 2023-12-30 20:11:24 +01:00
Sam Atkins
e62d692205 LibWeb: Implement helpers for parsing CSS numeric types
Frequently we want to parse "anything that's a `<length-percentage>`" or
similar, which could be a constant value or a calculation, but didn't
have a nice way of doing so. That meant repeating the same "try and
parse a dimension, see if it's the right type, then maybe try and parse
a calculation and see if that's the right type" boilerplate code. Or
more often, forgetting about calculations entirely.

These helpers should make that a lot more convenient to do. And they
also use TokenStream, so we can eventually drop the old `parse_length()`
method.
2023-12-30 20:11:24 +01:00
Shannon Booth
462f97b28a LibWeb: Port Element::get_attribute_value from ByteString 2023-12-27 09:23:44 +01:00
Sam Atkins
69f88c9a64 LibWeb: Parse grid property using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
5f99edad3b LibWeb: Parse grid-template property using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
b8c6c75ae1 LibWeb: Parse grid-template-[columns,rows] properties using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
ee5b00d1ee LibWeb: Parse grid-auto-[columns,rows] properties using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
4c17620712 LibWeb: Parse transform-origin property using TokenStream 2023-12-26 15:32:32 +00:00
Sam Atkins
dd5adb28fd LibWeb: Parse transform property using TokenStream
While I'm at it, use the helper for "none", and remove the unnecessary
whitespace skipping.
2023-12-26 15:32:32 +00:00
Sam Atkins
6a6995cb12 LibWeb: Make text-decoration-line parsing match other properties 2023-12-26 15:32:32 +00:00
Sam Atkins
ed77dee405 LibWeb: Parse text-decoration property using TokenStream 2023-12-26 15:32:32 +00:00
Sam Atkins
513dee04d4 LibWeb: Parse place-self property using TokenStream 2023-12-26 15:32:32 +00:00
Sam Atkins
5a8f57f7b3 LibWeb: Parse place-items property using TokenStream 2023-12-26 15:32:32 +00:00
Sam Atkins
61d6f611cb LibWeb: Parse place-content property using TokenStream 2023-12-26 15:32:32 +00:00
Sam Atkins
4f773a7dae LibWeb: Parse overflow property using TokenStream
Also simplify it a bit. We don't need to handle 1 / 2 values separately,
but past Sam didn't realise that.
2023-12-26 15:32:32 +00:00
Sam Atkins
0578bec655 LibWeb: Parse math-depth property using TokenStream
We don't need to skip whitespace at the top level because that's already
done before we're called. But we do still have to skip it inside the
`add()` function
2023-12-26 15:32:32 +00:00
Sam Atkins
6e0a550a03 LibWeb: Parse list-style property using TokenStream 2023-12-26 15:32:32 +00:00
Sam Atkins
14e2e2bac4 LibWeb: Parse grid track placements using TokenStream
I'm not entirely happy with this, but I barely understand grid, and this
does still work.
2023-12-26 15:32:32 +00:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Shannon Booth
ed97946975 LibWeb: Support obsolete but required -webkit- CSS parsing quirk
As outlined in: https://www.w3.org/TR/selectors-4/#compat

We now do not treat unknown webkit pseudo-elements as invalid at parse
time, and also support serializing these elements.

Fixes: #21959
2023-12-11 16:54:59 +01:00
Shannon Booth
83758d4cdd LibWeb: Wrap PseudoElements stored in SimpleSelector in a class
No functional impact intended. This is just a more complicated way of
writing what we have now.

The goal of this commit is so that we are able to store the 'name' of a
pseudo element for use in serializing 'unknown -webkit-
pseudo-elements', see:

https://www.w3.org/TR/selectors-4/#compat

This is quite awkward, as in pretty much all cases just the selector
type enum is enough, but we will need to cache the name for serializing
these unknown selectors. I can't figure out any reason why we would need
this name anywhere else in the engine, so pretty much everywhere is
still just passing around this raw enum. But this change will allow us
to easily store the name inside of this new struct for when it is needed
for serialization, once those webkit unknown elements are supported by
our engine.
2023-12-11 16:54:59 +01:00
Shannon Booth
08920b7a34 LibWeb: Simplify a conditional check in parse_pseudo_simple_selector
Put a shared `pseudo_element.has_value()` check into the same block.
2023-12-11 16:54:59 +01:00
Shannon Booth
2dce09b12e LibWeb: Use code_points helper for getting delim CSS token codepoint
This is less code, and more expressive.
2023-12-11 16:54:59 +01:00
Aliaksandr Kalenik
f50bf00814 LibWeb+LibGfx: Move UnicodeRange from LibWeb to LibGfx
In upcoming changes UnicodeRange is going to be used in LibGfx in
a class that represents font cascade list.
2023-12-10 17:32:04 +01:00
Shannon Booth
74b6e7b1f0 LibWeb: Avoid calling FlyString::from_utf8 on FlyString's 2023-12-10 09:45:03 +01:00
Shannon Booth
6ce0d588ee Everywhere: Avoid calling from_utf8 on FlyString or String
We already have a String :^)
2023-12-10 09:45:03 +01:00
Sam Atkins
29ecb2eda6 LibWeb: Parse grid-template-areas property using TokenStream 2023-12-08 10:47:23 +00:00
Sam Atkins
c3583317ee LibWeb: Parse grid-auto-flow property using TokenStream
RefPtr is already `[[nodiscard]]` so we can remove that extra noise from
the declaration.
2023-12-08 10:47:23 +00:00