diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-12-07 20:12:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-07 19:12:25 +0000 |
commit | 264c0f972fd1a732ee1d1490d78a1d26a65c6f5f (patch) | |
tree | 29a4ec249b90b0364a6de7638b3c66b8ef23ef2f /components/layout_2020/table/construct.rs | |
parent | 97e9841d47fca9ff576b0af8ec08fdd8421b6915 (diff) | |
download | servo-264c0f972fd1a732ee1d1490d78a1d26a65c6f5f.tar.gz servo-264c0f972fd1a732ee1d1490d78a1d26a65c6f5f.zip |
layout: Add `LayoutBoxBase` and use it for `IndependentFormattingContext` (#34507)
Add a new struct `LayoutBoxBase`, that will be used throughout the box
tree. The idea of this struct is that we have a place to consistently
store common layout information (style and node information) and also to
cache layout results such as content sizes (inline and maybe later box
sizes) and eventually layout results.
In addition to the addition of this struct,
`IndependentFormattingContext` is flattened slightly so that it directly
holds the contents of both replaced and non-replaced elements.
This is only added to independent formatting contexts, but will later be
added to all block containers as well.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/layout_2020/table/construct.rs')
-rw-r--r-- | components/layout_2020/table/construct.rs | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/components/layout_2020/table/construct.rs b/components/layout_2020/table/construct.rs index d57e315d3d8..8eb754d8df5 100644 --- a/components/layout_2020/table/construct.rs +++ b/components/layout_2020/table/construct.rs @@ -25,10 +25,11 @@ use crate::dom::{BoxSlot, NodeExt}; use crate::dom_traversal::{Contents, NodeAndStyleInfo, NonReplacedContents, TraversalHandler}; use crate::flow::{BlockContainerBuilder, BlockFormattingContext}; use crate::formatting_contexts::{ - IndependentFormattingContext, NonReplacedFormattingContext, - NonReplacedFormattingContextContents, + IndependentFormattingContext, IndependentFormattingContextContents, + IndependentNonReplacedContents, }; use crate::fragment_tree::BaseFragmentInfo; +use crate::layout_box_base::LayoutBoxBase; use crate::style_ext::{DisplayGeneratingBox, DisplayLayoutInternal}; /// A reference to a slot and its coordinates in the table @@ -134,12 +135,12 @@ impl Table { let mut table = table_builder.finish(); table.anonymous = true; - IndependentFormattingContext::NonReplaced(NonReplacedFormattingContext { - base_fragment_info: (&anonymous_info).into(), - style: grid_and_wrapper_style, - content_sizes_result: Default::default(), - contents: NonReplacedFormattingContextContents::Table(table), - }) + IndependentFormattingContext { + base: LayoutBoxBase::new((&anonymous_info).into(), grid_and_wrapper_style), + contents: IndependentFormattingContextContents::NonReplaced( + IndependentNonReplacedContents::Table(table), + ), + } } /// Push a new slot into the last row of this table. @@ -853,15 +854,13 @@ where DisplayLayoutInternal::TableCaption => { let contents = match contents.try_into() { Ok(non_replaced_contents) => { - NonReplacedFormattingContextContents::Flow( - BlockFormattingContext::construct( - self.context, - info, - non_replaced_contents, - self.current_text_decoration_line, - false, /* is_list_item */ - ), - ) + IndependentNonReplacedContents::Flow(BlockFormattingContext::construct( + self.context, + info, + non_replaced_contents, + self.current_text_decoration_line, + false, /* is_list_item */ + )) }, Err(_replaced) => { unreachable!("Replaced should not have a LayoutInternal display type."); @@ -869,11 +868,9 @@ where }; let caption = TableCaption { - context: ArcRefCell::new(NonReplacedFormattingContext { - style: info.style.clone(), - base_fragment_info: info.into(), - content_sizes_result: Default::default(), - contents, + context: ArcRefCell::new(IndependentFormattingContext { + base: LayoutBoxBase::new(info.into(), info.style.clone()), + contents: IndependentFormattingContextContents::NonReplaced(contents), }), }; |