mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:48:10 +00:00
LibWeb: Implement HTMLImageElement.width and HTMLImageElement.height
This commit is contained in:
parent
b023308f5c
commit
17f34488f6
3 changed files with 55 additions and 0 deletions
|
@ -78,4 +78,50 @@ const Gfx::Bitmap* HTMLImageElement::bitmap() const
|
||||||
return m_image_loader.bitmap(m_image_loader.current_frame_index());
|
return m_image_loader.bitmap(m_image_loader.current_frame_index());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-width
|
||||||
|
unsigned HTMLImageElement::width() const
|
||||||
|
{
|
||||||
|
const_cast<DOM::Document&>(document()).update_layout();
|
||||||
|
|
||||||
|
// Return the rendered width of the image, in CSS pixels, if the image is being rendered.
|
||||||
|
if (layout_node() && is<Layout::Box>(*layout_node()))
|
||||||
|
return static_cast<Layout::Box const&>(*layout_node()).content_width();
|
||||||
|
|
||||||
|
// ...or else the density-corrected intrinsic width and height of the image, in CSS pixels,
|
||||||
|
// if the image has intrinsic dimensions and is available but not being rendered.
|
||||||
|
if (m_image_loader.has_image())
|
||||||
|
return m_image_loader.width();
|
||||||
|
|
||||||
|
// ...or else 0, if the image is not available or does not have intrinsic dimensions.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLImageElement::set_width(unsigned width)
|
||||||
|
{
|
||||||
|
set_attribute(HTML::AttributeNames::width, String::number(width));
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-height
|
||||||
|
unsigned HTMLImageElement::height() const
|
||||||
|
{
|
||||||
|
const_cast<DOM::Document&>(document()).update_layout();
|
||||||
|
|
||||||
|
// Return the rendered height of the image, in CSS pixels, if the image is being rendered.
|
||||||
|
if (layout_node() && is<Layout::Box>(*layout_node()))
|
||||||
|
return static_cast<Layout::Box const&>(*layout_node()).content_height();
|
||||||
|
|
||||||
|
// ...or else the density-corrected intrinsic height and height of the image, in CSS pixels,
|
||||||
|
// if the image has intrinsic dimensions and is available but not being rendered.
|
||||||
|
if (m_image_loader.has_image())
|
||||||
|
return m_image_loader.height();
|
||||||
|
|
||||||
|
// ...or else 0, if the image is not available or does not have intrinsic dimensions.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLImageElement::set_height(unsigned height)
|
||||||
|
{
|
||||||
|
set_attribute(HTML::AttributeNames::height, String::number(height));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,12 @@ public:
|
||||||
|
|
||||||
const Gfx::Bitmap* bitmap() const;
|
const Gfx::Bitmap* bitmap() const;
|
||||||
|
|
||||||
|
unsigned width() const;
|
||||||
|
void set_width(unsigned);
|
||||||
|
|
||||||
|
unsigned height() const;
|
||||||
|
void set_height(unsigned);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,7 @@ interface HTMLImageElement : HTMLElement {
|
||||||
[Reflect] attribute DOMString align;
|
[Reflect] attribute DOMString align;
|
||||||
[LegacyNullToEmptyString, Reflect] attribute DOMString border;
|
[LegacyNullToEmptyString, Reflect] attribute DOMString border;
|
||||||
|
|
||||||
|
[CEReactions] attribute unsigned long width;
|
||||||
|
[CEReactions] attribute unsigned long height;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue