mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 12:37:40 +00:00
LibHTML: Use image URL as alt text if alt is missing
This commit is contained in:
parent
1ef53be2f3
commit
5f6903a714
1 changed files with 8 additions and 2 deletions
|
@ -16,7 +16,10 @@ void LayoutImage::layout()
|
||||||
{
|
{
|
||||||
if (renders_as_alt_text()) {
|
if (renders_as_alt_text()) {
|
||||||
auto& font = Font::default_font();
|
auto& font = Font::default_font();
|
||||||
rect().set_width(font.width(node().alt()) + 16);
|
auto alt = node().alt();
|
||||||
|
if (alt.is_empty())
|
||||||
|
alt = node().src();
|
||||||
|
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(node().bitmap()->width());
|
||||||
|
@ -31,7 +34,10 @@ void LayoutImage::render(RenderingContext& context)
|
||||||
if (renders_as_alt_text()) {
|
if (renders_as_alt_text()) {
|
||||||
context.painter().set_font(Font::default_font());
|
context.painter().set_font(Font::default_font());
|
||||||
StylePainter::paint_frame(context.painter(), rect(), FrameShape::Container, FrameShadow::Sunken, 2);
|
StylePainter::paint_frame(context.painter(), rect(), FrameShape::Container, FrameShadow::Sunken, 2);
|
||||||
context.painter().draw_text(rect(), node().alt(), TextAlignment::Center, Color::White);
|
auto alt = node().alt();
|
||||||
|
if (alt.is_empty())
|
||||||
|
alt = node().src();
|
||||||
|
context.painter().draw_text(rect(), alt, TextAlignment::Center, Color::White);
|
||||||
} else {
|
} else {
|
||||||
context.painter().draw_scaled_bitmap(rect(), *node().bitmap(), node().bitmap()->rect());
|
context.painter().draw_scaled_bitmap(rect(), *node().bitmap(), node().bitmap()->rect());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue