Changeset 212428 in webkit


Ignore:
Timestamp:
Feb 16, 2017 4:08:53 AM (7 years ago)
Author:
Carlos Garcia Campos
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.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r212420 r212428  
     12017-02-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Images are never read from the clipboard
     4        https://bugs.webkit.org/show_bug.cgi?id=168419
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        We write images in the clipboard, but we don't read them.
     9
     10        Fixes: editing/pasteboard/paste-image-using-image-data.html
     11
     12        * editing/Editor.cpp:
     13        (WebCore::Editor::createFragmentForImageAndURL): Moved from EditorMac.mm since it's cross-platform code.
     14        * editing/Editor.h:
     15        * editing/gtk/EditorGtk.cpp:
     16        (WebCore::createFragmentFromPasteboardData): Check if there's an image in the selection, and use
     17        Editor::createFragmentForImageAndURL in that case.
     18        * editing/mac/EditorMac.mm:
     19        (WebCore::Editor::createFragmentForImageAndURL): Deleted.
     20        * platform/gtk/PasteboardHelper.cpp:
     21        (WebCore::PasteboardHelper::getClipboardContents): Check also if there's an image in the clipboard.
     22
    1232017-02-15  Jer Noble  <jer.noble@apple.com>
    224
  • trunk/Source/WebCore/editing/Editor.cpp

    r211964 r212428  
    37413741}
    37423742
     3743Ref<DocumentFragment> Editor::createFragmentForImageAndURL(const String& url)
     3744{
     3745    auto imageElement = HTMLImageElement::create(*m_frame.document());
     3746    imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
     3747
     3748    auto fragment = document().createDocumentFragment();
     3749    fragment->appendChild(imageElement);
     3750
     3751    return fragment;
     3752}
    37433753
    37443754} // namespace WebCore
  • trunk/Source/WebCore/editing/Editor.h

    r210845 r212428  
    484484    bool isGettingDictionaryPopupInfo() const { return m_isGettingDictionaryPopupInfo; }
    485485
     486    Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
     487
    486488private:
    487489    class WebContentReader;
     
    523525    RefPtr<SharedBuffer> imageInWebArchiveFormat(Element&);
    524526    RefPtr<DocumentFragment> createFragmentForImageResourceAndAddResource(RefPtr<ArchiveResource>&&);
    525     Ref<DocumentFragment> createFragmentForImageAndURL(const String&);
    526527    RefPtr<DocumentFragment> createFragmentAndAddResources(NSAttributedString *);
    527528    FragmentAndResources createFragment(NSAttributedString *);
  • trunk/Source/WebCore/editing/gtk/EditorGtk.cpp

    r210109 r212428  
    2828#include "Editor.h"
    2929
     30#include "Blob.h"
    3031#include "CachedImage.h"
     32#include "DOMURL.h"
    3133#include "DocumentFragment.h"
    3234#include "Frame.h"
     
    5557
    5658    const auto& selection = pasteboard.selectionData();
     59    if (selection.hasImage()) {
     60        Vector<uint8_t> buffer;
     61        auto status = cairo_surface_write_to_png_stream(selection.image()->nativeImage().get(), [](void* output, const unsigned char* data, unsigned size) {
     62            if (!reinterpret_cast<Vector<uint8_t>*>(output)->tryAppend(data, size))
     63                return CAIRO_STATUS_WRITE_ERROR;
     64            return CAIRO_STATUS_SUCCESS;
     65        }, &buffer);
     66        if (status == CAIRO_STATUS_SUCCESS) {
     67            auto blob = Blob::create(WTFMove(buffer), "image/png");
     68            return frame.editor().createFragmentForImageAndURL(DOMURL::createObjectURL(*frame.document(), blob));
     69        }
     70    }
     71
    5772    if (selection.hasMarkup() && frame.document())
    5873        return createFragmentFromMarkup(*frame.document(), selection.markup(), emptyString(), DisallowScriptingAndPluginContent);
  • trunk/Source/WebCore/editing/mac/EditorMac.mm

    r211438 r212428  
    487487}
    488488
    489 Ref<DocumentFragment> Editor::createFragmentForImageAndURL(const String& url)
    490 {
    491     auto imageElement = HTMLImageElement::create(*m_frame.document());
    492     imageElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, url);
    493 
    494     auto fragment = document().createDocumentFragment();
    495     fragment->appendChild(imageElement);
    496 
    497     return fragment;
    498 }
    499 
    500489void Editor::applyFontStyles(const String& fontFamily, double fontSize, unsigned fontTraits)
    501490{
  • trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp

    r208841 r212428  
    2424#include "PasteboardHelper.h"
    2525
     26#include "BitmapImage.h"
    2627#include "GtkVersioning.h"
    2728#include "SelectionData.h"
     
    113114        }
    114115    }
     116
     117#ifndef GTK_API_VERSION_2
     118    if (gtk_clipboard_wait_is_image_available(clipboard)) {
     119        if (GRefPtr<GdkPixbuf> pixbuf = adoptGRef(gtk_clipboard_wait_for_image(clipboard))) {
     120            RefPtr<cairo_surface_t> surface = adoptRef(gdk_cairo_surface_create_from_pixbuf(pixbuf.get(), 1, nullptr));
     121            Ref<Image> image = BitmapImage::create(WTFMove(surface));
     122            selection.setImage(image.ptr());
     123        }
     124    }
     125#endif
    115126
    116127    selection.setCanSmartReplace(gtk_clipboard_wait_is_target_available(clipboard, smartPasteAtom));
Note: See TracChangeset for help on using the changeset viewer.