1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #ifndef nsIViewManager_h___
39 : #define nsIViewManager_h___
40 :
41 : #include "nscore.h"
42 : #include "nsIView.h"
43 : #include "nsEvent.h"
44 :
45 : class nsIWidget;
46 : struct nsRect;
47 : class nsRegion;
48 : class nsDeviceContext;
49 :
50 : #define NS_IVIEWMANAGER_IID \
51 : { 0x540610a6, 0x4fdd, 0x4ae3, \
52 : { 0x9b, 0xdb, 0xa6, 0x4d, 0x8b, 0xca, 0x02, 0x0f } }
53 :
54 : class nsIViewManager : public nsISupports
55 0 : {
56 : public:
57 :
58 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IVIEWMANAGER_IID)
59 : /**
60 : * Initialize the ViewManager
61 : * Note: this instance does not hold a reference to the presshell
62 : * because it holds a reference to this instance.
63 : * @result The result of the initialization, NS_OK if no errors
64 : */
65 : NS_IMETHOD Init(nsDeviceContext* aContext) = 0;
66 :
67 : /**
68 : * Create an ordinary view
69 : * @param aBounds initial bounds for view
70 : * XXX We should eliminate this parameter; you can set the bounds after CreateView
71 : * @param aParent intended parent for view. this is not actually set in the
72 : * nsIView through this method. it is only used by the initialization
73 : * code to walk up the view tree, if necessary, to find resources.
74 : * XXX We should eliminate this parameter!
75 : * @param aVisibilityFlag initial visibility state of view
76 : * XXX We should eliminate this parameter; you can set it after CreateView
77 : * @result The new view
78 : */
79 : NS_IMETHOD_(nsIView*) CreateView(const nsRect& aBounds,
80 : const nsIView* aParent,
81 : nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow) = 0;
82 :
83 : /**
84 : * Get the root of the view tree.
85 : * @result the root view
86 : */
87 : NS_IMETHOD_(nsIView*) GetRootView() = 0;
88 :
89 : /**
90 : * Set the root of the view tree. Does not destroy the current root view.
91 : * aView may have a parent view managed by a different view manager.
92 : * aView may have a widget (anything but printing) or may not (printing).
93 : * @param aView view to set as root
94 : */
95 : NS_IMETHOD SetRootView(nsIView *aView) = 0;
96 :
97 : /**
98 : * Get the dimensions of the root window. The dimensions are in
99 : * twips
100 : * @param aWidth out parameter for width of window in twips
101 : * @param aHeight out parameter for height of window in twips
102 : */
103 : NS_IMETHOD GetWindowDimensions(nscoord *aWidth, nscoord *aHeight) = 0;
104 :
105 : /**
106 : * Set the dimensions of the root window.
107 : * Called if the root window is resized. The dimensions are in
108 : * twips
109 : * @param aWidth of window in twips
110 : * @param aHeight of window in twips
111 : */
112 : NS_IMETHOD SetWindowDimensions(nscoord aWidth, nscoord aHeight) = 0;
113 :
114 : /**
115 : * Do any resizes that are pending.
116 : */
117 : NS_IMETHOD FlushDelayedResize(bool aDoReflow) = 0;
118 :
119 : /**
120 : * Called to inform the view manager that the entire area of a view
121 : * is dirty and needs to be redrawn.
122 : * @param aView view to paint. should be root view
123 : */
124 : NS_IMETHOD InvalidateView(nsIView *aView) = 0;
125 :
126 : /**
127 : * Called to inform the view manager that some portion of a view is dirty and
128 : * needs to be redrawn. The rect passed in should be in the view's coordinate
129 : * space. Does not check for paint suppression.
130 : * @param aView view to paint. should be root view
131 : * @param rect rect to mark as damaged
132 : */
133 : NS_IMETHOD InvalidateViewNoSuppression(nsIView *aView, const nsRect &aRect) = 0;
134 :
135 : /**
136 : * Called to inform the view manager that it should invalidate all views.
137 : */
138 : NS_IMETHOD InvalidateAllViews() = 0;
139 :
140 : /**
141 : * Called to dispatch an event to the appropriate view. Often called
142 : * as a result of receiving a mouse or keyboard event from the widget
143 : * event system.
144 : * @param aEvent event to dispatch
145 : * @param aViewTarget dispatch the event to this view
146 : * @param aStatus event handling status
147 : */
148 : NS_IMETHOD DispatchEvent(nsGUIEvent *aEvent,
149 : nsIView* aViewTarget, nsEventStatus* aStatus) = 0;
150 :
151 : /**
152 : * Given a parent view, insert another view as its child.
153 : * aSibling and aAbove control the "document order" for the insertion.
154 : * If aSibling is null, the view is inserted at the end of the document order
155 : * if aAfter is true, otherwise it is inserted at the beginning.
156 : * If aSibling is non-null, then if aAfter is true, the view is inserted
157 : * after the sibling in document order (appearing above the sibling unless
158 : * overriden by z-order).
159 : * If it is false, the view is inserted before the sibling.
160 : * The view manager generates the appopriate dirty regions.
161 : * @param aParent parent view
162 : * @param aChild child view
163 : * @param aSibling sibling view
164 : * @param aAfter after or before in the document order
165 : */
166 : NS_IMETHOD InsertChild(nsIView *aParent, nsIView *aChild, nsIView *aSibling,
167 : bool aAfter) = 0;
168 :
169 : /**
170 : * Remove a specific child view from its parent. This will NOT remove its placeholder
171 : * if there is one.
172 : * The view manager generates the appropriate dirty regions.
173 : * @param aParent parent view
174 : * @param aChild child view
175 : */
176 : NS_IMETHOD RemoveChild(nsIView *aChild) = 0;
177 :
178 : /**
179 : * Move a view to the specified position, provided in parent coordinates.
180 : * The new position is the (0, 0) origin for the view's coordinate system.
181 : * The view's bounds may extend above or to the left of this point.
182 : * The view manager generates the appropriate dirty regions.
183 : * @param aView view to move
184 : * @param aX x value for new view position
185 : * @param aY y value for new view position
186 : */
187 : NS_IMETHOD MoveViewTo(nsIView *aView, nscoord aX, nscoord aY) = 0;
188 :
189 : /**
190 : * Resize a view. In addition to setting the width and height, you can
191 : * set the x and y of its bounds relative to its position. Negative x and y
192 : * will let the view extend above and to the left of the (0,0) point in its
193 : * coordinate system.
194 : * The view manager generates the appropriate dirty regions.
195 : * @param aView view to move
196 : * @param the new bounds relative to the current position
197 : * @param RepaintExposedAreaOnly
198 : * if true Repaint only the expanded or contracted region,
199 : * if false Repaint the union of the old and new rectangles.
200 : */
201 : NS_IMETHOD ResizeView(nsIView *aView, const nsRect &aRect,
202 : bool aRepaintExposedAreaOnly = false) = 0;
203 :
204 : /**
205 : * Set the visibility of a view. Hidden views have the effect of hiding
206 : * their descendants as well. This does not affect painting, so layout
207 : * is responsible for ensuring that content in hidden views is not
208 : * painted nor handling events. It does affect the visibility of widgets;
209 : * if a view is hidden, descendant views with widgets have their widgets
210 : * hidden.
211 : * The view manager generates the appropriate dirty regions.
212 : * @param aView view to change visibility state of
213 : * @param visible new visibility state
214 : */
215 : NS_IMETHOD SetViewVisibility(nsIView *aView, nsViewVisibility aVisible) = 0;
216 :
217 : /**
218 : * Set the z-index of a view. Positive z-indices mean that a view
219 : * is above its parent in z-order. Negative z-indices mean that a
220 : * view is below its parent.
221 : * The view manager generates the appropriate dirty regions.
222 : * @param aAutoZIndex indicate that the z-index of a view is "auto". An "auto" z-index
223 : * means that the view does not define a new stacking context,
224 : * which means that the z-indicies of the view's children are
225 : * relative to the view's siblings.
226 : * @param aView view to change z depth of
227 : * @param aZindex explicit z depth
228 : * @param aTopMost used when this view is z-index:auto to compare against
229 : * other z-index:auto views.
230 : * true if the view should be topmost when compared with
231 : * other z-index:auto views.
232 : */
233 : NS_IMETHOD SetViewZIndex(nsIView *aView, bool aAutoZIndex, PRInt32 aZindex, bool aTopMost = false) = 0;
234 :
235 : /**
236 : * Set whether the view "floats" above all other views,
237 : * which tells the compositor not to consider higher views in
238 : * the view hierarchy that would geometrically intersect with
239 : * this view. This is a hack, but it fixes some problems with
240 : * views that need to be drawn in front of all other views.
241 : */
242 : NS_IMETHOD SetViewFloating(nsIView *aView, bool aFloatingView) = 0;
243 :
244 : /**
245 : * Set the presshell associated with this manager
246 : * @param aPresShell - new presshell
247 : */
248 : virtual void SetPresShell(nsIPresShell *aPresShell) = 0;
249 :
250 : /**
251 : * Get the pres shell associated with this manager
252 : */
253 : virtual nsIPresShell* GetPresShell() = 0;
254 :
255 : /**
256 : * Get the device context associated with this manager
257 : * @result device context
258 : */
259 : NS_IMETHOD GetDeviceContext(nsDeviceContext *&aContext) = 0;
260 :
261 : /**
262 : * A stack class for disallowing changes that would enter painting. For
263 : * example, popup widgets shouldn't be resized during reflow, since doing so
264 : * might cause synchronous painting inside reflow which is forbidden.
265 : * While refresh is disabled, widget geometry changes are deferred and will
266 : * be handled later, either from the refresh driver or from an NS_WILL_PAINT
267 : * event.
268 : * We don't want to defer widget geometry changes all the time. Resizing a
269 : * popup from script doesn't need to be deferred, for example, especially
270 : * since popup widget geometry is observable from script and expected to
271 : * update synchronously.
272 : */
273 : class NS_STACK_CLASS AutoDisableRefresh {
274 : public:
275 0 : AutoDisableRefresh(nsIViewManager* aVM) {
276 0 : if (aVM) {
277 0 : mRootVM = aVM->IncrementDisableRefreshCount();
278 : }
279 0 : }
280 0 : ~AutoDisableRefresh() {
281 0 : if (mRootVM) {
282 0 : mRootVM->DecrementDisableRefreshCount();
283 : }
284 0 : }
285 : private:
286 : AutoDisableRefresh(const AutoDisableRefresh& aOther);
287 : const AutoDisableRefresh& operator=(const AutoDisableRefresh& aOther);
288 :
289 : nsCOMPtr<nsIViewManager> mRootVM;
290 : };
291 :
292 : private:
293 : friend class AutoDisableRefresh;
294 :
295 : virtual nsIViewManager* IncrementDisableRefreshCount() = 0;
296 : virtual void DecrementDisableRefreshCount() = 0;
297 :
298 : public:
299 : /**
300 : * Retrieve the widget at the root of the nearest enclosing
301 : * view manager whose root view has a widget.
302 : */
303 : NS_IMETHOD GetRootWidget(nsIWidget **aWidget) = 0;
304 :
305 : /**
306 : * Indicate whether the viewmanager is currently painting
307 : *
308 : * @param aPainting true if the viewmanager is painting
309 : * false otherwise
310 : */
311 : NS_IMETHOD IsPainting(bool& aIsPainting)=0;
312 :
313 : /**
314 : * Retrieve the time of the last user event. User events
315 : * include mouse and keyboard events. The viewmanager
316 : * saves the time of the last user event.
317 : *
318 : * @param aTime Last user event time in microseconds
319 : */
320 : NS_IMETHOD GetLastUserEventTime(PRUint32& aTime)=0;
321 :
322 : /**
323 : * Find the nearest display root view for the view aView. This is the view for
324 : * the nearest enclosing popup or the root view for the root document.
325 : */
326 : static nsIView* GetDisplayRootFor(nsIView* aView);
327 :
328 : /**
329 : * Flush the accumulated dirty region to the widget and update widget
330 : * geometry.
331 : */
332 : virtual void ProcessPendingUpdates()=0;
333 :
334 : /**
335 : * Just update widget geometry without flushing the dirty region
336 : */
337 : virtual void UpdateWidgetGeometry() = 0;
338 : };
339 :
340 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIViewManager, NS_IVIEWMANAGER_IID)
341 :
342 : #endif // nsIViewManager_h___
|