layout: Add support for table captions (#32657)

This adds initial support for table captions. To do this, the idea of
the table wrapper becomes a bit more concrete. Even so, the wrapper is
still reponsible for allocating space for the grid's border and padding,
as those properties are specified on the wrapper and not grid in CSS.

In order to account for this weirdness of HTML/CSS captions and grid are
now laid out and placed with a negative offset in the table wrapper
content rect.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2024-07-03 20:24:19 +02:00 committed by GitHub
parent f8e4ae6040
commit 959ffad99a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 551 additions and 322 deletions

View file

@ -7,6 +7,7 @@ use serde::Serialize;
use servo_arc::Arc;
use style::logical_geometry::WritingMode;
use style::properties::ComputedValues;
use style::selector_parser::PseudoElement;
use style::values::specified::text::TextDecorationLine;
use crate::context::LayoutContext;
@ -59,12 +60,21 @@ pub(crate) enum NonReplacedFormattingContextContents {
/// The baselines of a layout or a [`crate::fragment_tree::BoxFragment`]. Some layout
/// uses the first and some layout uses the last.
#[derive(Debug, Default, Serialize)]
#[derive(Clone, Copy, Debug, Default, Serialize)]
pub(crate) struct Baselines {
pub first: Option<Au>,
pub last: Option<Au>,
}
impl Baselines {
pub(crate) fn offset(&self, block_offset: Au) -> Baselines {
Self {
first: self.first.map(|first| first + block_offset),
last: self.last.map(|last| last + block_offset),
}
}
}
pub(crate) struct IndependentLayout {
pub fragments: Vec<Fragment>,
@ -83,15 +93,16 @@ pub(crate) struct IndependentLayout {
}
impl IndependentFormattingContext {
pub fn construct<'dom>(
pub fn construct<'dom, Node: NodeExt<'dom>>(
context: &LayoutContext,
node_and_style_info: &NodeAndStyleInfo<impl NodeExt<'dom>>,
node_and_style_info: &NodeAndStyleInfo<Node>,
display_inside: DisplayInside,
contents: Contents,
propagated_text_decoration_line: TextDecorationLine,
) -> Self {
match contents {
Contents::NonReplaced(non_replaced_contents) => {
let mut base_fragment_info: BaseFragmentInfo = node_and_style_info.into();
let contents = match display_inside {
DisplayInside::Flow { is_list_item } |
DisplayInside::FlowRoot { is_list_item } => {
@ -114,17 +125,27 @@ impl IndependentFormattingContext {
))
},
DisplayInside::Table => {
let table_grid_style = context
.shared_context()
.stylist
.style_for_anonymous::<Node::ConcreteElement>(
&context.shared_context().guards,
&PseudoElement::ServoTableGrid,
&node_and_style_info.style,
);
base_fragment_info.flags.insert(FragmentFlags::DO_NOT_PAINT);
NonReplacedFormattingContextContents::Table(Table::construct(
context,
node_and_style_info,
table_grid_style,
non_replaced_contents,
propagated_text_decoration_line,
))
},
};
Self::NonReplaced(NonReplacedFormattingContext {
base_fragment_info: node_and_style_info.into(),
style: Arc::clone(&node_and_style_info.style),
base_fragment_info,
content_sizes: None,
contents,
})