LibWebView+WebContent: Add an IPC to take an element screenshot

This commit is contained in:
Timothy Flynn 2022-11-04 17:08:02 -04:00 committed by Linus Groh
parent 424e80ee75
commit 3c1c2994f1
Notes: sideshowbarker 2024-07-17 04:47:04 +09:00
5 changed files with 25 additions and 0 deletions

View file

@ -617,6 +617,11 @@ Gfx::ShareableBitmap OutOfProcessWebView::take_screenshot() const
return {};
}
Gfx::ShareableBitmap OutOfProcessWebView::take_element_screenshot(i32 element_id)
{
return client().take_element_screenshot(element_id);
}
Messages::WebContentServer::WebdriverExecuteScriptResponse OutOfProcessWebView::webdriver_execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)
{
return client().webdriver_execute_script(body, json_arguments, timeout, async);

View file

@ -85,6 +85,7 @@ public:
void set_window_size(Gfx::IntSize const&);
Gfx::ShareableBitmap take_screenshot() const;
Gfx::ShareableBitmap take_element_screenshot(i32 element_id);
Messages::WebContentServer::WebdriverExecuteScriptResponse webdriver_execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async);

View file

@ -691,6 +691,23 @@ Messages::WebContentServer::IsElementEnabledResponse ConnectionFromClient::is_el
return { enabled };
}
Messages::WebContentServer::TakeElementScreenshotResponse ConnectionFromClient::take_element_screenshot(i32 element_id)
{
auto element = find_element_by_id(element_id);
if (!element.has_value())
return { {} };
auto viewport_rect = page().top_level_browsing_context().viewport_rect();
auto rect = calculate_absolute_rect_of_element(page(), *element);
rect.intersect(viewport_rect);
auto bitmap = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, rect.size()).release_value_but_fixme_should_propagate_errors();
m_page_host->paint(rect, *bitmap);
return { bitmap->to_shareable_bitmap() };
}
Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
{
return page().focused_context().selected_text();

View file

@ -95,6 +95,7 @@ private:
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::TakeElementScreenshotResponse take_element_screenshot(i32 element_id) override;
virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;
virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;

View file

@ -52,6 +52,7 @@ endpoint WebContentServer
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)
take_element_screenshot(i32 element_id) => (Gfx::ShareableBitmap data)
webdriver_execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result)