Title: [108089] trunk/Source/WebKit2
Revision
108089
Author
[email protected]
Date
2012-02-17 10:08:18 -0800 (Fri, 17 Feb 2012)

Log Message

[GTK] Allow printing multiple copies in WebKit2 for printers that don't support it
https://bugs.webkit.org/show_bug.cgi?id=78805

Reviewed by Gustavo Noronha Silva.

* UIProcess/API/gtk/WebKitPrintOperation.cpp:
(webkitPrintOperationRunDialogUnix): Enable multiple copies and
collate options in print dialog.
* WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp:
(WebKit::PrintPagesData::PrintPagesData): Initialize number of
collated and uncolated copies done and total.
(WebKit::PrintPagesData::collatedCopiesLeft): Helper function that
returns the number of collated copies left to do.
(WebKit::PrintPagesData::uncollatedCopiesLeft): Helper function
that returns the number of uncollated copies left to do.
(WebKit::PrintPagesData::copiesLeft): Helper function
that returns the number of collated or uncollated copies left to
do.
(WebKit::PrintPagesData::incrementPageSequence): Do not finish the
print if there are uncollated copies left, and do not increment
sheet number if there are collated copies left.
(WebKit::WebPrintOperationGtk::WebPrintOperationGtk): Initialize
m_manualCopies to 1 and m_manualCollateCopies to false.
* WebProcess/WebPage/gtk/WebPrintOperationGtk.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (108088 => 108089)


--- trunk/Source/WebKit2/ChangeLog	2012-02-17 18:05:33 UTC (rev 108088)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-17 18:08:18 UTC (rev 108089)
@@ -1,5 +1,32 @@
 2012-02-17  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Allow printing multiple copies in WebKit2 for printers that don't support it
+        https://bugs.webkit.org/show_bug.cgi?id=78805
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * UIProcess/API/gtk/WebKitPrintOperation.cpp:
+        (webkitPrintOperationRunDialogUnix): Enable multiple copies and
+        collate options in print dialog.
+        * WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp:
+        (WebKit::PrintPagesData::PrintPagesData): Initialize number of
+        collated and uncolated copies done and total.
+        (WebKit::PrintPagesData::collatedCopiesLeft): Helper function that
+        returns the number of collated copies left to do.
+        (WebKit::PrintPagesData::uncollatedCopiesLeft): Helper function
+        that returns the number of uncollated copies left to do.
+        (WebKit::PrintPagesData::copiesLeft): Helper function
+        that returns the number of collated or uncollated copies left to
+        do.
+        (WebKit::PrintPagesData::incrementPageSequence): Do not finish the
+        print if there are uncollated copies left, and do not increment
+        sheet number if there are collated copies left.
+        (WebKit::WebPrintOperationGtk::WebPrintOperationGtk): Initialize
+        m_manualCopies to 1 and m_manualCollateCopies to false.
+        * WebProcess/WebPage/gtk/WebPrintOperationGtk.h:
+
+2012-02-17  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Allow printing pages in reverse order in WebKit2 for printers that don't support it
         https://bugs.webkit.org/show_bug.cgi?id=78799
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp (108088 => 108089)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp	2012-02-17 18:05:33 UTC (rev 108088)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp	2012-02-17 18:08:18 UTC (rev 108089)
@@ -203,7 +203,9 @@
     gtk_print_unix_dialog_set_manual_capabilities(printDialog, static_cast<GtkPrintCapabilities>(GTK_PRINT_CAPABILITY_NUMBER_UP
                                                                                                  | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT
                                                                                                  | GTK_PRINT_CAPABILITY_PAGE_SET
-                                                                                                 | GTK_PRINT_CAPABILITY_REVERSE));
+                                                                                                 | GTK_PRINT_CAPABILITY_REVERSE
+                                                                                                 | GTK_PRINT_CAPABILITY_COPIES
+                                                                                                 | GTK_PRINT_CAPABILITY_COLLATE));
 
     WebKitPrintOperationPrivate* priv = printOperation->priv;
     if (priv->printSettings)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp (108088 => 108089)


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp	2012-02-17 18:05:33 UTC (rev 108088)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp	2012-02-17 18:08:18 UTC (rev 108089)
@@ -93,6 +93,8 @@
         printOperation->m_numberUpLayout = gtk_print_job_get_n_up_layout(printOperation->m_printJob.get());
         printOperation->m_pageSet = gtk_print_job_get_page_set(printOperation->m_printJob.get());
         printOperation->m_reverse = gtk_print_job_get_reverse(printOperation->m_printJob.get());
+        printOperation->m_copies = gtk_print_job_get_num_copies(printOperation->m_printJob.get());
+        printOperation->m_collateCopies = gtk_print_job_get_collate(printOperation->m_printJob.get());
 
         printOperation->print(surface, 72, 72);
     }
@@ -201,9 +203,21 @@
         , totalPrinted(-1)
         , pageNumber(0)
         , sheetNumber(0)
+        , firstSheetNumber(0)
         , numberOfSheets(0)
+        , firstPagePosition(0)
+        , collated(0)
+        , uncollated(0)
         , isDone(false)
     {
+        if (printOperation->collateCopies()) {
+            collatedCopies = printOperation->copies();
+            uncollatedCopies = 1;
+        } else {
+            collatedCopies = 1;
+            uncollatedCopies = printOperation->copies();
+        }
+
         if (printOperation->pagesToPrint() == GTK_PRINT_PAGES_RANGES) {
             Vector<GtkPageRange> pageRanges;
             GtkPageRange* ranges = printOperation->pageRanges();
@@ -272,8 +286,25 @@
         // is implemented.
         printOperation->setPagePosition(sheetNumber * numberUp);
         pageNumber = pages[printOperation->pagePosition()];
+        firstPagePosition = printOperation->pagePosition();
+        firstSheetNumber = sheetNumber;
     }
 
+    size_t collatedCopiesLeft()
+    {
+        return collatedCopies > 1 ? collatedCopies - collated - 1 : 0;
+    }
+
+    size_t uncollatedCopiesLeft()
+    {
+        return uncollatedCopies > 1 ? uncollatedCopies - uncollated - 1 : 0;
+    }
+
+    size_t copiesLeft()
+    {
+        return collatedCopiesLeft() + uncollatedCopiesLeft();
+    }
+
     void incrementPageSequence()
     {
         if (totalPrinted == -1) {
@@ -282,15 +313,23 @@
         }
 
         size_t pagePosition = printOperation->pagePosition();
-        if (pagePosition == lastPagePosition) {
+        if (pagePosition == lastPagePosition && !copiesLeft()) {
             isDone = true;
             return;
         }
 
-        if (printOperation->currentPageIsLastPageOfSheet()) {
-            int step = printOperation->pageSet() == GTK_PAGE_SET_ALL ? 1 : 2;
-            step *= printOperation->reverse() ? -1 : 1;
-            sheetNumber += step;
+        if (pagePosition == lastPagePosition && uncollatedCopiesLeft()) {
+            pagePosition = firstPagePosition;
+            sheetNumber = firstSheetNumber;
+            uncollated++;
+        } else if (printOperation->currentPageIsLastPageOfSheet()) {
+            if (!collatedCopiesLeft()) {
+                int step = printOperation->pageSet() == GTK_PAGE_SET_ALL ? 1 : 2;
+                step *= printOperation->reverse() ? -1 : 1;
+                sheetNumber += step;
+                collated = 0;
+            } else
+                collated++;
             pagePosition = sheetNumber * printOperation->numberUp();
         } else
             pagePosition++;
@@ -311,8 +350,14 @@
     int pageNumber;
     Vector<size_t> pages;
     size_t sheetNumber;
+    size_t firstSheetNumber;
     size_t numberOfSheets;
+    size_t firstPagePosition;
     size_t lastPagePosition;
+    size_t collated;
+    size_t uncollated;
+    size_t collatedCopies;
+    size_t uncollatedCopies;
 
     bool isDone : 1;
 };
@@ -346,6 +391,8 @@
     , m_numberUpLayout(0)
     , m_pageSet(GTK_PAGE_SET_ALL)
     , m_reverse(false)
+    , m_copies(1)
+    , m_collateCopies(false)
 {
 }
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.h (108088 => 108089)


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.h	2012-02-17 18:05:33 UTC (rev 108088)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.h	2012-02-17 18:08:18 UTC (rev 108089)
@@ -65,6 +65,8 @@
     unsigned int numberUpLayout() const { return m_numberUpLayout; }
     unsigned int pageSet() const { return m_pageSet; }
     bool reverse() const { return m_reverse; }
+    unsigned int copies() const { return m_copies; }
+    bool collateCopies() const { return m_collateCopies; }
 
     virtual void startPrint(WebCore::PrintContext*, uint64_t callbackID) = 0;
 
@@ -108,6 +110,8 @@
     unsigned int m_numberUpLayout;
     unsigned int m_pageSet;
     bool m_reverse;
+    unsigned int m_copies;
+    bool m_collateCopies;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to