Commit Graph

5807 Commits

Author SHA1 Message Date
Andreas Kling
7115446995 LibWeb: Support font-size: calc()
Now that we have a way to resolve calc() lengths without a layout node,
we can finally support calc() values in font-size.

This wasn't possible before because font-related properties have to be
resolved eagerly in StyleComputer due to font-relative CSS length units
depending on the computed font being known.
2023-06-02 20:03:28 +02:00
Andreas Kling
df8a96ee00 LibWeb: Add a way to resolve calc() values without a layout node
Instead of a layout node, you can pass a new Length::ResolutionContext
struct which contains everything needed to resolve calc() lengths.
2023-06-02 20:03:28 +02:00
Aliaksandr Kalenik
2ade229f27 LibWeb: Fix crashing when grid track size is calc() with percentage
Use contains_percentage() that works for calc() values instead of
is_percentage().

This fixes issue when tracks with calc() that has percentages where
considered as "fixed" tracks with resolvable size which led to
incorrectly resolved infinite final track sizes.
2023-06-02 19:02:31 +02:00
Sam Atkins
1f2629f132 LibWeb: Bounds-check parsed CSS types
This reintroduces bounds-checking for the CSS `<angle>`, `<frequency>`,
`<integer>`, `<length>`, `<number>`, `<percentage>`, `<resolution>`,
and `<time>` types.

I regressed this around 6b8f484114 when
changing how we parsed StyleValues.

This is an improvement from before though, since we now allow the bounds
of a dimension type to have units.

Added a test to make sure we don't regress this again. :^)
2023-06-02 17:46:35 +02:00
Sam Atkins
fbfce2e73e LibWeb: Add comparison operators to CSS numeric types (except Length)
This is to make it easier to bounds-check their values during parsing.
Length is left out because many length units are relative to the
context in which they are used, and so we cannot easily compare `10px`
and `1em`, for example.
2023-06-02 17:46:35 +02:00
Andreas Kling
06617a982e LibWeb: Support flex items with calc() main size containing percentages
If a flex item's main size is a CSS calc() value that resolves to a
length and contains a percentage, we can only resolve it when we have
the corresponding reference size for the containing block.
2023-06-02 17:17:45 +02:00
Andreas Kling
d6c3cbd958 LibWeb: Make StackingContext sorting a lot faster
Stacking contexts are sorted after building a tree of them. They are
sorted by z-index first, DOM tree order second.

Sorting was previously *very* slow on pages with many stacking contexts.
That was because the sort() function used Node::is_before() in the
quick_sort comparator to see if one StackingContext was before another.
is_before() does tree traversal and can take quite a long time per call.

This patch avoids all that by letting StackingContext know its index
among all StackingContexts within the same document in tree order.
There's a noticeable snappiness increase on the CSS-FLEXBOX-1 spec page,
for instance. :^)
2023-06-02 15:00:38 +02:00
stelar7
2ef6aa5f3d LibWeb: Parse clamp() css math function 2023-06-02 05:22:12 +02:00
stelar7
eaee0ecd88 LibWeb: Parse max() css math function 2023-06-02 05:22:12 +02:00
stelar7
6a10821bfd LibWeb: Parse min() css math function 2023-06-02 05:22:12 +02:00
stelar7
570e43a66a LibWeb: Move function parsing to separate method 2023-06-02 05:22:12 +02:00
MacDue
47fc91ed43 LibWeb: Remove per path clipping for SVGGeometryPaintable
Somewhere the path bounding box in the layout and the actual draw path
are getting slightly mismatched. This results in partly clipped bits of
SVGs. The paths are already clipped to the containing SVG, and the size
of the path in the layout is computed from the bounding box, so it is
probably safe just to remove this clipping for now.
2023-06-02 05:21:48 +02:00
FalseHonesty
de9604212f LibWeb: Avoid text-aligning content that is too long for its line box
Previously, we would always respect the `text-align` property, even if
the text being aligned was too long for its line box and would be
clipped. This led to seeing the clipped middle/end of strings when we
should instead always see the beginning of the text.
2023-06-02 05:21:22 +02:00
Sam Atkins
7ce4cbfe1d LibWeb: Convert NumberStyleValue from float to double
We have double precision in the parser, and currently use doubles for
most of layout, so we might as well keep that extra precision inside
NumberStyleValue too.
2023-06-01 21:04:21 +02:00
Sam Atkins
8889635ba7 LibWeb: Remove int usage of NumberStyleValues
Use IntegerStyleValue where we should; remove the ability of
NumberStyleValue to hold integers, and add integer interpolation for
animations.
2023-06-01 21:04:21 +02:00
Sam Atkins
1160d8186b LibWeb: Implement IntegerStyleValue, for holding <integer>
Having one StyleValue for `<number>` and `<integer>` is making user code
more complicated than it needs to be. We know based on the property
being parsed, whether it wants a `<number>` or an `<integer>`, so we
can use separate StyleValue types for these.
2023-06-01 21:04:21 +02:00
Sam Atkins
ad8565011c LibWeb: Rename NumericStyleValue -> NumberStyleValue
This is in preparation of splitting off a separate IntegerStyleValue.
2023-06-01 21:04:21 +02:00
Andreas Kling
1a6a4ca7d4 LibWeb: Round lengths to 3 decimals after resolving from percentage
This is a hack to emulate the behavior of other engines that use
fixed-point math. By rounding to 3 decimals, we retain a fair amount of
detail, while still allowing overshooting 100% without breaking lines.

This is both gross and slow, but it fixes real sites. Notably, the
popular Bootstrap library uses overshooting percentages in their
12-column grid system.

This hack can be removed when CSSPixels is made a fixed-point type.
2023-06-01 18:13:42 +02:00
Andreas Kling
3f9cfa144c LibWeb: Allow infinitely long flex lines when sizing under max-content
If the flex container is being sized under a max-content main size
constraint, there is effectively infinite space available for flex
items. Thus, flex lines should be allowed to be infinitely long.

This is a little awkward, because the spec doesn't mention specifics
about how to resolve flexible lengths during intrninsic sizing.
I've marked the spec deviations with big "AD-HOC" comments.
2023-06-01 15:11:48 +02:00
stelar7
9c74f49b1d LibWeb: Implement has_transient_activation 2023-06-01 14:28:52 +02:00
stelar7
29029de839 LibWeb: Set last activation timestamp on the window 2023-06-01 14:28:52 +02:00
stelar7
266d4a3553 LibWeb: Implement step 7 of choose_a_browsing_context 2023-06-01 14:28:52 +02:00
Andreas Kling
caa491b72a LibWeb: Measure the overflow for all scroll containers
Instead of just measuring the layout viewport, we now measure overflow
in every box that is a scroll container.

This has the side effect of no longer creating paintables for layout
boxes that didn't participate in layout. (For example, empty/anonymous
boxes that were ignored by flex itemization.)

Such boxes are now marked as "(not painted)" in the layout tree dumps,
as they have no paintable to dump geometry from.
2023-06-01 13:33:35 +02:00
Andreas Kling
b7d2f6fa88 LibWeb: Clip overflow in descendant boxes for non-visible CSS overflow
We were only clipping for hidden, when we should be clipping for hidden,
clip, scroll and auto. Basically everything but visible. :^)
2023-06-01 13:33:35 +02:00
Andreas Kling
4ff52cebc4 LibWeb: Let's say that layout viewports are always scroll containers
This will allow us to have a shared code path for overflow calculation.
2023-06-01 13:33:35 +02:00
Andreas Kling
571c05bb47 LibWeb: Include scrollable overflow in paint tree dumps 2023-06-01 13:33:35 +02:00
Andreas Kling
966058d693 LibWeb: Support line-height: calc(...) values that resolve to number
This is used on GitHub and many other websites.
2023-06-01 09:20:05 +02:00
FalseHonesty
dcead6f5eb LibWeb: Add support for parsing place-content shorthand CSS property 2023-06-01 09:06:13 +02:00
Andreas Kling
fde86350e3 LibWeb: Put debug spam about indefinitely sized SVGs behind a flag 2023-06-01 07:34:37 +02:00
Andreas Kling
c62c714764 LibWeb: Put debug spam about negative content sizes behind a flag
We already clamp these values to zero, so it's actually pretty harmless
when this happens. If someone wants to investigate these issues deeper
and see if they can be fixed earlier in the layout pipeline, they can
enable the spam locally.
2023-06-01 07:34:37 +02:00
Andi Gallo
827936cf7b LibWeb: Invalidate layout tree in textContent setter
The textContent setter changes the structure of the DOM, therefore the
layout tree becomes invalid.
2023-06-01 07:22:50 +02:00
Andreas Kling
4fed7beb7b LibWeb: Make solve_replaced_size_constraint() into FormattingContext 2023-05-31 11:38:05 +02:00
Andreas Kling
42470d837e LibWeb: Move layout box rect helpers into FormattingContext
These are only used during layout, and always within formatting context
code, so we might as well put them in FormattingContext and avoid having
to pass the LayoutState around all the time.
2023-05-31 11:38:05 +02:00
Andreas Kling
4f08fcde29 LibWeb: Remove unnecessary static formatting context functions
At one point in the past, we had some functions that were called across
different formatting context types, which necessitated making them
static and taking the LayoutState as a parameter.

In all cases, those functions were used to do incorrect hacks, all of
which we've replaced with more correct solutions. :^)
2023-05-31 11:38:05 +02:00
stelar7
421559d725 LibWeb: Change calc node representation from float to double 2023-05-31 10:56:32 +02:00
stelar7
344f37986f LibWeb: Allow calculated values in transform 2023-05-31 05:57:53 +02:00
stelar7
e23d31ae83 LibWeb: Lazy evaluate optional to avoid crash 2023-05-31 05:56:46 +02:00
stelar7
5cdeb994b2 LibWeb: Serialize Resolution according to spec 2023-05-31 05:56:25 +02:00
stelar7
b6d767fbb0 LibWeb: Serialize Frequency according to spec 2023-05-31 05:56:25 +02:00
stelar7
5dc82db0cb LibWeb: Serialize Angle according to spec 2023-05-31 05:56:25 +02:00
stelar7
e72b7c5de2 LibWeb: Serialize Time according to spec 2023-05-31 05:56:25 +02:00
Simon Wanner
b5ba479d65 LibWeb: Render svg-as-image with 1:1 scaling factor
We're passing the SVGDecodedImageData a size in device pixels, so it's
incorrect to apply the host page's device_pixels_per_css_pixels on top
of that.
2023-05-30 21:28:18 +02:00
Aliaksandr Kalenik
31b9729333 LibWeb: Add Page::has_ongoing_navigation()
Introduce has_ongoing_navigation() that allows to check if resource
state in FrameLoading is pending. This API is going to be used in
upcoming fix for wait_for_navigation_to_complete() in WebDriver.
2023-05-30 20:40:23 +02:00
Aliaksandr Kalenik
857ceb215c LibWeb/WebDriver: Support resolve with callback in execute_async_script
Before execute_async_script supported returning value from script to
/execute/async caller only if script returns promise that resolves into
returned value. This change fixes execute_async_script to also support
returning value to caller using callback that is always passed to
script as a last argument.
2023-05-30 18:55:47 +02:00
Ali Mohammad Pur
0e3fb39a0a LibWeb: Make 'optional BufferSource' IDL arguments actually optional
Previously this was compiled to require an object despite the IDL file
specifying 'optional'.
This commit makes IDLGenerator respect this modifier, and fixes the only
affected instance.
2023-05-30 12:50:13 +02:00
Andi Gallo
7f9ede07bc LibWeb: Set margin, padding and border for replaced boxes
Separating the paths for replaced and non-replaced floating boxes lost
the logic for margin, padding and border which was done by
compute_width_for_floating_box. Set them the same way as we do for
block-level replaced elements, per the specification.
2023-05-30 10:09:47 +02:00
Andi Gallo
e48074e401 LibWeb: Make font selection closer to specification
Add matching on family name, style and weight. This improves the fonts
used by the MDN examples.
2023-05-30 07:47:57 +02:00
stelar7
518679b0dd LibWeb: Adjust change event timing for input elements 2023-05-30 06:17:36 +02:00
FalseHonesty
cabfb7867c LibWeb: Add support for parsing 'inset' shorthand CSS property 2023-05-30 06:02:06 +02:00
Timothy Flynn
e129c8049b LibWeb: Restore protection against empty HTMLImageElement resources
This if-statement was erroneously dropped in commit 8ff8309.
2023-05-30 05:50:07 +02:00