mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:15:09 +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:
parent
d64c054d25
commit
78d65c1c64
4 changed files with 69 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue