mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-14 04:03:47 +00:00
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.
This commit is contained in:
parent
bc48be7cc5
commit
2bb2f10650
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user