summarylogtreecommitdiffstats
path: root/PasteBoardGtk.patch
blob: 9c0b353f2f10a00d408a9497e9a3c397b748a45e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
diff -Naur webkitgtk-2.40.0/Source/WebCore/platform/gtk/PasteboardGtk.cpp webkitgtk-2.40.0-imgpaste/Source/WebCore/platform/gtk/PasteboardGtk.cpp
--- webkitgtk-2.40.0/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2023-03-17 18:00:23.481180200 +0800
+++ webkitgtk-2.40.0-imgpaste/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2023-03-19 15:37:47.620609123 +0800
@@ -329,6 +329,25 @@
         auto filePaths = platformStrategies()->pasteboardStrategy()->readFilePathsFromClipboard(m_name);
         for (const auto& filePath : filePaths)
             reader.readFilename(filePath);
+        if (filePaths.isEmpty()) {
+            // WTFLogAlways("xxoo Pasteboard::read readFilePathsFromClipboard got no filePaths, try readBufferFromClipboard pasteboardName=%s", m_name.utf8().data());
+            auto types = platformStrategies()->pasteboardStrategy()->types(m_name);
+            static const ASCIILiteral imageTypes[] = { "image/png"_s, "image/jpeg"_s, "image/gif"_s, "image/bmp"_s, "image/vnd.microsoft.icon"_s, "image/x-icon"_s };
+            static const ASCIILiteral imageNames[] = { "image.png"_s, "image.jpeg"_s, "image.gif"_s, "image.bmp"_s, "image.ico"_s, "image.ico"_s };
+            for (int i = 0;i < 6;i++) {
+                if (types.contains(imageTypes[i])) {
+                    // WTFLogAlways("xxoo Pasteboard::read readBufferFromClipboard types contains imageType");
+                    auto buffer = platformStrategies()->pasteboardStrategy()->readBufferFromClipboard(m_name, imageTypes[i]);
+                    // readBuffer(const String&, const String& type, Ref<SharedBuffer>&&)
+                    // readImage(Ref<SharedBuffer>&&, const String&, PresentationSize = { }) 
+                    if (!buffer->isEmpty()) {
+                        reader.readBuffer(imageNames[i], imageTypes[i], buffer.releaseNonNull());
+                        // WTFLogAlways("xxoo Pasteboard::read reader.readBuffer success");
+                        return;
+                    }
+                }
+            }
+        }
         return;
     }