~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/view/src/nsViewManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
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 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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#ifndef nsViewManager_h___
 
39
#define nsViewManager_h___
 
40
#include "nsCOMPtr.h"
 
41
#include "nsIViewManager.h"
 
42
#include "nsCRT.h"
 
43
#include "nsIWidget.h"
 
44
#include "nsITimer.h"
 
45
#include "prtime.h"
 
46
#include "prinrval.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"
 
54
#include "nsView.h"
 
55
 
 
56
class nsIRegion;
 
57
class nsIEvent;
 
58
class nsIPresContext;
 
59
class nsISupportsArray;
 
60
struct DisplayListElement2;
 
61
struct DisplayZTreeNode;
 
62
class BlendingBuffers;
 
63
 
 
64
//Uncomment the following line to enable generation of viewmanager performance data.
 
65
#ifdef MOZ_PERF_METRICS
 
66
//#define NS_VM_PERF_METRICS 1 
 
67
#endif
 
68
 
 
69
#ifdef NS_VM_PERF_METRICS
 
70
#include "nsTimer.h"
 
71
#endif
 
72
 
 
73
/**
 
74
   FIXED-POSITION FRAMES AND Z-ORDERING
 
75
 
 
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
 
82
   real view.
 
83
 
 
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.)
 
87
 
 
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.
 
93
 */
 
94
 
 
95
class nsZPlaceholderView : public nsView
 
96
{
 
97
public:
 
98
  nsZPlaceholderView() : nsView() {}
 
99
 
 
100
  void RemoveReparentedView() { mReparentedView = nsnull; }
 
101
  void SetReparentedView(nsView* aView) { mReparentedView = aView; }
 
102
  nsView* GetReparentedView() const { return mReparentedView; }
 
103
 
 
104
  virtual PRBool IsZPlaceholderView() const { return PR_TRUE; }
 
105
 
 
106
protected:
 
107
  virtual ~nsZPlaceholderView() {
 
108
    if (nsnull != mReparentedView) {
 
109
      mReparentedView->SetZParent(nsnull);
 
110
    }
 
111
  }
 
112
 
 
113
protected:
 
114
  nsView   *mReparentedView;
 
115
};
 
116
 
 
117
class nsViewManager : public nsIViewManager {
 
118
public:
 
119
  nsViewManager();
 
120
 
 
121
  NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
 
122
 
 
123
  NS_DECL_ISUPPORTS
 
124
 
 
125
  NS_IMETHOD  Init(nsIDeviceContext* aContext);
 
126
 
 
127
  NS_IMETHOD  GetRootView(nsIView *&aView);
 
128
  NS_IMETHOD  SetRootView(nsIView *aView, nsIWidget* aWidget=nsnull);
 
129
 
 
130
  NS_IMETHOD  GetWindowOffset(nscoord *aX, nscoord *aY);
 
131
  NS_IMETHOD  SetWindowOffset(nscoord aX, nscoord aY);
 
132
 
 
133
  NS_IMETHOD  GetWindowDimensions(nscoord *width, nscoord *height);
 
134
  NS_IMETHOD  SetWindowDimensions(nscoord width, nscoord height);
 
135
 
 
136
  NS_IMETHOD  ResetScrolling(void);
 
137
 
 
138
  NS_IMETHOD  Composite(void);
 
139
 
 
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);
 
143
 
 
144
  NS_IMETHOD  DispatchEvent(nsGUIEvent *aEvent, nsEventStatus* aStatus);
 
145
 
 
146
  NS_IMETHOD  GrabMouseEvents(nsIView *aView, PRBool &aResult);
 
147
  NS_IMETHOD  GrabKeyEvents(nsIView *aView, PRBool &aresult);
 
148
 
 
149
  NS_IMETHOD  GetMouseEventGrabber(nsIView *&aView);
 
150
  NS_IMETHOD  GetKeyEventGrabber(nsIView *&aView);
 
151
 
 
152
  NS_IMETHOD  InsertChild(nsIView *parent, nsIView *child, nsIView *sibling,
 
153
                          PRBool above);
 
154
 
 
155
  NS_IMETHOD  InsertChild(nsIView *parent, nsIView *child,
 
156
                          PRInt32 zindex);
 
157
 
 
158
  NS_IMETHOD  InsertZPlaceholder(nsIView *parent, nsIView *child, nsIView *sibling,
 
159
                                 PRBool above);
 
160
 
 
161
  NS_IMETHOD  RemoveChild(nsIView *parent);
 
162
 
 
163
  NS_IMETHOD  MoveViewBy(nsIView *aView, nscoord aX, nscoord aY);
 
164
 
 
165
  NS_IMETHOD  MoveViewTo(nsIView *aView, nscoord aX, nscoord aY);
 
166
 
 
167
  NS_IMETHOD  ResizeView(nsIView *aView, const nsRect &aRect, PRBool aRepaintExposedAreaOnly = PR_FALSE);
 
168
 
 
169
  NS_IMETHOD  SetViewChildClipRegion(nsIView *aView, const nsRegion *aRegion);
 
170
 
 
171
  NS_IMETHOD  SetViewBitBltEnabled(nsIView *aView, PRBool aEnable);
 
172
 
 
173
  NS_IMETHOD  SetViewCheckChildEvents(nsIView *aView, PRBool aEnable);
 
174
 
 
175
  NS_IMETHOD  SetViewFloating(nsIView *aView, PRBool aFloating);
 
176
 
 
177
  NS_IMETHOD  SetViewVisibility(nsIView *aView, nsViewVisibility aVisible);
 
178
 
 
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);
 
182
 
 
183
  NS_IMETHOD  SetViewObserver(nsIViewObserver *aObserver);
 
184
  NS_IMETHOD  GetViewObserver(nsIViewObserver *&aObserver);
 
185
 
 
186
  NS_IMETHOD  GetDeviceContext(nsIDeviceContext *&aContext);
 
187
 
 
188
  NS_IMETHOD  DisableRefresh(void);
 
189
  NS_IMETHOD  EnableRefresh(PRUint32 aUpdateFlags);
 
190
 
 
191
  NS_IMETHOD  BeginUpdateViewBatch(void);
 
192
  NS_IMETHOD  EndUpdateViewBatch(PRUint32 aUpdateFlags);
 
193
 
 
194
  NS_IMETHOD  SetRootScrollableView(nsIScrollableView *aScrollable);
 
195
  NS_IMETHOD  GetRootScrollableView(nsIScrollableView **aScrollable);
 
196
 
 
197
  NS_IMETHOD Display(nsIView *aView, nscoord aX, nscoord aY, const nsRect& aClipRect);
 
198
 
 
199
  NS_IMETHOD AddCompositeListener(nsICompositeListener *aListener);
 
200
  NS_IMETHOD RemoveCompositeListener(nsICompositeListener *aListener);
 
201
 
 
202
  NS_IMETHOD GetWidgetForView(nsIView *aView, nsIWidget **aWidget);
 
203
  NS_IMETHOD GetWidget(nsIWidget **aWidget);
 
204
  nsIWidget* GetWidget() { return mRootWindow; }
 
205
  NS_IMETHOD ForceUpdate();
 
206
 
 
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;
 
219
 
 
220
  /**
 
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
 
229
   */
 
230
  NS_IMETHOD GetRectVisibility(nsIView *aView, const nsRect &aRect, 
 
231
                               PRUint16 aMinTwips, 
 
232
                               nsRectVisibility *aRectVisibility);
 
233
 
 
234
protected:
 
235
  virtual ~nsViewManager();
 
236
  void ProcessPendingUpdates(nsView *aView);
 
237
 
 
238
private:
 
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;
 
243
 
 
244
  PRBool UpdateWidgetArea(nsView *aWidgetView, const nsRect &aDamagedRect, nsView* aIgnoreWidgetView);
 
245
 
 
246
  void UpdateViews(nsView *aView, PRUint32 aUpdateFlags);
 
247
 
 
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);
 
256
 
 
257
  void RenderDisplayListElement(DisplayListElement2* element,
 
258
                                nsIRenderingContext* aRC);
 
259
 
 
260
  void PaintView(nsView *aView, nsIRenderingContext &aRC, nscoord x, nscoord y,
 
261
                 const nsRect &aDamageRect);
 
262
 
 
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);
 
266
 
 
267
  BlendingBuffers* CreateBlendingBuffers(nsIRenderingContext *aRC, PRBool aBorrowContext,
 
268
                                         nsDrawingSurface aBorrowSurface, PRBool aNeedAlpha,
 
269
                                         const nsRect& aArea);
 
270
 
 
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);
 
275
 
 
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);
 
289
 
 
290
  void AddCoveringWidgetsToOpaqueRegion(nsRegion &aRgn, nsIDeviceContext* aContext,
 
291
                                        nsView* aRootView);
 
292
 
 
293
  // Predicates
 
294
  PRBool DoesViewHaveNativeWidget(nsView* aView);
 
295
 
 
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);
 
303
 
 
304
  void ShowDisplayList(const nsVoidArray* aDisplayList);
 
305
 
 
306
  // Utilities
 
307
 
 
308
  PRBool IsViewInserted(nsView *aView);
 
309
 
 
310
  /**
 
311
   * Returns the nearest parent view with an attached widget. Can be the
 
312
   * same view as passed-in.
 
313
   */
 
314
  static nsView* GetWidgetView(nsView *aView);
 
315
 
 
316
  /**
 
317
   * Transforms a rectangle from specified view's coordinate system to
 
318
   * the first parent that has an attached widget.
 
319
   */
 
320
  void ViewToWidget(nsView *aView, nsView* aWidgetView, nsRect &aRect) const;
 
321
 
 
322
  /**
 
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 
 
330
   */
 
331
 
 
332
  nsresult GetAbsoluteRect(nsView *aView, const nsRect &aRect, 
 
333
                           nsRect& aAbsRect);
 
334
  /**
 
335
   * Determine the visible rect 
 
336
   * @param aVisibleRect visible rectangle in twips
 
337
   * @returns NS_OK if successful, otherwise NS_ERROR_FAILURE.
 
338
   */
 
339
 
 
340
  nsresult GetVisibleRect(nsRect& aVisibleRect);
 
341
 
 
342
  nsresult ProcessWidgetChanges(nsView* aView);
 
343
 
 
344
  // Utilities used to size the offscreen drawing surface
 
345
 
 
346
  /**
 
347
   * Determine the maximum and width and height of all of the
 
348
   * view manager's widgets.
 
349
   *
 
350
   * @param aMaxWidgetBounds the maximum width and height of all view managers
 
351
   * widgets on exit.
 
352
   */
 
353
  void GetMaxWidgetBounds(nsRect& aMaxWidgetBounds) const;
 
354
 
 
355
  void DoSetWindowDimensions(nscoord aWidth, nscoord aHeight)
 
356
  {
 
357
    nsRect oldDim;
 
358
    nsRect newDim(0, 0, aWidth, aHeight);
 
359
    mRootView->GetDimensions(oldDim);
 
360
    if (oldDim != newDim) {
 
361
      mRootView->SetDimensions(newDim);
 
362
      if (mObserver)
 
363
        mObserver->ResizeReflow(mRootView, aWidth, aHeight);
 
364
    }
 
365
  }
 
366
 
 
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; }
 
371
 
 
372
  nsEventStatus HandleEvent(nsView* aView, nsGUIEvent* aEvent, PRBool aCaptured);
 
373
 
 
374
  /**
 
375
   * Called to inform the view manager that a view has scrolled.
 
376
   * The view manager will invalidate any widgets which may need
 
377
   * to be rerendered.
 
378
   * @param aView view to paint. should be root view
 
379
   * @param aUpdateFlags see bottom of nsIViewManager.h for description
 
380
   */
 
381
  void UpdateViewAfterScroll(nsIView *aView, PRInt32 aDX, PRInt32 aDY);
 
382
 
 
383
  PRBool CanScrollWithBitBlt(nsView* aView);
 
384
 
 
385
  nsresult CreateRegion(nsIRegion* *result);
 
386
 
 
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);
 
391
 
 
392
private:
 
393
  nsIDeviceContext  *mContext;
 
394
  float             mTwipsToPixels;
 
395
  float             mPixelsToTwips;
 
396
  nsIViewObserver   *mObserver;
 
397
  nsIWidget         *mRootWindow;
 
398
  PRBool            mRefreshEnabled;
 
399
  PRBool            mPainting;
 
400
  PRBool            mRecursiveRefreshPending;
 
401
  nsView            *mMouseGrabber;
 
402
  nsView            *mKeyGrabber;
 
403
  PRInt32           mUpdateCnt;
 
404
  PRInt32           mUpdateBatchCnt;
 
405
  nsIScrollableView *mRootScrollable;
 
406
  PRInt32           mCachingWidgetChanges;
 
407
  nscolor           mDefaultBackgroundColor;
 
408
 
 
409
  // The size for a resize that we delayed until the root view becomes
 
410
  // visible again.
 
411
  nsSize            mDelayedResize;
 
412
 
 
413
  nsHashtable       mMapPlaceholderViewToZTreeNode;
 
414
 
 
415
  //from here to public should be static and locked... MMP
 
416
  static PRInt32           mVMCount;        //number of viewmanagers
 
417
 
 
418
  //Rendering context used to cleanup the blending buffers
 
419
  static nsIRenderingContext* gCleanupContext;
 
420
 
 
421
  //list of view managers
 
422
  static nsVoidArray       *gViewManagers;
 
423
 
 
424
  nsCOMPtr<nsIBlender> mBlender;
 
425
 
 
426
  nsISupportsArray  *mCompositeListeners;
 
427
  void DestroyZTreeNode(DisplayZTreeNode* aNode);
 
428
 
 
429
  nsCOMPtr<nsIFactory> mRegionFactory;
 
430
protected:
 
431
  nsView            *mRootView;
 
432
  nscoord           mX;
 
433
  nscoord           mY;
 
434
  PRBool            mAllowDoubleBuffering;
 
435
  PRBool            mHasPendingInvalidates;
 
436
  nsCOMPtr<nsIEventQueueService>  mEventQueueService;
 
437
  nsCOMPtr<nsIEventQueue>         mInvalidateEventQueue;
 
438
  void PostInvalidateEvent();
 
439
 
 
440
#ifdef NS_VM_PERF_METRICS
 
441
  MOZ_TIMER_DECLARE(mWatch) //  Measures compositing+paint time for current document
 
442
#endif
 
443
};
 
444
 
 
445
//when the refresh happens, should it be double buffered?
 
446
#define NS_VMREFRESH_DOUBLE_BUFFER      0x0001
 
447
 
 
448
#endif /* nsViewManager_h___ */