Changeset 57901 in webkit
- Timestamp:
- Apr 20, 2010 11:52:44 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r57900 r57901 1 2010-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 1 38 2010-04-20 Simon Fraser <simon.fraser@apple.com> 2 39 -
trunk/WebCore/GNUmakefile.am
r57900 r57901 2093 2093 WebCore/platform/gtk/MouseEventGtk.cpp \ 2094 2094 WebCore/platform/gtk/PasteboardGtk.cpp \ 2095 WebCore/platform/gtk/PasteboardHelper.cpp \ 2095 2096 WebCore/platform/gtk/PasteboardHelper.h \ 2096 2097 WebCore/platform/gtk/PlatformScreenGtk.cpp \ -
trunk/WebCore/platform/Pasteboard.h
r56825 r57901 109 109 #if PLATFORM(GTK) 110 110 void setHelper(PasteboardHelper*); 111 PasteboardHelper* m_helper;111 PasteboardHelper* helper(); 112 112 #endif 113 113 … … 132 132 PasteboardPrivate p; 133 133 #endif 134 135 #if PLATFORM(GTK) 136 PasteboardHelper* m_helper; 137 #endif 134 138 }; 135 139 -
trunk/WebCore/platform/gtk/PasteboardGtk.cpp
r56825 r57901 59 59 PasteboardSelectionData* clipboardData = reinterpret_cast<PasteboardSelectionData*>(data); 60 60 ASSERT(clipboardData); 61 if ( (gint)info == Pasteboard::generalPasteboard()->m_helper->getWebViewTargetInfoHtml())61 if (info == Pasteboard::generalPasteboard()->helper()->getIdForTargetType(PasteboardHelper::TargetTypeMarkup)) 62 62 gtk_selection_data_set(selection_data, selection_data->target, 8, 63 63 reinterpret_cast<const guchar*>(clipboardData->markup()), … … 90 90 } 91 91 92 PasteboardHelper* Pasteboard::helper() 93 { 94 return m_helper; 95 } 96 92 97 void Pasteboard::setHelper(PasteboardHelper* helper) 93 98 { … … 122 127 123 128 GtkClipboard* clipboard = m_helper->getClipboard(frame); 124 GtkClipboard* primary = m_helper->getPrimary (frame);129 GtkClipboard* primary = m_helper->getPrimarySelectionClipboard(frame); 125 130 CString utf8 = url.string().utf8(); 126 131 gtk_clipboard_set_text(clipboard, utf8.data(), utf8.length()); … … 162 167 { 163 168 GdkAtom textHtml = gdk_atom_intern_static_string("text/html"); 164 GtkClipboard* clipboard = m_helper->getCurrent Target(frame);169 GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame); 165 170 chosePlainText = false; 166 171 … … 197 202 String Pasteboard::plainText(Frame* frame) 198 203 { 199 GtkClipboard* clipboard = m_helper->getCurrent Target(frame);204 GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame); 200 205 201 206 gchar* utf8 = gtk_clipboard_wait_for_text(clipboard); -
trunk/WebCore/platform/gtk/PasteboardHelper.h
r52421 r57901 2 2 * Copyright (C) 2007 Luca Bruno <lethalman88@gmail.com> 3 3 * Copyright (C) 2009 Holger Hans Peter Freyther 4 * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org> 4 5 * All rights reserved. 5 6 * … … 33 34 typedef struct _GtkClipboard GtkClipboard; 34 35 typedef struct _GtkTargetList GtkTargetList; 36 typedef struct _GtkWidget GtkWidget; 37 typedef struct _GtkSelectionData GtkSelectionData; 35 38 36 39 namespace WebCore { 37 40 41 class DataObjectGtk; 42 38 43 class PasteboardHelper { 39 44 public: 40 virtual ~PasteboardHelper() {}; 45 PasteboardHelper(); 46 virtual ~PasteboardHelper(); 41 47 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 58 protected: 59 void initializeTargetList(); 60 virtual bool usePrimarySelectionClipboard(GtkWidget*) = 0; 61 62 private: 63 GtkTargetList* m_targetList; 64 GtkTargetList* targetListForDataObject(DataObjectGtk*); 47 65 }; 48 66 -
trunk/WebKit/gtk/ChangeLog
r57874 r57901 1 2010-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 1 22 2010-04-19 Diego Escalante Urrelo <descalante@igalia.com> 2 23 -
trunk/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp
r56825 r57901 34 34 #include <glib.h> 35 35 #include "KeyboardEvent.h" 36 #include "markup.h" 36 37 #include "NotImplemented.h" 37 38 #include "Page.h" … … 39 40 #include "PlatformKeyboardEvent.h" 40 41 #include "WindowsKeyboardCodes.h" 41 #include " markup.h"42 #include "webkitmarshal.h" 42 43 #include "webkitprivate.h" 43 44 #include <wtf/text/CString.h> … … 197 198 } 198 199 200 static WebKitWebView* viewSettingClipboard = 0; 201 static 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 199 217 void EditorClient::respondToChangedSelection() 200 218 { … … 216 234 dataObject->clear(); 217 235 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; 219 242 } 220 243 #endif -
trunk/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp
r54230 r57901 2 2 * Copyright (C) 2007 Luca Bruno <lethalman88@gmail.com> 3 3 * Copyright (C) 2009 Holger Hans Peter Freyther 4 * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org> 4 5 * 5 6 * This library is free software; you can redistribute it and/or … … 33 34 namespace WebKit { 34 35 35 static GdkAtom gdkMarkupAtom = gdk_atom_intern("text/html", FALSE);36 37 36 PasteboardHelperGtk::PasteboardHelperGtk() 38 : m_targetList(gtk_target_list_new(0, 0))39 37 { 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(); 42 39 } 43 40 44 41 PasteboardHelperGtk::~PasteboardHelperGtk() 45 42 { 46 gtk_target_list_unref(m_targetList);47 43 } 48 44 49 GtkClipboard* PasteboardHelperGtk::getCurrentTarget(Frame* frame) const 45 guint PasteboardHelperGtk::getIdForTargetType(PasteboardTargetType type) 50 46 { 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; 52 55 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; 57 57 } 58 58 59 GtkClipboard* PasteboardHelperGtk::getClipboard(Frame* frame) const 59 bool PasteboardHelperGtk::usePrimarySelectionClipboard(GtkWidget* widget) 60 60 { 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))); 181 62 } 182 63 -
trunk/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h
r53264 r57901 2 2 * Copyright (C) 2007 Luca Bruno <lethalman88@gmail.com> 3 3 * Copyright (C) 2009 Holger Hans Peter Freyther 4 * Copyright (C) 2010 Martin Robinson <mrobinson@webkit.org> 4 5 * All rights reserved. 5 6 * … … 42 43 PasteboardHelperGtk(); 43 44 ~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); 49 46 50 void writeClipboardContents(GtkClipboard* clipboard, gpointer data = 0); 51 52 private: 53 GtkTargetList* m_targetList; 47 protected: 48 virtual bool usePrimarySelectionClipboard(GtkWidget*); 54 49 }; 55 50
Note: See TracChangeset
for help on using the changeset viewer.