mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
LibWeb: Implement fragment parsing and use it for Element.innerHTML
This patch implements most of the HTML fragment parsing algorithm and ports Element::set_inner_html() to it. This was the last remaining user of the old HTML parser. :^)
This commit is contained in:
parent
eb33021d65
commit
92d831c25b
7 changed files with 91 additions and 18 deletions
|
@ -468,4 +468,12 @@ NonnullRefPtrVector<HTMLScriptElement> Document::take_scripts_to_execute_as_soon
|
|||
return move(m_scripts_to_execute_as_soon_as_possible);
|
||||
}
|
||||
|
||||
void Document::adopt_node(Node& subtree_root)
|
||||
{
|
||||
subtree_root.for_each_in_subtree([&](auto& node) {
|
||||
node.set_document({}, *this);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -145,6 +145,8 @@ public:
|
|||
bool in_quirks_mode() const { return m_quirks_mode; }
|
||||
void set_quirks_mode(bool mode) { m_quirks_mode = mode; }
|
||||
|
||||
void adopt_node(Node&);
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include <LibWeb/Layout/LayoutTableRow.h>
|
||||
#include <LibWeb/Layout/LayoutTableRowGroup.h>
|
||||
#include <LibWeb/Layout/LayoutTreeBuilder.h>
|
||||
#include <LibWeb/Parser/HTMLParser.h>
|
||||
#include <LibWeb/Parser/HTMLDocumentParser.h>
|
||||
|
||||
namespace Web {
|
||||
|
||||
|
@ -247,13 +247,10 @@ NonnullRefPtr<StyleProperties> Element::computed_style()
|
|||
|
||||
void Element::set_inner_html(StringView markup)
|
||||
{
|
||||
auto fragment = parse_html_fragment(document(), markup);
|
||||
auto new_children = HTMLDocumentParser::parse_html_fragment(*this, markup);
|
||||
remove_all_children();
|
||||
if (!fragment)
|
||||
return;
|
||||
while (RefPtr<Node> child = fragment->first_child()) {
|
||||
fragment->remove_child(*child);
|
||||
append_child(*child);
|
||||
while (!new_children.is_empty()) {
|
||||
append_child(new_children.take_first());
|
||||
}
|
||||
|
||||
set_needs_style_update(true);
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
namespace Web {
|
||||
|
||||
Node::Node(Document& document, NodeType type)
|
||||
: m_document(document)
|
||||
: m_document(&document)
|
||||
, m_type(type)
|
||||
{
|
||||
}
|
||||
|
@ -212,4 +212,9 @@ RefPtr<Node> Node::insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, b
|
|||
return node;
|
||||
}
|
||||
|
||||
void Node::set_document(Badge<Document>, Document& document)
|
||||
{
|
||||
m_document = &document;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ public:
|
|||
|
||||
virtual String text_content() const;
|
||||
|
||||
Document& document() { return m_document; }
|
||||
const Document& document() const { return m_document; }
|
||||
Document& document() { return *m_document; }
|
||||
const Document& document() const { return *m_document; }
|
||||
|
||||
const HTMLAnchorElement* enclosing_link_element() const;
|
||||
const HTMLElement* enclosing_html_element() const;
|
||||
|
@ -140,10 +140,12 @@ public:
|
|||
virtual void document_did_attach_to_frame(Frame&) {}
|
||||
virtual void document_will_detach_from_frame(Frame&) {}
|
||||
|
||||
void set_document(Badge<Document>, Document&);
|
||||
|
||||
protected:
|
||||
Node(Document&, NodeType);
|
||||
|
||||
Document& m_document;
|
||||
Document* m_document { nullptr };
|
||||
mutable LayoutNode* m_layout_node { nullptr };
|
||||
NodeType m_type { NodeType::INVALID };
|
||||
bool m_needs_style_update { true };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue