mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibHTML: Support width/height attributes on images
This commit is contained in:
parent
088237a25f
commit
b240500107
Notes:
sideshowbarker
2024-07-19 11:47:12 +09:00
Author: https://github.com/deoxxa Commit: https://github.com/SerenityOS/serenity/commit/b240500107c Pull-request: https://github.com/SerenityOS/serenity/pull/634
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
|
||||
{
|
||||
auto style = resolver.resolve_style(*this, parent_style);
|
||||
|
|
|
@ -12,6 +12,8 @@ public:
|
|||
|
||||
String alt() const { return attribute("alt"); }
|
||||
String src() const { return attribute("src"); }
|
||||
int preferred_width() const;
|
||||
int preferred_height() const;
|
||||
|
||||
const GraphicsBitmap* bitmap() const;
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@ LayoutImage::~LayoutImage()
|
|||
|
||||
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 alt = node().alt();
|
||||
if (alt.is_empty())
|
||||
|
@ -22,8 +25,8 @@ void LayoutImage::layout()
|
|||
rect().set_width(font.width(alt) + 16);
|
||||
rect().set_height(font.glyph_height() + 16);
|
||||
} else {
|
||||
rect().set_width(node().bitmap()->width());
|
||||
rect().set_height(node().bitmap()->height());
|
||||
rect().set_width(16);
|
||||
rect().set_height(16);
|
||||
}
|
||||
|
||||
LayoutReplaced::layout();
|
||||
|
|
Loading…
Add table
Reference in a new issue