nsPagePrintTimer.h (2304B)
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/. */ 6 #ifndef nsPagePrintTimer_h___ 7 #define nsPagePrintTimer_h___ 8 9 // Timer Includes 10 #include "mozilla/OwningNonNull.h" 11 #include "nsIDocumentViewerPrint.h" 12 #include "nsITimer.h" 13 #include "nsThreadUtils.h" 14 15 class nsPrintJob; 16 class nsPrintObject; 17 18 namespace mozilla::dom { 19 class Document; 20 } 21 22 //--------------------------------------------------- 23 //-- Page Timer Class 24 //--------------------------------------------------- 25 // Strictly speaking, this actually manages the timing of printing *sheets* 26 // (instances of "PrintedSheetFrame"), each of which may encompass multiple 27 // pages (nsPageFrames) of the document. The use of "Page" in the class name 28 // here is for historical / colloquial purposes. 29 class nsPagePrintTimer final : public mozilla::Runnable, 30 public nsITimerCallback { 31 public: 32 NS_DECL_ISUPPORTS_INHERITED 33 34 nsPagePrintTimer(nsPrintJob* aPrintJob, 35 nsIDocumentViewerPrint* aDocViewerPrint, 36 mozilla::dom::Document* aDocument, uint32_t aDelay); 37 38 NS_DECL_NSITIMERCALLBACK 39 40 nsresult Start(nsPrintObject* aPO); 41 42 NS_IMETHOD Run() override; 43 44 void Stop(); 45 46 void WaitForRemotePrint(); 47 void RemotePrintFinished(); 48 49 void Disconnect(); 50 51 private: 52 ~nsPagePrintTimer(); 53 54 nsresult StartTimer(bool aUseDelay); 55 nsresult StartWatchDogTimer(); 56 void StopWatchDogTimer(); 57 void Fail(); 58 59 nsPrintJob* mPrintJob; 60 nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint; 61 RefPtr<mozilla::dom::Document> mDocument; 62 nsCOMPtr<nsITimer> mTimer; 63 nsCOMPtr<nsITimer> mWatchDogTimer; 64 nsCOMPtr<nsITimer> mWaitingForRemotePrint; 65 uint32_t mDelay; 66 uint32_t mFiringCount; 67 nsPrintObject* mPrintObj; 68 uint32_t mWatchDogCount; 69 bool mDone; 70 71 static const uint32_t WATCH_DOG_INTERVAL = 1000; 72 static const uint32_t WATCH_DOG_MAX_COUNT = 73 #ifdef DEBUG 74 // Debug builds are very slow (on Mac at least) and can need extra time 75 30 76 #else 77 10 78 #endif 79 ; 80 }; 81 82 #endif /* nsPagePrintTimer_h___ */