Commit Graph

162 Commits

Author SHA1 Message Date
Aliaksandr Kalenik
94fd17a467 LibWeb: Wrap child text sequences of grid container in anonymous blocks
From spec https://drafts.csswg.org/css-grid/#grid-items:
"Each in-flow child of a grid container becomes a grid item, and each
child text sequence is wrapped in an anonymous block container grid
item."

Fixes the problem that text sequences inside grid containers are
ignored and not displayed.
2023-05-28 21:12:04 +02:00
Aliaksandr Kalenik
537256fae2 LibWeb: Treat unresolvable percentages as auto to resolve sizes in GFC
Fixes the bug that currently we always consider tracks with percentage
size as ones with "fixed" length even when available size is not
definite. With this change tracks with percentage size when available
size is not definite will be considered as "intrinsic" sized.
2023-05-28 20:26:05 +02:00
Andreas Kling
30feb95d53 LibWeb: Support reverse flex layout with space-around/space-between
We were not taking reverse flex directions into account when choosing
the initial offset for flex item placement if justify-content were
either space-around or space-between.
2023-05-28 18:02:00 +02:00
Andi Gallo
29d29134ba LibWeb: Skip children based on media when updating the source set
If child has a media attribute and its value does not match the
environment, continue to the next child.
2023-05-28 12:11:10 +02:00
Karthik Karanth
f60446bbfe LibWeb: Unit tests for min/max-inline-size 2023-05-27 16:02:33 +02:00
Andreas Kling
8ba7bd1b67 LibWeb: Accept fit-content as a value for min-width and max-width
This starts working immediately in BFC thanks to calculate_inner_width
being used for width constraints. :^)
2023-05-27 05:47:54 +02:00
Andreas Kling
1bb4e5c428 LibWeb: Support fit-content width for block-level boxes 2023-05-27 05:47:54 +02:00
Andreas Kling
a277c393b9 LibWeb: Support grid items with fit-content width :^) 2023-05-27 05:47:54 +02:00
Aliaksandr Kalenik
ab5b89eb95 LibWeb: Add basic parsing of grid shorthand CSS property
Introduces incomplete parsing of grid shorthand property. Only
<grid-template> part of syntax is supported for now but it is enough
to significantly improve rendering of websites that use this shorthand
to define grid :)
2023-05-27 05:47:14 +02:00
Andi Gallo
1e526af430 LibWeb: Fix width calculation for floating replaced elements
The path for floating, replaced elements must not fall through to the
path taken for floating, non-replaced elements. The former works like
inline replaced elements, while the latter uses a completely different
algorithm which doesn't account for intrinsic ratio. Falling through
overrides the correct value computed by the former.

Fixes #19061.
2023-05-26 21:20:56 +02:00
Aliaksandr Kalenik
7cc20f4cb5 LibWeb: Reset margin collapsing state only if box indeed add clearance
This fixes the issue when margin collapsing state was always reset if
a box has clear property not equal to none even if it does not actually
introduce clearance.
2023-05-26 18:11:35 +02:00
Cameron Youell
0afdde0eef LibWeb: Consume sign in SVG::parse_elliptical_arg_argument
This was crashing on google.com with the linux chrome user agent,
interestingly it seems like this behavior may have been accidental as
only two of the three `parse_number()` were changed in f7dbcb6
2023-05-26 14:54:00 +02:00
Andi Gallo
5cec517153 LibWeb: Get reference height from closest non-anonymous ancestor
Ignore anonymous block boxes when resolving percentage weights that
would refer to them, per the CSS 2 visual formatting model
specification. This fixes the case when we create an anonymous block
between an image which uses a percentage height relative to a parent
which specifies a definite height.

Fixes #19052.
2023-05-26 14:53:53 +02:00
Andreas Kling
7d24c13d8b LibWeb: Make input element placeholders look better
We now create a flex container inside the input element's UA shadow tree
and add the placeholder and non-placeholder text as flex items (wrapped
in elements whose style we can manipulate).

This fixes the visual glitch where the placeholder would appear below
the bounding box of the input element. It also allows us to align the
text vertically inside the input element (like we're supposed to).

In order to achieve this, I had to make two small architectural changes
to layout tree building:

- Elements can now report that they represent a given pseudo element.
  This allows us to instantiate the ::placeholder pseudo element as an
  actual DOM element inside the input element's UA shadow tree.

- We no longer create a separate layout node for the shadow root itself.
  Instead, children of the shadow root are treated as if they were
  children of the DOM element itself for the purpose of layout tree
  building.
2023-05-25 14:42:24 +02:00
Aliaksandr Kalenik
202b24584f LibWeb: Sum horizontal margins to calculate space used by floats
This fixes the issue where max margin is used to find offset of
floating box although horizonal margins do not collapse so they need
to be summed instead.
2023-05-24 18:58:42 +02:00
Jelle Raaijmakers
90d8844c77 LibWeb: Remove Gfx::Rect<float> workarounds from BFC
No longer is the last horizontal line of pixels ignored during layout.
This used to be a bug in `Gfx::Rect<float>` that was fixed in
f391ccfe53.
2023-05-24 18:19:45 +02:00
Andreas Kling
655d9d1462 LibWeb: Make CSSPixels and Length use 64-bit (double) floating point
This fixes a plethora of rounding problems on many websites.
In the future, we may want to replace this with fixed-point arithmetic
(bug #18566) for performance (and consistency with other engines),
but in the meantime this makes the web look a bit better. :^)

There's a lot more things that could be converted to doubles, which
would reduce the amount of casting necessary in this patch.
We can do that incrementally, however.
2023-05-24 14:40:35 +02:00
Andreas Kling
30262d7023 LibWeb: Rebaseline a layout test after 10ceacf5fb 2023-05-24 13:25:05 +02:00
Andreas Kling
71d5dc510e LibWeb: Resolve CSS variables if present in SVG presentation attributes
SVG presentation attributes are parsed as CSS values, so we also need to
handle CSS variable expansion when handling them.

This (roughly) matches the behavior of other engines. It's also used on
the web, for example on https://stripe.com/ :^)
2023-05-24 06:43:21 +02:00
Aliaksandr Kalenik
76aa17be86 LibWeb: Make sure collapsed margins are not ignored if box creates FC
Fixes a bug that if box creates new formatting context then all already
collapsed margins are ignored and only margin_top is used.
2023-05-22 12:51:24 +02:00
Andi Gallo
668578ddc0 LibWeb: Propagate children_are_inline in wrap_in_anonymous
This fixes a crash in box_baseline, due to cells created for
display: table expecting a box child and getting the inline node wrapper
instead.

Fixes #18972.
2023-05-22 10:25:18 +02:00
Aliaksandr Kalenik
193290b19a LibWeb: Support grid-auto-columns and grid-auto-rows properties in GFC
Implements assignment of sizes specified in grid-auto-columns/rows for
implicitly created tracks.
2023-05-22 06:05:19 +02:00
Andi Gallo
e6221117a5 LibWeb: Implement table rowspan
Adjust computing the table height and positioning of cells to account
for the rowspan property.

Fixes #18952.
2023-05-21 14:23:41 +02:00
Andreas Kling
6cb9d755d9 LibWeb: Don't crash on percentage values for CSS stroke-width
Fixes a crash when loading https://vercel.com/
2023-05-21 12:40:27 +02:00
Aliaksandr Kalenik
409333d80a LibWeb: Implement more of spanning tracks sizing in GFC
Implements more parts of sizing algorithm for tracks with spanning
items to archive parity with implementation for sizing of tracks
with non-spanning items.
2023-05-21 11:59:19 +02:00
Andreas Kling
94a26e2715 LibWeb: Include SVG-as-image isolated contexts in layout/DOM tree dumps
This allows us to see the inside of SVG-as-image in layout tests. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
24ea78c613 LibWeb: Add a very basic test for SVG-as-image
This mainly just checks that we load the file and learn the correct
intrinsic aspect ratio from the external SVG.
2023-05-21 07:44:29 +02:00
Andreas Kling
f0560fd087 LibWeb: Support <svg> elements with display: block
There are a couple of things that went into this:

- We now calculate the intrinsic width/height and aspect ratio of <svg>
  elements based on the spec algorithm instead of our previous ad-hoc
  guesswork solution.

- Replaced elements with automatic size and intrinsic aspect ratio but
  no intrinsic dimensions are now sized with the stretch-fit width
  formula.

- We take care to assign both used width and used height to <svg>
  elements before running their SVG formatting contexts. This ensures
  that the inside SVG content is laid out with knowledge of its
  viewport geometry.

- We avoid infinite recursion in tentative_height_for_replaced_element()
  by using the already-calculated used width instead of calling the
  function that calculates the used width (since that may call us right
  back again).
2023-05-20 08:49:42 +02:00
Andreas Kling
6f204f8c32 LibWeb: Fix null dereference on SVG element with bogus fill URL
Fixes a crash seen on YouTube channel pages.
2023-05-19 15:41:34 +02:00
Andreas Kling
411b28fc59 LibWeb: Make sure that margins don't collapse across a nested BFC
In order to fix this, I also had to reorganize the code so that we
create an independent formatting context even for block-level boxes
that don't have any children. This accidentally improves a table
layout test as well (for empty tables).
2023-05-19 15:09:09 +02:00
Aliaksandr Kalenik
902ceb1675 LibWeb: Resolve grid item fixed size paddings in GFC
Adds support for grid items with fixed size paddings. Supporting
percentage paddings will probably require to do second pass of tracks
layout: second pass is needed to recalculate tracks sizes when final
items sizes are known when percentage paddings are already resolved.
2023-05-19 06:12:05 +02:00
Aliaksandr Kalenik
82aedfcaf0 LibWeb: Use grid item used width as available width during track sizing
This change addresses the incorrect assumption that the available width
inside a grid item is equal to the width of the track it belongs to.
For instance, if a grid item has a width of 200px, the available width
inside that item is also 200px regardless of its column(s) base size.

To solve this issue, it was necessary to move the final resolution of
grid items to occur immediately after the final column track sizes are
determined. By doing so, it becomes possible to obtain correct
available width inside grid items while resolving the row track sizes.
2023-05-18 18:06:05 +02:00
Andreas Kling
fb722e69f3 LibWeb: Resolve CSS custom properties on pseudo elements
The resolved property sets are stored with the element in a
per-pseudo-element array (same as for pseudo element layout nodes).

Longer term, we should stop storing this with elements entirely and make
it temporary state in StyleComputer somehow, so we don't waste memory
keeping all the resolved properties around.

This makes various gradients show up on https://shopify.com/ :^)
2023-05-17 20:37:29 +02:00
Aliaksandr Kalenik
628efda754 LibWeb: Consider span > 1 while getting available space for items in GFC 2023-05-17 15:55:14 +02:00
Aliaksandr Kalenik
d6d097b671 LibWeb: Remove borders from TemporaryTrack in GFC
This change makes grid items be responsible for their borders instead
of grid tracks which can not have borders itself.

There are changes in layout tests but those are improvements :)
2023-05-17 09:11:29 +02:00
Aliaksandr Kalenik
c61bb1706f LibWeb: Use auto minimimum size while resolving flexible tracks in GFC 2023-05-17 07:48:38 +02:00
Aliaksandr Kalenik
5f2264a2bd LibWeb: Skip non-spanning items sizing if there are no such items
Otherwise base_size and growth_limit for tracks that do not have any
spanning items will be overriden with wrong values.
2023-05-17 07:48:38 +02:00
Aliaksandr Kalenik
a3759b6e76 LibWeb: Implement more of "Expand Flexible Tracks" in GFC
Implements "Otherwise, if the free space is an indefinite length:" from
the spec.
2023-05-17 07:48:38 +02:00
Andreas Kling
2e13f65ff4 LibWeb: Support flex-basis: calc(...)
1. Propagate calc() values from StyleProperties to ComputedValues.
2. Actually resolve calc() values when determining the used flex basis.

This makes the "support" section on https://shopify.com/ show up
correctly as a 2x2 grid (instead of 1x4). :^)
2023-05-17 07:40:17 +02:00
Andreas Kling
e81d4ca1ac LibWeb: Fix off-by-one in CSS calc() "negate" operation
When negating a number, we should subtract it from 0, not 1. :^)
2023-05-17 07:40:17 +02:00
Andreas Kling
e938860126 LibWeb: Make text justification work between floats
While inline content between floating elements was broken correctly,
text justification was still using the original amount of available
space (without accounting for floats) when justifying fragments.
2023-05-16 14:35:10 +02:00
Andreas Kling
bab6796099 LibWeb: Rewrite calculation of available space between floats
This code now works in terms of *intrusion* by left and right side
floats into a given box whose insides we're trying to layout.

Previously, it worked in terms of space occupied by floats in the root
box of the BFC they participated in. That created a bunch of edge cases
since the code asking about the information wasn't operating in root
coordinate space, but in the coordinate space of some arbitrarily nested
block descendant of the root.

This finally allows horizontal margins in the containing block chain to
affect floats and nested content correctly, and it also allows us to
remove a bogus workaround in InlineFormattingContext.
2023-05-16 14:35:10 +02:00
Andi Gallo
9a6a635e51 LibWeb: Fix for absolutely positioned elements with specified height
Use inner height since the paintable adds padding back.

Fixes #18842.
2023-05-16 14:34:53 +02:00
Aliaksandr Kalenik
a613a0973e LibWeb: Reset item_incurred_increase before distributing space in GFC
item_incurred_increase should be reset before every next distirbution
because otherwise it will accumulate increases from previous
distributions which is not supposed to happen.
2023-05-16 07:47:47 +02:00
Andreas Kling
5d4e9a0673 LibWeb: Basic support for CSS text-indent: <length-percentage>
Note that this simple form of text-indent only affects the first line
of formatted content in each block.

Percentages are resolved against the width of the block.
2023-05-15 19:31:09 +02:00
Aliaksandr Kalenik
87a7299078 LibWeb: Start implementing sizing for tracks with span > 1 items in GFC
Partially implements:
- Increase sizes to accommodate spanning items crossing content-sized
  tracks
- Increase sizes to accommodate spanning items crossing flexible tracks

from https://www.w3.org/TR/css-grid-2/#algo-content
2023-05-14 19:32:34 +02:00
Aliaksandr Kalenik
6f82079a93 LibWeb: Remove dead code in resolve_intrinsic_track_sizes() in GFC
Removes partially implemented algorithm for distributing extra space
from spanning item:
https://www.w3.org/TR/css-grid-2/#extra-space

This algorithm should not be part of resolving track sizing on its own
but instead be a subfunction of step 3:
https://www.w3.org/TR/css-grid-2/#track-size-max-content-min

There are changes in layout tests but those are not regressions.
2023-05-14 13:45:29 +02:00
Aliaksandr Kalenik
dbafb11a7e LibWeb: Flesh out basic support of min-width/height for grid items
This change brings calculate_minimum_contribution() for grid items and
supporting functions.
2023-05-13 18:43:34 +02:00
Aliaksandr Kalenik
d187862f76 LibWeb: Return grid container width from automatic_content_width in GFC
automatic_content_width() should return grid container width that is
supposed to be set by determine_intrinsic_size_of_grid_container().
2023-05-13 12:53:25 +02:00
Aliaksandr Kalenik
644e4f4c99 LibWeb: Implement grid container intrinsic sizes calculation
When a width/height constraint is applied to GFC it should set its own
width/height to the sum of track sizes according to the spec.

Changes in layout tests are improvement over what we had before.
2023-05-13 12:53:25 +02:00