use std::ops::{Deref, DerefMut};
use super::*;
#[derive(Debug, Clone)]
pub(super) struct GridUsedStyle(css::ZoomedLayoutStyle);
impl GridUsedStyle {
pub(super) fn from_normalized(style: css::ZoomedLayoutStyle) -> Self {
Self(style)
}
pub(super) fn used_style(&self) -> &css::ZoomedLayoutStyle {
&self.0
}
pub(super) fn clone_used_style(&self) -> css::ZoomedLayoutStyle {
self.0.clone()
}
}
impl Deref for GridUsedStyle {
type Target = ComputedStyle;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for GridUsedStyle {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
#[derive(Debug, Clone)]
pub(super) struct GridUsedItem<'a> {
source: FormattingContextChild<'a>,
pub(super) style: GridUsedStyle,
}
impl<'a> GridUsedItem<'a> {
pub(super) fn from_source(
source: FormattingContextChild<'a>,
style: css::ZoomedLayoutStyle,
) -> Self {
Self {
source,
style: GridUsedStyle::from_normalized(style),
}
}
}
impl<'a> Deref for GridUsedItem<'a> {
type Target = FormattingContextChild<'a>;
fn deref(&self) -> &Self::Target {
&self.source
}
}
pub(super) type GridSourceChild<'a> = FormattingContextChild<'a>;
pub(super) type GridChild<'a> = GridUsedItem<'a>;
pub(super) fn positioned_grid_static_probe_child<'a>(child: &GridChild<'a>) -> GridChild<'a> {
let mut style = child.style.clone();
style.position = Position::Static;
if style.display.is_inline_level() {
style.display = style.display.blockified();
}
style.margin = css::Edges::ZERO;
style.box_values.width = css::ComputedLengthPercentageOrAuto::ZERO;
style
.box_values
.height
.replace_with_used(css::ComputedLengthPercentageOrAuto::ZERO);
style.box_values.min_width = css::ComputedLengthPercentageOrAuto::ZERO;
style.box_values.min_height = css::ComputedLengthPercentageOrAuto::ZERO;
style.box_values.max_width = css::ComputedLengthPercentageOrAuto::ZERO;
style.box_values.max_height = css::ComputedLengthPercentageOrAuto::ZERO;
GridUsedItem::from_source(
FormattingContextChild {
kind: FormattingContextChildKind::AnonymousContent {
children: Vec::new(),
},
style: child.source.style.clone(),
},
style.0,
)
}
pub(super) fn grid_child_lists_from_boxes<'a>(
child_boxes: &'a [box_tree::FormattingBox<'a>],
) -> (Vec<GridSourceChild<'a>>, Vec<GridSourceChild<'a>>) {
itemize_blockified_children(
child_boxes,
ItemizationOptions {
anonymous_item_tag: "__spindrift_anonymous_grid_item",
strip_blockified_inline_text_paint: true,
establish_independent_formatting_context: true,
},
)
}
impl<'a> LayoutBuilder<'a> {
pub(in crate::layout::grid) fn grid_used_style(&self, style: &ComputedStyle) -> GridUsedStyle {
GridUsedStyle::from_normalized(self.style_with_current_viewport_lengths(style))
}
pub(in crate::layout::grid) fn prepare_grid_children<'box_tree>(
&mut self,
children: Vec<GridSourceChild<'box_tree>>,
) -> Vec<GridChild<'box_tree>> {
children
.into_iter()
.map(|mut source| {
self.resolve_style_current_viewport_lengths(&mut source.style);
let mut style = css::LayoutStyle::from_computed(&source.style).into_zoomed();
if property_containment_applies_to_style(&style)
&& (style.contain.layout || style.contain.paint)
{
style.grid_template_rows.resolve_contained_subgrid();
style.grid_template_columns.resolve_contained_subgrid();
}
GridUsedItem::from_source(source, style)
})
.collect()
}
}
pub(super) fn grid_item_layout_style(style: &ComputedStyle) -> ComputedStyle {
independent_formatting_context_item_style(style.clone())
}