Bug 1558072. Inline the nsDocumentViewer::ReturnToGalleyPresentation code to its single caller. r=bobowen

Differential Revision: https://phabricator.services.mozilla.com/D34296

--HG--
extra : rebase_source : 51d3d47d6c2e24ae49247cc8496afa5924ab9eda
extra : amend_source : 6cdc328683a450001ca50f783c803d865483e219
This commit is contained in:
Jonathan Watt 2019-06-03 10:10:42 +01:00
Родитель cdbcb71463
Коммит 02015da744
1 изменённых файлов: 56 добавлений и 54 удалений

Просмотреть файл

@ -379,8 +379,6 @@ class nsDocumentViewer final : public nsIContentViewer,
bool aIsPrintingOrPP, bool aStartAtTop);
#endif // NS_PRINTING
void ReturnToGalleyPresentation();
// Whether we should attach to the top level widget. This is true if we
// are sharing/recycling a single base widget and not creating multiple
// child widgets.
@ -3762,14 +3760,67 @@ nsDocumentViewer::Cancel() {
return mPrintJob->Cancel();
}
# if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
// Reset ESM focus for all descendent doc shells.
static void ResetFocusState(nsIDocShell* aDocShell) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (!fm) {
return;
}
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
aDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent,
nsIDocShell::ENUMERATE_FORWARDS,
getter_AddRefs(docShellEnumerator));
nsCOMPtr<nsISupports> currentContainer;
bool hasMoreDocShells;
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) &&
hasMoreDocShells) {
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
nsCOMPtr<nsPIDOMWindowOuter> win = do_GetInterface(currentContainer);
if (win) {
fm->ClearFocus(win);
}
}
}
# endif // NS_PRINTING && NS_PRINT_PREVIEW
NS_IMETHODIMP
nsDocumentViewer::ExitPrintPreview() {
if (GetIsPrinting()) return NS_ERROR_FAILURE;
NS_ENSURE_TRUE(mPrintJob, NS_ERROR_FAILURE);
if (GetIsPrintPreview()) {
ReturnToGalleyPresentation();
if (GetIsPrinting()) {
// Block exiting the print preview window if we're in the middle of an
// actual print.
return NS_ERROR_FAILURE;
}
if (!GetIsPrintPreview()) {
NS_ERROR("Wow, we should never get here!");
return NS_OK;
}
# if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
mPrintJob->TurnScriptingOn(true);
mPrintJob->Destroy();
mPrintJob = nullptr;
// Nowadays we use a static clone document for printing, and print preview is
// in a separate tab that gets closed after print preview finishes. Probably
// nothing below this line is necessary anymore.
SetIsPrintPreview(false);
nsCOMPtr<nsIDocShell> docShell(mContainer);
ResetFocusState(docShell);
SetTextZoom(mTextZoom);
SetFullZoom(mPageZoom);
SetOverrideDPPX(mOverrideDPPX);
Show();
# endif // NS_PRINTING && NS_PRINT_PREVIEW
return NS_OK;
}
@ -3975,55 +4026,6 @@ void nsDocumentViewer::DecrementDestroyBlockedCount() {
--mDestroyBlockedCount;
}
//------------------------------------------------------------
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
//------------------------------------------------------------
// Reset ESM focus for all descendent doc shells.
static void ResetFocusState(nsIDocShell* aDocShell) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (!fm) return;
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
aDocShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeContent,
nsIDocShell::ENUMERATE_FORWARDS,
getter_AddRefs(docShellEnumerator));
nsCOMPtr<nsISupports> currentContainer;
bool hasMoreDocShells;
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) &&
hasMoreDocShells) {
docShellEnumerator->GetNext(getter_AddRefs(currentContainer));
nsCOMPtr<nsPIDOMWindowOuter> win = do_GetInterface(currentContainer);
if (win) fm->ClearFocus(win);
}
}
#endif // NS_PRINTING && NS_PRINT_PREVIEW
void nsDocumentViewer::ReturnToGalleyPresentation() {
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
if (!GetIsPrintPreview()) {
NS_ERROR("Wow, we should never get here!");
return;
}
SetIsPrintPreview(false);
mPrintJob->TurnScriptingOn(true);
mPrintJob->Destroy();
mPrintJob = nullptr;
nsCOMPtr<nsIDocShell> docShell(mContainer);
ResetFocusState(docShell);
SetTextZoom(mTextZoom);
SetFullZoom(mPageZoom);
SetOverrideDPPX(mOverrideDPPX);
Show();
#endif // NS_PRINTING && NS_PRINT_PREVIEW
}
//------------------------------------------------------------
// This called ONLY when printing has completed and the DV
// is being notified that it should get rid of the nsPrintJob.