mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibWeb+Browser: Add ability to run Browser with the new HTML parser
You can now pass "-n" to the browser to use the new HTML parser. It's not turned on by default since it's still very immature, but this is a huge step towards bringing it into maturity. :^)
This commit is contained in:
parent
08e2907210
commit
2cb50f6750
4 changed files with 30 additions and 4 deletions
|
@ -47,6 +47,7 @@
|
|||
#include <LibWeb/HtmlView.h>
|
||||
#include <LibWeb/Layout/LayoutDocument.h>
|
||||
#include <LibWeb/Layout/LayoutNode.h>
|
||||
#include <LibWeb/Parser/HTMLDocumentParser.h>
|
||||
#include <LibWeb/Parser/HTMLParser.h>
|
||||
#include <LibWeb/RenderingContext.h>
|
||||
#include <LibWeb/ResourceLoader.h>
|
||||
|
@ -431,7 +432,7 @@ static String guess_mime_type_based_on_filename(const URL& url)
|
|||
return "text/plain";
|
||||
}
|
||||
|
||||
static RefPtr<Document> create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding)
|
||||
RefPtr<Document> HtmlView::create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding)
|
||||
{
|
||||
if (mime_type.starts_with("image/"))
|
||||
return create_image_document(data, url);
|
||||
|
@ -441,8 +442,14 @@ static RefPtr<Document> create_document_from_mime_type(const ByteBuffer& data, c
|
|||
return create_markdown_document(data, url);
|
||||
if (mime_type == "text/gemini")
|
||||
return create_gemini_document(data, url);
|
||||
if (mime_type == "text/html")
|
||||
if (mime_type == "text/html") {
|
||||
if (m_use_new_parser) {
|
||||
HTMLDocumentParser parser(data);
|
||||
parser.run(url);
|
||||
return parser.document();
|
||||
}
|
||||
return parse_html_document(data, url, encoding);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ class HtmlView : public GUI::ScrollableWidget {
|
|||
public:
|
||||
virtual ~HtmlView() override;
|
||||
|
||||
// FIXME: Remove this once the new parser is ready.
|
||||
void set_use_new_parser(bool use_new_parser) { m_use_new_parser = use_new_parser; }
|
||||
|
||||
Document* document();
|
||||
const Document* document() const;
|
||||
void set_document(Document*);
|
||||
|
@ -83,6 +86,8 @@ protected:
|
|||
private:
|
||||
virtual void did_scroll() override;
|
||||
|
||||
RefPtr<Document> create_document_from_mime_type(const ByteBuffer& data, const URL& url, const String& mime_type, const String& encoding);
|
||||
|
||||
void run_javascript_url(const String& url);
|
||||
void layout_and_sync_size();
|
||||
void dump_selection(const char* event_name);
|
||||
|
@ -92,6 +97,8 @@ private:
|
|||
|
||||
bool m_should_show_line_box_borders { false };
|
||||
bool m_in_mouse_selection { false };
|
||||
|
||||
bool m_use_new_parser { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue