Commit 1421d0c5 authored by hausmann@webkit.org's avatar hausmann@webkit.org

Olivier Goffart <ogoffart@trolltech.com>

Fixes: copy to clipboard when selecting, and paste when clicking with the middle button


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31904 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c8d21e4b
2008-04-15 Olivier Goffart <ogoffart@trolltech.com>
Reviewed by Simon.
Fixes: copy to clipboard when selecting, and paste when clicking with the middle button
* platform/Pasteboard.h: Added Qt-specific selection mode
* platform/qt/PasteboardQt.cpp: Choose the clipboard or the selecton
according to the selection mode
(WebCore::Pasteboard::writeSelection):
(WebCore::Pasteboard::plainText):
(WebCore::Pasteboard::documentFragment):
(WebCore::Pasteboard::writeURL):
(WebCore::Pasteboard::clear):
(WebCore::Pasteboard::isSelectionMode):
2008-04-15 Andre Poenitz <andre.poenitz@trolltech.com>
Reviewed by Simon.
......@@ -91,6 +91,10 @@ public:
bool canSmartReplace();
PassRefPtr<DocumentFragment> documentFragment(Frame*, PassRefPtr<Range>, bool allowPlainText, bool& chosePlainText);
String plainText(Frame* = 0);
#if PLATFORM(QT)
bool isSelectionMode() const;
void setSelectionMode(bool selectionMode);
#endif
#if PLATFORM(GTK)
void setHelper(PasteboardHelper*);
......@@ -113,6 +117,9 @@ private:
PasteboardHelper* m_helper;
#endif
#if PLATFORM(QT)
bool m_selectionMode;
#endif
};
} // namespace WebCore
......
......@@ -44,8 +44,9 @@
#define methodDebug() qDebug() << "PasteboardQt: " << __FUNCTION__;
namespace WebCore {
Pasteboard::Pasteboard()
Pasteboard::Pasteboard()
: m_selectionMode(false)
{
}
......@@ -64,7 +65,8 @@ void Pasteboard::writeSelection(Range* selectedRange, bool, Frame* frame)
text.replace(QChar(0xa0), QLatin1Char(' '));
md->setText(text);
md->setHtml(createMarkup(selectedRange, 0, AnnotateForInterchange));
QApplication::clipboard()->setMimeData(md);
QApplication::clipboard()->setMimeData(md, m_selectionMode ?
QClipboard::Selection : QClipboard::Clipboard);
}
bool Pasteboard::canSmartReplace()
......@@ -74,13 +76,15 @@ bool Pasteboard::canSmartReplace()
String Pasteboard::plainText(Frame*)
{
return QApplication::clipboard()->text();
return QApplication::clipboard()->text(m_selectionMode ?
QClipboard::Selection : QClipboard::Clipboard);
}
PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context,
bool allowPlainText, bool& chosePlainText)
{
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
const QMimeData* mimeData = QApplication::clipboard()->mimeData(
m_selectionMode ? QClipboard::Selection : QClipboard::Clipboard);
chosePlainText = false;
......@@ -111,7 +115,8 @@ void Pasteboard::writeURL(const KURL& _url, const String&, Frame*)
QString url = _url.string();
md->setText(url);
md->setUrls(QList<QUrl>() << QUrl(url));
QApplication::clipboard()->setMimeData(md, QClipboard::Clipboard);
QApplication::clipboard()->setMimeData(md, m_selectionMode ?
QClipboard::Selection : QClipboard::Clipboard);
}
void Pasteboard::writeImage(Node* node, const KURL&, const String&)
......@@ -132,7 +137,18 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String&)
void Pasteboard::clear()
{
QApplication::clipboard()->clear();
QApplication::clipboard()->clear(m_selectionMode ?
QClipboard::Selection : QClipboard::Clipboard);
}
bool Pasteboard::isSelectionMode() const
{
return m_selectionMode;
}
void Pasteboard::setSelectionMode(bool selectionMode)
{
m_selectionMode = selectionMode;
}
}
......@@ -44,6 +44,7 @@
#include "EditorClientQt.h"
#include "Settings.h"
#include "Page.h"
#include "Pasteboard.h"
#include "FrameLoader.h"
#include "FrameLoadRequest.h"
#include "KURL.h"
......@@ -85,7 +86,7 @@
#endif
using namespace WebCore;
static inline DragOperation dropActionToDragOp(Qt::DropActions actions)
{
unsigned result = 0;
......@@ -371,6 +372,24 @@ void QWebPagePrivate::mouseReleaseEvent(QMouseEvent *ev)
return;
frame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
#ifndef QT_NO_CLIPBOARD
if (QApplication::clipboard()->supportsSelection()) {
bool oldSelectionMode = Pasteboard::generalPasteboard()->isSelectionMode();
Pasteboard::generalPasteboard()->setSelectionMode(true);
WebCore::Frame* focusFrame = page->focusController()->focusedOrMainFrame();
if (ev->button() == Qt::LeftButton) {
if(focusFrame && (focusFrame->editor()->canCopy() || focusFrame->editor()->canDHTMLCopy())) {
focusFrame->editor()->copy();
}
} else if (ev->button() == Qt::MidButton) {
if(focusFrame && (focusFrame->editor()->canPaste() || focusFrame->editor()->canDHTMLPaste())) {
focusFrame->editor()->paste();
}
}
Pasteboard::generalPasteboard()->setSelectionMode(oldSelectionMode);
}
#endif
}
void QWebPagePrivate::contextMenuEvent(QContextMenuEvent *ev)
......
2008-04-15 Olivier Goffart <ogoffart@trolltech.com>
Reviewed by Simon.
Fixes: copy to clipboard when selecting, and paste when clicking with the middle button
* Api/qwebpage.cpp:
(QWebPagePrivate::mouseReleaseEvent): If the clipboard supports
selections then we support copy & paste into the selection.
2008-04-15 Michael Brasser <michael.brasser@trolltech.com>
Reviewed by Simon.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment