2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsViewManager_h___
|
|
|
|
#define nsViewManager_h___
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "prtime.h"
|
|
|
|
#include "prinrval.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIRegion.h"
|
|
|
|
#include "nsView.h"
|
2007-06-27 14:23:02 -07:00
|
|
|
#include "nsIViewObserver.h"
|
2010-06-05 13:29:49 -07:00
|
|
|
#include "nsIDeviceContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Invalidation model:
|
|
|
|
|
|
|
|
1) Callers call into the view manager and ask it to update a view.
|
|
|
|
|
|
|
|
2) The view manager finds the "right" widget for the view, henceforth called
|
|
|
|
the root widget.
|
|
|
|
|
|
|
|
3) The view manager traverses descendants of the root widget and for each
|
|
|
|
one that needs invalidation either
|
|
|
|
|
|
|
|
a) Calls Invalidate() on the widget (no batching)
|
|
|
|
or
|
|
|
|
b) Stores the rect to invalidate on the widget's view (batching)
|
|
|
|
|
|
|
|
// XXXbz we want to change this a bit. See bug 243726
|
|
|
|
|
|
|
|
4) When batching, the call to end the batch either processes the pending
|
|
|
|
Invalidate() calls on the widgets or posts an event to do so.
|
|
|
|
|
|
|
|
It's important to note that widgets associated to views outside this view
|
|
|
|
manager can end up being invalidated during step 3. Therefore, the end of a
|
|
|
|
view update batch really needs to traverse the entire view tree, to ensure
|
|
|
|
that those invalidates happen.
|
|
|
|
|
|
|
|
To cope with this, invalidate event processing and view update batch
|
|
|
|
handling should only happen on the root viewmanager. This means the root
|
|
|
|
view manager is the only thing keeping track of mUpdateCnt. As a result,
|
|
|
|
Composite() calls should also be forwarded to the root view manager.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class nsViewManagerEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
nsViewManagerEvent(class nsViewManager *vm) : mViewManager(vm) {
|
|
|
|
NS_ASSERTION(mViewManager, "null parameter");
|
|
|
|
}
|
|
|
|
void Revoke() { mViewManager = nsnull; }
|
|
|
|
protected:
|
|
|
|
class nsViewManager *mViewManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsViewManager : public nsIViewManager {
|
|
|
|
public:
|
|
|
|
nsViewManager();
|
|
|
|
|
|
|
|
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD Init(nsIDeviceContext* aContext);
|
|
|
|
|
|
|
|
NS_IMETHOD_(nsIView*) CreateView(const nsRect& aBounds,
|
|
|
|
const nsIView* aParent,
|
|
|
|
nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow);
|
|
|
|
|
|
|
|
NS_IMETHOD GetRootView(nsIView *&aView);
|
|
|
|
NS_IMETHOD SetRootView(nsIView *aView);
|
|
|
|
|
|
|
|
NS_IMETHOD GetWindowDimensions(nscoord *width, nscoord *height);
|
|
|
|
NS_IMETHOD SetWindowDimensions(nscoord width, nscoord height);
|
2008-09-09 06:43:10 -07:00
|
|
|
NS_IMETHOD FlushDelayedResize();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Composite(void);
|
|
|
|
|
|
|
|
NS_IMETHOD UpdateView(nsIView *aView, PRUint32 aUpdateFlags);
|
|
|
|
NS_IMETHOD UpdateView(nsIView *aView, const nsRect &aRect, PRUint32 aUpdateFlags);
|
|
|
|
NS_IMETHOD UpdateAllViews(PRUint32 aUpdateFlags);
|
|
|
|
|
2009-07-21 17:44:59 -07:00
|
|
|
NS_IMETHOD DispatchEvent(nsGUIEvent *aEvent,
|
|
|
|
nsIView* aTargetView, nsEventStatus* aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD InsertChild(nsIView *parent, nsIView *child, nsIView *sibling,
|
|
|
|
PRBool above);
|
|
|
|
|
|
|
|
NS_IMETHOD InsertChild(nsIView *parent, nsIView *child,
|
|
|
|
PRInt32 zindex);
|
|
|
|
|
|
|
|
NS_IMETHOD RemoveChild(nsIView *parent);
|
|
|
|
|
|
|
|
NS_IMETHOD MoveViewTo(nsIView *aView, nscoord aX, nscoord aY);
|
|
|
|
|
|
|
|
NS_IMETHOD ResizeView(nsIView *aView, const nsRect &aRect, PRBool aRepaintExposedAreaOnly = PR_FALSE);
|
|
|
|
|
|
|
|
NS_IMETHOD SetViewFloating(nsIView *aView, PRBool aFloating);
|
|
|
|
|
|
|
|
NS_IMETHOD SetViewVisibility(nsIView *aView, nsViewVisibility aVisible);
|
|
|
|
|
|
|
|
NS_IMETHOD SetViewZIndex(nsIView *aView, PRBool aAuto, PRInt32 aZIndex, PRBool aTopMost=PR_FALSE);
|
|
|
|
|
|
|
|
NS_IMETHOD SetViewObserver(nsIViewObserver *aObserver);
|
|
|
|
NS_IMETHOD GetViewObserver(nsIViewObserver *&aObserver);
|
|
|
|
|
|
|
|
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
|
|
|
|
|
2008-01-26 15:59:50 -08:00
|
|
|
virtual nsIViewManager* BeginUpdateViewBatch(void);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD EndUpdateViewBatch(PRUint32 aUpdateFlags);
|
|
|
|
|
2009-07-21 17:45:03 -07:00
|
|
|
NS_IMETHOD GetRootWidget(nsIWidget **aWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD ForceUpdate();
|
|
|
|
|
|
|
|
NS_IMETHOD IsPainting(PRBool& aIsPainting);
|
|
|
|
NS_IMETHOD GetLastUserEventTime(PRUint32& aTime);
|
|
|
|
void ProcessInvalidateEvent();
|
|
|
|
static PRUint32 gLastUserEventTime;
|
|
|
|
|
|
|
|
NS_IMETHOD SynthesizeMouseMove(PRBool aFromScroll);
|
|
|
|
void ProcessSynthMouseMoveEvent(PRBool aFromScroll);
|
|
|
|
|
|
|
|
/* Update the cached RootViewManager pointer on this view manager. */
|
|
|
|
void InvalidateHierarchy();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsViewManager();
|
|
|
|
|
|
|
|
private:
|
2008-02-19 01:16:20 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void FlushPendingInvalidates();
|
|
|
|
void ProcessPendingUpdates(nsView *aView, PRBool aDoInvalidate);
|
2009-10-16 03:55:19 -07:00
|
|
|
/**
|
|
|
|
* Call WillPaint() on all view observers under this vm root.
|
|
|
|
*/
|
|
|
|
void CallWillPaintOnObservers();
|
2007-03-22 10:30:00 -07:00
|
|
|
void ReparentChildWidgets(nsIView* aView, nsIWidget *aNewWidget);
|
|
|
|
void ReparentWidgets(nsIView* aView, nsIView *aParent);
|
2009-07-21 17:45:00 -07:00
|
|
|
void UpdateWidgetArea(nsView *aWidgetView, nsIWidget* aWidget,
|
|
|
|
const nsRegion &aDamagedRegion,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsView* aIgnoreWidgetView);
|
|
|
|
|
|
|
|
void UpdateViews(nsView *aView, PRUint32 aUpdateFlags);
|
|
|
|
|
2010-02-18 11:23:23 -08:00
|
|
|
void TriggerRefresh(PRUint32 aUpdateFlags);
|
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
void Refresh(nsView *aView, nsIWidget *aWidget,
|
|
|
|
const nsIntRegion& aRegion, PRUint32 aUpdateFlags);
|
|
|
|
void RenderViews(nsView *aRootView, nsIWidget *aWidget,
|
2007-05-17 23:02:00 -07:00
|
|
|
const nsRegion& aRegion);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void InvalidateRectDifference(nsView *aView, const nsRect& aRect, const nsRect& aCutOut, PRUint32 aUpdateFlags);
|
|
|
|
void InvalidateHorizontalBandDifference(nsView *aView, const nsRect& aRect, const nsRect& aCutOut,
|
|
|
|
PRUint32 aUpdateFlags, nscoord aY1, nscoord aY2, PRBool aInCutOut);
|
|
|
|
|
|
|
|
// Utilities
|
|
|
|
|
|
|
|
PRBool IsViewInserted(nsView *aView);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to recursively call Update() on all widgets belonging to
|
|
|
|
* a view or its kids.
|
|
|
|
*/
|
|
|
|
void UpdateWidgetsForView(nsView* aView);
|
|
|
|
|
|
|
|
/**
|
2008-07-21 01:24:38 -07:00
|
|
|
* Transforms a rectangle from aView's coordinate system to the coordinate
|
|
|
|
* system of the widget attached to aWidgetView, which should be an ancestor
|
|
|
|
* of aView.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect ViewToWidget(nsView *aView, nsView* aWidgetView, const nsRect &aRect) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void DoSetWindowDimensions(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
nsRect oldDim;
|
|
|
|
nsRect newDim(0, 0, aWidth, aHeight);
|
|
|
|
mRootView->GetDimensions(oldDim);
|
2008-09-08 06:41:36 -07:00
|
|
|
// We care about resizes even when one dimension is already zero.
|
|
|
|
if (!oldDim.IsExactEqual(newDim)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't resize the widget. It is already being set elsewhere.
|
|
|
|
mRootView->SetDimensions(newDim, PR_TRUE, PR_FALSE);
|
|
|
|
if (mObserver)
|
|
|
|
mObserver->ResizeReflow(mRootView, aWidth, aHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Safety helpers
|
|
|
|
void IncrementUpdateCount() {
|
|
|
|
NS_ASSERTION(IsRootVM(),
|
|
|
|
"IncrementUpdateCount called on non-root viewmanager");
|
|
|
|
++mUpdateCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecrementUpdateCount() {
|
|
|
|
NS_ASSERTION(IsRootVM(),
|
|
|
|
"DecrementUpdateCount called on non-root viewmanager");
|
|
|
|
--mUpdateCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 UpdateCount() const {
|
|
|
|
NS_ASSERTION(IsRootVM(),
|
|
|
|
"DecrementUpdateCount called on non-root viewmanager");
|
|
|
|
return mUpdateCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearUpdateCount() {
|
|
|
|
NS_ASSERTION(IsRootVM(),
|
|
|
|
"DecrementUpdateCount called on non-root viewmanager");
|
|
|
|
mUpdateCnt = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool IsPainting() const {
|
|
|
|
return RootViewManager()->mPainting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPainting(PRBool aPainting) {
|
|
|
|
RootViewManager()->mPainting = aPainting;
|
|
|
|
}
|
|
|
|
|
|
|
|
public: // NOT in nsIViewManager, so private to the view module
|
|
|
|
nsView* GetRootView() const { return mRootView; }
|
|
|
|
nsViewManager* RootViewManager() const { return mRootViewManager; }
|
|
|
|
PRBool IsRootVM() const { return this == RootViewManager(); }
|
|
|
|
|
2010-06-05 13:29:49 -07:00
|
|
|
nsEventStatus HandleEvent(nsView* aView, nsGUIEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-10-07 20:01:15 -07:00
|
|
|
virtual nsresult WillBitBlit(nsIView* aView, const nsRect& aRect,
|
|
|
|
nsPoint aScrollAmount);
|
|
|
|
virtual void UpdateViewAfterScroll(nsIView *aView,
|
|
|
|
const nsRegion& aUpdateRegion);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult CreateRegion(nsIRegion* *result);
|
|
|
|
|
2010-02-18 11:23:23 -08:00
|
|
|
PRBool IsRefreshEnabled() { return RootViewManager()->mUpdateBatchCnt == 0; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIViewObserver* GetViewObserver() { return mObserver; }
|
|
|
|
|
|
|
|
// Call this when you need to let the viewmanager know that it now has
|
|
|
|
// pending updates.
|
|
|
|
void PostPendingUpdate() { RootViewManager()->mHasPendingUpdates = PR_TRUE; }
|
2010-06-05 13:29:49 -07:00
|
|
|
|
|
|
|
PRInt32 AppUnitsPerDevPixel() const
|
|
|
|
{
|
|
|
|
return mContext->AppUnitsPerDevPixel();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2009-11-17 16:38:16 -08:00
|
|
|
nsCOMPtr<nsIDeviceContext> mContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIViewObserver *mObserver;
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint mMouseLocation; // device units, relative to mRootView
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The size for a resize that we delayed until the root view becomes
|
|
|
|
// visible again.
|
|
|
|
nsSize mDelayedResize;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFactory> mRegionFactory;
|
|
|
|
nsView *mRootView;
|
|
|
|
// mRootViewManager is a strong ref unless it equals |this|. It's
|
|
|
|
// never null (if we have no ancestors, it will be |this|).
|
|
|
|
nsViewManager *mRootViewManager;
|
|
|
|
|
|
|
|
nsRevocableEventPtr<nsViewManagerEvent> mSynthMouseMoveEvent;
|
|
|
|
nsRevocableEventPtr<nsViewManagerEvent> mInvalidateEvent;
|
|
|
|
|
|
|
|
// The following members should not be accessed directly except by
|
|
|
|
// the root view manager. Some have accessor functions to enforce
|
|
|
|
// this, as noted.
|
|
|
|
|
|
|
|
// Use IncrementUpdateCount(), DecrementUpdateCount(), UpdateCount(),
|
|
|
|
// ClearUpdateCount() on the root viewmanager to access mUpdateCnt.
|
|
|
|
PRInt32 mUpdateCnt;
|
|
|
|
PRInt32 mUpdateBatchCnt;
|
|
|
|
PRUint32 mUpdateBatchFlags;
|
|
|
|
PRInt32 mScrollCnt;
|
|
|
|
// Use IsPainting() and SetPainting() to access mPainting.
|
|
|
|
PRPackedBool mPainting;
|
|
|
|
PRPackedBool mRecursiveRefreshPending;
|
|
|
|
PRPackedBool mHasPendingUpdates;
|
|
|
|
PRPackedBool mInScroll;
|
|
|
|
|
|
|
|
//from here to public should be static and locked... MMP
|
|
|
|
static PRInt32 mVMCount; //number of viewmanagers
|
|
|
|
|
|
|
|
//list of view managers
|
|
|
|
static nsVoidArray *gViewManagers;
|
|
|
|
|
|
|
|
void PostInvalidateEvent();
|
|
|
|
};
|
|
|
|
|
|
|
|
//when the refresh happens, should it be double buffered?
|
|
|
|
#define NS_VMREFRESH_DOUBLE_BUFFER 0x0001
|
|
|
|
|
|
|
|
#endif /* nsViewManager_h___ */
|