mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Rename BoxTreeRoot/FragmentTreeRoot to BoxTree/FragmentTree
This commit is contained in:
parent
ee62c7f2e4
commit
c43ab0c267
6 changed files with 93 additions and 85 deletions
|
@ -34,21 +34,33 @@ use style::values::computed::Length;
|
|||
use style_traits::CSSPixel;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct BoxTreeRoot(BlockFormattingContext);
|
||||
pub struct BoxTree {
|
||||
/// Contains typically exactly one block-level box, which was generated by the root element.
|
||||
/// There may be zero if that element has `display: none`.
|
||||
root: BlockFormattingContext,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct FragmentTreeRoot {
|
||||
/// The children of the root of the fragment tree.
|
||||
children: Vec<ArcRefCell<Fragment>>,
|
||||
pub struct FragmentTree {
|
||||
/// Fragments at the top-level of the tree.
|
||||
///
|
||||
/// If the root element has `display: none`, there are zero fragments.
|
||||
/// Otherwise, there is at least one:
|
||||
///
|
||||
/// * The first fragment is generated by the root element.
|
||||
/// * There may be additional fragments generated by positioned boxes
|
||||
/// that have the initial containing block.
|
||||
root_fragments: Vec<ArcRefCell<Fragment>>,
|
||||
|
||||
/// The scrollable overflow of the root of the fragment tree.
|
||||
/// The scrollable overflow rectangle for the entire tree
|
||||
/// https://drafts.csswg.org/css-overflow/#scrollable
|
||||
scrollable_overflow: PhysicalRect<Length>,
|
||||
|
||||
/// The containing block used in the layout of this fragment tree.
|
||||
initial_containing_block: PhysicalRect<Length>,
|
||||
}
|
||||
|
||||
impl BoxTreeRoot {
|
||||
impl BoxTree {
|
||||
pub fn construct<'dom, Node>(context: &LayoutContext, root_element: Node) -> Self
|
||||
where
|
||||
Node: 'dom + Copy + LayoutNode<'dom> + Send + Sync,
|
||||
|
@ -58,10 +70,12 @@ impl BoxTreeRoot {
|
|||
// Zero box for `:root { display: none }`, one for the root element otherwise.
|
||||
assert!(boxes.len() <= 1);
|
||||
|
||||
Self(BlockFormattingContext {
|
||||
contains_floats: contains_floats == ContainsFloats::Yes,
|
||||
contents: BlockContainer::BlockLevelBoxes(boxes),
|
||||
})
|
||||
Self {
|
||||
root: BlockFormattingContext {
|
||||
contains_floats: contains_floats == ContainsFloats::Yes,
|
||||
contents: BlockContainer::BlockLevelBoxes(boxes),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,12 +149,12 @@ fn construct_for_root_element<'dom>(
|
|||
(contains_floats, vec![root_box])
|
||||
}
|
||||
|
||||
impl BoxTreeRoot {
|
||||
impl BoxTree {
|
||||
pub fn layout(
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
viewport: euclid::Size2D<f32, CSSPixel>,
|
||||
) -> FragmentTreeRoot {
|
||||
) -> FragmentTree {
|
||||
let style = ComputedValues::initial_values();
|
||||
|
||||
// FIXME: use the document’s mode:
|
||||
|
@ -160,21 +174,21 @@ impl BoxTreeRoot {
|
|||
let dummy_tree_rank = 0;
|
||||
let mut positioning_context =
|
||||
PositioningContext::new_for_containing_block_for_all_descendants();
|
||||
let independent_layout = self.0.layout(
|
||||
let independent_layout = self.root.layout(
|
||||
layout_context,
|
||||
&mut positioning_context,
|
||||
&(&initial_containing_block).into(),
|
||||
dummy_tree_rank,
|
||||
);
|
||||
|
||||
let mut children = independent_layout
|
||||
let mut root_fragments = independent_layout
|
||||
.fragments
|
||||
.into_iter()
|
||||
.map(|fragment| ArcRefCell::new(fragment))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Zero box for `:root { display: none }`, one for the root element otherwise.
|
||||
assert!(children.len() <= 1);
|
||||
assert!(root_fragments.len() <= 1);
|
||||
|
||||
// There may be more fragments at the top-level
|
||||
// (for positioned boxes whose containing is the initial containing block)
|
||||
|
@ -182,39 +196,41 @@ impl BoxTreeRoot {
|
|||
positioning_context.layout_initial_containing_block_children(
|
||||
layout_context,
|
||||
&initial_containing_block,
|
||||
&mut children,
|
||||
&mut root_fragments,
|
||||
);
|
||||
|
||||
let scrollable_overflow = children.iter().fold(PhysicalRect::zero(), |acc, child| {
|
||||
let child_overflow = child
|
||||
.borrow()
|
||||
.scrollable_overflow(&physical_containing_block);
|
||||
let scrollable_overflow = root_fragments
|
||||
.iter()
|
||||
.fold(PhysicalRect::zero(), |acc, child| {
|
||||
let child_overflow = child
|
||||
.borrow()
|
||||
.scrollable_overflow(&physical_containing_block);
|
||||
|
||||
// https://drafts.csswg.org/css-overflow/#scrolling-direction
|
||||
// We want to clip scrollable overflow on box-start and inline-start
|
||||
// sides of the scroll container.
|
||||
//
|
||||
// FIXME(mrobinson, bug 25564): This should take into account writing
|
||||
// mode.
|
||||
let child_overflow = PhysicalRect::new(
|
||||
euclid::Point2D::zero(),
|
||||
euclid::Size2D::new(
|
||||
child_overflow.size.width + child_overflow.origin.x,
|
||||
child_overflow.size.height + child_overflow.origin.y,
|
||||
),
|
||||
);
|
||||
acc.union(&child_overflow)
|
||||
});
|
||||
// https://drafts.csswg.org/css-overflow/#scrolling-direction
|
||||
// We want to clip scrollable overflow on box-start and inline-start
|
||||
// sides of the scroll container.
|
||||
//
|
||||
// FIXME(mrobinson, bug 25564): This should take into account writing
|
||||
// mode.
|
||||
let child_overflow = PhysicalRect::new(
|
||||
euclid::Point2D::zero(),
|
||||
euclid::Size2D::new(
|
||||
child_overflow.size.width + child_overflow.origin.x,
|
||||
child_overflow.size.height + child_overflow.origin.y,
|
||||
),
|
||||
);
|
||||
acc.union(&child_overflow)
|
||||
});
|
||||
|
||||
FragmentTreeRoot {
|
||||
children,
|
||||
FragmentTree {
|
||||
root_fragments,
|
||||
scrollable_overflow,
|
||||
initial_containing_block: physical_containing_block,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FragmentTreeRoot {
|
||||
impl FragmentTree {
|
||||
pub fn build_display_list(&self, builder: &mut crate::display_list::DisplayListBuilder) {
|
||||
let mut stacking_context = StackingContext::create_root(&builder.wr);
|
||||
{
|
||||
|
@ -228,7 +244,7 @@ impl FragmentTreeRoot {
|
|||
),
|
||||
};
|
||||
|
||||
for fragment in &self.children {
|
||||
for fragment in &self.root_fragments {
|
||||
fragment.borrow().build_stacking_context_tree(
|
||||
fragment,
|
||||
&mut stacking_context_builder,
|
||||
|
@ -245,7 +261,7 @@ impl FragmentTreeRoot {
|
|||
|
||||
pub fn print(&self) {
|
||||
let mut print_tree = PrintTree::new("Fragment Tree".to_string());
|
||||
for fragment in &self.children {
|
||||
for fragment in &self.root_fragments {
|
||||
fragment.borrow().print(&mut print_tree);
|
||||
}
|
||||
}
|
||||
|
@ -261,7 +277,7 @@ impl FragmentTreeRoot {
|
|||
&self,
|
||||
mut process_func: impl FnMut(&Fragment, &PhysicalRect<Length>) -> Option<T>,
|
||||
) -> Option<T> {
|
||||
self.children.iter().find_map(|child| {
|
||||
self.root_fragments.iter().find_map(|child| {
|
||||
child
|
||||
.borrow()
|
||||
.find(&self.initial_containing_block, &mut process_func)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue