From d58d23067a512f803c331dff52869c1b2f2eba05 Mon Sep 17 00:00:00 2001 From: "joki%netscape.com" Date: Thu, 9 Mar 2000 15:31:44 +0000 Subject: [PATCH] Fix bug 29515, prevent excess processing inside GetFrameForPoint. a:rickg, r:dbaron@fas.harvard.edu git-svn-id: svn://10.0.0.236/trunk@62473 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsContainerFrame.cpp | 40 +++++++++++-------- .../layout/html/base/src/nsContainerFrame.cpp | 40 +++++++++++-------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/mozilla/layout/generic/nsContainerFrame.cpp b/mozilla/layout/generic/nsContainerFrame.cpp index cf564c4b41d..73a7612f205 100644 --- a/mozilla/layout/generic/nsContainerFrame.cpp +++ b/mozilla/layout/generic/nsContainerFrame.cpp @@ -257,6 +257,7 @@ nsContainerFrame::GetFrameForPointUsing(nsIPresContext* aPresContext, *aFrame = this; nsIFrame *childFrame = 0; + nsresult rv = NS_ERROR_FAILURE; // Attempt to find the first child that contains the desired // point. We try to use a quick check on the child frames bbox to @@ -271,7 +272,7 @@ nsContainerFrame::GetFrameForPointUsing(nsIPresContext* aPresContext, // contains the point. tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); - nsresult rv = kid->GetFrameForPoint(aPresContext, tmp, aFrame); + rv = kid->GetFrameForPoint(aPresContext, tmp, aFrame); if (NS_SUCCEEDED(rv) && *aFrame) { // We found the target frame somewhere in the child frame. @@ -287,23 +288,30 @@ nsContainerFrame::GetFrameForPointUsing(nsIPresContext* aPresContext, kid->GetNextSibling(&kid); } - // Try again, this time looking only inside child frames that have - // outside children. - FirstChild(aPresContext, aList, &kid); - while (nsnull != kid) { - nsFrameState state; - kid->GetFrameState(&state); - if (NS_FRAME_OUTSIDE_CHILDREN & state) { - kid->GetRect(kidRect); - tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); - if (NS_OK == kid->GetFrameForPoint(aPresContext, tmp, aFrame)) { - return NS_OK; - } - else { - *aFrame = this; + //Only keep looking outside if we didn't absolutely find a child leaf node. + //This is indicated by the successful return from GetFrameForPoint. If we + //only found a container frame we'll have set childFrame to our best guess + //at a container frame but rv will still have failed so we should go on + //looking for the correct leaf frame in the outside children. + if (NS_FAILED(rv)) { + // Try again, this time looking only inside child frames that have + // outside children. + FirstChild(aPresContext, aList, &kid); + while (nsnull != kid) { + nsFrameState state; + kid->GetFrameState(&state); + if (NS_FRAME_OUTSIDE_CHILDREN & state) { + kid->GetRect(kidRect); + tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); + if (NS_OK == kid->GetFrameForPoint(aPresContext, tmp, aFrame)) { + return NS_OK; + } + else { + *aFrame = this; + } } + kid->GetNextSibling(&kid); } - kid->GetNextSibling(&kid); } if (childFrame) { diff --git a/mozilla/layout/html/base/src/nsContainerFrame.cpp b/mozilla/layout/html/base/src/nsContainerFrame.cpp index cf564c4b41d..73a7612f205 100644 --- a/mozilla/layout/html/base/src/nsContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsContainerFrame.cpp @@ -257,6 +257,7 @@ nsContainerFrame::GetFrameForPointUsing(nsIPresContext* aPresContext, *aFrame = this; nsIFrame *childFrame = 0; + nsresult rv = NS_ERROR_FAILURE; // Attempt to find the first child that contains the desired // point. We try to use a quick check on the child frames bbox to @@ -271,7 +272,7 @@ nsContainerFrame::GetFrameForPointUsing(nsIPresContext* aPresContext, // contains the point. tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); - nsresult rv = kid->GetFrameForPoint(aPresContext, tmp, aFrame); + rv = kid->GetFrameForPoint(aPresContext, tmp, aFrame); if (NS_SUCCEEDED(rv) && *aFrame) { // We found the target frame somewhere in the child frame. @@ -287,23 +288,30 @@ nsContainerFrame::GetFrameForPointUsing(nsIPresContext* aPresContext, kid->GetNextSibling(&kid); } - // Try again, this time looking only inside child frames that have - // outside children. - FirstChild(aPresContext, aList, &kid); - while (nsnull != kid) { - nsFrameState state; - kid->GetFrameState(&state); - if (NS_FRAME_OUTSIDE_CHILDREN & state) { - kid->GetRect(kidRect); - tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); - if (NS_OK == kid->GetFrameForPoint(aPresContext, tmp, aFrame)) { - return NS_OK; - } - else { - *aFrame = this; + //Only keep looking outside if we didn't absolutely find a child leaf node. + //This is indicated by the successful return from GetFrameForPoint. If we + //only found a container frame we'll have set childFrame to our best guess + //at a container frame but rv will still have failed so we should go on + //looking for the correct leaf frame in the outside children. + if (NS_FAILED(rv)) { + // Try again, this time looking only inside child frames that have + // outside children. + FirstChild(aPresContext, aList, &kid); + while (nsnull != kid) { + nsFrameState state; + kid->GetFrameState(&state); + if (NS_FRAME_OUTSIDE_CHILDREN & state) { + kid->GetRect(kidRect); + tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y); + if (NS_OK == kid->GetFrameForPoint(aPresContext, tmp, aFrame)) { + return NS_OK; + } + else { + *aFrame = this; + } } + kid->GetNextSibling(&kid); } - kid->GetNextSibling(&kid); } if (childFrame) {