diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /widget/gtk/nsClipboardWayland.cpp | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | widget/gtk/nsClipboardWayland.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/widget/gtk/nsClipboardWayland.cpp b/widget/gtk/nsClipboardWayland.cpp new file mode 100644 index 0000000000..d179f242dd --- /dev/null +++ b/widget/gtk/nsClipboardWayland.cpp @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:expandtab:shiftwidth=2:tabstop=2: + */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsClipboardWayland.h" + +#include "AsyncGtkClipboardRequest.h" +#include "mozilla/TimeStamp.h" +#include "mozilla/ScopeExit.h" +#include "prtime.h" + +#include <gtk/gtk.h> +#include <stdlib.h> +#include <string.h> + +using namespace mozilla; + +nsRetrievalContextWayland::nsRetrievalContextWayland() = default; + +ClipboardTargets nsRetrievalContextWayland::GetTargetsImpl( + int32_t aWhichClipboard) { + LOGCLIP("nsRetrievalContextWayland::GetTargetsImpl()\n"); + + return WaitForClipboardData(ClipboardDataType::Targets, aWhichClipboard) + .ExtractTargets(); +} + +ClipboardData nsRetrievalContextWayland::GetClipboardData( + const char* aMimeType, int32_t aWhichClipboard) { + LOGCLIP("nsRetrievalContextWayland::GetClipboardData() mime %s\n", aMimeType); + + return WaitForClipboardData(ClipboardDataType::Data, aWhichClipboard, + aMimeType); +} + +GUniquePtr<char> nsRetrievalContextWayland::GetClipboardText( + int32_t aWhichClipboard) { + GdkAtom selection = GetSelectionAtom(aWhichClipboard); + + LOGCLIP("nsRetrievalContextWayland::GetClipboardText(), clipboard %s\n", + (selection == GDK_SELECTION_PRIMARY) ? "Primary" : "Selection"); + + return WaitForClipboardData(ClipboardDataType::Text, aWhichClipboard) + .ExtractText(); +} + +ClipboardData nsRetrievalContextWayland::WaitForClipboardData( + ClipboardDataType aDataType, int32_t aWhichClipboard, + const char* aMimeType) { + LOGCLIP("nsRetrievalContextWayland::WaitForClipboardData, MIME %s\n", + aMimeType); + + AsyncGtkClipboardRequest request(aDataType, aWhichClipboard, aMimeType); + int iteration = 1; + + PRTime entryTime = PR_Now(); + while (!request.HasCompleted()) { + if (iteration++ > kClipboardFastIterationNum) { + /* sleep for 10 ms/iteration */ + PR_Sleep(PR_MillisecondsToInterval(10)); + if (PR_Now() - entryTime > kClipboardTimeout) { + LOGCLIP(" failed to get async clipboard data in time limit\n"); + break; + } + } + LOGCLIP("doing iteration %d msec %ld ...\n", (iteration - 1), + (long)((PR_Now() - entryTime) / 1000)); + gtk_main_iteration(); + } + + return request.TakeResult(); +} |