summaryrefslogtreecommitdiffstats
path: root/toolkit/obsolete/content/nsClipboard.js
blob: d9f7c45897ed5dc8b0967620b250c3e08053ce96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;
    }
};