mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibWeb+LibWebView+WebContent: Add Inspector IPCs to manipulate DOM nodes
This adds the IDL methods and IPC to forward DOM-editing events from the Inspector WebView to the Inspector client.
This commit is contained in:
parent
4cfeb41c4b
commit
1236cbd41a
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/1236cbd41a Pull-request: https://github.com/SerenityOS/serenity/pull/22150 Reviewed-by: https://github.com/awesomekling ✅
10 changed files with 91 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <LibWeb/Bindings/InspectorPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/Selector.h>
|
||||
#include <LibWeb/DOM/NamedNodeMap.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Internals/Inspector.h>
|
||||
|
@ -47,6 +48,24 @@ void Inspector::inspect_dom_node(i32 node_id, Optional<i32> const& pseudo_elemen
|
|||
}
|
||||
}
|
||||
|
||||
void Inspector::set_dom_node_text(i32 node_id, String const& text)
|
||||
{
|
||||
if (auto* page = global_object().browsing_context()->page())
|
||||
page->client().inspector_did_set_dom_node_text(node_id, text);
|
||||
}
|
||||
|
||||
void Inspector::set_dom_node_tag(i32 node_id, String const& tag)
|
||||
{
|
||||
if (auto* page = global_object().browsing_context()->page())
|
||||
page->client().inspector_did_set_dom_node_tag(node_id, tag);
|
||||
}
|
||||
|
||||
void Inspector::replace_dom_node_attribute(i32 node_id, String const& name, JS::NonnullGCPtr<DOM::NamedNodeMap> replacement_attributes)
|
||||
{
|
||||
if (auto* page = global_object().browsing_context()->page())
|
||||
page->client().inspector_did_replace_dom_node_attribute(node_id, name, replacement_attributes);
|
||||
}
|
||||
|
||||
void Inspector::execute_console_script(String const& script)
|
||||
{
|
||||
if (auto* page = global_object().browsing_context()->page())
|
||||
|
|
|
@ -21,6 +21,10 @@ public:
|
|||
void inspector_loaded();
|
||||
void inspect_dom_node(i32 node_id, Optional<i32> const& pseudo_element);
|
||||
|
||||
void set_dom_node_text(i32 node_id, String const& text);
|
||||
void set_dom_node_tag(i32 node_id, String const& tag);
|
||||
void replace_dom_node_attribute(i32 node_id, String const& name, JS::NonnullGCPtr<DOM::NamedNodeMap> replacement_attributes);
|
||||
|
||||
void execute_console_script(String const& script);
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
#import <DOM/NamedNodeMap.idl>
|
||||
|
||||
[Exposed=Nobody] interface Inspector {
|
||||
|
||||
undefined inspectorLoaded();
|
||||
undefined inspectDOMNode(long nodeID, optional long pseudoElement);
|
||||
|
||||
undefined setDOMNodeText(long nodeID, DOMString text);
|
||||
undefined setDOMNodeTag(long nodeID, DOMString tag);
|
||||
undefined replaceDOMNodeAttribute(long nodeID, DOMString name, NamedNodeMap replacementAttributes);
|
||||
|
||||
undefined executeConsoleScript(DOMString script);
|
||||
|
||||
};
|
||||
|
|
|
@ -265,6 +265,9 @@ public:
|
|||
|
||||
virtual void inspector_did_load() { }
|
||||
virtual void inspector_did_select_dom_node([[maybe_unused]] i32 node_id, [[maybe_unused]] Optional<CSS::Selector::PseudoElement> const& pseudo_element) { }
|
||||
virtual void inspector_did_set_dom_node_text([[maybe_unused]] i32 node_id, [[maybe_unused]] String const& text) { }
|
||||
virtual void inspector_did_set_dom_node_tag([[maybe_unused]] i32 node_id, [[maybe_unused]] String const& tag) { }
|
||||
virtual void inspector_did_replace_dom_node_attribute([[maybe_unused]] i32 node_id, [[maybe_unused]] String const& name, [[maybe_unused]] JS::NonnullGCPtr<DOM::NamedNodeMap> replacement_attributes) {};
|
||||
virtual void inspector_did_execute_console_script([[maybe_unused]] String const& script) { }
|
||||
|
||||
protected:
|
||||
|
|
|
@ -153,6 +153,9 @@ public:
|
|||
Function<void(String const&, String const&, String const&)> on_insert_clipboard_entry;
|
||||
Function<void()> on_inspector_loaded;
|
||||
Function<void(i32, Optional<Web::CSS::Selector::PseudoElement> const&)> on_inspector_selected_dom_node;
|
||||
Function<void(i32, String const&)> on_inspector_set_dom_node_text;
|
||||
Function<void(i32, String const&)> on_inspector_set_dom_node_tag;
|
||||
Function<void(i32, String const&, Vector<Attribute> const&)> on_inspector_replaced_dom_node_attribute;
|
||||
Function<void(String const&)> on_inspector_executed_console_script;
|
||||
|
||||
virtual Gfx::IntRect viewport_rect() const = 0;
|
||||
|
|
|
@ -414,6 +414,24 @@ void WebContentClient::inspector_did_select_dom_node(i32 node_id, Optional<Web::
|
|||
m_view.on_inspector_selected_dom_node(node_id, pseudo_element);
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_set_dom_node_text(i32 node_id, String const& text)
|
||||
{
|
||||
if (m_view.on_inspector_set_dom_node_text)
|
||||
m_view.on_inspector_set_dom_node_text(node_id, text);
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_set_dom_node_tag(i32 node_id, String const& tag)
|
||||
{
|
||||
if (m_view.on_inspector_set_dom_node_tag)
|
||||
m_view.on_inspector_set_dom_node_tag(node_id, tag);
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_replace_dom_node_attribute(i32 node_id, String const& name, Vector<Attribute> const& replacement_attributes)
|
||||
{
|
||||
if (m_view.on_inspector_replaced_dom_node_attribute)
|
||||
m_view.on_inspector_replaced_dom_node_attribute(node_id, name, replacement_attributes);
|
||||
}
|
||||
|
||||
void WebContentClient::inspector_did_execute_console_script(String const& script)
|
||||
{
|
||||
if (m_view.on_inspector_executed_console_script)
|
||||
|
|
|
@ -88,6 +88,9 @@ private:
|
|||
virtual void did_insert_clipboard_entry(String const& data, String const& presentation_style, String const& mime_type) override;
|
||||
virtual void inspector_did_load() override;
|
||||
virtual void inspector_did_select_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) override;
|
||||
virtual void inspector_did_set_dom_node_text(i32 node_id, String const& text) override;
|
||||
virtual void inspector_did_set_dom_node_tag(i32 node_id, String const& tag) override;
|
||||
virtual void inspector_did_replace_dom_node_attribute(i32 node_id, String const& name, Vector<Attribute> const& replacement_attributes) override;
|
||||
virtual void inspector_did_execute_console_script(String const& script) override;
|
||||
|
||||
ViewImplementation& m_view;
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <LibGfx/SystemTheme.h>
|
||||
#include <LibWeb/CSS/SystemColor.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <LibWeb/DOM/Attr.h>
|
||||
#include <LibWeb/DOM/NamedNodeMap.h>
|
||||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
|
@ -17,6 +19,7 @@
|
|||
#include <LibWeb/Painting/PaintingCommandExecutorCPU.h>
|
||||
#include <LibWeb/Painting/ViewportPaintable.h>
|
||||
#include <LibWeb/Platform/Timer.h>
|
||||
#include <LibWebView/Attribute.h>
|
||||
#include <WebContent/ConnectionFromClient.h>
|
||||
#include <WebContent/PageClient.h>
|
||||
#include <WebContent/PageHost.h>
|
||||
|
@ -508,6 +511,31 @@ void PageClient::inspector_did_select_dom_node(i32 node_id, Optional<Web::CSS::S
|
|||
client().async_inspector_did_select_dom_node(node_id, pseudo_element);
|
||||
}
|
||||
|
||||
void PageClient::inspector_did_set_dom_node_text(i32 node_id, String const& text)
|
||||
{
|
||||
client().async_inspector_did_set_dom_node_text(node_id, text);
|
||||
}
|
||||
|
||||
void PageClient::inspector_did_set_dom_node_tag(i32 node_id, String const& tag)
|
||||
{
|
||||
client().async_inspector_did_set_dom_node_tag(node_id, tag);
|
||||
}
|
||||
|
||||
void PageClient::inspector_did_replace_dom_node_attribute(i32 node_id, String const& name, JS::NonnullGCPtr<Web::DOM::NamedNodeMap> replacement_attributes)
|
||||
{
|
||||
Vector<WebView::Attribute> attributes;
|
||||
attributes.ensure_capacity(replacement_attributes->length());
|
||||
|
||||
for (size_t i = 0; i < replacement_attributes->length(); ++i) {
|
||||
auto const* attribute = replacement_attributes->item(i);
|
||||
VERIFY(attribute);
|
||||
|
||||
attributes.empend(attribute->name().to_string(), attribute->value());
|
||||
}
|
||||
|
||||
client().async_inspector_did_replace_dom_node_attribute(node_id, name, move(attributes));
|
||||
}
|
||||
|
||||
void PageClient::inspector_did_execute_console_script(String const& script)
|
||||
{
|
||||
client().async_inspector_did_execute_console_script(script);
|
||||
|
|
|
@ -120,6 +120,9 @@ private:
|
|||
virtual void page_did_insert_clipboard_entry(String data, String presentation_style, String mime_type) override;
|
||||
virtual void inspector_did_load() override;
|
||||
virtual void inspector_did_select_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) override;
|
||||
virtual void inspector_did_set_dom_node_text(i32 node_id, String const& text) override;
|
||||
virtual void inspector_did_set_dom_node_tag(i32 node_id, String const& tag) override;
|
||||
virtual void inspector_did_replace_dom_node_attribute(i32 node_id, String const& name, JS::NonnullGCPtr<Web::DOM::NamedNodeMap> replacement_attributes) override;
|
||||
virtual void inspector_did_execute_console_script(String const& script) override;
|
||||
|
||||
Web::Layout::Viewport* layout_root();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <LibWeb/CSS/Selector.h>
|
||||
#include <LibWeb/HTML/ActivateTab.h>
|
||||
#include <LibWeb/Page/Page.h>
|
||||
#include <LibWebView/Attribute.h>
|
||||
|
||||
endpoint WebContentClient
|
||||
{
|
||||
|
@ -72,6 +73,9 @@ endpoint WebContentClient
|
|||
|
||||
inspector_did_load() =|
|
||||
inspector_did_select_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element) =|
|
||||
inspector_did_set_dom_node_text(i32 node_id, String text) =|
|
||||
inspector_did_set_dom_node_tag(i32 node_id, String tag) =|
|
||||
inspector_did_replace_dom_node_attribute(i32 node_id, String name, Vector<WebView::Attribute> replacement_attributes) =|
|
||||
inspector_did_execute_console_script(String script) =|
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue