Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / xpfe / appshell / AppWindow.h
blob4b26456ce45df93886a9eb38d0448860e739484c
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/Mutex.h"
25 // Interfaces needed
26 #include "nsIBaseWindow.h"
27 #include "nsIDocShellTreeItem.h"
28 #include "nsIInterfaceRequestor.h"
29 #include "nsIInterfaceRequestorUtils.h"
30 #include "nsIAppWindow.h"
31 #include "nsIPrompt.h"
32 #include "nsIAuthPrompt.h"
33 #include "nsIXULBrowserWindow.h"
34 #include "nsIWidgetListener.h"
35 #include "nsIRemoteTab.h"
36 #include "nsIWebProgressListener.h"
37 #include "nsITimer.h"
39 #ifndef MOZ_NEW_XULSTORE
40 # include "nsIXULStore.h"
41 #endif
43 namespace mozilla {
44 namespace dom {
45 class Element;
46 } // namespace dom
47 } // namespace mozilla
49 class nsAtom;
50 class nsXULTooltipListener;
51 struct nsWidgetInitData;
53 namespace mozilla {
54 class PresShell;
55 class AppWindowTimerCallback;
56 class L10nReadyPromiseHandler;
57 } // namespace mozilla
59 // AppWindow
61 #define NS_APPWINDOW_IMPL_CID \
62 { /* 8eaec2f3-ed02-4be2-8e0f-342798477298 */ \
63 0x8eaec2f3, 0xed02, 0x4be2, { \
64 0x8e, 0x0f, 0x34, 0x27, 0x98, 0x47, 0x72, 0x98 \
65 } \
68 class nsContentShellInfo;
70 namespace mozilla {
72 class AppWindow final : public nsIBaseWindow,
73 public nsIInterfaceRequestor,
74 public nsIAppWindow,
75 public nsSupportsWeakReference,
76 public nsIWebProgressListener {
77 friend class ::nsChromeTreeOwner;
78 friend class ::nsContentTreeOwner;
80 public:
81 // The implementation of non-refcounted nsIWidgetListener, which would hold a
82 // strong reference on stack before calling AppWindow's
83 // MOZ_CAN_RUN_SCRIPT methods.
84 class WidgetListenerDelegate : public nsIWidgetListener {
85 public:
86 explicit WidgetListenerDelegate(AppWindow* aAppWindow)
87 : mAppWindow(aAppWindow) {}
89 MOZ_CAN_RUN_SCRIPT_BOUNDARY
90 virtual nsIAppWindow* GetAppWindow() override;
91 MOZ_CAN_RUN_SCRIPT_BOUNDARY
92 virtual mozilla::PresShell* GetPresShell() override;
93 MOZ_CAN_RUN_SCRIPT_BOUNDARY
94 virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) override;
95 MOZ_CAN_RUN_SCRIPT_BOUNDARY
96 virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth,
97 int32_t aHeight) override;
98 MOZ_CAN_RUN_SCRIPT_BOUNDARY
99 virtual bool RequestWindowClose(nsIWidget* aWidget) override;
100 MOZ_CAN_RUN_SCRIPT_BOUNDARY
101 virtual void SizeModeChanged(nsSizeMode sizeMode) override;
102 MOZ_CAN_RUN_SCRIPT_BOUNDARY
103 virtual void UIResolutionChanged() override;
104 MOZ_CAN_RUN_SCRIPT_BOUNDARY
105 virtual void FullscreenWillChange(bool aInFullscreen) override;
106 MOZ_CAN_RUN_SCRIPT_BOUNDARY
107 virtual void FullscreenChanged(bool aInFullscreen) override;
108 MOZ_CAN_RUN_SCRIPT_BOUNDARY
109 virtual void MacFullscreenMenubarOverlapChanged(
110 mozilla::DesktopCoord aOverlapAmount) override;
111 MOZ_CAN_RUN_SCRIPT_BOUNDARY
112 virtual void OcclusionStateChanged(bool aIsFullyOccluded) override;
113 MOZ_CAN_RUN_SCRIPT_BOUNDARY
114 virtual void OSToolbarButtonPressed() override;
115 MOZ_CAN_RUN_SCRIPT_BOUNDARY
116 virtual bool ZLevelChanged(bool aImmediate, nsWindowZ* aPlacement,
117 nsIWidget* aRequestBelow,
118 nsIWidget** aActualBelow) override;
119 MOZ_CAN_RUN_SCRIPT_BOUNDARY
120 virtual void WindowActivated() override;
121 MOZ_CAN_RUN_SCRIPT_BOUNDARY
122 virtual void WindowDeactivated() override;
124 private:
125 // The lifetime of WidgetListenerDelegate is bound to AppWindow so
126 // we just use a raw pointer here.
127 AppWindow* mAppWindow;
130 NS_DECL_THREADSAFE_ISUPPORTS
132 NS_DECL_NSIINTERFACEREQUESTOR
133 NS_DECL_NSIAPPWINDOW
134 NS_DECL_NSIBASEWINDOW
136 NS_DECLARE_STATIC_IID_ACCESSOR(NS_APPWINDOW_IMPL_CID)
138 void LockUntilChromeLoad() { mLockedUntilChromeLoad = true; }
139 bool IsLocked() const { return mLockedUntilChromeLoad; }
140 void IgnoreXULSizeMode(bool aEnable) { mIgnoreXULSizeMode = aEnable; }
141 void WasRegistered() { mRegistered = true; }
143 // AppWindow methods...
144 nsresult Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
145 int32_t aInitialWidth, int32_t aInitialHeight,
146 bool aIsHiddenWindow, nsWidgetInitData& widgetInitData);
148 nsDocShell* GetDocShell() { return mDocShell; }
150 nsresult Toolbar();
152 // nsIWebProgressListener
153 NS_DECL_NSIWEBPROGRESSLISTENER
155 // nsIWidgetListener methods for WidgetListenerDelegate.
156 nsIAppWindow* GetAppWindow() { return this; }
157 mozilla::PresShell* GetPresShell();
158 MOZ_CAN_RUN_SCRIPT
159 bool WindowMoved(nsIWidget* aWidget, int32_t aX, int32_t aY);
160 MOZ_CAN_RUN_SCRIPT
161 bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight);
162 MOZ_CAN_RUN_SCRIPT bool RequestWindowClose(nsIWidget* aWidget);
163 MOZ_CAN_RUN_SCRIPT void SizeModeChanged(nsSizeMode aSizeMode);
164 MOZ_CAN_RUN_SCRIPT void UIResolutionChanged();
165 MOZ_CAN_RUN_SCRIPT void FullscreenWillChange(bool aInFullscreen);
166 MOZ_CAN_RUN_SCRIPT void FullscreenChanged(bool aInFullscreen);
167 MOZ_CAN_RUN_SCRIPT void MacFullscreenMenubarOverlapChanged(
168 mozilla::DesktopCoord aOverlapAmount);
169 MOZ_CAN_RUN_SCRIPT void OcclusionStateChanged(bool aIsFullyOccluded);
170 MOZ_CAN_RUN_SCRIPT void OSToolbarButtonPressed();
171 MOZ_CAN_RUN_SCRIPT
172 bool ZLevelChanged(bool aImmediate, nsWindowZ* aPlacement,
173 nsIWidget* aRequestBelow, nsIWidget** aActualBelow);
174 MOZ_CAN_RUN_SCRIPT void WindowActivated();
175 MOZ_CAN_RUN_SCRIPT void WindowDeactivated();
177 explicit AppWindow(uint32_t aChromeFlags);
179 protected:
180 enum persistentAttributes {
181 PAD_MISC = 0x1,
182 PAD_POSITION = 0x2,
183 PAD_SIZE = 0x4
186 virtual ~AppWindow();
188 friend class mozilla::AppWindowTimerCallback;
190 bool ExecuteCloseHandler();
191 void ConstrainToOpenerScreen(int32_t* aX, int32_t* aY);
193 void SetPersistenceTimer(uint32_t aDirtyFlags);
194 void FirePersistenceTimer();
196 NS_IMETHOD EnsureChromeTreeOwner();
197 NS_IMETHOD EnsureContentTreeOwner();
198 NS_IMETHOD EnsurePrimaryContentTreeOwner();
199 NS_IMETHOD EnsurePrompter();
200 NS_IMETHOD EnsureAuthPrompter();
201 NS_IMETHOD ForceRoundedDimensions();
202 NS_IMETHOD GetAvailScreenSize(int32_t* aAvailWidth, int32_t* aAvailHeight);
204 void FinishFullscreenChange(bool aInFullscreen);
206 void ApplyChromeFlags();
207 MOZ_CAN_RUN_SCRIPT_BOUNDARY void SizeShell();
208 void OnChromeLoaded();
209 void StaggerPosition(int32_t& aRequestedX, int32_t& aRequestedY,
210 int32_t aSpecWidth, int32_t aSpecHeight);
211 bool LoadPositionFromXUL(int32_t aSpecWidth, int32_t aSpecHeight);
212 bool LoadSizeFromXUL(int32_t& aSpecWidth, int32_t& aSpecHeight);
213 void SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight);
214 bool UpdateWindowStateFromMiscXULAttributes();
215 void SyncAttributesToWidget();
216 NS_IMETHOD SavePersistentAttributes();
218 bool NeedsTooltipListener();
219 void AddTooltipSupport();
220 void RemoveTooltipSupport();
222 NS_IMETHOD GetWindowDOMWindow(mozIDOMWindowProxy** aDOMWindow);
223 dom::Element* GetWindowDOMElement() const;
225 // See nsIDocShellTreeOwner for docs on next two methods
226 nsresult ContentShellAdded(nsIDocShellTreeItem* aContentShell, bool aPrimary);
227 nsresult ContentShellRemoved(nsIDocShellTreeItem* aContentShell);
228 NS_IMETHOD GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight);
229 NS_IMETHOD SetPrimaryContentSize(int32_t aWidth, int32_t aHeight);
230 nsresult GetRootShellSize(int32_t* aWidth, int32_t* aHeight);
231 nsresult SetRootShellSize(int32_t aWidth, int32_t aHeight);
233 NS_IMETHOD SizeShellTo(nsIDocShellTreeItem* aShellItem, int32_t aCX,
234 int32_t aCY);
235 NS_IMETHOD ExitModalLoop(nsresult aStatus);
236 NS_IMETHOD CreateNewChromeWindow(int32_t aChromeFlags,
237 nsIAppWindow** _retval);
238 NS_IMETHOD CreateNewContentWindow(int32_t aChromeFlags,
239 nsIOpenWindowInfo* aOpenWindowInfo,
240 nsIAppWindow** _retval);
241 NS_IMETHOD GetHasPrimaryContent(bool* aResult);
243 void EnableParent(bool aEnable);
244 bool ConstrainToZLevel(bool aImmediate, nsWindowZ* aPlacement,
245 nsIWidget* aReqBelow, nsIWidget** aActualBelow);
246 void PlaceWindowLayersBehind(uint32_t aLowLevel, uint32_t aHighLevel,
247 nsIAppWindow* aBehind);
248 void SetContentScrollbarVisibility(bool aVisible);
249 void PersistentAttributesDirty(uint32_t aDirtyFlags);
250 nsresult GetTabCount(uint32_t* aResult);
252 void LoadPersistentWindowState();
253 nsresult GetPersistentValue(const nsAtom* aAttr, nsAString& aValue);
254 nsresult SetPersistentValue(const nsAtom* aAttr, const nsAString& aValue);
256 // Saves window size and positioning values in order to display a very early
257 // skeleton UI. This has to happen before we can reasonably initialize the
258 // xulstore (i.e., before even loading libxul), so they have to use a special
259 // purpose store to do so.
260 nsresult MaybeSaveEarlyWindowPersistentValues(
261 const LayoutDeviceIntRect& aRect);
263 // Gets the uri spec and the window element ID for this window.
264 nsresult GetDocXulStoreKeys(nsString& aUriSpec, nsString& aWindowElementId);
266 // Enum for the current state of a fullscreen change.
268 // It is used to ensure that fullscreen change is issued after both
269 // the window state change and the window size change at best effort.
270 // This is needed because some platforms can't guarantee the order
271 // between such two events.
273 // It's changed in the following way:
274 // +---------------------------+--------------------------------------+
275 // | | |
276 // | v |
277 // | NotChanging |
278 // | + |
279 // | | FullscreenWillChange |
280 // | v |
281 // | +-----------+ WillChange +------------------+ |
282 // | | WindowResized FullscreenChanged | |
283 // | v v |
284 // | WidgetResized WidgetEnteredFullscreen |
285 // | + or WidgetExitedFullscreen |
286 // | | FullscreenChanged + |
287 // | v WindowResized or | |
288 // +--------+ delayed dispatch | |
289 // v |
290 // +-------------+
292 // The delayed dispatch serves as timeout, which is necessary because it's
293 // not even guaranteed that the widget will be resized at all.
294 enum class FullscreenChangeState : uint8_t {
295 // No current fullscreen change. Any previous change has finished.
296 NotChanging,
297 // Indicate there is going to be a fullscreen change.
298 WillChange,
299 // The widget has been resized since WillChange.
300 WidgetResized,
301 // The widget has entered fullscreen state since WillChange.
302 WidgetEnteredFullscreen,
303 // The widget has exited fullscreen state since WillChange.
304 WidgetExitedFullscreen,
307 nsChromeTreeOwner* mChromeTreeOwner;
308 nsContentTreeOwner* mContentTreeOwner;
309 nsContentTreeOwner* mPrimaryContentTreeOwner;
310 nsCOMPtr<nsIWidget> mWindow;
311 RefPtr<nsDocShell> mDocShell;
312 nsCOMPtr<nsPIDOMWindowOuter> mDOMWindow;
313 nsWeakPtr mParentWindow;
314 nsCOMPtr<nsIPrompt> mPrompter;
315 nsCOMPtr<nsIAuthPrompt> mAuthPrompter;
316 nsCOMPtr<nsIXULBrowserWindow> mXULBrowserWindow;
317 nsCOMPtr<nsIDocShellTreeItem> mPrimaryContentShell;
318 nsresult mModalStatus;
319 FullscreenChangeState mFullscreenChangeState;
320 bool mContinueModalLoop;
321 bool mDebuting; // being made visible right now
322 bool mChromeLoaded; // True when chrome has loaded
323 bool mSizingShellFromXUL; // true when in SizeShell()
324 bool mShowAfterLoad;
325 bool mIntrinsicallySized;
326 bool mCenterAfterLoad;
327 bool mIsHiddenWindow;
328 bool mLockedUntilChromeLoad;
329 bool mIgnoreXULSize;
330 bool mIgnoreXULPosition;
331 bool mChromeFlagsFrozen;
332 bool mIgnoreXULSizeMode;
333 // mDestroying is used to prevent reentry into into Destroy(), which can
334 // otherwise happen due to script running as we tear down various things.
335 bool mDestroying;
336 bool mRegistered;
337 uint32_t mPersistentAttributesDirty; // persistentAttributes
338 uint32_t mPersistentAttributesMask;
339 uint32_t mChromeFlags;
340 nsCOMPtr<nsIOpenWindowInfo> mInitialOpenWindowInfo;
341 nsString mTitle;
342 nsIntRect mOpenerScreenRect; // the screen rect of the opener
344 nsCOMPtr<nsIRemoteTab> mPrimaryBrowserParent;
346 nsCOMPtr<nsITimer> mSPTimer;
347 mozilla::Mutex mSPTimerLock;
348 WidgetListenerDelegate mWidgetListenerDelegate;
350 private:
351 // GetPrimaryBrowserParentSize is called from xpidl methods and we don't have
352 // a good way to annotate those with MOZ_CAN_RUN_SCRIPT yet. It takes no
353 // refcounted args other than "this", and the "this" uses seem ok.
354 MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult
355 GetPrimaryRemoteTabSize(int32_t* aWidth, int32_t* aHeight);
356 nsresult GetPrimaryContentShellSize(int32_t* aWidth, int32_t* aHeight);
357 nsresult SetPrimaryRemoteTabSize(int32_t aWidth, int32_t aHeight);
358 #ifndef MOZ_NEW_XULSTORE
359 nsCOMPtr<nsIXULStore> mLocalStore;
360 #endif
363 NS_DEFINE_STATIC_IID_ACCESSOR(AppWindow, NS_APPWINDOW_IMPL_CID)
365 } // namespace mozilla
367 #endif /* mozilla_AppWindow_h__ */