aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/flow
diff options
context:
space:
mode:
Diffstat (limited to 'components/layout_2020/flow')
-rw-r--r--components/layout_2020/flow/inline.rs65
-rw-r--r--components/layout_2020/flow/mod.rs19
-rw-r--r--components/layout_2020/flow/root.rs91
3 files changed, 131 insertions, 44 deletions
diff --git a/components/layout_2020/flow/inline.rs b/components/layout_2020/flow/inline.rs
index 7c3fd9a29e3..ba9453a5b80 100644
--- a/components/layout_2020/flow/inline.rs
+++ b/components/layout_2020/flow/inline.rs
@@ -339,11 +339,12 @@ impl Lines {
block: line_block_size,
};
self.next_line_block_position += size.block;
- self.fragments.push(Fragment::Anonymous(AnonymousFragment {
- children: line_contents,
- rect: Rect { start_corner, size },
- mode: containing_block.style.writing_mode,
- }))
+ self.fragments
+ .push(Fragment::Anonymous(AnonymousFragment::new(
+ Rect { start_corner, size },
+ line_contents,
+ containing_block.style.writing_mode,
+ )))
}
}
@@ -402,22 +403,24 @@ impl<'box_tree> PartialInlineBoxFragment<'box_tree> {
inline_position: &mut Length,
at_line_break: bool,
) {
- let mut fragment = BoxFragment {
- tag: self.tag,
- style: self.style.clone(),
- children: std::mem::take(&mut nesting_level.fragments_so_far),
- content_rect: Rect {
- size: Vec2 {
- inline: *inline_position - self.start_corner.inline,
- block: nesting_level.max_block_size_of_fragments_so_far,
- },
- start_corner: self.start_corner.clone(),
+ let content_rect = Rect {
+ size: Vec2 {
+ inline: *inline_position - self.start_corner.inline,
+ block: nesting_level.max_block_size_of_fragments_so_far,
},
- padding: self.padding.clone(),
- border: self.border.clone(),
- margin: self.margin.clone(),
- block_margins_collapsed_with_children: CollapsedBlockMargins::zero(),
+ start_corner: self.start_corner.clone(),
};
+
+ let mut fragment = BoxFragment::new(
+ self.tag,
+ self.style.clone(),
+ std::mem::take(&mut nesting_level.fragments_so_far),
+ content_rect,
+ self.padding.clone(),
+ self.border.clone(),
+ self.margin.clone(),
+ CollapsedBlockMargins::zero(),
+ );
let last_fragment = self.last_box_tree_fragment && !at_line_break;
if last_fragment {
*inline_position += fragment.padding.inline_end +
@@ -470,16 +473,16 @@ fn layout_atomic<'box_tree>(
let size = replaced.used_size_as_if_inline_element(ifc.containing_block, &atomic.style);
let fragments = replaced.make_fragments(&atomic.style, size.clone());
let content_rect = Rect { start_corner, size };
- BoxFragment {
- tag: atomic.tag,
- style: atomic.style.clone(),
- children: fragments,
+ BoxFragment::new(
+ atomic.tag,
+ atomic.style.clone(),
+ fragments,
content_rect,
padding,
border,
margin,
- block_margins_collapsed_with_children: CollapsedBlockMargins::zero(),
- }
+ CollapsedBlockMargins::zero(),
+ )
},
Err(non_replaced) => {
let box_size = atomic.style.box_size();
@@ -545,16 +548,16 @@ fn layout_atomic<'box_tree>(
inline: inline_size,
},
};
- BoxFragment {
- tag: atomic.tag,
- style: atomic.style.clone(),
- children: independent_layout.fragments,
+ BoxFragment::new(
+ atomic.tag,
+ atomic.style.clone(),
+ independent_layout.fragments,
content_rect,
padding,
border,
margin,
- block_margins_collapsed_with_children: CollapsedBlockMargins::zero(),
- }
+ CollapsedBlockMargins::zero(),
+ )
},
};
diff --git a/components/layout_2020/flow/mod.rs b/components/layout_2020/flow/mod.rs
index b7373baf55a..b047fee78df 100644
--- a/components/layout_2020/flow/mod.rs
+++ b/components/layout_2020/flow/mod.rs
@@ -495,16 +495,16 @@ fn layout_in_flow_non_replaced_block_level<'a>(
inline: inline_size,
},
};
- BoxFragment {
+ BoxFragment::new(
tag,
- style: style.clone(),
- children: fragments,
+ style.clone(),
+ fragments,
content_rect,
padding,
border,
margin,
block_margins_collapsed_with_children,
- }
+ )
}
/// https://drafts.csswg.org/css2/visudet.html#block-replaced-width
@@ -545,16 +545,17 @@ fn layout_in_flow_replaced_block_level<'a>(
},
size,
};
- BoxFragment {
+ let block_margins_collapsed_with_children = CollapsedBlockMargins::from_margin(&margin);
+ BoxFragment::new(
tag,
- style: style.clone(),
- children: fragments,
+ style.clone(),
+ fragments,
content_rect,
padding,
border,
- block_margins_collapsed_with_children: CollapsedBlockMargins::from_margin(&margin),
margin,
- }
+ block_margins_collapsed_with_children,
+ )
}
fn solve_inline_margins_for_in_flow_block_level(
diff --git a/components/layout_2020/flow/root.rs b/components/layout_2020/flow/root.rs
index 14b1081c84a..f6466e99844 100644
--- a/components/layout_2020/flow/root.rs
+++ b/components/layout_2020/flow/root.rs
@@ -11,12 +11,15 @@ use crate::formatting_contexts::IndependentFormattingContext;
use crate::fragments::Fragment;
use crate::geom;
use crate::geom::flow_relative::Vec2;
+use crate::geom::physical;
use crate::positioned::AbsolutelyPositionedBox;
use crate::positioned::PositioningContext;
use crate::replaced::ReplacedContent;
use crate::sizing::ContentSizesRequest;
use crate::style_ext::{Display, DisplayGeneratingBox, DisplayInside};
use crate::DefiniteContainingBlock;
+use app_units::Au;
+use euclid::default::{Point2D, Rect, Size2D};
use gfx_traits::print_tree::PrintTree;
use script_layout_interface::wrapper_traits::LayoutNode;
use servo_arc::Arc;
@@ -26,7 +29,17 @@ use style::Zero;
use style_traits::CSSPixel;
pub struct BoxTreeRoot(BlockFormattingContext);
-pub struct FragmentTreeRoot(Vec<Fragment>);
+
+pub struct FragmentTreeRoot {
+ /// The children of the root of the fragment tree.
+ children: Vec<Fragment>,
+
+ /// The scrollable overflow of the root of the fragment tree.
+ scrollable_overflow: physical::Rect<Length>,
+
+ /// The axis-aligned bounding box of the border box of all child fragments
+ bounding_box_of_border_boxes: physical::Rect<Length>,
+}
impl BoxTreeRoot {
pub fn construct<'dom, Node>(context: &LayoutContext, root_element: Node) -> Self
@@ -131,7 +144,58 @@ impl BoxTreeRoot {
&mut independent_layout.fragments,
);
- FragmentTreeRoot(independent_layout.fragments)
+ // FIXME(mrobinson, bug 25564): We should be using the containing block
+ // here to properly convert scrollable overflow to physical geometry.
+ let scrollable_overflow =
+ independent_layout
+ .fragments
+ .iter()
+ .fold(physical::Rect::zero(), |acc, child| {
+ let child_overflow = child.scrollable_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 = physical::Rect {
+ top_left: physical::Vec2::zero(),
+ size: physical::Vec2 {
+ x: child_overflow.size.x + child_overflow.top_left.x,
+ y: child_overflow.size.y + child_overflow.top_left.y,
+ },
+ };
+ acc.axis_aligned_bounding_box(&child_overflow)
+ });
+
+ let containing_block = physical::Rect::zero();
+ let bounding_box_of_border_boxes =
+ independent_layout
+ .fragments
+ .iter()
+ .fold(physical::Rect::zero(), |acc, child| {
+ acc.axis_aligned_bounding_box(&match child {
+ Fragment::Box(fragment) => fragment
+ .border_rect()
+ .to_physical(fragment.style.writing_mode, &containing_block),
+ Fragment::Anonymous(fragment) => {
+ fragment.rect.to_physical(fragment.mode, &containing_block)
+ },
+ Fragment::Text(fragment) => fragment
+ .rect
+ .to_physical(fragment.parent_style.writing_mode, &containing_block),
+ Fragment::Image(fragment) => fragment
+ .rect
+ .to_physical(fragment.style.writing_mode, &containing_block),
+ })
+ });
+
+ FragmentTreeRoot {
+ children: independent_layout.fragments,
+ scrollable_overflow,
+ bounding_box_of_border_boxes,
+ }
}
}
@@ -151,15 +215,34 @@ impl FragmentTreeRoot {
y: Length::new(viewport_size.height),
},
};
- for fragment in &self.0 {
+ for fragment in &self.children {
fragment.build_display_list(builder, &containing_block)
}
}
pub fn print(&self) {
let mut print_tree = PrintTree::new("Fragment Tree".to_string());
- for fragment in &self.0 {
+ for fragment in &self.children {
fragment.print(&mut print_tree);
}
}
+
+ pub fn scrollable_overflow(&self) -> webrender_api::units::LayoutSize {
+ webrender_api::units::LayoutSize::from_untyped(Size2D::new(
+ self.scrollable_overflow.size.x.px(),
+ self.scrollable_overflow.size.y.px(),
+ ))
+ }
+
+ pub fn bounding_box_of_border_boxes(&self) -> Rect<Au> {
+ let origin = Point2D::new(
+ Au::from_f32_px(self.bounding_box_of_border_boxes.top_left.x.px()),
+ Au::from_f32_px(self.bounding_box_of_border_boxes.top_left.y.px()),
+ );
+ let size = Size2D::new(
+ Au::from_f32_px(self.bounding_box_of_border_boxes.size.x.px()),
+ Au::from_f32_px(self.bounding_box_of_border_boxes.size.y.px()),
+ );
+ Rect::new(origin, size)
+ }
}