mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
layout: Allow layouts to customize their used style (#35012)
Some layouts like table need some style overrides. We were handling this in `ComputedValuesExt`, but it was messy, unreliable and too limited. For example, we were assuming that a style with `display: table` would belong to a table wrapper box or table grid box. However, certain HTML elements can ignore their `display` value and generate a different kind of box. I think we aren't doing that yet, but we will need this. Also, resolving the used border of a table needs layout information, which we don't have in `ComputedValuesExt`. This patch will allow to improve border collapsing in a follow-up. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
7e7792dfbd
commit
60dc3b26fb
11 changed files with 368 additions and 238 deletions
|
@ -21,7 +21,7 @@ use crate::layout_box_base::LayoutBoxBase;
|
|||
use crate::positioned::PositioningContext;
|
||||
use crate::replaced::ReplacedContents;
|
||||
use crate::sizing::{self, ComputeInlineContentSizes, InlineContentSizesResult};
|
||||
use crate::style_ext::{AspectRatio, DisplayInside};
|
||||
use crate::style_ext::{AspectRatio, DisplayInside, LayoutStyle};
|
||||
use crate::table::Table;
|
||||
use crate::taffy::TaffyContainer;
|
||||
use crate::{ConstraintSpace, ContainingBlock, IndefiniteContainingBlock, LogicalVec2};
|
||||
|
@ -217,7 +217,7 @@ impl IndependentFormattingContext {
|
|||
auto_block_size_stretches_to_containing_block: bool,
|
||||
) -> InlineContentSizesResult {
|
||||
sizing::outer_inline(
|
||||
self.style(),
|
||||
&self.layout_style(),
|
||||
containing_block,
|
||||
auto_minimum,
|
||||
auto_block_size_stretches_to_containing_block,
|
||||
|
@ -242,6 +242,18 @@ impl IndependentFormattingContext {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn layout_style(&self) -> LayoutStyle {
|
||||
match &self.contents {
|
||||
IndependentFormattingContextContents::NonReplaced(content) => {
|
||||
content.layout_style(&self.base)
|
||||
},
|
||||
IndependentFormattingContextContents::Replaced(content) => {
|
||||
content.layout_style(&self.base)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IndependentNonReplacedContents {
|
||||
|
@ -279,6 +291,16 @@ impl IndependentNonReplacedContents {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn layout_style<'a>(&'a self, base: &'a LayoutBoxBase) -> LayoutStyle<'a> {
|
||||
match self {
|
||||
IndependentNonReplacedContents::Flow(fc) => fc.layout_style(base),
|
||||
IndependentNonReplacedContents::Flex(fc) => fc.layout_style(),
|
||||
IndependentNonReplacedContents::Grid(fc) => fc.layout_style(),
|
||||
IndependentNonReplacedContents::Table(fc) => fc.layout_style(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn preferred_aspect_ratio(&self) -> Option<AspectRatio> {
|
||||
// TODO: support preferred aspect ratios on non-replaced boxes.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue