Bug 1858509 add thread-safety annotations around MediaSourceDemuxer::mMonitor r=alwu
[gecko.git] / layout / printing / nsPrintObject.cpp
blob79c134a9dee69a49e03c5bb1dc2ac23afe517c50
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsPrintObject.h"
9 #include "nsIDocumentViewer.h"
10 #include "nsContentUtils.h" // for nsAutoScriptBlocker
11 #include "nsIInterfaceRequestorUtils.h"
12 #include "nsPIDOMWindow.h"
13 #include "nsPresContext.h"
14 #include "nsGkAtoms.h"
15 #include "nsComponentManagerUtils.h"
16 #include "nsIBaseWindow.h"
17 #include "nsDocShell.h"
19 #include "mozilla/PresShell.h"
20 #include "mozilla/dom/BrowsingContext.h"
21 #include "mozilla/dom/Document.h"
22 #include "mozilla/dom/Element.h"
24 using namespace mozilla;
25 using mozilla::dom::BrowsingContext;
26 using mozilla::dom::Document;
27 using mozilla::dom::Element;
28 using mozilla::dom::Selection;
30 //---------------------------------------------------
31 //-- nsPrintObject Class Impl
32 //---------------------------------------------------
33 nsPrintObject::nsPrintObject(nsIDocShell& aDocShell, Document& aDoc,
34 nsPrintObject* aParent)
35 : mDocShell(&aDocShell), mDocument(&aDoc), mParent(aParent) {
36 MOZ_COUNT_CTOR(nsPrintObject);
37 MOZ_ASSERT(aDoc.IsStaticDocument());
39 if (!aParent) {
40 // We are a root nsPrintObject.
41 // Ensure the document has no presentation.
42 DestroyPresentation();
43 } else {
44 // We are a nested nsPrintObject.
45 nsCOMPtr<nsPIDOMWindowOuter> window = aDoc.GetWindow();
46 mContent = window->GetFrameElementInternal();
50 nsPrintObject::~nsPrintObject() {
51 MOZ_COUNT_DTOR(nsPrintObject);
53 DestroyPresentation();
54 mDocShell = nullptr;
55 mTreeOwner = nullptr; // mTreeOwner must be released after mDocShell;
58 //------------------------------------------------------------------
59 // Resets PO by destroying the presentation
60 void nsPrintObject::DestroyPresentation() {
61 if (mDocument) {
62 if (RefPtr<PresShell> ps = mDocument->GetPresShell()) {
63 MOZ_DIAGNOSTIC_ASSERT(!mPresShell || ps == mPresShell);
64 mPresShell = nullptr;
65 nsAutoScriptBlocker scriptBlocker;
66 ps->EndObservingDocument();
67 ps->Destroy();
70 mPresShell = nullptr;
71 mPresContext = nullptr;
72 mViewManager = nullptr;
75 void nsPrintObject::EnablePrinting(bool aEnable) {
76 mPrintingIsEnabled = aEnable;
78 for (const UniquePtr<nsPrintObject>& kid : mKids) {
79 kid->EnablePrinting(aEnable);
83 bool nsPrintObject::HasSelection() const {
84 return mDocument && mDocument->GetProperty(nsGkAtoms::printselectionranges);
87 void nsPrintObject::EnablePrintingSelectionOnly() {
88 mPrintingIsEnabled = HasSelection();
90 for (const UniquePtr<nsPrintObject>& kid : mKids) {
91 kid->EnablePrintingSelectionOnly();