diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-11-03 13:30:11 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-03 19:15:43 +0000 |
commit | 683c99f299f011b334da43d2ed85676fb3dc403a (patch) | |
tree | e7c37b1c8f27d1b6be2fb2485c3d81605f0080e3 /Userland | |
parent | 9564f04fa61789ebde1f3a2524e33d8aad11a333 (diff) | |
download | serenity-683c99f299f011b334da43d2ed85676fb3dc403a.zip |
LibWebView+WebConent: Add an IPC to get an element's enabled state
Diffstat (limited to 'Userland')
5 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 151ba6f264..d7ccbaeac7 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -565,6 +565,11 @@ Gfx::IntRect OutOfProcessWebView::get_element_rect(i32 element_id) return client().get_element_rect(element_id); } +bool OutOfProcessWebView::is_element_enabled(i32 element_id) +{ + return client().is_element_enabled(element_id); +} + void OutOfProcessWebView::set_content_filters(Vector<String> filters) { client().async_set_content_filters(filters); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 6b8b90a14a..934c865f29 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -72,6 +72,7 @@ public: String get_element_text(i32 element_id); String get_element_tag_name(i32 element_id); Gfx::IntRect get_element_rect(i32 element_id); + bool is_element_enabled(i32 element_id); void set_content_filters(Vector<String>); void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 7f38ef8e7d..73c1c9a935 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -3,6 +3,7 @@ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -26,6 +27,7 @@ #include <LibWeb/Dump.h> #include <LibWeb/Geometry/DOMRect.h> #include <LibWeb/HTML/BrowsingContext.h> +#include <LibWeb/HTML/FormAssociatedElement.h> #include <LibWeb/HTML/Scripting/ClassicScript.h> #include <LibWeb/HTML/Storage.h> #include <LibWeb/HTML/Window.h> @@ -616,6 +618,26 @@ Messages::WebContentServer::GetElementRectResponse ConnectionFromClient::get_ele return { { coordinates.x(), coordinates.y(), static_cast<int>(bounding_rect->width()), static_cast<int>(bounding_rect->height()) } }; } +Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_element_enabled(i32 element_id) +{ + auto element = find_element_by_id(element_id); + if (!element.has_value()) + return { false }; + + auto* document = page().top_level_browsing_context().active_document(); + if (!document) + return { false }; + + bool enabled = !document->is_xml_document(); + + if (enabled && is<Web::HTML::FormAssociatedElement>(*element)) { + auto& form_associated_element = dynamic_cast<Web::HTML::FormAssociatedElement&>(*element); + enabled = form_associated_element.enabled(); + } + + return { enabled }; +} + Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text() { return page().focused_context().selected_text(); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index b1b23efb26..c6cbb114c4 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org> + * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -91,6 +92,7 @@ private: 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::GetElementRectResponse get_element_rect(i32 element_id) override; + virtual Messages::WebContentServer::IsElementEnabledResponse is_element_enabled(i32 element_id) override; virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override; virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index e943d6cd51..88c6841dfc 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -49,6 +49,7 @@ endpoint WebContentServer get_element_text(i32 element_id) => (String text) get_element_tag_name(i32 element_id) => (String tag_name) get_element_rect(i32 element_id) => (Gfx::IntRect rect) + is_element_enabled(i32 element_id) => (bool enabled) webdriver_execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result) |