diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java index 2c8cfdeafd9..e72ea0d6b3d 100644 --- a/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java @@ -303,20 +303,22 @@ public void selectAll() { public void print() { - getWrapperFactory().verifyInitialized(); - - synchronized(getBrowserControl()) { - nativePrint(getNativeBrowserControl()); - } + NativeEventThread.instance.pushRunnable(new Runnable() { + public void run() { + nativePrint(CurrentPageImpl.this.getNativeBrowserControl()); + } + }); } -public void printPreview(boolean preview) +public void printPreview(boolean pre) { - getWrapperFactory().verifyInitialized(); - - synchronized(getBrowserControl()) { - nativePrintPreview(getNativeBrowserControl(), preview); - } + final boolean preview = pre; + NativeEventThread.instance.pushRunnable(new Runnable() { + public void run() { + nativePrintPreview(CurrentPageImpl.this.getNativeBrowserControl(), + preview); + } + }); } // diff --git a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp index 6eac3a98c5e..8b686742ac0 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp +++ b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp @@ -39,6 +39,8 @@ #include "nsIWebBrowser.h" #include "nsIWebBrowserFind.h" +#include "nsIWebBrowserPrint.h" +#include "nsIPrintSettings.h" #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsIDOMRange.h" @@ -528,8 +530,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa } } -#if 0 // convenience - /* * Class: org_mozilla_webclient_impl_wrapper_0005fnative_CurrentPageImpl * Method: nativePrint @@ -539,10 +539,33 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa (JNIEnv * env, jobject obj, jint nativeBCPtr) { NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr; - if (nativeBrowserControl->initComplete) { - wsPrintEvent * actionEvent = new wsPrintEvent(nativeBrowserControl); - PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostEvent(nativeBrowserControl, event); + nsresult rv; + nsCOMPtr webBrowser; + nsCOMPtr printSettings; + + // get the web browser + rv = nativeBrowserControl->mWindow->GetWebBrowser(getter_AddRefs(webBrowser)); + if (NS_FAILED(rv) || !webBrowser) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't get WebBrowser"); + } + + // get the print interface + nsCOMPtr print(do_GetInterface(webBrowser)); + if (!print) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't get nsIWebBrowserPrint"); + } + + rv = print->GetGlobalPrintSettings(getter_AddRefs(printSettings)); + if (NS_FAILED(rv) || !printSettings) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't get printSettings"); + + } + // XXX kyle: we have to disable the Print Progress dialog until we are able to show the java native dialog. + printSettings->SetShowPrintProgress(PR_FALSE); + rv = print->Print(printSettings, nsnull); + + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't print"); } } @@ -555,11 +578,40 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa (JNIEnv * env, jobject obj, jint nativeBCPtr, jboolean preview) { NativeBrowserControl* nativeBrowserControl = (NativeBrowserControl *) nativeBCPtr; - if (nativeBrowserControl->initComplete) { - wsPrintPreviewEvent * actionEvent = new wsPrintPreviewEvent(nativeBrowserControl, preview); - PLEvent * event = (PLEvent*) *actionEvent; - ::util_PostEvent(nativeBrowserControl, event); + nsresult rv; + nsCOMPtr webBrowser; + nsCOMPtr printSettings; + + // get the web browser + rv = nativeBrowserControl->mWindow->GetWebBrowser(getter_AddRefs(webBrowser)); + if (NS_FAILED(rv) || !webBrowser) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't get WebBrowser"); } + + // get the print interface + nsCOMPtr print(do_GetInterface(webBrowser)); + if (!print) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't get nsIWebBrowserPrint"); + } + + rv = print->GetGlobalPrintSettings(getter_AddRefs(printSettings)); + if (NS_FAILED(rv) || !printSettings) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't get printSettings"); + + } + // XXX kyle: we have to disable the Print Progress dialog by now because we are unable to show the java native dialog yet. + printSettings->SetShowPrintProgress(PR_FALSE); + printSettings->SetShowPrintProgress(PR_FALSE); + if (preview) { + rv = print->PrintPreview(printSettings, nsnull, nsnull); + } + else { + rv = print->ExitPrintPreview(); + } + + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativePrint: Can't print"); + } + } -# endif // if 0 diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java index 8f3e7b1e247..55664bc10da 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java @@ -1,5 +1,5 @@ /* - * $Id: CurrentPageTest.java,v 1.8 2005-02-14 02:16:18 edburns%acm.org Exp $ + * $Id: CurrentPageTest.java,v 1.9 2005-02-14 02:37:51 edburns%acm.org Exp $ */ /* @@ -377,6 +377,122 @@ public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner assertEquals(0, selection.toString().length()); + frame.setVisible(false); + BrowserControlFactory.deleteBrowserControl(firstBrowserControl); + } + + public void NoIdeaHowToTestPrintingUsingJunit() throws Exception { + BrowserControl firstBrowserControl = null; + DocumentLoadListenerImpl listener = null; + Selection selection = null; + firstBrowserControl = BrowserControlFactory.newBrowserControl(); + assertNotNull(firstBrowserControl); + BrowserControlCanvas canvas = (BrowserControlCanvas) + firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME); + eventRegistration = (EventRegistration2) + firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); + + assertNotNull(canvas); + Frame frame = new Frame(); + frame.setUndecorated(true); + frame.setBounds(0, 0, 640, 480); + frame.add(canvas, BorderLayout.CENTER); + frame.setVisible(true); + canvas.setVisible(true); + + Navigation2 nav = (Navigation2) + firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME); + assertNotNull(nav); + currentPage = (CurrentPage2) + firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); + + assertNotNull(currentPage); + + eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() { + public void doEndCheck() { + CurrentPageTest.keepWaiting = false; + } + }); + + Thread.currentThread().sleep(3000); + + + // + // load four files. + // + CurrentPageTest.keepWaiting = true; + + nav.loadURL("http://localhost:5243/HistoryTest0.html"); + + // keep waiting until the previous load completes + while (CurrentPageTest.keepWaiting) { + Thread.currentThread().sleep(1000); + } + + currentPage.print(); + + Thread.currentThread().sleep(10000); + + + frame.setVisible(false); + BrowserControlFactory.deleteBrowserControl(firstBrowserControl); + } + + public void testPrintPreview() throws Exception { + BrowserControl firstBrowserControl = null; + DocumentLoadListenerImpl listener = null; + Selection selection = null; + firstBrowserControl = BrowserControlFactory.newBrowserControl(); + assertNotNull(firstBrowserControl); + BrowserControlCanvas canvas = (BrowserControlCanvas) + firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME); + eventRegistration = (EventRegistration2) + firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); + + assertNotNull(canvas); + Frame frame = new Frame(); + frame.setUndecorated(true); + frame.setBounds(0, 0, 640, 480); + frame.add(canvas, BorderLayout.CENTER); + frame.setVisible(true); + canvas.setVisible(true); + + Navigation2 nav = (Navigation2) + firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME); + assertNotNull(nav); + currentPage = (CurrentPage2) + firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); + + assertNotNull(currentPage); + + eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() { + public void doEndCheck() { + CurrentPageTest.keepWaiting = false; + } + }); + + Thread.currentThread().sleep(3000); + + + // + // load four files. + // + CurrentPageTest.keepWaiting = true; + + nav.loadURL("http://localhost:5243/HistoryTest0.html"); + + // keep waiting until the previous load completes + while (CurrentPageTest.keepWaiting) { + Thread.currentThread().sleep(1000); + } + + currentPage.printPreview(true); + + Thread.currentThread().sleep(3000); + + currentPage.printPreview(false); + + frame.setVisible(false); BrowserControlFactory.deleteBrowserControl(firstBrowserControl); }