mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Properly handle fallback aspect ratio for videos (#34082)
A `<video>` element with no source won't have a natural aspect ratio, but `aspect-ratio: auto` should still fall back to a ratio of 300/150. `used_size_as_if_inline_element_from_content_box_sizes()` was already handling this, but other consumers of `preferred_aspect_ratio()` were wrong. In particular, this resulted in a 0px wide inline-block: ```html <div style="display: inline-block; border: solid"> <video style="height: 100px; background: cyan"></video> </div> ``` So this patch moves the fallback into `preferred_aspect_ratio()`. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
31566aef02
commit
851b125d4b
4 changed files with 70 additions and 15 deletions
|
@ -415,11 +415,20 @@ impl ReplacedContent {
|
|||
containing_block: &IndefiniteContainingBlock,
|
||||
style: &ComputedValues,
|
||||
) -> Option<AspectRatio> {
|
||||
style.preferred_aspect_ratio(
|
||||
self.inline_size_over_block_size_intrinsic_ratio(style),
|
||||
containing_block.try_into().ok().as_ref(),
|
||||
containing_block.style.writing_mode,
|
||||
)
|
||||
style
|
||||
.preferred_aspect_ratio(
|
||||
self.inline_size_over_block_size_intrinsic_ratio(style),
|
||||
containing_block.try_into().ok().as_ref(),
|
||||
containing_block.style.writing_mode,
|
||||
)
|
||||
.or_else(|| {
|
||||
matches!(self.kind, ReplacedContentKind::Video(_)).then(|| {
|
||||
let size = Self::default_object_size();
|
||||
AspectRatio::from_content_ratio(
|
||||
size.width.to_f32_px() / size.height.to_f32_px(),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css2/visudet.html#inline-replaced-width>
|
||||
|
@ -475,16 +484,7 @@ impl ReplacedContent {
|
|||
) -> LogicalVec2<Au> {
|
||||
let mode = style.writing_mode;
|
||||
let intrinsic_size = self.flow_relative_intrinsic_size(style);
|
||||
let intrinsic_ratio = self
|
||||
.preferred_aspect_ratio(&containing_block.into(), style)
|
||||
.or_else(|| {
|
||||
matches!(self.kind, ReplacedContentKind::Video(_)).then(|| {
|
||||
let size = Self::default_object_size();
|
||||
AspectRatio::from_content_ratio(
|
||||
size.width.to_f32_px() / size.height.to_f32_px(),
|
||||
)
|
||||
})
|
||||
});
|
||||
let intrinsic_ratio = self.preferred_aspect_ratio(&containing_block.into(), style);
|
||||
|
||||
let default_object_size =
|
||||
|| LogicalVec2::from_physical_size(&Self::default_object_size(), mode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue