diff --git a/Libraries/LibHTML/DOM/Document.cpp b/Libraries/LibHTML/DOM/Document.cpp
index 97e5873c4f2..4cdceb60693 100644
--- a/Libraries/LibHTML/DOM/Document.cpp
+++ b/Libraries/LibHTML/DOM/Document.cpp
@@ -1,3 +1,5 @@
+#include
+#include
#include
#include
#include
@@ -99,3 +101,27 @@ Color Document::background_color() const
return background_color.value()->to_color();
}
+
+URL Document::complete_url(const String& string) const
+{
+ URL url(string);
+ if (url.is_valid())
+ return url;
+
+ FileSystemPath fspath(m_url.path());
+ StringBuilder builder;
+ builder.append('/');
+ for (int i = 0; i < fspath.parts().size(); ++i) {
+ if (i == fspath.parts().size() - 1)
+ break;
+ builder.append(fspath.parts()[i]);
+ builder.append('/');
+ }
+ builder.append(string);
+ auto built = builder.to_string();
+ fspath = FileSystemPath(built);
+
+ url = m_url;
+ url.set_path(fspath.string());
+ return url;
+}
diff --git a/Libraries/LibHTML/DOM/Document.h b/Libraries/LibHTML/DOM/Document.h
index 07ea5454b26..c66ebc6afa3 100644
--- a/Libraries/LibHTML/DOM/Document.h
+++ b/Libraries/LibHTML/DOM/Document.h
@@ -3,6 +3,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -21,6 +22,11 @@ public:
Document();
virtual ~Document() override;
+ void set_url(const URL& url) { m_url = url; }
+ const URL& url() const { return m_url; }
+
+ URL complete_url(const String&) const;
+
void normalize();
StyleResolver& style_resolver();
@@ -53,4 +59,5 @@ private:
NonnullRefPtrVector m_sheets;
RefPtr m_hovered_node;
WeakPtr m_frame;
+ URL m_url;
};
diff --git a/Libraries/LibHTML/HtmlView.cpp b/Libraries/LibHTML/HtmlView.cpp
index 89d4cb8df24..3669ef2e951 100644
--- a/Libraries/LibHTML/HtmlView.cpp
+++ b/Libraries/LibHTML/HtmlView.cpp
@@ -1,3 +1,4 @@
+#include
#include
#include
#include
@@ -7,6 +8,7 @@
#include
#include
#include
+#include
#include
#include
@@ -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);
+}
diff --git a/Libraries/LibHTML/HtmlView.h b/Libraries/LibHTML/HtmlView.h
index 61d374d01cd..bccd78286a3 100644
--- a/Libraries/LibHTML/HtmlView.h
+++ b/Libraries/LibHTML/HtmlView.h
@@ -1,5 +1,6 @@
#pragma once
+#include
#include
#include
@@ -17,8 +18,14 @@ public:
Frame& main_frame() { return *m_main_frame; }
const Frame& main_frame() const { return *m_main_frame; }
+ void reload();
+ void load(const URL&);
+
+ URL url() const;
+
Function on_link_click;
Function on_title_change;
+ Function on_load_start;
protected:
HtmlView(GWidget* parent = nullptr);