2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-08-21 16:01:05 +04:00
|
|
|
|
|
|
|
#include "nsPrintObject.h"
|
2018-11-13 01:20:52 +03:00
|
|
|
|
2006-12-10 11:05:05 +03:00
|
|
|
#include "nsIContentViewer.h"
|
2013-08-14 10:56:21 +04:00
|
|
|
#include "nsContentUtils.h" // for nsAutoScriptBlocker
|
2009-12-11 07:02:13 +03:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2018-11-13 01:20:52 +03:00
|
|
|
#include "nsPresContext.h"
|
2009-12-11 07:02:13 +03:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2011-01-14 15:27:31 +03:00
|
|
|
#include "nsIBaseWindow.h"
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "nsDocShell.h"
|
|
|
|
|
2019-04-16 10:25:10 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2018-11-05 15:43:10 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2019-04-16 10:25:10 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2018-11-13 01:20:52 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
|
2020-07-14 21:15:49 +03:00
|
|
|
using namespace mozilla;
|
2018-11-13 01:20:52 +03:00
|
|
|
using mozilla::dom::BrowsingContext;
|
2019-05-01 19:03:35 +03:00
|
|
|
using mozilla::dom::Document;
|
2018-11-13 01:20:52 +03:00
|
|
|
using mozilla::dom::Element;
|
2020-07-14 21:15:49 +03:00
|
|
|
using mozilla::dom::Selection;
|
2013-10-03 00:09:18 +04:00
|
|
|
|
2002-08-21 16:01:05 +04:00
|
|
|
//---------------------------------------------------
|
|
|
|
//-- nsPrintObject Class Impl
|
|
|
|
//---------------------------------------------------
|
2018-04-13 16:01:28 +03:00
|
|
|
nsPrintObject::nsPrintObject()
|
|
|
|
: mContent(nullptr),
|
|
|
|
mFrameType(eFrame),
|
|
|
|
mParent(nullptr),
|
|
|
|
mHasBeenPrinted(false),
|
2018-07-12 09:42:14 +03:00
|
|
|
mInvisible(false),
|
|
|
|
mDidCreateDocShell(false),
|
2018-04-13 16:01:28 +03:00
|
|
|
mShrinkRatio(1.0),
|
|
|
|
mZoomRatio(1.0) {
|
2011-06-16 22:20:13 +04:00
|
|
|
MOZ_COUNT_CTOR(nsPrintObject);
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintObject::~nsPrintObject() {
|
2011-06-16 22:20:13 +04:00
|
|
|
MOZ_COUNT_DTOR(nsPrintObject);
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2006-12-10 11:05:05 +03:00
|
|
|
DestroyPresentation();
|
2011-01-14 15:27:31 +03:00
|
|
|
if (mDidCreateDocShell && mDocShell) {
|
2020-02-06 22:07:56 +03:00
|
|
|
RefPtr<BrowsingContext> bc(mDocShell->GetBrowsingContext());
|
|
|
|
nsDocShell::Cast(mDocShell)->Destroy();
|
|
|
|
bc->Detach();
|
2017-03-06 10:35:39 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocShell = nullptr;
|
2017-03-06 10:35:39 +03:00
|
|
|
mTreeOwner = nullptr; // mTreeOwner must be released after mDocShell;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2020-04-23 19:41:49 +03:00
|
|
|
|
2019-05-28 14:48:21 +03:00
|
|
|
nsresult nsPrintObject::InitAsRootObject(nsIDocShell* aDocShell, Document* aDoc,
|
|
|
|
bool aForPrintPreview) {
|
|
|
|
NS_ENSURE_STATE(aDocShell);
|
2018-05-11 20:46:15 +03:00
|
|
|
NS_ENSURE_STATE(aDoc);
|
|
|
|
|
Bug 1636728 - Centralize printing entry points in nsGlobalWindowOuter, and move cloning out of nsPrintJob. r=jwatt,geckoview-reviewers,smaug,agi
This centralizes our print and preview setup in nsGlobalWindowOuter so
that we never re-clone a clone, and so that we reuse the window.open()
codepath to create the browsing context to clone into.
For window.print, for both old print dialog / silent printing and new
print preview UI, we now create a hidden browser (as in with visibility:
collapse, which takes no space but still gets a layout box).
* In the modern UI case, this browser is swapped with the actual print
preview clone, and the UI takes care of removing the browser.
* In the print dialog / silent printing case, the printing code calls
window.close() from nsDocumentViewer::OnDonePrinting().
* We don't need to care about the old print preview UI for this case
because it can't be open from window.print().
We need to fall back to an actual window when there's no
nsIBrowserDOMWindow around for WPT print tests and the like, which don't
have one. That seems fine, we could special-case this code path more if
needed but it doesn't seem worth it.
Differential Revision: https://phabricator.services.mozilla.com/D87063
2020-08-25 20:45:12 +03:00
|
|
|
MOZ_ASSERT(aDoc->IsStaticDocument());
|
2009-12-11 07:02:13 +03:00
|
|
|
|
Bug 1636728 - Centralize printing entry points in nsGlobalWindowOuter, and move cloning out of nsPrintJob. r=jwatt,geckoview-reviewers,smaug,agi
This centralizes our print and preview setup in nsGlobalWindowOuter so
that we never re-clone a clone, and so that we reuse the window.open()
codepath to create the browsing context to clone into.
For window.print, for both old print dialog / silent printing and new
print preview UI, we now create a hidden browser (as in with visibility:
collapse, which takes no space but still gets a layout box).
* In the modern UI case, this browser is swapped with the actual print
preview clone, and the UI takes care of removing the browser.
* In the print dialog / silent printing case, the printing code calls
window.close() from nsDocumentViewer::OnDonePrinting().
* We don't need to care about the old print preview UI for this case
because it can't be open from window.print().
We need to fall back to an actual window when there's no
nsIBrowserDOMWindow around for WPT print tests and the like, which don't
have one. That seems fine, we could special-case this code path more if
needed but it doesn't seem worth it.
Differential Revision: https://phabricator.services.mozilla.com/D87063
2020-08-25 20:45:12 +03:00
|
|
|
mDocShell = aDocShell;
|
|
|
|
mDocument = aDoc;
|
2016-07-18 19:37:11 +03:00
|
|
|
|
Bug 1636728 - Centralize printing entry points in nsGlobalWindowOuter, and move cloning out of nsPrintJob. r=jwatt,geckoview-reviewers,smaug,agi
This centralizes our print and preview setup in nsGlobalWindowOuter so
that we never re-clone a clone, and so that we reuse the window.open()
codepath to create the browsing context to clone into.
For window.print, for both old print dialog / silent printing and new
print preview UI, we now create a hidden browser (as in with visibility:
collapse, which takes no space but still gets a layout box).
* In the modern UI case, this browser is swapped with the actual print
preview clone, and the UI takes care of removing the browser.
* In the print dialog / silent printing case, the printing code calls
window.close() from nsDocumentViewer::OnDonePrinting().
* We don't need to care about the old print preview UI for this case
because it can't be open from window.print().
We need to fall back to an actual window when there's no
nsIBrowserDOMWindow around for WPT print tests and the like, which don't
have one. That seems fine, we could special-case this code path more if
needed but it doesn't seem worth it.
Differential Revision: https://phabricator.services.mozilla.com/D87063
2020-08-25 20:45:12 +03:00
|
|
|
// Ensure the document has no presentation.
|
|
|
|
DestroyPresentation();
|
2009-12-11 07:02:13 +03:00
|
|
|
|
2019-05-28 14:48:21 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsPrintObject::InitAsNestedObject(nsIDocShell* aDocShell,
|
|
|
|
Document* aDoc,
|
|
|
|
nsPrintObject* aParent) {
|
|
|
|
NS_ENSURE_STATE(aDocShell);
|
|
|
|
NS_ENSURE_STATE(aDoc);
|
|
|
|
|
|
|
|
mParent = aParent;
|
|
|
|
mDocShell = aDocShell;
|
|
|
|
mDocument = aDoc;
|
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = aDoc->GetWindow();
|
|
|
|
mContent = window->GetFrameElementInternal();
|
2002-08-21 16:01:05 +04:00
|
|
|
|
2020-06-03 00:03:20 +03:00
|
|
|
// "frame" elements not in a frameset context should be treated
|
|
|
|
// as iframes
|
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::frame) &&
|
|
|
|
mParent->mFrameType == eFrameSet) {
|
|
|
|
mFrameType = eFrame;
|
|
|
|
} else {
|
|
|
|
// Assume something iframe-like, i.e. iframe, object, or embed
|
|
|
|
mFrameType = eIFrame;
|
|
|
|
}
|
2002-08-21 16:01:05 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Resets PO by destroying the presentation
|
|
|
|
void nsPrintObject::DestroyPresentation() {
|
Bug 1636728 - Centralize printing entry points in nsGlobalWindowOuter, and move cloning out of nsPrintJob. r=jwatt,geckoview-reviewers,smaug,agi
This centralizes our print and preview setup in nsGlobalWindowOuter so
that we never re-clone a clone, and so that we reuse the window.open()
codepath to create the browsing context to clone into.
For window.print, for both old print dialog / silent printing and new
print preview UI, we now create a hidden browser (as in with visibility:
collapse, which takes no space but still gets a layout box).
* In the modern UI case, this browser is swapped with the actual print
preview clone, and the UI takes care of removing the browser.
* In the print dialog / silent printing case, the printing code calls
window.close() from nsDocumentViewer::OnDonePrinting().
* We don't need to care about the old print preview UI for this case
because it can't be open from window.print().
We need to fall back to an actual window when there's no
nsIBrowserDOMWindow around for WPT print tests and the like, which don't
have one. That seems fine, we could special-case this code path more if
needed but it doesn't seem worth it.
Differential Revision: https://phabricator.services.mozilla.com/D87063
2020-08-25 20:45:12 +03:00
|
|
|
if (mDocument) {
|
|
|
|
if (RefPtr<PresShell> ps = mDocument->GetPresShell()) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mPresShell || ps == mPresShell);
|
|
|
|
mPresShell = nullptr;
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
ps->EndObservingDocument();
|
|
|
|
ps->Destroy();
|
|
|
|
}
|
2006-12-10 11:05:05 +03:00
|
|
|
}
|
Bug 1636728 - Centralize printing entry points in nsGlobalWindowOuter, and move cloning out of nsPrintJob. r=jwatt,geckoview-reviewers,smaug,agi
This centralizes our print and preview setup in nsGlobalWindowOuter so
that we never re-clone a clone, and so that we reuse the window.open()
codepath to create the browsing context to clone into.
For window.print, for both old print dialog / silent printing and new
print preview UI, we now create a hidden browser (as in with visibility:
collapse, which takes no space but still gets a layout box).
* In the modern UI case, this browser is swapped with the actual print
preview clone, and the UI takes care of removing the browser.
* In the print dialog / silent printing case, the printing code calls
window.close() from nsDocumentViewer::OnDonePrinting().
* We don't need to care about the old print preview UI for this case
because it can't be open from window.print().
We need to fall back to an actual window when there's no
nsIBrowserDOMWindow around for WPT print tests and the like, which don't
have one. That seems fine, we could special-case this code path more if
needed but it doesn't seem worth it.
Differential Revision: https://phabricator.services.mozilla.com/D87063
2020-08-25 20:45:12 +03:00
|
|
|
mPresShell = nullptr;
|
2012-12-18 08:32:34 +04:00
|
|
|
mPresContext = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewManager = nullptr;
|
2002-08-21 16:01:05 +04:00
|
|
|
}
|
2020-05-22 12:56:55 +03:00
|
|
|
|
2020-05-22 12:57:12 +03:00
|
|
|
void nsPrintObject::EnablePrinting(bool aEnable) {
|
2020-05-31 22:00:42 +03:00
|
|
|
mPrintingIsEnabled = aEnable;
|
2020-05-22 12:57:12 +03:00
|
|
|
|
|
|
|
for (const UniquePtr<nsPrintObject>& kid : mKids) {
|
|
|
|
kid->EnablePrinting(aEnable);
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 17:23:56 +03:00
|
|
|
|
2020-08-13 14:11:35 +03:00
|
|
|
bool nsPrintObject::HasSelection() const {
|
|
|
|
return mDocument && mDocument->GetProperty(nsGkAtoms::printselectionranges);
|
|
|
|
}
|
|
|
|
|
2020-08-03 17:23:56 +03:00
|
|
|
void nsPrintObject::EnablePrintingSelectionOnly() {
|
2020-08-13 14:11:35 +03:00
|
|
|
mPrintingIsEnabled = HasSelection();
|
2020-08-03 17:23:56 +03:00
|
|
|
|
|
|
|
for (const UniquePtr<nsPrintObject>& kid : mKids) {
|
|
|
|
kid->EnablePrintingSelectionOnly();
|
|
|
|
}
|
|
|
|
}
|