summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
AgeCommit message (Collapse)Author
2021-01-12Libraries: Move to Userland/Libraries/Andreas Kling
2021-01-06LibWeb: Move absolute positioning up to FormattingContextAndreas Kling
It seems like both BFC and IFC can have absolutely positioned children. It's a bit strange, but consider the following HTML: <html><body>foobar<img style="position: absolute"></body></html> In such a document, the <img> element is an absolutely positioned child of a block-level element (<body>) with no block-level children. An IFC is established for <body>, and needs to handle layout for <img>.
2021-01-06LibWeb: Rename LayoutStyle => CSS::ComputedValuesAndreas Kling
This object represents the CSS "computed values" so let's call it that.
2021-01-02LibWeb: When collapsing margins, consider border box heightsAndreas Kling
Empty boxes should be fully collapsed, but a box with border and/or padding is not empty. This fixes an issue where <hr> elements were getting weirdly collapsed since they have zero content height (but some border height.)
2021-01-01LibWeb: Remove hand-rolled is_foo() helpers in Layout::Node classesAndreas Kling
2020-12-18LibWeb: Silence BFC spam about not knowing how to place boxesAndreas Kling
This gets way too noisy on some pages, and isn't even interesting.
2020-12-17LibWeb: Fix shrink-to-fit layout for position:absoluteAndreas Kling
We were following the spec incorrectly. The comment was right, but the code was wrong.
2020-12-17LibWeb: Use the correct containing block for position:absolute widthAndreas Kling
2020-12-17LibWeb: Make sure the ICB is at least as tall as the viewportAndreas Kling
This is a hack until we implement a proper overflow mechanism. For now, this allows us to right-click below the lowest content on the page.
2020-12-15LibWeb: Generate the CSS::ValueID enum and its helper functionsAndreas Kling
2020-12-14LibWeb: Use final box model metrics for absolute 'right' and 'bottom'Andreas Kling
We've already converted these to floats, so no need to do it again.
2020-12-14LibWeb: Layout absolutely positioned children *after* computing heightAndreas Kling
This is required for CSS "bottom" to work correctly on absolutely positioned elements.
2020-12-12LibWeb: Store layout box model metrics as floatsAndreas Kling
Instead of storing them as CSS::Lengths, we now store the resolved values for margin/padding/border/offset top/right/bottom/left with each Layout::NodeWithStyleAndBoxModelMetrics. This simplifies a lot of code since it's no longer necessary to resolve values before using them.
2020-12-12LibWeb: Don't place floating boxes before everything elseAndreas Kling
Instead, just handle them as we go about laying out block-level boxes.
2020-12-11LibWeb: Remove some unnecessary is_replaced() checks in BFCAndreas Kling
BFC::compute_width() has a short-circuit path for replaced elements.
2020-12-11LibWeb: Move replaced element layout out of Layout::ReplacedBoxAndreas Kling
Replaced elements are now laid out by the current formatting context. Since the logic is almost identical in BFC and IFC, it's implemented by static helpers in FormattingContext.
2020-12-11LibWeb: Fix inline-block width computation with no specified widthAndreas Kling
Undefined width should be treated the same as width:auto;
2020-12-07LibWeb: Use CSS::Length::resolved_or_zero() in a few placesAndreas Kling
2020-12-06LibWeb: Forget floating boxes once we've gone past themAndreas Kling
Once we've generated enough lines to make it past all the floating boxes on either side, just forget those boxes. This simplifies the available space computation since we don't have to consider boxes that can't vertically intersect the current line anyway.
2020-12-06LibWeb: Floating elements should not stack horizontally after clearAndreas Kling
After we've cleared past some floating elements, we should not keep stacking new floats horizontally. Instead, new floats after the clear should once again start at the left or right edge of their containing block.
2020-12-06LibWeb: Pass current target box to BFC::run()Andreas Kling
The BFC "context box" is now the outer box of the block formatting context. Previously the context box was always the current target box, which made it hard to reason about who was really the containing block of whom in various places. Note that IFC still has the containing block as its context box, this change only affects BFC. However, to clarify the situation in IFC, I've added a containing_block() getter than returns the context_box().
2020-12-06LibWeb: Move box floatation out of normal flow layoutAndreas Kling
Layout of floating children now places the child in the normal flow and then floats it left or right afterwards.
2020-12-06LibWeb: Layout floating children per block instead of whole BFC at onceAndreas Kling
Instead of plowing through all the floating boxes within a BFC and doing all the layout up front, do the children of each block as we go. This will allow us to know the vertical position of the containing block when placing floats.
2020-12-06LibWeb: Do floating box placement together with other boxesAndreas Kling
I realized that we're supposed to float the boxes sideways, but not always to y=0, so that makes it logical to share the placement logic with other normal non-replaced blocks. This is still pretty buggy but we're getting closer. :^)
2020-12-06LibWeb: Naively implement the CSS clear propertyAndreas Kling
This is definitely not fully-featured, but basically we now handle the clear property by forcing the cleared box below the bottom-most floated box on the relevant side.
2020-12-06LibWeb: Floating boxes with width:auto should be shrink-to-fitAndreas Kling
2020-12-05LibWeb: First slightly naive implementation of CSS floats :^)Andreas Kling
Boxes can now be floated left or right, which makes text within the same block formatting context flow around them. We were creating way too many block formatting contexts. As it turns out, we don't need one for every new block, but rather there's a set of rules that determines whether a given block creates a new block formatting context. Each BFC keeps track of the floating boxes within it, and IFC's can then query it to find the available space for line boxes. There's a huge hack in here where we assume all lines are the exact line-height. Making this work with vertically non-uniform lines will require some architectural changes.
2020-12-04LibWeb: Block layout should account for vertical border spaceAndreas Kling
We were not accounting for space occupied by borders when computing the vertical (y) position of blocks. This meant that blocks with wide top/bottom borders could bleed into each other incorrectly. Fix this by using the combined padding+border geometry instead of just the padding when placing blocks on the y axis.
2020-12-04LibWeb: Block layout should resolve relative lengths against each boxAndreas Kling
We were incorrectly resolving relative length units (ex, em, etc.) against the containing block in many cases. Fix this to resolve them against the descendant box we're currently processing.
2020-12-04LibWeb: Rename LayoutNode::is_root() => is_initial_containing_block()Andreas Kling
Let's use spec language for this. :^)
2020-11-25LibWeb: Keep track of the parent of each formatting contextAndreas Kling
This will allow us to find the containing block formatting context when needed later on.
2020-11-22LibWeb: Rename LayoutNode classes and move them into Layout namespaceAndreas Kling
Bring the names of various boxes closer to spec language. This should hopefully make things easier to understand and hack on. :^) Some notable changes: - LayoutNode -> Layout::Node - LayoutBox -> Layout::Box - LayoutBlock -> Layout::BlockBox - LayoutReplaced -> Layout::ReplacedBox - LayoutDocument -> Layout::InitialContainingBlockBox - LayoutText -> Layout::TextNode - LayoutInline -> Layout::InlineNode Note that this is not strictly a "box tree" as we also hang inline/text nodes in the same tree, and they don't generate boxes. (Instead, they contribute line box fragments to their containing block!)
2020-11-22LibWeb: Reorganize layout system in terms of formatting contextsAndreas Kling
This is a first (huge) step towards modernizing the layout architecture and bringing it closer to spec language. Layout is now performed by a stack of formatting contexts, operating on the box tree (or layout tree, if you will.) There are currently three types of formatting context: - BlockFormattingContext (BFC) - InlineFormattingContext (IFC) - TableFormattingContext (TFC) Document::layout() creates the initial BlockFormattingContext (BFC) which lays out the initial containing block (ICB), and then we recurse through the tree, creating BFC, IFC or TFC as appropriate and handing over control at the context boundaries. The majority of this patch is just refactoring the old logic spread out in LayoutBlock and LayoutTableRowGroup, and turning into these context classes instead. A lot more cleanup will be needed. There are many architectural wins here, the main one being that layout is no longer performed by boxes themselves, which gives us much greater flexibility in the outer/inner layout of a given box.