1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef nsWindowMediator_h_
7 #define nsWindowMediator_h_
8 
9 #include "nsCOMPtr.h"
10 #include "nsIWindowMediator.h"
11 #include "nsIObserver.h"
12 #include "nsTArray.h"
13 #include "nsString.h"
14 #include "nsWeakReference.h"
15 #include "nsTObserverArray.h"
16 
17 class nsAppShellWindowEnumerator;
18 class nsASAppWindowEarlyToLateEnumerator;
19 class nsASDOMWindowEarlyToLateEnumerator;
20 class nsASAppWindowFrontToBackEnumerator;
21 class nsASAppWindowBackToFrontEnumerator;
22 class nsIWindowMediatorListener;
23 struct nsWindowInfo;
24 
25 class nsWindowMediator : public nsIWindowMediator,
26                          public nsIObserver,
27                          public nsSupportsWeakReference {
28   friend class nsAppShellWindowEnumerator;
29   friend class nsASAppWindowEarlyToLateEnumerator;
30   friend class nsASDOMWindowEarlyToLateEnumerator;
31   friend class nsASAppWindowFrontToBackEnumerator;
32   friend class nsASAppWindowBackToFrontEnumerator;
33 
34  protected:
35   virtual ~nsWindowMediator();
36 
37  public:
38   nsWindowMediator();
39 
40   nsresult Init();
41 
42   NS_DECL_ISUPPORTS
43   NS_DECL_NSIWINDOWMEDIATOR
44   NS_DECL_NSIOBSERVER
45 
46   static nsresult GetDOMWindow(nsIAppWindow* inWindow,
47                                nsCOMPtr<nsPIDOMWindowOuter>& outDOMWindow);
48 
49  private:
50   void AddEnumerator(nsAppShellWindowEnumerator* inEnumerator);
51   int32_t RemoveEnumerator(nsAppShellWindowEnumerator* inEnumerator);
52   nsWindowInfo* MostRecentWindowInfo(const char16_t* inType,
53                                      bool aSkipPrivateBrowsingOrClosed = false);
54 
55   nsresult UnregisterWindow(nsWindowInfo* inInfo);
56   nsWindowInfo* GetInfoFor(nsIAppWindow* aWindow);
57   nsWindowInfo* GetInfoFor(nsIWidget* aWindow);
58   void SortZOrderFrontToBack();
59   void SortZOrderBackToFront();
60 
61   nsTArray<nsAppShellWindowEnumerator*> mEnumeratorList;
62   nsWindowInfo* mOldestWindow;
63   nsWindowInfo* mTopmostWindow;
64   int32_t mTimeStamp;
65   bool mSortingZOrder;
66   bool mReady;
67 
68   typedef nsTObserverArray<nsCOMPtr<nsIWindowMediatorListener>> ListenerArray;
69   ListenerArray mListeners;
70 };
71 
72 #endif
73