From 5e6b533bf5a19f67d51529fc75b01267cd8eb9b2 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 3 Oct 2012 21:25:00 -0400 Subject: [PATCH] Bug 796839 - Part 4: Don't pretend that empty text nodes are not editable; r=roc This is the real fix for this bug. Previously we mistakenly thought that if a text node is empty (or has only whitespace content), it is not editable. This patch removes that check completely and makes us treat text nodes the same way that we treat element nodes. --- editor/libeditor/base/nsEditor.cpp | 17 +---------------- editor/libeditor/base/nsEditor.h | 5 ----- editor/libeditor/html/nsHTMLEditor.cpp | 17 ----------------- editor/libeditor/html/nsHTMLEditor.h | 5 ----- editor/libeditor/html/tests/Makefile.in | 1 + editor/libeditor/html/tests/test_bug796839.html | 17 +++++++++++++++++ 6 files changed, 19 insertions(+), 43 deletions(-) create mode 100644 editor/libeditor/html/tests/test_bug796839.html diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 38f64bdb335..1e1c5bcb5ff 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -3641,20 +3641,6 @@ nsEditor::IsContainer(nsIDOMNode *aNode) return aNode ? true : false; } -bool -nsEditor::IsTextInDirtyFrameVisible(nsIContent *aNode) -{ - MOZ_ASSERT(aNode); - MOZ_ASSERT(aNode->NodeType() == nsIDOMNode::TEXT_NODE); - - // virtual method - // - // If this is a simple non-html editor, - // the best we can do is to assume it's visible. - - return true; -} - static inline bool IsElementVisible(dom::Element* aElement) { @@ -3737,9 +3723,8 @@ nsEditor::IsEditable(nsIContent *aNode) } switch (aNode->NodeType()) { case nsIDOMNode::ELEMENT_NODE: - return true; // not a text node; not invisible case nsIDOMNode::TEXT_NODE: - return IsTextInDirtyFrameVisible(aNode); + return true; // element or text node; not invisible default: return false; } diff --git a/editor/libeditor/base/nsEditor.h b/editor/libeditor/base/nsEditor.h index 6279121e82a..e8ac0a63615 100644 --- a/editor/libeditor/base/nsEditor.h +++ b/editor/libeditor/base/nsEditor.h @@ -586,11 +586,6 @@ public: bool IsEditable(nsIDOMNode *aNode); virtual bool IsEditable(nsIContent *aNode); - /** - * aNode must be a non-null text node. - */ - virtual bool IsTextInDirtyFrameVisible(nsIContent *aNode); - /** returns true if aNode is a MozEditorBogus node */ bool IsMozEditorBogusNode(nsIContent *aNode); diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index ea4dacc3e57..ea40e22d4d0 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -4338,23 +4338,6 @@ nsHTMLEditor::GetLastEditableLeaf(nsIDOMNode *aNode, nsCOMPtr *aOutL return res; } -bool -nsHTMLEditor::IsTextInDirtyFrameVisible(nsIContent *aNode) -{ - MOZ_ASSERT(aNode); - MOZ_ASSERT(aNode->NodeType() == nsIDOMNode::TEXT_NODE); - - bool isEmptyTextNode; - nsresult rv = IsVisTextNode(aNode, &isEmptyTextNode, false); - if (NS_FAILED(rv)) { - // We are following the historical decision: - // if we don't know, we say it's visible... - return true; - } - - return !isEmptyTextNode; -} - /////////////////////////////////////////////////////////////////////////// // IsVisTextNode: figure out if textnode aTextNode has any visible content. diff --git a/editor/libeditor/html/nsHTMLEditor.h b/editor/libeditor/html/nsHTMLEditor.h index 2a55508b254..4337a77ebca 100644 --- a/editor/libeditor/html/nsHTMLEditor.h +++ b/editor/libeditor/html/nsHTMLEditor.h @@ -342,11 +342,6 @@ public: // aSelection is optional -- if null, we get current seletion nsresult CollapseSelectionToDeepestNonTableFirstChild(nsISelection *aSelection, nsIDOMNode *aNode); - /** - * aNode must be a non-null text node. - */ - virtual bool IsTextInDirtyFrameVisible(nsIContent *aNode); - /** * aNode must be a non-null text node. * outIsEmptyNode must be non-null. diff --git a/editor/libeditor/html/tests/Makefile.in b/editor/libeditor/html/tests/Makefile.in index 1bdfbf089ee..1ca55792341 100644 --- a/editor/libeditor/html/tests/Makefile.in +++ b/editor/libeditor/html/tests/Makefile.in @@ -81,6 +81,7 @@ MOCHITEST_FILES = \ test_bug767684.html \ test_bug780035.html \ test_bug787432.html \ + test_bug796839.html \ $(NULL) ifneq (mobile,$(MOZ_BUILD_APP)) diff --git a/editor/libeditor/html/tests/test_bug796839.html b/editor/libeditor/html/tests/test_bug796839.html new file mode 100644 index 00000000000..be4be316c55 --- /dev/null +++ b/editor/libeditor/html/tests/test_bug796839.html @@ -0,0 +1,17 @@ + + +Test for Bug 796839 + + +Mozilla Bug 796839 +

+