mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +00:00
LibHTML: Support width/height attributes on images
This commit is contained in:
parent
088237a25f
commit
b240500107
3 changed files with 34 additions and 3 deletions
|
@ -29,6 +29,32 @@ void HTMLImageElement::load_image(const String& src)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int HTMLImageElement::preferred_width() const
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
int width = attribute("width").to_int(ok);
|
||||||
|
if (ok)
|
||||||
|
return width;
|
||||||
|
|
||||||
|
if (m_bitmap)
|
||||||
|
return m_bitmap->width();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int HTMLImageElement::preferred_height() const
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
int height = attribute("height").to_int(ok);
|
||||||
|
if (ok)
|
||||||
|
return height;
|
||||||
|
|
||||||
|
if (m_bitmap)
|
||||||
|
return m_bitmap->height();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
|
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
|
||||||
{
|
{
|
||||||
auto style = resolver.resolve_style(*this, parent_style);
|
auto style = resolver.resolve_style(*this, parent_style);
|
||||||
|
|
|
@ -12,6 +12,8 @@ public:
|
||||||
|
|
||||||
String alt() const { return attribute("alt"); }
|
String alt() const { return attribute("alt"); }
|
||||||
String src() const { return attribute("src"); }
|
String src() const { return attribute("src"); }
|
||||||
|
int preferred_width() const;
|
||||||
|
int preferred_height() const;
|
||||||
|
|
||||||
const GraphicsBitmap* bitmap() const;
|
const GraphicsBitmap* bitmap() const;
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,10 @@ LayoutImage::~LayoutImage()
|
||||||
|
|
||||||
void LayoutImage::layout()
|
void LayoutImage::layout()
|
||||||
{
|
{
|
||||||
if (renders_as_alt_text()) {
|
if (node().preferred_width() && node().preferred_height()) {
|
||||||
|
rect().set_width(node().preferred_width());
|
||||||
|
rect().set_height(node().preferred_height());
|
||||||
|
} else if (renders_as_alt_text()) {
|
||||||
auto& font = Font::default_font();
|
auto& font = Font::default_font();
|
||||||
auto alt = node().alt();
|
auto alt = node().alt();
|
||||||
if (alt.is_empty())
|
if (alt.is_empty())
|
||||||
|
@ -22,8 +25,8 @@ void LayoutImage::layout()
|
||||||
rect().set_width(font.width(alt) + 16);
|
rect().set_width(font.width(alt) + 16);
|
||||||
rect().set_height(font.glyph_height() + 16);
|
rect().set_height(font.glyph_height() + 16);
|
||||||
} else {
|
} else {
|
||||||
rect().set_width(node().bitmap()->width());
|
rect().set_width(16);
|
||||||
rect().set_height(node().bitmap()->height());
|
rect().set_height(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutReplaced::layout();
|
LayoutReplaced::layout();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue