зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1812078 - Part 2: Make SelectionCache type behave more generic; r=mstange
This also makes SelectionCache type supports clipboard owner. Differential Revision: https://phabricator.services.mozilla.com/D168006
This commit is contained in:
Родитель
1950c56084
Коммит
4ad4deaba0
|
@ -24,8 +24,6 @@ class nsClipboard : public nsBaseClipboard {
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIClipboard
|
||||
NS_IMETHOD SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner,
|
||||
int32_t aWhichClipboard) override;
|
||||
NS_IMETHOD HasDataMatchingFlavors(const nsTArray<nsCString>& aFlavorList, int32_t aWhichClipboard,
|
||||
bool* _retval) override;
|
||||
NS_IMETHOD EmptyClipboard(int32_t aWhichClipboard) override;
|
||||
|
|
|
@ -85,8 +85,13 @@ nsClipboard::SetNativeClipboardData(nsITransferable* aTransferable, nsIClipboard
|
|||
int32_t aWhichClipboard) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if ((aWhichClipboard != kGlobalClipboard && aWhichClipboard != kFindClipboard) || !aTransferable)
|
||||
return NS_ERROR_FAILURE;
|
||||
MOZ_ASSERT(aTransferable);
|
||||
MOZ_ASSERT(nsIClipboard::IsClipboardTypeSupported(aWhichClipboard));
|
||||
|
||||
if (aWhichClipboard == kSelectionCache) {
|
||||
SetSelectionCache(aTransferable);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NSDictionary* pasteboardOutputDict = PasteboardDictFromTransferable(aTransferable);
|
||||
if (!pasteboardOutputDict) return NS_ERROR_FAILURE;
|
||||
|
@ -747,38 +752,17 @@ NSString* nsClipboard::WrapHtmlForSystemPasteboard(NSString* aString) {
|
|||
return wrapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the transferable object
|
||||
*
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsClipboard::SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner,
|
||||
int32_t aWhichClipboard) {
|
||||
NS_ASSERTION(aTransferable, "clipboard given a null transferable");
|
||||
|
||||
if (aWhichClipboard == kSelectionCache) {
|
||||
if (aTransferable) {
|
||||
SetSelectionCache(aTransferable);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return nsBaseClipboard::SetData(aTransferable, anOwner, aWhichClipboard);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsClipboard::EmptyClipboard(int32_t aWhichClipboard) {
|
||||
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
|
||||
|
||||
if (aWhichClipboard == kSelectionCache) {
|
||||
ClearSelectionCache();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!mEmptyingForSetData) {
|
||||
if (NSPasteboard* cocoaPasteboard = GetPasteboard(aWhichClipboard)) {
|
||||
[cocoaPasteboard clearContents];
|
||||
if (aWhichClipboard == kSelectionCache) {
|
||||
ClearSelectionCache();
|
||||
} else {
|
||||
if (NSPasteboard* cocoaPasteboard = GetPasteboard(aWhichClipboard)) {
|
||||
[cocoaPasteboard clearContents];
|
||||
}
|
||||
if (mCachedClipboard == aWhichClipboard) {
|
||||
mCachedClipboard = -1;
|
||||
mChangeCount = 0;
|
||||
|
|
|
@ -38,10 +38,6 @@ class ClipboardSetDataHelper : public nsIClipboard {
|
|||
ClipboardSetDataHelper() = default;
|
||||
|
||||
// nsIClipboard
|
||||
// XXX the Cocoa widget currently overrides `SetData` for `kSelectionCache`
|
||||
// type, so it cannot be marked as final. Once the Cocoa widget handles
|
||||
// `kSelectionCache` type more generic after bug 1812078, it can be marked
|
||||
// as final, too.
|
||||
NS_IMETHOD SetData(nsITransferable* aTransferable, nsIClipboardOwner* aOwner,
|
||||
int32_t aWhichClipboard) override;
|
||||
NS_IMETHOD AsyncSetData(int32_t aWhichClipboard,
|
||||
|
@ -108,7 +104,7 @@ class nsBaseClipboard : public ClipboardSetDataHelper {
|
|||
|
||||
// nsIClipboard
|
||||
NS_IMETHOD SetData(nsITransferable* aTransferable, nsIClipboardOwner* anOwner,
|
||||
int32_t aWhichClipboard) override;
|
||||
int32_t aWhichClipboard) override final;
|
||||
NS_IMETHOD GetData(nsITransferable* aTransferable,
|
||||
int32_t aWhichClipboard) override;
|
||||
NS_IMETHOD EmptyClipboard(int32_t aWhichClipboard) override;
|
||||
|
|
|
@ -50,17 +50,14 @@ function testClipboardOwner(aClipboardType, aAsync) {
|
|||
}
|
||||
});
|
||||
|
||||
// XXX We don't support clipboard owner for kSelectionCache type.
|
||||
if (aClipboardType != clipboard.kSelectionCache) {
|
||||
// Test whether should lose ownership.
|
||||
losingOwnership = false;
|
||||
writeRandomStringToClipboard("text/plain", aClipboardType, clipboardOwner);
|
||||
ok(losingOwnership, `Should lose ownership while setting data to type ${aClipboardType}`);
|
||||
// Test whether should lose ownership.
|
||||
losingOwnership = false;
|
||||
writeRandomStringToClipboard("text/plain", aClipboardType, clipboardOwner);
|
||||
ok(losingOwnership, `Should lose ownership while setting data to type ${aClipboardType}`);
|
||||
|
||||
losingOwnership = false;
|
||||
writeRandomStringToClipboard("text/plain", aClipboardType, null, true);
|
||||
ok(losingOwnership, `Should lose ownership while async setting data to type ${aClipboardType}`);
|
||||
}
|
||||
losingOwnership = false;
|
||||
writeRandomStringToClipboard("text/plain", aClipboardType, null, true);
|
||||
ok(losingOwnership, `Should lose ownership while async setting data to type ${aClipboardType}`);
|
||||
|
||||
// Clean clipboard data.
|
||||
cleanupAllClipboard();
|
||||
|
|
Загрузка…
Ссылка в новой задаче