summaryrefslogtreecommitdiff
path: root/Userland/Applications/Browser/Tab.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-05-17 09:53:13 -0400
committerAndreas Kling <kling@serenityos.org>2023-05-17 19:47:05 +0200
commitd8b14da380f0d35f5197b741c81f84c64cfb6204 (patch)
tree1a67b0b15771b5feac5cae6eb5a182035e4accea /Userland/Applications/Browser/Tab.cpp
parent5312a140fedc08f8fd2469b65f5d7b05a172bd62 (diff)
downloadserenity-d8b14da380f0d35f5197b741c81f84c64cfb6204.zip
Browser+Ladybird+LibWebView: Move some common functions to LibWebView
The implementations of handle_web_content_process_crash and take_screenshot are exactly the same across Browser and Ladybird. Let's reduce some code duplication and move them to LibWebView.
Diffstat (limited to 'Userland/Applications/Browser/Tab.cpp')
-rw-r--r--Userland/Applications/Browser/Tab.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp
index f83e24ecb6..af7e7a5c7c 100644
--- a/Userland/Applications/Browser/Tab.cpp
+++ b/Userland/Applications/Browser/Tab.cpp
@@ -554,6 +554,26 @@ Tab::Tab(BrowserWindow& window)
on_tab_close_other_request(*this);
}));
+ auto take_visible_screenshot_action = GUI::Action::create(
+ "Take &Visible Screenshot"sv, g_icon_bag.filetype_image, [this](auto&) {
+ if (auto result = view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Visible); result.is_error()) {
+ auto error = String::formatted("{}", result.error()).release_value_but_fixme_should_propagate_errors();
+ GUI::MessageBox::show_error(&this->window(), error);
+ }
+ },
+ this);
+ take_visible_screenshot_action->set_status_tip("Save a screenshot of the visible portion of the current tab to the Downloads directory"sv);
+
+ auto take_full_screenshot_action = GUI::Action::create(
+ "Take &Full Screenshot"sv, g_icon_bag.filetype_image, [this](auto&) {
+ if (auto result = view().take_screenshot(WebView::ViewImplementation::ScreenshotType::Full); result.is_error()) {
+ auto error = String::formatted("{}", result.error()).release_value_but_fixme_should_propagate_errors();
+ GUI::MessageBox::show_error(&this->window(), error);
+ }
+ },
+ this);
+ take_full_screenshot_action->set_status_tip("Save a screenshot of the entirety of the current tab to the Downloads directory"sv);
+
m_page_context_menu = GUI::Menu::construct();
m_page_context_menu->add_action(window.go_back_action());
m_page_context_menu->add_action(window.go_forward_action());
@@ -562,8 +582,8 @@ Tab::Tab(BrowserWindow& window)
m_page_context_menu->add_action(window.copy_selection_action());
m_page_context_menu->add_action(window.select_all_action());
m_page_context_menu->add_separator();
- m_page_context_menu->add_action(window.take_visible_screenshot_action());
- m_page_context_menu->add_action(window.take_full_screenshot_action());
+ m_page_context_menu->add_action(move(take_visible_screenshot_action));
+ m_page_context_menu->add_action(move(take_full_screenshot_action));
m_page_context_menu->add_separator();
m_page_context_menu->add_action(window.view_source_action());
m_page_context_menu->add_action(window.inspect_dom_tree_action());