Skip to content

Commit

Permalink
layout: Layout for column flex-basis and minimum automatic size deter…
Browse files Browse the repository at this point in the history
…mination (#33068)

This change adds an expensive layout for the determination of minimum
automatic size and flex basis in process of flexbox layout. Currently,
the layout is not cached, so may be performed up to 2 more times than
necessary.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
  • Loading branch information
mrobinson and Loirooriol committed Aug 19, 2024
1 parent 2a31fdd commit 2f6745c
Show file tree
Hide file tree
Showing 45 changed files with 423 additions and 479 deletions.
5 changes: 1 addition & 4 deletions components/layout_2020/flexbox/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,6 @@ where
FlexLevelBox::OutOfFlowAbsolutelyPositionedBox(_) => 0,
});

FlexContainer {
children,
style: self.info.style.clone(),
}
FlexContainer::new(&self.info.style, children)
}
}
7 changes: 4 additions & 3 deletions components/layout_2020/flexbox/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

//! <https://drafts.csswg.org/css-flexbox/#box-model>

use serde::Serialize;
use style::properties::longhands::flex_direction::computed_value::T as FlexDirection;

use crate::geom::{LogicalRect, LogicalSides, LogicalVec2};

#[derive(Clone, Copy, Default)]
#[derive(Clone, Copy, Debug, Default)]
pub(super) struct FlexRelativeVec2<T> {
pub main: T,
pub cross: T,
Expand Down Expand Up @@ -67,7 +68,7 @@ impl<T> FlexRelativeSides<T> {

/// One of the two bits set by the `flex-direction` property
/// (The other is "forward" v.s. reverse.)
#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug, PartialEq, Serialize)]
pub(super) enum FlexAxis {
/// The main axis is the inline axis of the container (not necessarily of flex items!),
/// cross is block.
Expand All @@ -78,7 +79,7 @@ pub(super) enum FlexAxis {

/// Which flow-relative sides map to the main-start and cross-start sides, respectively.
/// See <https://drafts.csswg.org/css-flexbox/#box-model>
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug, Serialize)]
pub(super) enum MainStartCrossStart {
InlineStartBlockStart,
InlineStartBlockEnd,
Expand Down
609 changes: 331 additions & 278 deletions components/layout_2020/flexbox/layout.rs

Large diffs are not rendered by default.

85 changes: 85 additions & 0 deletions components/layout_2020/flexbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,105 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use geom::{FlexAxis, MainStartCrossStart};
use serde::Serialize;
use servo_arc::Arc as ServoArc;
use style::properties::longhands::align_items::computed_value::T as AlignItems;
use style::properties::longhands::flex_direction::computed_value::T as FlexDirection;
use style::properties::longhands::flex_wrap::computed_value::T as FlexWrap;
use style::properties::ComputedValues;
use style::values::computed::{AlignContent, JustifyContent};
use style::values::specified::align::AlignFlags;

use crate::cell::ArcRefCell;
use crate::formatting_contexts::IndependentFormattingContext;
use crate::fragment_tree::BaseFragmentInfo;
use crate::positioned::AbsolutelyPositionedBox;

mod construct;
mod geom;
mod layout;

/// A structure to hold the configuration of a flex container for use during layout
/// and preferred width calculation.
#[derive(Clone, Debug, Serialize)]
pub(crate) struct FlexContainerConfig {
container_is_single_line: bool,
flex_axis: FlexAxis,
flex_direction: FlexDirection,
flex_direction_is_reversed: bool,
flex_wrap: FlexWrap,
flex_wrap_reverse: bool,
main_start_cross_start_sides_are: MainStartCrossStart,
align_content: AlignContent,
align_items: AlignItems,
justify_content: JustifyContent,
}

impl FlexContainerConfig {
fn new(container_style: &ComputedValues) -> FlexContainerConfig {
let flex_direction = container_style.clone_flex_direction();
let flex_axis = FlexAxis::from(flex_direction);
let flex_wrap = container_style.get_position().flex_wrap;
let container_is_single_line = match flex_wrap {
FlexWrap::Nowrap => true,
FlexWrap::Wrap | FlexWrap::WrapReverse => false,
};
let flex_direction_is_reversed = match flex_direction {
FlexDirection::Row | FlexDirection::Column => false,
FlexDirection::RowReverse | FlexDirection::ColumnReverse => true,
};
let flex_wrap_reverse = match flex_wrap {
FlexWrap::Nowrap | FlexWrap::Wrap => false,
FlexWrap::WrapReverse => true,
};

let align_content = container_style.clone_align_content();
let align_items = AlignItems(match container_style.clone_align_items().0 {
AlignFlags::AUTO | AlignFlags::NORMAL => AlignFlags::STRETCH,
align => align,
});
let justify_content = container_style.clone_justify_content();
let main_start_cross_start_sides_are =
MainStartCrossStart::from(flex_direction, flex_wrap_reverse);

FlexContainerConfig {
container_is_single_line,
flex_axis,
flex_direction,
flex_direction_is_reversed,
flex_wrap,
flex_wrap_reverse,
main_start_cross_start_sides_are,
align_content,
align_items,
justify_content,
}
}
}

#[derive(Debug, Serialize)]
pub(crate) struct FlexContainer {
children: Vec<ArcRefCell<FlexLevelBox>>,

#[serde(skip_serializing)]
style: ServoArc<ComputedValues>,

/// The configuration of this [`FlexContainer`].
config: FlexContainerConfig,
}

impl FlexContainer {
pub(crate) fn new(
style: &ServoArc<ComputedValues>,
children: Vec<ArcRefCell<FlexLevelBox>>,
) -> Self {
Self {
children,
style: style.clone(),
config: FlexContainerConfig::new(style),
}
}
}

#[derive(Debug, Serialize)]
Expand All @@ -37,4 +118,8 @@ impl FlexItemBox {
fn style(&self) -> &ServoArc<ComputedValues> {
self.independent_formatting_context.style()
}

fn base_fragment_info(&self) -> BaseFragmentInfo {
self.independent_formatting_context.base_fragment_info()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
[.target > * 27]
expected: FAIL

[.target > * 29]
expected: FAIL

[.target > * 31]
expected: FAIL

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
[flex-aspect-ratio-img-column-011.html]
[.flexbox 10]
expected: FAIL

[.flexbox 5]
expected: FAIL

[.flexbox 7]
expected: FAIL

[.flexbox 6]
expected: FAIL

[.flexbox 1]
expected: FAIL

Expand Down
2 changes: 2 additions & 0 deletions tests/wpt/meta/css/css-flexbox/flex-basis-011.html.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flex-basis-011.html]
expected: FAIL
12 changes: 0 additions & 12 deletions tests/wpt/meta/css/css-flexbox/flex-basis-intrinsics-001.html.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,5 @@
[.flex-item 10]
expected: FAIL

[.flex-item 4]
expected: FAIL

[.flex-item 5]
expected: FAIL

[.flex-item 6]
expected: FAIL

[.flex-item 11]
expected: FAIL

[.flex-item 12]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions tests/wpt/meta/css/css-flexbox/flex-minimum-size-001.html.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[flex-minimum-size-001.html]
[.flexbox, .inline-flexbox 2]
expected: FAIL

[.flexbox, .inline-flexbox 3]
expected: FAIL
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
[.flexbox 6]
expected: FAIL

[.flexbox 1]
expected: FAIL

[.flexbox 2]
expected: FAIL

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions tests/wpt/meta/css/css-flexbox/gap-007-lr.html.ini

This file was deleted.

2 changes: 0 additions & 2 deletions tests/wpt/meta/css/css-flexbox/gap-007-ltr.html.ini

This file was deleted.

2 changes: 0 additions & 2 deletions tests/wpt/meta/css/css-flexbox/gap-007-rl.html.ini

This file was deleted.

2 changes: 0 additions & 2 deletions tests/wpt/meta/css/css-flexbox/gap-007-rtl.html.ini

This file was deleted.

30 changes: 0 additions & 30 deletions tests/wpt/meta/css/css-flexbox/image-as-flexitem-size-002.html.ini
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
[image-as-flexitem-size-002.html]
[.flexbox > img 4]
expected: FAIL

[.flexbox > img 11]
expected: FAIL

[.flexbox > img 10]
expected: FAIL

[.flexbox > img 1]
expected: FAIL

[.flexbox > img 2]
expected: FAIL

[.flexbox > img 5]
expected: FAIL

[.flexbox > img 8]
expected: FAIL

[.flexbox > img 9]
expected: FAIL

[.flexbox > img 12]
expected: FAIL

[.flexbox > img 13]
expected: FAIL

[.flexbox > img 16]
expected: FAIL
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
[image-as-flexitem-size-002v.html]
[.flexbox > img 4]
expected: FAIL

[.flexbox > img 11]
expected: FAIL

[.flexbox > img 10]
expected: FAIL

[.flexbox > img 1]
expected: FAIL

[.flexbox > img 2]
expected: FAIL

[.flexbox > img 5]
expected: FAIL

[.flexbox > img 8]
expected: FAIL

[.flexbox > img 9]
expected: FAIL

[.flexbox > img 12]
expected: FAIL

[.flexbox > img 13]
expected: FAIL

[.flexbox > img 16]
expected: FAIL
21 changes: 0 additions & 21 deletions tests/wpt/meta/css/css-flexbox/image-as-flexitem-size-004.html.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[image-as-flexitem-size-004.html]
[.flexbox > img 10]
expected: FAIL

[.flexbox > img 13]
expected: FAIL

[.flexbox > img 8]
expected: FAIL

Expand All @@ -19,18 +13,3 @@

[.flexbox > img 1]
expected: FAIL

[.flexbox > img 12]
expected: FAIL

[.flexbox > img 9]
expected: FAIL

[.flexbox > img 2]
expected: FAIL

[.flexbox > img 11]
expected: FAIL

[.flexbox > img 16]
expected: FAIL
Loading

0 comments on commit 2f6745c

Please sign in to comment.