void copyConstructor_data() { genericData(); }
void assignment_data() { genericData(); }
void settersAndGetters_data() { genericData(); }
NS_IMETHODIMP nsClipboardHelper::CopyStringToClipboard(const nsAString& aString, int32_t aClipboardID, nsIDOMDocument* aDocument) { nsresult rv; // get the clipboard nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(clipboard, NS_ERROR_FAILURE); // don't go any further if they're asking for the selection // clipboard on a platform which doesn't support it (i.e., unix) if (nsIClipboard::kSelectionClipboard == aClipboardID) { bool clipboardSupported; rv = clipboard->SupportsSelectionClipboard(&clipboardSupported); NS_ENSURE_SUCCESS(rv, rv); if (!clipboardSupported) return NS_ERROR_FAILURE; } // create a transferable for putting data on the clipboard nsCOMPtr<nsITransferable> trans(do_CreateInstance("@mozilla.org/widget/transferable;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE); nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDocument); nsILoadContext* loadContext = doc ? doc->GetLoadContext() : nullptr; trans->Init(loadContext); // Add the text data flavor to the transferable rv = trans->AddDataFlavor(kUnicodeMime); NS_ENSURE_SUCCESS(rv, rv); // get wStrings to hold clip data nsCOMPtr<nsISupportsString> data(do_CreateInstance("@mozilla.org/supports-string;1", &rv)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(data, NS_ERROR_FAILURE); // populate the string rv = data->SetData(aString); NS_ENSURE_SUCCESS(rv, rv); // qi the data object an |nsISupports| so that when the transferable holds // onto it, it will addref the correct interface. nsCOMPtr<nsISupports> genericData(do_QueryInterface(data, &rv)); NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(genericData, NS_ERROR_FAILURE); // set the transfer data rv = trans->SetTransferData(kUnicodeMime, genericData, aString.Length() * 2); NS_ENSURE_SUCCESS(rv, rv); // put the transferable on the clipboard rv = clipboard->SetData(trans, nullptr, aClipboardID); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }