LibWebView+WebContent: Make the hovered node retrieval IPC async

This commit is contained in:
Timothy Flynn 2023-12-30 09:42:24 -05:00 committed by Andreas Kling
parent 760ba5932b
commit 1eba170d03
Notes: sideshowbarker 2024-07-17 18:46:30 +09:00
9 changed files with 26 additions and 12 deletions

View File

@ -89,6 +89,10 @@ InspectorClient::InspectorClient(ViewImplementation& content_web_view, ViewImple
m_inspector_web_view.run_javascript(script);
};
m_content_web_view.on_received_hovered_node_id = [this](auto node_id) {
select_node(node_id);
};
m_content_web_view.on_received_console_message = [this](auto message_index) {
handle_console_message(message_index);
};
@ -198,8 +202,7 @@ void InspectorClient::reset()
void InspectorClient::select_hovered_node()
{
auto hovered_node_id = m_content_web_view.get_hovered_node_id();
select_node(hovered_node_id);
m_content_web_view.get_hovered_node_id();
}
void InspectorClient::select_default_node()

View File

@ -146,9 +146,9 @@ void ViewImplementation::clear_inspected_dom_node()
inspect_dom_node(0, {});
}
i32 ViewImplementation::get_hovered_node_id()
void ViewImplementation::get_hovered_node_id()
{
return client().get_hovered_node_id();
client().async_get_hovered_node_id();
}
void ViewImplementation::set_dom_node_text(i32 node_id, String text)

View File

@ -62,7 +62,7 @@ public:
void inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element);
void inspect_accessibility_tree();
void clear_inspected_dom_node();
i32 get_hovered_node_id();
void get_hovered_node_id();
void set_dom_node_text(i32 node_id, String text);
Optional<i32> set_dom_node_tag(i32 node_id, String name);
@ -143,6 +143,7 @@ public:
Function<void(ByteString const&)> on_received_dom_tree;
Function<void(Optional<DOMNodeProperties>)> on_received_dom_node_properties;
Function<void(ByteString const&)> on_received_accessibility_tree;
Function<void(i32 node_id)> on_received_hovered_node_id;
Function<void(i32 message_id)> on_received_console_message;
Function<void(i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages)> on_received_console_messages;
Function<Vector<Web::Cookie::Cookie>(AK::URL const& url)> on_get_all_cookies;

View File

@ -213,6 +213,12 @@ void WebContentClient::did_inspect_accessibility_tree(ByteString const& accessib
m_view.on_received_accessibility_tree(accessibility_tree);
}
void WebContentClient::did_get_hovered_node_id(i32 node_id)
{
if (m_view.on_received_hovered_node_id)
m_view.on_received_hovered_node_id(node_id);
}
void WebContentClient::did_output_js_console_message(i32 message_index)
{
if (m_view.on_received_console_message)

View File

@ -55,6 +55,7 @@ private:
virtual void did_inspect_dom_tree(ByteString const&) override;
virtual void did_inspect_dom_node(bool has_style, ByteString const& computed_style, ByteString const& resolved_style, ByteString const& custom_properties, ByteString const& node_box_sizing, ByteString const& aria_properties_state) override;
virtual void did_inspect_accessibility_tree(ByteString const&) override;
virtual void did_get_hovered_node_id(i32 node_id) override;
virtual void did_output_js_console_message(i32 message_index) override;
virtual void did_get_js_console_messages(i32 start_index, Vector<ByteString> const& message_types, Vector<ByteString> const& messages) override;
virtual void did_change_favicon(Gfx::ShareableBitmap const&) override;

View File

@ -621,14 +621,16 @@ void ConnectionFromClient::inspect_accessibility_tree()
}
}
Messages::WebContentServer::GetHoveredNodeIdResponse ConnectionFromClient::get_hovered_node_id()
void ConnectionFromClient::get_hovered_node_id()
{
i32 node_id = 0;
if (auto* document = page().page().top_level_browsing_context().active_document()) {
auto hovered_node = document->hovered_node();
if (hovered_node)
return hovered_node->unique_id();
if (auto* hovered_node = document->hovered_node())
node_id = hovered_node->unique_id();
}
return (i32)0;
async_did_get_hovered_node_id(node_id);
}
void ConnectionFromClient::set_dom_node_text(i32 node_id, String const& text)

View File

@ -74,7 +74,7 @@ private:
virtual void inspect_dom_tree() override;
virtual void inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> const& pseudo_element) override;
virtual void inspect_accessibility_tree() override;
virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
virtual void get_hovered_node_id() override;
virtual void set_dom_node_text(i32 node_id, String const& text) override;
virtual Messages::WebContentServer::SetDomNodeTagResponse set_dom_node_tag(i32 node_id, String const& name) override;

View File

@ -44,6 +44,7 @@ endpoint WebContentClient
did_inspect_dom_tree(ByteString dom_tree) =|
did_inspect_dom_node(bool has_style, ByteString computed_style, ByteString resolved_style, ByteString custom_properties, ByteString node_box_sizing, ByteString aria_properties_state) =|
did_inspect_accessibility_tree(ByteString accessibility_tree) =|
did_get_hovered_node_id(i32 node_id) =|
did_change_favicon(Gfx::ShareableBitmap favicon) =|
did_request_all_cookies(URL url) => (Vector<Web::Cookie::Cookie> cookies)

View File

@ -40,7 +40,7 @@ endpoint WebContentServer
inspect_dom_tree() =|
inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement::Type> pseudo_element) =|
inspect_accessibility_tree() =|
get_hovered_node_id() => (i32 node_id)
get_hovered_node_id() =|
js_console_input(ByteString js_source) =|
js_console_request_messages(i32 start_index) =|