mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
LibWebView+WebContent: Add an IPC to take an element screenshot
This commit is contained in:
parent
424e80ee75
commit
3c1c2994f1
Notes:
sideshowbarker
2024-07-17 04:47:04 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/3c1c2994f1 Pull-request: https://github.com/SerenityOS/serenity/pull/15927 Reviewed-by: https://github.com/linusg ✅
5 changed files with 25 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue