mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 18:19:03 +00:00
LibWeb+LibWebVew+WebContent+UI: Add IPC to retrieve the system clipboard
We currently have a single IPC to set clipboard data. We will also need an IPC to retrieve that data from the UI. This defines system clipboard data in LibWeb to handle this transfer, and adds the IPC to provide it.
This commit is contained in:
parent
5fb5066e89
commit
61c0f67c8c
Notes:
github-actions[bot]
2025-05-02 21:47:42 +00:00
Author: https://github.com/trflynn89
Commit: 61c0f67c8c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4548
Reviewed-by: https://github.com/shannonbooth
23 changed files with 255 additions and 28 deletions
|
@ -1064,19 +1064,50 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
|||
totalMatchCount:total_match_count];
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_insert_clipboard_entry = [](auto const& data, auto const&, auto const& mime_type) {
|
||||
m_web_view_bridge->on_insert_clipboard_entry = [](Web::Clipboard::SystemClipboardRepresentation const& entry, auto const&) {
|
||||
NSPasteboardType pasteboard_type = nil;
|
||||
|
||||
// https://w3c.github.io/clipboard-apis/#os-specific-well-known-format
|
||||
if (mime_type == "text/plain"sv)
|
||||
if (entry.mime_type == "text/plain"sv)
|
||||
pasteboard_type = NSPasteboardTypeString;
|
||||
else if (mime_type == "text/html"sv)
|
||||
else if (entry.mime_type == "text/html"sv)
|
||||
pasteboard_type = NSPasteboardTypeHTML;
|
||||
else if (mime_type == "text/png"sv)
|
||||
else if (entry.mime_type == "image/png"sv)
|
||||
pasteboard_type = NSPasteboardTypePNG;
|
||||
|
||||
if (pasteboard_type)
|
||||
copy_data_to_clipboard(data, pasteboard_type);
|
||||
copy_data_to_clipboard(entry.data, pasteboard_type);
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_request_clipboard_entries = [weak_self](auto request_id) {
|
||||
LadybirdWebView* self = weak_self;
|
||||
if (self == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<Web::Clipboard::SystemClipboardItem> items;
|
||||
Vector<Web::Clipboard::SystemClipboardRepresentation> representations;
|
||||
|
||||
auto* pasteBoard = [NSPasteboard generalPasteboard];
|
||||
|
||||
for (NSPasteboardType type : [pasteBoard types]) {
|
||||
String mime_type;
|
||||
|
||||
if (type == NSPasteboardTypeString)
|
||||
mime_type = "text/plain"_string;
|
||||
else if (type == NSPasteboardTypeHTML)
|
||||
mime_type = "text/html"_string;
|
||||
else if (type == NSPasteboardTypePNG)
|
||||
mime_type = "image/png"_string;
|
||||
|
||||
auto data = Ladybird::ns_data_to_string([pasteBoard dataForType:type]);
|
||||
representations.empend(move(data), move(mime_type));
|
||||
}
|
||||
|
||||
if (!representations.is_empty())
|
||||
items.empend(AK::move(representations));
|
||||
|
||||
m_web_view_bridge->retrieved_clipboard_entries(request_id, items);
|
||||
};
|
||||
|
||||
m_web_view_bridge->on_audio_play_state_changed = [weak_self](auto play_state) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue