mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 13:57:35 +00:00
LibWeb: Add AbstractImageStyleValue::natural_aspect_ratio()
This commit is contained in:
parent
bbceb155ce
commit
d2c96e213f
3 changed files with 17 additions and 0 deletions
|
@ -23,6 +23,15 @@ public:
|
||||||
virtual Optional<CSSPixels> natural_width() const { return {}; }
|
virtual Optional<CSSPixels> natural_width() const { return {}; }
|
||||||
virtual Optional<CSSPixels> natural_height() const { return {}; }
|
virtual Optional<CSSPixels> natural_height() const { return {}; }
|
||||||
|
|
||||||
|
virtual Optional<CSSPixelFraction> natural_aspect_ratio() const
|
||||||
|
{
|
||||||
|
auto width = natural_width();
|
||||||
|
auto height = natural_height();
|
||||||
|
if (width.has_value() && height.has_value())
|
||||||
|
return *width / *height;
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
virtual void load_any_resources(DOM::Document&) {};
|
virtual void load_any_resources(DOM::Document&) {};
|
||||||
virtual void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const {};
|
virtual void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const {};
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,13 @@ Optional<CSSPixels> ImageStyleValue::natural_height() const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<CSSPixelFraction> ImageStyleValue::natural_aspect_ratio() const
|
||||||
|
{
|
||||||
|
if (auto image_data = this->image_data())
|
||||||
|
return image_data->intrinsic_aspect_ratio();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void ImageStyleValue::paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const
|
void ImageStyleValue::paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const
|
||||||
{
|
{
|
||||||
if (auto const* b = bitmap(m_current_frame_index, dest_rect.size().to_type<int>()); b != nullptr) {
|
if (auto const* b = bitmap(m_current_frame_index, dest_rect.size().to_type<int>()); b != nullptr) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
|
|
||||||
Optional<CSSPixels> natural_width() const override;
|
Optional<CSSPixels> natural_width() const override;
|
||||||
Optional<CSSPixels> natural_height() const override;
|
Optional<CSSPixels> natural_height() const override;
|
||||||
|
Optional<CSSPixelFraction> natural_aspect_ratio() const override;
|
||||||
|
|
||||||
virtual bool is_paintable() const override;
|
virtual bool is_paintable() const override;
|
||||||
void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
|
void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue