mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Rename ReplacedContent::layout to make_fragments and simplify its API
This commit is contained in:
parent
b8db9459bc
commit
34e8cda801
4 changed files with 57 additions and 85 deletions
|
@ -17,7 +17,7 @@ use app_units::Au;
|
||||||
use gfx::text::text_run::GlyphRun;
|
use gfx::text::text_run::GlyphRun;
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
use style::values::computed::{Length, LengthOrAuto, Percentage};
|
use style::values::computed::{Length, Percentage};
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
use webrender_api::FontInstanceKey;
|
use webrender_api::FontInstanceKey;
|
||||||
|
|
||||||
|
@ -418,29 +418,13 @@ fn layout_atomic<'box_tree>(
|
||||||
let fragment = match atomic.as_replaced() {
|
let fragment = match atomic.as_replaced() {
|
||||||
Ok(replaced) => {
|
Ok(replaced) => {
|
||||||
// FIXME: implement https://drafts.csswg.org/css2/visudet.html#inline-replaced-width
|
// FIXME: implement https://drafts.csswg.org/css2/visudet.html#inline-replaced-width
|
||||||
let inline_size = Length::zero();
|
// and https://drafts.csswg.org/css2/visudet.html#inline-replaced-height
|
||||||
let block_size = Length::zero();
|
let size = Vec2::zero();
|
||||||
let containing_block_for_children = ContainingBlock {
|
let fragments = replaced.make_fragments(&atomic.style, size.clone());
|
||||||
inline_size,
|
let content_rect = Rect { start_corner, size };
|
||||||
block_size: LengthOrAuto::LengthPercentage(block_size),
|
|
||||||
mode: atomic.style.writing_mode(),
|
|
||||||
};
|
|
||||||
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
|
|
||||||
assert_eq!(
|
|
||||||
ifc.containing_block.mode, containing_block_for_children.mode,
|
|
||||||
"Mixed writing modes are not supported yet"
|
|
||||||
);
|
|
||||||
let independent_layout = replaced.layout(&atomic.style, &containing_block_for_children);
|
|
||||||
let content_rect = Rect {
|
|
||||||
start_corner,
|
|
||||||
size: Vec2 {
|
|
||||||
block: independent_layout.content_block_size,
|
|
||||||
inline: inline_size,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
BoxFragment {
|
BoxFragment {
|
||||||
style: atomic.style.clone(),
|
style: atomic.style.clone(),
|
||||||
children: independent_layout.fragments,
|
children: fragments,
|
||||||
content_rect,
|
content_rect,
|
||||||
padding,
|
padding,
|
||||||
border,
|
border,
|
||||||
|
|
|
@ -516,17 +516,11 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
block_start: computed_margin.block_start.auto_is(Length::zero),
|
block_start: computed_margin.block_start.auto_is(Length::zero),
|
||||||
block_end: computed_margin.block_end.auto_is(Length::zero),
|
block_end: computed_margin.block_end.auto_is(Length::zero),
|
||||||
};
|
};
|
||||||
let containing_block_for_children = ContainingBlock {
|
let size = Vec2 {
|
||||||
inline_size,
|
block: block_size,
|
||||||
block_size: LengthOrAuto::LengthPercentage(block_size),
|
inline: inline_size,
|
||||||
mode,
|
|
||||||
};
|
};
|
||||||
// https://drafts.csswg.org/css-writing-modes/#orthogonal-flows
|
let fragments = replaced.make_fragments(style, size.clone());
|
||||||
assert_eq!(
|
|
||||||
containing_block.mode, containing_block_for_children.mode,
|
|
||||||
"Mixed writing modes are not supported yet"
|
|
||||||
);
|
|
||||||
let independent_layout = replaced.layout(style, &containing_block_for_children);
|
|
||||||
let relative_adjustement = relative_adjustement(
|
let relative_adjustement = relative_adjustement(
|
||||||
style,
|
style,
|
||||||
inline_size,
|
inline_size,
|
||||||
|
@ -537,14 +531,11 @@ fn layout_in_flow_replaced_block_level<'a>(
|
||||||
block: pb.block_start + relative_adjustement.block,
|
block: pb.block_start + relative_adjustement.block,
|
||||||
inline: pb.inline_start + relative_adjustement.inline + margin.inline_start,
|
inline: pb.inline_start + relative_adjustement.inline + margin.inline_start,
|
||||||
},
|
},
|
||||||
size: Vec2 {
|
size,
|
||||||
block: block_size,
|
|
||||||
inline: inline_size,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
BoxFragment {
|
BoxFragment {
|
||||||
style: style.clone(),
|
style: style.clone(),
|
||||||
children: independent_layout.fragments,
|
children: fragments,
|
||||||
content_rect,
|
content_rect,
|
||||||
padding,
|
padding,
|
||||||
border,
|
border,
|
||||||
|
|
|
@ -302,6 +302,25 @@ impl<'a> AbsolutelyPositionedFragment<'a> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut absolutely_positioned_fragments = Vec::new();
|
||||||
|
let mut independent_layout = match self.absolutely_positioned_box.contents.as_replaced() {
|
||||||
|
Ok(replaced) => {
|
||||||
|
// FIXME: implement https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
|
||||||
|
// and https://drafts.csswg.org/css2/visudet.html#abs-replaced-height
|
||||||
|
let block_size = block_size.auto_is(|| Length::zero());
|
||||||
|
let fragments = replaced.make_fragments(
|
||||||
|
&self.absolutely_positioned_box.contents.style,
|
||||||
|
Vec2 {
|
||||||
|
inline: inline_size,
|
||||||
|
block: block_size,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
crate::formatting_contexts::IndependentLayout {
|
||||||
|
fragments,
|
||||||
|
content_block_size: block_size,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(non_replaced) => {
|
||||||
let containing_block_for_children = ContainingBlock {
|
let containing_block_for_children = ContainingBlock {
|
||||||
inline_size,
|
inline_size,
|
||||||
block_size,
|
block_size,
|
||||||
|
@ -312,14 +331,6 @@ impl<'a> AbsolutelyPositionedFragment<'a> {
|
||||||
containing_block.mode, containing_block_for_children.mode,
|
containing_block.mode, containing_block_for_children.mode,
|
||||||
"Mixed writing modes are not supported yet"
|
"Mixed writing modes are not supported yet"
|
||||||
);
|
);
|
||||||
let mut absolutely_positioned_fragments = Vec::new();
|
|
||||||
let mut independent_layout = match self.absolutely_positioned_box.contents.as_replaced() {
|
|
||||||
// FIXME: implement https://drafts.csswg.org/css2/visudet.html#abs-replaced-width
|
|
||||||
Ok(replaced) => replaced.layout(
|
|
||||||
&self.absolutely_positioned_box.contents.style,
|
|
||||||
&containing_block_for_children,
|
|
||||||
),
|
|
||||||
Err(non_replaced) => {
|
|
||||||
let dummy_tree_rank = 0;
|
let dummy_tree_rank = 0;
|
||||||
non_replaced.layout(
|
non_replaced.layout(
|
||||||
layout_context,
|
layout_context,
|
||||||
|
@ -358,7 +369,7 @@ impl<'a> AbsolutelyPositionedFragment<'a> {
|
||||||
&mut independent_layout.fragments,
|
&mut independent_layout.fragments,
|
||||||
&content_rect.size,
|
&content_rect.size,
|
||||||
&padding,
|
&padding,
|
||||||
containing_block_for_children.mode,
|
style.writing_mode(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Fragment::Box(BoxFragment {
|
Fragment::Box(BoxFragment {
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
* 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 crate::dom_traversal::NodeExt;
|
use crate::dom_traversal::NodeExt;
|
||||||
use crate::formatting_contexts::IndependentLayout;
|
|
||||||
use crate::fragments::{Fragment, ImageFragment};
|
use crate::fragments::{Fragment, ImageFragment};
|
||||||
use crate::geom::{flow_relative, physical};
|
use crate::geom::{flow_relative, physical};
|
||||||
use crate::ContainingBlock;
|
|
||||||
use net_traits::image::base::Image;
|
use net_traits::image::base::Image;
|
||||||
use servo_arc::Arc as ServoArc;
|
use servo_arc::Arc as ServoArc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -35,16 +33,13 @@ impl ReplacedContent {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout<'a>(
|
pub fn make_fragments<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
style: &ServoArc<ComputedValues>,
|
style: &ServoArc<ComputedValues>,
|
||||||
containing_block: &ContainingBlock,
|
size: flow_relative::Vec2<Length>,
|
||||||
) -> IndependentLayout {
|
) -> Vec<Fragment> {
|
||||||
let (fragments, content_block_size) = match self.kind {
|
match &self.kind {
|
||||||
ReplacedContentKind::Image(ref image) => {
|
ReplacedContentKind::Image(image) => image
|
||||||
// FIXME(nox): We should not assume block size is known.
|
|
||||||
let block_size = containing_block.block_size.non_auto().unwrap();
|
|
||||||
let fragments = image
|
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|image| image.id)
|
.and_then(|image| image.id)
|
||||||
.map(|image_key| {
|
.map(|image_key| {
|
||||||
|
@ -52,22 +47,13 @@ impl ReplacedContent {
|
||||||
style: style.clone(),
|
style: style.clone(),
|
||||||
content_rect: flow_relative::Rect {
|
content_rect: flow_relative::Rect {
|
||||||
start_corner: flow_relative::Vec2::zero(),
|
start_corner: flow_relative::Vec2::zero(),
|
||||||
size: flow_relative::Vec2 {
|
size,
|
||||||
inline: containing_block.inline_size,
|
|
||||||
block: block_size,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
image_key,
|
image_key,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<Vec<_>>();
|
.collect(),
|
||||||
(fragments, block_size)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
IndependentLayout {
|
|
||||||
fragments,
|
|
||||||
content_block_size,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue