nsPIWindowRoot.h (3074B)
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 7 #ifndef nsPIWindowRoot_h__ 8 #define nsPIWindowRoot_h__ 9 10 #include "mozilla/dom/EventTarget.h" 11 #include "nsISupports.h" 12 13 class nsPIDOMWindowOuter; 14 class nsIControllers; 15 class nsIController; 16 class nsINode; 17 class nsIRemoteTab; 18 19 #define NS_IWINDOWROOT_IID \ 20 {0xb8724c49, 0xc398, 0x4f9b, {0x82, 0x59, 0x87, 0x27, 0xa6, 0x47, 0xdd, 0x0f}} 21 22 class nsPIWindowRoot : public mozilla::dom::EventTarget { 23 public: 24 NS_INLINE_DECL_STATIC_IID(NS_IWINDOWROOT_IID) 25 26 bool IsRootWindow() const final { return true; } 27 28 NS_IMPL_FROMEVENTTARGET_HELPER(nsPIWindowRoot, IsRootWindow()) 29 30 virtual nsPIDOMWindowOuter* GetWindow() = 0; 31 32 // get and set the node that is the context of a popup menu 33 virtual already_AddRefed<nsINode> GetPopupNode() = 0; 34 virtual void SetPopupNode(nsINode* aNode) = 0; 35 36 /** 37 * @param aForVisibleWindow true if caller needs controller which is 38 * associated with visible window. 39 */ 40 virtual nsresult GetControllerForCommand(const char* aCommand, 41 bool aForVisibleWindow, 42 nsIController** aResult) = 0; 43 44 /** 45 * @param aForVisibleWindow true if caller needs controllers which are 46 * associated with visible window. 47 */ 48 virtual nsresult GetControllers(bool aForVisibleWindow, 49 nsIControllers** aResult) = 0; 50 51 virtual void GetEnabledDisabledCommands( 52 nsTArray<nsCString>& aEnabledCommands, 53 nsTArray<nsCString>& aDisabledCommands) = 0; 54 55 virtual void SetParentTarget(mozilla::dom::EventTarget* aTarget) = 0; 56 virtual mozilla::dom::EventTarget* GetParentTarget() = 0; 57 58 // Stores a weak reference to the browser. 59 virtual void AddBrowser(nsIRemoteTab* aBrowser) = 0; 60 virtual void RemoveBrowser(nsIRemoteTab* aBrowser) = 0; 61 62 using BrowserEnumerator = void (*)(nsIRemoteTab* aTab, void* aArg); 63 64 // Enumerate all stored browsers that for which the weak reference is valid. 65 virtual void EnumerateBrowsers(BrowserEnumerator aEnumFunc, void* aArg) = 0; 66 }; 67 68 namespace mozilla::dom { 69 70 inline nsPIWindowRoot* EventTarget::GetAsWindowRoot() { 71 return IsRootWindow() ? static_cast<nsPIWindowRoot*>(this) : nullptr; 72 } 73 74 inline const nsPIWindowRoot* EventTarget::GetAsWindowRoot() const { 75 return IsRootWindow() ? static_cast<const nsPIWindowRoot*>(this) : nullptr; 76 } 77 78 inline nsPIWindowRoot* EventTarget::AsWindowRoot() { 79 MOZ_DIAGNOSTIC_ASSERT(IsRootWindow()); 80 return static_cast<nsPIWindowRoot*>(this); 81 } 82 83 inline const nsPIWindowRoot* EventTarget::AsWindowRoot() const { 84 MOZ_DIAGNOSTIC_ASSERT(IsRootWindow()); 85 return static_cast<const nsPIWindowRoot*>(this); 86 } 87 88 } // namespace mozilla::dom 89 90 #endif // nsPIWindowRoot_h__