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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsIViewManager_h___
39 #define nsIViewManager_h___
45 #include "nsIRenderingContext.h"
47 class nsIScrollableView
;
51 class nsIDeviceContext
;
52 class nsIViewObserver
;
54 enum nsRectVisibility
{
55 nsRectVisibility_kVisible
,
56 nsRectVisibility_kAboveViewport
,
57 nsRectVisibility_kBelowViewport
,
58 nsRectVisibility_kLeftOfViewport
,
59 nsRectVisibility_kRightOfViewport
,
60 nsRectVisibility_kZeroAreaRect
63 // 855e75b8-32cf-4e16-bc50-4e04c53f6cbc
64 #define NS_IVIEWMANAGER_IID \
65 { 0x855e75b8, 0x32cf, 0x4e16, \
66 { 0xbc, 0x50, 0x4e, 0x04, 0xc5, 0x3f, 0x6c, 0xbc } }
68 class nsIViewManager
: public nsISupports
72 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IVIEWMANAGER_IID
)
74 * Initialize the ViewManager
75 * Note: this instance does not hold a reference to the viewobserver
76 * because it holds a reference to this instance.
77 * @result The result of the initialization, NS_OK if no errors
79 NS_IMETHOD
Init(nsIDeviceContext
* aContext
) = 0;
82 * Create an ordinary view
83 * @param aBounds initial bounds for view
84 * XXX We should eliminate this parameter; you can set the bounds after CreateView
85 * @param aParent intended parent for view. this is not actually set in the
86 * nsIView through this method. it is only used by the initialization
87 * code to walk up the view tree, if necessary, to find resources.
88 * XXX We should eliminate this parameter!
89 * @param aVisibilityFlag initial visibility state of view
90 * XXX We should eliminate this parameter; you can set it after CreateView
91 * @result The new view
93 NS_IMETHOD_(nsIView
*) CreateView(const nsRect
& aBounds
,
94 const nsIView
* aParent
,
95 nsViewVisibility aVisibilityFlag
= nsViewVisibility_kShow
) = 0;
98 * Create an scrollable view
99 * @param aBounds initial bounds for view
100 * XXX We should eliminate this parameter; you can set the bounds after CreateScrollableView
101 * @param aParent intended parent for view. this is not actually set in the
102 * nsIView through this method. it is only used by the initialization
103 * code to walk up the view tree, if necessary, to find resources.
104 * XXX We should eliminate this parameter!
105 * @result The new view
107 NS_IMETHOD_(nsIScrollableView
*) CreateScrollableView(const nsRect
& aBounds
,
108 const nsIView
* aParent
) = 0;
111 * Get the root of the view tree.
112 * @result the root view
114 NS_IMETHOD
GetRootView(nsIView
*&aView
) = 0;
117 * Set the root of the view tree. Does not destroy the current root view.
118 * aView may have a parent view managed by a different view manager.
119 * aView may have a widget (anything but printing) or may not (printing).
120 * @param aView view to set as root
122 NS_IMETHOD
SetRootView(nsIView
*aView
) = 0;
125 * Get the dimensions of the root window. The dimensions are in
127 * @param aWidth out parameter for width of window in twips
128 * @param aHeight out parameter for height of window in twips
130 NS_IMETHOD
GetWindowDimensions(nscoord
*aWidth
, nscoord
*aHeight
) = 0;
133 * Set the dimensions of the root window.
134 * Called if the root window is resized. The dimensions are in
136 * @param aWidth of window in twips
137 * @param aHeight of window in twips
139 NS_IMETHOD
SetWindowDimensions(nscoord aWidth
, nscoord aHeight
) = 0;
142 * Called to force a redrawing of any dirty areas.
144 // XXXbz why is this exposed? Shouldn't update view batches handle this?
145 // It's not like Composite() does what's expected inside a view update batch
146 // anyway, since dirty areas may not have been invalidated on the widget yet
147 // and widget changes may not have been propagated yet. Maybe this should
148 // call FlushPendingInvalidates()?
149 NS_IMETHOD
Composite(void) = 0;
152 * Called to inform the view manager that the entire area of a view
153 * is dirty and needs to be redrawn.
154 * @param aView view to paint. should be root view
155 * @param aUpdateFlags see bottom of nsIViewManager.h for description
157 NS_IMETHOD
UpdateView(nsIView
*aView
, PRUint32 aUpdateFlags
) = 0;
160 * Called to inform the view manager that some portion of a view
161 * is dirty and needs to be redrawn. The rect passed in
162 * should be in the view's coordinate space.
163 * @param aView view to paint. should be root view
164 * @param rect rect to mark as damaged
165 * @param aUpdateFlags see bottom of nsIViewManager.h for description
167 NS_IMETHOD
UpdateView(nsIView
*aView
, const nsRect
&aRect
, PRUint32 aUpdateFlags
) = 0;
170 * Called to inform the view manager that it should redraw all views.
171 * @param aView view to paint. should be root view
172 * @param aUpdateFlags see bottom of nsIViewManager.h for description
174 NS_IMETHOD
UpdateAllViews(PRUint32 aUpdateFlags
) = 0;
177 * Called to dispatch an event to the appropriate view. Often called
178 * as a result of receiving a mouse or keyboard event from the widget
180 * @param event event to dispatch
181 * @result event handling status
183 NS_IMETHOD
DispatchEvent(nsGUIEvent
*aEvent
, nsEventStatus
* aStatus
) = 0;
186 * Used to grab/capture all mouse events for a specific view,
187 * irrespective of the cursor position at which the
189 * @param aView view to capture mouse events
190 * @result event handling status
192 NS_IMETHOD
GrabMouseEvents(nsIView
*aView
, PRBool
& aResult
) = 0;
195 * Get the current view, if any, that's capturing mouse events.
196 * @result view that is capturing mouse events or nsnull
198 NS_IMETHOD
GetMouseEventGrabber(nsIView
*&aView
) = 0;
201 * Given a parent view, insert another view as its child.
202 * aSibling and aAbove control the "document order" for the insertion.
203 * If aSibling is null, the view is inserted at the end of the document order
204 * if aAfter is PR_TRUE, otherwise it is inserted at the beginning.
205 * If aSibling is non-null, then if aAfter is PR_TRUE, the view is inserted
206 * after the sibling in document order (appearing above the sibling unless
207 * overriden by z-order).
208 * If it is PR_FALSE, the view is inserted before the sibling.
209 * The view manager generates the appopriate dirty regions.
210 * @param aParent parent view
211 * @param aChild child view
212 * @param aSibling sibling view
213 * @param aAfter after or before in the document order
215 NS_IMETHOD
InsertChild(nsIView
*aParent
, nsIView
*aChild
, nsIView
*aSibling
,
219 * Remove a specific child view from its parent. This will NOT remove its placeholder
221 * The view manager generates the appropriate dirty regions.
222 * @param aParent parent view
223 * @param aChild child view
225 NS_IMETHOD
RemoveChild(nsIView
*aChild
) = 0;
228 * Move a view to the specified position, provided in parent coordinates.
229 * The new position is the (0, 0) origin for the view's coordinate system.
230 * The view's bounds may extend above or to the left of this point.
231 * The view manager generates the appropriate dirty regions.
232 * @param aView view to move
233 * @param aX x value for new view position
234 * @param aY y value for new view position
236 NS_IMETHOD
MoveViewTo(nsIView
*aView
, nscoord aX
, nscoord aY
) = 0;
239 * Resize a view. In addition to setting the width and height, you can
240 * set the x and y of its bounds relative to its position. Negative x and y
241 * will let the view extend above and to the left of the (0,0) point in its
243 * The view manager generates the appropriate dirty regions.
244 * @param aView view to move
245 * @param the new bounds relative to the current position
246 * @param RepaintExposedAreaOnly
247 * if PR_TRUE Repaint only the expanded or contracted region,
248 * if PR_FALSE Repaint the union of the old and new rectangles.
250 NS_IMETHOD
ResizeView(nsIView
*aView
, const nsRect
&aRect
,
251 PRBool aRepaintExposedAreaOnly
= PR_FALSE
) = 0;
254 * Set the visibility of a view.
255 * The view manager generates the appropriate dirty regions.
256 * @param aView view to change visibility state of
257 * @param visible new visibility state
259 NS_IMETHOD
SetViewVisibility(nsIView
*aView
, nsViewVisibility aVisible
) = 0;
262 * Set the z-index of a view. Positive z-indices mean that a view
263 * is above its parent in z-order. Negative z-indices mean that a
264 * view is below its parent.
265 * The view manager generates the appropriate dirty regions.
266 * @param aAutoZIndex indicate that the z-index of a view is "auto". An "auto" z-index
267 * means that the view does not define a new stacking context,
268 * which means that the z-indicies of the view's children are
269 * relative to the view's siblings.
270 * @param aView view to change z depth of
271 * @param aZindex explicit z depth
272 * @param aTopMost used when this view is z-index:auto to compare against
273 * other z-index:auto views.
274 * PR_TRUE if the view should be topmost when compared with
275 * other z-index:auto views.
277 NS_IMETHOD
SetViewZIndex(nsIView
*aView
, PRBool aAutoZIndex
, PRInt32 aZindex
, PRBool aTopMost
= PR_FALSE
) = 0;
280 * Set whether the view "floats" above all other views,
281 * which tells the compositor not to consider higher views in
282 * the view hierarchy that would geometrically intersect with
283 * this view. This is a hack, but it fixes some problems with
284 * views that need to be drawn in front of all other views.
286 NS_IMETHOD
SetViewFloating(nsIView
*aView
, PRBool aFloatingView
) = 0;
289 * Set the view observer associated with this manager
290 * @param aObserver - new observer
291 * @result error status
293 NS_IMETHOD
SetViewObserver(nsIViewObserver
*aObserver
) = 0;
296 * Get the view observer associated with this manager
297 * @param aObserver - out parameter for observer
298 * @result error status
300 NS_IMETHOD
GetViewObserver(nsIViewObserver
*&aObserver
) = 0;
303 * Get the device context associated with this manager
304 * @result device context
306 NS_IMETHOD
GetDeviceContext(nsIDeviceContext
*&aContext
) = 0;
309 * prevent the view manager from refreshing.
310 * @return error status
312 // XXXbz callers of this function don't seem to realize that it disables
313 // refresh for the entire view manager hierarchy.... Maybe it shouldn't do
315 NS_IMETHOD
DisableRefresh(void) = 0;
318 * allow the view manager to refresh. this may cause a synchronous
319 * paint to occur inside the call.
320 * @param aUpdateFlags see bottom of nsIViewManager.h for description
321 * @return error status
323 NS_IMETHOD
EnableRefresh(PRUint32 aUpdateFlags
) = 0;
325 class NS_STACK_CLASS UpdateViewBatch
{
329 * prevents the view manager from refreshing. allows UpdateView()
330 * to notify widgets of damaged regions that should be repainted
331 * when the batch is ended. Call EndUpdateViewBatch on this object
332 * before it is destroyed
333 * @return error status
335 UpdateViewBatch(nsIViewManager
* aVM
) {
337 mRootVM
= aVM
->BeginUpdateViewBatch();
341 NS_ASSERTION(!mRootVM
, "Someone forgot to call EndUpdateViewBatch!");
345 * See the constructor, this lets you "fill in" a blank UpdateViewBatch.
347 void BeginUpdateViewBatch(nsIViewManager
* aVM
) {
348 NS_ASSERTION(!mRootVM
, "already started a batch!");
350 mRootVM
= aVM
->BeginUpdateViewBatch();
355 * allow the view manager to refresh any damaged areas accumulated
356 * after the BeginUpdateViewBatch() call. this may cause a
357 * synchronous paint to occur inside the call if aUpdateFlags
358 * NS_VMREFRESH_IMMEDIATE is set.
360 * If this is not the outermost view batch command, then this does
361 * nothing except that the specified flags are remembered. When the
362 * outermost batch finally ends, we merge together all the flags for the
363 * inner batches in the following way:
364 * -- If any batch specified NS_VMREFRESH_IMMEDIATE, then we use that flag
365 * (i.e. there is a synchronous paint under the last EndUpdateViewBatch)
366 * -- Otherwise if any batch specified NS_VMREFERSH_DEFERRED, then we use
367 * that flag (i.e. invalidation is deferred until the processing of an
368 * Invalidate PLEvent)
369 * -- Otherwise all batches specified NS_VMREFRESH_NO_SYNC and we honor
370 * that; all widgets are invalidated normally and will be painted the next
371 * time the toolkit chooses to update them.
373 * @param aUpdateFlags see bottom of nsIViewManager.h for
374 * description @return error status
376 void EndUpdateViewBatch(PRUint32 aUpdateFlags
) {
379 mRootVM
->EndUpdateViewBatch(aUpdateFlags
);
384 UpdateViewBatch(const UpdateViewBatch
& aOther
);
385 const UpdateViewBatch
& operator=(const UpdateViewBatch
& aOther
);
387 nsCOMPtr
<nsIViewManager
> mRootVM
;
391 friend class UpdateViewBatch
;
393 virtual nsIViewManager
* BeginUpdateViewBatch(void) = 0;
394 NS_IMETHOD
EndUpdateViewBatch(PRUint32 aUpdateFlags
) = 0;
399 * set the view that is is considered to be the root scrollable
400 * view for the document.
401 * @param aScrollable root scrollable view
402 * @return error status
404 NS_IMETHOD
SetRootScrollableView(nsIScrollableView
*aScrollable
) = 0;
407 * get the view that is is considered to be the root scrollable
408 * view for the document.
409 * @param aScrollable out parameter for root scrollable view
410 * @return error status
412 NS_IMETHOD
GetRootScrollableView(nsIScrollableView
**aScrollable
) = 0;
415 * Retrieve the widget at the root of the view manager. This is the
416 * widget associated with the root view, if the root view exists and has
419 NS_IMETHOD
GetWidget(nsIWidget
**aWidget
) = 0;
422 * Force update of view manager widget
423 * Callers should use UpdateView(view, NS_VMREFRESH_IMMEDIATE) in most cases instead
424 * @result error status
426 // XXXbz Callers seem to be confused about this one... and it doesn't play
427 // right with view update batching at all (will miss updates). Maybe this
428 // should call FlushPendingInvalidates()?
429 NS_IMETHOD
ForceUpdate() = 0;
432 * Indicate whether the viewmanager is currently painting
434 * @param aPainting PR_TRUE if the viewmanager is painting
437 NS_IMETHOD
IsPainting(PRBool
& aIsPainting
)=0;
440 * Set the default background color that the view manager should use
441 * to paint otherwise unowned areas. If the color isn't known, just set
442 * it to zero (which means 'transparent' since the color is RGBA).
444 * @param aColor the default background color
446 NS_IMETHOD
SetDefaultBackgroundColor(nscolor aColor
)=0;
449 * Retrieve the default background color.
451 * @param aColor the default background color
453 NS_IMETHOD
GetDefaultBackgroundColor(nscolor
* aColor
)=0;
456 * Retrieve the time of the last user event. User events
457 * include mouse and keyboard events. The viewmanager
458 * saves the time of the last user event.
460 * @param aTime Last user event time in microseconds
462 NS_IMETHOD
GetLastUserEventTime(PRUint32
& aTime
)=0;
465 * Determine if a rectangle specified in the view's coordinate system
466 * is completely, or partially visible.
467 * @param aView view that aRect coordinates are specified relative to
468 * @param aRect rectangle in twips to test for visibility
469 * @param aMinTwips is the min. pixel rows or cols at edge of screen
470 * needed for object to be counted visible
471 * @param aRectVisibility returns eVisible if the rect is visible,
472 * otherwise it returns an enum indicating why not
474 NS_IMETHOD
GetRectVisibility(nsIView
*aView
, const nsRect
&aRect
,
476 nsRectVisibility
*aRectVisibility
)=0;
479 * Dispatch a mouse move event based on the most recent mouse
480 * position. This is used when the contents of the page moved
481 * (aFromScroll is false) or scrolled (aFromScroll is true).
483 NS_IMETHOD
SynthesizeMouseMove(PRBool aFromScroll
)=0;
487 NS_DEFINE_STATIC_IID_ACCESSOR(nsIViewManager
, NS_IVIEWMANAGER_IID
)
489 // Paint timing mode flags
491 // intermediate: do no special timing processing; repaint when the
492 // toolkit issues an expose event (which will happen *before* PLEvent
493 // processing). This is essentially the default.
494 #define NS_VMREFRESH_NO_SYNC 0
496 // least immediate: we suppress invalidation, storing dirty areas in
497 // views, and post an Invalidate PLEvent. The Invalidate event gets
498 // processed after toolkit events such as window resize events!
499 // This is only usable with EndUpdateViewBatch and EnableRefresh.
500 #define NS_VMREFRESH_DEFERRED 0x0001
502 // most immediate: force a call to nsViewManager::Composite, which
503 // synchronously updates the window(s) right away before returning
504 #define NS_VMREFRESH_IMMEDIATE 0x0002
506 //animate scroll operation
507 #define NS_VMREFRESH_SMOOTHSCROLL 0x0008
509 #endif // nsIViewManager_h___