Bug 1876541 - Remove an assert that doesn't hold for svg roots.
[gecko.git] / xpfe / appshell / AppWindow.h
blob4acee5dbfee32965bf1dbb2a027b14b0ebe47703
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef mozilla_AppWindow_h__
8 #define mozilla_AppWindow_h__
10 // Local Includes
11 #include "nsChromeTreeOwner.h"
12 #include "nsContentTreeOwner.h"
14 // Helper classes
15 #include "nsCOMPtr.h"
16 #include "nsTArray.h"
17 #include "nsString.h"
18 #include "nsWeakReference.h"
19 #include "nsCOMArray.h"
20 #include "nsDocShell.h"
21 #include "nsRect.h"
22 #include "Units.h"
23 #include "mozilla/Maybe.h"
24 #include "mozilla/Mutex.h"
26 // Interfaces needed
27 #include "nsIBaseWindow.h"
28 #include "nsIDocShellTreeItem.h"
29 #include "nsIInterfaceRequestor.h"
30 #include "nsIInterfaceRequestorUtils.h"
31 #include "nsIAppWindow.h"
32 #include "nsIPrompt.h"
33 #include "nsIAuthPrompt.h"
34 #include "nsIXULBrowserWindow.h"
35 #include "nsIWidgetListener.h"
36 #include "nsIRemoteTab.h"
37 #include "nsIWebProgressListener.h"
38 #include "nsITimer.h"
39 #include "nsIXULStore.h"
41 class nsAtom;
42 class nsXULTooltipListener;
44 namespace mozilla {
45 class PresShell;
46 class AppWindowTimerCallback;
47 class L10nReadyPromiseHandler;
48 namespace dom {
49 class Element;
50 } // namespace dom
51 namespace widget {
52 struct InitData;
53 } // namespace widget
54 } // namespace mozilla
56 // AppWindow
58 #define NS_APPWINDOW_IMPL_CID \
59 { /* 8eaec2f3-ed02-4be2-8e0f-342798477298 */ \
60 0x8eaec2f3, 0xed02, 0x4be2, { \
61 0x8e, 0x0f, 0x34, 0x27, 0x98, 0x47, 0x72, 0x98 \
62 } \
65 class nsContentShellInfo;
67 namespace mozilla {
69 class AppWindow final : public nsIBaseWindow,
70 public nsIInterfaceRequestor,
71 public nsIAppWindow,
72 public nsSupportsWeakReference,
73 public nsIWebProgressListener {
74 friend class ::nsChromeTreeOwner;
75 friend class ::nsContentTreeOwner;
77 public:
78 // The implementation of non-refcounted nsIWidgetListener, which would hold a
79 // strong reference on stack before calling AppWindow's
80 // MOZ_CAN_RUN_SCRIPT methods.
81 class WidgetListenerDelegate : public nsIWidgetListener {
82 public:
83 explicit WidgetListenerDelegate(AppWindow* aAppWindow)
84 : mAppWindow(aAppWindow) {}
86 MOZ_CAN_RUN_SCRIPT_BOUNDARY
87 virtual nsIAppWindow* GetAppWindow() override;
88 MOZ_CAN_RUN_SCRIPT_BOUNDARY
89 virtual mozilla::PresShell* GetPresShell() override;
90 MOZ_CAN_RUN_SCRIPT_BOUNDARY
91 virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y,
92 ByMoveToRect) override;
93 MOZ_CAN_RUN_SCRIPT_BOUNDARY
94 virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth,
95 int32_t aHeight) override;
96 MOZ_CAN_RUN_SCRIPT_BOUNDARY
97 virtual bool RequestWindowClose(nsIWidget* aWidget) override;
98 MOZ_CAN_RUN_SCRIPT_BOUNDARY
99 virtual void SizeModeChanged(nsSizeMode sizeMode) override;
100 MOZ_CAN_RUN_SCRIPT_BOUNDARY
101 virtual void UIResolutionChanged() override;
102 MOZ_CAN_RUN_SCRIPT_BOUNDARY
103 virtual void MacFullscreenMenubarOverlapChanged(
104 mozilla::DesktopCoord aOverlapAmount) override;
105 MOZ_CAN_RUN_SCRIPT_BOUNDARY
106 virtual void OcclusionStateChanged(bool aIsFullyOccluded) override;
107 MOZ_CAN_RUN_SCRIPT_BOUNDARY
108 virtual void OSToolbarButtonPressed() override;
109 MOZ_CAN_RUN_SCRIPT_BOUNDARY
110 virtual bool ZLevelChanged(bool aImmediate, nsWindowZ* aPlacement,
111 nsIWidget* aRequestBelow,
112 nsIWidget** aActualBelow) override;
113 MOZ_CAN_RUN_SCRIPT_BOUNDARY
114 virtual void WindowActivated() override;
115 MOZ_CAN_RUN_SCRIPT_BOUNDARY
116 virtual void WindowDeactivated() override;
118 private:
119 // The lifetime of WidgetListenerDelegate is bound to AppWindow so
120 // we just use a raw pointer here.
121 AppWindow* mAppWindow;
124 NS_DECL_THREADSAFE_ISUPPORTS
126 NS_DECL_NSIINTERFACEREQUESTOR
127 NS_DECL_NSIAPPWINDOW
128 NS_DECL_NSIBASEWINDOW
130 NS_DECLARE_STATIC_IID_ACCESSOR(NS_APPWINDOW_IMPL_CID)
132 void LockUntilChromeLoad() { mLockedUntilChromeLoad = true; }
133 bool IsLocked() const { return mLockedUntilChromeLoad; }
134 void IgnoreXULSizeMode(bool aEnable) { mIgnoreXULSizeMode = aEnable; }
135 void WasRegistered() { mRegistered = true; }
137 using nsIBaseWindow::GetPositionAndSize;
138 using nsIBaseWindow::GetSize;
140 // AppWindow methods...
141 nsresult Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
142 int32_t aInitialWidth, int32_t aInitialHeight,
143 bool aIsHiddenWindow, widget::InitData& widgetInitData);
145 nsDocShell* GetDocShell() { return mDocShell; }
147 nsresult Toolbar();
149 // nsIWebProgressListener
150 NS_DECL_NSIWEBPROGRESSLISTENER
152 // nsIWidgetListener methods for WidgetListenerDelegate.
153 nsIAppWindow* GetAppWindow() { return this; }
154 mozilla::PresShell* GetPresShell();
155 MOZ_CAN_RUN_SCRIPT
156 bool WindowMoved(nsIWidget* aWidget, int32_t aX, int32_t aY);
157 MOZ_CAN_RUN_SCRIPT
158 bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight);
159 MOZ_CAN_RUN_SCRIPT bool RequestWindowClose(nsIWidget* aWidget);
160 MOZ_CAN_RUN_SCRIPT void SizeModeChanged(nsSizeMode aSizeMode);
161 MOZ_CAN_RUN_SCRIPT void UIResolutionChanged();
162 MOZ_CAN_RUN_SCRIPT void FullscreenWillChange(bool aInFullscreen);
163 MOZ_CAN_RUN_SCRIPT void FullscreenChanged(bool aInFullscreen);
164 MOZ_CAN_RUN_SCRIPT void MacFullscreenMenubarOverlapChanged(
165 mozilla::DesktopCoord aOverlapAmount);
166 MOZ_CAN_RUN_SCRIPT void OcclusionStateChanged(bool aIsFullyOccluded);
167 void RecomputeBrowsingContextVisibility();
168 MOZ_CAN_RUN_SCRIPT void OSToolbarButtonPressed();
169 MOZ_CAN_RUN_SCRIPT
170 bool ZLevelChanged(bool aImmediate, nsWindowZ* aPlacement,
171 nsIWidget* aRequestBelow, nsIWidget** aActualBelow);
172 MOZ_CAN_RUN_SCRIPT void WindowActivated();
173 MOZ_CAN_RUN_SCRIPT void WindowDeactivated();
175 explicit AppWindow(uint32_t aChromeFlags);
177 protected:
178 enum class PersistentAttribute : uint8_t {
179 Position,
180 Size,
181 Misc,
183 using PersistentAttributes = EnumSet<PersistentAttribute>;
185 static PersistentAttributes AllPersistentAttributes() {
186 return {PersistentAttribute::Position, PersistentAttribute::Size,
187 PersistentAttribute::Misc};
190 virtual ~AppWindow();
192 friend class mozilla::AppWindowTimerCallback;
194 MOZ_CAN_RUN_SCRIPT bool ExecuteCloseHandler();
195 void ConstrainToOpenerScreen(int32_t* aX, int32_t* aY);
197 void SetPersistenceTimer(uint32_t aDirtyFlags);
198 void FirePersistenceTimer();
200 NS_IMETHOD EnsureChromeTreeOwner();
201 NS_IMETHOD EnsureContentTreeOwner();
202 NS_IMETHOD EnsurePrimaryContentTreeOwner();
203 NS_IMETHOD EnsurePrompter();
204 NS_IMETHOD EnsureAuthPrompter();
205 NS_IMETHOD ForceRoundedDimensions();
206 NS_IMETHOD GetAvailScreenSize(int32_t* aAvailWidth, int32_t* aAvailHeight);
208 void FinishFullscreenChange(bool aInFullscreen);
210 void ApplyChromeFlags();
211 MOZ_CAN_RUN_SCRIPT_BOUNDARY void SizeShell();
212 void OnChromeLoaded();
213 void StaggerPosition(int32_t& aRequestedX, int32_t& aRequestedY,
214 int32_t aSpecWidth, int32_t aSpecHeight);
215 bool LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight);
216 bool LoadSizeFromXUL(int32_t& aSpecWidth, int32_t& aSpecHeight);
217 void SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight);
218 bool UpdateWindowStateFromMiscXULAttributes();
219 void SyncAttributesToWidget();
220 void SavePersistentAttributes(PersistentAttributes);
221 void MaybeSavePersistentPositionAndSize(PersistentAttributes,
222 dom::Element& aRootElement,
223 const nsAString& aPersistString,
224 bool aShouldPersist);
225 void MaybeSavePersistentMiscAttributes(PersistentAttributes,
226 dom::Element& aRootElement,
227 const nsAString& aPersistString,
228 bool aShouldPersist);
229 void SavePersistentAttributes() {
230 SavePersistentAttributes(mPersistentAttributesDirty);
233 bool NeedsTooltipListener();
234 void AddTooltipSupport();
235 void RemoveTooltipSupport();
237 NS_IMETHOD GetWindowDOMWindow(mozIDOMWindowProxy** aDOMWindow);
238 dom::Element* GetWindowDOMElement() const;
240 // See nsIDocShellTreeOwner for docs on next two methods
241 nsresult ContentShellAdded(nsIDocShellTreeItem* aContentShell, bool aPrimary);
242 nsresult ContentShellRemoved(nsIDocShellTreeItem* aContentShell);
243 NS_IMETHOD GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight);
244 NS_IMETHOD SetPrimaryContentSize(int32_t aWidth, int32_t aHeight);
245 nsresult GetRootShellSize(int32_t* aWidth, int32_t* aHeight);
246 nsresult SetRootShellSize(int32_t aWidth, int32_t aHeight);
248 NS_IMETHOD SizeShellTo(nsIDocShellTreeItem* aShellItem, int32_t aCX,
249 int32_t aCY);
250 NS_IMETHOD ExitModalLoop(nsresult aStatus);
251 NS_IMETHOD CreateNewChromeWindow(int32_t aChromeFlags,
252 nsIAppWindow** _retval);
253 NS_IMETHOD CreateNewContentWindow(int32_t aChromeFlags,
254 nsIOpenWindowInfo* aOpenWindowInfo,
255 nsIAppWindow** _retval);
256 NS_IMETHOD GetHasPrimaryContent(bool* aResult);
258 void EnableParent(bool aEnable);
259 bool ConstrainToZLevel(bool aImmediate, nsWindowZ* aPlacement,
260 nsIWidget* aReqBelow, nsIWidget** aActualBelow);
261 void PlaceWindowLayersBehind(uint32_t aLowLevel, uint32_t aHighLevel,
262 nsIAppWindow* aBehind);
263 void SetContentScrollbarVisibility(bool aVisible);
265 enum PersistentAttributeUpdate { Sync, Async };
266 void PersistentAttributesDirty(PersistentAttributes,
267 PersistentAttributeUpdate);
268 nsresult GetTabCount(uint32_t* aResult);
270 void LoadPersistentWindowState();
271 nsresult GetPersistentValue(const nsAtom* aAttr, nsAString& aValue);
272 nsresult SetPersistentValue(const nsAtom* aAttr, const nsAString& aValue);
274 // Saves window size and positioning values in order to display a very early
275 // skeleton UI. This has to happen before we can reasonably initialize the
276 // xulstore (i.e., before even loading libxul), so they have to use a special
277 // purpose store to do so.
278 nsresult MaybeSaveEarlyWindowPersistentValues(
279 const LayoutDeviceIntRect& aRect);
281 // Gets the uri spec and the window element ID for this window.
282 nsresult GetDocXulStoreKeys(nsString& aUriSpec, nsString& aWindowElementId);
284 // Enum for the current state of a fullscreen change.
286 // It is used to ensure that fullscreen change is issued after both
287 // the window state change and the window size change at best effort.
288 // This is needed because some platforms can't guarantee the order
289 // between such two events.
291 // It's changed in the following way:
292 // +---------------------------+--------------------------------------+
293 // | | |
294 // | v |
295 // | NotChanging |
296 // | + |
297 // | | FullscreenWillChange |
298 // | v |
299 // | +-----------+ WillChange +------------------+ |
300 // | | WindowResized FullscreenChanged | |
301 // | v v |
302 // | WidgetResized WidgetEnteredFullscreen |
303 // | + or WidgetExitedFullscreen |
304 // | | FullscreenChanged + |
305 // | v WindowResized or | |
306 // +--------+ delayed dispatch | |
307 // v |
308 // +-------------+
310 // The delayed dispatch serves as timeout, which is necessary because it's
311 // not even guaranteed that the widget will be resized at all.
312 enum class FullscreenChangeState : uint8_t {
313 // No current fullscreen change. Any previous change has finished.
314 NotChanging,
315 // Indicate there is going to be a fullscreen change.
316 WillChange,
317 // The widget has been resized since WillChange.
318 WidgetResized,
319 // The widget has entered fullscreen state since WillChange.
320 WidgetEnteredFullscreen,
321 // The widget has exited fullscreen state since WillChange.
322 WidgetExitedFullscreen,
325 nsChromeTreeOwner* mChromeTreeOwner;
326 nsContentTreeOwner* mContentTreeOwner;
327 nsContentTreeOwner* mPrimaryContentTreeOwner;
328 nsCOMPtr<nsIWidget> mWindow;
329 RefPtr<nsDocShell> mDocShell;
330 nsCOMPtr<nsPIDOMWindowOuter> mDOMWindow;
331 nsWeakPtr mParentWindow;
332 nsCOMPtr<nsIPrompt> mPrompter;
333 nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
334 nsCOMPtr<nsIXULBrowserWindow> mXULBrowserWindow;
335 nsCOMPtr<nsIDocShellTreeItem> mPrimaryContentShell;
336 nsresult mModalStatus;
337 FullscreenChangeState mFullscreenChangeState;
338 bool mContinueModalLoop;
339 bool mDebuting; // being made visible right now
340 bool mChromeLoaded; // True when chrome has loaded
341 bool mSizingShellFromXUL; // true when in SizeShell()
342 bool mShowAfterLoad;
343 bool mIntrinsicallySized;
344 bool mCenterAfterLoad;
345 bool mIsHiddenWindow;
346 bool mLockedUntilChromeLoad;
347 bool mIgnoreXULSize;
348 bool mIgnoreXULPosition;
349 bool mChromeFlagsFrozen;
350 bool mIgnoreXULSizeMode;
351 // mDestroying is used to prevent reentry into into Destroy(), which can
352 // otherwise happen due to script running as we tear down various things.
353 bool mDestroying;
354 bool mRegistered;
355 // Indicator for whether the client size, instead of the window size, should
356 // be maintained in case of a change in their relation.
357 bool mDominantClientSize;
358 PersistentAttributes mPersistentAttributesDirty;
359 PersistentAttributes mPersistentAttributesMask;
360 uint32_t mChromeFlags;
361 nsCOMPtr<nsIOpenWindowInfo> mInitialOpenWindowInfo;
362 nsString mTitle;
364 // The screen rect of the opener.
365 mozilla::DesktopIntRect mOpenerScreenRect;
367 nsCOMPtr<nsIRemoteTab> mPrimaryBrowserParent;
369 nsCOMPtr<nsITimer> mSPTimer;
370 WidgetListenerDelegate mWidgetListenerDelegate;
372 private:
373 MOZ_CAN_RUN_SCRIPT void IntrinsicallySizeShell(const CSSIntSize& aWindowDiff,
374 int32_t& aSpecWidth,
375 int32_t& aSpecHeight);
377 // GetPrimaryBrowserParentSize is called from xpidl methods and we don't have
378 // a good way to annotate those with MOZ_CAN_RUN_SCRIPT yet. It takes no
379 // refcounted args other than "this", and the "this" uses seem ok.
380 MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
381 GetPrimaryRemoteTabSize(int32_t* aWidth, int32_t* aHeight);
382 nsresult GetPrimaryContentShellSize(int32_t* aWidth, int32_t* aHeight);
383 nsresult SetPrimaryRemoteTabSize(int32_t aWidth, int32_t aHeight);
384 void SizeShellToWithLimit(int32_t aDesiredWidth, int32_t aDesiredHeight,
385 int32_t shellItemWidth, int32_t shellItemHeight);
386 nsresult MoveResize(const Maybe<LayoutDeviceIntPoint>& aPosition,
387 const Maybe<LayoutDeviceIntSize>& aSize, bool aRepaint);
388 nsresult MoveResize(const Maybe<DesktopPoint>& aPosition,
389 const Maybe<DesktopSize>& aSize, bool aRepaint);
390 nsCOMPtr<nsIXULStore> mLocalStore;
391 bool mIsWidgetInFullscreen = false;
394 NS_DEFINE_STATIC_IID_ACCESSOR(AppWindow, NS_APPWINDOW_IMPL_CID)
396 } // namespace mozilla
398 #endif /* mozilla_AppWindow_h__ */