Commit Graph

1749 Commits

Author SHA1 Message Date
Andreas Kling
1cea4e6407 LibWeb: Use cached UsedValues pointer in IFC and its helper classes
This avoids expensive LayoutState lookups when we already have the
pointer sitting around anyway.
2024-03-16 14:27:59 +01:00
MacDue
163b6bb401 LibWeb: Special case SVG masks during layout
Rather than try to lay out masks normally, this updates the TreeBuilder
to create layout nodes for masks as a child of their user (i.e. the
masked element). This allows each use of a mask to be laid out
differently, which makes supporting `maskContentUnits=objectBoundingBox`
fairly easy.

The `SVGFormattingContext` is then updated to lay out masks last (as
their sizing may depend on their parent), and treats them like
viewports.

This is pretty ad-hoc, but the SVG specification does not give any
guidance on how to actually implement this.
2024-03-12 08:51:50 +01:00
MacDue
05f42efc06 LibWeb: Support preserveAspectRatio=none for SVGs
This is very easy now all transforms are computed during layout.
2024-03-12 08:51:50 +01:00
Aliaksandr Kalenik
bcdf4a375d LibWeb: Use resolve_grid_position for abspos boxes layout in GFC
Removes duplicated code that resolves position based on computed
values.

No behaviour change intended.
2024-03-11 15:20:58 +01:00
implicitfield
5da9f52b1f LibWeb: Use the parent container's y offset when finding static position
Fixes #18819.
2024-03-10 18:10:01 +01:00
implicitfield
54d8e58a68 LibWeb: Account for margin and padding of justified abspos flex items 2024-03-09 16:02:17 +01:00
implicitfield
3888a91c5b LibWeb: Account for margin and padding of aligned abspos flex items
This patch also makes FlexFormattingContext::calculate_static_position
use computed values for margins and borders, since this function may be
called before the box's state has been finalized.
2024-03-09 16:02:17 +01:00
implicitfield
e3b1d4a141 LibWeb: Compute content width before static position for abspos elements
In some scenarios, correctly computing the static position may depend on
the content width having been calculated beforehand.
2024-03-09 16:02:17 +01:00
Aliaksandr Kalenik
749dcac196 LibWeb: Add record_grid_placement() helper in GFC
When placement position is found we always want to do following:
- Mark the occupied cells in the occupation grid
- Add the item to the list of placed items

Therefore, having helper that does both is useful
2024-03-07 08:26:37 +01:00
Aliaksandr Kalenik
2a3891781c LibWeb: Delete is_auto_positioned_row{column} in GFC
Use is_auto_positioned_track() instead.
2024-03-07 08:26:37 +01:00
Aliaksandr Kalenik
1fbd9674b4 LibWeb: Use resolve_grid_position if row and column are definite in GFC
With this change we use the same code to resolve (start, end, span)
based on computed values in all cases:
- When only column is definite
- When only row is definite
- When both are definite
2024-03-07 08:26:37 +01:00
Aliaksandr Kalenik
8695a82c56 LibWeb: Extract common path in definite row/column placement in GFC
Moves the code that identifies (start, end, span) for a grid item into
a separate function. By doing so, we can eliminate the duplicated code
between the placement of grid items with definite columns and those
with definite rows.

This change omits some of the comments that reference the spec, as they
were largely irrelevant and unhelpful for making changes or diagnosing
issues.
2024-03-07 08:26:37 +01:00
implicitfield
0243278587 LibWeb: Account for absolutely positioned table wrappers
Table wrappers don't quite behave the same as most elements, in that
their computed height and width are not meant to be used for layout.
Instead, we now calculate suitable widths and heights based on the
contents of the table wrapper when performing absolute layout.

Fixes the layout of
http://wpt.live/css/css-position/position-absolute-center-007.html
2024-03-07 08:09:04 +01:00
Matthew Olsson
1ca31e0dc1 LibWeb: Remove unnecessary ErrorOr<> from StyleComputer
All of this error propogation came from a single call to
HashMap::try_ensure_capacity! As part of the ongoing effort to ignore
small allocation failures, lets just assert this works. This has the
nice side-effect of propogating out to a few other classes.
2024-03-06 07:45:56 +01:00
Aliaksandr Kalenik
4d8bc16812 LibWeb: Respect "auto flow" property in grid layout
Before this change, we only considering `grid-auto-flow` to determine
whether a row or column should be added when there was not enough space
in the implicit grid to fit the next unplaced item.

Now, we also choose the direction in which the "auto placement cursor"
is moved, based on the auto flow property.
2024-03-06 07:23:27 +01:00
MacDue
4f78ddd6a2 LibWeb: Setup computed values for SVG geometry properties 2024-03-04 10:50:32 +01:00
MacDue
b9afea40e6 LibWeb: Update SVG get_path() API to take a viewport size
This will allow resolving paths that use sizes that are relative to the
viewport. This necessarily removes the on element caching, which has
been redundant for a while as computed paths are stored on the
paintable.
2024-03-04 10:50:32 +01:00
Zac Brannelly
4a3680cafc LibWeb/CSS: Add "text" into list of possible "background-box" values 2024-03-03 15:33:12 +01:00
Aliaksandr Kalenik
06c176bbfb LibGfx+LibWeb: Use ref-counted object to store glyph run
...to avoid allocating a copy of glyph run for painting commands. We
can't simply save pointers to a glyph run in layout/paintable tree
because it should be safe to deallocate layout and paintable trees
after painting commands are recorded, if in the future we decide to
move command execution to a separate thread.
2024-03-02 09:09:10 +01:00
implicitfield
b08fd1b9ae LibWeb: Improve support for 'vertical-align: middle'
This rebaselines a few table-related layout tests since our default
stylesheet applies 'vertical-align: middle' to a few table-related
elements.
2024-02-28 16:11:05 -05:00
Aliaksandr Kalenik
8d9e20cb03 LibWeb: Parse the CSS scrollbar-width property 2024-02-28 07:51:13 -05:00
Aliaksandr Kalenik
a0dc9584de LibWeb: Add "object-position" CSS property into ComputedValues 2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
677a00ed92 LibWeb: Add "object-fit" CSS property into ComputedValues 2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
ef01c735cd LibWeb: Visit ImageProvider from Layout::ImageBox
Adds missing visit of HTMLElement that serves as image provider of
image layout node.
2024-02-27 16:53:13 +01:00
Andreas Kling
a61f09a010 LibWeb: Stretch-fit flex items with aspect ratio but no fixed sizes
This solves a particular issue with SVG as flex items, where the SVG has
an intrinsic aspect ratio via its viewBox, but no explicit natural width
or height.

Makes all corporate sponsor logos show up on https://ziglang.org/ :^)
2024-02-25 14:06:06 +01:00
Tim Ledbetter
588a031e2d LibWeb: Clamp calculated border width values to zero
Previously, a calculated CSS border-width property with a resolved
value of less than zero pixels would cause a crash.
2024-02-24 21:57:24 +01:00
Aliaksandr Kalenik
309259aeb6 LibWeb: Clamp scroll offset into valid range after relayout
If the layout has been recalculated and the sizes of scrollable
overflow rectangles could have changed, we need to ensure that scroll
offsets remain within the valid range.
2024-02-22 07:35:30 +01:00
Andreas Kling
f963bb4f36 LibWeb: Don't mark heights as definite in set_content_height()
Height definiteness is now preserved as intended by CSS-SIZING-3
(assuming I've understood it correctly) and not implicitly granted by
layout algorithms when they assign height.

For the specific special/magical cases where some sizes become definite
during layout, the preceding commits have made them explicit in code.

This fixes a number of flex layout issues where we were previously
resolving percentage values against post-layout flex container heights,
but other browsers don't.
2024-02-21 17:54:05 +01:00
Andreas Kling
0dd8458683 LibWeb: Add FIXME about definiteness to UsedValues::set_content_width()
Fixing this function will be quite an undertaking since a *lot* of code
relies on set_content_width() implicitly flipping the definiteness of
the width. It is wrong though, so we do need to fix it eventually.
2024-02-21 17:54:05 +01:00
Andreas Kling
221650f3cd LibWeb: Mark fixed-length abspos element sizes as definite
In particular, these two interesting cases:

- The containing block of an abspos box is always definite from the
  perspective of the abspos box.

- When resolving abspos box sizes from two opposing fixed insets,
  we now mark those sizes as definite (since no layout was required
  to resolve them).
2024-02-21 17:54:05 +01:00
Andreas Kling
70ce77fc72 LibWeb: Make SVGFormattingContext treat all sizes as definite for now
The whole way we lay out SVG content is ad-hoc, so this doesn't follow
any particular spec. However, our viewport transform logic depends on
having definite sizes, so let's just mark them as such for now.
2024-02-21 17:54:05 +01:00
Andreas Kling
f0269b0a94 LibWeb: Mark root element height as definite when affected by quirk
This will be required for percentages to resolve against it correctly
after we make set_content_height() not automatically mark heights as
definite sizes.
2024-02-21 17:54:05 +01:00
Andreas Kling
b079f4d590 LibWeb: Make flexbox special definite size cases explicit
The CSS-FLEXBOX-1 spec has a bunch of special cases where sizes are
considered definite after reaching a specific point of the layout
algorithm.

Before this change, we were relying on set_content_width/height also
implicitly marking those content sizes as definite.

To prepare for that implicit behavior going away, this patch makes
the special cases explicit.
2024-02-21 17:54:05 +01:00
Andreas Kling
5a995e95e3 LibWeb: Add UsedValues::set_has_definite_width/height()
These will be used to explicitly mark some box geometry as definite
at various stages of layout. It's gonna get finicky.
2024-02-21 17:54:05 +01:00
Andreas Kling
b83e41c9b5 LibWeb: Only assign block container heights during BFC intrinsic sizing
Before this change, we were always assigning the calculated height to
each block container after laying it out in BFC.

This should really only happen during intrinsic sizing, since that is
how measurements are communicated to the client there.
2024-02-21 17:54:05 +01:00
Aliaksandr Kalenik
aee5120078 LibWeb: Fix infinite recursion when grid has "max-width: max-content"
With this change "max-width: max-content" is treated as "none" when
the available width is also "max-content". This fix prevents a stack
overflow in the grid track size maximization algorithm by avoiding
recursive calls to calculate_max_width() when determining the maximum
grid container size.
2024-02-21 10:06:19 +01:00
Aliaksandr Kalenik
c4f49e343a LibWeb: Fix division by zero in solve_replaced_size_constraint()
Fixes crashes that occur in Discord after clicking on a direct messages
conversation.
2024-02-20 20:35:34 +01:00
Timothy Flynn
45a47cb32b LibWeb: Generalize ImageBox and ImagePaintable for any ImageProvider
They currently assume the DOM node is an HTMLImageElement with respect
to handling the alt attribute. The HTMLInputElement will require the
same behavior.
2024-02-19 11:07:30 +01:00
Aliaksandr Kalenik
1af466babf LibWeb: Fix invalidation of CSS properties that do not affect layout
Recently, we moved the resolution of CSS properties that do not affect
layout to occur within LayoutState::commit(). This decision was a
mistake as it breaks invalidation. With this change, we now re-resolve
all properties that do not affect layout before each repaint.
2024-02-03 09:28:03 +01:00
MacDue
b10f58a1fe LibWeb: Support x and y attributes on nested SVGs
This allows positioning a child SVG relative to its parent SVG.

Note: These have been implemented as CSS properties as in SVG 2, these
are geometry properties that can be used in CSS (see
https://www.w3.org/TR/SVG/geometry.html), but there is not much browser
support for this. It is nicer to implement than the ad-hoc SVG
attribute parsing though, so I feel it may make sense to port the rest
of the attributes specified here (which should fix some issues with
viewport relative sizes).
2024-01-29 10:01:10 +00:00
Tim Ledbetter
99fbd33d7d LibWeb: Make button flex wrapper inherit min-height property
This ensures that the vertical positioning of button text is correct
if a `min-height` property is present.
2024-01-28 14:48:33 +01:00
MacDue
5cf1570f40 LibWeb: Add initial support for nesting SVG viewports
Previously, we were handling viewBoxes/viewports in a slightly hacky
way, asking graphics elements to figure out what viewBox to use during
layout. This does not work in all cases, and can't allow for more
complex SVGs where it is possible to have nested viewports.

This commit makes the SVGFormattingContext keep track of the
viewport/boxes, and it now lays out each viewport recursively, where
each nested `<svg>` or `<symbol>` can establish a new viewport.

This fixes some previous edge cases, and starts to allow nested
viewports (there's still some issues to resolve there).

Fixes #22931
2024-01-27 18:12:13 +01:00
Andreas Kling
ad7e6878fe LibWeb: Allocate CSS::ComputedValues objects on the heap
This makes them cheap to move around, since we can store them in a
NonnullOwnPtr instead of memcopying 2584(!) bytes.

Drastically reduces the chance of stack overflow while building the
layout tree for deeply nested DOMs (since tree building was putting
these things on the stack).

This change also exposed a completely unnecessary ComputedValues deep
copy in block layout.
2024-01-27 12:27:44 +01:00
Sam Atkins
e025bcc4f9 LibWeb: Make use of transform-box when calculating transforms
We don't currently calculate the fill- or stroke-boxes of SVG elements,
so for now we use the content- and border-boxes respectively, as those
are the closest equivalents. The test will need updating when we do
support them.

Also, the test is a screenshot because of rendering differences when
applying transforms: a 20px box does not get painted the same as a 10px
box scaled up 2x. Otherwise that would be the more ideal form of test.
2024-01-27 07:46:37 +01:00
Sam Atkins
391cfdc085 LibWeb: Parse the CSS transform-box property 2024-01-27 07:46:37 +01:00
Aliaksandr Kalenik
0d76a9da17 LibWeb: Resolve text-decoration-thickness during layout commit
Refactoring towards stop resolving CSS lengths during paintable
commands recording.
2024-01-26 07:36:40 +01:00
Andreas Kling
1583e6ce07 LibWeb: Clamp justification space between flex items to 0
Before this change, it was possible for flex lines with negative
remaining space (due to overflowing items) to put a negative amount
of space between items for some values of `justify-content`.

This makes https://polar.sh/SerenityOS look much better :^)
2024-01-25 15:10:21 +01:00
Andreas Kling
7fedf806c2 LibWeb: Cache pointer to UsedValues for each FlexItem
This avoids expensive repeated LayoutState hash lookups.
2024-01-24 07:53:33 +01:00
Andreas Kling
4e6de47f93 LibWeb: Avoid LayoutState hash lookups in more parts of float layout 2024-01-24 07:53:16 +01:00
Aliaksandr Kalenik
91ef4fed93 LibWeb: Resolve all layout-dependent properties in one loop
Instead of using separate loops for each property, all the work can
be completed in one loop.

Performance improvement on https://html.spec.whatwg.org/
2024-01-23 21:06:02 +01:00