mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 14:58:46 +00:00
LibHTML: Add ResourceLoader to support protocol-agnostic URL loading
We now support loading both file:// and http:// URLs. Feel free to visit http://www.serenityos.org/ and enjoy the fancy good times. :^)
This commit is contained in:
parent
3fdc595e0c
commit
3be6d1aff0
Notes:
sideshowbarker
2024-07-19 11:45:12 +09:00
Author: https://github.com/awesomekling
Commit: 3be6d1aff0
6 changed files with 89 additions and 18 deletions
|
@ -1,7 +1,9 @@
|
|||
#include <LibDraw/PNGLoader.h>
|
||||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/HTMLImageElement.h>
|
||||
#include <LibHTML/Layout/LayoutImage.h>
|
||||
#include <LibHTML/ResourceLoader.h>
|
||||
|
||||
HTMLImageElement::HTMLImageElement(Document& document, const String& tag_name)
|
||||
: HTMLElement(document, tag_name)
|
||||
|
@ -21,12 +23,15 @@ void HTMLImageElement::parse_attribute(const String& name, const String& 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();
|
||||
}
|
||||
ResourceLoader::the().load(src_url, [this](auto data) {
|
||||
if (data.is_null()) {
|
||||
dbg() << "HTMLImageElement: Failed to load " << this->src();
|
||||
return;
|
||||
}
|
||||
|
||||
m_bitmap = load_png_from_memory(data.data(), data.size());
|
||||
document().invalidate_layout();
|
||||
});
|
||||
}
|
||||
|
||||
int HTMLImageElement::preferred_width() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue