mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
Browser: Add a context menu item to take a full document screenshot
This commit is contained in:
parent
95e591b61b
commit
ea7ce76d20
Notes:
sideshowbarker
2024-07-17 04:46:37 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/ea7ce76d20 Pull-request: https://github.com/SerenityOS/serenity/pull/15934
3 changed files with 29 additions and 4 deletions
|
@ -246,12 +246,20 @@ void BrowserWindow::build_menus()
|
|||
|
||||
m_take_visible_screenshot_action = GUI::Action::create(
|
||||
"Take &Visible Screenshot"sv, g_icon_bag.filetype_image, [this](auto&) {
|
||||
if (auto result = take_screenshot(); result.is_error())
|
||||
if (auto result = take_screenshot(ScreenshotType::Visible); result.is_error())
|
||||
GUI::MessageBox::show_error(this, String::formatted("{}", result.error()));
|
||||
},
|
||||
this);
|
||||
m_take_visible_screenshot_action->set_status_tip("Save a screenshot of the visible portion of the current tab to the Downloads directory"sv);
|
||||
|
||||
m_take_full_screenshot_action = GUI::Action::create(
|
||||
"Take &Full Screenshot"sv, g_icon_bag.filetype_image, [this](auto&) {
|
||||
if (auto result = take_screenshot(ScreenshotType::Full); result.is_error())
|
||||
GUI::MessageBox::show_error(this, String::formatted("{}", result.error()));
|
||||
},
|
||||
this);
|
||||
m_take_full_screenshot_action->set_status_tip("Save a screenshot of the entirety of the current tab to the Downloads directory"sv);
|
||||
|
||||
auto& inspect_menu = add_menu("&Inspect");
|
||||
inspect_menu.add_action(*m_view_source_action);
|
||||
inspect_menu.add_action(*m_inspect_dom_tree_action);
|
||||
|
@ -758,12 +766,22 @@ void BrowserWindow::event(Core::Event& event)
|
|||
Window::event(event);
|
||||
}
|
||||
|
||||
ErrorOr<void> BrowserWindow::take_screenshot()
|
||||
ErrorOr<void> BrowserWindow::take_screenshot(ScreenshotType type)
|
||||
{
|
||||
if (!active_tab().on_take_screenshot)
|
||||
return {};
|
||||
|
||||
auto bitmap = active_tab().on_take_screenshot();
|
||||
Gfx::ShareableBitmap bitmap;
|
||||
|
||||
switch (type) {
|
||||
case ScreenshotType::Visible:
|
||||
bitmap = active_tab().on_take_screenshot();
|
||||
break;
|
||||
case ScreenshotType::Full:
|
||||
bitmap = active_tab().view().take_document_screenshot();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!bitmap.is_valid())
|
||||
return Error::from_string_view("Failed to take a screenshot of the current tab"sv);
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
GUI::Action& inspect_dom_tree_action() { return *m_inspect_dom_tree_action; }
|
||||
GUI::Action& inspect_dom_node_action() { return *m_inspect_dom_node_action; }
|
||||
GUI::Action& take_visible_screenshot_action() { return *m_take_visible_screenshot_action; }
|
||||
GUI::Action& take_full_screenshot_action() { return *m_take_full_screenshot_action; }
|
||||
|
||||
void content_filters_changed();
|
||||
void proxy_mappings_changed();
|
||||
|
@ -59,7 +60,11 @@ private:
|
|||
|
||||
virtual void event(Core::Event&) override;
|
||||
|
||||
ErrorOr<void> take_screenshot();
|
||||
enum class ScreenshotType {
|
||||
Visible,
|
||||
Full,
|
||||
};
|
||||
ErrorOr<void> take_screenshot(ScreenshotType);
|
||||
|
||||
RefPtr<GUI::Action> m_go_back_action;
|
||||
RefPtr<GUI::Action> m_go_forward_action;
|
||||
|
@ -71,6 +76,7 @@ private:
|
|||
RefPtr<GUI::Action> m_inspect_dom_tree_action;
|
||||
RefPtr<GUI::Action> m_inspect_dom_node_action;
|
||||
RefPtr<GUI::Action> m_take_visible_screenshot_action;
|
||||
RefPtr<GUI::Action> m_take_full_screenshot_action;
|
||||
|
||||
CookieJar& m_cookie_jar;
|
||||
WindowActions m_window_actions;
|
||||
|
|
|
@ -406,6 +406,7 @@ Tab::Tab(BrowserWindow& window)
|
|||
m_page_context_menu->add_action(window.inspect_dom_node_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());
|
||||
view().on_context_menu_request = [&](auto& screen_position) {
|
||||
m_page_context_menu->popup(screen_position);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue