1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/obsolete/content/nsClipboard.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * nsClipboard - wrapper around nsIClipboard and nsITransferable 1.11 + * that simplifies access to the clipboard. 1.12 + **/ 1.13 +var nsClipboard = { 1.14 + _CB: null, 1.15 + get mClipboard() 1.16 + { 1.17 + if (!this._CB) 1.18 + { 1.19 + const kCBContractID = "@mozilla.org/widget/clipboard;1"; 1.20 + const kCBIID = Components.interfaces.nsIClipboard; 1.21 + this._CB = Components.classes[kCBContractID].getService(kCBIID); 1.22 + } 1.23 + return this._CB; 1.24 + }, 1.25 + 1.26 + currentClipboard: null, 1.27 + /** 1.28 + * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ; 1.29 + * 1.30 + * returns the data in the clipboard 1.31 + * 1.32 + * @param FlavourSet aFlavourSet 1.33 + * formatted list of desired flavours 1.34 + * @param long aClipboard 1.35 + * the clipboard to read data from (kSelectionClipboard/kGlobalClipboard) 1.36 + * @param Bool aAnyFlag 1.37 + * should be false. 1.38 + **/ 1.39 + read: function (aFlavourList, aClipboard, aAnyFlag) 1.40 + { 1.41 + this.currentClipboard = aClipboard; 1.42 + var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag); 1.43 + return data.first.first; // only support one item 1.44 + }, 1.45 + 1.46 + /** 1.47 + * nsISupportsArray getClipboardTransferable (Object aFlavourList) ; 1.48 + * 1.49 + * returns a nsISupportsArray of the item on the clipboard 1.50 + * 1.51 + * @param Object aFlavourList 1.52 + * formatted list of desired flavours. 1.53 + **/ 1.54 + getClipboardTransferable: function (aFlavourList) 1.55 + { 1.56 + const supportsContractID = "@mozilla.org/supports-array;1"; 1.57 + const supportsIID = Components.interfaces.nsISupportsArray; 1.58 + var supportsArray = Components.classes[supportsContractID].createInstance(supportsIID); 1.59 + var trans = nsTransferable.createTransferable(); 1.60 + for (var flavour in aFlavourList) 1.61 + trans.addDataFlavor(flavour); 1.62 + nsClipboard.mClipboard.getData(trans, nsClipboard.currentClipboard) 1.63 + supportsArray.AppendElement(trans); 1.64 + return supportsArray; 1.65 + } 1.66 +}; 1.67 +