Remove rayon_croissant and clean up contains_floats (#29960)

Remove rayon_croissant and refactor the way that information about
floats in flows bubbles up. This simplifies the code a good deal and
lets us take advantage of some more optimized functions provided by
rayon. This removes 2 crates from the dependency tree.

In addition, this allows avoiding passing `contains_floats` up from
every box tree construction function. This makes things simpler, but
also opens up the possibility of passing more of these flags up in the
future (such as `contains_counters`).
This commit is contained in:
Martin Robinson 2023-07-19 09:01:55 +02:00 committed by GitHub
parent 9c333ab1ee
commit 4f4c2a5922
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 108 additions and 144 deletions

View file

@ -7,7 +7,6 @@ use crate::context::LayoutContext;
use crate::dom::{LayoutBox, NodeExt};
use crate::dom_traversal::{iter_child_nodes, Contents, NodeAndStyleInfo};
use crate::flexbox::FlexLevelBox;
use crate::flow::construct::ContainsFloats;
use crate::flow::float::FloatBox;
use crate::flow::inline::InlineLevelBox;
use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
@ -45,15 +44,17 @@ impl BoxTree {
where
Node: 'dom + Copy + LayoutNode<'dom> + Send + Sync,
{
let (contains_floats, boxes) = construct_for_root_element(&context, root_element);
let boxes = construct_for_root_element(&context, root_element);
// Zero box for `:root { display: none }`, one for the root element otherwise.
assert!(boxes.len() <= 1);
let contents = BlockContainer::BlockLevelBoxes(boxes);
let contains_floats = contents.contains_floats();
Self {
root: BlockFormattingContext {
contains_floats: contains_floats == ContainsFloats::Yes,
contents: BlockContainer::BlockLevelBoxes(boxes),
contents,
contains_floats,
},
canvas_background: CanvasBackground::for_root_element(context, root_element),
}
@ -209,14 +210,14 @@ impl BoxTree {
fn construct_for_root_element<'dom>(
context: &LayoutContext,
root_element: impl NodeExt<'dom>,
) -> (ContainsFloats, Vec<ArcRefCell<BlockLevelBox>>) {
) -> Vec<ArcRefCell<BlockLevelBox>> {
let info = NodeAndStyleInfo::new(root_element, root_element.style(context));
let box_style = info.style.get_box();
let display_inside = match Display::from(box_style.display) {
Display::None => {
root_element.unset_all_boxes();
return (ContainsFloats::No, Vec::new());
return Vec::new();
},
Display::Contents => {
// Unreachable because the style crate adjusts the computed values:
@ -230,41 +231,32 @@ fn construct_for_root_element<'dom>(
let contents =
ReplacedContent::for_element(root_element).map_or(Contents::OfElement, Contents::Replaced);
let (contains_floats, root_box) = if box_style.position.is_absolutely_positioned() {
(
ContainsFloats::No,
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(ArcRefCell::new(
AbsolutelyPositionedBox::construct(context, &info, display_inside, contents),
)),
)
let root_box = if box_style.position.is_absolutely_positioned() {
BlockLevelBox::OutOfFlowAbsolutelyPositionedBox(ArcRefCell::new(
AbsolutelyPositionedBox::construct(context, &info, display_inside, contents),
))
} else if box_style.float.is_floating() {
(
ContainsFloats::Yes,
BlockLevelBox::OutOfFlowFloatBox(FloatBox::construct(
context,
&info,
display_inside,
contents,
)),
)
BlockLevelBox::OutOfFlowFloatBox(FloatBox::construct(
context,
&info,
display_inside,
contents,
))
} else {
let propagated_text_decoration_line = info.style.clone_text_decoration_line();
(
ContainsFloats::No,
BlockLevelBox::Independent(IndependentFormattingContext::construct(
context,
&info,
display_inside,
contents,
propagated_text_decoration_line,
)),
)
BlockLevelBox::Independent(IndependentFormattingContext::construct(
context,
&info,
display_inside,
contents,
propagated_text_decoration_line,
))
};
let root_box = ArcRefCell::new(root_box);
root_element
.element_box_slot()
.set(LayoutBox::BlockLevel(root_box.clone()));
(contains_floats, vec![root_box])
vec![root_box]
}
impl BoxTree {