diff --git a/editor/base/nsEditor.cpp b/editor/base/nsEditor.cpp index d84bb1c1486..283f9f24f7f 100644 --- a/editor/base/nsEditor.cpp +++ b/editor/base/nsEditor.cpp @@ -3250,9 +3250,9 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, result = node->GetParentNode(getter_AddRefs(parent)); if ((NS_SUCCEEDED(result)) && parent) { - if (bNoBlockCrossing && IsBlockNode(parent)) + if ((bNoBlockCrossing && IsBlockNode(parent)) || IsRootNode(parent)) { - // we are at front of block, do not step out + // we are at front of block or root, do not step out *aResultNode = nsnull; return result; } @@ -3341,9 +3341,9 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, result = node->GetParentNode(getter_AddRefs(parent)); if ((NS_SUCCEEDED(result)) && parent) { - if (bNoBlockCrossing && IsBlockNode(parent)) + if ((bNoBlockCrossing && IsBlockNode(parent)) || IsRootNode(parent)) { - // we are at front of block, do not step out + // we are at end of block or root, do not step out *aResultNode = nsnull; return result; } @@ -3522,6 +3522,24 @@ nsEditor::TagCanContainTag(const nsAReadableString &aParentTag, const nsAReadabl return mDTD->CanContain(parentTagEnum, childTagEnum); } +PRBool +nsEditor::IsRootNode(nsIDOMNode *inNode) +{ + if (!inNode) + return PR_FALSE; + + nsCOMPtr rootElement; + + nsresult result = GetRootElement(getter_AddRefs(rootElement)); + + if (NS_FAILED(result) || !rootElement) + return PR_FALSE; + + nsCOMPtr rootNode = do_QueryInterface(rootElement); + + return inNode == rootNode.get(); +} + PRBool nsEditor::IsDescendantOfBody(nsIDOMNode *inNode) { diff --git a/editor/base/nsEditor.h b/editor/base/nsEditor.h index e4318215e90..ffe3211e0dc 100644 --- a/editor/base/nsEditor.h +++ b/editor/base/nsEditor.h @@ -461,6 +461,9 @@ public: PRBool TagCanContain(const nsAReadableString &aParentTag, nsIDOMNode* aChild); virtual PRBool TagCanContainTag(const nsAReadableString &aParentTag, const nsAReadableString &aChildTag); + /** returns PR_TRUE if aNode is our root node */ + PRBool IsRootNode(nsIDOMNode *inNode); + /** returns PR_TRUE if aNode is a descendant of our root node */ PRBool IsDescendantOfBody(nsIDOMNode *inNode); diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index d84bb1c1486..283f9f24f7f 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -3250,9 +3250,9 @@ nsEditor::GetPriorNode(nsIDOMNode *aCurrentNode, result = node->GetParentNode(getter_AddRefs(parent)); if ((NS_SUCCEEDED(result)) && parent) { - if (bNoBlockCrossing && IsBlockNode(parent)) + if ((bNoBlockCrossing && IsBlockNode(parent)) || IsRootNode(parent)) { - // we are at front of block, do not step out + // we are at front of block or root, do not step out *aResultNode = nsnull; return result; } @@ -3341,9 +3341,9 @@ nsEditor::GetNextNode(nsIDOMNode *aCurrentNode, result = node->GetParentNode(getter_AddRefs(parent)); if ((NS_SUCCEEDED(result)) && parent) { - if (bNoBlockCrossing && IsBlockNode(parent)) + if ((bNoBlockCrossing && IsBlockNode(parent)) || IsRootNode(parent)) { - // we are at front of block, do not step out + // we are at end of block or root, do not step out *aResultNode = nsnull; return result; } @@ -3522,6 +3522,24 @@ nsEditor::TagCanContainTag(const nsAReadableString &aParentTag, const nsAReadabl return mDTD->CanContain(parentTagEnum, childTagEnum); } +PRBool +nsEditor::IsRootNode(nsIDOMNode *inNode) +{ + if (!inNode) + return PR_FALSE; + + nsCOMPtr rootElement; + + nsresult result = GetRootElement(getter_AddRefs(rootElement)); + + if (NS_FAILED(result) || !rootElement) + return PR_FALSE; + + nsCOMPtr rootNode = do_QueryInterface(rootElement); + + return inNode == rootNode.get(); +} + PRBool nsEditor::IsDescendantOfBody(nsIDOMNode *inNode) { diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index e4318215e90..ffe3211e0dc 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -461,6 +461,9 @@ public: PRBool TagCanContain(const nsAReadableString &aParentTag, nsIDOMNode* aChild); virtual PRBool TagCanContainTag(const nsAReadableString &aParentTag, const nsAReadableString &aChildTag); + /** returns PR_TRUE if aNode is our root node */ + PRBool IsRootNode(nsIDOMNode *inNode); + /** returns PR_TRUE if aNode is a descendant of our root node */ PRBool IsDescendantOfBody(nsIDOMNode *inNode);