예제 #1
0
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText)
{
    GtkClipboard* clipboard = PasteboardHelper::clipboardForFrame(frame);
    ASSERT(clipboard);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);
    PasteboardHelper::helper()->getClipboardContents(clipboard);

    if (dataObject->hasMarkup()) {
        chosePlainText = false;
        String markup(dataObject->markup());

        if (!markup.isEmpty()) {
            RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), markup, "");
            if (fragment)
                return fragment.release();
        }
    }

    if (!allowPlainText || !dataObject->hasText())
        return 0;

    chosePlainText = true;
    String text(dataObject->text());
    RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), text);
    if (fragment)
        return fragment.release();

    return 0;
}
예제 #2
0
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context,
                                                          bool allowPlainText, bool& chosePlainText)
{
    PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
    GtkClipboard* clipboard = helper->getCurrentClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    helper->getClipboardContents(clipboard);

    chosePlainText = false;

    if (dataObject->hasMarkup()) {
        RefPtr<DocumentFragment> fragment = createFragmentFromMarkup(frame->document(), dataObject->markup(), "", FragmentScriptingNotAllowed);
        if (fragment)
            return fragment.release();
    }

    if (!allowPlainText)
        return 0;

    if (dataObject->hasText()) {
        chosePlainText = true;
        RefPtr<DocumentFragment> fragment = createFragmentFromText(context.get(), dataObject->text());
        if (fragment)
            return fragment.release();
    }

    return 0;
}
예제 #3
0
void PasteboardHelper::getClipboardContents(GtkClipboard* clipboard)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    if (gtk_clipboard_wait_is_text_available(clipboard)) {
        GOwnPtr<gchar> textData(gtk_clipboard_wait_for_text(clipboard));
        if (textData)
            dataObject->setText(String::fromUTF8(textData.get()));
    }

    if (gtk_clipboard_wait_is_target_available(clipboard, markupAtom)) {
        if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, markupAtom)) {
            String markup(selectionDataToUTF8String(data));
            removeMarkupPrefix(markup);
            dataObject->setMarkup(markup);
            gtk_selection_data_free(data);
        }
    }

    if (gtk_clipboard_wait_is_target_available(clipboard, uriListAtom)) {
        if (GtkSelectionData* data = gtk_clipboard_wait_for_contents(clipboard, uriListAtom)) {
            dataObject->setURIList(selectionDataToUTF8String(data));
            gtk_selection_data_free(data);
        }
    }
}
static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer data)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    // Only clear the DataObject for this clipboard if we are not currently setting it.
    if (dataObject != settingClipboardDataObject)
        dataObject->clear();

    // Only collapse the selection if this is an X11 primary clipboard
    // and we aren't currently setting the clipboard for this WebView.
    if (!data || data == settingClipboardData)
        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);
}
예제 #5
0
void Pasteboard::writePlainText(const String& text)
{
    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->setText(text);
    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard);
}
예제 #6
0
void Pasteboard::writeImage(Node* node, const KURL&, const String& title)
{
    ASSERT(node);

    if (!(node->renderer() && node->renderer()->isImage()))
        return;

    RenderImage* renderer = toRenderImage(node->renderer());
    CachedImage* cachedImage = renderer->cachedImage();
    if (!cachedImage || cachedImage->errorOccurred())
        return;
    Image* image = cachedImage->imageForRenderer(renderer);
    ASSERT(image);

    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);

    KURL url = getURLForImageNode(node);
    if (!url.isEmpty()) {
        dataObject->setURL(url, title);

        dataObject->setMarkup(createMarkup(static_cast<Element*>(node), IncludeNode, 0, ResolveAllURLs));
    }

    GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf());
    dataObject->setImage(pixbuf.get());

    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard);
}
예제 #7
0
void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
{
    GtkClipboard* clipboard = m_helper->getClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->setText(frame->selectedText());
    dataObject->setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange, false, AbsoluteURLs));
    m_helper->writeClipboardContents(clipboard);
}
예제 #8
0
String Pasteboard::plainText(Frame* frame)
{
    GtkClipboard* clipboard = m_helper->getCurrentClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);

    m_helper->getClipboardContents(clipboard);
    return dataObject->text();
}
예제 #9
0
String Pasteboard::plainText(Frame* frame)
{
    PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
    GtkClipboard* clipboard = helper->getCurrentClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);

    helper->getClipboardContents(clipboard);
    return dataObject->text();
}
예제 #10
0
void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
{
    PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
    GtkClipboard* clipboard = helper->getClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->setText(frame->editor()->selectedText());
    dataObject->setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange, false, ResolveNonLocalURLs));
    helper->writeClipboardContents(clipboard, canSmartCopyOrDelete ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
}
예제 #11
0
void Pasteboard::writePlainText(const String& text, SmartReplaceOption smartReplaceOption)
{
    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->clearAll();

    dataObject->setText(text);
    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard,
        (smartReplaceOption == CanSmartReplace) ? PasteboardHelper::IncludeSmartPaste : PasteboardHelper::DoNotIncludeSmartPaste);
}
예제 #12
0
String Pasteboard::plainText(Frame* frame)
{
    GtkClipboard* clipboard = PasteboardHelper::clipboardForFrame(frame);
    ASSERT(clipboard);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);
    PasteboardHelper::helper()->getClipboardContents(clipboard);

    return dataObject->text();
}
예제 #13
0
void Pasteboard::clear()
{
    // TODO: Is there a way to get the widget's clipboard here?
    GtkClipboard* clipboard = PasteboardHelper::clipboard();
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    dataObject->clear();
    PasteboardHelper::helper()->writeClipboardContents(clipboard);
}
예제 #14
0
void Pasteboard::writeURL(const KURL& url, const String& label, Frame* frame)
{
    if (url.isEmpty())
        return;

    GtkClipboard* clipboard = m_helper->getClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->setURL(url, label);
    m_helper->writeClipboardContents(clipboard);
}
예제 #15
0
void Pasteboard::writeSelection(Range* selectedRange, bool canSmartCopyOrDelete, Frame* frame)
{
    GtkClipboard* clipboard = PasteboardHelper::clipboardForFrame(frame);
    ASSERT(clipboard);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    dataObject->setText(frame->selectedText());
    dataObject->setMarkup(createMarkup(selectedRange, 0, AnnotateForInterchange));
    PasteboardHelper::helper()->writeClipboardContents(clipboard);
}
예제 #16
0
void Pasteboard::writePlainText(const String& text)
{
    // TODO: Is there a way to get the widget's clipboard here?
    GtkClipboard* clipboard = PasteboardHelper::clipboard();
    ASSERT(clipboard);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    dataObject->setText(text);
    PasteboardHelper::helper()->writeClipboardContents(clipboard);
}
예제 #17
0
void Pasteboard::writeURL(const KURL& url, const String& label, Frame* frame)
{
    if (url.isEmpty())
        return;

    PasteboardHelper* helper = PasteboardHelper::defaultPasteboardHelper();
    GtkClipboard* clipboard = helper->getCurrentClipboard(frame);

    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->clearAll();

    dataObject->setURL(url, label);
    helper->writeClipboardContents(clipboard);
}
예제 #18
0
void Pasteboard::writeImage(Node* node, const KURL&, const String&)
{
    GtkClipboard* clipboard = gtk_clipboard_get_for_display(gdk_display_get_default(), GDK_SELECTION_CLIPBOARD);

    ASSERT(node && node->renderer() && node->renderer()->isImage());
    RenderImage* renderer = toRenderImage(node->renderer());
    CachedImage* cachedImage = renderer->cachedImage();
    if (!cachedImage || cachedImage->errorOccurred())
        return;
    Image* image = cachedImage->image();
    ASSERT(image);

    PlatformRefPtr<GdkPixbuf> pixbuf = adoptPlatformRef(image->getGdkPixbuf());
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    dataObject->setImage(pixbuf.get());
    m_helper->writeClipboardContents(clipboard);
}
예제 #19
0
static void clearClipboardContentsCallback(GtkClipboard* clipboard, gpointer data)
{
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    // Only clear the DataObject for this clipboard if we are not currently setting it.
    if (dataObject != settingClipboardDataObject)
        dataObject->clearAll();

    if (!data)
        return;

    GRefPtr<GClosure> callback = adoptGRef(static_cast<GClosure*>(data));
    GValue firstArgument = {0, {{0}}};
    g_value_init(&firstArgument, G_TYPE_POINTER);
    g_value_set_pointer(&firstArgument, clipboard);
    g_closure_invoke(callback.get(), nullptr, 1, &firstArgument, 0);
}
예제 #20
0
static RefPtr<DocumentFragment> createFragmentFromPasteboardData(Pasteboard& pasteboard, Frame& frame, Range& range, bool allowPlainText, bool& chosePlainText)
{
    chosePlainText = false;

    if (!pasteboard.hasData())
        return nullptr;

    DataObjectGtk* dataObject = pasteboard.dataObject();
    if (dataObject->hasMarkup() && frame.document())
        return createFragmentFromMarkup(*frame.document(), dataObject->markup(), emptyString(), DisallowScriptingAndPluginContent);

    if (!allowPlainText)
        return nullptr;

    if (dataObject->hasText()) {
        chosePlainText = true;
        return createFragmentFromText(range, dataObject->text());
    }

    return nullptr;
}
예제 #21
0
void Pasteboard::writeURL(const KURL& url, const String& label, Frame* frame)
{
    if (url.isEmpty())
        return;

    GtkClipboard* clipboard = PasteboardHelper::clipboardForFrame(frame);
    ASSERT(clipboard);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    String actualLabel(label);
    if (actualLabel.isEmpty())
        actualLabel = url;

    Vector<KURL> uriList;
    uriList.append(url);
    dataObject->setURIList(uriList);
    dataObject->setText(actualLabel);

    PasteboardHelper::helper()->writeClipboardContents(clipboard);
}
예제 #22
0
static void setSelectionPrimaryClipboardIfNeeded(WebKitWebView* webView)
{
    if (!gtk_widget_has_screen(GTK_WIDGET(webView)))
        return;

    GtkClipboard* clipboard = gtk_widget_get_clipboard(GTK_WIDGET(webView), GDK_SELECTION_PRIMARY);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    WebCore::Page* corePage = core(webView);
    Frame* targetFrame = corePage->focusController()->focusedOrMainFrame();

    if (!targetFrame->selection()->isRange())
        return;

    dataObject->clear();
    dataObject->setRange(targetFrame->selection()->toNormalizedRange());

    viewSettingClipboard = webView;
    GClosure* callback = g_cclosure_new_object(G_CALLBACK(collapseSelection), G_OBJECT(webView));
    g_closure_set_marshal(callback, g_cclosure_marshal_VOID__VOID);
    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard, PasteboardHelper::DoNotIncludeSmartPaste, callback);
    viewSettingClipboard = 0;
}
예제 #23
0
void Pasteboard::writeImage(Node* node, const KURL&, const String&)
{
    ASSERT(node && node->renderer() && node->renderer()->isImage());
    RenderImage* renderer = toRenderImage(node->renderer());
    CachedImage* cachedImage = renderer->cachedImage();
    ASSERT(cachedImage);
    Image* image = cachedImage->image();
    ASSERT(image);

    ASSERT(node->document());
    GtkClipboard* clipboard = PasteboardHelper::clipboardForFrame(node->document()->frame());
    ASSERT(clipboard);

    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);
    ASSERT(dataObject);

    GdkPixbuf* pixbuf = image->getGdkPixbuf();
    dataObject->setImage(pixbuf);
    g_object_unref(pixbuf);

    PasteboardHelper::helper()->writeClipboardContents(clipboard);
}
예제 #24
0
void WebEditorClient::updateGlobalSelection(Frame* frame)
{
#if PLATFORM(X11)
    GtkClipboard* clipboard = PasteboardHelper::defaultPasteboardHelper()->getPrimarySelectionClipboard(frame);
    DataObjectGtk* dataObject = DataObjectGtk::forClipboard(clipboard);

    if (!frame->selection()->isRange())
        return;

    dataObject->clearAll();
    dataObject->setRange(frame->selection()->toNormalizedRange());

    frameSettingClipboard = frame;
    GClosure* callback = g_cclosure_new(G_CALLBACK(collapseSelection), frame, 0);
    // This observer will be self-destroyed on closure finalization,
    // that will happen either after closure execution or after
    // closure invalidation.
    new EditorClientFrameDestructionObserver(frame, callback);
    g_closure_set_marshal(callback, g_cclosure_marshal_VOID__VOID);
    PasteboardHelper::defaultPasteboardHelper()->writeClipboardContents(clipboard, PasteboardHelper::DoNotIncludeSmartPaste, callback);
    frameSettingClipboard = 0;
#endif
}