Commit graph

67 commits

Author SHA1 Message Date
Naveen Gattu
0e3b52af27 fmt 2021-11-30 18:13:39 -08:00
Naveen Gattu
00a7c172e2
rm ws 2021-11-30 12:54:15 -08:00
Naveen Gattu
9af545e4e4
Do not use ParallelIterator if not using rayon 2021-11-30 12:51:56 -08:00
Manish Goregaokar
5a53fb1271 Adjust absolute positioned box offsets in flow layout 2020-07-27 09:48:37 -07:00
Manish Goregaokar
96c0c50874 Allow adjusting box offsets 2020-07-27 09:48:37 -07:00
Patrick Walton
362b64aa68 Use the size of the containing block, not the size of the block formatting
context, to place floats in layout 2020.

The containing block for a float is not necessarily the same as the block
formatting context the float is in per CSS 2.1 [1]:

"For other elements, if the element’s position is relative or static, the
containing block is formed by the content edge of the nearest block container
ancestor box."

This shows up in the simplest case:

	<html>
	<body>
	<div style="float: left">Hello</div>
	</body>
	</html>

In this case, the `<html>` element is the block formatting context with inline
size equal to the width of the window, but the `<body>` element with nonzero
inline margins is the containing block for the float. The float placement must
respect the content box of the `<body>` element (i.e. floats must not overlap
the `<body>` element's margins), not that of the `<html>` element.

Because a single block formatting context may contain floats with different
containing blocks, the left and right "walls" of that containing block become
properties of individual floats at the time of placement, not properties of the
float context itself.

Additionally, this commit generalizes the float placement logic a bit to allow
the placement of arbitrary objects, not just floats. This is intended to
support inline layout and block formatting context placement.

This commit updates the `FloatContext` and associated tests only and doesn't
actually wire the context up to the rest of layout, so floats in pages still
aren't actually laid out.

[1]: https://drafts.csswg.org/css2/#containing-block-details
2020-07-22 19:58:28 -07:00
Patrick Walton
5b36d211b4 Add an implementation of the core float and clear placement logic in layout
2020, not yet wired to the rest of layout.

This commit implements an object that handles the 10 rules in CSS 2.1:

https://www.w3.org/TR/CSS2/visuren.html#float-position

The implementation strategy is that of a persistent balanced binary search tree
of float bands. Binary search trees are commonly used for implementing float
positioning; e.g. by WebKit.  Persistence enables each object that interacts
with floats to efficiently contain a snapshot of the float list at the time
that object was laid out. That way, incremental layout can invalidate and start
reflow at any point in a containing block.

This commit features extensive use of
[QuickCheck](https://github.com/BurntSushi/quickcheck) to ensure that the rules
of the CSS specification are followed.

Because this is not yet connected to layout, floats will not actually be laid
out in Web pages yet.

Note that unit tests as set up in Servo currently require types that they
access to be public. Therefore, some internal layout 2020 types that were
previously private have been made public. This is somewhat unfortunate.

Part of #25167.
2020-07-20 12:42:34 -07:00
Simon Sapin
080f5bb763 An element establishing a formatting context *is* the containing block for its contents 2020-06-23 00:41:26 +02:00
Simon Sapin
42e9d2450e Parallelize BlockContainer::inline_content_sizes 2020-06-19 15:38:15 +02:00
Simon Sapin
51c388fe1c Rename outer_inline* outside of sizing.rs to outer_inline_content_sizes* 2020-06-19 15:27:33 +02:00
Anthony Ramine
235df94f2e Compute content sizes lazily in layout 2020 2020-06-18 14:11:02 +02:00
Anthony Ramine
db80b8e3c1 Make IndependentFormattingContext an enum 2020-06-15 18:09:15 +02:00
Anthony Ramine
b53959d23d Move IndependentFormattingContext::as_replaced to IndependentFormattingContextContents 2020-06-15 18:09:15 +02:00
Anthony Ramine
b66dd66403 Rename contents to context in AbsolutelyPositionedBox 2020-06-15 18:09:15 +02:00
Simon Sapin
08f008a011 Use the writing mode of the containing block when accessing CSS properties
… and converting them to flow-relative geometric values.

These values are almost always used to size and position a fragment within its containing block, so using the mode of the containing block seems more correct.

Note that the `writing-mode` and `direction` properties are disabled in Servo at the moment, so this PR by itself should have no effect: the writing mode of an element is always the same of that of its containing block since they’re both horizontal rtl.
2020-06-10 09:03:18 +02:00
Anthony Ramine
e975d24c4b Store abspos boxes in a RefCell too
We want to mutate them when lazily computing their content sizes, but they
are behind an Arc for the hoisting infra, so it also needs its own layer
of inner mutability.
2020-06-09 15:13:18 +02:00
Anthony Ramine
d9e87f2eb1 Mutably borrow to do layout of independent formatting contexts
We want to compute content sizes on demand rather than eagerly so we will
need to mutate the independent formatting contexts that own the content sizes.
2020-06-09 13:44:43 +02:00
Martin Robinson
89855afa4d layout_2020: Tag fragments with their pseudo content type
This will allow us to answer queries and properly handle animations in
the future for fragments generated for pseudo content.
2020-06-06 17:25:08 +02:00
Simon Sapin
c43ab0c267 Rename BoxTreeRoot/FragmentTreeRoot to BoxTree/FragmentTree 2020-05-15 13:25:35 +02:00
Simon Sapin
7f975c3d5d Remove use of some other unstable features 2020-04-15 15:17:52 +02:00
Simon Sapin
c377d9c48e Implement the box-sizing property 2020-03-31 23:43:58 +02:00
Simon Sapin
0e35d70ca8 Introduce a PaddingBorderMargin helper 2020-03-31 23:04:10 +02:00
Simon Sapin
8350f8a08a Don’t forget to apply the inline-start margin to blocks 🤦 2020-03-31 22:59:43 +02:00
Martin Robinson
19f4b708b3 layout_2020: Use ArcRefCell to track hoisted fragments
This avoids the use of lookup tables for containing blocks when
constructing the stacking context tree.

This seems to catch some laid-out hoisted fragments that were otherwise
dropped in the previous design. The changes cause one new test to pass
and one to fail. Visual examination of the failing tests reveals that
it's a progression (list markers are appearing when they were previously
not rendered).
2020-03-27 13:02:22 +01:00
Patrick Walton
42058681a5 Switch the standard slice iterator in inline layout to a custom one in order to
avoid lifetime problems
2020-03-17 20:13:57 -07:00
Patrick Walton
9cb824e77c Wrap BlockLevelBox and InlineLevelBox with AtomicRefCell 2020-03-17 11:15:17 -07:00
Anthony Ramine
c3932185ec Make AbsolutelyPositionedBox be 'static 2020-03-17 11:15:17 -07:00
Martin Robinson
c3b1c92ac1 layout_2020: Paint hoisted positioned fragments in tree order
Instead of painting hoisted position fragments in the order to which
they are hoisted, paint them in tree order and properly incorporate them
into the stacking context.

We do this by creating a placeholder fragment in the original tree position
of hoisted fragments. The ghost fragment contains an atomic id which
links back to the hoisted fragment in the containing block.

While building the stacking context, we keep track of containing blocks
and their children. When encountering a placeholder fragment we look at
the containing block's hoisted children in order to properly paint the
hoisted fragment.

One notable design modification in this change is that hoisted fragments
no longer need an AnonymousFragment as their parent. Instead they are
now direct children of the fragment that establishes their containing block.
2020-03-11 12:47:06 +01:00
Martin Robinson
8de55695e4 Have transforms and filters be CBs for all descendants in layout_2020
This is a feature that was never properly implemented in the previous
layout system. We still need to preserve their in-tree order in the
display list though.
2020-03-02 11:47:00 +01:00
Martin Robinson
c20c468814 Rename AbsolutelyPositionedBox::layout to AbsolutelyPositionedBox::to_hoisted
This method doesn't actually do any layout, but converts this block to a
HoistedAbsolutelyPositionedBox which is hoisted and then laid-out with
its containing block later. This makes the code a little easier to read.
2020-02-28 14:42:29 +01:00
Fernando Jiménez Moreno
c4276aa27e Fix rebase issues and run Prettier on layout viewer code 2020-02-21 11:11:00 +01:00
Fernando Jiménez Moreno
a042f85083 Dump box tree state into json files and display it on layout 2020 viewer 2020-02-21 11:11:00 +01:00
Fernando Jiménez Moreno
67706f9c0b Add fragment debug id 2020-02-21 11:11:00 +01:00
Martin Robinson
8825d588c1 Add initial support for scrollable overflow in layout_2020
This still isn't totally correct and non-root scrolling is not handled
at all, but the root frame now scrolls.
2020-01-21 15:29:23 +01:00
Anthony Ramine
abc2c15c28 Store an OpaqueNode in boxes and fragments 2019-12-13 17:59:27 +01:00
Simon Sapin
6f3c5ce773 Rename BlockLevelKind to NonReplacedContents 2019-12-13 13:59:15 +01:00
Simon Sapin
58b7005a9b Make for_maybe_position_relative take care of relative adjustment. 2019-12-13 13:13:50 +01:00
Simon Sapin
04b701b9e0 Move call to for_maybe_position_relative out of layout_in_flow_non_replaced_block_level 2019-12-13 12:41:58 +01:00
Simon Sapin
672d971d58 Regroup branches specific to SameFormattingContextBlock 2019-12-13 12:33:07 +01:00
Simon Sapin
c0962aa3fc Replace the closure in layout_in_flow_non_replaced_block_level with an enum 2019-12-13 12:09:51 +01:00
Simon Sapin
5ebddf19e6 Layout position: fixed in the initial containing block 2019-12-12 22:50:11 +01:00
Simon Sapin
c44ee516a1 Give PositioningContext more responsibilities
Iits details are now private to the module.

It has a couple methods that take closures to make sure that "before" and "after" steps are done together:

* In an absolutely positioned box, take care of nested abspos (establish a new containing block, etc.)
* For a box that *might* be `position: relative`, optionally take care of the same.
2019-12-12 22:50:11 +01:00
Simon Sapin
1c8d14ac0d Upgrade rayon_croissant to 0.2.0 2019-12-12 18:57:18 +01:00
Simon Sapin
9edda952c9 Make adjust_static_positions a method of PositioningContext 2019-12-12 15:43:50 +01:00
Simon Sapin
b43a3de51d Introduce PositioningContext 2019-12-12 15:37:01 +01:00
Simon Sapin
c895e3d236 Disable use of rayon with --layout-threads 1 instead of panicking 2019-12-10 18:41:24 +01:00
Simon Sapin
14ddf39215 Rename ReplacedContent::used_size to used_size_as_if_inline_element 2019-12-10 15:11:53 +01:00
Simon Sapin
c40583b644 Move replaced box used size computation to a method of ReplacedContents 2019-12-10 12:36:43 +01:00
Simon Sapin
ce7e84be72 Replace percent_resolved_* functions with methods 2019-12-10 12:36:43 +01:00
Simon Sapin
a2c2b294d5 Move clamp_* functions to methods of Length 2019-12-10 12:36:43 +01:00