diff options
author | Conrad Pankoff <deoxxa@fknsrs.biz> | 2019-10-06 23:13:54 +1100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-06 14:33:00 +0200 |
commit | 5f6903a714accf1072b60dfff1f8c63ca8aaa344 (patch) | |
tree | c7dfc4d3ef61e477498ebc2b843c64473edbb595 | |
parent | 1ef53be2f38526779ae121ebdefe10d95e13958c (diff) | |
download | serenity-5f6903a714accf1072b60dfff1f8c63ca8aaa344.zip |
LibHTML: Use image URL as alt text if alt is missing
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutImage.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Libraries/LibHTML/Layout/LayoutImage.cpp b/Libraries/LibHTML/Layout/LayoutImage.cpp index 2344afd713..f28401cf39 100644 --- a/Libraries/LibHTML/Layout/LayoutImage.cpp +++ b/Libraries/LibHTML/Layout/LayoutImage.cpp @@ -16,7 +16,10 @@ void LayoutImage::layout() { if (renders_as_alt_text()) { 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); } else { rect().set_width(node().bitmap()->width()); @@ -31,7 +34,10 @@ void LayoutImage::render(RenderingContext& context) if (renders_as_alt_text()) { context.painter().set_font(Font::default_font()); 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 { context.painter().draw_scaled_bitmap(rect(), *node().bitmap(), node().bitmap()->rect()); } |