From 6e27efe6c6a6b15ff6b8a7351509f5976db5695c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Jun 2020 21:37:07 +0200 Subject: 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. --- Libraries/LibWeb/PageView.cpp | 8 ++++++++ Libraries/LibWeb/PageView.h | 1 + 2 files changed, 9 insertions(+) (limited to 'Libraries/LibWeb') 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 #include #include +#include #include //#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(); -- cgit v1.2.3