From 6f9f127fbd159078a8eabe943d24219eeea1fa46 Mon Sep 17 00:00:00 2001 From: "kin%netscape.com" Date: Wed, 29 Aug 2001 21:33:52 +0000 Subject: [PATCH] Fix for bug 83607: too much backspace segfaults mozilla in textbox forms Prevent GetPriorNode() and GetNextNode() from traversing above root node when aCurrentNode is the rootNode. r=brade@netscape.com sr=sfraser@netscape.com a=asa@mozilla.org git-svn-id: svn://10.0.0.236/trunk@101968 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditor.cpp | 20 +++++++++++++++++++- mozilla/editor/libeditor/base/nsEditor.cpp | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index 283f9f24f7f..beac9ccda37 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -3211,6 +3211,15 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, *aResultNode = nsnull; // init out-param + if (IsRootNode(aCurrentNode)) + { + // Don't allow traversal above the root node! This helps + // prevent us from accidentally editing browser content + // when the editor is in a text widget. + + return NS_OK; + } + // if aCurrentNode has a left sibling, return that sibling's rightmost child (or itself if it has no children) nsCOMPtr prevSibling; result = aCurrentNode->GetPreviousSibling(getter_AddRefs(prevSibling)); @@ -3300,7 +3309,16 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, if (!aCurrentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; } *aResultNode = nsnull; // init out-param - + + if (IsRootNode(aCurrentNode)) + { + // Don't allow traversal above the root node! This helps + // prevent us from accidentally editing browser content + // when the editor is in a text widget. + + return NS_OK; + } + // if aCurrentNode has a right sibling, return that sibling's leftmost child (or itself if it has no children) nsCOMPtr nextSibling; result = aCurrentNode->GetNextSibling(getter_AddRefs(nextSibling)); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index 283f9f24f7f..beac9ccda37 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -3211,6 +3211,15 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, *aResultNode = nsnull; // init out-param + if (IsRootNode(aCurrentNode)) + { + // Don't allow traversal above the root node! This helps + // prevent us from accidentally editing browser content + // when the editor is in a text widget. + + return NS_OK; + } + // if aCurrentNode has a left sibling, return that sibling's rightmost child (or itself if it has no children) nsCOMPtr prevSibling; result = aCurrentNode->GetPreviousSibling(getter_AddRefs(prevSibling)); @@ -3300,7 +3309,16 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, if (!aCurrentNode || !aResultNode) { return NS_ERROR_NULL_POINTER; } *aResultNode = nsnull; // init out-param - + + if (IsRootNode(aCurrentNode)) + { + // Don't allow traversal above the root node! This helps + // prevent us from accidentally editing browser content + // when the editor is in a text widget. + + return NS_OK; + } + // if aCurrentNode has a right sibling, return that sibling's leftmost child (or itself if it has no children) nsCOMPtr nextSibling; result = aCurrentNode->GetNextSibling(getter_AddRefs(nextSibling));