mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
LibWebView+WebContent: Add WebContent IPC to create children DOM nodes
This adds IPC to create append a child <div> element or a text node to a DOM node.
This commit is contained in:
parent
bb217fb0d7
commit
111e53a2f6
5 changed files with 41 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/ElementFactory.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
|
@ -720,6 +721,30 @@ void ConnectionFromClient::replace_dom_node_attribute(i32 node_id, String const&
|
|||
element.remove_attribute(name);
|
||||
}
|
||||
|
||||
Messages::WebContentServer::CreateChildElementResponse ConnectionFromClient::create_child_element(i32 node_id)
|
||||
{
|
||||
auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
|
||||
if (!dom_node)
|
||||
return OptionalNone {};
|
||||
|
||||
auto element = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors();
|
||||
dom_node->append_child(element).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
return element->unique_id();
|
||||
}
|
||||
|
||||
Messages::WebContentServer::CreateChildTextNodeResponse ConnectionFromClient::create_child_text_node(i32 node_id)
|
||||
{
|
||||
auto* dom_node = Web::DOM::Node::from_unique_id(node_id);
|
||||
if (!dom_node)
|
||||
return OptionalNone {};
|
||||
|
||||
auto text_node = dom_node->heap().allocate<Web::DOM::Text>(dom_node->realm(), dom_node->document(), "text"_string);
|
||||
dom_node->append_child(text_node).release_value_but_fixme_should_propagate_errors();
|
||||
|
||||
return text_node->unique_id();
|
||||
}
|
||||
|
||||
void ConnectionFromClient::remove_dom_node(i32 node_id)
|
||||
{
|
||||
auto* active_document = page().page().top_level_browsing_context().active_document();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue