mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Fix min/max-content of replaced boxes
This commit is contained in:
parent
8996be3c5e
commit
80b2b5fb5e
2 changed files with 51 additions and 27 deletions
|
@ -59,31 +59,30 @@ impl IndependentFormattingContext {
|
||||||
contents: Contents<impl NodeExt<'dom>>,
|
contents: Contents<impl NodeExt<'dom>>,
|
||||||
content_sizes: ContentSizesRequest,
|
content_sizes: ContentSizesRequest,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
use self::IndependentFormattingContextContents as Contents;
|
match contents.try_into() {
|
||||||
let (contents, content_sizes) = match contents.try_into() {
|
|
||||||
Ok(non_replaced) => match display_inside {
|
Ok(non_replaced) => match display_inside {
|
||||||
DisplayInside::Flow | DisplayInside::FlowRoot => {
|
DisplayInside::Flow | DisplayInside::FlowRoot => {
|
||||||
let (bfc, box_content_sizes) = BlockFormattingContext::construct(
|
let (bfc, content_sizes) = BlockFormattingContext::construct(
|
||||||
context,
|
context,
|
||||||
&style,
|
&style,
|
||||||
non_replaced,
|
non_replaced,
|
||||||
content_sizes,
|
content_sizes,
|
||||||
);
|
);
|
||||||
(Contents::Flow(bfc), box_content_sizes)
|
Self {
|
||||||
|
style,
|
||||||
|
content_sizes,
|
||||||
|
contents: IndependentFormattingContextContents::Flow(bfc),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Err(replaced) => {
|
Err(replaced) => {
|
||||||
// The `content_sizes` field is not used by layout code:
|
let content_sizes = content_sizes.compute(|| replaced.inline_content_sizes(&style));
|
||||||
(
|
Self {
|
||||||
Contents::Replaced(replaced),
|
style,
|
||||||
BoxContentSizes::NoneWereRequested,
|
content_sizes,
|
||||||
)
|
contents: IndependentFormattingContextContents::Replaced(replaced),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
|
||||||
Self {
|
|
||||||
style,
|
|
||||||
contents,
|
|
||||||
content_sizes,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::dom_traversal::NodeExt;
|
||||||
use crate::fragments::{Fragment, ImageFragment};
|
use crate::fragments::{Fragment, ImageFragment};
|
||||||
use crate::geom::flow_relative::{Rect, Vec2};
|
use crate::geom::flow_relative::{Rect, Vec2};
|
||||||
use crate::geom::physical;
|
use crate::geom::physical;
|
||||||
|
use crate::sizing::ContentSizes;
|
||||||
use crate::style_ext::ComputedValuesExt;
|
use crate::style_ext::ComputedValuesExt;
|
||||||
use crate::ContainingBlock;
|
use crate::ContainingBlock;
|
||||||
use net_traits::image::base::Image;
|
use net_traits::image::base::Image;
|
||||||
|
@ -63,6 +64,41 @@ impl ReplacedContent {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn flow_relative_intrinsic_size(&self, style: &ComputedValues) -> Vec2<Option<Length>> {
|
||||||
|
let intrinsic_size = physical::Vec2 {
|
||||||
|
x: self.intrinsic_width,
|
||||||
|
y: self.intrinsic_height,
|
||||||
|
};
|
||||||
|
intrinsic_size.size_to_flow_relative(style.writing_mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inline_size_over_block_size_intrinsic_ratio(
|
||||||
|
&self,
|
||||||
|
style: &ComputedValues,
|
||||||
|
) -> Option<CSSFloat> {
|
||||||
|
self.intrinsic_ratio.map(|width_over_height| {
|
||||||
|
if style.writing_mode.is_vertical() {
|
||||||
|
1. / width_over_height
|
||||||
|
} else {
|
||||||
|
width_over_height
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn inline_content_sizes(&self, style: &ComputedValues) -> ContentSizes {
|
||||||
|
// FIXME: min/max-content of replaced elements is not defined in
|
||||||
|
// https://dbaron.org/css/intrinsic/
|
||||||
|
// This seems sensible?
|
||||||
|
let inline = self
|
||||||
|
.flow_relative_intrinsic_size(style)
|
||||||
|
.inline
|
||||||
|
.unwrap_or(Length::zero());
|
||||||
|
ContentSizes {
|
||||||
|
min_content: inline,
|
||||||
|
max_content: inline,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn make_fragments<'a>(
|
pub fn make_fragments<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
style: &ServoArc<ComputedValues>,
|
style: &ServoArc<ComputedValues>,
|
||||||
|
@ -95,19 +131,8 @@ impl ReplacedContent {
|
||||||
style: &ComputedValues,
|
style: &ComputedValues,
|
||||||
) -> Vec2<Length> {
|
) -> Vec2<Length> {
|
||||||
let mode = style.writing_mode;
|
let mode = style.writing_mode;
|
||||||
let intrinsic_size = physical::Vec2 {
|
let intrinsic_size = self.flow_relative_intrinsic_size(style);
|
||||||
x: self.intrinsic_width,
|
let intrinsic_ratio = self.inline_size_over_block_size_intrinsic_ratio(style);
|
||||||
y: self.intrinsic_height,
|
|
||||||
};
|
|
||||||
let intrinsic_size = intrinsic_size.size_to_flow_relative(mode);
|
|
||||||
let intrinsic_ratio = self.intrinsic_ratio.map(|width_over_height| {
|
|
||||||
// inline-size over block-size
|
|
||||||
if style.writing_mode.is_vertical() {
|
|
||||||
1. / width_over_height
|
|
||||||
} else {
|
|
||||||
width_over_height
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let box_size = style.box_size().percentages_relative_to(containing_block);
|
let box_size = style.box_size().percentages_relative_to(containing_block);
|
||||||
let min_box_size = style
|
let min_box_size = style
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue