Changeset 36323 in webkit


Ignore:
Timestamp:
Sep 10, 2008 1:30:18 PM (16 years ago)
Author:
alp@webkit.org
Message:

2008-09-10 Alp Toker <alp@nuanti.com>

Reviewed by Mark Rowe.

https://bugs.webkit.org/show_bug.cgi?id=17267
[GTK] Primary selection/clipboard support

Implement primary selection support (copying only, no paste yet).

  • WebCoreSupport/EditorClientGtk.cpp: (WebKit::clipboard_get_contents_cb): (WebKit::clipboard_clear_contents_cb): (WebKit::EditorClient::respondToChangedSelection):
Location:
trunk/WebKit/gtk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r36263 r36323  
     12008-09-10  Alp Toker  <alp@nuanti.com>
     2
     3        Reviewed by Mark Rowe.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=17267
     6        [GTK] Primary selection/clipboard support
     7
     8        Implement primary selection support (copying only, no paste yet).
     9
     10        * WebCoreSupport/EditorClientGtk.cpp:
     11        (WebKit::clipboard_get_contents_cb):
     12        (WebKit::clipboard_clear_contents_cb):
     13        (WebKit::EditorClient::respondToChangedSelection):
     14
    1152008-09-07  Cameron Zwarich  <cwzwarich@uwaterloo.ca>
    216
  • trunk/WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp

    r35958 r36323  
    2121#include "EditorClientGtk.h"
    2222
     23#include "CString.h"
    2324#include "EditCommand.h"
    2425#include "Editor.h"
     
    3031#include "Page.h"
    3132#include "PlatformKeyboardEvent.h"
     33#include "markup.h"
    3234#include "webkitprivate.h"
    3335
     
    163165}
    164166
     167#if GTK_CHECK_VERSION(2,10,0)
     168static void clipboard_get_contents_cb(GtkClipboard* clipboard, GtkSelectionData* selection_data, guint info, gpointer data)
     169{
     170    WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data);
     171    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
     172    PassRefPtr<Range> selectedRange = frame->selection()->toRange();
     173
     174    if (static_cast<gint>(info) == WEBKIT_WEB_VIEW_TARGET_INFO_HTML) {
     175        String markup = createMarkup(selectedRange.get(), 0, AnnotateForInterchange);
     176        gtk_selection_data_set(selection_data, selection_data->target, 8,
     177                               reinterpret_cast<const guchar*>(markup.utf8().data()), markup.utf8().length());
     178    } else {
     179        String text = selectedRange->text();
     180        gtk_selection_data_set_text(selection_data, text.utf8().data(), text.utf8().length());
     181    }
     182}
     183
     184static void clipboard_clear_contents_cb(GtkClipboard* clipboard, gpointer data)
     185{
     186    WebKitWebView* webView = reinterpret_cast<WebKitWebView*>(data);
     187    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
     188
     189    // Collapse the selection without clearing it
     190    frame->selection()->setBase(frame->selection()->extent(), frame->selection()->affinity());
     191}
     192#endif
     193
    165194void EditorClient::respondToChangedSelection()
    166195{
    167196    WebKitWebViewPrivate* priv = m_webView->priv;
    168 
    169197    Frame* targetFrame = core(m_webView)->focusController()->focusedOrMainFrame();
    170     if (!targetFrame || !targetFrame->editor()->hasComposition())
     198
     199    if (!targetFrame)
    171200        return;
    172201
    173202    if (targetFrame->editor()->ignoreCompositionSelectionChange())
     203        return;
     204
     205#if GTK_CHECK_VERSION(2,10,0)
     206    GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(m_webView), GDK_SELECTION_PRIMARY);
     207    if (targetFrame->selection()->isRange()) {
     208        GtkTargetList* targetList = webkit_web_view_get_copy_target_list(m_webView);
     209        gint targetCount;
     210        GtkTargetEntry* targets = gtk_target_table_new_from_list(targetList, &targetCount);
     211        gtk_clipboard_set_with_owner(clipboard, targets, targetCount,
     212                                     clipboard_get_contents_cb, clipboard_clear_contents_cb, G_OBJECT(m_webView));
     213        gtk_target_table_free(targets, targetCount);
     214    } else if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(m_webView))
     215        gtk_clipboard_clear(clipboard);
     216#endif
     217
     218    if (!targetFrame->editor()->hasComposition())
    174219        return;
    175220
Note: See TracChangeset for help on using the changeset viewer.