1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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#include "nsISupports.idl"
7#include "nsISimpleEnumerator.idl"
8
9%{C++
10#define NS_WINDOWMEDIATOR_CID \
11{ 0x79a2b7cc, 0xf05b, 0x4605, \
12  { 0xbf, 0xa0, 0xfa, 0xc5, 0x4f, 0x27, 0xee, 0xc8 } }
13
14#define NS_WINDOWMEDIATOR_CONTRACTID \
15  "@mozilla.org/appshell/window-mediator;1"
16%}
17
18interface mozIDOMWindow;
19interface mozIDOMWindowProxy;
20interface nsIXULWindow;
21interface nsIWidget;
22interface nsIWindowMediatorListener;
23
24[scriptable, uuid(df0da056-357d-427f-bafd-e6cbf19c9381)]
25interface nsIWindowMediator: nsISupports
26{
27  /** Return an enumerator which iterates over all windows of type aWindowType
28    * from the oldest window to the youngest.
29    * @param  aWindowType the returned enumerator will enumerate only
30    *                     windows of this type. ("type" is the
31    *                     |windowtype| attribute of the XML <window> element.)
32    *                     If null, all windows will be enumerated.
33    * @return an enumerator of nsIDOMWindows.  Note that windows close
34    *         asynchronously in many cases, so windows returned from this
35    *         enumerator can have .closed set to true.  Caveat enumerator!
36    */
37  nsISimpleEnumerator getEnumerator(in wstring aWindowType);
38
39  /** Identical to getEnumerator except:
40    * @return an enumerator of nsIXULWindows
41  */
42  nsISimpleEnumerator getXULWindowEnumerator(in wstring aWindowType);
43
44  /** Return an enumerator which iterates over all windows of type aWindowType
45    * in their z (front-to-back) order. Note this interface makes
46    * no requirement that a window couldn't be revisited if windows
47    * are re-ordered while z-order enumerators are active.
48    * @param  aWindowType the returned enumerator will enumerate only
49    *                     windows of this type. ("type" is the
50    *                     |windowtype| attribute of the XML <window> element.)
51    *                     If null, all windows will be enumerated.
52    * @param  aFrontToBack if true, the enumerator enumerates windows in order
53    *                      from front to back. back to front if false.
54    * @return an enumerator of nsIDOMWindows
55    */
56  nsISimpleEnumerator getZOrderDOMWindowEnumerator(in wstring aWindowType,
57                        in boolean aFrontToBack);
58
59  /** Identical to getZOrderDOMWindowEnumerator except:
60    * @return an enumerator of nsIXULWindows
61    */
62  nsISimpleEnumerator getZOrderXULWindowEnumerator(in wstring aWindowType,
63                        in boolean aFrontToBack);
64
65  /** This is a shortcut for simply fetching the first window in
66    * front to back order.
67    * @param  aWindowType return the topmost window of this type.
68    *                     ("type" is the |windowtype| attribute of
69    *                     the XML <window> element.)
70    *                     If null, return the topmost window of any type.
71    * @return the topmost window
72    */
73  mozIDOMWindowProxy getMostRecentWindow(in wstring aWindowType);
74
75  /**
76   * Return the outer window with the given ID, if any.  Can return null.
77   */
78  mozIDOMWindowProxy getOuterWindowWithId(in unsigned long long aOuterWindowID);
79
80  /**
81    * Return the inner window with the given current window ID, if any.
82    * Can return null if no inner window with the ID exists or if it's not
83    * a current inner anymore.
84    */
85  mozIDOMWindow getCurrentInnerWindowWithId(in unsigned long long aInnerWindowID);
86
87  /** Add the window to the list of known windows. Listeners (see
88    * addListener) will be notified through their onOpenWindow method.
89    * @param aWindow the window to add
90    */
91  [noscript] void registerWindow(in nsIXULWindow aWindow);
92
93  /** Remove the window from the list of known windows. Listeners (see
94    * addListener) will be be notified through their onCloseWindow method.
95    * @param aWindow the window to remove
96    */
97  [noscript] void unregisterWindow(in nsIXULWindow aWindow);
98
99  /** Call this method when a window gains focus. It's a primitive means of
100    * determining the most recent window. It's no longer necessary and it
101    * really should be removed.
102    * @param aWindow the window which has gained focus
103    */
104  [noscript] void updateWindowTimeStamp(in nsIXULWindow aWindow);
105
106  /* z-ordering: */
107
108  const unsigned long zLevelTop    = 1;
109  const unsigned long zLevelBottom = 2;
110  const unsigned long zLevelBelow  = 3; // below some window
111
112  /** A window wants to be moved in z-order. Calculate whether and how
113    * it should be constrained. Note this method is advisory only:
114    * it changes nothing either in WindowMediator's internal state
115    * or with the window.
116    * Note it compares the nsIXULWindow to nsIWidgets. A pure interface
117    * would use all nsIXULWindows. But we expect this to be called from
118    * callbacks originating in native window code. They are expected to
119    * hand us comparison values which are pulled from general storage
120    * in the native widget, and may not correspond to an nsIWidget at all.
121    * For that reason this interface requires only objects one step
122    * removed from the native window (nsIWidgets), and its implementation
123    * must be very understanding of what may be completely invalid
124    * pointers in those parameters.
125    *
126    * @param inWindow the window in question
127    * @param inPosition requested position
128    *                   values: zLevelTop: topmost window. zLevelBottom: bottom.
129    *                   zLevelBelow: below ioBelow. (the value of ioBelow will
130    *                   be ignored for zLevelTop and Bottom.)
131    * @param inBelow if inPosition==zLevelBelow, the window
132    *                 below which inWindow wants to be placed. Otherwise this
133    *                 variable is ignored.
134    * @param outPosition constrained position, values like inPosition.
135    * @param outBelow if outPosition==zLevelBelow, the window
136    *                 below which inWindow should be placed. Otherwise this
137    *                 this value will be null.
138    * @return PR_TRUE if the position returned is different from
139    *         the position given.
140    */
141
142  [noscript] boolean calculateZPosition(in nsIXULWindow   inWindow,
143                                        in unsigned long  inPosition,
144                                        in nsIWidget      inBelow,
145                                        out unsigned long outPosition,
146                                        out nsIWidget     outBelow);
147
148  /** A window has been positioned behind another. Inform WindowMediator
149    * @param inWindow the window in question
150    * @param inPosition new position. values:
151    *                   zLevelTop: topmost window.
152    *                   zLevelBottom: bottom.
153    *                   zLevelBelow: below inBelow. (inBelow is ignored
154    *                                for other values of inPosition.)
155    * @param inBelow the window inWindow is behind, if zLevelBelow
156    */
157  [noscript] void setZPosition(in nsIXULWindow inWindow,
158                               in unsigned long inPosition,
159                               in nsIXULWindow inBelow);
160
161  /** Return the window's Z level (as defined in nsIXULWindow).
162    * @param aWindow the window in question
163    * @return aWindow's z level
164    */
165  [noscript] uint32_t getZLevel(in nsIXULWindow aWindow);
166
167  /** Set the window's Z level (as defined in nsIXULWindow). The implementation
168    * will reposition the window as necessary to match its new Z level.
169    * The implementation will assume a window's Z level to be
170    * nsIXULWindow::normalZ until it has been informed of a different level.
171    * @param aWindow the window in question
172    * @param aZLevel the window's new Z level
173    */
174  [noscript] void setZLevel(in nsIXULWindow aWindow, in uint32_t aZLevel);
175
176  /** Register a listener for window status changes.
177    * keeps strong ref? (to be decided)
178    * @param aListener the listener to register
179    */
180  void addListener(in nsIWindowMediatorListener aListener);
181
182  /** Unregister a listener of window status changes.
183    * @param aListener the listener to unregister
184    */
185  void removeListener(in nsIWindowMediatorListener aListener);
186};
187
188// XXXcatalinb: This should be merged to nsIWindowMediator. Using this
189// to avoid UUID change in aurora.
190[scriptable, uuid(b9ed4063-39a2-4302-8e5c-7287eef021fe)]
191interface nsIWindowMediator_44 : nsIWindowMediator
192{
193  /**
194   * Same as getMostRecentWindow, but ignores private browsing
195   * windows.
196   */
197  mozIDOMWindowProxy getMostRecentNonPBWindow(in wstring aWindowType);
198};
199