Changeset 58470 in webkit


Ignore:
Timestamp:
Apr 28, 2010 9:13:23 PM (14 years ago)
Author:
Martin Robinson
Message:

2010-04-28 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha.

[GTK] Enable DOM clipboard and drag-and-drop access
https://bugs.webkit.org/show_bug.cgi?id=30623

Make ClipboardGtk a "live" DataTransfer object, able to modify
the clipboard when setData(...) is called.

  • platform/gtk/Skipped: Uncomment tests that are now passing.

2010-04-28 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha.

[GTK] Enable DOM clipboard and drag-and-drop access
https://bugs.webkit.org/show_bug.cgi?id=30623

Make ClipboardGtk a "live" DataTransfer object, able to modify
the clipboard when setData(...) is called.

  • platform/gtk/ClipboardGtk.cpp: (WebCore::Editor::newGeneralClipboard): Pass the GtkClipboard into the factory method. (WebCore::ClipboardGtk::ClipboardGtk): Create two separate constructors, one for DnD data and one for clipboard data. (WebCore::dataObjectTypeFromHTMLClipboardType): Added. (WebCore::ClipboardGtk::clearData): Clear the member DataObject, optionally write the clipboard. (WebCore::ClipboardGtk::clearAllData): Ditto. (WebCore::joinURIList): Added. (WebCore::ClipboardGtk::getData): Get the data from the clipboard, if possible. (WebCore::ClipboardGtk::setData): Write data to the DataObject and maybe the clipboard. (WebCore::ClipboardGtk::types): Read the clipboard/DataObject to find applicable types. (WebCore::ClipboardGtk::files): Read the clipboard/DataObject to find the files. (WebCore::ClipboardGtk::writeURL): Write to the DataObject and maybe the clipboard. (WebCore::ClipboardGtk::writeRange): Ditto. (WebCore::ClipboardGtk::writePlainText): Ditto. (WebCore::ClipboardGtk::hasData): Query the clipboard/DataObject.
  • platform/gtk/ClipboardGtk.h: (WebCore::ClipboardGtk::create): Added one factory for pasteboard-backed DataObjects and one for DnD-backed objects.
  • platform/gtk/DataObjectGtk.cpp: (WebCore::replaceNonBreakingSpaceWithSpace): Added this helper function to clean &nbsp; from plain text. (WebCore::DataObjectGtk::markup): Actually return the range if it's set. (WebCore::DataObjectGtk::setText): Clean &nbsp; from plain text. (WebCore::DataObjectGtk::clearText): Added. (WebCore::DataObjectGtk::clearMarkup): Added.
  • platform/gtk/DataObjectGtk.h: (WebCore::DataObjectGtk::clearURIList): Added. (WebCore::DataObjectGtk::clearImage): Added.
  • platform/gtk/PasteboardHelper.cpp: (WebCore::PasteboardHelper::initializeTargetList): Added target ID's for URI list and Netscape URL targets. (WebCore::urisToKURLVector): Added. (WebCore::PasteboardHelper::getClipboardContents): Added. (WebCore::PasteboardHelper::fillSelectionData): Added logic for URI lists and Netscape URLs. (WebCore::PasteboardHelper::targetListForDataObject): Ditto.
  • platform/gtk/PasteboardHelper.h: Added default argument to writeClipboardContents and new method.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r58447 r58470  
     12010-04-28  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Make ClipboardGtk a "live" DataTransfer object, able to modify
     9        the clipboard when setData(...) is called.
     10
     11        * platform/gtk/Skipped: Uncomment tests that are now passing.
     12
    1132010-04-28  Evan Martin  <evan@chromium.org>
    214
  • trunk/LayoutTests/platform/gtk/Skipped

    r58417 r58470  
    741741editing/deleting/type-delete-after-quote-2.html
    742742editing/execCommand/4128080-2.html
    743 editing/execCommand/copy-without-selection.html
    744743editing/execCommand/createLink.html
    745744editing/execCommand/delete-image-in-anchor.html
     
    774773editing/pasteboard/4744008.html
    775774editing/pasteboard/5368833.html
    776 editing/pasteboard/5665299.html
    777775editing/pasteboard/5780697-2.html
    778776editing/pasteboard/copy-in-password-field.html
    779 editing/pasteboard/copy-paste-float.html
    780777editing/pasteboard/drag-image-in-about-blank-frame.html
    781778editing/pasteboard/file-input-files-access.html
    782779editing/pasteboard/get-data-text-plain-drop.html
    783 editing/pasteboard/get-data-text-plain-paste.html
    784 editing/pasteboard/onpaste-text-html.html
    785 editing/pasteboard/paste-blockquote-before-blockquote.html
    786 editing/pasteboard/paste-double-nested-blockquote-before-blockquote.html
    787780editing/pasteboard/paste-into-anchor-text.html
    788781editing/pasteboard/paste-plaintext-user-select-none.html
  • trunk/WebCore/ChangeLog

    r58468 r58470  
     12010-04-28  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Make ClipboardGtk a "live" DataTransfer object, able to modify
     9        the clipboard when setData(...) is called.
     10
     11        * platform/gtk/ClipboardGtk.cpp:
     12        (WebCore::Editor::newGeneralClipboard): Pass the GtkClipboard into the factory method.
     13        (WebCore::ClipboardGtk::ClipboardGtk): Create two separate constructors, one for DnD data and one for clipboard data.
     14        (WebCore::dataObjectTypeFromHTMLClipboardType): Added.
     15        (WebCore::ClipboardGtk::clearData): Clear the member DataObject, optionally write the clipboard.
     16        (WebCore::ClipboardGtk::clearAllData): Ditto.
     17        (WebCore::joinURIList): Added.
     18        (WebCore::ClipboardGtk::getData): Get the data from the clipboard, if possible.
     19        (WebCore::ClipboardGtk::setData): Write data to the DataObject and maybe the clipboard.
     20        (WebCore::ClipboardGtk::types): Read the clipboard/DataObject to find applicable types.
     21        (WebCore::ClipboardGtk::files): Read the clipboard/DataObject to find the files.
     22        (WebCore::ClipboardGtk::writeURL): Write to the DataObject and maybe the clipboard.
     23        (WebCore::ClipboardGtk::writeRange): Ditto.
     24        (WebCore::ClipboardGtk::writePlainText): Ditto.
     25        (WebCore::ClipboardGtk::hasData): Query the clipboard/DataObject.
     26        * platform/gtk/ClipboardGtk.h:
     27        (WebCore::ClipboardGtk::create): Added one factory for pasteboard-backed DataObjects and one for DnD-backed objects.
     28        * platform/gtk/DataObjectGtk.cpp:
     29        (WebCore::replaceNonBreakingSpaceWithSpace): Added this helper function to clean &nbsp; from plain text.
     30        (WebCore::DataObjectGtk::markup): Actually return the range if it's set.
     31        (WebCore::DataObjectGtk::setText): Clean &nbsp; from plain text.
     32        (WebCore::DataObjectGtk::clearText): Added.
     33        (WebCore::DataObjectGtk::clearMarkup): Added.
     34        * platform/gtk/DataObjectGtk.h:
     35        (WebCore::DataObjectGtk::clearURIList): Added.
     36        (WebCore::DataObjectGtk::clearImage): Added.
     37        * platform/gtk/PasteboardHelper.cpp:
     38        (WebCore::PasteboardHelper::initializeTargetList): Added target ID's for URI list and Netscape URL targets.
     39        (WebCore::urisToKURLVector): Added.
     40        (WebCore::PasteboardHelper::getClipboardContents): Added.
     41        (WebCore::PasteboardHelper::fillSelectionData): Added logic for URI lists and Netscape URLs.
     42        (WebCore::PasteboardHelper::targetListForDataObject): Ditto.
     43        * platform/gtk/PasteboardHelper.h: Added default argument to writeClipboardContents and new method.
     44
    1452010-04-28  Martin Robinson  <mrobinson@webkit.org>
    246
  • trunk/WebCore/platform/gtk/ClipboardGtk.cpp

    r56825 r58470  
    2525#include "Image.h"
    2626#include "NotImplemented.h"
     27#include "Pasteboard.h"
     28#include "PasteboardHelper.h"
    2729#include "RenderImage.h"
    2830#include "StringHash.h"
     
    3335namespace WebCore {
    3436
     37enum ClipboardType {
     38    ClipboardTypeText,
     39    ClipboardTypeMarkup,
     40    ClipboardTypeURIList,
     41    ClipboardTypeURL,
     42    ClipboardTypeImage,
     43    ClipboardTypeUnknown
     44};
     45
    3546PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy)
    3647{
    37     return ClipboardGtk::create(policy, false);
    38 }
    39 
    40 ClipboardGtk::ClipboardGtk(ClipboardAccessPolicy policy, bool forDragging)
     48    return ClipboardGtk::create(policy, gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD), false);
     49}
     50
     51ClipboardGtk::ClipboardGtk(ClipboardAccessPolicy policy, GtkClipboard* clipboard)
     52    : Clipboard(policy, false)
     53    , m_dataObject(DataObjectGtk::forClipboard(clipboard))
     54    , m_clipboard(clipboard)
     55    , m_helper(Pasteboard::generalPasteboard()->helper())
     56{
     57}
     58
     59ClipboardGtk::ClipboardGtk(ClipboardAccessPolicy policy, PassRefPtr<DataObjectGtk> dataObject, bool forDragging)
    4160    : Clipboard(policy, forDragging)
     61    , m_dataObject(dataObject)
     62    , m_clipboard(0)
     63    , m_helper(Pasteboard::generalPasteboard()->helper())
    4264{
    4365}
     
    4769}
    4870
    49 void ClipboardGtk::clearData(const String&)
    50 {
    51     notImplemented();
    52 }
     71static ClipboardType dataObjectTypeFromHTMLClipboardType(const String& rawType)
     72{
     73    String type(rawType.stripWhiteSpace());
     74
     75    // Two special cases for IE compatibility
     76    if (type == "Text")
     77        return ClipboardTypeText;
     78    if (type == "URL")
     79        return ClipboardTypeURL;
     80
     81    // From the Mac port: Ignore any trailing charset - JS strings are
     82    // Unicode, which encapsulates the charset issue.
     83    if (type == "text/plain" || type.startsWith("text/plain;"))
     84        return ClipboardTypeText;
     85    if (type == "text/html" || type.startsWith("text/html;"))
     86        return ClipboardTypeMarkup;
     87    if (type == "Files" || type == "text/uri-list" || type.startsWith("text/uri-list;"))
     88        return ClipboardTypeURIList;
     89
     90    // Not a known type, so just default to using the text portion.
     91    return ClipboardTypeUnknown;
     92}
     93
     94void ClipboardGtk::clearData(const String& typeString)
     95{
     96    if (policy() != ClipboardWritable)
     97        return;
     98
     99    ClipboardType type = dataObjectTypeFromHTMLClipboardType(typeString);
     100    switch (type) {
     101    case ClipboardTypeURIList:
     102    case ClipboardTypeURL:
     103        m_dataObject->clearURIList();
     104        break;
     105    case ClipboardTypeMarkup:
     106        m_dataObject->clearMarkup();
     107        break;
     108    case ClipboardTypeText:
     109        m_dataObject->clearText();
     110        break;
     111    case ClipboardTypeUnknown:
     112    default:
     113        m_dataObject->clear();
     114    }
     115
     116    if (m_clipboard)
     117        m_helper->writeClipboardContents(m_clipboard);
     118}
     119
    53120
    54121void ClipboardGtk::clearAllData()
    55122{
    56     notImplemented();
    57 }
    58 
    59 String ClipboardGtk::getData(const String&, bool &success) const
    60 {
    61     notImplemented();
    62     success = false;
     123    if (policy() != ClipboardWritable)
     124        return;
     125
     126    m_dataObject->clear();
     127
     128    if (m_clipboard)
     129        m_helper->writeClipboardContents(m_clipboard);
     130}
     131
     132static String joinURIList(Vector<KURL> uriList)
     133{
     134    if (uriList.isEmpty())
     135        return String();
     136
     137    String joined(uriList[0].string());
     138    for (size_t i = 1; i < uriList.size(); i++) {
     139        joined.append("\r\n");
     140        joined.append(uriList[i].string());
     141    }
     142
     143    return joined;
     144}
     145
     146String ClipboardGtk::getData(const String& typeString, bool& success) const
     147{
     148    success = false; // Pessimism.
     149    if (policy() != ClipboardReadable || !m_dataObject)
     150        return String();
     151
     152    if (m_clipboard)
     153        m_helper->getClipboardContents(m_clipboard);
     154
     155    ClipboardType type = dataObjectTypeFromHTMLClipboardType(typeString);
     156    if (type == ClipboardTypeURIList) {
     157        if (!m_dataObject->hasURIList())
     158            return String();
     159        success = true;
     160        return joinURIList(m_dataObject->uriList());
     161    }
     162
     163    if (type == ClipboardTypeURL) {
     164        if (!m_dataObject->hasURL())
     165            return String();
     166        success = true;
     167        return m_dataObject->url();
     168    }
     169
     170    if (type == ClipboardTypeMarkup) {
     171        if (!m_dataObject->hasMarkup())
     172            return String();
     173        success = true;
     174        return m_dataObject->markup();
     175    }
     176
     177    if (type == ClipboardTypeText) {
     178        if (!m_dataObject->hasText())
     179                return String();
     180        success = true;
     181        return m_dataObject->text();
     182    }
     183
    63184    return String();
    64185}
    65186
    66 bool ClipboardGtk::setData(const String&, const String&)
    67 {
    68     notImplemented();
    69     return false;
     187bool ClipboardGtk::setData(const String& typeString, const String& data)
     188{
     189    if (policy() != ClipboardWritable)
     190        return false;
     191
     192    bool success = false;
     193    ClipboardType type = dataObjectTypeFromHTMLClipboardType(typeString);
     194    if (type == ClipboardTypeURIList || type == ClipboardTypeURL) {
     195        Vector<KURL> uriList;
     196        gchar** uris = g_uri_list_extract_uris(data.utf8().data());
     197        if (uris) {
     198            gchar** currentURI = uris;
     199            while (*currentURI) {
     200                uriList.append(KURL(KURL(), *currentURI));
     201                currentURI++;
     202            }
     203            g_strfreev(uris);
     204            m_dataObject->setURIList(uriList);
     205            success = true;
     206        }
     207    } else if (type == ClipboardTypeMarkup) {
     208        m_dataObject->setMarkup(data);
     209        success = true;
     210    } else if (type == ClipboardTypeText) {
     211        m_dataObject->setText(data);
     212        success = true;
     213    }
     214
     215    if (success && m_clipboard)
     216        m_helper->writeClipboardContents(m_clipboard);
     217
     218    return success;
    70219}
    71220
    72221HashSet<String> ClipboardGtk::types() const
    73222{
    74     notImplemented();
    75     return HashSet<String>();
     223    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
     224        return HashSet<String>();
     225
     226    if (m_clipboard)
     227        m_helper->getClipboardContents(m_clipboard);
     228
     229    HashSet<String> types;
     230    if (m_dataObject->hasText()) {
     231        types.add("text/plain");
     232        types.add("Text");
     233    }
     234
     235    if (m_dataObject->hasMarkup())
     236        types.add("text/html");
     237
     238    if (m_dataObject->hasURIList()) {
     239        types.add("text/uri-list");
     240        types.add("URL");
     241        types.add("Files");
     242    }
     243
     244    return types;
    76245}
    77246
    78247PassRefPtr<FileList> ClipboardGtk::files() const
    79248{
    80     notImplemented();
    81     return 0;
     249    if (policy() != ClipboardReadable)
     250        return FileList::create();
     251
     252    if (m_clipboard)
     253        m_helper->getClipboardContents(m_clipboard);
     254
     255    RefPtr<FileList> fileList = FileList::create();
     256    Vector<String> fileVector(m_dataObject->files());
     257
     258    for (size_t i = 0; i < fileVector.size(); i++)
     259        fileList->append(File::create(fileVector[i]));
     260
     261    return fileList.release();
    82262}
    83263
     
    152332void ClipboardGtk::writeURL(const KURL& url, const String& label, Frame*)
    153333{
    154     GtkClipboard* textClipboard = gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardText"));
    155     GtkClipboard* urlClipboard = gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardUrl"));
    156     GtkClipboard* urlLabelClipboard = gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardUrlLabel"));
    157 
    158     gtk_clipboard_clear(textClipboard);
    159     gtk_clipboard_clear(urlClipboard);
    160     gtk_clipboard_clear(urlLabelClipboard);
    161 
    162     gtk_clipboard_set_text(textClipboard, url.string().utf8().data(), -1);
    163     gtk_clipboard_set_text(urlClipboard, url.string().utf8().data(), -1);
    164     gtk_clipboard_set_text(urlLabelClipboard, label.utf8().data(), -1);
     334    String actualLabel(label);
     335    if (actualLabel.isEmpty())
     336        actualLabel = url;
     337
     338    m_dataObject->setText(url.string());
     339
     340    Vector<UChar> markup;
     341    append(markup, "<a href=\"");
     342    append(markup, url.string());
     343    append(markup, "\">");
     344    append(markup, label);
     345    append(markup, "</a>");
     346    m_dataObject->setMarkup(String::adopt(markup));
     347
     348    Vector<KURL> uriList;
     349    uriList.append(url);
     350    m_dataObject->setURIList(uriList);
     351
     352    if (m_clipboard)
     353        m_helper->writeClipboardContents(m_clipboard);
    165354}
    166355
    167356void ClipboardGtk::writeRange(Range* range, Frame* frame)
    168357{
    169     GtkClipboard* textClipboard = gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardText"));
    170     GtkClipboard* htmlClipboard = gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardHtml"));
    171 
    172     gtk_clipboard_clear(textClipboard);
    173     gtk_clipboard_clear(htmlClipboard);
    174 
    175     gtk_clipboard_set_text(textClipboard, frame->selectedText().utf8().data(), -1);
    176     gtk_clipboard_set_text(htmlClipboard, createMarkup(range, 0, AnnotateForInterchange).utf8().data(), -1);
     358    ASSERT(range);
     359
     360    m_dataObject->setText(frame->selectedText());
     361    m_dataObject->setMarkup(createMarkup(range, 0, AnnotateForInterchange));
     362
     363    if (m_clipboard)
     364        m_helper->writeClipboardContents(m_clipboard);
    177365}
    178366
    179367void ClipboardGtk::writePlainText(const String& text)
    180368{
    181     GtkClipboard* textClipboard = gtk_clipboard_get(gdk_atom_intern_static_string("WebKitClipboardText"));
    182    
    183     gtk_clipboard_clear(textClipboard);
    184    
    185     gtk_clipboard_set_text(textClipboard, text.utf8().data(), -1);
    186 }
    187    
     369    m_dataObject->setText(text);
     370
     371    if (m_clipboard)
     372        m_helper->writeClipboardContents(m_clipboard);
     373}
     374
    188375bool ClipboardGtk::hasData()
    189376{
    190     notImplemented();
    191     return false;
    192 }
    193 
    194 }
     377    if (m_clipboard)
     378        m_helper->getClipboardContents(m_clipboard);
     379
     380    return m_dataObject->hasText() || m_dataObject->hasMarkup()
     381        || m_dataObject->hasURIList() || m_dataObject->hasImage();
     382}
     383
     384}
  • trunk/WebCore/platform/gtk/ClipboardGtk.h

    r54368 r58470  
    2929
    3030#include "Clipboard.h"
     31#include "DataObjectGtk.h"
     32
     33typedef struct _GtkClipboard GtkClipboard;
    3134
    3235namespace WebCore {
    3336    class CachedImage;
     37    class PasteboardHelper;
    3438
    3539    // State available during IE's events for drag and drop and copy/paste
     
    3741    class ClipboardGtk : public Clipboard {
    3842    public:
     43        static PassRefPtr<ClipboardGtk> create(ClipboardAccessPolicy policy, GtkClipboard* clipboard, bool isForDragging)
     44        {
     45            return adoptRef(new ClipboardGtk(policy, clipboard));
     46        }
     47
    3948        static PassRefPtr<ClipboardGtk> create(ClipboardAccessPolicy policy, bool isForDragging)
    4049        {
    41             return adoptRef(new ClipboardGtk(policy, isForDragging));
     50            return adoptRef(new ClipboardGtk(policy, DataObjectGtk::create(), isForDragging));
    4251        }
    4352        virtual ~ClipboardGtk();
     
    6675
    6776    private:
    68         ClipboardGtk(ClipboardAccessPolicy, bool);
     77        ClipboardGtk(ClipboardAccessPolicy, GtkClipboard*);
     78        ClipboardGtk(ClipboardAccessPolicy, PassRefPtr<DataObjectGtk>, bool);
     79
     80        RefPtr<DataObjectGtk> m_dataObject;
     81        GtkClipboard* m_clipboard;
     82        PasteboardHelper* m_helper;
    6983    };
    7084}
  • trunk/WebCore/platform/gtk/DataObjectGtk.cpp

    r53264 r58470  
    2525namespace WebCore {
    2626
     27static void replaceNonBreakingSpaceWithSpace(String& str)
     28{
     29    static const UChar NonBreakingSpaceCharacter = 0xA0;
     30    static const UChar SpaceCharacter = ' ';
     31    str.replace(NonBreakingSpaceCharacter, SpaceCharacter);
     32}
     33
    2734String DataObjectGtk::text()
    2835{
     
    3542{
    3643    if (m_range)
    37         createMarkup(m_range.get(), 0, AnnotateForInterchange);
     44        return createMarkup(m_range.get(), 0, AnnotateForInterchange);
    3845    return m_markup;
    3946}
     
    4350    m_range = 0;
    4451    m_text = newText;
     52    replaceNonBreakingSpaceWithSpace(m_text);
    4553}
    4654
     
    4957    m_range = 0;
    5058    m_markup = newMarkup;
     59}
     60
     61void DataObjectGtk::clearText()
     62{
     63    m_range = 0;
     64    m_text = "";
     65}
     66
     67void DataObjectGtk::clearMarkup()
     68{
     69    m_range = 0;
     70    m_markup = "";
    5171}
    5272
  • trunk/WebCore/platform/gtk/DataObjectGtk.h

    r56825 r58470  
    5151    bool hasURIList() { return !m_uriList.isEmpty(); }
    5252    bool hasImage() { return m_image; }
     53    void clearURIList() { m_uriList.clear(); }
     54    void clearImage() { m_image = 0; }
    5355    GdkDragContext* dragContext() { return m_dragContext.get(); }
    5456
     
    6264    String urlLabel();
    6365    void clear();
     66    void clearText();
     67    void clearMarkup();
    6468
    6569    static DataObjectGtk* forClipboard(GtkClipboard*);
  • trunk/WebCore/platform/gtk/PasteboardHelper.cpp

    r57901 r58470  
    2727#include "Page.h"
    2828#include "Pasteboard.h"
     29#include "TextResourceDecoder.h"
    2930#include <gtk/gtk.h>
    3031#include <wtf/gobject/GOwnPtr.h>
     
    3334
    3435static GdkAtom gdkMarkupAtom = gdk_atom_intern("text/html", FALSE);
     36static GdkAtom netscapeURLAtom = gdk_atom_intern("_NETSCAPE_URL", FALSE);
     37static GdkAtom uriListAtom = gdk_atom_intern("text/uri-list", FALSE);
    3538
    3639PasteboardHelper::PasteboardHelper()
     
    4952    gtk_target_list_add_text_targets(m_targetList, getIdForTargetType(TargetTypeText));
    5053    gtk_target_list_add(m_targetList, gdkMarkupAtom, 0, getIdForTargetType(TargetTypeMarkup));
     54    gtk_target_list_add_uri_targets(m_targetList, getIdForTargetType(TargetTypeURIList));
     55    gtk_target_list_add(m_targetList, netscapeURLAtom, 0, getIdForTargetType(TargetTypeNetscapeURL));
    5156}
    5257
     
    8590}
    8691
     92static Vector<KURL> urisToKURLVector(gchar** uris)
     93{
     94    ASSERT(uris);
     95
     96    Vector<KURL> uriList;
     97    for (int i = 0; *(uris + i); i++)
     98        uriList.append(KURL(KURL(), *(uris + i)));
     99
     100    return uriList;
     101}
     102
     103void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard)
     104{
     105    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
     106    ASSERT(dataObject);
     107
     108    if (gtk_clipboard_wait_is_text_available(clipboard)) {
     109        GOwnPtr<gchar> textData(gtk_clipboard_wait_for_text(clipboard));
     110        if (textData)
     111            dataObject->setText(String::fromUTF8(textData.get()));
     112    }
     113
     114    if (gtk_clipboard_wait_is_target_available(clipboard, gdkMarkupAtom)) {
     115       if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, gdkMarkupAtom)) {
     116          RefPtr<TextResourceDecoder> decoder(TextResourceDecoder::create("text/plain", "UTF-8", true));
     117          String markup(decoder->decode(reinterpret_cast<char*>(data->data), data->length));
     118          markup += decoder->flush();
     119          dataObject->setMarkup(markup);
     120          gtk_selection_data_free(data);
     121       }
     122    }
     123
     124    if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) {
     125        if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, uriListAtom)) {
     126            gchar** uris = gtk_selection_data_get_uris(data);
     127            if (uris) {
     128                dataObject->setURIList(urisToKURLVector(uris));
     129                g_strfreev(uris);
     130            }
     131            gtk_selection_data_free(data);
     132        }
     133    }
     134}
     135
    87136void PasteboardHelper::fillSelectionData(GtkSelectionData* selectionData, guint info, DataObjectGtk* dataObject)
    88137{
    89138    if (info == getIdForTargetType(TargetTypeText))
    90139        gtk_selection_data_set_text(selectionData, dataObject->text().utf8().data(), -1);
     140
    91141    else if (info == getIdForTargetType(TargetTypeMarkup)) {
    92142        GOwnPtr<gchar> markup(g_strdup(dataObject->markup().utf8().data()));
    93143        gtk_selection_data_set(selectionData, selectionData->target, 8,
    94                                reinterpret_cast<const guchar*>(markup.get()),
    95                                strlen(markup.get()));
     144            reinterpret_cast<const guchar*>(markup.get()), strlen(markup.get()));
     145
     146    } else if (info == getIdForTargetType(TargetTypeURIList)) {
     147        Vector<KURL> uriList(dataObject->uriList());
     148        gchar** uris = g_new0(gchar*, uriList.size() + 1);
     149        for (size_t i = 0; i < uriList.size(); i++)
     150            uris[i] = g_strdup(uriList[i].string().utf8().data());
     151
     152        gtk_selection_data_set_uris(selectionData, uris);
     153        g_strfreev(uris);
     154
     155    } else if (info == getIdForTargetType(TargetTypeNetscapeURL) && dataObject->hasURL()) {
     156        String url(dataObject->url());
     157        String result(url);
     158        result.append("\n");
     159
     160        if (dataObject->hasText())
     161            result.append(dataObject->text());
     162        else
     163            result.append(url);
     164
     165        GOwnPtr<gchar> resultData(g_strdup(result.utf8().data()));
     166        gtk_selection_data_set(selectionData, selectionData->target, 8,
     167            reinterpret_cast<const guchar*>(resultData.get()), strlen(resultData.get()));
    96168    }
    97169}
     
    106178    if (dataObject->hasMarkup())
    107179        gtk_target_list_add(list, gdkMarkupAtom, 0, getIdForTargetType(TargetTypeMarkup));
     180
     181    if (dataObject->hasURIList()) {
     182        gtk_target_list_add_uri_targets(list, getIdForTargetType(TargetTypeURIList));
     183        gtk_target_list_add(list, netscapeURLAtom, 0, getIdForTargetType(TargetTypeNetscapeURL));
     184    }
    108185
    109186    return list;
  • trunk/WebCore/platform/gtk/PasteboardHelper.h

    r57901 r58470  
    5151    GtkTargetList* targetList() const;
    5252    void fillSelectionData(GtkSelectionData*, guint, DataObjectGtk*);
    53     void writeClipboardContents(GtkClipboard*, GClosure*);
     53    void writeClipboardContents(GtkClipboard*, GClosure* closure = 0);
     54    void getClipboardContents(GtkClipboard*);
    5455
    5556    enum PasteboardTargetType { TargetTypeText, TargetTypeMarkup, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeImage, TargetTypeUnknown };
Note: See TracChangeset for help on using the changeset viewer.