mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibWeb+LibWebView+WebContent: Support both inspecting/highlighting nodes
Our own Inspector differs from most other DevTools implementations with regard to highlighting DOM nodes as you hover elements in the inspected DOM tree. In other implementations, as you change the hovered node, the browser will render a box model overlay onto the page for that node. We currently don't do this; we wait until you click the node, at which point we both paint the overlay and inspect the node's properties. This patch does not change that behavior, but separates the IPCs and internal tracking of inspected nodes to support the standard DevTools behavior. So the DOM document now stores an inspected node and a highlighted node. The former is used for features such as "$0" in the JavaScript console, and the latter is used for the box model overlay. Our Inspector continues to set these to the same node.
This commit is contained in:
@@ -442,7 +442,7 @@ void ConnectionFromClient::inspect_dom_node(u64 page_id, Web::UniqueNodeID const
|
||||
|
||||
for (auto& navigable : Web::HTML::all_navigables()) {
|
||||
if (navigable->active_document() != nullptr) {
|
||||
navigable->active_document()->set_inspected_node(nullptr, {});
|
||||
navigable->active_document()->set_inspected_node(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ void ConnectionFromClient::inspect_dom_node(u64 page_id, Web::UniqueNodeID const
|
||||
return;
|
||||
}
|
||||
|
||||
node->document().set_inspected_node(node, pseudo_element);
|
||||
node->document().set_inspected_node(node);
|
||||
|
||||
if (node->is_element()) {
|
||||
auto& element = as<Web::DOM::Element>(*node);
|
||||
@@ -599,6 +599,25 @@ void ConnectionFromClient::inspect_dom_node(u64 page_id, Web::UniqueNodeID const
|
||||
async_did_inspect_dom_node(page_id, false, {}, {}, {}, {}, {}, {});
|
||||
}
|
||||
|
||||
void ConnectionFromClient::highlight_dom_node(u64 page_id, Web::UniqueNodeID const& node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element)
|
||||
{
|
||||
auto page = this->page(page_id);
|
||||
if (!page.has_value())
|
||||
return;
|
||||
|
||||
for (auto& navigable : Web::HTML::all_navigables()) {
|
||||
if (navigable->active_document() != nullptr) {
|
||||
navigable->active_document()->set_highlighted_node(nullptr, {});
|
||||
}
|
||||
}
|
||||
|
||||
auto* node = Web::DOM::Node::from_unique_id(node_id);
|
||||
if (!node || !node->layout_node())
|
||||
return;
|
||||
|
||||
node->document().set_highlighted_node(node, pseudo_element);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::inspect_accessibility_tree(u64 page_id)
|
||||
{
|
||||
if (auto page = this->page(page_id); page.has_value()) {
|
||||
|
||||
@@ -76,6 +76,7 @@ private:
|
||||
virtual void get_source(u64 page_id) override;
|
||||
virtual void inspect_dom_tree(u64 page_id) override;
|
||||
virtual void inspect_dom_node(u64 page_id, Web::UniqueNodeID const& node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) override;
|
||||
virtual void highlight_dom_node(u64 page_id, Web::UniqueNodeID const& node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) override;
|
||||
virtual void inspect_accessibility_tree(u64 page_id) override;
|
||||
virtual void get_hovered_node_id(u64 page_id) override;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ JS_DEFINE_NATIVE_FUNCTION(ConsoleGlobalEnvironmentExtensions::$0_getter)
|
||||
{
|
||||
auto* console_global_object = TRY(get_console(vm));
|
||||
auto& window = *console_global_object->m_window_object;
|
||||
auto* inspected_node = window.associated_document().inspected_node();
|
||||
auto inspected_node = window.associated_document().inspected_node();
|
||||
if (!inspected_node)
|
||||
return JS::js_undefined();
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ endpoint WebContentServer
|
||||
get_source(u64 page_id) =|
|
||||
inspect_dom_tree(u64 page_id) =|
|
||||
inspect_dom_node(u64 page_id, Web::UniqueNodeID node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) =|
|
||||
highlight_dom_node(u64 page_id, Web::UniqueNodeID node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) =|
|
||||
inspect_accessibility_tree(u64 page_id) =|
|
||||
get_hovered_node_id(u64 page_id) =|
|
||||
js_console_input(u64 page_id, ByteString js_source) =|
|
||||
|
||||
Reference in New Issue
Block a user