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 nsAppShellWindowEnumerator_h 7 #define nsAppShellWindowEnumerator_h 8 9 #include "nsCOMPtr.h" 10 #include "nsString.h" 11 12 #include "nsSimpleEnumerator.h" 13 #include "nsIAppWindow.h" 14 15 class nsWindowMediator; 16 17 // 18 // nsWindowInfo 19 // 20 21 struct nsWindowInfo { 22 nsWindowInfo(nsIAppWindow* inWindow, int32_t inTimeStamp); 23 ~nsWindowInfo(); 24 25 nsCOMPtr<nsIAppWindow> mWindow; 26 int32_t mTimeStamp; 27 uint32_t mZLevel; 28 29 // each struct is in two, independent, circular, doubly-linked lists 30 nsWindowInfo *mYounger, // next younger in sequence 31 *mOlder; 32 nsWindowInfo *mLower, // next lower in z-order 33 *mHigher; 34 35 bool TypeEquals(const nsAString& aType); 36 void InsertAfter(nsWindowInfo* inOlder, nsWindowInfo* inHigher); 37 void Unlink(bool inAge, bool inZ); 38 void ReferenceSelf(bool inAge, bool inZ); 39 }; 40 41 // 42 // virtual enumerators 43 // 44 45 class nsAppShellWindowEnumerator : public nsSimpleEnumerator { 46 friend class nsWindowMediator; 47 48 public: 49 nsAppShellWindowEnumerator(const char16_t* aTypeString, 50 nsWindowMediator& inMediator); 51 NS_IMETHOD GetNext(nsISupports** retval) override = 0; 52 NS_IMETHOD HasMoreElements(bool* retval) override; 53 54 protected: 55 ~nsAppShellWindowEnumerator() override; 56 57 void AdjustInitialPosition(); 58 virtual nsWindowInfo* FindNext() = 0; 59 60 void WindowRemoved(nsWindowInfo* inInfo); 61 62 nsWindowMediator* mWindowMediator; 63 nsString mType; 64 nsWindowInfo* mCurrentPosition; 65 }; 66 67 class nsASDOMWindowEnumerator : public nsAppShellWindowEnumerator { 68 public: 69 nsASDOMWindowEnumerator(const char16_t* aTypeString, 70 nsWindowMediator& inMediator); 71 virtual ~nsASDOMWindowEnumerator(); 72 NS_IMETHOD GetNext(nsISupports** retval) override; 73 }; 74 75 class nsASAppWindowEnumerator : public nsAppShellWindowEnumerator { 76 public: 77 nsASAppWindowEnumerator(const char16_t* aTypeString, 78 nsWindowMediator& inMediator); 79 virtual ~nsASAppWindowEnumerator(); 80 NS_IMETHOD GetNext(nsISupports** retval) override; 81 DefaultInterface()82 const nsID& DefaultInterface() override { return NS_GET_IID(nsIAppWindow); } 83 }; 84 85 // 86 // concrete enumerators 87 // 88 89 class nsASDOMWindowEarlyToLateEnumerator : public nsASDOMWindowEnumerator { 90 public: 91 nsASDOMWindowEarlyToLateEnumerator(const char16_t* aTypeString, 92 nsWindowMediator& inMediator); 93 94 virtual ~nsASDOMWindowEarlyToLateEnumerator(); 95 96 protected: 97 virtual nsWindowInfo* FindNext() override; 98 }; 99 100 class nsASAppWindowEarlyToLateEnumerator : public nsASAppWindowEnumerator { 101 public: 102 nsASAppWindowEarlyToLateEnumerator(const char16_t* aTypeString, 103 nsWindowMediator& inMediator); 104 105 virtual ~nsASAppWindowEarlyToLateEnumerator(); 106 107 protected: 108 virtual nsWindowInfo* FindNext() override; 109 }; 110 111 class nsASAppWindowFrontToBackEnumerator : public nsASAppWindowEnumerator { 112 public: 113 nsASAppWindowFrontToBackEnumerator(const char16_t* aTypeString, 114 nsWindowMediator& inMediator); 115 116 virtual ~nsASAppWindowFrontToBackEnumerator(); 117 118 protected: 119 virtual nsWindowInfo* FindNext() override; 120 }; 121 122 class nsASAppWindowBackToFrontEnumerator : public nsASAppWindowEnumerator { 123 public: 124 nsASAppWindowBackToFrontEnumerator(const char16_t* aTypeString, 125 nsWindowMediator& inMediator); 126 127 virtual ~nsASAppWindowBackToFrontEnumerator(); 128 129 protected: 130 virtual nsWindowInfo* FindNext() override; 131 }; 132 133 #endif 134