diff options
Diffstat (limited to 'WebKit/gtk/WebCoreSupport')
-rw-r--r-- | WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp | 37 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/DocumentLoaderGtk.cpp | 13 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp | 46 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp | 42 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h | 2 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp | 8 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp | 103 | ||||
-rw-r--r-- | WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h | 2 |
8 files changed, 180 insertions, 73 deletions
diff --git a/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp b/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp index d9a043b..8ea8991 100644 --- a/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp @@ -64,7 +64,11 @@ void ChromeClient::chromeDestroyed() FloatRect ChromeClient::windowRect() { GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView)); +#if GTK_CHECK_VERSION(2, 18, 0) + if (gtk_widget_is_toplevel(window)) { +#else if (GTK_WIDGET_TOPLEVEL(window)) { +#endif gint left, top, width, height; gtk_window_get_position(GTK_WINDOW(window), &left, &top); gtk_window_get_size(GTK_WINDOW(window), &width, &height); @@ -106,7 +110,11 @@ void ChromeClient::focus() void ChromeClient::unfocus() { GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView)); +#if GTK_CHECK_VERSION(2, 18, 0) + if (gtk_widget_is_toplevel(window)) +#else if (GTK_WIDGET_TOPLEVEL(window)) +#endif gtk_window_set_focus(GTK_WINDOW(window), NULL); } @@ -234,7 +242,11 @@ void ChromeClient::closeWindowSoon() bool ChromeClient::canTakeFocus(FocusDirection) { +#if GTK_CHECK_VERSION(2, 18, 0) + return gtk_widget_get_can_focus(GTK_WIDGET(m_webView)); +#else return GTK_WIDGET_CAN_FOCUS(m_webView); +#endif } void ChromeClient::takeFocus(FocusDirection) @@ -442,20 +454,6 @@ void ChromeClient::scrollbarsModeDidChange() const void ChromeClient::mouseDidMoveOverElement(const HitTestResult& hit, unsigned modifierFlags) { - // If a tooltip must be displayed it will be, afterwards, when - // setToolTip is called; this is just a work-around to make sure - // it updates its location correctly; see - // https://bugs.webkit.org/show_bug.cgi?id=15793. - g_object_set(m_webView, "has-tooltip", FALSE, NULL); - - GdkDisplay* gdkDisplay; - GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView)); - if (GTK_WIDGET_TOPLEVEL(window)) - gdkDisplay = gtk_widget_get_display(window); - else - gdkDisplay = gdk_display_get_default(); - gtk_tooltip_trigger_tooltip_query(gdkDisplay); - // check if the element is a link... bool isLink = hit.isLiveLink(); if (isLink) { @@ -475,16 +473,7 @@ void ChromeClient::mouseDidMoveOverElement(const HitTestResult& hit, unsigned mo void ChromeClient::setToolTip(const String& toolTip, TextDirection) { -#if GTK_CHECK_VERSION(2,12,0) - if (toolTip.isEmpty()) - g_object_set(m_webView, "has-tooltip", FALSE, NULL); - else - gtk_widget_set_tooltip_text(GTK_WIDGET(m_webView), toolTip.utf8().data()); -#else - // TODO: Support older GTK+ versions - // See http://bugs.webkit.org/show_bug.cgi?id=15793 - notImplemented(); -#endif + webkit_web_view_set_tooltip_text(m_webView, toolTip.utf8().data()); } void ChromeClient::print(Frame* frame) diff --git a/WebKit/gtk/WebCoreSupport/DocumentLoaderGtk.cpp b/WebKit/gtk/WebCoreSupport/DocumentLoaderGtk.cpp index 0efc9fa..2b355cb 100644 --- a/WebKit/gtk/WebCoreSupport/DocumentLoaderGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/DocumentLoaderGtk.cpp @@ -30,6 +30,7 @@ #include "config.h" #include "DocumentLoaderGtk.h" +#include "webkitprivate.h" #include "webkitwebdatasource.h" using namespace WebCore; @@ -60,7 +61,16 @@ void DocumentLoader::attachToFrame() { WebCore::DocumentLoader::attachToFrame(); - refDataSource(); + if (m_dataSource) { + refDataSource(); + return; + } + + // We may get to here without having a datasource, when the data + // is coming from the page cache. + WebKitWebDataSource* dataSource = webkit_web_data_source_new_with_loader(this); + setDataSource(dataSource); + g_object_unref(dataSource); } void DocumentLoader::detachFromFrame() @@ -110,6 +120,7 @@ void DocumentLoader::unrefDataSource() ASSERT(m_dataSource); m_isDataSourceReffed = false; g_object_unref(m_dataSource); + m_dataSource = 0; } } // end namespace WebKit diff --git a/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp b/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp index 6ec6baf..02d1a53 100644 --- a/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp @@ -24,6 +24,7 @@ #include "EditorClientGtk.h" #include "CString.h" +#include "DataObjectGtk.h" #include "EditCommand.h" #include "Editor.h" #include <enchant.h> @@ -35,6 +36,7 @@ #include "KeyboardEvent.h" #include "NotImplemented.h" #include "Page.h" +#include "PasteboardHelperGtk.h" #include "PlatformKeyboardEvent.h" #include "markup.h" #include "webkitprivate.h" @@ -185,35 +187,11 @@ void EditorClient::respondToChangedContents() notImplemented(); } -static void clipboard_get_contents_cb(GtkClipboard* clipboard, GtkSelectionData* selection_data, guint info, gpointer data) -{ - WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data); - Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); - PassRefPtr<Range> selectedRange = frame->selection()->toNormalizedRange(); - - if (static_cast<gint>(info) == WEBKIT_WEB_VIEW_TARGET_INFO_HTML) { - String markup = createMarkup(selectedRange.get(), 0, AnnotateForInterchange); - gtk_selection_data_set(selection_data, selection_data->target, 8, - reinterpret_cast<const guchar*>(markup.utf8().data()), markup.utf8().length()); - } else { - String text = selectedRange->text(); - gtk_selection_data_set_text(selection_data, text.utf8().data(), text.utf8().length()); - } -} - -static void clipboard_clear_contents_cb(GtkClipboard* clipboard, gpointer data) -{ - WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data); - Frame* frame = core(webView)->focusController()->focusedOrMainFrame(); - - // Collapse the selection without clearing it - frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity()); -} - void EditorClient::respondToChangedSelection() { WebKitWebViewPrivate* priv = m_webView->priv; - Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame(); + WebCore::Page* corePage = core(m_webView); + Frame* targetFrame = corePage->focusController()->focusedOrMainFrame(); if (!targetFrame) return; @@ -221,16 +199,16 @@ void EditorClient::respondToChangedSelection() if (targetFrame->editor()->ignoreCompositionSelectionChange()) return; +#if PLATFORM(X11) GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(m_webView), GDK_SELECTION_PRIMARY); + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + if (targetFrame->selection()->isRange()) { - GtkTargetList* targetList = webkit_web_view_get_copy_target_list(m_webView); - gint targetCount; - GtkTargetEntry* targets = gtk_target_table_new_from_list(targetList, &targetCount); - gtk_clipboard_set_with_owner(clipboard, targets, targetCount, - clipboard_get_contents_cb, clipboard_clear_contents_cb, G_OBJECT(m_webView)); - gtk_target_table_free(targets, targetCount); - } else if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(m_webView)) - gtk_clipboard_clear(clipboard); + dataObject->clear(); + dataObject->setRange(targetFrame->selection()->toNormalizedRange()); + pasteboardHelperInstance()->writeClipboardContents(clipboard, m_webView); + } +#endif if (!targetFrame->editor()->hasComposition()) return; diff --git a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp index 0eaa7c8..8f1bec2 100644 --- a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp @@ -33,6 +33,7 @@ #include "FrameView.h" #include "FrameTree.h" #include "GOwnPtr.h" +#include "GRefPtr.h" #include "GtkPluginWidget.h" #include "HTMLAppletElement.h" #include "HTMLFormElement.h" @@ -76,6 +77,7 @@ namespace WebKit { FrameLoaderClient::FrameLoaderClient(WebKitWebFrame* frame) : m_frame(frame) , m_policyDecision(0) + , m_loadingErrorPage(false) , m_pluginView(0) , m_hasSentResponseToPlugin(false) { @@ -440,7 +442,7 @@ PassRefPtr<Widget> FrameLoaderClient::createPlugin(const IntSize& pluginSize, HT CString mimeTypeString = mimeType.utf8(); ASSERT(paramNames.size() == paramValues.size()); - GOwnPtr<GHashTable> hash(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free)); + GRefPtr<GHashTable> hash = adoptGRef(g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free)); for (unsigned i = 0; i < paramNames.size(); ++i) { g_hash_table_insert(hash.get(), g_strdup(paramNames[i].utf8().data()), @@ -567,6 +569,11 @@ bool FrameLoaderClient::hasWebView() const void FrameLoaderClient::dispatchDidFinishLoad() { + if (m_loadingErrorPage) { + m_loadingErrorPage = false; + return; + } + loadDone(m_frame, true); } @@ -639,7 +646,9 @@ void FrameLoaderClient::setCopiesOnScroll() void FrameLoaderClient::detachedFromParent2() { - notImplemented(); + FrameView *view = core(m_frame)->view(); + if (view) + view->setGtkAdjustments(0, 0); } void FrameLoaderClient::detachedFromParent3() @@ -700,6 +709,9 @@ void FrameLoaderClient::dispatchWillClose() void FrameLoaderClient::dispatchDidReceiveIcon() { + if (m_loadingErrorPage) + return; + WebKitWebView* webView = getViewFromFrame(m_frame); // Avoid reporting favicons for non-main frames. @@ -712,11 +724,17 @@ void FrameLoaderClient::dispatchDidReceiveIcon() void FrameLoaderClient::dispatchDidStartProvisionalLoad() { + if (m_loadingErrorPage) + return; + notifyStatus(m_frame, WEBKIT_LOAD_PROVISIONAL); } void FrameLoaderClient::dispatchDidReceiveTitle(const String& title) { + if (m_loadingErrorPage) + return; + WebKitWebFramePrivate* priv = m_frame->priv; g_free(priv->title); priv->title = g_strdup(title.utf8().data()); @@ -733,6 +751,9 @@ void FrameLoaderClient::dispatchDidReceiveTitle(const String& title) void FrameLoaderClient::dispatchDidCommitLoad() { + if (m_loadingErrorPage) + return; + /* Update the URI once first data has been received. * This means the URI is valid and successfully identify the page that's going to be loaded. */ @@ -740,7 +761,7 @@ void FrameLoaderClient::dispatchDidCommitLoad() WebKitWebFramePrivate* priv = m_frame->priv; g_free(priv->uri); - priv->uri = g_strdup(core(m_frame)->loader()->url().prettyURL().utf8().data()); + priv->uri = g_strdup(core(m_frame)->loader()->activeDocumentLoader()->url().prettyURL().utf8().data()); g_free(priv->title); priv->title = NULL; g_object_notify(G_OBJECT(m_frame), "uri"); @@ -773,6 +794,9 @@ void FrameLoaderClient::dispatchDidFirstLayout() void FrameLoaderClient::dispatchDidFirstVisuallyNonEmptyLayout() { + if (m_loadingErrorPage) + return; + notifyStatus(m_frame, WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT); } @@ -837,9 +861,10 @@ String FrameLoaderClient::generatedMIMETypeForURLScheme(const String&) const void FrameLoaderClient::finishedLoading(WebCore::DocumentLoader* documentLoader) { - if (!m_pluginView) - committedLoad(documentLoader, 0, 0); - else { + if (!m_pluginView) { + FrameLoader* loader = documentLoader->frameLoader(); + loader->setEncoding(m_response.textEncodingName(), false); + } else { m_pluginView->didFinishLoading(); m_pluginView = 0; m_hasSentResponseToPlugin = false; @@ -933,6 +958,9 @@ void FrameLoaderClient::dispatchDidFailProvisionalLoad(const ResourceError& erro void FrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) { + if (m_loadingErrorPage) + return; + notifyStatus(m_frame, WEBKIT_LOAD_FAILED); WebKitWebView* webView = getViewFromFrame(m_frame); @@ -952,6 +980,8 @@ void FrameLoaderClient::dispatchDidFailLoad(const ResourceError& error) return; } + m_loadingErrorPage = true; + String content; gchar* fileContent = 0; gchar* errorURI = g_filename_to_uri(DATA_DIR"/webkit-1.0/resources/error.html", NULL, NULL); diff --git a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h index cace770..b364873 100644 --- a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h +++ b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.h @@ -184,6 +184,8 @@ namespace WebKit { WebCore::ResourceResponse m_response; WebKitWebPolicyDecision* m_policyDecision; + bool m_loadingErrorPage; + // Plugin view to redirect data to WebCore::PluginView* m_pluginView; bool m_hasSentResponseToPlugin; diff --git a/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp b/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp index a06ff50..99bc627 100644 --- a/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/InspectorClientGtk.cpp @@ -44,13 +44,8 @@ InspectorClient::InspectorClient(WebKitWebView* webView) void InspectorClient::inspectorDestroyed() { - if (m_webView) { - gboolean handled = FALSE; - g_signal_emit_by_name(m_webInspector, "destroy", &handled); - - /* we can now dispose our own reference */ + if (m_webInspector) g_object_unref(m_webInspector); - } delete this; } @@ -64,6 +59,7 @@ void InspectorClient::webViewDestroyed() // something else, and the inspector will be referenced again, // there. g_object_unref(m_webInspector); + m_webInspector = 0; } Page* InspectorClient::createPage() diff --git a/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp b/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp index c71ef1b..8406ada 100644 --- a/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp +++ b/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.cpp @@ -20,13 +20,14 @@ #include "config.h" #include "PasteboardHelperGtk.h" +#include "DataObjectGtk.h" +#include "FocusController.h" #include "Frame.h" +#include <gtk/gtk.h> #include "webkitwebframe.h" #include "webkitwebview.h" #include "webkitprivate.h" -#include <gtk/gtk.h> - using namespace WebCore; namespace WebKit { @@ -79,4 +80,102 @@ gint PasteboardHelperGtk::getWebViewTargetInfoHtml() const return WEBKIT_WEB_VIEW_TARGET_INFO_HTML; } +static void fillSelectionData(GtkSelectionData* selectionData, guint info, DataObjectGtk* dataObject) +{ + if (info == WEBKIT_WEB_VIEW_TARGET_INFO_TEXT) + gtk_selection_data_set_text(selectionData, dataObject->text().utf8().data(), -1); + else if (info == WEBKIT_WEB_VIEW_TARGET_INFO_HTML) { + GOwnPtr<gchar> markup(g_strdup(dataObject->markup().utf8().data())); + gtk_selection_data_set(selectionData, selectionData->target, 8, + reinterpret_cast<const guchar*>(markup.get()), + strlen(markup.get())); + } +} + +static GtkTargetList* targetListForDataObject(DataObjectGtk* dataObject) +{ + GtkTargetList* list = gtk_target_list_new(0, 0); + + if (dataObject->hasText()) + gtk_target_list_add_text_targets(list, WEBKIT_WEB_VIEW_TARGET_INFO_TEXT); + + if (dataObject->hasMarkup()) + gtk_target_list_add(list, gdkMarkupAtom, 0, WEBKIT_WEB_VIEW_TARGET_INFO_HTML); + + return list; +} + +static bool settingClipboard = false; +static void getClipboardContentsCallback(GtkClipboard* clipboard, GtkSelectionData *selectionData, guint info, gpointer data) +{ + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + ASSERT(dataObject); + fillSelectionData(selectionData, info, dataObject); +} + +static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer data) +{ + // GTK will call the clear clipboard callback while setting clipboard data. + // We don't actually want to clear the DataObject during that time. + if (settingClipboard) + return; + + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + ASSERT(dataObject); + dataObject->clear(); + + // This will be true for clipboards other than X11 primary. + if (!data) + return; + + WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data); + WebCore::Page* corePage = core(webView); + + if (!corePage || !corePage->focusController()) { + g_object_unref(webView); + return; + } + + Frame* frame = corePage->focusController()->focusedOrMainFrame(); + + // Collapse the selection without clearing it + ASSERT(frame); + frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity()); + + g_object_unref(webView); +} + +void PasteboardHelperGtk::writeClipboardContents(GtkClipboard* clipboard, gpointer data) +{ + DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard); + GtkTargetList* list = targetListForDataObject(dataObject); + + int numberOfTargets; + GtkTargetEntry* table = gtk_target_table_new_from_list(list, &numberOfTargets); + + if (numberOfTargets > 0 && table) { + settingClipboard = true; + + // Protect the web view from being destroyed before one of the clipboard callbacks + // is called. Balanced in both getClipboardContentsCallback and + // clearClipboardContentsCallback. + WebKitWebView* webView = static_cast<WebKitWebView*>(data); + g_object_ref(webView); + + gboolean succeeded = gtk_clipboard_set_with_data(clipboard, table, numberOfTargets, + getClipboardContentsCallback, + clearClipboardContentsCallback, data); + if (!succeeded) + g_object_unref(webView); + + settingClipboard = false; + } else + gtk_clipboard_clear(clipboard); + + if (table) + gtk_target_table_free(table, numberOfTargets); + + gtk_target_list_unref(list); +} + } diff --git a/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h b/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h index 12ba207..97eff90 100644 --- a/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h +++ b/WebKit/gtk/WebCoreSupport/PasteboardHelperGtk.h @@ -47,6 +47,8 @@ public: virtual GtkTargetList* targetList() const; virtual gint getWebViewTargetInfoHtml() const; + void writeClipboardContents(GtkClipboard* clipboard, gpointer data = 0); + private: GtkTargetList* m_targetList; }; |