Commit graph

233 commits

Author SHA1 Message Date
Andreas Kling
5c8e7217f7 LibWeb: Remove ad-hoc setup step from FFC layout algorithm
This step will not be necessary when we implement indefinite size
calculations more correctly.
2022-03-13 00:04:51 +01:00
Andreas Kling
43b8f65d82 LibWeb: Support indefinite flex container cross sizes
Instead of assuming that any indefinite cross size must be "auto", check
what is actually is, and resolve it accordingly.
2022-03-13 00:04:51 +01:00
Andreas Kling
a3a10b2379 LibWeb: Fix flex line alignment in single-line flex containers
For single-line flex containers, center the only flex line along the
cross axis. Alignment of multi-line flex containers are left as a FIXME.

This patch also moves out the assignment of final metrics to the
FormattingState from align_all_flex_lines() to a separate function.
2022-03-13 00:04:51 +01:00
Andreas Kling
1dfb3d555c LibWeb: Remove FFC::cross_size_is_absolute_or_resolved_nicely()
This is now answered authoritatively by Layout::Box itself.
2022-03-13 00:04:51 +01:00
Andreas Kling
1ce1af5d8b LibWeb: Improve FFC step 7 (hypothetical cross size)
- Avoid performing inside layout on definite-size flex items (since
  their computed size can be used as-is.)

- Use FormattingState::clone() to generate a throwaway layout instead of
  mutating the tree in-place.

- Update spec link & comments based on current CSSWG draft. The latest
  version is quite a bit clearer on how this should work.
2022-03-13 00:04:51 +01:00
Andreas Kling
b904bff838 LibWeb: Put available space information in an FFC member
This makes it easier for each step of the flex layout algorithm to
access this information.
2022-03-13 00:04:51 +01:00
Andreas Kling
88302b0dca LibWeb: Layout inside of flex items at the end of FFC layout
Instead of doing internal child layout incrementally as we go, save it
for the end of flex layout. The code will become simpler if we can focus
on simply computing the dimensions of each flex item while we're doing
the main FFC algorithm.
2022-03-13 00:04:51 +01:00
Andreas Kling
7c5b578df9 LibWeb: Move unrelated things out of FFC step 1
Setting some initial width and height on the flex container is totally
unrelated to the "generate anonymous flex items" step.
2022-03-13 00:04:51 +01:00
Andreas Kling
3506a91349 LibWeb: Avoid unnecessary layout_inside() in FFC step 1
We don't need to perform inside layout here. The only information we
need in this step is whether an anonymous block container has nothing
but empty-or-whitespace text children.

This information is already accurate after the initial layout tree
construction. Performing a layout does not change the answer. It does
however have many other side effects, so let's defer those.
2022-03-13 00:04:51 +01:00
Andreas Kling
db5bf6e64c LibWeb: Rename FormattingState::ensure() -> get_mutable()
This makes it much more obvious what the difference between get() and
get_mutable() is.
2022-02-21 18:35:12 +01:00
Andreas Kling
c9700e100e LibWeb: Start making our layout system "transactional"
This patch adds a map of Layout::Node to FormattingState::NodeState.
Instead of updating layout nodes incrementally as layout progresses
through the formatting contexts, all updates are now written to the
corresponding NodeState instead.

At the end of layout, FormattingState::commit() is called, which
transfers all the values from the NodeState objects to the Node.

This will soon allow us to perform completely non-destructive layouts
which don't affect the tree.

Note that there are many imperfections here, and still many places
where we assign to the NodeState, but later read directly from the Node
instead. I'm just committing at this stage to make subsequent diffs
easier to understand.
2022-02-21 18:35:12 +01:00
Andreas Kling
561612f219 LibWeb: Add Layout::FormattingState
The purpose of this new object will be to keep track of various states
during an ongoing layout.

Until now, we've been updating layout tree nodes as we go during layout,
which adds an invisible layer of implicit serialization to the whole
layout system.

My idea with FormattingState is that running layout will produce a
result entirely contained within the FormattingState object. At the end
of layout, it can then be applied to the layout tree, or simply queried
for some metrics we were trying to determine.

When doing subtree layouts to determine intrinsic sizes, we will
eventually be able to clone the current FormattingState, and run the
subtree layout in isolation, opening up opportunities for parallelism.

This first patch doesn't go very far though, it merely adds the object
as a skeleton class, and makes sure the root BFC has one. :^)
2022-02-21 18:35:12 +01:00
Andreas Kling
c04c2df0f7 LibWeb: Add missing is_length() check in FFC::is_cross_auto()
We can't access LengthPercentage::length() before verifying that it's
indeed a length.
2022-02-18 19:19:56 +01:00
Sam Atkins
356d8bcfe8 LibWeb: Remove Length::Type::Undefined! :^) 2022-02-18 19:04:37 +01:00
Sam Atkins
b715943035 LibWeb: Remove redundant Length::resolved() calls
Now that calc() is also resolved in to_px(), code in the form
`foo.resolved(bar).to_px(bar)` can be simplified to `foo.to_px(bar)`.
2022-02-18 19:04:37 +01:00
Sam Atkins
67066c5140 LibWeb: Remove fallback value from Length::resolved()
Nobody makes undefined Lengths now, (although actually removing
Undefined will come in a later commit) so we can remove this parameter,
and `resolved_or_auto()`/`resolved_or_zero()`.
2022-02-18 19:04:37 +01:00
Sam Atkins
5b2482a939 LibWeb: Use Optional instead of undefined-lengths for widths/heights 2022-02-18 19:04:37 +01:00
Andreas Kling
0608de8c12 LibWeb: Rename Layout::Box::size() to content_size()
This property represents the CSS content size, so let's reduce ambiguity
by using the spec terminology.

We also bring a bunch of related functions along for the ride.
2022-02-06 01:07:47 +01:00
Sam Atkins
ce0de4b2b4 LibWeb: Allow LengthPercentage to hold a calculated value
Most of the time, we cannot resolve a `calc()` expression until we go to
use it. Since any `<length-percentage>` can legally be a `calc
()`, let's store it in `LengthPercentage` rather than make every single
user care about this distinction.
2022-02-04 13:52:02 +01:00
Andreas Kling
00bd17034d LibWeb: Make IFC aware that its parent is always a BFC
This simplifies some code and allows us to use tighter types for the
parent context everywhere.
2022-01-24 02:09:17 +01:00
Sam Atkins
bfcbab0dcf LibWeb: Remove reference_for_percent parameter from Length::resolved()
Despite looking like it was still needed, it was only used for passing
to other calls to Length::resolved() recursively. This makes the
various `foo.resolved().resolved()` calls a lot less awkward.
(Though, still quite awkward.)

I think we'd need to separate calculated lengths out to properly tidy
these calls up, but one yak at a time. :^)
2022-01-20 00:04:10 +01:00
Sam Atkins
dc681913e8 LibWeb: Convert width/height and min-/max- versions to LengthPercentage
A lot of this is quite ugly, but it should only be so until I remove
Length::Type::Percentage entirely. (Which should happen later in this
PR, otherwise, yell at me!) For now, a lot of things have to be
resolved twice, first from a LengthPercentage to a Length, and then
from a Length to a pixel one.
2022-01-20 00:04:10 +01:00
Sam Atkins
cb0cce5cdc LibWeb: Convert flex-basis to LengthPercentage
The flexbox logic confuses me so regressions are possible, though our
test page looks the same as before so it should be fine.

Renamed FlexBasis::Length -> LengthPercentage too, for clarity.
2022-01-20 00:04:10 +01:00
Sam Atkins
7196570f9b LibWeb: Cast unused smart-pointer return values to void 2021-12-05 15:31:03 +01:00
Andreas Kling
ca154723f7 LibWeb: Remove Layout::Box::width_of_logical_containing_block()
This was a hack to percentages within tables relative to the nearest
table-row ancestor instead of the nearest table container.

That didn't actually make sense, so this patch simply removes the hack
in favor of containing_block()->width().
2021-10-27 18:00:51 +02:00
Andreas Kling
c1ba9c66b5 LibWeb: Use is_single_line() and add spec comments to FFC step 8 2021-10-21 16:48:24 +02:00
Andreas Kling
07f15aa550 LibWeb: Make computed flex-grow and flex-shrink always available
These values are not allowed to be absent (auto/none/etc) so we don't
need to use Optional<float> for them. This simplifies some things.
2021-10-19 19:17:01 +02:00
Andreas Kling
f2d0e8d0ee LibWeb: Expose FormattingContext type
Instead of having a virtual is_block_formatting_context(), let's have a
type() that can tell you exactly which type of formatting context it is.
2021-10-17 22:18:59 +02:00
Andreas Kling
410e2b43ce LibWeb: Use Box::has_intrinsic_aspect_ratio() check in FFC step 3
Now that we can ask any Box about its intrinsic aspect ratio, let's fix
a FIXME in FlexFormattingContext.
2021-10-14 19:42:09 +02:00
Andreas Kling
42f6bd5f83 LibWeb: Add spec comments to FFC layout algorithm step 2 2021-10-13 23:56:26 +02:00
Andreas Kling
1d0c4a07ff LibWeb: Add spec comments to FFC layout algorithm step 5 2021-10-13 23:56:26 +02:00
Andreas Kling
82bb5ef8b7 LibWeb: Tidy up and add spec comments to FFC layout algorithm step 3 2021-10-13 23:56:26 +02:00
Andreas Kling
d37e5dc64c LibWeb: Add FFC::flex_container() and use throughout
Since FFC is only ever run() on the flex container, we can assume (but
verify) that the run box is the flex container and use an accessor
throughout. The end result: less parameter passing.
2021-10-13 23:56:26 +02:00
Andreas Kling
1580c59f39 LibWeb: Make FFC line and item vectors members instead of locals
This gives all member functions access to these vectors without having
to pass them as arguments.
2021-10-13 23:56:26 +02:00
Andreas Kling
c793797e61 LibWeb: Make various function parameters const in FlexFormattingContext
This is mainly to validate that inputs are treated as inputs only and
don't get written to.
2021-10-13 23:56:26 +02:00
Andreas Kling
9359df4be9 LibWeb: Move FFC layout algorithm step 16 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
f401794d23 LibWeb: Move FFC layout algorithm step 15 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
6d433c99f4 LibWeb: Move FFC layout algorithm step 14 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
e590e17b8a LibWeb: Move FFC layout algorithm step 12 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
176f1ad214 LibWeb: Move FFC layout algorithm step 11 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
8f027b4792 LibWeb: Move FFC layout algorithm step 8 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
3402584646 LibWeb: Move FFC layout algorithm step 7 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
0c0df78030 LibWeb: Move FFC layout algorithm step 6 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
0fd25fcbbc LibWeb: Move FFC layout algorithm step 5 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
fa7bbc602d LibWeb: Move FFC layout algorithm step 4 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
3375953918 LibWeb: Move FFC layout algorithm step 3 to a separate function 2021-10-13 23:56:26 +02:00
Andreas Kling
c19358e157 LibWeb: Move FFC layout algorithm step 2 into a separate function
Determining the available main and cross space is now done by a separate
function. The signature is a little bit hairy since this function
computes some things that are used by subsequent algorithm steps.

Factoring can definitely be improved further.
2021-10-13 23:56:26 +02:00
Andreas Kling
cd6b97ab9e LibWeb: Turn FlexFormattingContext helper lambdas into member functions
Continuing on the quest towards making FlexFormattingContext readable.
2021-10-13 23:56:26 +02:00
Andreas Kling
674b6f5385 LibWeb: Call the FlexFormattingContext context box "flow_container"
This is what the spec calls it and makes the code much less ambiguous.
2021-10-13 23:56:26 +02:00
Andreas Kling
ca02d112a5 LibWeb: Split out FFC's "generate anonymous flex items" to a function
Let's begin splitting the FlexFormattingContext layout algorithm into
separate functions to make it more manageable.
2021-10-13 23:56:26 +02:00