diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-23 14:04:34 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-23 14:04:34 -0500 |
commit | 6f93b00559c8fe5b8dfaf59fcbaac8f1e0dd3366 (patch) | |
tree | 4f39457e7407bcbdbb72888622982675d2ef0054 /toolkit/content/nsClipboard.js | |
parent | be18578af63e60da83d25e44fa731213ddf087e2 (diff) | |
download | UXP-6f93b00559c8fe5b8dfaf59fcbaac8f1e0dd3366.tar UXP-6f93b00559c8fe5b8dfaf59fcbaac8f1e0dd3366.tar.gz UXP-6f93b00559c8fe5b8dfaf59fcbaac8f1e0dd3366.tar.lz UXP-6f93b00559c8fe5b8dfaf59fcbaac8f1e0dd3366.tar.xz UXP-6f93b00559c8fe5b8dfaf59fcbaac8f1e0dd3366.zip |
Restore toolkit/obsolete files and reinstate them to toolkit/content
Diffstat (limited to 'toolkit/content/nsClipboard.js')
-rw-r--r-- | toolkit/content/nsClipboard.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/toolkit/content/nsClipboard.js b/toolkit/content/nsClipboard.js new file mode 100644 index 000000000..d9f7c4589 --- /dev/null +++ b/toolkit/content/nsClipboard.js @@ -0,0 +1,64 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * nsClipboard - wrapper around nsIClipboard and nsITransferable + * that simplifies access to the clipboard. + **/ +var nsClipboard = { + _CB: null, + get mClipboard() + { + if (!this._CB) + { + const kCBContractID = "@mozilla.org/widget/clipboard;1"; + const kCBIID = Components.interfaces.nsIClipboard; + this._CB = Components.classes[kCBContractID].getService(kCBIID); + } + return this._CB; + }, + + currentClipboard: null, + /** + * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ; + * + * returns the data in the clipboard + * + * @param FlavourSet aFlavourSet + * formatted list of desired flavours + * @param long aClipboard + * the clipboard to read data from (kSelectionClipboard/kGlobalClipboard) + * @param Bool aAnyFlag + * should be false. + **/ + read: function (aFlavourList, aClipboard, aAnyFlag) + { + this.currentClipboard = aClipboard; + var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag); + return data.first.first; // only support one item + }, + + /** + * nsISupportsArray getClipboardTransferable (Object aFlavourList) ; + * + * returns a nsISupportsArray of the item on the clipboard + * + * @param Object aFlavourList + * formatted list of desired flavours. + **/ + getClipboardTransferable: function (aFlavourList) + { + const supportsContractID = "@mozilla.org/supports-array;1"; + const supportsIID = Components.interfaces.nsISupportsArray; + var supportsArray = Components.classes[supportsContractID].createInstance(supportsIID); + var trans = nsTransferable.createTransferable(); + for (var flavour in aFlavourList) + trans.addDataFlavor(flavour); + nsClipboard.mClipboard.getData(trans, nsClipboard.currentClipboard) + supportsArray.AppendElement(trans); + return supportsArray; + } +}; + |