mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-04-05 04:06:08 +00:00
LibHTML: Add load(URL) and reload() functions to HtmlView
You can now pass a file:/// URL to HtmlView and it will take care of the loading logic for you. Each Document remembers the URL it was loaded from, which allows us to also have reload(). This patch also adds a very simple function for resolving relative URL's into absolute ones.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <LibCore/CFile.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <LibGUI/GScrollBar.h>
|
||||
@@ -7,6 +8,7 @@
|
||||
#include <LibHTML/Frame.h>
|
||||
#include <LibHTML/HtmlView.h>
|
||||
#include <LibHTML/Layout/LayoutNode.h>
|
||||
#include <LibHTML/Parser/HTMLParser.h>
|
||||
#include <LibHTML/RenderingContext.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -147,3 +149,30 @@ void HtmlView::mousedown_event(GMouseEvent& event)
|
||||
update();
|
||||
event.accept();
|
||||
}
|
||||
|
||||
void HtmlView::reload()
|
||||
{
|
||||
load(main_frame().document()->url());
|
||||
}
|
||||
|
||||
void HtmlView::load(const URL& url)
|
||||
{
|
||||
dbg() << "HtmlView::load: " << url;
|
||||
|
||||
if (on_load_start)
|
||||
on_load_start(url);
|
||||
|
||||
auto f = CFile::construct();
|
||||
f->set_filename(url.path());
|
||||
if (!f->open(CIODevice::OpenMode::ReadOnly)) {
|
||||
dbg() << "HtmlView::load: Error: " << f->error_string();
|
||||
return;
|
||||
}
|
||||
|
||||
String html = String::copy(f->read_all());
|
||||
auto document = parse_html(html);
|
||||
document->set_url(url);
|
||||
document->normalize();
|
||||
|
||||
set_document(document);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user