nsXULWindow.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  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 nsXULWindow_h__
  7. #define nsXULWindow_h__
  8. // Local Includes
  9. #include "nsChromeTreeOwner.h"
  10. #include "nsContentTreeOwner.h"
  11. // Helper classes
  12. #include "nsCOMPtr.h"
  13. #include "nsTArray.h"
  14. #include "nsString.h"
  15. #include "nsWeakReference.h"
  16. #include "nsCOMArray.h"
  17. #include "nsRect.h"
  18. #include "Units.h"
  19. // Interfaces needed
  20. #include "nsIBaseWindow.h"
  21. #include "nsIDocShell.h"
  22. #include "nsIDocShellTreeItem.h"
  23. #include "nsIDOMWindow.h"
  24. #include "nsIInterfaceRequestor.h"
  25. #include "nsIInterfaceRequestorUtils.h"
  26. #include "nsIXULWindow.h"
  27. #include "nsIPrompt.h"
  28. #include "nsIAuthPrompt.h"
  29. #include "nsIXULBrowserWindow.h"
  30. #include "nsIWeakReference.h"
  31. #include "nsIWidgetListener.h"
  32. #include "nsITabParent.h"
  33. namespace mozilla {
  34. namespace dom {
  35. class Element;
  36. } // namespace dom
  37. } // namespace mozilla
  38. // nsXULWindow
  39. #define NS_XULWINDOW_IMPL_CID \
  40. { /* 8eaec2f3-ed02-4be2-8e0f-342798477298 */ \
  41. 0x8eaec2f3, \
  42. 0xed02, \
  43. 0x4be2, \
  44. { 0x8e, 0x0f, 0x34, 0x27, 0x98, 0x47, 0x72, 0x98 } \
  45. }
  46. class nsContentShellInfo;
  47. class nsXULWindow : public nsIBaseWindow,
  48. public nsIInterfaceRequestor,
  49. public nsIXULWindow,
  50. public nsSupportsWeakReference
  51. {
  52. friend class nsChromeTreeOwner;
  53. friend class nsContentTreeOwner;
  54. public:
  55. NS_DECL_THREADSAFE_ISUPPORTS
  56. NS_DECL_NSIINTERFACEREQUESTOR
  57. NS_DECL_NSIXULWINDOW
  58. NS_DECL_NSIBASEWINDOW
  59. NS_DECLARE_STATIC_IID_ACCESSOR(NS_XULWINDOW_IMPL_CID)
  60. void LockUntilChromeLoad() { mLockedUntilChromeLoad = true; }
  61. bool IsLocked() const { return mLockedUntilChromeLoad; }
  62. void IgnoreXULSizeMode(bool aEnable) { mIgnoreXULSizeMode = aEnable; }
  63. void WasRegistered() { mRegistered = true; }
  64. protected:
  65. enum persistentAttributes {
  66. PAD_MISC = 0x1,
  67. PAD_POSITION = 0x2,
  68. PAD_SIZE = 0x4
  69. };
  70. explicit nsXULWindow(uint32_t aChromeFlags);
  71. virtual ~nsXULWindow();
  72. NS_IMETHOD EnsureChromeTreeOwner();
  73. NS_IMETHOD EnsureContentTreeOwner();
  74. NS_IMETHOD EnsurePrimaryContentTreeOwner();
  75. NS_IMETHOD EnsurePrompter();
  76. NS_IMETHOD EnsureAuthPrompter();
  77. void OnChromeLoaded();
  78. void StaggerPosition(int32_t &aRequestedX, int32_t &aRequestedY,
  79. int32_t aSpecWidth, int32_t aSpecHeight);
  80. bool LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight);
  81. bool LoadSizeFromXUL(int32_t& aSpecWidth, int32_t& aSpecHeight);
  82. void SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight);
  83. bool LoadMiscPersistentAttributesFromXUL();
  84. void SyncAttributesToWidget();
  85. NS_IMETHOD SavePersistentAttributes();
  86. NS_IMETHOD GetWindowDOMWindow(mozIDOMWindowProxy** aDOMWindow);
  87. mozilla::dom::Element* GetWindowDOMElement() const;
  88. // See nsIDocShellTreeOwner for docs on next two methods
  89. nsresult ContentShellAdded(nsIDocShellTreeItem* aContentShell,
  90. bool aPrimary, bool aTargetable,
  91. const nsAString& aID);
  92. nsresult ContentShellRemoved(nsIDocShellTreeItem* aContentShell);
  93. NS_IMETHOD GetPrimaryContentSize(int32_t* aWidth,
  94. int32_t* aHeight);
  95. NS_IMETHOD SetPrimaryContentSize(int32_t aWidth,
  96. int32_t aHeight);
  97. nsresult GetRootShellSize(int32_t* aWidth,
  98. int32_t* aHeight);
  99. nsresult SetRootShellSize(int32_t aWidth,
  100. int32_t aHeight);
  101. NS_IMETHOD SizeShellTo(nsIDocShellTreeItem* aShellItem, int32_t aCX,
  102. int32_t aCY);
  103. NS_IMETHOD ExitModalLoop(nsresult aStatus);
  104. NS_IMETHOD CreateNewChromeWindow(int32_t aChromeFlags, nsITabParent* aOpeningTab, mozIDOMWindowProxy* aOpenerWindow, nsIXULWindow **_retval);
  105. NS_IMETHOD CreateNewContentWindow(int32_t aChromeFlags, nsITabParent* aOpeningTab, mozIDOMWindowProxy* aOpenerWindow, nsIXULWindow **_retval);
  106. NS_IMETHOD GetHasPrimaryContent(bool* aResult);
  107. void EnableParent(bool aEnable);
  108. bool ConstrainToZLevel(bool aImmediate, nsWindowZ *aPlacement,
  109. nsIWidget *aReqBelow, nsIWidget **aActualBelow);
  110. void PlaceWindowLayersBehind(uint32_t aLowLevel, uint32_t aHighLevel,
  111. nsIXULWindow *aBehind);
  112. void SetContentScrollbarVisibility(bool aVisible);
  113. bool GetContentScrollbarVisibility();
  114. void PersistentAttributesDirty(uint32_t aDirtyFlags);
  115. nsChromeTreeOwner* mChromeTreeOwner;
  116. nsContentTreeOwner* mContentTreeOwner;
  117. nsContentTreeOwner* mPrimaryContentTreeOwner;
  118. nsCOMPtr<nsIWidget> mWindow;
  119. nsCOMPtr<nsIDocShell> mDocShell;
  120. nsCOMPtr<nsPIDOMWindowOuter> mDOMWindow;
  121. nsCOMPtr<nsIWeakReference> mParentWindow;
  122. nsCOMPtr<nsIPrompt> mPrompter;
  123. nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
  124. nsCOMPtr<nsIXULBrowserWindow> mXULBrowserWindow;
  125. nsCOMPtr<nsIDocShellTreeItem> mPrimaryContentShell;
  126. nsTArray<nsContentShellInfo*> mContentShells; // array of doc shells by id
  127. nsresult mModalStatus;
  128. bool mContinueModalLoop;
  129. bool mDebuting; // being made visible right now
  130. bool mChromeLoaded; // True when chrome has loaded
  131. bool mShowAfterLoad;
  132. bool mIntrinsicallySized;
  133. bool mCenterAfterLoad;
  134. bool mIsHiddenWindow;
  135. bool mLockedUntilChromeLoad;
  136. bool mIgnoreXULSize;
  137. bool mIgnoreXULPosition;
  138. bool mChromeFlagsFrozen;
  139. bool mIgnoreXULSizeMode;
  140. // mDestroying is used to prevent reentry into into Destroy(), which can
  141. // otherwise happen due to script running as we tear down various things.
  142. bool mDestroying;
  143. bool mRegistered;
  144. uint32_t mContextFlags;
  145. uint32_t mPersistentAttributesDirty; // persistentAttributes
  146. uint32_t mPersistentAttributesMask;
  147. uint32_t mChromeFlags;
  148. nsString mTitle;
  149. nsIntRect mOpenerScreenRect; // the screen rect of the opener
  150. nsCOMArray<nsIWeakReference> mTargetableShells; // targetable shells only
  151. nsCOMPtr<nsITabParent> mPrimaryTabParent;
  152. private:
  153. nsresult GetPrimaryTabParentSize(int32_t* aWidth, int32_t* aHeight);
  154. nsresult GetPrimaryContentShellSize(int32_t* aWidth, int32_t* aHeight);
  155. nsresult SetPrimaryTabParentSize(int32_t aWidth, int32_t aHeight);
  156. };
  157. NS_DEFINE_STATIC_IID_ACCESSOR(nsXULWindow, NS_XULWINDOW_IMPL_CID)
  158. // nsContentShellInfo
  159. // Used to map shell IDs to nsIDocShellTreeItems.
  160. class nsContentShellInfo
  161. {
  162. public:
  163. nsContentShellInfo(const nsAString& aID,
  164. nsIWeakReference* aContentShell);
  165. ~nsContentShellInfo();
  166. public:
  167. nsString id; // The identifier of the content shell
  168. nsWeakPtr child; // content shell (weak reference to nsIDocShellTreeItem)
  169. };
  170. #endif /* nsXULWindow_h__ */