mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Use natural ratio for object-fit
(#34413)
We were using the preferred aspect ratio provided by the `aspect-ratio` property instead of the natural aspect ratio. However, the preferred aspect ratio should only be used to size the replaced element. To paint the replaced contents into that element we need the natural ratio. Signed-off-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
895b8d30ea
commit
a37ccc3e64
8 changed files with 10 additions and 32 deletions
|
@ -305,32 +305,22 @@ impl ReplacedContent {
|
|||
pub fn make_fragments(
|
||||
&self,
|
||||
style: &ServoArc<ComputedValues>,
|
||||
containing_block: &ContainingBlock,
|
||||
size: PhysicalSize<Au>,
|
||||
) -> Vec<Fragment> {
|
||||
let aspect_ratio = self.preferred_aspect_ratio(&containing_block.into(), style);
|
||||
let natural_size = PhysicalSize::new(
|
||||
self.natural_size.width.unwrap_or(size.width),
|
||||
self.natural_size.height.unwrap_or(size.height),
|
||||
);
|
||||
|
||||
let object_fit_size = aspect_ratio.map_or(size, |aspect_ratio| {
|
||||
let object_fit_size = self.natural_size.ratio.map_or(size, |width_over_height| {
|
||||
let preserve_aspect_ratio_with_comparison =
|
||||
|size: PhysicalSize<Au>, comparison: fn(&Au, &Au) -> bool| {
|
||||
let (width_axis, height_axis) = if style.writing_mode.is_horizontal() {
|
||||
(Direction::Inline, Direction::Block)
|
||||
} else {
|
||||
(Direction::Block, Direction::Inline)
|
||||
};
|
||||
|
||||
let candidate_width =
|
||||
aspect_ratio.compute_dependent_size(width_axis, size.height);
|
||||
let candidate_width = size.height.scale_by(width_over_height);
|
||||
if comparison(&candidate_width, &size.width) {
|
||||
return PhysicalSize::new(candidate_width, size.height);
|
||||
}
|
||||
|
||||
let candidate_height =
|
||||
aspect_ratio.compute_dependent_size(height_axis, size.width);
|
||||
let candidate_height = size.width.scale_by(1. / width_over_height);
|
||||
debug_assert!(comparison(&candidate_height, &size.height));
|
||||
PhysicalSize::new(size.width, candidate_height)
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue