Implement progress dialog for printing and PP that show before reflow

Bug 154136 r=dcone/sgehani sr=alecf
This commit is contained in:
rods%netscape.com 2002-07-09 12:39:02 +00:00
parent 8d81b61c50
commit 1ba1fcde85
24 changed files with 1011 additions and 223 deletions

View File

@ -158,7 +158,7 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
// Print Progress
#include "nsIPrintProgress.h"
#include "nsIPrintProgressParams.h"
#include "nsIObserver.h"
// Print error dialog
#include "nsIPrompt.h"
@ -433,7 +433,8 @@ public:
nsCOMPtr<nsIWebProgressListener> mPrintProgressListener;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIPrintProgressParams> mPrintProgressParams;
PRBool mShowProgressDialog;
PRBool mShowProgressDialog; // means we should try to show it
PRPackedBool mProgressDialogIsShown; // means it is already being shown
nsCOMPtr<nsIDOMWindowInternal> mCurrentFocusWin; // cache a pointer to the currently focused window
@ -484,7 +485,8 @@ class DocumentViewerImpl : public nsIDocumentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile,
public nsIMarkupDocumentViewer,
public nsIWebBrowserPrint
public nsIWebBrowserPrint,
public nsIObserver
{
friend class nsDocViewerSelectionListener;
friend class nsPagePrintTimer;
@ -522,6 +524,9 @@ public:
// nsIWebBrowserPrint
NS_DECL_NSIWEBBROWSERPRINT
// nsIObserver
NS_DECL_NSIOBSERVER
typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer,
void* aClosure);
nsresult CallChildren(CallChildFunc aFunc, void* aClosure);
@ -612,9 +617,14 @@ private:
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void DoPrintProgress(PRBool aIsForPrinting);
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
void CleanUpBeforeReflow(nsresult aResult);
nsresult FinishPrintPreview();
void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
void SetDocAndURLIntoProgress(PrintObject* aPO,
nsIPrintProgressParams* aParams);
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions,
nsIPrintSettings* aPrintSettings,
PRUint32 aErrorCode,
@ -888,7 +898,7 @@ static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult)
//---------------------------------------------------
PrintData::PrintData(ePrintDataType aType) :
mType(aType), mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull),
mShowProgressDialog(PR_TRUE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mShowProgressDialog(PR_TRUE), mProgressDialogIsShown(PR_FALSE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE),
mIsAborted(PR_FALSE), mPreparingForPrint(PR_FALSE), mDocWasToBeDestroyed(PR_FALSE),
mShrinkToFit(PR_FALSE), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
@ -933,7 +943,7 @@ PrintData::~PrintData()
}
// Only Send an OnEndPrinting if we have started printing
if (mOnStartSent) {
if (mOnStartSent && mType != eIsPrintPreview) {
OnEndPrinting();
}
@ -980,7 +990,7 @@ PrintData::~PrintData()
void PrintData::OnStartPrinting()
{
if (!mOnStartSent) {
DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT);
DoOnProgressChange(mPrintProgressListeners, 0, 0, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT);
mOnStartSent = PR_TRUE;
}
}
@ -1128,13 +1138,14 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
PrepareToStartLoad();
}
NS_IMPL_ISUPPORTS6(DocumentViewerImpl,
NS_IMPL_ISUPPORTS7(DocumentViewerImpl,
nsIContentViewer,
nsIDocumentViewer,
nsIMarkupDocumentViewer,
nsIContentViewerFile,
nsIContentViewerEdit,
nsIWebBrowserPrint)
nsIWebBrowserPrint,
nsIObserver)
DocumentViewerImpl::~DocumentViewerImpl()
{
@ -3916,7 +3927,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink)
}
}
if (!adjRect.width || !adjRect.height) {
if (!adjRect.width || !adjRect.height || !width || !height) {
aPO->mDontPrint = PR_TRUE;
return NS_OK;
}
@ -4559,6 +4570,11 @@ DocumentViewerImpl::SetupToPrintContent(nsIWebShell* aParent,
PR_PL(("--- Printing %d docs and %d pages\n", mPrt->mNumPrintableDocs, mPrt->mNumPrintablePages));
DUMP_DOC_TREELAYOUT;
// Print listener setup...
if (mPrt != nsnull) {
mPrt->OnStartPrinting();
}
mPrt->mPrintDocDW = aCurrentFocusedDOMWin;
PRUnichar* fileName = nsnull;
@ -6323,6 +6339,13 @@ void DocumentViewerImpl::CheckForHiddenFrameSetFrames()
}
}
void
DocumentViewerImpl::CloseProgressDialog(nsIWebProgressListener* aWebProgressListener)
{
if (aWebProgressListener) {
aWebProgressListener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT, nsnull);
}
}
/** ---------------------------------------------------
* See documentation above in the nsIContentViewerfile class definition
@ -6336,13 +6359,16 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
nsIDOMWindow *aChildDOMWin,
nsIWebProgressListener* aWebProgressListener)
{
nsresult rv = NS_OK;
#ifdef NS_PRINT_PREVIEW
if (!mPresShell) {
// A frame that's not displayed can't be printed!
return NS_OK;
}
if (mIsDoingPrinting) {
CloseProgressDialog(aWebProgressListener);
return NS_ERROR_FAILURE;
}
@ -6352,6 +6378,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
// Temporary code for Bug 136185
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
if (xulDoc) {
CloseProgressDialog(aWebProgressListener);
ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL, PR_FALSE);
return NS_ERROR_FAILURE;
}
@ -6368,12 +6395,11 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) ||
busyFlags != nsIDocShell::BUSY_FLAGS_NONE) {
CloseProgressDialog(aWebProgressListener);
ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP, PR_FALSE);
return NS_ERROR_FAILURE;
}
nsresult rv = NS_OK;
#if defined(XP_PC) && defined(EXTENDED_DEBUG_PRINTING)
if (!mIsDoingPrintPreview) {
if (kPrintingLogMod && kPrintingLogMod->level == DUMP_LAYOUT_LEVEL) {
@ -6382,7 +6408,6 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
}
#endif
#ifdef NS_PRINT_PREVIEW
if (mIsDoingPrintPreview) {
mOldPrtPreview = mPrtPreview;
mPrtPreview = nsnull;
@ -6390,10 +6415,16 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
mPrt = new PrintData(PrintData::eIsPrintPreview);
if (!mPrt) {
CloseProgressDialog(aWebProgressListener);
mIsCreatingPrintPreview = PR_FALSE;
return NS_ERROR_OUT_OF_MEMORY;
}
// The WebProgressListener can be QI'ed to nsIPrintingPromptService
// then that means the progress dialog is already being shown.
nsCOMPtr<nsIPrintingPromptService> pps(do_QueryInterface(aWebProgressListener));
mPrt->mProgressDialogIsShown = pps != nsnull;
// Check to see if we need to transfer any of our old values
// over to the new PrintData object
if (mOldPrtPreview) {
@ -6437,6 +6468,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
CloseProgressDialog(aWebProgressListener);
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
@ -6588,33 +6620,61 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
mPresShell->EndObservingDocument();
}
if (aWebProgressListener != nsnull) {
mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener);
NS_ADDREF(aWebProgressListener);
}
PRBool notifyOnInit = PR_FALSE;
ShowPrintProgress(PR_FALSE, notifyOnInit);
if (!notifyOnInit) {
rv = FinishPrintPreview();
} else {
rv = NS_OK;
}
#endif // NS_PRINT_PREVIEW
return rv;
}
nsresult
DocumentViewerImpl::FinishPrintPreview()
{
nsresult rv = NS_OK;
#ifdef NS_PRINT_PREVIEW
rv = DocumentReadyForPrinting();
mIsCreatingPrintPreview = PR_FALSE;
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*/
mIsCreatingPrintPreview = PR_FALSE;
mIsDoingPrintPreview = PR_FALSE;
mPrt->OnEndPrinting();
ShowPrintErrorDialog(rv, PR_FALSE);
TurnScriptingOn(PR_TRUE);
if (mPrt) {
delete mPrt;
mPrt = nsnull;
}
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*/
ShowPrintErrorDialog(rv, PR_FALSE);
TurnScriptingOn(PR_TRUE);
mIsCreatingPrintPreview = PR_FALSE;
mIsDoingPrintPreview = PR_FALSE;
return rv;
}
// At this point we are done preparing everything
// before it is to be created
// Noew create the new Presentation and display it
InstallNewPresentation();
mPrt->OnEndPrinting();
// PrintPreview was built using the mPrt (code reuse)
// then we assign it over
mPrtPreview = mPrt;
@ -6634,6 +6694,28 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
}
void
DocumentViewerImpl::ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront)
{
// Make sure the URLS don't get too long for the progress dialog
if (aStr && nsCRT::strlen(aStr) > aLen) {
if (aDoFront) {
PRUnichar * ptr = &aStr[nsCRT::strlen(aStr)-aLen+3];
nsAutoString newStr;
newStr.AppendWithConversion("...");
newStr += ptr;
nsMemory::Free(aStr);
aStr = ToNewUnicode(newStr);
} else {
nsAutoString newStr(aStr);
newStr.SetLength(aLen-3);
newStr.AppendWithConversion("...");
nsMemory::Free(aStr);
aStr = ToNewUnicode(newStr);
}
}
}
void
DocumentViewerImpl::SetDocAndURLIntoProgress(PrintObject* aPO,
nsIPrintProgressParams* aParams)
@ -6651,15 +6733,9 @@ DocumentViewerImpl::SetDocAndURLIntoProgress(PrintObject* aPO,
GetDisplayTitleAndURL(aPO, mPrt->mPrintSettings, mPrt->mBrandName,
&docTitleStr, &docURLStr, eDocTitleDefURLDoc);
// Make sure the URLS don't get too long for the progress dialog
if (docURLStr && nsCRT::strlen(docURLStr) > kTitleLength) {
PRUnichar * ptr = &docURLStr[nsCRT::strlen(docURLStr)-kTitleLength+3];
nsAutoString newURLStr;
newURLStr.AppendWithConversion("...");
newURLStr += ptr;
nsMemory::Free(docURLStr);
docURLStr = ToNewUnicode(newURLStr);
}
// Make sure the Titles & URLS don't get too long for the progress dialog
ElipseLongString(docTitleStr, kTitleLength, PR_FALSE);
ElipseLongString(docURLStr, kTitleLength, PR_TRUE);
aParams->SetDocTitle((const PRUnichar*) docTitleStr);
aParams->SetDocURL((const PRUnichar*) docURLStr);
@ -6671,14 +6747,23 @@ DocumentViewerImpl::SetDocAndURLIntoProgress(PrintObject* aPO,
//----------------------------------------------------------------------
// Set up to use the "pluggable" Print Progress Dialog
void
DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting)
DocumentViewerImpl::ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify)
{
// default to not notifying, that if something here goes wrong
// or we aren't going to show the progress dialog we can straight into
// reflowing the doc for printing.
aDoNotify = PR_FALSE;
// Assume we can't do progress and then see if we can
mPrt->mShowProgressDialog = PR_FALSE;
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
prefs->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog);
// if it is already being shown then don't bother to find out if it should be
// so skip this and leave mShowProgressDialog set to FALSE
if (!mPrt->mProgressDialogIsShown) {
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
prefs->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog);
}
}
// Turning off the showing of Print Progress in Prefs overrides
@ -6689,18 +6774,20 @@ DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting)
}
// Now open the service to get the progress dialog
nsCOMPtr<nsIPrintingPromptService> printPromptService(do_GetService(kPrintingPromptService));
if (printPromptService) {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
if (!scriptGlobalObject) return;
nsCOMPtr<nsIDOMWindow> domWin = do_QueryInterface(scriptGlobalObject);
if (!domWin) return;
// If we don't get a service, that's ok, then just don't show progress
if (mPrt->mShowProgressDialog) {
nsCOMPtr<nsIPrintingPromptService> printPromptService(do_GetService(kPrintingPromptService));
if (printPromptService) {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
if (!scriptGlobalObject) return;
nsCOMPtr<nsIDOMWindow> domWin = do_QueryInterface(scriptGlobalObject);
if (!domWin) return;
// If we don't get a service, that's ok, then just don't show progress
if (mPrt->mShowProgressDialog) {
PRBool notifyOnOpen;
nsresult rv = printPromptService->ShowProgress(domWin, this, mPrt->mPrintSettings, nsnull, PR_TRUE, getter_AddRefs(mPrt->mPrintProgressListener), getter_AddRefs(mPrt->mPrintProgressParams), &notifyOnOpen);
nsresult rv = printPromptService->ShowProgress(domWin, this, mPrt->mPrintSettings, this, aIsForPrinting,
getter_AddRefs(mPrt->mPrintProgressListener),
getter_AddRefs(mPrt->mPrintProgressParams),
&aDoNotify);
if (NS_SUCCEEDED(rv)) {
mPrt->mShowProgressDialog = mPrt->mPrintProgressListener != nsnull && mPrt->mPrintProgressParams != nsnull;
@ -6753,6 +6840,35 @@ DocumentViewerImpl::Print(PRBool aSilent,
}
/** ---------------------------------------------------
* Cleans up when an error occurred
*/
void DocumentViewerImpl::CleanUpBeforeReflow(nsresult aResult)
{
/* cleanup... */
if (mPagePrintTimer) {
mPagePrintTimer->Stop();
NS_RELEASE(mPagePrintTimer);
}
if (mPrt) {
delete mPrt;
mPrt = nsnull;
}
mIsDoingPrinting = PR_FALSE;
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*
* When rv == NS_ERROR_ABORT, it means we want out of the
* print job without displaying any error messages
*/
if (aResult != NS_ERROR_ABORT) {
ShowPrintErrorDialog(aResult);
}
}
/** ---------------------------------------------------
* From nsIWebBrowserPrint
*/
@ -7169,15 +7285,16 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
if (docURLStr) nsMemory::Free(docURLStr);
NS_ENSURE_SUCCESS(rv, rv);
DoPrintProgress(PR_TRUE);
PRBool doNotify;
ShowPrintProgress(PR_TRUE, doNotify);
// Print listener setup...
if (mPrt != nsnull) {
mPrt->OnStartPrinting();
if (!doNotify) {
// Print listener setup...
if (mPrt != nsnull) {
mPrt->OnStartPrinting();
}
rv = DocumentReadyForPrinting();
}
rv = DocumentReadyForPrinting();
PR_PL(("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"));
}
}
}
@ -7188,28 +7305,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
/* cleanup... */
if (mPagePrintTimer) {
mPagePrintTimer->Stop();
NS_RELEASE(mPagePrintTimer);
}
if (mPrt) {
delete mPrt;
mPrt = nsnull;
}
mIsDoingPrinting = PR_FALSE;
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*
* When rv == NS_ERROR_ABORT, it means we want out of the
* print job without displaying any error messages
*/
if (rv != NS_ERROR_ABORT) {
ShowPrintErrorDialog(rv);
}
PR_PL(("**** Printing Failed - rv 0x%X", rv));
CleanUpBeforeReflow(rv);
}
return rv;
@ -8422,3 +8518,26 @@ DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext,
return mPagePrintTimer->Start(this, aPresContext, aPrintSettings, aPOect, aDelay);
}
/*=============== nsIObserver Interface ======================*/
NS_IMETHODIMP DocumentViewerImpl::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
nsresult rv = NS_ERROR_FAILURE;
if (mIsDoingPrinting) {
rv = DocumentReadyForPrinting();
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
CleanUpBeforeReflow(rv);
}
} else {
rv = FinishPrintPreview();
if (mPrtPreview) {
mPrtPreview->OnEndPrinting();
}
rv = NS_OK;
}
return rv;
}

View File

@ -76,7 +76,9 @@ NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
*notifyOnOpen = PR_TRUE;
m_observer = openDialogObserver;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
@ -186,6 +188,9 @@ NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listen
/* void doneIniting (); */
NS_IMETHODIMP nsPrintProgress::DoneIniting()
{
if (m_observer) {
m_observer->Observe(nsnull, nsnull, nsnull);
}
return NS_OK;
}

View File

@ -46,6 +46,7 @@
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsIObserver.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
@ -69,6 +70,7 @@ private:
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
nsCOMPtr<nsIObserver> m_observer;
};
#endif

View File

@ -76,7 +76,8 @@ NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
*notifyOnOpen = PR_TRUE;
m_observer = openDialogObserver;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
@ -186,6 +187,9 @@ NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listen
/* void doneIniting (); */
NS_IMETHODIMP nsPrintProgress::DoneIniting()
{
if (m_observer) {
m_observer->Observe(nsnull, nsnull, nsnull);
}
return NS_OK;
}

View File

@ -46,6 +46,7 @@
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsIObserver.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
@ -69,6 +70,7 @@ private:
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
nsCOMPtr<nsIObserver> m_observer;
};
#endif

View File

@ -59,6 +59,7 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printsettings-se
static const char *kPrintDialogURL = "chrome://global/content/printdialog.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPrtPrvProgressDialogURL = "chrome://global/content/printPreviewProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
#define NS_DIALOGPARAMBLOCK_CONTRACTID \
@ -170,7 +171,9 @@ nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
mPrintProgress->OpenProgressDialog(parentDOMIntl,
isForPrinting?kPrintProgressDialogURL:kPrtPrvProgressDialogURL,
*printProgressParams, openDialogObserver, notifyOnOpen);
}
}

View File

@ -76,7 +76,8 @@ NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
*notifyOnOpen = PR_TRUE;
m_observer = openDialogObserver;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
@ -186,6 +187,9 @@ NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listen
/* void doneIniting (); */
NS_IMETHODIMP nsPrintProgress::DoneIniting()
{
if (m_observer) {
m_observer->Observe(nsnull, nsnull, nsnull);
}
return NS_OK;
}

View File

@ -46,6 +46,7 @@
#include "nsISupportsArray.h"
#include "nsIDOMWindowInternal.h"
#include "nsIPrintStatusFeedback.h"
#include "nsIObserver.h"
#include "nsString.h"
class nsPrintProgress : public nsIPrintProgress, public nsIPrintStatusFeedback
@ -69,6 +70,7 @@ private:
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
nsCOMPtr<nsIObserver> m_observer;
};
#endif

View File

@ -53,6 +53,7 @@
static const char *kPrintDialogURL = "chrome://global/content/printdialog.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPrtPrvProgressDialogURL = "chrome://global/content/printPreviewProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
static const char *kPrinterPropertiesURL = "chrome://global/content/printjoboptions.xul";
@ -165,7 +166,9 @@ nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
mPrintProgress->OpenProgressDialog(parentDOMIntl,
isForPrinting?kPrintProgressDialogURL:kPrtPrvProgressDialogURL,
*printProgressParams, openDialogObserver, notifyOnOpen);
}
}

View File

@ -77,7 +77,9 @@ NS_IMETHODIMP nsPrintProgress::OpenProgressDialog(nsIDOMWindowInternal *parent,
nsIObserver *openDialogObserver,
PRBool *notifyOnOpen)
{
*notifyOnOpen = PR_FALSE;
*notifyOnOpen = PR_TRUE;
m_observer = openDialogObserver;
nsresult rv = NS_ERROR_FAILURE;
if (m_dialog)
@ -187,6 +189,9 @@ NS_IMETHODIMP nsPrintProgress::UnregisterListener(nsIWebProgressListener *listen
/* void doneIniting (); */
NS_IMETHODIMP nsPrintProgress::DoneIniting()
{
if (m_observer) {
m_observer->Observe(nsnull, nsnull, nsnull);
}
return NS_OK;
}

View File

@ -71,6 +71,7 @@ private:
PRInt32 m_pendingStateValue;
nsCOMPtr<nsIDOMWindowInternal> m_dialog;
nsCOMPtr<nsISupportsArray> m_listenerList;
nsCOMPtr<nsIObserver> m_observer;
};
#endif

View File

@ -56,8 +56,9 @@
#define NS_DIALOGPARAMBLOCK_CONTRACTID "@mozilla.org/embedcomp/dialogparam;1"
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
static const char *kPrintProgressDialogURL = "chrome://global/content/printProgress.xul";
static const char *kPrtPrvProgressDialogURL = "chrome://global/content/printPreviewProgress.xul";
static const char *kPageSetupDialogURL = "chrome://communicator/content/printPageSetup.xul";
// Static Data
static HINSTANCE gInstance;
@ -186,7 +187,7 @@ nsPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrin
}
//-----------------------------------------------------------
/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, in nsIObserver openDialogObserver, in boolean isForPrinting, out nsIWebProgressListener webProgressListener, out nsIPrintProgressParams printProgressParams, out boolean notifyOnOpen); */
NS_IMETHODIMP
nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
nsIWebBrowserPrint* webBrowserPrint, // ok to be null
@ -201,6 +202,14 @@ nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
NS_ENSURE_ARG(printProgressParams);
NS_ENSURE_ARG(notifyOnOpen);
if (mPrintProgress)
{
*webProgressListener = nsnull;
*printProgressParams = nsnull;
*notifyOnOpen = PR_FALSE;
return NS_ERROR_FAILURE;
}
nsPrintProgress* prtProgress = new nsPrintProgress();
nsresult rv = prtProgress->QueryInterface(NS_GET_IID(nsIPrintProgress), (void**)getter_AddRefs(mPrintProgress));
NS_ENSURE_SUCCESS(rv, rv);
@ -226,7 +235,9 @@ nsPrintingPromptService::ShowProgress(nsIDOMWindow* parent,
if (parentDOMIntl)
{
mPrintProgress->OpenProgressDialog(parentDOMIntl, kPrintProgressDialogURL, *printProgressParams, openDialogObserver, notifyOnOpen);
mPrintProgress->OpenProgressDialog(parentDOMIntl,
isForPrinting?kPrintProgressDialogURL:kPrtPrvProgressDialogURL,
*printProgressParams, openDialogObserver, notifyOnOpen);
}
}
@ -250,6 +261,15 @@ nsPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *p
block->SetInt(0, 0);
rv = DoDialog(parent, block, printSettings, kPageSetupDialogURL);
// if aWebBrowserPrint is not null then we are printing
// so we want to pass back NS_ERROR_ABORT on cancel
if (NS_SUCCEEDED(rv))
{
PRInt32 status;
block->GetInt(0, &status);
return status == 0?NS_ERROR_ABORT:NS_OK;
}
return rv;
}
@ -321,11 +341,15 @@ nsPrintingPromptService::DoDialog(nsIDOMWindow *aParent,
NS_IMETHODIMP
nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
{
if (aStateFlags & STATE_STOP)
if ((aStateFlags & STATE_STOP) && mWebProgressListener)
{
mWebProgressListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
mPrintProgress->CloseProgressDialog(PR_TRUE);
mPrintProgress = nsnull;
if (mPrintProgress)
{
mPrintProgress->CloseProgressDialog(PR_TRUE);
}
mPrintProgress = nsnull;
mWebProgressListener = nsnull;
}
return NS_OK;
}
@ -334,28 +358,44 @@ nsPrintingPromptService::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest
NS_IMETHODIMP
nsPrintingPromptService::OnProgressChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRInt32 aCurSelfProgress, PRInt32 aMaxSelfProgress, PRInt32 aCurTotalProgress, PRInt32 aMaxTotalProgress)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
if (mWebProgressListener)
{
return mWebProgressListener->OnProgressChange(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress);
}
return NS_ERROR_FAILURE;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP
nsPrintingPromptService::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
if (mWebProgressListener)
{
return mWebProgressListener->OnLocationChange(aWebProgress, aRequest, location);
}
return NS_ERROR_FAILURE;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP
nsPrintingPromptService::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
if (mWebProgressListener)
{
return mWebProgressListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
return NS_ERROR_FAILURE;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
NS_IMETHODIMP
nsPrintingPromptService::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
if (mWebProgressListener)
{
return mWebProgressListener->OnSecurityChange(aWebProgress, aRequest, state);
}
return NS_ERROR_FAILURE;
}

View File

@ -158,7 +158,7 @@ static const char sPrintOptionsContractID[] = "@mozilla.org/gfx/printset
// Print Progress
#include "nsIPrintProgress.h"
#include "nsIPrintProgressParams.h"
#include "nsIObserver.h"
// Print error dialog
#include "nsIPrompt.h"
@ -433,7 +433,8 @@ public:
nsCOMPtr<nsIWebProgressListener> mPrintProgressListener;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIPrintProgressParams> mPrintProgressParams;
PRBool mShowProgressDialog;
PRBool mShowProgressDialog; // means we should try to show it
PRPackedBool mProgressDialogIsShown; // means it is already being shown
nsCOMPtr<nsIDOMWindowInternal> mCurrentFocusWin; // cache a pointer to the currently focused window
@ -484,7 +485,8 @@ class DocumentViewerImpl : public nsIDocumentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile,
public nsIMarkupDocumentViewer,
public nsIWebBrowserPrint
public nsIWebBrowserPrint,
public nsIObserver
{
friend class nsDocViewerSelectionListener;
friend class nsPagePrintTimer;
@ -522,6 +524,9 @@ public:
// nsIWebBrowserPrint
NS_DECL_NSIWEBBROWSERPRINT
// nsIObserver
NS_DECL_NSIOBSERVER
typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer,
void* aClosure);
nsresult CallChildren(CallChildFunc aFunc, void* aClosure);
@ -612,9 +617,14 @@ private:
void CalcNumPrintableDocsAndPages(PRInt32& aNumDocs, PRInt32& aNumPages);
void DoProgressForAsIsFrames();
void DoProgressForSeparateFrames();
void DoPrintProgress(PRBool aIsForPrinting);
void ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify);
void CleanUpBeforeReflow(nsresult aResult);
nsresult FinishPrintPreview();
void CloseProgressDialog(nsIWebProgressListener* aWebProgressListener);
void SetDocAndURLIntoProgress(PrintObject* aPO,
nsIPrintProgressParams* aParams);
void ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront);
nsresult CheckForPrinters(nsIPrintOptions* aPrintOptions,
nsIPrintSettings* aPrintSettings,
PRUint32 aErrorCode,
@ -888,7 +898,7 @@ static nsresult NS_NewUpdateTimer(nsPagePrintTimer **aResult)
//---------------------------------------------------
PrintData::PrintData(ePrintDataType aType) :
mType(aType), mPrintView(nsnull), mDebugFilePtr(nsnull), mPrintObject(nsnull), mSelectedPO(nsnull),
mShowProgressDialog(PR_TRUE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mShowProgressDialog(PR_TRUE), mProgressDialogIsShown(PR_FALSE), mPrintDocList(nsnull), mIsIFrameSelected(PR_FALSE),
mIsParentAFrameSet(PR_FALSE), mPrintingAsIsSubDoc(PR_FALSE), mOnStartSent(PR_FALSE),
mIsAborted(PR_FALSE), mPreparingForPrint(PR_FALSE), mDocWasToBeDestroyed(PR_FALSE),
mShrinkToFit(PR_FALSE), mPrintFrameType(nsIPrintSettings::kFramesAsIs),
@ -933,7 +943,7 @@ PrintData::~PrintData()
}
// Only Send an OnEndPrinting if we have started printing
if (mOnStartSent) {
if (mOnStartSent && mType != eIsPrintPreview) {
OnEndPrinting();
}
@ -980,7 +990,7 @@ PrintData::~PrintData()
void PrintData::OnStartPrinting()
{
if (!mOnStartSent) {
DoOnProgressChange(mPrintProgressListeners, 100, 100, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT);
DoOnProgressChange(mPrintProgressListeners, 0, 0, PR_TRUE, nsIWebProgressListener::STATE_START|nsIWebProgressListener::STATE_IS_DOCUMENT);
mOnStartSent = PR_TRUE;
}
}
@ -1128,13 +1138,14 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
PrepareToStartLoad();
}
NS_IMPL_ISUPPORTS6(DocumentViewerImpl,
NS_IMPL_ISUPPORTS7(DocumentViewerImpl,
nsIContentViewer,
nsIDocumentViewer,
nsIMarkupDocumentViewer,
nsIContentViewerFile,
nsIContentViewerEdit,
nsIWebBrowserPrint)
nsIWebBrowserPrint,
nsIObserver)
DocumentViewerImpl::~DocumentViewerImpl()
{
@ -3916,7 +3927,7 @@ DocumentViewerImpl::ReflowPrintObject(PrintObject * aPO, PRBool aDoCalcShrink)
}
}
if (!adjRect.width || !adjRect.height) {
if (!adjRect.width || !adjRect.height || !width || !height) {
aPO->mDontPrint = PR_TRUE;
return NS_OK;
}
@ -4559,6 +4570,11 @@ DocumentViewerImpl::SetupToPrintContent(nsIWebShell* aParent,
PR_PL(("--- Printing %d docs and %d pages\n", mPrt->mNumPrintableDocs, mPrt->mNumPrintablePages));
DUMP_DOC_TREELAYOUT;
// Print listener setup...
if (mPrt != nsnull) {
mPrt->OnStartPrinting();
}
mPrt->mPrintDocDW = aCurrentFocusedDOMWin;
PRUnichar* fileName = nsnull;
@ -6323,6 +6339,13 @@ void DocumentViewerImpl::CheckForHiddenFrameSetFrames()
}
}
void
DocumentViewerImpl::CloseProgressDialog(nsIWebProgressListener* aWebProgressListener)
{
if (aWebProgressListener) {
aWebProgressListener->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT, nsnull);
}
}
/** ---------------------------------------------------
* See documentation above in the nsIContentViewerfile class definition
@ -6336,13 +6359,16 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
nsIDOMWindow *aChildDOMWin,
nsIWebProgressListener* aWebProgressListener)
{
nsresult rv = NS_OK;
#ifdef NS_PRINT_PREVIEW
if (!mPresShell) {
// A frame that's not displayed can't be printed!
return NS_OK;
}
if (mIsDoingPrinting) {
CloseProgressDialog(aWebProgressListener);
return NS_ERROR_FAILURE;
}
@ -6352,6 +6378,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
// Temporary code for Bug 136185
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
if (xulDoc) {
CloseProgressDialog(aWebProgressListener);
ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL, PR_FALSE);
return NS_ERROR_FAILURE;
}
@ -6368,12 +6395,11 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) ||
busyFlags != nsIDocShell::BUSY_FLAGS_NONE) {
CloseProgressDialog(aWebProgressListener);
ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_DOC_IS_BUSY_PP, PR_FALSE);
return NS_ERROR_FAILURE;
}
nsresult rv = NS_OK;
#if defined(XP_PC) && defined(EXTENDED_DEBUG_PRINTING)
if (!mIsDoingPrintPreview) {
if (kPrintingLogMod && kPrintingLogMod->level == DUMP_LAYOUT_LEVEL) {
@ -6382,7 +6408,6 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
}
#endif
#ifdef NS_PRINT_PREVIEW
if (mIsDoingPrintPreview) {
mOldPrtPreview = mPrtPreview;
mPrtPreview = nsnull;
@ -6390,10 +6415,16 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
mPrt = new PrintData(PrintData::eIsPrintPreview);
if (!mPrt) {
CloseProgressDialog(aWebProgressListener);
mIsCreatingPrintPreview = PR_FALSE;
return NS_ERROR_OUT_OF_MEMORY;
}
// The WebProgressListener can be QI'ed to nsIPrintingPromptService
// then that means the progress dialog is already being shown.
nsCOMPtr<nsIPrintingPromptService> pps(do_QueryInterface(aWebProgressListener));
mPrt->mProgressDialogIsShown = pps != nsnull;
// Check to see if we need to transfer any of our old values
// over to the new PrintData object
if (mOldPrtPreview) {
@ -6437,6 +6468,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
rv = NS_ERROR_FAILURE;
}
if (NS_FAILED(rv)) {
CloseProgressDialog(aWebProgressListener);
delete mPrt;
mPrt = nsnull;
return NS_ERROR_FAILURE;
@ -6588,33 +6620,61 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
mPresShell->EndObservingDocument();
}
if (aWebProgressListener != nsnull) {
mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener);
NS_ADDREF(aWebProgressListener);
}
PRBool notifyOnInit = PR_FALSE;
ShowPrintProgress(PR_FALSE, notifyOnInit);
if (!notifyOnInit) {
rv = FinishPrintPreview();
} else {
rv = NS_OK;
}
#endif // NS_PRINT_PREVIEW
return rv;
}
nsresult
DocumentViewerImpl::FinishPrintPreview()
{
nsresult rv = NS_OK;
#ifdef NS_PRINT_PREVIEW
rv = DocumentReadyForPrinting();
mIsCreatingPrintPreview = PR_FALSE;
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*/
mIsCreatingPrintPreview = PR_FALSE;
mIsDoingPrintPreview = PR_FALSE;
mPrt->OnEndPrinting();
ShowPrintErrorDialog(rv, PR_FALSE);
TurnScriptingOn(PR_TRUE);
if (mPrt) {
delete mPrt;
mPrt = nsnull;
}
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*/
ShowPrintErrorDialog(rv, PR_FALSE);
TurnScriptingOn(PR_TRUE);
mIsCreatingPrintPreview = PR_FALSE;
mIsDoingPrintPreview = PR_FALSE;
return rv;
}
// At this point we are done preparing everything
// before it is to be created
// Noew create the new Presentation and display it
InstallNewPresentation();
mPrt->OnEndPrinting();
// PrintPreview was built using the mPrt (code reuse)
// then we assign it over
mPrtPreview = mPrt;
@ -6634,6 +6694,28 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
}
void
DocumentViewerImpl::ElipseLongString(PRUnichar *& aStr, const PRUint32 aLen, PRBool aDoFront)
{
// Make sure the URLS don't get too long for the progress dialog
if (aStr && nsCRT::strlen(aStr) > aLen) {
if (aDoFront) {
PRUnichar * ptr = &aStr[nsCRT::strlen(aStr)-aLen+3];
nsAutoString newStr;
newStr.AppendWithConversion("...");
newStr += ptr;
nsMemory::Free(aStr);
aStr = ToNewUnicode(newStr);
} else {
nsAutoString newStr(aStr);
newStr.SetLength(aLen-3);
newStr.AppendWithConversion("...");
nsMemory::Free(aStr);
aStr = ToNewUnicode(newStr);
}
}
}
void
DocumentViewerImpl::SetDocAndURLIntoProgress(PrintObject* aPO,
nsIPrintProgressParams* aParams)
@ -6651,15 +6733,9 @@ DocumentViewerImpl::SetDocAndURLIntoProgress(PrintObject* aPO,
GetDisplayTitleAndURL(aPO, mPrt->mPrintSettings, mPrt->mBrandName,
&docTitleStr, &docURLStr, eDocTitleDefURLDoc);
// Make sure the URLS don't get too long for the progress dialog
if (docURLStr && nsCRT::strlen(docURLStr) > kTitleLength) {
PRUnichar * ptr = &docURLStr[nsCRT::strlen(docURLStr)-kTitleLength+3];
nsAutoString newURLStr;
newURLStr.AppendWithConversion("...");
newURLStr += ptr;
nsMemory::Free(docURLStr);
docURLStr = ToNewUnicode(newURLStr);
}
// Make sure the Titles & URLS don't get too long for the progress dialog
ElipseLongString(docTitleStr, kTitleLength, PR_FALSE);
ElipseLongString(docURLStr, kTitleLength, PR_TRUE);
aParams->SetDocTitle((const PRUnichar*) docTitleStr);
aParams->SetDocURL((const PRUnichar*) docURLStr);
@ -6671,14 +6747,23 @@ DocumentViewerImpl::SetDocAndURLIntoProgress(PrintObject* aPO,
//----------------------------------------------------------------------
// Set up to use the "pluggable" Print Progress Dialog
void
DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting)
DocumentViewerImpl::ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify)
{
// default to not notifying, that if something here goes wrong
// or we aren't going to show the progress dialog we can straight into
// reflowing the doc for printing.
aDoNotify = PR_FALSE;
// Assume we can't do progress and then see if we can
mPrt->mShowProgressDialog = PR_FALSE;
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
prefs->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog);
// if it is already being shown then don't bother to find out if it should be
// so skip this and leave mShowProgressDialog set to FALSE
if (!mPrt->mProgressDialogIsShown) {
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
prefs->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog);
}
}
// Turning off the showing of Print Progress in Prefs overrides
@ -6689,18 +6774,20 @@ DocumentViewerImpl::DoPrintProgress(PRBool aIsForPrinting)
}
// Now open the service to get the progress dialog
nsCOMPtr<nsIPrintingPromptService> printPromptService(do_GetService(kPrintingPromptService));
if (printPromptService) {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
if (!scriptGlobalObject) return;
nsCOMPtr<nsIDOMWindow> domWin = do_QueryInterface(scriptGlobalObject);
if (!domWin) return;
// If we don't get a service, that's ok, then just don't show progress
if (mPrt->mShowProgressDialog) {
nsCOMPtr<nsIPrintingPromptService> printPromptService(do_GetService(kPrintingPromptService));
if (printPromptService) {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
mDocument->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject));
if (!scriptGlobalObject) return;
nsCOMPtr<nsIDOMWindow> domWin = do_QueryInterface(scriptGlobalObject);
if (!domWin) return;
// If we don't get a service, that's ok, then just don't show progress
if (mPrt->mShowProgressDialog) {
PRBool notifyOnOpen;
nsresult rv = printPromptService->ShowProgress(domWin, this, mPrt->mPrintSettings, nsnull, PR_TRUE, getter_AddRefs(mPrt->mPrintProgressListener), getter_AddRefs(mPrt->mPrintProgressParams), &notifyOnOpen);
nsresult rv = printPromptService->ShowProgress(domWin, this, mPrt->mPrintSettings, this, aIsForPrinting,
getter_AddRefs(mPrt->mPrintProgressListener),
getter_AddRefs(mPrt->mPrintProgressParams),
&aDoNotify);
if (NS_SUCCEEDED(rv)) {
mPrt->mShowProgressDialog = mPrt->mPrintProgressListener != nsnull && mPrt->mPrintProgressParams != nsnull;
@ -6753,6 +6840,35 @@ DocumentViewerImpl::Print(PRBool aSilent,
}
/** ---------------------------------------------------
* Cleans up when an error occurred
*/
void DocumentViewerImpl::CleanUpBeforeReflow(nsresult aResult)
{
/* cleanup... */
if (mPagePrintTimer) {
mPagePrintTimer->Stop();
NS_RELEASE(mPagePrintTimer);
}
if (mPrt) {
delete mPrt;
mPrt = nsnull;
}
mIsDoingPrinting = PR_FALSE;
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*
* When rv == NS_ERROR_ABORT, it means we want out of the
* print job without displaying any error messages
*/
if (aResult != NS_ERROR_ABORT) {
ShowPrintErrorDialog(aResult);
}
}
/** ---------------------------------------------------
* From nsIWebBrowserPrint
*/
@ -7169,15 +7285,16 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
if (docURLStr) nsMemory::Free(docURLStr);
NS_ENSURE_SUCCESS(rv, rv);
DoPrintProgress(PR_TRUE);
PRBool doNotify;
ShowPrintProgress(PR_TRUE, doNotify);
// Print listener setup...
if (mPrt != nsnull) {
mPrt->OnStartPrinting();
if (!doNotify) {
// Print listener setup...
if (mPrt != nsnull) {
mPrt->OnStartPrinting();
}
rv = DocumentReadyForPrinting();
}
rv = DocumentReadyForPrinting();
PR_PL(("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"));
}
}
}
@ -7188,28 +7305,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
/* cleanup... */
if (mPagePrintTimer) {
mPagePrintTimer->Stop();
NS_RELEASE(mPagePrintTimer);
}
if (mPrt) {
delete mPrt;
mPrt = nsnull;
}
mIsDoingPrinting = PR_FALSE;
/* cleanup done, let's fire-up an error dialog to notify the user
* what went wrong...
*
* When rv == NS_ERROR_ABORT, it means we want out of the
* print job without displaying any error messages
*/
if (rv != NS_ERROR_ABORT) {
ShowPrintErrorDialog(rv);
}
PR_PL(("**** Printing Failed - rv 0x%X", rv));
CleanUpBeforeReflow(rv);
}
return rv;
@ -8422,3 +8518,26 @@ DocumentViewerImpl::StartPagePrintTimer(nsIPresContext * aPresContext,
return mPagePrintTimer->Start(this, aPresContext, aPrintSettings, aPOect, aDelay);
}
/*=============== nsIObserver Interface ======================*/
NS_IMETHODIMP DocumentViewerImpl::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
nsresult rv = NS_ERROR_FAILURE;
if (mIsDoingPrinting) {
rv = DocumentReadyForPrinting();
/* cleaup on failure + notify user */
if (NS_FAILED(rv)) {
CleanUpBeforeReflow(rv);
}
} else {
rv = FinishPrintPreview();
if (mPrtPreview) {
mPrtPreview->OnEndPrinting();
}
rv = NS_OK;
}
return rv;
}

View File

@ -45,6 +45,7 @@ var gPrintSettings = null;
var gChromeState = null; // chrome state before we went into print preview
var gOldCloseHandler = null; // close handler before we went into print preview
var gInPrintPreviewMode = false;
var gWebProgress = null;
function getWebNavigation()
{
@ -205,32 +206,95 @@ function GetPrintSettings()
return gPrintSettings;
}
// This observer is called once the progress dialog has been "opened"
var gPrintPreviewObs = {
observe: function(aSubject, aTopic, aData)
{
setTimeout(FinishPrintPreview, 0);
},
QueryInterface : function(iid)
{
if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupportsWeakReference))
return this;
throw Components.results.NS_NOINTERFACE;
}
};
function BrowserPrintPreview()
{
var ifreq;
var webBrowserPrint;
try {
ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
gPrintSettings = GetPrintSettings();
} catch (e) {
// Pressing cancel is expressed as an NS_ERROR_ABORT return value,
// causing an exception to be thrown which we catch here.
// Unfortunately this will also consume helpful failures, so add a
// dump(e); // if you need to debug
}
// Here we get the PrintingPromptService tso we can display the PP Progress from script
// For the browser implemented via XUL with the PP toolbar we cannot let it be
// automatically opened from the print engine because the XUL scrollbars in the PP window
// will layout before the content window and a crash will occur.
//
// Doing it all from script, means it lays out before hand and we can let printing do it's own thing
gWebProgress = new Object();
var printPreviewParams = new Object();
var notifyOnOpen = new Object();
var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
.getService(Components.interfaces.nsIPrintingPromptService);
if (printingPromptService) {
// just in case we are already printing,
// an error code could be returned if the Prgress Dialog is already displayed
try {
printingPromptService.showProgress(this, webBrowserPrint, gPrintSettings, gPrintPreviewObs, false, gWebProgress,
printPreviewParams, notifyOnOpen);
if (printPreviewParams.value) {
var webNav = getWebNavigation();
printPreviewParams.value.docTitle = webNav.document.title;
printPreviewParams.value.docURL = webNav.currentURI.spec;
}
// this tells us whether we should continue on with PP or
// wait for the callback via the observer
if (!notifyOnOpen.value.valueOf() || gWebProgress.value == null) {
FinishPrintPreview();
}
} catch (e) {}
}
}
function FinishPrintPreview()
{
gInPrintPreviewMode = true;
var browser = getBrowser();
browser.setAttribute("handleCtrlPageUpDown", "false");
var mainWin = document.getElementById("main-window");
// save previous close handler to restoreon exiting print preview mode
if (mainWin.hasAttribute("onclose"))
gOldCloseHandler = mainWin.getAttribute("onclose");
else
gOldCloseHandler = null;
mainWin.setAttribute("onclose", "BrowserExitPrintPreview(); return false;");
try {
var ifreq = _content.QueryInterface(
Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(
Components.interfaces.nsIWebBrowserPrint);
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var webBrowserPrint = ifreq.getInterface(Components.interfaces.nsIWebBrowserPrint);
if (webBrowserPrint) {
gPrintSettings = GetPrintSettings();
webBrowserPrint.printPreview(gPrintSettings, null, null);
webBrowserPrint.printPreview(gPrintSettings, null, gWebProgress.value);
}
browser.setAttribute("handleCtrlPageUpDown", "false");
var mainWin = document.getElementById("main-window");
// save previous close handler to restoreon exiting print preview mode
if (mainWin.hasAttribute("onclose"))
gOldCloseHandler = mainWin.getAttribute("onclose");
else
gOldCloseHandler = null;
mainWin.setAttribute("onclose", "BrowserExitPrintPreview(); return false;");
// show the toolbar after we go into print preview mode so
// that we can initialize the toolbar with total num pages
showPrintPreviewToolbar();
@ -264,9 +328,6 @@ function BrowserPrintSetup()
.getService(Components.interfaces.nsIPrintSettingsService);
psService.savePrintSettingsToPrefs(gPrintSettings, false, gPrintSettings.kInitSaveNativeData);
}
if (webBrowserPrint.doingPrintPreview) {
webBrowserPrint.printPreview(gPrintSettings, null, null);
}
}
}
} catch (e) {

View File

@ -154,7 +154,11 @@
<field name="mCustomTitle">
document.getAnonymousNodes(this)[16].firstChild
</field>
<field name="mPrintPreviewObs">
</field>
<field name="mWebProgress">
</field>
<constructor>
<![CDATA[
this._debug("constructor");
@ -197,7 +201,13 @@
<![CDATA[
var didOK = BrowserPrintSetup();
if (didOK) {
// the changes that effect the UI
this._getValuesFromPS();
// Now do PrintPreview
var print = this._getWebBrowserPrint();
var settings = print.currentPrintSettings;
this.doPrintPreview(print, settings, this.mTotalPages, null);
}
]]>
</body>
@ -317,6 +327,92 @@
</body>
</method>
<method name="doPrintPreview">
<parameter name="aWebBrowserPrint"/>
<parameter name="aPrintSettings"/>
<parameter name="aTotalPages"/>
<parameter name="aScaleCombobox"/>
<body>
<![CDATA[
// This observer is called once the progress dialog has been "opened"
this.mPrintPreviewObs = {
mDOMWin:null,
mWebBrowserPrint:null,
mPrintSettings:null,
mWebProgress:null,
mTotalPages:null,
mScaleCombobox:null,
observe: function(aSubject, aTopic, aData)
{
// First do PrintPreview
this.mWebBrowserPrint.printPreview(this.mPrintSettings, this.mDOMWin, this.mWebProgress.value);
// update total number of pages since this could have changed
this.mTotalPages.value = this.mWebBrowserPrint.printPreviewNumPages;
if (this.mScaleCombobox) {
this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
}
},
QueryInterface : function(iid)
{
if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupportsWeakReference))
return this;
throw Components.results.NS_NOINTERFACE;
}
};
var ifreq;
var webBrowserPrint;
var domWin;
try {
var ifreq = _content.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
domWin = ifreq.QueryInterface(Components.interfaces.nsIDOMWindow);
} catch (e) {
// Pressing cancel is expressed as an NS_ERROR_ABORT return value,
// causing an exception to be thrown which we catch here.
// Unfortunately this will also consume helpful failures, so add a
//dump(e); // if you need to debug
}
// Here we get the PrintingPromptService tso we can display the PP Progress from script
// For the browser implemented via XUL with the PP toolbar we cannot let it be
// automatically opened from the print engine because the XUL scrollbars in the PP window
// will layout before the content window and a crash will occur.
//
// Doing it all from script, means it lays out before hand and we can let printing do it's own thing
this.mWebProgress = new Object();
// set up observer's global data for invoking Print Preview
this.mPrintPreviewObs.mDOMWin = domWin;
this.mPrintPreviewObs.mWebBrowserPrint = aWebBrowserPrint;
this.mPrintPreviewObs.mPrintSettings = aPrintSettings;
this.mPrintPreviewObs.mWebProgress = this.mWebProgress;
this.mPrintPreviewObs.mTotalPages = aTotalPages;
this.mPrintPreviewObs.mScaleCombobox = aScaleCombobox;
var printPreviewParams = new Object();
var notifyOnOpen = new Object();
var printingPromptService = Components.classes["@mozilla.org/embedcomp/printingprompt-service;1"]
.getService(Components.interfaces.nsIPrintingPromptService);
if (printingPromptService) {
printingPromptService.showProgress(domWin, aWebBrowserPrint, aPrintSettings,
this.mPrintPreviewObs, false, this.mWebProgress,
printPreviewParams, notifyOnOpen);
if (printPreviewParams.value) {
var webNav = getWebNavigation();
printPreviewParams.value.docTitle = webNav.document.title;
printPreviewParams.value.docURL = webNav.currentURI.spec;
}
}
]]>
</body>
</method>
<method name="scale">
<parameter name="aValue"/>
<body>
@ -328,10 +424,7 @@
if (aValue == "ShrinkToFit") {
if (!settings.shrinkToFit) {
settings.shrinkToFit = true;
print.printPreview(settings, null, null);
this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex);
// update total number of pages since this could have changed
this.mTotalPages.value = print.printPreviewNumPages;
this.doPrintPreview(print, settings, this.mTotalPages, this.mScaleCombobox);
return;
} else {
return;
@ -354,9 +447,7 @@
settings.shrinkToFit = false;
settings.scaling = aValue;
print.printPreview(settings, null, null);
// update total number of pages since this could have changed
this.mTotalPages.value = print.printPreviewNumPages;
this.doPrintPreview(print, settings, this.mTotalPages, null);
]]>
</body>
</method>
@ -385,10 +476,7 @@
var print = this._getWebBrowserPrint();
var settings = print.currentPrintSettings;
settings.orientation = orientValue;
print.printPreview(settings, null, null);
// update total number of pages since this could have changed
this.mTotalPages.value = print.printPreviewNumPages;
this.doPrintPreview(print, settings, this.mTotalPages, null);
]]>
</body>
</method>

View File

@ -142,6 +142,7 @@ function goPageSetup(domwin, printSettings)
} catch(e) {
return false;
}
return true;
}
function goPreferences(containerID, paneURL, itemID)

View File

@ -43,6 +43,8 @@ toolkit.jar:
content/global/printdialog.js (resources/content/printdialog.js)
content/global/printProgress.xul (resources/content/printProgress.xul)
content/global/printProgress.js (resources/content/printProgress.js)
content/global/printPreviewProgress.xul (resources/content/printPreviewProgress.xul)
content/global/printPreviewProgress.js (resources/content/printPreviewProgress.js)
content/global/fullScreen.js (resources/content/fullScreen.js)
content/global/build.dtd (build.dtd)
content/global/MPL-1.1.html (resources/content/MPL-1.1.html)
@ -102,6 +104,7 @@ en-US.jar:
locale/en-US/global/dialog.properties (resources/locale/en-US/dialog.properties)
locale/en-US/global/printdialog.dtd (resources/locale/en-US/printdialog.dtd)
locale/en-US/global/printProgress.dtd (resources/locale/en-US/printProgress.dtd)
locale/en-US/global/printPreviewProgress.dtd (resources/locale/en-US/printPreviewProgress.dtd)
US.jar:
locale/US/global-region/contents.rdf (resources/locale/en-US/contents-region.rdf)

View File

@ -0,0 +1,203 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Rod Spears <rods@netscape.com>
*/
// dialog is just an array we'll use to store various properties from the dialog document...
var dialog;
// the printProgress is a nsIPrintProgress object
var printProgress = null;
// random global variables...
var targetFile;
var docTitle = "";
var docURL = "";
var progressParams = null;
function elipseString(aStr, doFront)
{
if (aStr.length > 3 && (aStr.substr(0, 3) == "..." || aStr.substr(aStr.length-4, 3) == "...")) {
return aStr;
}
var fixedLen = 64;
if (aStr.length > fixedLen) {
if (doFront) {
var endStr = aStr.substr(aStr.length-fixedLen, fixedLen);
var str = "..." + endStr;
return str;
} else {
var frontStr = aStr.substr(0, fixedLen);
var str = frontStr + "...";
return str;
}
}
return aStr;
}
// all progress notifications are done through the nsIWebProgressListener implementation...
var progressListener = {
onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
{
if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
{
window.close();
}
},
onProgressChange: function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
{
if (progressParams)
{
var docTitleStr = elipseString(progressParams.docTitle, false);
if (docTitleStr != docTitle) {
docTitle = docTitleStr;
dialog.title.value = docTitle;
}
var docURLStr = elipseString(rogressParams.docURL, true);
if (docURLStr != docURL && dialog.title != null) {
docURL = docURLStr;
if (docTitle == "") {
dialog.title.value = docURLStr;
}
}
}
},
onLocationChange: function(aWebProgress, aRequest, aLocation)
{
// we can ignore this notification
},
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
{
if (aMessage != "")
dialog.title.setAttribute("value", aMessage);
},
onSecurityChange: function(aWebProgress, aRequest, state)
{
// we can ignore this notification
},
QueryInterface : function(iid)
{
if (iid.equals(Components.interfaces.nsIWebProgressListener) || iid.equals(Components.interfaces.nsISupportsWeakReference))
return this;
throw Components.results.NS_NOINTERFACE;
}
};
function onLoad() {
// Set global variables.
printProgress = window.arguments[0];
if (window.arguments[1])
{
progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams)
if (progressParams)
{
docTitle = elipseString(progressParams.docTitle, false);
docURL = elipseString(progressParams.docURL, true);
}
}
if ( !printProgress ) {
dump( "Invalid argument to printPreviewProgress.xul\n" );
window.close()
return;
}
dialog = new Object;
dialog.strings = new Array;
dialog.title = document.getElementById("dialog.title");
dialog.titleLabel = document.getElementById("dialog.titleLabel");
dialog.title.value = docTitle;
// set our web progress listener on the helper app launcher
printProgress.registerListener(progressListener);
moveToAlertPosition();
//We need to delay the set title else dom will overwrite it
window.setTimeout(doneIniting, 100);
}
function onUnload()
{
if (printProgress)
{
try
{
printProgress.unregisterListener(progressListener);
printProgress = null;
}
catch( exception ) {}
}
}
function getString( stringId ) {
// Check if we've fetched this string already.
if (!(stringId in dialog.strings)) {
// Try to get it.
var elem = document.getElementById( "dialog.strings."+stringId );
try {
if ( elem
&&
elem.childNodes
&&
elem.childNodes[0]
&&
elem.childNodes[0].nodeValue ) {
dialog.strings[ stringId ] = elem.childNodes[0].nodeValue;
} else {
// If unable to fetch string, use an empty string.
dialog.strings[ stringId ] = "";
}
} catch (e) { dialog.strings[ stringId ] = ""; }
}
return dialog.strings[ stringId ];
}
// If the user presses cancel, tell the app launcher and close the dialog...
function onCancel ()
{
// Cancel app launcher.
try
{
printProgress.processCanceledByUser = true;
}
catch( exception ) {return true;}
// don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
return false;
}
function doneIniting()
{
// called by function timeout in onLoad
printProgress.doneIniting();
}

View File

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<!-- The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-2000 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Rod Spears <rods@netscape.com>
-->
<?xml-stylesheet href="chrome://communicator/skin/dialogs.css" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
<!DOCTYPE window SYSTEM "chrome://global/locale/printPreviewProgress.dtd">
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
class="dialog"
title="&printWindow.title;"
style="width: 36em;"
onload="onLoad()"
onunload="onUnload()">
<script type="application/x-javascript" src="chrome://global/content/printPreviewProgress.js"/>
<grid flex="1">
<columns>
<column/>
<column/>
</columns>
<rows>
<row>
<hbox pack="end">
<label id="dialog.titleLabel" value="&title;"/>
</hbox>
<label id="dialog.title"/>
</row>
<row class="thin-separator">
<hbox pack="end">
<label id="dialog.progressSpaces" value="&progress;"/>
</hbox>
<label id="dialog.progressLabel" value="&preparing;"/>
</row>
</rows>
</grid>
</window>

View File

@ -38,6 +38,27 @@ var docTitle = "";
var docURL = "";
var progressParams = null;
function elipseString(aStr, doFront)
{
if (aStr.length > 3 && (aStr.substr(0, 3) == "..." || aStr.substr(aStr.length-4, 3) == "...")) {
return aStr;
}
var fixedLen = 64;
if (aStr.length > fixedLen) {
if (doFront) {
var endStr = aStr.substr(aStr.length-fixedLen, fixedLen);
var str = "..." + endStr;
return str;
} else {
var frontStr = aStr.substr(0, fixedLen);
var str = frontStr + "...";
return str;
}
}
return aStr;
}
// all progress notifications are done through the nsIWebProgressListener implementation...
var progressListener = {
onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
@ -51,10 +72,10 @@ var progressListener = {
if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
{
// we are done sending/saving the message...
// Indicate completion in status area.
// we are done printing
// Indicate completion in title area.
var msg = getString( "printComplete" );
dialog.status.setAttribute("value", msg);
dialog.title.setAttribute("value", msg);
// Put progress meter at 100%.
dialog.progress.setAttribute( "value", 100 );
@ -71,16 +92,16 @@ var progressListener = {
{
if (progressParams)
{
var docTitleStr = progressParams.docTitle;
var docTitleStr = elipseString(progressParams.docTitle, false);
if (docTitleStr != docTitle) {
docTitle = docTitleStr;
dialog.status.value = docTitle;
dialog.title.value = docTitle;
}
var docURLStr = progressParams.docURL;
if (docURLStr != docURL && dialog.status != null) {
if (docURLStr != docURL && dialog.title != null) {
docURL = docURLStr;
if (docTitle == "") {
dialog.status.value = docURLStr;
dialog.title.value = elipseString(docURLStr, true);
}
}
}
@ -120,7 +141,7 @@ var progressListener = {
onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage)
{
if (aMessage != "")
dialog.status.setAttribute("value", aMessage);
dialog.title.setAttribute("value", aMessage);
},
onSecurityChange: function(aWebProgress, aRequest, state)
@ -172,6 +193,7 @@ function replaceInsert( text, index, value ) {
}
function onLoad() {
// Set global variables.
printProgress = window.arguments[0];
if (window.arguments[1])
@ -179,25 +201,37 @@ function onLoad() {
progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams)
if (progressParams)
{
docTitle = progressParams.docTitle;
docURL = progressParams.docURL;
docTitle = elipseString(progressParams.docTitle, false);
docURL = elipseString(progressParams.docURL, true);
}
}
if ( !printProgress ) {
dump( "Invalid argument to downloadProgress.xul\n" );
dump( "Invalid argument to printProgress.xul\n" );
window.close()
return;
}
dialog = new Object;
dialog.strings = new Array;
dialog.status = document.getElementById("dialog.status");
dialog.title = document.getElementById("dialog.title");
dialog.titleLabel = document.getElementById("dialog.titleLabel");
dialog.progress = document.getElementById("dialog.progress");
dialog.progressText = document.getElementById("dialog.progressText");
dialog.progressLabel = document.getElementById("dialog.progressLabel");
dialog.tempLabel = document.getElementById("dialog.tempLabel");
dialog.cancel = document.getElementById("cancel");
dialog.status.value = docTitle;
dialog.progress.setAttribute("hidden", "true");
dialog.cancel.setAttribute("disabled", "true");
var progressLabel = getString("preparing");
if (progressLabel == "") {
progressLabel = "Preparing..."; // better than nothing
}
dialog.tempLabel.value = progressLabel;
dialog.title.value = docTitle;
// Set up dialog button callbacks.
var object = this;
@ -209,6 +243,9 @@ function onLoad() {
// set our web progress listener on the helper app launcher
printProgress.registerListener(progressListener);
moveToAlertPosition();
//We need to delay the set title else dom will overwrite it
window.setTimeout(doneIniting, 500);
}
function onUnload()
@ -238,3 +275,18 @@ function onCancel ()
// don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted.
return false;
}
function doneIniting()
{
dialog.tempLabel.setAttribute("hidden", "true");
dialog.progress.setAttribute("hidden", "false");
dialog.cancel.setAttribute("disabled", "false");
var progressLabel = getString("progress");
if (progressLabel == "") {
progressLabel = "Progress:"; // better than nothing
}
//dialog.progressLabel.value = progressLabel;
printProgress.doneIniting();
}

View File

@ -25,7 +25,7 @@ Contributor(s):
-->
<?xml-stylesheet href="chrome://messenger/skin/dialogs.css" type="text/css"?>
<?xml-stylesheet href="chrome://communicator/skin/dialogs.css" type="text/css"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
@ -50,6 +50,8 @@ Contributor(s):
<data id="dialog.strings.dialogCloseLabel">&dialogClose.label;</data>
<data id="dialog.strings.printComplete">&printComplete;</data>
<data id="dialog.strings.progressText">&percentPrint;</data>
<data id="dialog.strings.progressLabel">&progress;</data>
<data id="dialog.strings.preparing">&preparing;</data>
<grid flex="1">
<columns>
@ -61,15 +63,16 @@ Contributor(s):
<rows>
<row>
<hbox pack="end">
<label value="&status;"/>
<label id="dialog.titleLabel" value="&title;"/>
</hbox>
<label id="dialog.status"/>
<label id="dialog.title"/>
</row>
<row class="thin-separator">
<hbox pack="end">
<label value="&progress;"/>
<label id="dialog.progressLabel" value="&progress;"/>
</hbox>
<progressmeter id="dialog.progress" mode="normal" value="0"/>
<label id="dialog.tempLabel" value="&preparing;"/>
<progressmeter id="dialog.progress" mode="normal" value="0"/>
<hbox pack="end" style="min-width: 2.5em;">
<label id="dialog.progressText"/>
</hbox>

View File

@ -20,3 +20,4 @@ printdialog.dtd
printPageSetup.dtd
printPageSetup.properties
printProgress.dtd
printPreviewProgress.dtd

View File

@ -0,0 +1,6 @@
<!--LOCALIZATION NOTE printPreviewProgress.dtd Main UI for Print Preview Progress Dialog -->
<!ENTITY printWindow.title "Print Preview">
<!ENTITY title "Title:">
<!ENTITY spaces " ">
<!ENTITY preparing "Preparing...">
<!ENTITY progress "Progress:">

View File

@ -1,9 +1,9 @@
<!--LOCALIZATION NOTE sendprogress.dtd Main UI for Send Message Progress Dialog -->
<!--LOCALIZATION NOTE printProgress.dtd Main UI for Print Progress Dialog -->
<!ENTITY printWindow.title "Printing">
<!ENTITY status "Title:">
<!ENTITY title "Title:">
<!ENTITY progress "Progress:">
<!ENTITY keepProgressDialogUpMsg.label "Keep this window open after the message is successfully sent.">
<!ENTITY preparing "Preparing...">
<!ENTITY printComplete "Printing is Completed.">
<!ENTITY dialogCancel.label "Cancel">
<!ENTITY dialogClose.label "Close">
@ -16,4 +16,3 @@
#1 will be replaced by the percentage of the file that has been saved -->
<!ENTITY percentPrint "#1&#037;">
<!ENTITY printComplete "Print is complete.">