diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.cpp b/Libraries/LibHTML/DOM/HTMLImageElement.cpp
index 97bec0b402a..6fda6dee7fb 100644
--- a/Libraries/LibHTML/DOM/HTMLImageElement.cpp
+++ b/Libraries/LibHTML/DOM/HTMLImageElement.cpp
@@ -1,4 +1,5 @@
#include
+#include
#include
#include
@@ -22,3 +23,18 @@ RefPtr HTMLImageElement::create_layout_node(const StyleResolver& res
return nullptr;
return adopt(*new LayoutImage(*this, move(style)));
}
+
+const GraphicsBitmap* HTMLImageElement::bitmap() const
+{
+ if (!m_bitmap) {
+ URL src_url = document().complete_url(this->src());
+ if (src_url.protocol() == "file") {
+ m_bitmap = GraphicsBitmap::load_from_file(src_url.path());
+ } else {
+ // FIXME: Implement! This whole thing should be at a different layer though..
+ ASSERT_NOT_REACHED();
+ }
+ }
+
+ return m_bitmap;
+}
diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.h b/Libraries/LibHTML/DOM/HTMLImageElement.h
index 69d3513c5d9..33d5587b812 100644
--- a/Libraries/LibHTML/DOM/HTMLImageElement.h
+++ b/Libraries/LibHTML/DOM/HTMLImageElement.h
@@ -1,5 +1,6 @@
#pragma once
+#include
#include
class HTMLImageElement : public HTMLElement {
@@ -10,6 +11,10 @@ public:
String alt() const { return attribute("alt"); }
String src() const { return attribute("src"); }
+ const GraphicsBitmap* bitmap() const;
+
private:
virtual RefPtr create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
+
+ mutable RefPtr m_bitmap;
};
diff --git a/Libraries/LibHTML/Layout/LayoutImage.cpp b/Libraries/LibHTML/Layout/LayoutImage.cpp
index 68c4a8a7c7d..2344afd713f 100644
--- a/Libraries/LibHTML/Layout/LayoutImage.cpp
+++ b/Libraries/LibHTML/Layout/LayoutImage.cpp
@@ -18,6 +18,9 @@ void LayoutImage::layout()
auto& font = Font::default_font();
rect().set_width(font.width(node().alt()) + 16);
rect().set_height(font.glyph_height() + 16);
+ } else {
+ rect().set_width(node().bitmap()->width());
+ rect().set_height(node().bitmap()->height());
}
LayoutReplaced::layout();
@@ -29,11 +32,13 @@ void LayoutImage::render(RenderingContext& context)
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);
+ } else {
+ context.painter().draw_scaled_bitmap(rect(), *node().bitmap(), node().bitmap()->rect());
}
LayoutReplaced::render(context);
}
bool LayoutImage::renders_as_alt_text() const
{
- return true;
+ return !node().bitmap();
}