• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.printing;
6 
7 import android.print.PrintDocumentAdapter;
8 
9 /**
10  * This interface describes a class which is responsible of talking to the printing backend.
11  *
12  * Such class communicates with a {@link PrintingContext}, which in turn talks to the native side.
13  */
14 public interface PrintingController {
15     /**
16      * @return Dots Per Inch (DPI) of the currently selected printer.
17      */
getDpi()18     int getDpi();
19 
20     /**
21      * @return The file descriptor number of the file into which Chromium will write the PDF.  This
22      *         is provided to us by {@link PrintDocumentAdapter#onWrite}.
23      */
getFileDescriptor()24     int getFileDescriptor();
25 
26     /**
27      * @return The media height in mils (thousands of an inch).
28      */
getPageHeight()29     int getPageHeight();
30 
31     /**
32      * @return The media width in mils (thousands of an inch).
33      */
getPageWidth()34     int getPageWidth();
35 
36     /**
37      * @return The individual page numbers of the document to be printed, of null if all pages are
38      *         to be printed.  The numbers are zero indexed.
39      */
getPageNumbers()40     int[] getPageNumbers();
41 
42     /**
43      * @return If the controller is busy.
44      */
isBusy()45     public boolean isBusy();
46 
47     /**
48      * Initiates the printing process for the Android API.
49      *
50      * @param printable An object capable of starting native side PDF generation, i.e. typically
51      *                  a Tab.
52      * @param printManager The print manager that manages the print job.
53      */
startPrint(final Printable printable, PrintManagerDelegate printManager)54     void startPrint(final Printable printable, PrintManagerDelegate printManager);
55 
56     /**
57      * This method is called by the native side to signal PDF writing process is completed.
58      *
59      * @param success Whether the PDF is written into the provided file descriptor successfully.
60      */
pdfWritingDone(boolean success)61     void pdfWritingDone(boolean success);
62 
63     /**
64      * Called when the native side estimates the number of pages in the PDF (before generation).
65      *
66      * @param maxPages Number of pages in the PDF, according to the last provided settings.
67      *                 If this is PrintDocumentInfo.PAGE_COUNT_UNKNOWN, then use the last known
68      *                 valid max pages count.
69      */
pageCountEstimationDone(final int maxPages)70     void pageCountEstimationDone(final int maxPages);
71 
72     /**
73      * Sets PrintingContext currently associated with the controller.
74      *
75      * This needs to be called after PrintingContext object is created. Firstly its native
76      * counterpart is created, and then the Java.  PrintingController implementation
77      * needs this to interact with the native side, since JNI is built on PrintingContext.
78      **/
setPrintingContext(final PrintingContextInterface printingContext)79     void setPrintingContext(final PrintingContextInterface printingContext);
80 
81     /**
82      * @return Whether a complete PDF generation cycle inside Chromium has been completed.
83      */
hasPrintingFinished()84     boolean hasPrintingFinished();
85 }
86