Title: [212428] trunk/Source/WebCore
Revision
212428
Author
carlo...@webkit.org
Date
2017-02-16 04:08:53 -0800 (Thu, 16 Feb 2017)

Log Message

[GTK] Images are never read from the clipboard
https://bugs.webkit.org/show_bug.cgi?id=168419

Reviewed by Sergio Villar Senin.

We write images in the clipboard, but we don't read them.

Fixes: editing/pasteboard/paste-image-using-image-data.html

* editing/Editor.cpp:
(WebCore::Editor::createFragmentForImageAndURL): Moved from EditorMac.mm since it's cross-platform code.
* editing/Editor.h:
* editing/gtk/EditorGtk.cpp:
(WebCore::createFragmentFromPasteboardData): Check if there's an image in the selection, and use
Editor::createFragmentForImageAndURL in that case.
* editing/mac/EditorMac.mm:
(WebCore::Editor::createFragmentForImageAndURL): Deleted.
* platform/gtk/PasteboardHelper.cpp:
(WebCore::PasteboardHelper::getClipboardContents): Check also if there's an image in the clipboard.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (212427 => 212428)


--- trunk/Source/WebCore/ChangeLog	2017-02-16 10:17:59 UTC (rev 212427)
+++ trunk/Source/WebCore/ChangeLog	2017-02-16 12:08:53 UTC (rev 212428)
@@ -1,3 +1,25 @@
+2017-02-16  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Images are never read from the clipboard
+        https://bugs.webkit.org/show_bug.cgi?id=168419
+
+        Reviewed by Sergio Villar Senin.
+
+        We write images in the clipboard, but we don't read them.
+
+        Fixes: editing/pasteboard/paste-image-using-image-data.html
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::createFragmentForImageAndURL): Moved from EditorMac.mm since it's cross-platform code.
+        * editing/Editor.h:
+        * editing/gtk/EditorGtk.cpp:
+        (WebCore::createFragmentFromPasteboardData): Check if there's an image in the selection, and use
+        Editor::createFragmentForImageAndURL in that case.
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::createFragmentForImageAndURL): Deleted.
+        * platform/gtk/PasteboardHelper.cpp:
+        (WebCore::PasteboardHelper::getClipboardContents): Check also if there's an image in the clipboard.
+
 2017-02-15  Jer Noble  <jer.no...@apple.com>
 
         REGRESSION (r212311): NULL-dereference in HTMLMediaElement::prepareToPlay()

Modified: trunk/Source/WebCore/editing/Editor.cpp (212427 => 212428)


--- trunk/Source/WebCore/editing/Editor.cpp	2017-02-16 10:17:59 UTC (rev 212427)
+++ trunk/Source/WebCore/editing/Editor.cpp	2017-02-16 12:08:53 UTC (rev 212428)
@@ -3740,5 +3740,15 @@
     return font;
 }
 
+Ref<DocumentFragment> Editor::createFragmentForImageAndURL(const String& url)
+{
+    auto imageElement = HTMLImageElement::create(*m_frame.document());
+    imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
 
+    auto fragment = document().createDocumentFragment();
+    fragment->appendChild(imageElement);
+
+    return fragment;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/editing/Editor.h (212427 => 212428)


--- trunk/Source/WebCore/editing/Editor.h	2017-02-16 10:17:59 UTC (rev 212427)
+++ trunk/Source/WebCore/editing/Editor.h	2017-02-16 12:08:53 UTC (rev 212428)
@@ -483,6 +483,8 @@
     void setIsGettingDictionaryPopupInfo(bool b) { m_isGettingDictionaryPopupInfo = b; }
     bool isGettingDictionaryPopupInfo() const { return m_isGettingDictionaryPopupInfo; }
 
+    Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
+
 private:
     class WebContentReader;
 
@@ -522,7 +524,6 @@
     String selectionInHTMLFormat();
     RefPtr<SharedBuffer> imageInWebArchiveFormat(Element&);
     RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(RefPtr<ArchiveResource>&&);
-    Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
     RefPtr<DocumentFragment> createFragmentAndAddResources(NSAttributedString *);
     FragmentAndResources createFragment(NSAttributedString *);
     void fillInUserVisibleForm(PasteboardURL&);

Modified: trunk/Source/WebCore/editing/gtk/EditorGtk.cpp (212427 => 212428)


--- trunk/Source/WebCore/editing/gtk/EditorGtk.cpp	2017-02-16 10:17:59 UTC (rev 212427)
+++ trunk/Source/WebCore/editing/gtk/EditorGtk.cpp	2017-02-16 12:08:53 UTC (rev 212428)
@@ -27,7 +27,9 @@
 #include "config.h"
 #include "Editor.h"
 
+#include "Blob.h"
 #include "CachedImage.h"
+#include "DOMURL.h"
 #include "DocumentFragment.h"
 #include "Frame.h"
 #include "HTMLEmbedElement.h"
@@ -54,6 +56,19 @@
         return nullptr;
 
     const auto& selection = pasteboard.selectionData();
+    if (selection.hasImage()) {
+        Vector<uint8_t> buffer;
+        auto status = cairo_surface_write_to_png_stream(selection.image()->nativeImage().get(), [](void* output, const unsigned char* data, unsigned size) {
+            if (!reinterpret_cast<Vector<uint8_t>*>(output)->tryAppend(data, size))
+                return CAIRO_STATUS_WRITE_ERROR;
+            return CAIRO_STATUS_SUCCESS;
+        }, &buffer);
+        if (status == CAIRO_STATUS_SUCCESS) {
+            auto blob = Blob::create(WTFMove(buffer), "image/png");
+            return frame.editor().createFragmentForImageAndURL(DOMURL::createObjectURL(*frame.document(), blob));
+        }
+    }
+
     if (selection.hasMarkup() && frame.document())
         return createFragmentFromMarkup(*frame.document(), selection.markup(), emptyString(), DisallowScriptingAndPluginContent);
 

Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (212427 => 212428)


--- trunk/Source/WebCore/editing/mac/EditorMac.mm	2017-02-16 10:17:59 UTC (rev 212427)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm	2017-02-16 12:08:53 UTC (rev 212428)
@@ -486,17 +486,6 @@
     return WTFMove(reader.fragment);
 }
 
-Ref<DocumentFragment> Editor::createFragmentForImageAndURL(const String& url)
-{
-    auto imageElement = HTMLImageElement::create(*m_frame.document());
-    imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
-
-    auto fragment = document().createDocumentFragment();
-    fragment->appendChild(imageElement);
-
-    return fragment;
-}
-
 void Editor::applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits)
 {
     auto& cssValuePool = CSSValuePool::singleton();

Modified: trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp (212427 => 212428)


--- trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2017-02-16 10:17:59 UTC (rev 212427)
+++ trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp	2017-02-16 12:08:53 UTC (rev 212428)
@@ -23,6 +23,7 @@
 #include "config.h"
 #include "PasteboardHelper.h"
 
+#include "BitmapImage.h"
 #include "GtkVersioning.h"
 #include "SelectionData.h"
 #include <gtk/gtk.h>
@@ -113,6 +114,16 @@
         }
     }
 
+#ifndef GTK_API_VERSION_2
+    if (gtk_clipboard_wait_is_image_available(clipboard)) {
+        if (GRefPtr<GdkPixbuf> pixbuf = adoptGRef(gtk_clipboard_wait_for_image(clipboard))) {
+            RefPtr<cairo_surface_t> surface = adoptRef(gdk_cairo_surface_create_from_pixbuf(pixbuf.get(), 1, nullptr));
+            Ref<Image> image = BitmapImage::create(WTFMove(surface));
+            selection.setImage(image.ptr());
+        }
+    }
+#endif
+
     selection.setCanSmartReplace(gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom));
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to