1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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 the GNU General Public License Version 2 or later (the "GPL"), or
26
* 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 NPL, 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 NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#ifndef nsViewManager_h___
39
#define nsViewManager_h___
41
#include "nsIViewManager.h"
43
#include "nsIWidget.h"
47
#include "nsVoidArray.h"
48
#include "nsHashtable.h"
49
#include "nsIScrollableView.h"
50
#include "nsIRegion.h"
51
#include "nsIBlender.h"
52
#include "nsIEventQueueService.h"
53
#include "nsIEventQueue.h"
59
class nsISupportsArray;
60
struct DisplayListElement2;
61
struct DisplayZTreeNode;
62
class BlendingBuffers;
64
//Uncomment the following line to enable generation of viewmanager performance data.
65
#ifdef MOZ_PERF_METRICS
66
//#define NS_VM_PERF_METRICS 1
69
#ifdef NS_VM_PERF_METRICS
74
FIXED-POSITION FRAMES AND Z-ORDERING
76
Fixed-position frames are special. They have TWO views. There is the "real" view, which is
77
a child of the root view for the viewport (which is the root view of the view manager).
78
There is also a "placeholder" view (of class nsZPlaceholderView) which never really
79
participates in any view operations. It is a child of the view that would have contained
80
the fixed-position element if it had not been fixed-position. The real view keeps track
81
of the placeholder view and returns the placeholder view when you call GetZParent on the
84
(Although currently all views which have a placeholder view are themselves children of the
85
root view, we don't want to depend on this. Later we might want to support views that
86
are fixed relative to some container other than the viewport.)
88
As we build the display list in CreateDisplayList, once we've processed the parent of
89
real views (i.e., the root), we move those real views from their current position in the
90
display list over to where their placeholder views are in the display list. This ensures that
91
views get repainted in the order they would have been repainted in the absence of
92
fixed-position frames.
95
class nsZPlaceholderView : public nsView
98
nsZPlaceholderView() : nsView() {}
100
void RemoveReparentedView() { mReparentedView = nsnull; }
101
void SetReparentedView(nsView* aView) { mReparentedView = aView; }
102
nsView* GetReparentedView() const { return mReparentedView; }
104
virtual PRBool IsZPlaceholderView() const { return PR_TRUE; }
107
virtual ~nsZPlaceholderView() {
108
if (nsnull != mReparentedView) {
109
mReparentedView->SetZParent(nsnull);
114
nsView *mReparentedView;
117
class nsViewManager : public nsIViewManager {
121
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
125
NS_IMETHOD Init(nsIDeviceContext* aContext);
127
NS_IMETHOD GetRootView(nsIView *&aView);
128
NS_IMETHOD SetRootView(nsIView *aView, nsIWidget* aWidget=nsnull);
130
NS_IMETHOD GetWindowOffset(nscoord *aX, nscoord *aY);
131
NS_IMETHOD SetWindowOffset(nscoord aX, nscoord aY);
133
NS_IMETHOD GetWindowDimensions(nscoord *width, nscoord *height);
134
NS_IMETHOD SetWindowDimensions(nscoord width, nscoord height);
136
NS_IMETHOD ResetScrolling(void);
138
NS_IMETHOD Composite(void);
140
NS_IMETHOD UpdateView(nsIView *aView, PRUint32 aUpdateFlags);
141
NS_IMETHOD UpdateView(nsIView *aView, const nsRect &aRect, PRUint32 aUpdateFlags);
142
NS_IMETHOD UpdateAllViews(PRUint32 aUpdateFlags);
144
NS_IMETHOD DispatchEvent(nsGUIEvent *aEvent, nsEventStatus* aStatus);
146
NS_IMETHOD GrabMouseEvents(nsIView *aView, PRBool &aResult);
147
NS_IMETHOD GrabKeyEvents(nsIView *aView, PRBool &aresult);
149
NS_IMETHOD GetMouseEventGrabber(nsIView *&aView);
150
NS_IMETHOD GetKeyEventGrabber(nsIView *&aView);
152
NS_IMETHOD InsertChild(nsIView *parent, nsIView *child, nsIView *sibling,
155
NS_IMETHOD InsertChild(nsIView *parent, nsIView *child,
158
NS_IMETHOD InsertZPlaceholder(nsIView *parent, nsIView *child, nsIView *sibling,
161
NS_IMETHOD RemoveChild(nsIView *parent);
163
NS_IMETHOD MoveViewBy(nsIView *aView, nscoord aX, nscoord aY);
165
NS_IMETHOD MoveViewTo(nsIView *aView, nscoord aX, nscoord aY);
167
NS_IMETHOD ResizeView(nsIView *aView, const nsRect &aRect, PRBool aRepaintExposedAreaOnly = PR_FALSE);
169
NS_IMETHOD SetViewChildClipRegion(nsIView *aView, const nsRegion *aRegion);
171
NS_IMETHOD SetViewBitBltEnabled(nsIView *aView, PRBool aEnable);
173
NS_IMETHOD SetViewCheckChildEvents(nsIView *aView, PRBool aEnable);
175
NS_IMETHOD SetViewFloating(nsIView *aView, PRBool aFloating);
177
NS_IMETHOD SetViewVisibility(nsIView *aView, nsViewVisibility aVisible);
179
NS_IMETHOD SetViewZIndex(nsIView *aView, PRBool aAuto, PRInt32 aZIndex, PRBool aTopMost=PR_FALSE);
180
NS_IMETHOD SetViewContentTransparency(nsIView *aView, PRBool aTransparent);
181
NS_IMETHOD SetViewOpacity(nsIView *aView, float aOpacity);
183
NS_IMETHOD SetViewObserver(nsIViewObserver *aObserver);
184
NS_IMETHOD GetViewObserver(nsIViewObserver *&aObserver);
186
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
188
NS_IMETHOD DisableRefresh(void);
189
NS_IMETHOD EnableRefresh(PRUint32 aUpdateFlags);
191
NS_IMETHOD BeginUpdateViewBatch(void);
192
NS_IMETHOD EndUpdateViewBatch(PRUint32 aUpdateFlags);
194
NS_IMETHOD SetRootScrollableView(nsIScrollableView *aScrollable);
195
NS_IMETHOD GetRootScrollableView(nsIScrollableView **aScrollable);
197
NS_IMETHOD Display(nsIView *aView, nscoord aX, nscoord aY, const nsRect& aClipRect);
199
NS_IMETHOD AddCompositeListener(nsICompositeListener *aListener);
200
NS_IMETHOD RemoveCompositeListener(nsICompositeListener *aListener);
202
NS_IMETHOD GetWidgetForView(nsIView *aView, nsIWidget **aWidget);
203
NS_IMETHOD GetWidget(nsIWidget **aWidget);
204
nsIWidget* GetWidget() { return mRootWindow; }
205
NS_IMETHOD ForceUpdate();
207
NS_IMETHOD IsCachingWidgetChanges(PRBool* aCaching);
208
NS_IMETHOD CacheWidgetChanges(PRBool aCache);
209
NS_IMETHOD AllowDoubleBuffering(PRBool aDoubleBuffer);
210
NS_IMETHOD IsPainting(PRBool& aIsPainting);
211
NS_IMETHOD FlushPendingInvalidates();
212
NS_IMETHOD SetDefaultBackgroundColor(nscolor aColor);
213
NS_IMETHOD GetDefaultBackgroundColor(nscolor* aColor);
214
NS_IMETHOD GetLastUserEventTime(PRUint32& aTime);
215
void ProcessInvalidateEvent();
216
static PRInt32 GetViewManagerCount();
217
static const nsVoidArray* GetViewManagerArray();
218
static PRUint32 gLastUserEventTime;
221
* Determine if a rectangle specified in the view's coordinate system
222
* is completely, or partially visible.
223
* @param aView view that aRect coordinates are specified relative to
224
* @param aRect rectangle in twips to test for visibility
225
* @param aMinTwips is the min. pixel rows or cols at edge of screen
226
* needed for object to be counted visible
227
* @param aRectVisibility returns eVisible if the rect is visible,
228
* otherwise it returns an enum indicating why not
230
NS_IMETHOD GetRectVisibility(nsIView *aView, const nsRect &aRect,
232
nsRectVisibility *aRectVisibility);
235
virtual ~nsViewManager();
236
void ProcessPendingUpdates(nsView *aView);
239
void ReparentChildWidgets(nsIView* aView, nsIWidget *aNewWidget);
240
void ReparentWidgets(nsIView* aView, nsIView *aParent);
241
nsIRenderingContext *CreateRenderingContext(nsView &aView);
242
void AddRectToDirtyRegion(nsView* aView, const nsRect &aRect) const;
244
PRBool UpdateWidgetArea(nsView *aWidgetView, const nsRect &aDamagedRect, nsView* aIgnoreWidgetView);
246
void UpdateViews(nsView *aView, PRUint32 aUpdateFlags);
248
void Refresh(nsView *aView, nsIRenderingContext *aContext,
249
nsIRegion *region, PRUint32 aUpdateFlags);
250
void DefaultRefresh(nsView* aView, const nsRect* aRect);
251
PRBool BuildRenderingDisplayList(nsIView* aRootView,
252
const nsRegion& aRegion, nsVoidArray* aDisplayList);
253
void RenderViews(nsView *aRootView, nsIRenderingContext& aRC,
254
const nsRegion& aRegion, nsDrawingSurface aRCSurface,
255
const nsVoidArray& aDisplayList);
257
void RenderDisplayListElement(DisplayListElement2* element,
258
nsIRenderingContext* aRC);
260
void PaintView(nsView *aView, nsIRenderingContext &aRC, nscoord x, nscoord y,
261
const nsRect &aDamageRect);
263
void InvalidateRectDifference(nsView *aView, const nsRect& aRect, const nsRect& aCutOut, PRUint32 aUpdateFlags);
264
void InvalidateHorizontalBandDifference(nsView *aView, const nsRect& aRect, const nsRect& aCutOut,
265
PRUint32 aUpdateFlags, nscoord aY1, nscoord aY2, PRBool aInCutOut);
267
BlendingBuffers* CreateBlendingBuffers(nsIRenderingContext *aRC, PRBool aBorrowContext,
268
nsDrawingSurface aBorrowSurface, PRBool aNeedAlpha,
269
const nsRect& aArea);
271
void ReparentViews(DisplayZTreeNode* aNode);
272
void BuildDisplayList(nsView* aView, const nsRect& aRect, PRBool aEventProcessing,
273
PRBool aCaptured, nsVoidArray* aDisplayList);
274
void BuildEventTargetList(nsVoidArray &aTargets, nsView* aView, nsGUIEvent* aEvent, PRBool aCaptured);
276
PRBool CreateDisplayList(nsView *aView,
277
PRBool aReparentedViewsPresent, DisplayZTreeNode* &aResult,
278
nscoord aOriginX, nscoord aOriginY,
279
nsView *aRealView, const nsRect *aDamageRect,
280
nsView *aTopView, nscoord aX, nscoord aY,
281
PRBool aPaintFloats, PRBool aEventProcessing);
282
PRBool AddToDisplayList(nsView *aView,
283
DisplayZTreeNode* &aParent, nsRect &aClipRect,
284
nsRect& aDirtyRect, PRUint32 aFlags, nscoord aAbsX, nscoord aAbsY,
285
PRBool aAssumeIntersection);
286
void OptimizeDisplayList(const nsVoidArray* aDisplayList, const nsRegion& aDirtyRegion,
287
nsRect& aFinalTransparentRect, nsRegion& aOpaqueRgn,
288
PRBool aTreatUniformAsOpaque);
290
void AddCoveringWidgetsToOpaqueRegion(nsRegion &aRgn, nsIDeviceContext* aContext,
294
PRBool DoesViewHaveNativeWidget(nsView* aView);
296
void PauseTimer(void);
297
void RestartTimer(void);
298
void OptimizeDisplayListClipping(const nsVoidArray* aDisplayList, PRBool aHaveClip,
299
nsRect& aClipRect, PRInt32& aIndex,
300
PRBool& aAnyRendered);
301
nsRect OptimizeTranslucentRegions(const nsVoidArray& aDisplayList,
302
PRInt32* aIndex, nsRegion* aOpaqueRegion);
304
void ShowDisplayList(const nsVoidArray* aDisplayList);
308
PRBool IsViewInserted(nsView *aView);
311
* Returns the nearest parent view with an attached widget. Can be the
312
* same view as passed-in.
314
static nsView* GetWidgetView(nsView *aView);
317
* Transforms a rectangle from specified view's coordinate system to
318
* the first parent that has an attached widget.
320
void ViewToWidget(nsView *aView, nsView* aWidgetView, nsRect &aRect) const;
323
* Transforms a rectangle from specified view's coordinate system to
324
* an absolute coordinate rectangle which can be compared against the
325
* rectangle returned by GetVisibleRect to determine visibility.
326
* @param aView view that aRect coordinates are specified relative to
327
* @param aRect rectangle in twips to convert to absolute coordinates
328
* @param aAbsRect rectangle in absolute coorindates.
329
* @returns NS_OK if successful otherwise, NS_ERROR_FAILURE
332
nsresult GetAbsoluteRect(nsView *aView, const nsRect &aRect,
335
* Determine the visible rect
336
* @param aVisibleRect visible rectangle in twips
337
* @returns NS_OK if successful, otherwise NS_ERROR_FAILURE.
340
nsresult GetVisibleRect(nsRect& aVisibleRect);
342
nsresult ProcessWidgetChanges(nsView* aView);
344
// Utilities used to size the offscreen drawing surface
347
* Determine the maximum and width and height of all of the
348
* view manager's widgets.
350
* @param aMaxWidgetBounds the maximum width and height of all view managers
353
void GetMaxWidgetBounds(nsRect& aMaxWidgetBounds) const;
355
void DoSetWindowDimensions(nscoord aWidth, nscoord aHeight)
358
nsRect newDim(0, 0, aWidth, aHeight);
359
mRootView->GetDimensions(oldDim);
360
if (oldDim != newDim) {
361
mRootView->SetDimensions(newDim);
363
mObserver->ResizeReflow(mRootView, aWidth, aHeight);
367
public: // NOT in nsIViewManager, so private to the view module
368
nsView* GetRootView() const { return mRootView; }
369
nsView* GetMouseEventGrabber() const { return mMouseGrabber; }
370
nsView* GetKeyEventGrabber() const { return mKeyGrabber; }
372
nsEventStatus HandleEvent(nsView* aView, nsGUIEvent* aEvent, PRBool aCaptured);
375
* Called to inform the view manager that a view has scrolled.
376
* The view manager will invalidate any widgets which may need
378
* @param aView view to paint. should be root view
379
* @param aUpdateFlags see bottom of nsIViewManager.h for description
381
void UpdateViewAfterScroll(nsIView *aView, PRInt32 aDX, PRInt32 aDY);
383
PRBool CanScrollWithBitBlt(nsView* aView);
385
nsresult CreateRegion(nsIRegion* *result);
387
// return the sum of all view offsets from aView right up to the
388
// root of this view hierarchy (the view with no parent, which might
389
// not be in this view manager).
390
static nsPoint ComputeViewOffset(const nsView *aView);
393
nsIDeviceContext *mContext;
394
float mTwipsToPixels;
395
float mPixelsToTwips;
396
nsIViewObserver *mObserver;
397
nsIWidget *mRootWindow;
398
PRBool mRefreshEnabled;
400
PRBool mRecursiveRefreshPending;
401
nsView *mMouseGrabber;
404
PRInt32 mUpdateBatchCnt;
405
nsIScrollableView *mRootScrollable;
406
PRInt32 mCachingWidgetChanges;
407
nscolor mDefaultBackgroundColor;
409
// The size for a resize that we delayed until the root view becomes
411
nsSize mDelayedResize;
413
nsHashtable mMapPlaceholderViewToZTreeNode;
415
//from here to public should be static and locked... MMP
416
static PRInt32 mVMCount; //number of viewmanagers
418
//Rendering context used to cleanup the blending buffers
419
static nsIRenderingContext* gCleanupContext;
421
//list of view managers
422
static nsVoidArray *gViewManagers;
424
nsCOMPtr<nsIBlender> mBlender;
426
nsISupportsArray *mCompositeListeners;
427
void DestroyZTreeNode(DisplayZTreeNode* aNode);
429
nsCOMPtr<nsIFactory> mRegionFactory;
434
PRBool mAllowDoubleBuffering;
435
PRBool mHasPendingInvalidates;
436
nsCOMPtr<nsIEventQueueService> mEventQueueService;
437
nsCOMPtr<nsIEventQueue> mInvalidateEventQueue;
438
void PostInvalidateEvent();
440
#ifdef NS_VM_PERF_METRICS
441
MOZ_TIMER_DECLARE(mWatch) // Measures compositing+paint time for current document
445
//when the refresh happens, should it be double buffered?
446
#define NS_VMREFRESH_DOUBLE_BUFFER 0x0001
448
#endif /* nsViewManager_h___ */