This checkin re-enables printing. Thanks to Kyle Yuan from Sun Microsystems.

Next step is to take a step back and see what's best to do next!

M classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java

- call through to print related methods

M src_moz/CurrentPageImpl.cpp

- Copy from CurrentPageActionEvents.cpp

M test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java

- add test stub for print preview.
This commit is contained in:
edburns%acm.org 2005-02-14 02:37:51 +00:00
parent ab7af6537a
commit 2bd243cbb6
3 changed files with 193 additions and 23 deletions

View File

@ -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);
}
});
}
//

View File

@ -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<nsIWebBrowser> webBrowser;
nsCOMPtr<nsIPrintSettings> 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<nsIWebBrowserPrint> 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<nsIWebBrowser> webBrowser;
nsCOMPtr<nsIPrintSettings> 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<nsIWebBrowserPrint> 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

View File

@ -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);
}