mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +00:00
LibWeb: Add support for object-fit: scale-down
This commit is contained in:
parent
1b165d887b
commit
09a55e56ee
Notes:
github-actions[bot]
2024-12-16 19:48:34 +00:00
Author: https://github.com/InvalidUsernameException 🔰
Commit: 09a55e56ee
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2856
Reviewed-by: https://github.com/kalenikaliaksandr ✅
Reviewed-by: https://github.com/shlyakpavel ✅
3 changed files with 122 additions and 1 deletions
|
@ -75,11 +75,21 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
auto bitmap_aspect_ratio = (float)bitmap_rect.height() / bitmap_rect.width();
|
||||
auto image_aspect_ratio = (float)image_rect.height().value() / image_rect.width().value();
|
||||
|
||||
// FIXME: Scale may be wrong if device-pixels != css-pixels.
|
||||
auto scale_x = 0.0f;
|
||||
auto scale_y = 0.0f;
|
||||
Gfx::IntRect bitmap_intersect = bitmap_rect;
|
||||
|
||||
// https://drafts.csswg.org/css-images/#the-object-fit
|
||||
auto object_fit = m_is_svg_image ? CSS::ObjectFit::Contain : computed_values().object_fit();
|
||||
if (object_fit == CSS::ObjectFit::ScaleDown) {
|
||||
if (bitmap_rect.width() > image_int_rect.width() || bitmap_rect.height() > image_int_rect.height()) {
|
||||
object_fit = CSS::ObjectFit::Contain;
|
||||
} else {
|
||||
object_fit = CSS::ObjectFit::None;
|
||||
}
|
||||
}
|
||||
|
||||
switch (object_fit) {
|
||||
case CSS::ObjectFit::Fill:
|
||||
scale_x = (float)image_int_rect.width() / bitmap_rect.width();
|
||||
|
@ -106,7 +116,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
}
|
||||
break;
|
||||
case CSS::ObjectFit::ScaleDown:
|
||||
// FIXME: Implement
|
||||
VERIFY_NOT_REACHED(); // handled outside the switch-case
|
||||
case CSS::ObjectFit::None:
|
||||
scale_x = 1;
|
||||
scale_y = 1;
|
||||
|
@ -122,6 +132,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const
|
|||
bitmap_intersect.set_x((bitmap_rect.width() - bitmap_intersect.width()) / 2);
|
||||
bitmap_intersect.set_y((bitmap_rect.height() - bitmap_intersect.height()) / 2);
|
||||
|
||||
// https://drafts.csswg.org/css-images/#the-object-position
|
||||
auto const& object_position = computed_values().object_position();
|
||||
|
||||
auto offset_x = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue