Browse Source

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.
Andreas Kling 5 years ago
parent
commit
6e27efe6c6
2 changed files with 9 additions and 0 deletions
  1. 8 0
      Libraries/LibWeb/PageView.cpp
  2. 1 0
      Libraries/LibWeb/PageView.h

+ 8 - 0
Libraries/LibWeb/PageView.cpp

@@ -48,6 +48,7 @@
 #include <LibWeb/Loader/ResourceLoader.h>
 #include <LibWeb/Loader/ResourceLoader.h>
 #include <LibWeb/PageView.h>
 #include <LibWeb/PageView.h>
 #include <LibWeb/Painting/PaintContext.h>
 #include <LibWeb/Painting/PaintContext.h>
+#include <LibWeb/Parser/HTMLDocumentParser.h>
 #include <stdio.h>
 #include <stdio.h>
 
 
 //#define SELECTION_DEBUG
 //#define SELECTION_DEBUG
@@ -272,6 +273,13 @@ void PageView::reload()
     load(page().main_frame().document()->url());
     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)
 bool PageView::load(const URL& url)
 {
 {
     if (window())
     if (window())

+ 1 - 0
Libraries/LibWeb/PageView.h

@@ -44,6 +44,7 @@ public:
     // FIXME: Remove this once the new parser is ready.
     // FIXME: Remove this once the new parser is ready.
     void set_use_old_parser(bool use_old_parser);
     void set_use_old_parser(bool use_old_parser);
 
 
+    void load_html(const StringView&, const URL&);
     void load_empty_document();
     void load_empty_document();
 
 
     Document* document();
     Document* document();