From 6e27efe6c6a6b15ff6b8a7351509f5976db5695c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 21 Jun 2020 21:37:07 +0200 Subject: [PATCH] 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(+) diff --git a/Libraries/LibWeb/PageView.cpp b/Libraries/LibWeb/PageView.cpp index d014a54c557..24c8d9a6583 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 756022f10d7..f57f5f0f8a4 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();