mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Layout 2020 skeleton for display: flex
, behind a pref
This commit is contained in:
parent
d4f1f4641d
commit
64124f7a5e
8 changed files with 114 additions and 18 deletions
62
components/layout_2020/flexbox.rs
Normal file
62
components/layout_2020/flexbox.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* 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::context::LayoutContext;
|
||||
use crate::dom_traversal::{NodeExt, NonReplacedContents};
|
||||
use crate::formatting_contexts::IndependentLayout;
|
||||
use crate::positioned::PositioningContext;
|
||||
use crate::sizing::{BoxContentSizes, ContentSizesRequest};
|
||||
use crate::ContainingBlock;
|
||||
use servo_arc::Arc;
|
||||
use style::properties::ComputedValues;
|
||||
use style::values::specified::text::TextDecorationLine;
|
||||
|
||||
// FIXME: `min-width: auto` is not zero: https://drafts.csswg.org/css-flexbox/#min-size-auto
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) struct FlexContainer {
|
||||
unimplemented_fallback: crate::flow::BlockFormattingContext,
|
||||
}
|
||||
|
||||
impl FlexContainer {
|
||||
pub fn construct<'dom>(
|
||||
context: &LayoutContext,
|
||||
node: impl NodeExt<'dom>,
|
||||
style: &Arc<ComputedValues>,
|
||||
contents: NonReplacedContents,
|
||||
content_sizes: ContentSizesRequest,
|
||||
propagated_text_decoration_line: TextDecorationLine,
|
||||
) -> (Self, BoxContentSizes) {
|
||||
let (unimplemented_fallback, content_sizes) =
|
||||
crate::flow::BlockFormattingContext::construct(
|
||||
context,
|
||||
node,
|
||||
style,
|
||||
contents,
|
||||
content_sizes,
|
||||
propagated_text_decoration_line,
|
||||
);
|
||||
(
|
||||
Self {
|
||||
unimplemented_fallback,
|
||||
},
|
||||
content_sizes,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn layout(
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
positioning_context: &mut PositioningContext,
|
||||
containing_block: &ContainingBlock,
|
||||
tree_rank: usize,
|
||||
) -> IndependentLayout {
|
||||
self.unimplemented_fallback.layout(
|
||||
layout_context,
|
||||
positioning_context,
|
||||
containing_block,
|
||||
tree_rank,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use crate::context::LayoutContext;
|
||||
use crate::dom_traversal::{Contents, NodeExt};
|
||||
use crate::flexbox::FlexContainer;
|
||||
use crate::flow::BlockFormattingContext;
|
||||
use crate::fragments::Fragment;
|
||||
use crate::positioned::PositioningContext;
|
||||
|
@ -43,6 +44,7 @@ pub(crate) struct IndependentLayout {
|
|||
#[derive(Debug, Serialize)]
|
||||
enum IndependentFormattingContextContents {
|
||||
Flow(BlockFormattingContext),
|
||||
Flex(FlexContainer),
|
||||
|
||||
// Not called FC in specs, but behaves close enough
|
||||
Replaced(ReplacedContent),
|
||||
|
@ -53,6 +55,7 @@ pub(crate) struct NonReplacedIFC<'a>(NonReplacedIFCKind<'a>);
|
|||
|
||||
enum NonReplacedIFCKind<'a> {
|
||||
Flow(&'a BlockFormattingContext),
|
||||
Flex(&'a FlexContainer),
|
||||
}
|
||||
|
||||
impl IndependentFormattingContext {
|
||||
|
@ -83,6 +86,22 @@ impl IndependentFormattingContext {
|
|||
contents: IndependentFormattingContextContents::Flow(bfc),
|
||||
}
|
||||
},
|
||||
DisplayInside::Flex => {
|
||||
let (fc, content_sizes) = FlexContainer::construct(
|
||||
context,
|
||||
node,
|
||||
&style,
|
||||
non_replaced,
|
||||
content_sizes,
|
||||
propagated_text_decoration_line,
|
||||
);
|
||||
Self {
|
||||
tag: node.as_opaque(),
|
||||
style,
|
||||
content_sizes,
|
||||
contents: IndependentFormattingContextContents::Flex(fc),
|
||||
}
|
||||
},
|
||||
},
|
||||
Err(replaced) => {
|
||||
let content_sizes = content_sizes.compute(|| replaced.inline_content_sizes(&style));
|
||||
|
@ -103,6 +122,7 @@ impl IndependentFormattingContext {
|
|||
match &self.contents {
|
||||
Contents::Replaced(r) => Ok(r),
|
||||
Contents::Flow(f) => Err(NR(Kind::Flow(f))),
|
||||
Contents::Flex(f) => Err(NR(Kind::Flex(f))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +142,12 @@ impl NonReplacedIFC<'_> {
|
|||
containing_block,
|
||||
tree_rank,
|
||||
),
|
||||
NonReplacedIFCKind::Flex(fc) => fc.layout(
|
||||
layout_context,
|
||||
positioning_context,
|
||||
containing_block,
|
||||
tree_rank,
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ pub mod data;
|
|||
pub mod display_list;
|
||||
mod dom_traversal;
|
||||
pub mod element_data;
|
||||
mod flexbox;
|
||||
mod flow;
|
||||
mod formatting_contexts;
|
||||
mod fragments;
|
||||
|
|
|
@ -48,6 +48,7 @@ pub(crate) enum DisplayOutside {
|
|||
pub(crate) enum DisplayInside {
|
||||
Flow,
|
||||
FlowRoot,
|
||||
Flex,
|
||||
}
|
||||
|
||||
/// Percentages resolved but not `auto` margins
|
||||
|
@ -394,6 +395,7 @@ impl From<stylo::Display> for Display {
|
|||
let inside = match packed.inside() {
|
||||
stylo::DisplayInside::Flow => DisplayInside::Flow,
|
||||
stylo::DisplayInside::FlowRoot => DisplayInside::FlowRoot,
|
||||
stylo::DisplayInside::Flex => DisplayInside::Flex,
|
||||
|
||||
// These should not be values of DisplayInside, but oh well
|
||||
stylo::DisplayInside::None => return Display::None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue