summaryrefslogtreecommitdiff
path: root/Libraries/LibHTML/DOM
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-05 23:41:14 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-05 23:41:14 +0200
commit958b395418d1d5aa092c2a89278447ece2c9364e (patch)
tree7d18e58a5309afeb0302890f925830049b43481a /Libraries/LibHTML/DOM
parent9858e2632c3eac9756551f2ade3a7eb13a25dac8 (diff)
downloadserenity-958b395418d1d5aa092c2a89278447ece2c9364e.zip
LibHTML: Support rendering <img src> with file:// URLs
We can now show images loaded from local file:// URLs. Pretty neat :^)
Diffstat (limited to 'Libraries/LibHTML/DOM')
-rw-r--r--Libraries/LibHTML/DOM/HTMLImageElement.cpp16
-rw-r--r--Libraries/LibHTML/DOM/HTMLImageElement.h5
2 files changed, 21 insertions, 0 deletions
diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.cpp b/Libraries/LibHTML/DOM/HTMLImageElement.cpp
index 97bec0b402..6fda6dee7f 100644
--- a/Libraries/LibHTML/DOM/HTMLImageElement.cpp
+++ b/Libraries/LibHTML/DOM/HTMLImageElement.cpp
@@ -1,4 +1,5 @@
#include <LibHTML/CSS/StyleResolver.h>
+#include <LibHTML/DOM/Document.h>
#include <LibHTML/DOM/HTMLImageElement.h>
#include <LibHTML/Layout/LayoutImage.h>
@@ -22,3 +23,18 @@ RefPtr<LayoutNode> 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 69d3513c5d..33d5587b81 100644
--- a/Libraries/LibHTML/DOM/HTMLImageElement.h
+++ b/Libraries/LibHTML/DOM/HTMLImageElement.h
@@ -1,5 +1,6 @@
#pragma once
+#include <LibDraw/GraphicsBitmap.h>
#include <LibHTML/DOM/HTMLElement.h>
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<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
+
+ mutable RefPtr<GraphicsBitmap> m_bitmap;
};