Auto merge of #26838 - servo:flexbox, r=nox

Flexbox, the boring parts

I have a local branch starting to implement https://drafts.csswg.org/css-flexbox/#layout-algorithm. It’s not PR-ready yet, but it’s going to be large so here are some of the less interesting parts meaningful by themselves. Landing the module split in particular will help reduce merge conflicts.

CC https://github.com/servo/servo/issues/26639
This commit is contained in:
bors-servo 2020-06-10 17:19:16 -04:00 committed by GitHub
commit d85c6ee341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 71 additions and 45 deletions

View file

@ -2,36 +2,21 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use super::{FlexContainer, FlexLevelBox};
use crate::cell::ArcRefCell; use crate::cell::ArcRefCell;
use crate::context::LayoutContext; use crate::context::LayoutContext;
use crate::dom_traversal::{ use crate::dom_traversal::{
BoxSlot, Contents, NodeAndStyleInfo, NodeExt, NonReplacedContents, TraversalHandler, BoxSlot, Contents, NodeAndStyleInfo, NodeExt, NonReplacedContents, TraversalHandler,
}; };
use crate::element_data::LayoutBox; use crate::element_data::LayoutBox;
use crate::formatting_contexts::{IndependentFormattingContext, IndependentLayout}; use crate::formatting_contexts::IndependentFormattingContext;
use crate::fragments::Tag; use crate::fragments::Tag;
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext}; use crate::positioned::AbsolutelyPositionedBox;
use crate::sizing::{BoxContentSizes, ContentSizes, ContentSizesRequest}; use crate::sizing::{BoxContentSizes, ContentSizes, ContentSizesRequest};
use crate::style_ext::DisplayGeneratingBox; use crate::style_ext::DisplayGeneratingBox;
use crate::ContainingBlock;
use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rayon::iter::{IntoParallelIterator, ParallelIterator};
use std::borrow::Cow; use std::borrow::Cow;
use style::values::computed::Length;
use style::values::specified::text::TextDecorationLine; use style::values::specified::text::TextDecorationLine;
use style::Zero;
// FIXME: `min-width: auto` is not zero: https://drafts.csswg.org/css-flexbox/#min-size-auto
#[derive(Debug, Serialize)]
pub(crate) struct FlexContainer {
children: Vec<ArcRefCell<FlexLevelBox>>,
}
#[derive(Debug, Serialize)]
pub(crate) enum FlexLevelBox {
FlexItem(IndependentFormattingContext),
OutOfFlowAbsolutelyPositionedBox(ArcRefCell<AbsolutelyPositionedBox>),
}
impl FlexContainer { impl FlexContainer {
pub fn construct<'dom>( pub fn construct<'dom>(
@ -230,23 +215,3 @@ where
FlexContainer { children } FlexContainer { children }
} }
} }
impl FlexContainer {
pub(crate) fn layout(
&self,
layout_context: &LayoutContext,
positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock,
tree_rank: usize,
) -> IndependentLayout {
// FIXME
let _ = layout_context;
let _ = positioning_context;
let _ = containing_block;
let _ = tree_rank;
IndependentLayout {
fragments: Vec::new(),
content_block_size: Length::zero(),
}
}
}

View file

@ -0,0 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 super::FlexContainer;
use crate::context::LayoutContext;
use crate::formatting_contexts::IndependentLayout;
use crate::positioned::PositioningContext;
use crate::ContainingBlock;
use style::values::computed::Length;
use style::Zero;
// FIXME: `min-width: auto` is not zero: https://drafts.csswg.org/css-flexbox/#min-size-auto
impl FlexContainer {
pub(crate) fn layout(
&self,
layout_context: &LayoutContext,
positioning_context: &mut PositioningContext,
containing_block: &ContainingBlock,
tree_rank: usize,
) -> IndependentLayout {
// FIXME
let _ = layout_context;
let _ = positioning_context;
let _ = containing_block;
let _ = tree_rank;
IndependentLayout {
fragments: Vec::new(),
content_block_size: Length::zero(),
}
}
}

View file

@ -0,0 +1,21 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 crate::cell::ArcRefCell;
use crate::formatting_contexts::IndependentFormattingContext;
use crate::positioned::AbsolutelyPositionedBox;
mod construct;
mod layout;
#[derive(Debug, Serialize)]
pub(crate) struct FlexContainer {
children: Vec<ArcRefCell<FlexLevelBox>>,
}
#[derive(Debug, Serialize)]
pub(crate) enum FlexLevelBox {
FlexItem(IndependentFormattingContext),
OutOfFlowAbsolutelyPositionedBox(ArcRefCell<AbsolutelyPositionedBox>),
}

View file

@ -72,7 +72,8 @@ ${helpers.predefined_type(
${helpers.single_keyword( ${helpers.single_keyword(
"flex-direction", "flex-direction",
"row row-reverse column column-reverse", "row row-reverse column column-reverse",
engines="gecko servo-2013", engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-flexbox/#flex-direction-property", spec="https://drafts.csswg.org/css-flexbox/#flex-direction-property",
extra_prefixes="webkit", extra_prefixes="webkit",
animation_value_type="discrete", animation_value_type="discrete",
@ -83,7 +84,8 @@ ${helpers.single_keyword(
${helpers.single_keyword( ${helpers.single_keyword(
"flex-wrap", "flex-wrap",
"nowrap wrap wrap-reverse", "nowrap wrap wrap-reverse",
engines="gecko servo-2013", engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-flexbox/#flex-wrap-property", spec="https://drafts.csswg.org/css-flexbox/#flex-wrap-property",
extra_prefixes="webkit", extra_prefixes="webkit",
animation_value_type="discrete", animation_value_type="discrete",
@ -205,7 +207,8 @@ ${helpers.predefined_type(
"flex-grow", "flex-grow",
"NonNegativeNumber", "NonNegativeNumber",
"From::from(0.0)", "From::from(0.0)",
engines="gecko servo-2013", engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-flexbox/#flex-grow-property", spec="https://drafts.csswg.org/css-flexbox/#flex-grow-property",
extra_prefixes="webkit", extra_prefixes="webkit",
animation_value_type="NonNegativeNumber", animation_value_type="NonNegativeNumber",
@ -216,7 +219,8 @@ ${helpers.predefined_type(
"flex-shrink", "flex-shrink",
"NonNegativeNumber", "NonNegativeNumber",
"From::from(1.0)", "From::from(1.0)",
engines="gecko servo-2013", engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-flexbox/#flex-shrink-property", spec="https://drafts.csswg.org/css-flexbox/#flex-shrink-property",
extra_prefixes="webkit", extra_prefixes="webkit",
animation_value_type="NonNegativeNumber", animation_value_type="NonNegativeNumber",
@ -278,7 +282,8 @@ ${helpers.predefined_type(
"flex-basis", "flex-basis",
"FlexBasis", "FlexBasis",
"computed::FlexBasis::auto()", "computed::FlexBasis::auto()",
engines="gecko servo-2013", engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property",
extra_prefixes="webkit", extra_prefixes="webkit",
animation_value_type="FlexBasis", animation_value_type="FlexBasis",

View file

@ -5,7 +5,8 @@
<%namespace name="helpers" file="/helpers.mako.rs" /> <%namespace name="helpers" file="/helpers.mako.rs" />
<%helpers:shorthand name="flex-flow" <%helpers:shorthand name="flex-flow"
engines="gecko servo-2013" engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
sub_properties="flex-direction flex-wrap" sub_properties="flex-direction flex-wrap"
extra_prefixes="webkit" extra_prefixes="webkit"
derive_serialize="True" derive_serialize="True"
@ -45,7 +46,8 @@
</%helpers:shorthand> </%helpers:shorthand>
<%helpers:shorthand name="flex" <%helpers:shorthand name="flex"
engines="gecko servo-2013" engines="gecko servo-2013 servo-2020",
servo_2020_pref="layout.flexbox.enabled",
sub_properties="flex-grow flex-shrink flex-basis" sub_properties="flex-grow flex-shrink flex-basis"
extra_prefixes="webkit" extra_prefixes="webkit"
derive_serialize="True" derive_serialize="True"