Title: [108085] trunk/Source/WebKit2
Revision
108085
Author
[email protected]
Date
2012-02-17 09:25:56 -0800 (Fri, 17 Feb 2012)

Log Message

[GTK] Allow printing only odd/even pages in WebKit2 for printers that don't support it
https://bugs.webkit.org/show_bug.cgi?id=78793

Reviewed by Gustavo Noronha Silva.

* UIProcess/API/gtk/WebKitPrintOperation.cpp:
(webkitPrintOperationRunDialogUnix): Enable print odd/even pages
option in print dialog.
* WebProcess/WebPage/gtk/WebPrintOperationGtk.h:
* WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp:
(WebKit::PrintPagesData::PrintPagesData): Add lastPagePosition and
initialize it depending on the page set.
(WebKit::PrintPagesData::incrementPageSequence): Use 2 step
increment when printing only odd/even pages.
(WebKit::WebPrintOperationGtk::WebPrintOperationGtk): Initialize
m_manualPageSet to GTK_PAGE_SET_ALL.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (108084 => 108085)


--- trunk/Source/WebKit2/ChangeLog	2012-02-17 17:06:11 UTC (rev 108084)
+++ trunk/Source/WebKit2/ChangeLog	2012-02-17 17:25:56 UTC (rev 108085)
@@ -1,5 +1,24 @@
 2012-02-17  Carlos Garcia Campos  <[email protected]>
 
+        [GTK] Allow printing only odd/even pages in WebKit2 for printers that don't support it
+        https://bugs.webkit.org/show_bug.cgi?id=78793
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * UIProcess/API/gtk/WebKitPrintOperation.cpp:
+        (webkitPrintOperationRunDialogUnix): Enable print odd/even pages
+        option in print dialog.
+        * WebProcess/WebPage/gtk/WebPrintOperationGtk.h:
+        * WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp:
+        (WebKit::PrintPagesData::PrintPagesData): Add lastPagePosition and
+        initialize it depending on the page set.
+        (WebKit::PrintPagesData::incrementPageSequence): Use 2 step
+        increment when printing only odd/even pages.
+        (WebKit::WebPrintOperationGtk::WebPrintOperationGtk): Initialize
+        m_manualPageSet to GTK_PAGE_SET_ALL.
+
+2012-02-17  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Allow printing multiple pages per sheet in WebKit2 for printers that don't support it
         https://bugs.webkit.org/show_bug.cgi?id=78715
 

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp	2012-02-17 17:06:11 UTC (rev 108084)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.cpp	2012-02-17 17:25:56 UTC (rev 108085)
@@ -201,7 +201,8 @@
 {
     GtkPrintUnixDialog* printDialog = GTK_PRINT_UNIX_DIALOG(gtk_print_unix_dialog_new(0, parent));
     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_NUMBER_UP_LAYOUT
+                                                                                                 | GTK_PRINT_CAPABILITY_PAGE_SET));
 
     WebKitPrintOperationPrivate* priv = printOperation->priv;
     if (priv->printSettings)

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


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp	2012-02-17 17:06:11 UTC (rev 108084)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.cpp	2012-02-17 17:25:56 UTC (rev 108085)
@@ -91,6 +91,7 @@
         // Manual capabilities.
         printOperation->m_numberUp = gtk_print_job_get_n_up(printOperation->m_printJob.get());
         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->print(surface, 72, 72);
     }
@@ -238,6 +239,23 @@
         else
             numberOfSheets = pages.size();
 
+        switch (printOperation->pageSet()) {
+        case GTK_PAGE_SET_ODD:
+            lastPagePosition = std::min(((numberOfSheets - 1) - ((numberOfSheets - 1) % 2)) * numberUp - 1, pages.size() - 1);
+            break;
+        case GTK_PAGE_SET_EVEN:
+            lastPagePosition = std::min(((numberOfSheets - 1) - (1 - (numberOfSheets - 1) % 2)) * numberUp - 1, pages.size() - 1);
+            sheetNumber = numberOfSheets > 1 ? 1 : -1;
+            break;
+        case GTK_PAGE_SET_ALL:
+            lastPagePosition = pages.size() - 1;
+            break;
+        }
+
+        // FIXME: check pagePostion is between [0..pages.size() - 1]
+        // and cancel the operation otherwise when error reporting
+        // is implemented.
+        printOperation->setPagePosition(sheetNumber * numberUp);
         pageNumber = pages[printOperation->pagePosition()];
     }
 
@@ -249,6 +267,11 @@
         }
 
         size_t pagePosition = printOperation->pagePosition();
+        if (pagePosition == lastPagePosition) {
+            isDone = true;
+            return;
+        }
+
         if (printOperation->currentPageIsLastPageOfSheet()) {
             sheetNumber++;
             pagePosition = sheetNumber * printOperation->numberUp();
@@ -272,6 +295,7 @@
     Vector<size_t> pages;
     size_t sheetNumber;
     size_t numberOfSheets;
+    size_t lastPagePosition;
 
     bool isDone : 1;
 };
@@ -303,6 +327,7 @@
     , m_needsRotation(false)
     , m_numberUp(1)
     , m_numberUpLayout(0)
+    , m_pageSet(GTK_PAGE_SET_ALL)
 {
 }
 

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


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.h	2012-02-17 17:06:11 UTC (rev 108084)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPrintOperationGtk.h	2012-02-17 17:25:56 UTC (rev 108085)
@@ -63,6 +63,7 @@
 
     unsigned int numberUp() const { return m_numberUp; }
     unsigned int numberUpLayout() const { return m_numberUpLayout; }
+    unsigned int pageSet() const { return m_pageSet; }
 
     virtual void startPrint(WebCore::PrintContext*, uint64_t callbackID) = 0;
 
@@ -104,6 +105,7 @@
     // Manual capabilities.
     unsigned int m_numberUp;
     unsigned int m_numberUpLayout;
+    unsigned int m_pageSet;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to