LibWebView: Move headless clipboard management to LibWebView

We only supported headless clipboard management in test-web. So when WPT
tests the clipboard APIs, we would blindly try to access the Qt app,
which does not exist.

Note that the AppKit UI has no such restriction, as the NSPasteboard is
accessible even without a GUI.
This commit is contained in:
Timothy Flynn 2025-10-10 10:11:56 -04:00 committed by Tim Flynn
commit e57176b484
Notes: github-actions[bot] 2025-10-10 19:11:12 +00:00
9 changed files with 247 additions and 22 deletions

View file

@ -177,12 +177,18 @@ void Application::display_error_dialog(StringView error_message) const
Utf16String Application::clipboard_text() const
{
if (browser_options().headless_mode.has_value())
return WebView::Application::clipboard_text();
auto const* clipboard = QGuiApplication::clipboard();
return utf16_string_from_qstring(clipboard->text());
}
Vector<Web::Clipboard::SystemClipboardRepresentation> Application::clipboard_entries() const
{
if (browser_options().headless_mode.has_value())
return WebView::Application::clipboard_entries();
Vector<Web::Clipboard::SystemClipboardRepresentation> representations;
auto const* clipboard = QGuiApplication::clipboard();
@ -202,6 +208,11 @@ Vector<Web::Clipboard::SystemClipboardRepresentation> Application::clipboard_ent
void Application::insert_clipboard_entry(Web::Clipboard::SystemClipboardRepresentation entry)
{
if (browser_options().headless_mode.has_value()) {
WebView::Application::insert_clipboard_entry(move(entry));
return;
}
auto* mime_data = new QMimeData();
mime_data->setData(qstring_from_ak_string(entry.mime_type), qbytearray_from_ak_string(entry.data));