From fdc84978d89b4dc4127e0ef611f0facaf7b23e54 Mon Sep 17 00:00:00 2001 From: "michaelp%netscape.com" Date: Fri, 16 Apr 1999 04:50:02 +0000 Subject: [PATCH] added GetExtents(). --- view/public/nsIView.h | 8 ++++++++ view/src/nsView.cpp | 34 ++++++++++++++++++++++++++++++++++ view/src/nsView.h | 1 + 3 files changed, 43 insertions(+) diff --git a/view/public/nsIView.h b/view/public/nsIView.h index 14678fe98c4d..4b435ea4fa71 100644 --- a/view/public/nsIView.h +++ b/view/public/nsIView.h @@ -452,6 +452,14 @@ public: */ NS_IMETHOD GetScratchPoint(nsPoint **aPoint) = 0; + /** + * Get the extents of the view tree from 'this' down. + * 'this' is the coordinate system origin. + * @param aExtents out paramemter for extents + * @return error status + */ + NS_IMETHOD GetExtents(nsRect *aExtents) = 0; + private: NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt) Release(void) = 0; diff --git a/view/src/nsView.cpp b/view/src/nsView.cpp index 9216be74069c..edd23caa8dad 100644 --- a/view/src/nsView.cpp +++ b/view/src/nsView.cpp @@ -1371,3 +1371,37 @@ NS_IMETHODIMP nsView :: GetScratchPoint(nsPoint **aPoint) return NS_OK; } + +static void calc_extents(nsIView *view, nsRect *extents, nscoord ox, nscoord oy) +{ + nsIView *kid; + PRInt32 numkids, cnt; + nsRect bounds; + + view->GetChildCount(numkids); + + for (cnt = 0; cnt < numkids; cnt++) + { + view->GetChild(cnt, kid); + kid->GetBounds(bounds); + + bounds.x += ox; + bounds.y += oy; + + extents->IntersectRect(*extents, bounds); + + calc_extents(kid, extents, bounds.x, bounds.y); + } +} + +NS_IMETHODIMP nsView :: GetExtents(nsRect *aExtents) +{ + GetBounds(*aExtents); + + aExtents->x = 0; + aExtents->y = 0; + + calc_extents(this, aExtents, 0, 0); + + return NS_OK; +} diff --git a/view/src/nsView.h b/view/src/nsView.h index 4ef2573dca37..5f1da5e4f56b 100644 --- a/view/src/nsView.h +++ b/view/src/nsView.h @@ -97,6 +97,7 @@ public: NS_IMETHOD ClearViewFlags(PRUint32 aFlags); NS_IMETHOD GetViewFlags(PRUint32 *aFlags); NS_IMETHOD GetScratchPoint(nsPoint **aPoint); + NS_IMETHOD GetExtents(nsRect *aExtents); // Helper function to get the view that's associated with a widget static nsIView* GetViewFor(nsIWidget* aWidget);