Commit Graph

33 Commits

Author SHA1 Message Date
Andreas Kling
2615728d6b LibWeb: Store overflow data in the FormattingState 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
63345c4dfc LibWeb: Rename Layout::Box absolute rect helpers
- padded_rect() -> absolute_padding_box_rect()
- bordered_rect() -> absolute_border_box_rect()
2022-02-11 21:57:56 +01:00
Andreas Kling
9a92236a24 LibWeb: Remove unused functions from Layout::Box 2022-02-11 21:57:39 +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
Andreas Kling
9201f626c1 LibWeb: Use BFC root relative coordinates when flowing around floats
While IFC flows text into a block container, floating objects are
anchored at the BFC root, not necessarily the local block container.

Because of this, we have to use root-relative coordinates when checking
how much space is available in between left and right floated objects.
2022-01-24 02:16:13 +01:00
Andreas Kling
83a6e698a0 LibWeb: Move rect-in-coordinate-space helper to Layout::Box 2022-01-24 02:09:17 +01:00
Daniel Bertalan
4a81b33c07 Everywhere: Fix -Winconsistent-missing-override warnings from Clang
This option is already enabled when building Lagom, so let's enable it
for the main build too. We will no longer be surprised by Lagom Clang
CI builds failing while everything compiles locally.

Furthermore, the stronger `-Wsuggest-override` warning is enabled in
this commit, which enforces the use of the `override` keyword in all
classes, not just those which already have some methods marked as
`override`. This works with both GCC and Clang.
2021-12-11 13:14:15 -08:00
Andreas Kling
723ea4bcd7 LibWeb: Add Layout::Box::border_box_as_relative_rect()
This helper returns the border box (content+padding+border) of a given
box. Margin not included.
2021-10-28 19:44:21 +02:00
Andreas Kling
ec49c8fefd LibWeb: Clip descendants of boxes with overflow:hidden
This is a very limited implementation of overflow:hidden, but since it's
easy to cover this common scenario, let's do it.
2021-10-28 17:09:51 +02: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
27d4ac316f LibWeb: Introduce simple scrollable overflow, size ICB to viewport
Per spec, the initial containing block (ICB) should have the size of the
viewport. We have only done this for the width until now, since we had
no way to express scrollable overflow.

This patch adds Layout::Box::m_overflow_data, an optional struct that
can hold on to information about a box's overflow. Then we have BFC
set the ICB up with some scrollable overflow instead of sizing it to fit
its content vertically.

This fixes a number of broken layouts where correctness depends on
having the appropriate ICB height.
2021-10-14 23:22:59 +02:00
Andreas Kling
a58cc2eeb4 LibWeb: Rename "intrinsic ratio" => "intrinsic aspect ratio" 2021-10-14 18:48:49 +02:00
Andreas Kling
81590b1804 LibWeb: Make intrinsic width/height/ratio a Box concept and simplify it
Apparently it's not only replaced elements that can have intrinsic
sizes, so let's move this concept from ReplacedBox to Box. To avoid
bloating Box, we make the accessors virtual.
2021-10-14 18:39:27 +02:00
Andreas Kling
f73aa8e2bd LibWeb: Move line boxes from Layout::Box to BlockContainer
Per the spec, only a BlockContainer" can have line boxes, so let's not
clutter up every Layout::Box with line boxes.

This also allows us to establish an invariant that BFC and IFC always
operate on a Layout::BlockContainer.

Note that if BlockContainer has all block-level children, its line boxes
are not used for anything. They are only used in the all inline-level
children scenario.
2021-10-06 21:53:25 +02:00
Sam Atkins
abc22b727c LibWeb: Move background painting from Box to its own file
This makes the code accessible to things that aren't a Box, such as
InlineNode.
2021-09-19 22:53:35 +02:00
Sam Atkins
aaf12929d5 LibWeb: Extract border-radius normalization code from Box
This is going to be needed by InlineNodes too!

`BorderPainting.{h,cpp}` might not be the best place for it, but it
works for now.
2021-09-19 22:53:35 +02:00
Andreas Kling
4e47e6d578 LibWeb: Use floating-point math for border-radius rendering
We're still limited by Gfx::Painter here, but we can at least do most
of the LibWeb things in floating-point math.
2021-09-18 12:21:42 +02:00
Andreas Kling
eac31e21f2 LibWeb: Avoid some redundant calls to Layout::Box::absolute_rect()
Computing the absolute rect of a box requires walking the chain of
containing blocks and apply any offsets encountered. This can be slow in
deeply nested box trees, so let's at least avoid doing it multiple times
when once is enough.
2021-09-15 14:18:17 +02:00
Sam Atkins
2844f89a83 LibWeb: Implement "out-of-flow" property of Layout Box
In some situations, a layout box should not participate in the standard
layout process, for example when set to `position: absolute`.
2021-09-15 13:55:25 +02:00
Tobias Christiansen
5471c87246 LibWeb: Add box-shadow rendering
This patch adds the box-shadow rendering to Boxes. We do parse the
blur-radius of a box-shadow but we don't use it for now as the Filter
in the system don't seem quite powerful enough yet to handle that.
2021-07-24 22:16:48 +02:00
Tobias Christiansen
7a566e54e5 LibWeb: Introduce struct to hold border radii and normalize once
The struct BorderRadiusData contains the four radii of the box.
In case the specified borders are too large for the dimensions of the
box, they get scaled down.
2021-05-20 22:08:02 +02:00
Tobias Christiansen
d13526e1e7 LibWeb: Handle background-painting of Box in seperate function 2021-05-20 22:08:02 +02:00
Tobias Christiansen
ff0b3518fa LibWeb: Move the painting of the border out of paint()
So other Boxes can override this function.
2021-05-20 22:08:02 +02:00
Egor Ananyin
d2b6148787 LibWeb: Make painting order more spec-compliant
Now our painting order inside stacking contexts is closer to the
algorithm specified by CSS 2.1 (see section 9.9 and Appendix E)
2021-05-07 22:27:48 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
5de0e0068c LibWeb: Support two-value background-repeat
The background-repeat value may be specified as either one- or two-value
identifiers (to be interpreted as horizontal and vertical repeat). This
adds two pseudo-properties, background-repeat-x and background-repeat-y,
to handle this. One-value identifiers are mapped to two-value in
accordance with the spec.
2021-04-05 18:49:04 +02:00
Timothy Flynn
735829f694 LibWeb: Move painting of background images to common location
For now, painting of background color is kept separate. The ICB needs to
perform a "translate" call between painting the color and background,
whereas other divs must not make that call.
2021-04-05 18:49:04 +02:00
Andreas Kling
543dd54a1d LibWeb: Add bordered_rect() and padded_rect() helpers in Layout::Box 2021-02-22 18:52:58 +01:00
Andreas Kling
3e8873b63e LibWeb: Add Layout::Box::margin_box_height() 2021-01-18 20:20:20 +01:00
Andreas Kling
d18bc9ccd2 LibWeb: Add Layout::Box::margin_box_width() 2021-01-18 20:20:07 +01:00
Andreas Kling
fd441b954d LibWeb: Add fast_is<T>() for some DOM and layout node subclasses
The generic is<T>() uses dynamic_cast which is fine in the majority
of cases, but when one of them shows up in profiles, we can make it
faster by answering the is-a question manually.
2021-01-17 14:42:50 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00