From af6f3b8e45728f80d3321d9f180b20b108942d30 Mon Sep 17 00:00:00 2001 From: "martijn.martijn%gmail.com" Date: Thu, 13 Apr 2006 15:40:52 +0000 Subject: [PATCH] Bug 333136 - scrollSelectionIntoView should try to scroll the complete selection into view, r+sr=roc git-svn-id: svn://10.0.0.236/trunk@194315 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/generic/nsSelection.cpp | 42 +++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index c7186c7b37a..20cbd39fb46 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -7150,10 +7150,22 @@ nsTypedSelection::ScrollIntoView(SelectionRegion aRegion, PRBool aIsSynchronous) // Scroll the selection region into view. // - nsRect rect; - nsIScrollableView *scrollableView = 0; + nsRect anchorRect; + nsIScrollableView *anchorScrollableView = 0; - result = GetSelectionRegionRectAndScrollableView(aRegion, &rect, &scrollableView); + result = GetSelectionRegionRectAndScrollableView( + nsISelectionController::SELECTION_ANCHOR_REGION, + &anchorRect, &anchorScrollableView); + + if (NS_FAILED(result)) + return result; + + nsRect focusRect; + nsIScrollableView *focusScrollableView = 0; + + result = GetSelectionRegionRectAndScrollableView( + nsISelectionController::SELECTION_FOCUS_REGION, + &focusRect, &focusScrollableView); if (NS_FAILED(result)) return result; @@ -7161,10 +7173,30 @@ nsTypedSelection::ScrollIntoView(SelectionRegion aRegion, PRBool aIsSynchronous) // // It's ok if we don't have a scrollable view, just return early. // - if (!scrollableView) + if (!anchorScrollableView && !focusScrollableView) return NS_OK; - result = ScrollRectIntoView(scrollableView, rect, NS_PRESSHELL_SCROLL_ANYWHERE, NS_PRESSHELL_SCROLL_ANYWHERE, PR_TRUE); + if (anchorScrollableView == focusScrollableView) { + nsRect newRect; + newRect.UnionRect(focusRect, anchorRect); + + result = ScrollRectIntoView(anchorScrollableView, newRect, + NS_PRESSHELL_SCROLL_ANYWHERE, + NS_PRESSHELL_SCROLL_ANYWHERE, PR_TRUE); + } + + if (anchorScrollableView && + aRegion == nsISelectionController::SELECTION_ANCHOR_REGION) { + result = ScrollRectIntoView(anchorScrollableView, anchorRect, + NS_PRESSHELL_SCROLL_ANYWHERE, + NS_PRESSHELL_SCROLL_ANYWHERE, PR_TRUE); + } + if (focusScrollableView && + aRegion == nsISelectionController::SELECTION_FOCUS_REGION) { + result = ScrollRectIntoView(focusScrollableView, focusRect, + NS_PRESSHELL_SCROLL_ANYWHERE, + NS_PRESSHELL_SCROLL_ANYWHERE, PR_TRUE); + } } return result; }