mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Flex items in the box tree
This commit is contained in:
parent
64124f7a5e
commit
ec548e849c
3 changed files with 121 additions and 25 deletions
|
@ -2,21 +2,33 @@
|
|||
* 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::context::LayoutContext;
|
||||
use crate::dom_traversal::{NodeExt, NonReplacedContents};
|
||||
use crate::formatting_contexts::IndependentLayout;
|
||||
use crate::positioned::PositioningContext;
|
||||
use crate::sizing::{BoxContentSizes, ContentSizesRequest};
|
||||
use crate::dom_traversal::{BoxSlot, Contents, NodeExt, NonReplacedContents, TraversalHandler};
|
||||
use crate::element_data::LayoutBox;
|
||||
use crate::formatting_contexts::{IndependentFormattingContext, IndependentLayout};
|
||||
use crate::positioned::{AbsolutelyPositionedBox, PositioningContext};
|
||||
use crate::sizing::{BoxContentSizes, ContentSizes, ContentSizesRequest};
|
||||
use crate::style_ext::DisplayGeneratingBox;
|
||||
use crate::ContainingBlock;
|
||||
use servo_arc::Arc;
|
||||
use std::borrow::Cow;
|
||||
use style::properties::ComputedValues;
|
||||
use style::values::computed::Length;
|
||||
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 {
|
||||
unimplemented_fallback: crate::flow::BlockFormattingContext,
|
||||
children: Vec<ArcRefCell<FlexLevelBox>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub(crate) enum FlexLevelBox {
|
||||
FlexItem(IndependentFormattingContext),
|
||||
OutOfFlowAbsolutelyPositionedBox(Arc<AbsolutelyPositionedBox>),
|
||||
}
|
||||
|
||||
impl FlexContainer {
|
||||
|
@ -28,23 +40,86 @@ impl FlexContainer {
|
|||
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,
|
||||
let text_decoration_line =
|
||||
propagated_text_decoration_line | style.clone_text_decoration_line();
|
||||
let mut builder = FlexContainerBuilder {
|
||||
context,
|
||||
text_decoration_line,
|
||||
flex_container: Self {
|
||||
children: Vec::new(),
|
||||
},
|
||||
content_sizes,
|
||||
)
|
||||
};
|
||||
contents.traverse(context, node, style, &mut builder);
|
||||
let content_sizes = content_sizes.compute(|| {
|
||||
// FIXME
|
||||
ContentSizes::zero()
|
||||
});
|
||||
(builder.flex_container, content_sizes)
|
||||
}
|
||||
}
|
||||
|
||||
struct FlexContainerBuilder<'context> {
|
||||
context: &'context LayoutContext<'context>,
|
||||
text_decoration_line: TextDecorationLine,
|
||||
flex_container: FlexContainer,
|
||||
}
|
||||
|
||||
impl<'context, 'dom, Node: 'dom> TraversalHandler<'dom, Node> for FlexContainerBuilder<'context>
|
||||
where
|
||||
Node: NodeExt<'dom>,
|
||||
{
|
||||
fn handle_text(
|
||||
&mut self,
|
||||
node: Node,
|
||||
text: Cow<'dom, str>,
|
||||
parent_style: &Arc<ComputedValues>,
|
||||
) {
|
||||
// FIXME
|
||||
let _ = node;
|
||||
let _ = text;
|
||||
let _ = parent_style;
|
||||
}
|
||||
|
||||
/// Or pseudo-element
|
||||
fn handle_element(
|
||||
&mut self,
|
||||
node: Node,
|
||||
style: &Arc<ComputedValues>,
|
||||
display: DisplayGeneratingBox,
|
||||
contents: Contents,
|
||||
box_slot: BoxSlot<'dom>,
|
||||
) {
|
||||
let display_inside = match display {
|
||||
DisplayGeneratingBox::OutsideInside { inside, .. } => inside,
|
||||
};
|
||||
let box_ = if style.get_box().position.is_absolutely_positioned() {
|
||||
// https://drafts.csswg.org/css-flexbox/#abspos-items
|
||||
ArcRefCell::new(FlexLevelBox::OutOfFlowAbsolutelyPositionedBox(Arc::new(
|
||||
AbsolutelyPositionedBox::construct(
|
||||
self.context,
|
||||
node,
|
||||
style.clone(),
|
||||
display_inside,
|
||||
contents,
|
||||
),
|
||||
)))
|
||||
} else {
|
||||
ArcRefCell::new(FlexLevelBox::FlexItem(IndependentFormattingContext::construct(
|
||||
self.context,
|
||||
node,
|
||||
style.clone(),
|
||||
display_inside,
|
||||
contents,
|
||||
ContentSizesRequest::None, // FIXME: request sizes when we start using them
|
||||
self.text_decoration_line,
|
||||
)))
|
||||
};
|
||||
self.flex_container.children.push(box_.clone());
|
||||
box_slot.set(LayoutBox::FlexLevel(box_))
|
||||
}
|
||||
}
|
||||
|
||||
impl FlexContainer {
|
||||
pub(crate) fn layout(
|
||||
&self,
|
||||
layout_context: &LayoutContext,
|
||||
|
@ -52,11 +127,14 @@ impl FlexContainer {
|
|||
containing_block: &ContainingBlock,
|
||||
tree_rank: usize,
|
||||
) -> IndependentLayout {
|
||||
self.unimplemented_fallback.layout(
|
||||
layout_context,
|
||||
positioning_context,
|
||||
containing_block,
|
||||
tree_rank,
|
||||
)
|
||||
// FIXME
|
||||
let _ = layout_context;
|
||||
let _ = positioning_context;
|
||||
let _ = containing_block;
|
||||
let _ = tree_rank;
|
||||
IndependentLayout {
|
||||
fragments: Vec::new(),
|
||||
content_block_size: Length::zero(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue