From 5cf9105b700baba117e3303dcb1662401471ccab Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Wed, 5 Jul 2000 23:12:35 +0000 Subject: [PATCH] take into account the scroll position of the tree's view when computing frame-relative mouse coordinates. r=damn bug 43405 --- .../xul/base/src/nsTreeItemDragCapturer.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/layout/xul/base/src/nsTreeItemDragCapturer.cpp b/layout/xul/base/src/nsTreeItemDragCapturer.cpp index 0324196ffb3d..c4ffe5297e97 100644 --- a/layout/xul/base/src/nsTreeItemDragCapturer.cpp +++ b/layout/xul/base/src/nsTreeItemDragCapturer.cpp @@ -36,6 +36,7 @@ #include "nsIDocument.h" #include "nsIPresShell.h" #include "nsIDOMEventTarget.h" +#include "nsIView.h" NS_IMPL_ADDREF(nsTreeItemDragCapturer) @@ -138,7 +139,7 @@ nsTreeItemDragCapturer :: ComputeDropPosition ( nsIDOMEvent* aDragEvent, nscoord mTreeItem->FirstChild(mPresContext, nsnull, &rowFrame); NS_ASSERTION ( rowFrame, "couldn't get rowGroup's row frame" ); rowFrame->GetRect(rowRect); - + // compute the offset to top level in twips float t2p; mPresContext->GetTwipsToPixels(&t2p); @@ -154,10 +155,20 @@ nsTreeItemDragCapturer :: ComputeDropPosition ( nsIDOMEvent* aDragEvent, nscoord } // until we reach the top // subtract the offset from the mouse coord to put it into row relative coordinates. - xp -= frameOffsetX; - yp -= frameOffsetY; nsPoint pnt(xp, yp); + pnt.MoveBy ( -frameOffsetX, -frameOffsetY ); + // Find the tree's view and take it's scroll position into account + nsIView *containingView = nsnull; + nsPoint unusedOffset(0,0); + mTreeItem->GetOffsetFromView(mPresContext, unusedOffset, &containingView); + NS_ASSERTION(containingView, "No containing view!"); + if ( !containingView ) + return; + nscoord viewOffsetToParentX = 0, viewOffsetToParentY = 0; + containingView->GetPosition ( &viewOffsetToParentX, &viewOffsetToParentY ); + pnt.MoveBy ( -viewOffsetToParentX, -viewOffsetToParentY ); + // now check if item is a container PRBool isContainer = PR_FALSE; nsCOMPtr treeItemContent; @@ -170,7 +181,7 @@ nsTreeItemDragCapturer :: ComputeDropPosition ( nsIDOMEvent* aDragEvent, nscoord } else NS_WARNING("Not a DOM element"); - + // if we have a container, the area is broken up into 3 pieces (top, middle, bottom). If // it isn't it's only broken up into two (top and bottom) if ( isContainer ) {