widget/android/nsDeviceContextAndroid.cpp

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

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4 #include "nsDeviceContextAndroid.h"
     5 #include "nsString.h"
     6 #include "nsIFile.h"
     7 #include "nsIFileStreams.h"
     8 #include "nsAutoPtr.h"
     9 #include "gfxPDFSurface.h"
    10 #include "nsIPrintSettings.h"
    11 #include "nsDirectoryServiceDefs.h"
    13 NS_IMPL_ISUPPORTS(nsDeviceContextSpecAndroid, nsIDeviceContextSpec)
    15 NS_IMETHODIMP
    16 nsDeviceContextSpecAndroid::GetSurfaceForPrinter(gfxASurface** aSurface)
    17 {
    18   nsresult rv =
    19     NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mTempFile));
    20   NS_ENSURE_SUCCESS(rv, rv);
    22   nsAutoCString filename("tmp-printing.pdf");
    23   mTempFile->AppendNative(filename);
    24   rv = mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660);
    25   NS_ENSURE_SUCCESS(rv, rv);
    27   nsCOMPtr<nsIFileOutputStream> stream = do_CreateInstance("@mozilla.org/network/file-output-stream;1");
    28   rv = stream->Init(mTempFile, -1, -1, 0);
    29   NS_ENSURE_SUCCESS(rv, rv);
    31   nsRefPtr<gfxASurface> surface;
    33   // XXX: what should we do here for size? screen size?
    34   gfxSize surfaceSize(480, 800);
    36   surface = new gfxPDFSurface(stream, surfaceSize);
    39   NS_ABORT_IF_FALSE(surface, "valid address expected");
    40   surface.swap(*aSurface);
    41   return NS_OK;
    42 }
    44 NS_IMETHODIMP
    45 nsDeviceContextSpecAndroid::Init(nsIWidget* aWidget,
    46                              nsIPrintSettings* aPS,
    47                              bool aIsPrintPreview)
    48 {
    49   mPrintSettings = aPS;
    50   return NS_OK;
    51 }
    53 NS_IMETHODIMP
    54 nsDeviceContextSpecAndroid::BeginDocument(const nsAString& aTitle,
    55                                           char16_t* aPrintToFileName,
    56                                           int32_t aStartPage,
    57                                           int32_t aEndPage)
    58 {
    59   return NS_OK;
    60 }
    62 NS_IMETHODIMP
    63 nsDeviceContextSpecAndroid::EndDocument()
    64 {
    65   nsXPIDLString targetPath;
    66   nsCOMPtr<nsIFile> destFile;
    67   mPrintSettings->GetToFileName(getter_Copies(targetPath));
    69   nsresult rv = NS_NewNativeLocalFile(NS_ConvertUTF16toUTF8(targetPath),
    70                                       false, getter_AddRefs(destFile));
    71   NS_ENSURE_SUCCESS(rv, rv);
    73   nsAutoString destLeafName;
    74   rv = destFile->GetLeafName(destLeafName);
    75   NS_ENSURE_SUCCESS(rv, rv);
    77   nsCOMPtr<nsIFile> destDir;
    78   rv = destFile->GetParent(getter_AddRefs(destDir));
    79   NS_ENSURE_SUCCESS(rv, rv);
    81   rv = mTempFile->MoveTo(destDir, destLeafName);
    82   NS_ENSURE_SUCCESS(rv, rv);
    84   destFile->SetPermissions(0666);
    85   return NS_OK;
    86 }
    88 NS_IMETHODIMP
    89 nsDeviceContextSpecAndroid::GetPath (const char** aPath)
    90 {
    91   return NS_OK;
    92 }

mercurial