After having corrected the tracking of span variables in the
GridTrackPlacement class, now can fix some small bugs for its correct
implementation in the GridFormattingContext class.
Implement span correctly when indicated in the grid-column-start,
grid-row-start, etc. CSS properties. Previously it had been implemented
as if span was something that went alongside the position property, but
actually it seems like if you do 'span 3' in the grid-column-start
property, for example, this means it literally spans 3 blocks, and the
3 has nothing to do with position.
We were skipping over inline flex containers when looking for an
insertion parent. This made us not generate flex items in those cases.
This commit changes the behavior, so that non-inline-level items can
get inserted into an inline-outside parent, as long as the parent isn't
just flow-inside.
Now that we don't have to deal with the ad-hoc "inline" flag on layout
nodes anymore, we're free to simply obey the inline-outside flag from
the CSS display value when choosing whether to insert as an inline-level
node or not.
Before this, whenever encountering something other than dumb text
content in an inline flow, we assumed it had to be either a replaced
element, or an inline-block.
This removes the special-casing of inline-block so that IFC can size and
layout anything as long as it's inline on the outside.
There's no need to make the assumption that any inline-block box will
be represented by a BlockContainer. Nothing we do with the box here
requires that specific type anyway.
This is a more correct check than !is_inline_block(), as it now enters
all elements that have inline behavior on the outside and flow behavior
on the inside.
These were totally ad-hoc before, is_inline() was based on a boolean
flag on Layout::Node that we set in various situations.
Meanwhile, is_inline_block() was a combination on is_inline() plus a
type check to see if the layout node inherited from BlockContainer.
This patch replaces the above mess with simple lookups of the CSS
display value. Note that layout nodes without their own style (i.e text
nodes) are automatically assumed to be inline and non-blocks. This has
to be special-cased since layout nodes without style will consult the
style of their parent, so without short-circuiting this would break.
This is one of many small steps towards being able to remove the ad-hoc
Layout::Node::is_inline() in favor of honoring the CSS display value
everywhere instead.
When we have nested flexbox layouts within one another, and the child
context wants to call up to the parent context and ask for help with
dimensioning the child flex container, we now simply do nothing.
As far as I can tell, this works out just fine, since the child flex
container will already be dimensioned by the flex layout algorithm.
Previously, FlexFormattingContext would calculate intrinsic sizes in
both axes simultaneously, despite only one being needed.
This patch reduces the amount of unnecessary work by only calculating
the requested intrinsic size.
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.
Inline-level blocks already have the half-leading applied internally,
so by adding it twice, we were offsetting their baseline by the
half-leading of the line.
This fixes an issue where inline-blocks were vertically offset from
the line they're supposed to sit on.
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.
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.
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().
We were using `>=` instead of `>` when checking if a float with a given
width could fit in the available space. If the width was an exact match,
we rejected it! Oops :^)
I couldn't find anything in the specs about this, but GMail uses
empty generated boxes (`::before` and `::after` with `content: ""`)
inside a flexbox container in order to vertically center things.
The flexbox spec tells us to not generate flex items for empty
*anonymous* boxes, so we continue not doing that, but generated boxes
(any pseudo-element box) now always produce a flex item. This probably
isn't perfect either, and we'll have to revisit it for stuff like
`::first-letter`.
Let's not assume the containing block has a paintable box just because
someone is calling set_needs_display(). It can just be a no-op in that
case, and nobody gets hurt.
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.
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`).
This ends up having a big impact on performance, as we now correctly
treat a used flex-basis of `content` as `max-content` which means
we can use cacheable intrinsic sizes for flex items in the majority
of cases.