Changeset 57901 in webkit


Ignore:
Timestamp:
Apr 20, 2010 11:52:44 AM (14 years ago)
Author:
Martin Robinson
Message:

2010-04-20 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha Silva.

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

Move most of the PasteboardHelper logic into WebCore. This helps
prepare for WebKit2 and leads to a clearer separation of concerns
between the WebKit and WebCore layers.

  • WebCoreSupport/EditorClientGtk.cpp: (WebKit::collapseSelection): Converted this logic to a GClosure callback. (WebKit::EditorClient::respondToChangedSelection): Collapse selection via GClosure now.
  • WebCoreSupport/PasteboardHelperGtk.cpp: Moved most of the code to WebCore. (WebKit::PasteboardHelperGtk::PasteboardHelperGtk): This constructor just initializes the target list. (WebKit::PasteboardHelperGtk::~PasteboardHelperGtk): The destructor no longer needs to free the target list. (WebKit::PasteboardHelperGtk::getIdForTargetType): Added, virtual method for getting target ids. (WebKit::PasteboardHelperGtk::usePrimarySelectionClipboard): Added, virtual method for querying current clipboard.
  • WebCoreSupport/PasteboardHelperGtk.h: Update method list to reflect reduced functionality.

2010-04-20 Martin Robinson <Martin Robinson>

Reviewed by Gustavo Noronha Silva.

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

Move most of the PasteboardHelper logic into WebCore. This helps
prepare for WebKit2 and leads to a clearer separation of concerns
between the WebKit and WebCore layers.

No new tests as functionality has not changed.

  • GNUmakefile.am: Add PastboardHelper.cpp to list of sources.
  • platform/Pasteboard.h: Added a getter for the PasteboardHelper and made the member private.
  • platform/gtk/PasteboardGtk.cpp: Update PasteboardHelper method calls to use new naming. (WebCore::clipboard_get_contents_cb): Ditto. (WebCore::Pasteboard::helper): Added, member is now private. (WebCore::Pasteboard::writeURL): Ditto. (WebCore::Pasteboard::documentFragment): Update to reflect method renaming. (WebCore::Pasteboard::plainText): Ditto.
  • platform/gtk/PasteboardHelper.cpp: Added. (WebCore::PasteboardHelper::PasteboardHelper): Added. (WebCore::PasteboardHelper::~PasteboardHelper): Added. (WebCore::PasteboardHelper::initializeTargetList): Added, originally from WebKit. (WebCore::widgetFromFrame): Added helper function. (WebCore::PasteboardHelper::getCurrentClipboard): Added, originally from WebKit. (WebCore::PasteboardHelper::getClipboard): Ditto. (WebCore::PasteboardHelper::getPrimarySelectionClipboard): Ditto. (WebCore::PasteboardHelper::targetList): Ditto. (WebCore::PasteboardHelper::fillSelectionData): Ditto. (WebCore::PasteboardHelper::targetListForDataObject): Ditto. (WebCore::getClipboardContentsCallback): Ditto. (WebCore::clearClipboardContentsCallback): Ditto. (WebCore::PasteboardHelper::writeClipboardContents): Ditto.
  • platform/gtk/PasteboardHelper.h: Moved methods from WebKit to WebCore.
Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57900 r57901  
     12010-04-20  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Move most of the PasteboardHelper logic into WebCore. This helps
     9        prepare for WebKit2 and leads to a clearer separation of concerns
     10        between the WebKit and WebCore layers.
     11
     12        No new tests as functionality has not changed.
     13
     14        * GNUmakefile.am: Add PastboardHelper.cpp to list of sources.
     15        * platform/Pasteboard.h: Added a getter for the PasteboardHelper and made the member private.
     16        * platform/gtk/PasteboardGtk.cpp: Update PasteboardHelper method calls to use new naming.
     17        (WebCore::clipboard_get_contents_cb): Ditto.
     18        (WebCore::Pasteboard::helper): Added, member is now private.
     19        (WebCore::Pasteboard::writeURL): Ditto.
     20        (WebCore::Pasteboard::documentFragment): Update to reflect method renaming.
     21        (WebCore::Pasteboard::plainText): Ditto.
     22        * platform/gtk/PasteboardHelper.cpp: Added.
     23        (WebCore::PasteboardHelper::PasteboardHelper): Added.
     24        (WebCore::PasteboardHelper::~PasteboardHelper): Added.
     25        (WebCore::PasteboardHelper::initializeTargetList): Added, originally from WebKit.
     26        (WebCore::widgetFromFrame): Added helper function.
     27        (WebCore::PasteboardHelper::getCurrentClipboard): Added, originally from WebKit.
     28        (WebCore::PasteboardHelper::getClipboard): Ditto.
     29        (WebCore::PasteboardHelper::getPrimarySelectionClipboard): Ditto.
     30        (WebCore::PasteboardHelper::targetList): Ditto.
     31        (WebCore::PasteboardHelper::fillSelectionData): Ditto.
     32        (WebCore::PasteboardHelper::targetListForDataObject): Ditto.
     33        (WebCore::getClipboardContentsCallback): Ditto.
     34        (WebCore::clearClipboardContentsCallback): Ditto.
     35        (WebCore::PasteboardHelper::writeClipboardContents): Ditto.
     36        * platform/gtk/PasteboardHelper.h: Moved methods from WebKit to WebCore.
     37
    1382010-04-20  Simon Fraser  <simon.fraser@apple.com>
    239
  • trunk/WebCore/GNUmakefile.am

    r57900 r57901  
    20932093        WebCore/platform/gtk/MouseEventGtk.cpp \
    20942094        WebCore/platform/gtk/PasteboardGtk.cpp \
     2095        WebCore/platform/gtk/PasteboardHelper.cpp \
    20952096        WebCore/platform/gtk/PasteboardHelper.h \
    20962097        WebCore/platform/gtk/PlatformScreenGtk.cpp \
  • trunk/WebCore/platform/Pasteboard.h

    r56825 r57901  
    109109#if PLATFORM(GTK)
    110110    void setHelper(PasteboardHelper*);
    111     PasteboardHelper* m_helper;
     111    PasteboardHelper* helper();
    112112#endif
    113113
     
    132132    PasteboardPrivate p;
    133133#endif
     134
     135#if PLATFORM(GTK)
     136    PasteboardHelper* m_helper;
     137#endif
    134138};
    135139
  • trunk/WebCore/platform/gtk/PasteboardGtk.cpp

    r56825 r57901  
    5959    PasteboardSelectionData* clipboardData = reinterpret_cast<PasteboardSelectionData*>(data);
    6060    ASSERT(clipboardData);
    61     if ((gint)info == Pasteboard::generalPasteboard()->m_helper->getWebViewTargetInfoHtml())
     61    if (info == Pasteboard::generalPasteboard()->helper()->getIdForTargetType(PasteboardHelper::TargetTypeMarkup))
    6262        gtk_selection_data_set(selection_data, selection_data->target, 8,
    6363                               reinterpret_cast<const guchar*>(clipboardData->markup()),
     
    9090}
    9191
     92PasteboardHelper* Pasteboard::helper()
     93{
     94    return m_helper;
     95}
     96
    9297void Pasteboard::setHelper(PasteboardHelper* helper)
    9398{
     
    122127
    123128    GtkClipboard* clipboard = m_helper->getClipboard(frame);
    124     GtkClipboard* primary = m_helper->getPrimary(frame);
     129    GtkClipboard* primary = m_helper->getPrimarySelectionClipboard(frame);
    125130    CString utf8 = url.string().utf8();
    126131    gtk_clipboard_set_text(clipboard, utf8.data(), utf8.length());
     
    162167{
    163168    GdkAtom textHtml = gdk_atom_intern_static_string("text/html");
    164     GtkClipboard* clipboard = m_helper->getCurrentTarget(frame);
     169    GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame);
    165170    chosePlainText = false;
    166171
     
    197202String Pasteboard::plainText(Frame* frame)
    198203{
    199     GtkClipboard* clipboard = m_helper->getCurrentTarget(frame);
     204    GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame);
    200205
    201206    gchar* utf8 = gtk_clipboard_wait_for_text(clipboard);
  • trunk/WebCore/platform/gtk/PasteboardHelper.h

    r52421 r57901  
    22 * Copyright (C) 2007 Luca Bruno <lethalman88@gmail.com>
    33 * Copyright (C) 2009 Holger Hans Peter Freyther
     4 * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org>
    45 * All rights reserved.
    56 *
     
    3334typedef struct _GtkClipboard GtkClipboard;
    3435typedef struct _GtkTargetList GtkTargetList;
     36typedef struct _GtkWidget GtkWidget;
     37typedef struct _GtkSelectionData GtkSelectionData;
    3538
    3639namespace WebCore {
    3740
     41class DataObjectGtk;
     42
    3843class PasteboardHelper {
    3944public:
    40     virtual ~PasteboardHelper() {};
     45    PasteboardHelper();
     46    virtual ~PasteboardHelper();
    4147
    42     virtual GtkClipboard* getCurrentTarget(Frame*) const = 0;
    43     virtual GtkClipboard* getClipboard(Frame*) const = 0;
    44     virtual GtkClipboard* getPrimary(Frame*) const = 0;
    45     virtual GtkTargetList* targetList() const = 0;
    46     virtual gint getWebViewTargetInfoHtml() const = 0;
     48    GtkClipboard* getCurrentClipboard(Frame*);
     49    GtkClipboard* getClipboard(Frame*) const;
     50    GtkClipboard* getPrimarySelectionClipboard(Frame*) const;
     51    GtkTargetList* targetList() const;
     52    void fillSelectionData(GtkSelectionData*, guint, DataObjectGtk*);
     53    void writeClipboardContents(GtkClipboard*, GClosure*);
     54
     55    enum PasteboardTargetType { TargetTypeText, TargetTypeMarkup, TargetTypeURIList, TargetTypeNetscapeURL, TargetTypeImage, TargetTypeUnknown };
     56    virtual guint getIdForTargetType(PasteboardTargetType) = 0;
     57
     58protected:
     59    void initializeTargetList();
     60    virtual bool usePrimarySelectionClipboard(GtkWidget*) = 0;
     61
     62private:
     63    GtkTargetList* m_targetList;
     64    GtkTargetList* targetListForDataObject(DataObjectGtk*);
    4765};
    4866
  • trunk/WebKit/gtk/ChangeLog

    r57874 r57901  
     12010-04-20  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Reviewed by Gustavo Noronha Silva.
     4
     5        [GTK] Enable DOM clipboard and drag-and-drop access
     6        https://bugs.webkit.org/show_bug.cgi?id=30623
     7
     8        Move most of the PasteboardHelper logic into WebCore. This helps
     9        prepare for WebKit2 and leads to a clearer separation of concerns
     10        between the WebKit and WebCore layers.
     11
     12        * WebCoreSupport/EditorClientGtk.cpp:
     13        (WebKit::collapseSelection): Converted this logic to a GClosure callback.
     14        (WebKit::EditorClient::respondToChangedSelection): Collapse selection via GClosure now.
     15        * WebCoreSupport/PasteboardHelperGtk.cpp: Moved most of the code to WebCore.
     16        (WebKit::PasteboardHelperGtk::PasteboardHelperGtk): This constructor just initializes the target list.
     17        (WebKit::PasteboardHelperGtk::~PasteboardHelperGtk): The destructor no longer needs to free the target list.
     18        (WebKit::PasteboardHelperGtk::getIdForTargetType): Added, virtual method for getting target ids.
     19        (WebKit::PasteboardHelperGtk::usePrimarySelectionClipboard): Added, virtual method for querying current clipboard.
     20        * WebCoreSupport/PasteboardHelperGtk.h: Update method list to reflect reduced functionality.
     21
    1222010-04-19  Diego Escalante Urrelo  <descalante@igalia.com>
    223
  • trunk/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp

    r56825 r57901  
    3434#include <glib.h>
    3535#include "KeyboardEvent.h"
     36#include "markup.h"
    3637#include "NotImplemented.h"
    3738#include "Page.h"
     
    3940#include "PlatformKeyboardEvent.h"
    4041#include "WindowsKeyboardCodes.h"
    41 #include "markup.h"
     42#include "webkitmarshal.h"
    4243#include "webkitprivate.h"
    4344#include <wtf/text/CString.h>
     
    197198}
    198199
     200static WebKitWebView* viewSettingClipboard = 0;
     201static void collapseSelection(GtkClipboard* clipboard, WebKitWebView* webView)
     202{
     203    if (viewSettingClipboard && viewSettingClipboard == webView)
     204        return;
     205
     206    WebCore::Page* corePage = core(webView);
     207    if (!corePage || !corePage->focusController())
     208        return;
     209
     210    Frame* frame = corePage->focusController()->focusedOrMainFrame();
     211
     212    // Collapse the selection without clearing it
     213    ASSERT(frame);
     214    frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
     215}
     216
    199217void EditorClient::respondToChangedSelection()
    200218{
     
    216234        dataObject->clear();
    217235        dataObject->setRange(targetFrame->selection()->toNormalizedRange());
    218         pasteboardHelperInstance()->writeClipboardContents(clipboard, m_webView);
     236
     237        viewSettingClipboard = m_webView;
     238        GClosure* callback = g_cclosure_new_object(G_CALLBACK(collapseSelection), G_OBJECT(m_webView));
     239        g_closure_set_marshal(callback, g_cclosure_marshal_VOID__VOID);
     240        pasteboardHelperInstance()->writeClipboardContents(clipboard, callback);
     241        viewSettingClipboard = 0;
    219242    }
    220243#endif
  • trunk/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp

    r54230 r57901  
    22 *  Copyright (C) 2007 Luca Bruno <lethalman88@gmail.com>
    33 *  Copyright (C) 2009 Holger Hans Peter Freyther
     4 *  Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org>
    45 *
    56 *  This library is free software; you can redistribute it and/or
     
    3334namespace WebKit {
    3435
    35 static GdkAtom gdkMarkupAtom = gdk_atom_intern("text/html", FALSE);
    36 
    3736PasteboardHelperGtk::PasteboardHelperGtk()
    38     : m_targetList(gtk_target_list_new(0, 0))
    3937{
    40     gtk_target_list_add_text_targets(m_targetList, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
    41     gtk_target_list_add(m_targetList, gdkMarkupAtom, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
     38    initializeTargetList();
    4239}
    4340
    4441PasteboardHelperGtk::~PasteboardHelperGtk()
    4542{
    46     gtk_target_list_unref(m_targetList);
    4743}
    4844
    49 GtkClipboard* PasteboardHelperGtk::getCurrentTarget(Frame* frame) const
     45guint PasteboardHelperGtk::getIdForTargetType(PasteboardTargetType type)
    5046{
    51     WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame));
     47    if (type == TargetTypeMarkup)
     48        return WEBKIT_WEB_VIEW_TARGET_INFO_HTML;
     49    if (type == TargetTypeImage)
     50        return WEBKIT_WEB_VIEW_TARGET_INFO_IMAGE;
     51    if (type == TargetTypeURIList)
     52        return WEBKIT_WEB_VIEW_TARGET_INFO_URI_LIST;
     53    if (type == TargetTypeNetscapeURL)
     54        return WEBKIT_WEB_VIEW_TARGET_INFO_NETSCAPE_URL;
    5255
    53     if (webkit_web_view_use_primary_for_paste(webView))
    54         return getPrimary(frame);
    55     else
    56         return getClipboard(frame);
     56    return WEBKIT_WEB_VIEW_TARGET_INFO_TEXT;
    5757}
    5858
    59 GtkClipboard* PasteboardHelperGtk::getClipboard(Frame* frame) const
     59bool PasteboardHelperGtk::usePrimarySelectionClipboard(GtkWidget* widget)
    6060{
    61     WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame));
    62     return gtk_widget_get_clipboard(GTK_WIDGET (webView),
    63                                     GDK_SELECTION_CLIPBOARD);
    64 }
    65 
    66 GtkClipboard* PasteboardHelperGtk::getPrimary(Frame* frame) const
    67 {
    68     WebKitWebView* webView = webkit_web_frame_get_web_view(kit(frame));
    69     return gtk_widget_get_clipboard(GTK_WIDGET (webView),
    70                                     GDK_SELECTION_PRIMARY);
    71 }
    72 
    73 GtkTargetList* PasteboardHelperGtk::targetList() const
    74 {
    75     return m_targetList;
    76 }
    77 
    78 gint PasteboardHelperGtk::getWebViewTargetInfoHtml() const
    79 {
    80     return WEBKIT_WEB_VIEW_TARGET_INFO_HTML;
    81 }
    82 
    83 static void fillSelectionData(GtkSelectionData* selectionData, guint info, DataObjectGtk* dataObject)
    84 {
    85     if (info == WEBKIT_WEB_VIEW_TARGET_INFO_TEXT)
    86         gtk_selection_data_set_text(selectionData, dataObject->text().utf8().data(), -1);
    87     else if (info == WEBKIT_WEB_VIEW_TARGET_INFO_HTML) {
    88         GOwnPtr<gchar> markup(g_strdup(dataObject->markup().utf8().data()));
    89         gtk_selection_data_set(selectionData, selectionData->target, 8,
    90                                reinterpret_cast<const guchar*>(markup.get()),
    91                                strlen(markup.get()));
    92     }
    93 }
    94 
    95 static GtkTargetList* targetListForDataObject(DataObjectGtk* dataObject)
    96 {
    97     GtkTargetList* list = gtk_target_list_new(0, 0);
    98 
    99     if (dataObject->hasText())
    100         gtk_target_list_add_text_targets(list, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT);
    101 
    102     if (dataObject->hasMarkup())
    103         gtk_target_list_add(list, gdkMarkupAtom, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML);
    104 
    105     return list;
    106 }
    107 
    108 static DataObjectGtk* settingClipboardDataObject = 0;
    109 static gpointer settingClipboardData = 0;
    110 static void getClipboardContentsCallback(GtkClipboard* clipboard, GtkSelectionData *selectionData, guint info, gpointer data)
    111 {
    112     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    113     ASSERT(dataObject);
    114     fillSelectionData(selectionData, info, dataObject);
    115 }
    116 
    117 static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer data)
    118 {
    119     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    120     ASSERT(dataObject);
    121 
    122     // Only clear the DataObject for this clipboard if we are not currently setting it.
    123     if (dataObject != settingClipboardDataObject)
    124         dataObject->clear();
    125 
    126     // Only collapse the selection if this is an X11 primary clipboard
    127     // and we aren't currently setting the clipboard for this WebView.
    128     if (!data || data == settingClipboardData)
    129         return;
    130 
    131     WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data);
    132     WebCore::Page* corePage = core(webView);
    133 
    134     if (!corePage || !corePage->focusController()) {
    135         g_object_unref(webView);
    136         return;
    137     }
    138 
    139     Frame* frame = corePage->focusController()->focusedOrMainFrame();
    140 
    141     // Collapse the selection without clearing it
    142     ASSERT(frame);
    143     frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
    144 
    145     g_object_unref(webView);
    146 }
    147 
    148 void PasteboardHelperGtk::writeClipboardContents(GtkClipboard* clipboard, gpointer data)
    149 {
    150     DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    151     GtkTargetList* list = targetListForDataObject(dataObject);
    152 
    153     int numberOfTargets;
    154     GtkTargetEntry* table = gtk_target_table_new_from_list(list, &numberOfTargets);
    155 
    156     if (numberOfTargets > 0 && table) {
    157         settingClipboardDataObject = dataObject;
    158         settingClipboardData = data;
    159 
    160         // Protect the web view from being destroyed before one of the clipboard callbacks
    161         // is called. Balanced in both getClipboardContentsCallback and
    162         // clearClipboardContentsCallback.
    163         WebKitWebView* webView = static_cast<WebKitWebView*>(data);
    164         g_object_ref(webView);
    165 
    166         gboolean succeeded = gtk_clipboard_set_with_data(clipboard, table, numberOfTargets,
    167                                                          getClipboardContentsCallback,
    168                                                          clearClipboardContentsCallback, data);
    169         if (!succeeded)
    170             g_object_unref(webView);
    171 
    172         settingClipboardDataObject = 0;
    173         settingClipboardData = 0;
    174     } else
    175         gtk_clipboard_clear(clipboard);
    176 
    177     if (table)
    178         gtk_target_table_free(table, numberOfTargets);
    179 
    180     gtk_target_list_unref(list);
     61    return webkit_web_view_use_primary_for_paste(WEBKIT_WEB_VIEW((widget)));
    18162}
    18263
  • trunk/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h

    r53264 r57901  
    22 * Copyright (C) 2007 Luca Bruno <lethalman88@gmail.com>
    33 * Copyright (C) 2009 Holger Hans Peter Freyther
     4 * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org>
    45 * All rights reserved.
    56 *
     
    4243    PasteboardHelperGtk();
    4344    ~PasteboardHelperGtk();
    44     virtual GtkClipboard* getCurrentTarget(Frame*) const;
    45     virtual GtkClipboard* getClipboard(Frame*) const;
    46     virtual GtkClipboard* getPrimary(Frame*) const;
    47     virtual GtkTargetList* targetList() const;
    48     virtual gint getWebViewTargetInfoHtml() const;
     45    virtual guint getIdForTargetType(PasteboardTargetType);
    4946
    50     void writeClipboardContents(GtkClipboard* clipboard, gpointer data = 0);
    51 
    52 private:
    53     GtkTargetList* m_targetList;
     47protected:
     48    virtual bool usePrimarySelectionClipboard(GtkWidget*);
    5449};
    5550
Note: See TracChangeset for help on using the changeset viewer.