widget/xpwidgets/nsTransferable.h

changeset 0
6474c204b198
child 10
ac0c01689b40
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/xpwidgets/nsTransferable.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; 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 +#ifndef nsTransferable_h__
    1.10 +#define nsTransferable_h__
    1.11 +
    1.12 +#include "nsIFormatConverter.h"
    1.13 +#include "nsITransferable.h"
    1.14 +#include "nsCOMPtr.h"
    1.15 +#include "nsString.h"
    1.16 +#include "nsTArray.h"
    1.17 +
    1.18 +class nsString;
    1.19 +class nsDataObj;
    1.20 +
    1.21 +//
    1.22 +// DataStruct
    1.23 +//
    1.24 +// Holds a flavor (a mime type) that describes the data and the associated data.
    1.25 +//
    1.26 +struct DataStruct
    1.27 +{
    1.28 +  DataStruct ( const char* aFlavor )
    1.29 +    : mDataLen(0), mFlavor(aFlavor), mCacheFileName(nullptr) { }
    1.30 +  ~DataStruct();
    1.31 +  
    1.32 +  const nsCString& GetFlavor() const { return mFlavor; }
    1.33 +  void SetData( nsISupports* inData, uint32_t inDataLen );
    1.34 +  void GetData( nsISupports** outData, uint32_t *outDataLen );
    1.35 +  already_AddRefed<nsIFile> GetFileSpec(const char* aFileName);
    1.36 +  bool IsDataAvailable() const { return (mData && mDataLen > 0) || (!mData && mCacheFileName); }
    1.37 +  
    1.38 +protected:
    1.39 +
    1.40 +  enum {
    1.41 +    // The size of data over which we write the data to disk rather than
    1.42 +    // keep it around in memory.
    1.43 +    kLargeDatasetSize = 1000000        // 1 million bytes
    1.44 +  };
    1.45 +  
    1.46 +  nsresult WriteCache(nsISupports* aData, uint32_t aDataLen );
    1.47 +  nsresult ReadCache(nsISupports** aData, uint32_t* aDataLen );
    1.48 +  
    1.49 +  nsCOMPtr<nsISupports> mData;   // OWNER - some varient of primitive wrapper
    1.50 +  uint32_t mDataLen;
    1.51 +  const nsCString mFlavor;
    1.52 +  char *   mCacheFileName;
    1.53 +
    1.54 +};
    1.55 +
    1.56 +/**
    1.57 + * XP Transferable wrapper
    1.58 + */
    1.59 +
    1.60 +class nsTransferable : public nsITransferable
    1.61 +{
    1.62 +public:
    1.63 +
    1.64 +  nsTransferable();
    1.65 +  virtual ~nsTransferable();
    1.66 +
    1.67 +    // nsISupports
    1.68 +  NS_DECL_ISUPPORTS
    1.69 +  NS_DECL_NSITRANSFERABLE
    1.70 +
    1.71 +protected:
    1.72 +
    1.73 +    // get flavors w/out converter
    1.74 +  nsresult GetTransferDataFlavors(nsISupportsArray** aDataFlavorList);
    1.75 + 
    1.76 +  nsTArray<DataStruct> mDataArray;
    1.77 +  nsCOMPtr<nsIFormatConverter> mFormatConv;
    1.78 +  bool mPrivateData;
    1.79 +#if DEBUG
    1.80 +  bool mInitialized;
    1.81 +#endif
    1.82 +
    1.83 +};
    1.84 +
    1.85 +#endif // nsTransferable_h__

mercurial