1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +00:00

WebContent+Friends: Add get_element_text IPC and plumbing

This commit is contained in:
martinfalisse 2022-11-01 10:10:51 +01:00 committed by Linus Groh
parent 67236d9573
commit 5ffff09e05
7 changed files with 27 additions and 0 deletions

View file

@ -607,6 +607,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
return active_tab().view().get_computed_value_for_element(element_id, property_name); return active_tab().view().get_computed_value_for_element(element_id, property_name);
}; };
new_tab.webdriver_endpoints().on_get_element_text = [this](i32 element_id) {
return active_tab().view().get_element_text(element_id);
};
new_tab.webdriver_endpoints().on_get_element_tag_name = [this](i32 element_id) { new_tab.webdriver_endpoints().on_get_element_tag_name = [this](i32 element_id) {
return active_tab().view().get_element_tag_name(element_id); return active_tab().view().get_element_tag_name(element_id);
}; };

View file

@ -23,6 +23,7 @@ public:
Function<Optional<String>(i32 element_id, String const&)> on_get_element_property; Function<Optional<String>(i32 element_id, String const&)> on_get_element_property;
Function<String()> on_get_active_documents_type; Function<String()> on_get_active_documents_type;
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element; Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
Function<String(i32 element_id)> on_get_element_text;
Function<String(i32 element_id)> on_get_element_tag_name; Function<String(i32 element_id)> on_get_element_tag_name;
}; };

View file

@ -545,6 +545,11 @@ String OutOfProcessWebView::get_computed_value_for_element(i32 element_id, Strin
return client().get_computed_value_for_element(element_id, property_name); return client().get_computed_value_for_element(element_id, property_name);
} }
String OutOfProcessWebView::get_element_text(i32 element_id)
{
return client().get_element_text(element_id);
}
String OutOfProcessWebView::get_element_tag_name(i32 element_id) String OutOfProcessWebView::get_element_tag_name(i32 element_id)
{ {
return client().get_element_tag_name(element_id); return client().get_element_tag_name(element_id);

View file

@ -64,6 +64,7 @@ public:
Optional<String> get_element_property(i32 element_id, String const& name); Optional<String> get_element_property(i32 element_id, String const& name);
String get_active_documents_type(); String get_active_documents_type();
String get_computed_value_for_element(i32 element_id, String const& property_name); String get_computed_value_for_element(i32 element_id, String const& property_name);
String get_element_text(i32 element_id);
String get_element_tag_name(i32 element_id); String get_element_tag_name(i32 element_id);
void set_content_filters(Vector<String>); void set_content_filters(Vector<String>);

View file

@ -561,6 +561,20 @@ Messages::WebContentServer::GetComputedValueForElementResponse ConnectionFromCli
return { style_value->to_string() }; return { style_value->to_string() };
} }
Messages::WebContentServer::GetElementTextResponse ConnectionFromClient::get_element_text(i32 element_id)
{
auto* node = Web::DOM::Node::from_id(element_id);
if (!node)
return { "" };
if (!node->is_element())
return { "" };
auto& element = verify_cast<Web::DOM::Element>(*node);
return { element.layout_node()->dom_node()->text_content() };
}
Messages::WebContentServer::GetElementTagNameResponse ConnectionFromClient::get_element_tag_name(i32 element_id) Messages::WebContentServer::GetElementTagNameResponse ConnectionFromClient::get_element_tag_name(i32 element_id)
{ {
auto* node = Web::DOM::Node::from_id(element_id); auto* node = Web::DOM::Node::from_id(element_id);

View file

@ -85,6 +85,7 @@ private:
virtual Messages::WebContentServer::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override; virtual Messages::WebContentServer::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override;
virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override; virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override;
virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override; virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override;
virtual Messages::WebContentServer::GetElementTextResponse get_element_text(i32 element_id) override;
virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override;
virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override; virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;

View file

@ -43,6 +43,7 @@ endpoint WebContentServer
get_element_property(i32 element_id, String name) => (Optional<String> property) get_element_property(i32 element_id, String name) => (Optional<String> property)
get_active_documents_type() => (String type) get_active_documents_type() => (String type)
get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value) get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value)
get_element_text(i32 element_id) => (String text)
get_element_tag_name(i32 element_id) => (String tag_name) get_element_tag_name(i32 element_id) => (String tag_name)
run_javascript(String js_source) =| run_javascript(String js_source) =|