mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
LibWeb: Add Document create_element() and create_text_node() helpers
This commit is contained in:
parent
9d7ab13b32
commit
0e60e7aef0
2 changed files with 16 additions and 2 deletions
|
@ -46,6 +46,7 @@
|
||||||
#include <LibWeb/DOM/HTMLHeadElement.h>
|
#include <LibWeb/DOM/HTMLHeadElement.h>
|
||||||
#include <LibWeb/DOM/HTMLHtmlElement.h>
|
#include <LibWeb/DOM/HTMLHtmlElement.h>
|
||||||
#include <LibWeb/DOM/HTMLTitleElement.h>
|
#include <LibWeb/DOM/HTMLTitleElement.h>
|
||||||
|
#include <LibWeb/DOM/Text.h>
|
||||||
#include <LibWeb/DOM/Window.h>
|
#include <LibWeb/DOM/Window.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
#include <LibWeb/Frame.h>
|
#include <LibWeb/Frame.h>
|
||||||
|
@ -112,8 +113,8 @@ void Document::fixup()
|
||||||
if (is<HTMLHtmlElement>(first_child()->next_sibling()))
|
if (is<HTMLHtmlElement>(first_child()->next_sibling()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto body = create_element(*this, "body");
|
auto body = create_element("body");
|
||||||
auto html = create_element(*this, "html");
|
auto html = create_element("html");
|
||||||
html->append_child(body);
|
html->append_child(body);
|
||||||
this->donate_all_children_to(body);
|
this->donate_all_children_to(body);
|
||||||
this->append_child(html);
|
this->append_child(html);
|
||||||
|
@ -384,4 +385,14 @@ JS::Value Document::run_javascript(const StringView& source)
|
||||||
return document().interpreter().run(*program);
|
return document().interpreter().run(*program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NonnullRefPtr<Element> Document::create_element(const String& tag_name)
|
||||||
|
{
|
||||||
|
return Web::create_element(*this, tag_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
NonnullRefPtr<Text> Document::create_text_node(const String& data)
|
||||||
|
{
|
||||||
|
return adopt(*new Text(*this, data));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,9 @@ public:
|
||||||
|
|
||||||
JS::Value run_javascript(const StringView&);
|
JS::Value run_javascript(const StringView&);
|
||||||
|
|
||||||
|
NonnullRefPtr<Element> create_element(const String& tag_name);
|
||||||
|
NonnullRefPtr<Text> create_text_node(const String& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue