mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
LibHTML: Load image resource when src attribute is set
This commit is contained in:
parent
ef8b754a46
commit
1ef53be2f3
2 changed files with 21 additions and 10 deletions
|
@ -12,6 +12,23 @@ HTMLImageElement::~HTMLImageElement()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTMLImageElement::parse_attribute(const String& name, const String& value)
|
||||||
|
{
|
||||||
|
if (name == "src")
|
||||||
|
load_image(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLImageElement::load_image(const String& src)
|
||||||
|
{
|
||||||
|
URL src_url = document().complete_url(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
|
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& resolver, const StyleProperties* parent_style) const
|
||||||
{
|
{
|
||||||
auto style = resolver.resolve_style(*this, parent_style);
|
auto style = resolver.resolve_style(*this, parent_style);
|
||||||
|
@ -26,15 +43,5 @@ RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleResolver& res
|
||||||
|
|
||||||
const GraphicsBitmap* HTMLImageElement::bitmap() const
|
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;
|
return m_bitmap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,16 @@ public:
|
||||||
HTMLImageElement(Document&, const String& tag_name);
|
HTMLImageElement(Document&, const String& tag_name);
|
||||||
virtual ~HTMLImageElement() override;
|
virtual ~HTMLImageElement() override;
|
||||||
|
|
||||||
|
virtual void parse_attribute(const String& name, const String& value) override;
|
||||||
|
|
||||||
String alt() const { return attribute("alt"); }
|
String alt() const { return attribute("alt"); }
|
||||||
String src() const { return attribute("src"); }
|
String src() const { return attribute("src"); }
|
||||||
|
|
||||||
const GraphicsBitmap* bitmap() const;
|
const GraphicsBitmap* bitmap() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void load_image(const String& src);
|
||||||
|
|
||||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
|
virtual RefPtr<LayoutNode> create_layout_node(const StyleResolver&, const StyleProperties* parent_style) const override;
|
||||||
|
|
||||||
mutable RefPtr<GraphicsBitmap> m_bitmap;
|
mutable RefPtr<GraphicsBitmap> m_bitmap;
|
||||||
|
|
Loading…
Add table
Reference in a new issue