toolkit/obsolete/content/nsClipboard.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /**
michael@0 7 * nsClipboard - wrapper around nsIClipboard and nsITransferable
michael@0 8 * that simplifies access to the clipboard.
michael@0 9 **/
michael@0 10 var nsClipboard = {
michael@0 11 _CB: null,
michael@0 12 get mClipboard()
michael@0 13 {
michael@0 14 if (!this._CB)
michael@0 15 {
michael@0 16 const kCBContractID = "@mozilla.org/widget/clipboard;1";
michael@0 17 const kCBIID = Components.interfaces.nsIClipboard;
michael@0 18 this._CB = Components.classes[kCBContractID].getService(kCBIID);
michael@0 19 }
michael@0 20 return this._CB;
michael@0 21 },
michael@0 22
michael@0 23 currentClipboard: null,
michael@0 24 /**
michael@0 25 * Array/Object read (Object aFlavourList, long aClipboard, Bool aAnyFlag) ;
michael@0 26 *
michael@0 27 * returns the data in the clipboard
michael@0 28 *
michael@0 29 * @param FlavourSet aFlavourSet
michael@0 30 * formatted list of desired flavours
michael@0 31 * @param long aClipboard
michael@0 32 * the clipboard to read data from (kSelectionClipboard/kGlobalClipboard)
michael@0 33 * @param Bool aAnyFlag
michael@0 34 * should be false.
michael@0 35 **/
michael@0 36 read: function (aFlavourList, aClipboard, aAnyFlag)
michael@0 37 {
michael@0 38 this.currentClipboard = aClipboard;
michael@0 39 var data = nsTransferable.get(aFlavourList, this.getClipboardTransferable, aAnyFlag);
michael@0 40 return data.first.first; // only support one item
michael@0 41 },
michael@0 42
michael@0 43 /**
michael@0 44 * nsISupportsArray getClipboardTransferable (Object aFlavourList) ;
michael@0 45 *
michael@0 46 * returns a nsISupportsArray of the item on the clipboard
michael@0 47 *
michael@0 48 * @param Object aFlavourList
michael@0 49 * formatted list of desired flavours.
michael@0 50 **/
michael@0 51 getClipboardTransferable: function (aFlavourList)
michael@0 52 {
michael@0 53 const supportsContractID = "@mozilla.org/supports-array;1";
michael@0 54 const supportsIID = Components.interfaces.nsISupportsArray;
michael@0 55 var supportsArray = Components.classes[supportsContractID].createInstance(supportsIID);
michael@0 56 var trans = nsTransferable.createTransferable();
michael@0 57 for (var flavour in aFlavourList)
michael@0 58 trans.addDataFlavor(flavour);
michael@0 59 nsClipboard.mClipboard.getData(trans, nsClipboard.currentClipboard)
michael@0 60 supportsArray.AppendElement(trans);
michael@0 61 return supportsArray;
michael@0 62 }
michael@0 63 };
michael@0 64

mercurial