Bug 559710 - Don't add a br node under text controls when the editor is not initialized for them yet; r=roc,davidb a=1hr

This commit is contained in:
Ehsan Akhgari 2010-04-15 21:25:40 -04:00
parent 483533a0ce
commit 87f4d73ed2
2 changed files with 22 additions and 63 deletions

View File

@ -55,6 +55,9 @@
children: [
{
role: ROLE_TEXT_LEAF // HTML 5 placeholder attribute value
},
{
role: ROLE_TEXT_LEAF // Text node for the node's value
}
]
},
@ -125,6 +128,9 @@
children: [
{
role: ROLE_TEXT_LEAF // HTML 5 placeholder attribute value
},
{
role: ROLE_TEXT_LEAF // Text node for the node's value
}
]
},

View File

@ -2943,32 +2943,24 @@ nsTextControlFrame::UpdateValueDisplay(PRBool aNotify,
NS_PRECONDITION(mValueDiv, "Must have a div content\n");
NS_PRECONDITION(!mUseEditor,
"Do not call this after editor has been initialized");
NS_ASSERTION(mValueDiv->GetChildCount() <= 1,
"Cannot have more than one child node");
NS_ASSERTION(mPlaceholderDiv, "A placeholder div must exist");
enum {
NO_NODE,
TXT_NODE,
BR_NODE
} childNodeType = NO_NODE;
nsIContent* childNode = mValueDiv->GetChildAt(0);
#ifdef NS_DEBUG
if (aBeforeEditorInit)
NS_ASSERTION(childNode, "A child node should exist before initializing the editor");
#endif
nsIContent *textContent = mValueDiv->GetChildAt(0);
if (!textContent) {
// Set up a textnode with our value
nsCOMPtr<nsIContent> textNode;
nsresult rv = NS_NewTextNode(getter_AddRefs(textNode),
mContent->NodeInfo()->NodeInfoManager());
NS_ENSURE_SUCCESS(rv, rv);
if (childNode) {
if (childNode->IsNodeOfType(nsINode::eELEMENT))
childNodeType = BR_NODE;
else if (childNode->IsNodeOfType(nsINode::eTEXT))
childNodeType = TXT_NODE;
#ifdef NS_DEBUG
else
NS_NOTREACHED("Invalid child node found");
#endif
NS_ASSERTION(textNode, "Must have textcontent!\n");
mValueDiv->AppendChildTo(textNode, aNotify);
textContent = textNode;
}
NS_ENSURE_TRUE(textContent, NS_ERROR_UNEXPECTED);
// Get the current value of the textfield from the content.
nsAutoString value;
if (aValue) {
@ -2997,49 +2989,10 @@ nsTextControlFrame::UpdateValueDisplay(PRBool aNotify,
}
nsTextEditRules::HandleNewLines(value, -1);
nsresult rv;
if (value.IsEmpty()) {
if (childNodeType != BR_NODE) {
nsCOMPtr<nsINodeInfo> nodeInfo;
nodeInfo = mContent->NodeInfo()
->NodeInfoManager()
->GetNodeInfo(nsGkAtoms::br, nsnull,
kNameSpaceID_XHTML);
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIContent> brNode;
rv = NS_NewHTMLElement(getter_AddRefs(brNode), nodeInfo, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMElement> brElement = do_QueryInterface(brNode);
NS_ENSURE_TRUE(brElement, NS_ERROR_UNEXPECTED);
brElement->SetAttribute(kMOZEditorBogusNodeAttr, kMOZEditorBogusNodeValue);
mValueDiv->RemoveChildAt(0, aNotify, PR_FALSE);
mValueDiv->AppendChildTo(brNode, aNotify);
}
} else {
if (IsPasswordTextControl())
nsTextEditRules::FillBufWithPWChars(&value, value.Length());
// Set up a textnode with our value
nsCOMPtr<nsIContent> textNode;
if (childNodeType != TXT_NODE) {
rv = NS_NewTextNode(getter_AddRefs(textNode),
mContent->NodeInfo()->NodeInfoManager());
NS_ENSURE_SUCCESS(rv, rv);
NS_ASSERTION(textNode, "Must have textcontent!\n");
mValueDiv->RemoveChildAt(0, aNotify, PR_FALSE);
mValueDiv->AppendChildTo(textNode, aNotify);
} else {
textNode = childNode;
}
textNode->SetText(value, aNotify);
if (!value.IsEmpty() && IsPasswordTextControl()) {
nsTextEditRules::FillBufWithPWChars(&value, value.Length());
}
return NS_OK;
return textContent->SetText(value, aNotify);
}