summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-21 21:37:07 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-21 21:54:30 +0200
commit6e27efe6c6a6b15ff6b8a7351509f5976db5695c (patch)
treefada26d6a0f299eb1c60ade82bdfe2697adf00a0 /Libraries/LibWeb
parent59537cf257c43cfaa8417da81a9cf723e2666567 (diff)
downloadserenity-6e27efe6c6a6b15ff6b8a7351509f5976db5695c.zip
LibWeb: Add PageView::load_html() for loading HTML directly
When you're using Web::PageView as a GUI widget, you'll often just have a chunk of HTML you want to show. So let's have an API for that.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/PageView.cpp8
-rw-r--r--Libraries/LibWeb/PageView.h1
2 files changed, 9 insertions, 0 deletions
diff --git a/Libraries/LibWeb/PageView.cpp b/Libraries/LibWeb/PageView.cpp
index d014a54c55..24c8d9a658 100644
--- a/Libraries/LibWeb/PageView.cpp
+++ b/Libraries/LibWeb/PageView.cpp
@@ -48,6 +48,7 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/PageView.h>
#include <LibWeb/Painting/PaintContext.h>
+#include <LibWeb/Parser/HTMLDocumentParser.h>
#include <stdio.h>
//#define SELECTION_DEBUG
@@ -272,6 +273,13 @@ void PageView::reload()
load(page().main_frame().document()->url());
}
+void PageView::load_html(const StringView& html, const URL& url)
+{
+ HTMLDocumentParser parser(html, "utf-8");
+ parser.run(url);
+ set_document(&parser.document());
+}
+
bool PageView::load(const URL& url)
{
if (window())
diff --git a/Libraries/LibWeb/PageView.h b/Libraries/LibWeb/PageView.h
index 756022f10d..f57f5f0f8a 100644
--- a/Libraries/LibWeb/PageView.h
+++ b/Libraries/LibWeb/PageView.h
@@ -44,6 +44,7 @@ public:
// FIXME: Remove this once the new parser is ready.
void set_use_old_parser(bool use_old_parser);
+ void load_html(const StringView&, const URL&);
void load_empty_document();
Document* document();