From ad217f921da523c59ff76024ee272b5aa8efe970 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 16 Mar 2012 12:56:54 -0400 Subject: [PATCH] Bug 719523 - Selection.selectAllChildren() on a Document always produces end offset of 1; r=ehsan --- layout/generic/nsSelection.cpp | 42 ++++++------------------- layout/generic/test/Makefile.in | 1 + layout/generic/test/test_bug719523.html | 20 ++++++++++++ 3 files changed, 31 insertions(+), 32 deletions(-) create mode 100644 layout/generic/test/test_bug719523.html diff --git a/layout/generic/nsSelection.cpp b/layout/generic/nsSelection.cpp index 813809c95b5e..78ac52c96f8e 100644 --- a/layout/generic/nsSelection.cpp +++ b/layout/generic/nsSelection.cpp @@ -5283,47 +5283,25 @@ nsTypedSelection::Extend(nsINode* aParentNode, PRInt32 aOffset) return mFrameSelection->NotifySelectionListeners(GetType()); } -static nsresult -GetChildOffset(nsIDOMNode *aChild, nsIDOMNode *aParent, PRInt32 &aOffset) -{ - NS_ASSERTION((aChild && aParent), "bad args"); - nsCOMPtr content = do_QueryInterface(aParent); - nsCOMPtr cChild = do_QueryInterface(aChild); - - if (!cChild || !content) - return NS_ERROR_NULL_POINTER; - - aOffset = content->IndexOf(cChild); - - return NS_OK; -} - NS_IMETHODIMP nsTypedSelection::SelectAllChildren(nsIDOMNode* aParentNode) { NS_ENSURE_ARG_POINTER(aParentNode); - - if (mFrameSelection) + nsCOMPtr node = do_QueryInterface(aParentNode); + + if (mFrameSelection) { mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON); } - nsresult result = Collapse(aParentNode, 0); - if (NS_SUCCEEDED(result)) + nsresult result = Collapse(node, 0); + if (NS_FAILED(result)) + return result; + + if (mFrameSelection) { - nsCOMPtrlastChild; - result = aParentNode->GetLastChild(getter_AddRefs(lastChild)); - if ((NS_SUCCEEDED(result)) && lastChild) - { - PRInt32 numBodyChildren=0; - GetChildOffset(lastChild, aParentNode, numBodyChildren); - if (mFrameSelection) - { - mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON); - } - result = Extend(aParentNode, numBodyChildren+1); - } + mFrameSelection->PostReason(nsISelectionListener::SELECTALL_REASON); } - return result; + return Extend(node, node->GetChildCount()); } NS_IMETHODIMP diff --git a/layout/generic/test/Makefile.in b/layout/generic/test/Makefile.in index e85ba2e4675e..d82d465f221a 100644 --- a/layout/generic/test/Makefile.in +++ b/layout/generic/test/Makefile.in @@ -130,6 +130,7 @@ _TEST_FILES = \ test_bug719503.html \ test_bug719515.html \ test_bug719518.html \ + test_bug719523.html \ $(NULL) _CHROME_FILES = \ diff --git a/layout/generic/test/test_bug719523.html b/layout/generic/test/test_bug719523.html new file mode 100644 index 000000000000..ff6da72102e4 --- /dev/null +++ b/layout/generic/test/test_bug719523.html @@ -0,0 +1,20 @@ + + + +Test for Bug 719523 + + +Mozilla Bug 719523 +

+ +
+