From 2bb2f10650be1dc9016b140597164ca61ea97a41 Mon Sep 17 00:00:00 2001 From: michaelp Date: Mon, 27 Apr 1998 23:51:57 +0000 Subject: [PATCH] added support for setting clip rects in views. removed paint_all_kids(). damage rect passed to frames is now properly translated into coord space of containing view. --- view/public/nsIView.h | 2 +- view/src/nsView.cpp | 66 +++++++++++++++++++++++++++++++++++--- view/src/nsView.h | 4 ++- view/src/nsViewManager.cpp | 37 +-------------------- 4 files changed, 67 insertions(+), 42 deletions(-) diff --git a/view/public/nsIView.h b/view/public/nsIView.h index 60562cad3a28..43dc63c570a1 100644 --- a/view/public/nsIView.h +++ b/view/public/nsIView.h @@ -208,7 +208,7 @@ public: * @param aClip out parameter for bounds * @result PR_TRUE of there actually is a clip for the view, else PR_FALSE */ - virtual PRBool GetClip(nsRect *aClip) = 0; + virtual PRBool GetClip(nsRect &aClip) = 0; /** * Called to indicate that the visibility of a view has been diff --git a/view/src/nsView.cpp b/view/src/nsView.cpp index 8eb239a1eafd..d177531f84aa 100644 --- a/view/src/nsView.cpp +++ b/view/src/nsView.cpp @@ -266,6 +266,8 @@ nsresult nsView :: Init(nsIViewManager* aManager, NS_ADDREF(aManager); mBounds = aBounds; + mContainerRect = aBounds; + mClipRect.Empty(); // assign the parent view SetParent(aParent); @@ -320,14 +322,52 @@ nsIWidget * nsView :: GetWidget() void nsView :: Paint(nsIRenderingContext& rc, const nsRect& rect) { + rc.PushState(); + rc.Translate(mBounds.x, mBounds.y); + + if (mClipRect.IsEmpty() == PR_FALSE) + { + nsRect trect; + + trect.x = mClipRect.x; + trect.y = mClipRect.y; + trect.width = (mClipRect.width - mClipRect.x) + 1; + trect.height = (mClipRect.height - mClipRect.y) + 1; + + rc.SetClipRect(trect, PR_TRUE); + } + if (nsnull != mFrame) { nsIPresContext *cx = mViewManager->GetPresContext(); - mFrame->Paint(*cx, rc, rect); - NS_RELEASE(cx); } + + PRInt32 numkids = GetChildCount(); + + for (PRInt32 cnt = 0; cnt < numkids; cnt++) + { + nsIView *kid = GetChild(cnt); + + if (nsnull != kid) + { + nsRect kidRect; + kid->GetBounds(kidRect); + nsRect damageArea; + PRBool overlap = damageArea.IntersectRect(rect, kidRect); + + if (overlap == PR_TRUE) + { + // Translate damage area into kid's coordinate system + nsRect kidDamageArea(damageArea.x - kidRect.x, damageArea.y - kidRect.y, + damageArea.width, damageArea.height); + kid->Paint(rc, kidDamageArea); + } + } + } + + rc.PopState(); } void nsView :: Paint(nsIRenderingContext& rc, const nsRegion& region) @@ -535,15 +575,33 @@ void nsView :: GetBounds(nsRect &aBounds) void nsView :: SetClip(const nsRect &aClip) { + mClipRect.x = aClip.x; + mClipRect.y = aClip.y; + mClipRect.width = aClip.width; + mClipRect.width = aClip.height; } void nsView :: SetClip(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight) { + mClipRect.x = aX; + mClipRect.y = aY; + mClipRect.width = aWidth; + mClipRect.width = aHeight; } -PRBool nsView :: GetClip(nsRect *aClip) +PRBool nsView :: GetClip(nsRect& aClip) { - return PR_FALSE; + if (mClipRect.IsEmpty() == PR_TRUE) + return PR_FALSE; + else + { + aClip.x = mClipRect.x; + aClip.y = mClipRect.y; + aClip.width = mClipRect.width; + aClip.width = mClipRect.height; + + return PR_TRUE; + } } void nsView :: SetVisibility(nsViewVisibility aVisibility) diff --git a/view/src/nsView.h b/view/src/nsView.h index 491aa240ecd5..edcfd75289c7 100644 --- a/view/src/nsView.h +++ b/view/src/nsView.h @@ -68,7 +68,7 @@ public: virtual void GetBounds(nsRect &aBounds); virtual void SetClip(const nsRect &aClip); virtual void SetClip(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); - virtual PRBool GetClip(nsRect *aClip); + virtual PRBool GetClip(nsRect& aClip); virtual void SetVisibility(nsViewVisibility visibility); virtual nsViewVisibility GetVisibility(); virtual void SetZIndex(PRInt32 zindex); @@ -117,6 +117,8 @@ protected: nsViewVisibility mVis; PRInt32 mNumKids; nsRect mBounds; + nsRect mClipRect; + nsRect mContainerRect; }; #endif diff --git a/view/src/nsViewManager.cpp b/view/src/nsViewManager.cpp index 82b9841cc53c..33f981ec56db 100644 --- a/view/src/nsViewManager.cpp +++ b/view/src/nsViewManager.cpp @@ -231,41 +231,6 @@ void nsViewManager :: Refresh(nsIRenderingContext *aContext, nsRegion *region, P { } -static void paint_all_kids(nsIRenderingContext *context, nsIView *par, nsRect *rect) -{ - nsIView *kid; - - if (gsDebug) - { - printf("ViewManager::Refresh: view=%p painting twips=(%d, %d, %d, %d) pixels: ", - par, rect->x, rect->y, rect->XMost(), rect->YMost()); - stdout << *rect; - printf("\n"); - } - - nsRect parbounds; - - par->GetBounds(parbounds); - - context->PushState(); - context->Translate(parbounds.x, parbounds.y); - - par->Paint(*context, *rect); - - if (par->GetChildCount() > 0) - { - kid = par->GetChild(0); - - while (nsnull != kid) - { - paint_all_kids(context, kid, rect); - kid = kid->GetNextSibling(); - } - } - - context->PopState(); -} - void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsRect *rect, PRUint32 aUpdateFlags) { nsRect wrect; @@ -302,7 +267,7 @@ void nsViewManager :: Refresh(nsIView *aView, nsIRenderingContext *aContext, nsR else localcx->SetClipRect(trect, PR_FALSE); - paint_all_kids(localcx, aView, &trect); + aView->Paint(*localcx, trect); if (aUpdateFlags & NS_VMREFRESH_DOUBLE_BUFFER) localcx->CopyOffScreenBits(wrect);