Bug 1665252 - remove allowpaymentrequest attribute from HTMLIFrameElement r=dom-worke...
[gecko.git] / dom / base / AutoPrintEventDispatcher.h
blob0eba437ef72fa6b9d15f17dbe9551c60cfed4653
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 #ifndef mozilla_dom_AutoPrintEventDispatcher_h
8 #define mozilla_dom_AutoPrintEventDispatcher_h
10 #include "mozilla/dom/Document.h"
11 #include "nsContentUtils.h"
13 namespace mozilla::dom {
15 class AutoPrintEventDispatcher {
16 // NOTE(emilio): For fission iframes, we dispatch this event in
17 // RecvCloneDocumentTreeIntoSelf.
18 static void CollectInProcessSubdocuments(
19 Document& aDoc, nsTArray<nsCOMPtr<Document>>& aDocs) {
20 aDocs.AppendElement(&aDoc);
21 auto recurse = [&aDocs](Document& aSubDoc) {
22 CollectInProcessSubdocuments(aSubDoc, aDocs);
23 return CallState::Continue;
25 aDoc.EnumerateSubDocuments(recurse);
28 void DispatchEvent(bool aBefore) {
29 for (nsCOMPtr<Document>& doc : mDocuments) {
30 nsContentUtils::DispatchTrustedEvent(
31 doc, doc->GetWindow(), aBefore ? u"beforeprint"_ns : u"afterprint"_ns,
32 CanBubble::eNo, Cancelable::eNo, nullptr);
36 public:
37 explicit AutoPrintEventDispatcher(Document& aDoc) {
38 if (!aDoc.IsStaticDocument()) {
39 CollectInProcessSubdocuments(aDoc, mDocuments);
42 DispatchEvent(true);
45 ~AutoPrintEventDispatcher() { DispatchEvent(false); }
47 AutoTArray<nsCOMPtr<Document>, 8> mDocuments;
50 } // namespace mozilla::dom
52 #endif