Commit 4ad4deab authored by Edgar Chen's avatar Edgar Chen
Browse files

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
parent 1950c560
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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;
+13 −29
Original line number Diff line number Diff line
@@ -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 (!mEmptyingForSetData) {
    if (aWhichClipboard == kSelectionCache) {
      ClearSelectionCache();
    return NS_OK;
  }

  if (!mEmptyingForSetData) {
    } else {
      if (NSPasteboard* cocoaPasteboard = GetPasteboard(aWhichClipboard)) {
        [cocoaPasteboard clearContents];
      }
      if (mCachedClipboard == aWhichClipboard) {
        mCachedClipboard = -1;
        mChangeCount = 0;
+1 −5
Original line number Diff line number Diff line
@@ -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;
+7 −10
Original line number Diff line number Diff line
@@ -50,8 +50,6 @@ 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);
@@ -60,7 +58,6 @@ function testClipboardOwner(aClipboardType, aAsync) {
    losingOwnership = false;
    writeRandomStringToClipboard("text/plain", aClipboardType, null, true);
    ok(losingOwnership, `Should lose ownership while async setting data to type ${aClipboardType}`);
    }

    // Clean clipboard data.
    cleanupAllClipboard();