Rename ReplacedContent::layout to make_fragments and simplify its API

This commit is contained in:
Simon Sapin 2019-12-03 15:09:03 +01:00
parent b8db9459bc
commit 34e8cda801
4 changed files with 57 additions and 85 deletions

View file

@ -3,10 +3,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom_traversal::NodeExt;
use crate::formatting_contexts::IndependentLayout;
use crate::fragments::{Fragment, ImageFragment};
use crate::geom::{flow_relative, physical};
use crate::ContainingBlock;
use net_traits::image::base::Image;
use servo_arc::Arc as ServoArc;
use std::sync::Arc;
@ -35,39 +33,27 @@ impl ReplacedContent {
None
}
pub fn layout<'a>(
pub fn make_fragments<'a>(
&'a self,
style: &ServoArc<ComputedValues>,
containing_block: &ContainingBlock,
) -> IndependentLayout {
let (fragments, content_block_size) = match self.kind {
ReplacedContentKind::Image(ref 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()
.and_then(|image| image.id)
.map(|image_key| {
Fragment::Image(ImageFragment {
style: style.clone(),
content_rect: flow_relative::Rect {
start_corner: flow_relative::Vec2::zero(),
size: flow_relative::Vec2 {
inline: containing_block.inline_size,
block: block_size,
},
},
image_key,
})
size: flow_relative::Vec2<Length>,
) -> Vec<Fragment> {
match &self.kind {
ReplacedContentKind::Image(image) => image
.as_ref()
.and_then(|image| image.id)
.map(|image_key| {
Fragment::Image(ImageFragment {
style: style.clone(),
content_rect: flow_relative::Rect {
start_corner: flow_relative::Vec2::zero(),
size,
},
image_key,
})
.into_iter()
.collect::<Vec<_>>();
(fragments, block_size)
},
};
IndependentLayout {
fragments,
content_block_size,
})
.into_iter()
.collect(),
}
}
}