Commit Graph

253 Commits

Author SHA1 Message Date
Sam Atkins
84e7216603 LibWeb: Move "natural size" concept into Layout::Box
Having this here instead of in ReplacedBox means we can access it when
figuring out what the "preferred aspect ratio" is.

There's some inconsistency between specs about what this is called, but
they're moving towards referring to this as "natural width/height/
aspect-ratio", so let's copy that terminology.
2023-06-09 20:37:51 +02:00
Andreas Kling
3365a1e034 LibWeb: Resolve cyclic % against 0 when available size is min-content
This fixes an issue where replaced elements with cyclic percentage width
would make an oversized min-content contribution to its container.
2023-06-08 13:54:11 +02:00
Andreas Kling
c197fb4037 LibWeb: Take box-sizing into account when sizing replaced elements
This fixes an issue where images with padding and/or border did not have
their size adjusted for `border-box`, thereby becoming larger than
intended by the author.
2023-06-05 09:00:00 +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
Aliaksandr Kalenik
787f2d2a10 LibWeb: Remove Layout::TableCellBox
Special box types for inner table boxes might conflict with special
types for <button>, <input> or <label>.
2023-05-29 21:36:17 +02:00
Andreas Kling
af004ff0ef LibWeb: Support min-content for width, min-width and max-width
We're gonna need to handle this in many more places, this patch only
adds it to calculate_inner_width().
2023-05-29 21:29:25 +02:00
Andreas Kling
97c510329c LibWeb: Support max-content for width, min-width and max-width
We're gonna need to handle this in many more places, this patch only
adds it to calculate_inner_width().
2023-05-29 21:29:25 +02:00
Aliaksandr Kalenik
258f3ea952 LibWeb: Remove Layout::TableBox
Solves conflict in layout tree "type system" when elements <label> (or
<button>) can't have `display: table` because Box can't be
Layout::Label (or Layout::ButtonBox) and Layout::TableBox at the same
time.
2023-05-29 14:12:29 +02:00
Andreas Kling
1bb4e5c428 LibWeb: Support fit-content width for block-level boxes 2023-05-27 05:47:54 +02:00
Andreas Kling
299775345d LibWeb: Allow calculating intrinsic sizes of non-FC-roots
In order to support intrinsic size keywords (such as fit-content), we
need to be able to calculate the intrinsic sizes of any element, not
just those that form their own formatting context.

When a non-FC-root element is passed to calculate_some_intrinsic_size(),
we now create a synthetic BFC to handle sizing of them.
2023-05-27 05:47:54 +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
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
Jelle Raaijmakers
f391ccfe53 LibGfx+Everywhere: Change Gfx::Rect to be endpoint exclusive
Previously, calling `.right()` on a `Gfx::Rect` would return the last
column's coordinate still inside the rectangle, or `left + width - 1`.
This is called 'endpoint inclusive' and does not make a lot of sense for
`Gfx::Rect<float>` where a rectangle of width 5 at position (0, 0) would
return 4 as its right side. This same problem exists for `.bottom()`.

This changes `Gfx::Rect` to be endpoint exclusive, which gives us the
nice property that `width = right - left` and `height = bottom - top`.
It enables us to treat `Gfx::Rect<int>` and `Gfx::Rect<float>` exactly
the same.

All users of `Gfx::Rect` have been updated accordingly.
2023-05-23 12:35:42 +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
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
MacDue
1012947a30 LibWeb: Use .to_px_or_zero() in tentative_height_for_replaced_element()
If just .to_px() is used the height can end up as the float `inf` or
`nan`. This caused an OOM when loading Polygon as this `inf` would
become a `nan` and propagate to the SVG painting, which then attempts
to draw a path with nan control points, which would make the
Gfx::Painter infinitely split the path till it OOM'd.
2023-05-12 05:37:44 +02:00
Andreas Kling
197efc8985 LibWeb: Improve handling of min/max constraint violations on images
Instead of bailing after resolving one violated constraint, we have to
continue down the list of remaining constraints.

We now also call the constraint solver for all replaced elements with
"auto" for both width and height.

Co-authored-by: 0GreenClover0 <clovers02123@gmail.com>
2023-05-09 12:11:28 +02:00
Andreas Kling
90b21890c5 LibWeb: Remove dead code in compute_width_for_replaced_element() 2023-05-09 12:11:28 +02:00
Andreas Kling
fc3c3aef22 LibWeb: Enforce min/max height constraints on abspos replaced boxes
Fixes #18658
2023-05-07 06:28:47 +02:00
Andreas Kling
6ccb77a9b8 LibWeb: Stop using weird Length::resolved() in {Block,}FormattingContext 2023-05-06 21:14:38 +02:00
Andreas Kling
07815dacf8 LibWeb: Don't use weird resolved() when calculating abspos box height 2023-05-06 21:14:38 +02:00
Andreas Kling
7eb9e730e0 LibWeb: Remove unused variable in FormattingContext 2023-05-06 21:14:38 +02:00
Andreas Kling
4699365a64 LibWeb: Stop using weird resolved() in calculate_inner_{width,height}() 2023-05-06 21:14:38 +02:00
Andreas Kling
452a527ff3 LibWeb: Don't use weird resolved() for insets in FormattingContext 2023-05-06 21:14:38 +02:00
Andreas Kling
ca1fa5f748 LibWeb: Use the new to_px() helpers in CSS, SVG and layout code
There should be no behavior change from this, only slightly less
verbosity. :^)
2023-05-06 18:41:34 +02:00
Andreas Kling
f09391dd7f LibWeb: Remove debug spam when creating a dummy formatting context
This will go away when we get rid of the dummy context. There's no value
in spamming the debug console about it.
2023-05-06 18:41:34 +02:00
Andreas Kling
ecd3d0935a LibWeb: Re-lookup the intrinsic sizing cache slot after doing the layout
It's not safe to hold on to a pointer to the cache slot across layout
work, since the nested layout may end up causing new entries to get
added to the cache, potentially invalidating a cache slot pointer.
2023-05-06 18:41:34 +02:00
Aliaksandr Kalenik
34b1186272 LibWeb: Remove early resolve to auto while calculating border-box width
`Length::resolved(Node&)` transforms infinite values to "auto".

Following transformations:
Infinite (Length) -> "auto" -> 0 (px)
cause border-box width to be resolved in zero when it should be inf px.

Removing `Length::resolved(Node&)` makes it work right:
Infinite (Length) -> Infinite (px)

Fixes #18649
2023-05-05 10:01:28 +02:00
Aliaksandr Kalenik
0318ac5ce4 LibWeb: Remove setting length to 0px if it is not definite
If available width (or height) is max-content and width (or height)
value is 100% it should be resolved in infinite px, not 0 px.

Fixes #18639
2023-05-05 06:20:44 +02:00
Andreas Kling
968db96101 LibWeb: Show formatting context roots in layout tree dumps
This patch does three things:

- Factors out the code that determines whether a box will create a new
  formatting context for its children (and which type of context)

- Uses that code to mark all formatting context roots in layout tree
  dumps. This makes it much easier to follow along with layout since
  you can now see exactly where control is transferred to a new
  formatting context.

- Rebaselines all existing layout tests, since the output format has
  changed slightly.
2023-05-03 13:14:36 +02:00
matcool
cc33a57620 LibWeb: Use intrinsic aspect ratio when calculating max content height 2023-04-05 16:23:56 +02:00
Andreas Kling
ca290b27ea LibWeb: Make box content sizes indefinite before intrinsic sizing
When calculating the intrinsic width of a box, we now make its content
width & height indefinite before entering the intrinsic sizing layout.
This ensures that any geometry assigned to the box by its parent
formatting context is ignored.

For intrinsic heights, we only make the content height indefinite.
This is because used content width is a valid (but optional) input
to intrinsic height calculation.
2023-03-27 23:28:07 +02:00
Andreas Kling
4bf10674fa LibWeb: Don't allow resolved height of abspos elements to become negative
We have to clamp the resulting height to 0 when solving for it.
2023-03-25 19:41:31 +01:00
Andreas Kling
3f6f3966b9 LibWeb: Don't allow resolved width of abspos elements to become negative
We have to clamp the resulting width to 0 when solving for it.
2023-03-25 19:41:31 +01:00
Andreas Kling
00999a245c LibWeb: Let FormattingContext decide the automatic width of its root
Instead of special-casing FlexFormattingContext in the intrinsic sizing
layout helpers, add FormattingContext::automatic_content_width() and let
each context subclass decide what that means.

No behavior change here, just moving this responsibility.
2023-03-20 17:57:58 +01:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Andreas Kling
24d5a9d7df LibWeb: Fix bogus percentage vertical padding with box-sizing:border-box
The padding-top and padding-bottom properties are relative to the
*width* of the containing block, not the height.

It's funny how we keep making this same mistake again and again. :^)
2023-03-10 13:38:34 +01:00
Andreas Kling
7e76a51cb0 LibWeb: Rename Layout::InitialContainingBlock to Layout::Viewport
The name "initial containing block" was wrong for this, as it doesn't
correspond to the HTML element, and that's specifically what it's
supposed to do! :^)
2023-02-28 12:21:56 +01:00
Sam Atkins
dca19b764b LibWeb: Port CSS::Display to new Strings 2023-02-15 12:48:26 -05:00
Andreas Kling
4e06e86438 LibWeb: Make min-content height equivalent to max-content as appropriate
Per CSS-SIZING-3, the min-content block size should be equivalent to the
max-content block size for some boxes.

Honoring this gives more correct results, and avoids unnecessary work in
many cases since the cached max-content size can be reused.
2023-01-24 11:44:03 +01:00
Andreas Kling
8fe748bb89 LibWeb: Make grid containers be Layout::Box
Grid containers were incorrectly represented as BlockContainer before.
Furthermore, GridFormattingContext had a bogus inheritance relationship
with BlockFormattingContext.

This patch brings our architecture closer to spec by making grid
containers be plain boxes and making GFC not inherit from BFC.
2023-01-24 11:44:03 +01:00
Andreas Kling
d5480a44e5 LibWeb: Allow BFC auto height calculation on any Layout::Box
This algorithm is reused in abspos sizing, and so should not be specific
to block containers (even if the name suggests it.)
2023-01-24 11:44:03 +01:00
Andreas Kling
80ce0419b6 LibWeb: Fix abspos flex container with height:auto getting zero height
When laying out abspos boxes, we compute the height twice: before and
after the inside of the box has been laid out.

The first pass allows percentage vertical values inside the box to be
resolved against the box's height. The second pass resolves the final
used value for the height of the box itself.

In cases where the box height depends on the results of inside layout,
we were incorrectly setting the box to having a definite zero height.
This led to incorrect results when sizing an abspos flex container,
since the FFC sizes containers (in row layouts) based on whether the
container has a definite height.

To avoid this problem, this patch adds an enum so we can differentiate
between the two abspos height computation passes. If the first pass
discovers a dependency on the inside layout, we simply bail out of
computing the height, leaving it as indefinite. This allows the FFC
to size its container correctly, and the correct height gets set by
the second pass.
2023-01-06 21:12:55 +01:00
Sam Atkins
c70dcaefcd LibWeb: Convert LayoutState to new pixel units 2023-01-05 17:42:31 +01:00
Sam Atkins
f5f25562d1 LibWeb: Convert FormattingContext to new pixel units
Just FormattingContext and AvailableSpace, and the minor adjustments to
make everything else work.
2023-01-05 17:42:31 +01:00
Aliaksandr Kalenik
8259ff12bd LibWeb: Margin bottom collapsing between parent and last child 2022-12-30 14:21:19 +01:00
Aliaksandr Kalenik
fe8304d5de LibWeb: Introduce structure that maintains collapsible margins in BFC
Previously y position of boxes in block formatting context
was calculated by looking at y position of previous in-flow
sibling and adding collapsed margin of "collapse through"
boxes lying between box currently being laid out and it's
previous in-flow sibling.

Here introduced BlockMarginState structure that maintains
array of currently collapsible margins hence we no longer
need to look at previous sibling to calculate y position
of a box.
2022-12-30 14:21:19 +01:00
Tom
0bbf7a1b54 LibWeb: Refactor should_skip_anonymous_text_runs
This same function was being copied in the {Flex,Grid}FormattingContext,
so unify them in the parent FormattingContext.
2022-12-28 15:04:58 +01:00
Sam Atkins
ab49dbf137 LibWeb: Convert Paintable coordinates to new pixel units
This fixes a few sizing issues too. The page size is now correct in most
cases! \o/

We get to remove some of the `to_type<>()` shenanigans, though it
reappears in some other places.
2022-12-14 16:47:57 +00:00
Aliaksandr Kalenik
daece542f5 LibWeb: Check if block creates BFC even if all it's children are inline
Even if block has all children inline there need to be a check
if it creates BFC because otherwise IFC will be looking in
wrong parent BFC to calculate space used by floats.
2022-12-11 22:08:44 +01:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Aliaksandr Kalenik
2b246d980a LibWeb: Fix typo in calculate_inner_height 2022-11-25 17:06:59 +01:00
Aliaksandr Kalenik
7bc7790912 LibWeb: Flex, grid and table containers should not create BFC
Fixes https://github.com/SerenityOS/serenity/issues/16082
2022-11-25 10:45:37 +01:00
Aliaksandr Kalenik
428db6e766 LibWeb: Return max margin box width from greatest_child_width
Return max margin box width instead of max border box width
from greatest_child_width.

This change fixes:
https://wpt.live/css/CSS2/margin-padding-clear/margin-008.xht
2022-11-23 23:11:39 +01:00
Aliaksandr Kalenik
aa08c825ec LibWeb: Support box-sizing in BFC
Add support for box-sizing in block formatting context, support
for Flex Formatting Context and Grid Formatting Context is missing
2022-11-22 12:43:36 +01:00
Aliaksandr Kalenik
767cdf7b11 LibWeb: Return content box position from calculate_static_position
This change makes calculate_static_position to return content box
for both x and y (at least for the case when children are not inline).
It makes it possible to be consistent about x and y when calculating
box offset inside layout_absolutely_positioned_element.
2022-11-20 21:54:39 +01:00
Aliaksandr Kalenik
1b5b7e3b01 LibWeb: Solve width for absolute positioned elemenent according to spec
https://www.w3.org/TR/css-position-3/#abs-non-replaced-width
If left and width are auto and right is not auto, then
the width is shrink-to-fit. Then solve for left.
2022-11-16 03:10:26 +01:00
Andreas Kling
bc807466f9 LibWeb: Finish half-written comment in abspos height calculation
Apparently I forgot to write the whole comment in the previous commit,
8a87f4fa20.
2022-11-09 16:16:10 +01:00
Andreas Kling
8a87f4fa20 LibWeb: Try to compute height for abspos elements before inside layout
This can resolve height early in some cases, notably this kind of setup:

    position: absolute;
    top: 0px;
    bottom: 0px;

By resolving height before inside layout, descendants of the abspos
element can resolve automatic and relative vertical lengths against it.

This makes the Discord UI occupy the whole window instead of looking
"shrink-to-fit".
2022-11-09 15:48:08 +01:00
Andreas Kling
5e996b461c LibWeb: Actually assign solved value for left in abspos width case 1 2022-11-09 15:48:08 +01:00
Andreas Kling
305cb8a5d1 LibWeb: Treat unresolvable percentage sizes as auto on replaced elements
For replaced elements with percentage width or height, we were treating
them as 0 instead of auto when their containing block had an indefinite
corresponding size.

This produced incorrect layouts in various cases, and although I can't
actually find something about this exact scenario in specs, the new
behavior does match other browsers.
2022-11-03 19:22:40 +01:00
Andreas Kling
db318aece0 LibWeb: Move should_treat_{width,height}_as_auto() to FormattingContext
These are not specific to BFC, so let's move them up to the super class
so that other layout classes can use them.
2022-11-03 19:22:40 +01:00
martinfalisse
f7bd1edde3 LibWeb: Calculate the height of the css grid correctly
Enable the CSS grid height to be calculated correclly.
2022-10-15 16:04:01 +02:00
Andreas Kling
b289f97a65 LibWeb: Split intrinsic heights cache by definite available widths
As it turns out, we sometimes query the intrinsic height of a box before
having fully resolved and/or constrained its containing block. Because
of this, we may enter intrinsic sizing with different amounts of
available width for the same box.

To accommodate this scenario, we now allow caching of multiple intrinsic
heights, separated by the amount of available width provided as input.
2022-10-15 14:01:54 +02:00
Andreas Kling
27a7c5ef40 LibWeb: Implement CSS fit-content algorithm precisely as spec says
We were using the available space in place of the stretch-fit size.
This was an oversight, and this patch fixes that. It's very possible
that this will uncover broken behavior elsewhere.
2022-10-14 19:53:52 +02:00
Andreas Kling
d7d8e3c78b LibWeb: Resolve *all* percentages in abspos height calculation
We were neglecting to resolve() percentages for many values.
2022-10-14 19:52:07 +02:00
Timon Kruiper
8373a14835 LibWeb: Remove code duplication in computing height for abs-pos elements
This refactors the solve_for_{top, bottom, height, etc} lambdas to use a
common solve_for lambda that takes the length to be solved as an
argument. This way some code duplication is removed.
2022-10-12 11:08:29 +02:00
Samuel Bowman
ca0a0b7a93 LibWeb: Add missing else's in absolutely positioned height computation
Rules 1, 2, and 3 use else if, so rules 4, 5, and 6 should too.
2022-10-12 10:32:57 +02:00
Andreas Kling
e6de382679 LibWeb: Constrain abspos element heights by min-height and max-height 2022-10-11 22:31:51 +02:00
Andreas Kling
0e295f727a LibWeb: Fix dumb typos in solver helpers for abspos height 2022-10-11 22:23:13 +02:00
Andreas Kling
84953c5020 LibWeb: Calculate height of absolute-position elements according to spec
This patch implements the full "old model" height algorithm from the
CSS Positioned Layout spec. I went with the old model since we don't
yet have the machinery required to implement the new model.

Also, the width calculations already follow the old model, so this
is symmetric with that. Eventually we should of course implement the new
positioned layout model.
2022-10-11 21:49:48 +02:00
Andreas Kling
0f2d5f91dc LibWeb: Fix two uninitialized variables in FormattingContext 2022-10-10 23:42:35 +02:00
Andreas Kling
b945d164e2 LibWeb: Split intrinsic heights cache based on available width
Now that intrinsic heights (correctly) depend on the amount of available
width, we can't just cache the first calculated min-content and
max-content heights and reuse it without thinking.

Instead, we have to cache three pairs:

- min-content & max-content height with definite available width
- min-content & max-content height with min-content available width
- min-content & max-content height with max-content available width

There might be some more elegant way of solving this, but basically this
makes the cache work correctly when someone's containing block is being
sized under a width constraint.
2022-10-10 20:22:50 +02:00
Andreas Kling
5ff1fc4347 LibWeb: Make sure replaced elements never create a BFC 2022-10-06 18:29:52 +02:00
Andreas Kling
829ba4afb9 LibWeb: Remove unnecessary verify_cast in greatest_child_width() 2022-10-06 18:29:52 +02:00
Andreas Kling
9d50191dca LibWeb: Tidy up FormattingContext::creates_block_formatting_context()
We use comments from MDN here, since the rules for creating a BFC are
inconsistently spread across many different specifications.
2022-10-06 17:15:28 +02:00
Andreas Kling
13834cfdff LibWeb: Use Layout::Node::display() everywhere 2022-10-06 16:25:26 +02:00
Andreas Kling
b13a8706e1 LibWeb: Make intrinsic heights dependent on available width
After speaking with fantasai at CSSWG about this, it turns out I had
misunderstood intrinsic heights. I originally believed all intrinsic
sizes had to be computed with no influence from the surrounding context.

As it turns out, intrinsic heights *are* influenced by the available
width, since it's needed to determine where lines break.

The APIs for calculating min-content and max-content heights now take
the available width as inputs. This instantly improves layout in many
cases where we'd previously make things way too wide.
2022-10-03 23:49:23 +02:00
Andreas Kling
3408f7a3c5 LibWeb: Get rid of FormattingContext::run_intrinsic_sizing()
Now that we have AvailableSpace, it's actually quite convenient to
simply set up the available space and call run() with that directly.
2022-10-03 23:49:23 +02:00
Andreas Kling
de6d012367 LibWeb: Improve placement of abspos boxes with dual-auto insets
When an absolutely positioned box has auto insets on both sides of an
axis, it's placed according to the "static position rectangle". This is,
roughly, the rectangle a box would occupy if it were position:static
instead of position:absolute or position:fixed.

This patch implements a rough, but still significantly better,
estimation of such static positions. It gets pretty hairy in the case
where an abspos box has a parent whose children are inline.
2022-10-02 21:14:02 +02:00
Andreas Kling
46a13c3d2e LibWeb: Add helpful locals in layout_absolutely_positioned_element()
This code had some obnoxiously repetetive call chains.
2022-10-02 21:14:02 +02:00
Andreas Kling
d1d99fda32 LibWeb: Vertical % margins are relative to containing block width
We were messing this up on absolutely positioned elements by using the
containing block height instead.
2022-10-02 21:14:02 +02:00
Andreas Kling
9c44634ca5 LibWeb: Reorganize layout algorithms around available space
This is a big and messy change, and here's the gist:

- AvaliableSpace is now 2x AvailableSize (width and height)

- Layout algorithms are redesigned around the idea of available space

- When doing layout across nested formatting contexts, the parent
  context tells the child context how much space is available for the
  child's root box in both axes.

- "Available space" replaces "containing block width" in most places.

- The width and height in a box's UsedValues are considered to be
  definite after they're assigned to. Marking something as having
  definite size is no longer a separate step,

This probably introduces various regressions, but the big win here is
that our layout system now works with available space, just like the
specs are written. Fixing issues will be much easier going forward,
since you don't need to do nearly as much conversion from "spec logic"
to "LibWeb logic" as you previously did.
2022-10-02 21:14:02 +02:00
Andreas Kling
a0f3e2c9a2 LibWeb: Never claim that flex containers create a BFC
If a flex item is itself a flex container, we were previously lying when
asked if the item created a BFC. It creates an FFC, so stop lying about
this in FormattingContext::creates_block_formatting_context().
2022-09-29 20:10:12 +02:00
Andreas Kling
385657a4bf LibWeb: Add a helper for calculating the stretch-fit width of a box 2022-09-29 18:33:41 +02:00
Andreas Kling
f161e20e57 LibWeb: Make FormattingContext::run() take available space as input
Instead of formatting contexts flailing around to figure out from the
"inside" how much space is available on the "outside", we should
provide the amount of available space in both axes as an input to run().

This basically means that when something creates a nested formatting
context, the parent context is responsible for telling the nested context
how much space is available for layout. This information is provided
immediately when invoking run().

Note that this commit doesn't pass accurate values in all cases yet.
This first step just makes it build, and passes available values in some
cases where getting them was trivial.
2022-09-29 18:33:41 +02:00
Andreas Kling
0843960235 LibWeb: Use CSS::Size for computed size and max-size values
This patch changes the *computed* representation of the following CSS
properties to use CSS::Size:

- width, min-width, max-width
- height, min-height, max-height

A few things had to change in order for things to keep working,
but I tried to keep the diff to a minimum.

The main trouble was that `min-width` and `max-width` can't actually be
`auto`, but they *can* be `none`. We previously treated `auto` as a
valid value (and it behaved mostly like `none`).
2022-09-25 17:51:43 +02:00
martinfalisse
521e19444c LibWeb: Make CSS Grid work again
Fixes bug after the automatic_content_height() changes where the height
of the grid container was not being calculated correctly.
2022-09-24 20:57:28 +02:00
Andreas Kling
c04b107e26 LibWeb: Treat replaced % sizes as 0 if containing block is indefinite 2022-09-24 14:41:18 +02:00
Andreas Kling
5656173e00 LibWeb: Use automatic_content_height() when computing intrinsic heights 2022-09-24 13:47:17 +02:00
Andreas Kling
62974160da LibWeb: Add FormattingContext::automatic_content_height()
This function should return the automatic height of the formatting
context's root box.

Until now, we've been relying on some magical handshakes between parent
and child context, when negotiating the height of child context root
boxes. This is a step towards something more reasonable.
2022-09-24 13:41:08 +02:00
Ben Wiederhake
8deced39a8 LibWeb: Resolve cyclic declaration/definitions involving Length
This remained undetected for a long time as HeaderCheck is disabled by
default. This commit makes the following file compile again:

    // file: compile_me.cpp
    #include <LibWeb/CSS/GridTrackSize.h>
    // That's it, this was enough to cause a compilation error.
2022-09-15 14:45:38 +01:00
Andreas Kling
34025442ff LibWeb: Account for float's container offsets in BFC root auto height
When calculating the automatic height of a BFC root, we stretch it to
contain the bottommost margin edge of floating boxes.

Before this change, we assumed that floating boxes had coordinates
relative to the BFC root, when they're actually relative to the floating
box's containing block. This may or may not be the BFC root, so we have
to use margin_box_in_ancestor_coordinate_space() to apply offsets from
all boxes in the containing block chain (up to the BFC root).
2022-09-14 20:18:49 +02:00
Andreas Kling
35a9a2fbb2 LibWeb: Account for containing block padding when placing abspos boxes
Unlike the other positioning schemes, absolute positioning is relative
to the *padding* edge of the containing block.
2022-09-14 14:43:17 +02:00
Andreas Kling
fb5879fdcc LibWeb: Don't include abspos children in containing block's auto width 2022-09-14 00:09:49 +02:00
martinfalisse
df22f38feb LibWeb: Inform the parent context of the grid's size 2022-09-14 00:09:14 +02:00
Andreas Kling
c9a7853fef LibWeb: Include all floating descendants in BFC root's automatic height
Before this change, we were only considering floating boxes that were
immediate children of the BFC root.
2022-09-13 17:03:31 +02:00
Andreas Kling
9e39f51fd3 LibWeb: Position blocks after previous block-level box, ignoring type
Before this change, block-level boxes were laid out vertically by
placing them after the nearest previous BlockContainer sibling. This
only worked if the preceding block-level box happened to be a
BlockContainer.

This fixes an issue where the screenshot on netsurf-browser.org was not
being laid out properly (it was `img { display: block }` which creates
a block-level ImageBox, and ImageBox is not a BlockContainer but a
ReplacedBox, so the following block-level box was skipping over the
ImageBox and being placed next to whatever was before the ImageBox..)
2022-09-08 01:42:25 +02:00