Atomically update the system clipboard for copy/cut events
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2011 04:12:14 +0000 (04:12 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2011 04:12:14 +0000 (04:12 +0000)
commitb6fea91c4a73186adf0c4cc601fe2a4e26dd446a
tree49472280221372a9625b619b6ce6561d135dd563
parent8596edb40f2d27321c5f2c64438c79c75bb15588
Atomically update the system clipboard for copy/cut events
https://bugs.webkit.org/show_bug.cgi?id=40515

Reviewed by David Levin.

This change consolidates the system pasteboard mutation logic into dispatchCPPEvent() rather
than having it scattered throughout tryDHTMLCopy/tryDHTMLCut and the various Clipboard*
classes. This allows us to ensure that the system pasteboard remains in a consistent state
even if there's an exception thrown during event handling, and it also lays the ground work
for allowing pages to prevent copy/cut without causing the system pasteboard to be cleared.

No new tests, since any layout test would be flaky since it would depend on and affect
global system state.

* editing/Editor.cpp:
(WebCore::Editor::tryDHTMLCopy): Move Pasteboard::clear() call to dispatchCPPEvent().
(WebCore::Editor::tryDHTMLCut): Ditto.
(WebCore::Editor::dispatchCPPEvent):
Only persist Clipboard mutations to the system pasteboard if the event was dispatched
successfully and default processing was prevented.
* editing/mac/EditorMac.mm:
(WebCore::Editor::newGeneralClipboard):
When creating a Clipboard for copy/cut, back it with a unique instance of NSPasteboard to
buffer pasteboard mutations.
* platform/Pasteboard.h:
* platform/chromium/PasteboardChromium.cpp:
(WebCore::Pasteboard::writeClipboard):
* platform/efl/PasteboardEfl.cpp:
(WebCore::Pasteboard::writeClipboard):
* platform/gtk/ClipboardGtk.cpp: Moved pasteboard writeback to PasteboardGtk.
(WebCore::ClipboardGtk::setData):
* platform/gtk/ClipboardGtk.h:
(WebCore::ClipboardGtk::clipboard):
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writeClipboard):
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writeClipboard):
Implement logic to flush data from temporary NSPasteboard to system pasteboard.
* platform/gtk/ClipboardGtk.cpp: Moved pasteboard writeback to PasteboardQt.
(WebCore::ClipboardGtk::setData):
* platform/qt/PasteboardQt.cpp:
(WebCore::Pasteboard::writeClipboard):
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writeClipboard):
* platform/wince/PasteboardWinCE.cpp:
(WebCore::Pasteboard::writeClipboard):
* platform/wx/PasteboardWx.cpp:
(WebCore::Pasteboard::writeClipboard):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@99924 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/mac/EditorMac.mm
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/chromium/PasteboardChromium.cpp
Source/WebCore/platform/efl/PasteboardEfl.cpp
Source/WebCore/platform/gtk/ClipboardGtk.cpp
Source/WebCore/platform/gtk/ClipboardGtk.h
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebCore/platform/qt/ClipboardQt.cpp
Source/WebCore/platform/qt/PasteboardQt.cpp
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/platform/wince/PasteboardWinCE.cpp
Source/WebCore/platform/wx/PasteboardWx.cpp