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.
This commit is contained in:
Ehsan Akhgari 2012-10-03 21:25:00 -04:00
parent 3ac41e17eb
commit 5e6b533bf5
6 changed files with 19 additions and 43 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -4338,23 +4338,6 @@ nsHTMLEditor::GetLastEditableLeaf(nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *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.

View File

@ -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.

View File

@ -81,6 +81,7 @@ MOCHITEST_FILES = \
test_bug767684.html \
test_bug780035.html \
test_bug787432.html \
test_bug796839.html \
$(NULL)
ifneq (mobile,$(MOZ_BUILD_APP))

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=796839
-->
<title>Test for Bug 796839</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=796839">Mozilla Bug 796839</a>
<div id="test" contenteditable><br></div>
<script>
var div = document.getElementById("test");
var text = document.createTextNode("");
div.insertBefore(text, div.firstChild);
getSelection().collapse(text, 0);
document.execCommand("inserthtml", false, "x");
is(div.textContent, 'x', "Empty textnodes should be editable");
</script>