Backed out changeset e03a9a31e9c4 (bug 857617) because of build bustage

Landed on a CLOSED TREE
This commit is contained in:
Ehsan Akhgari 2013-04-03 20:29:16 -04:00
Родитель d7c78d45aa
Коммит 793fdb86cb
3 изменённых файлов: 123 добавлений и 85 удалений

Просмотреть файл

@ -103,7 +103,6 @@
#include "nsStyleStruct.h" // for nsStyleDisplay, nsStyleText, etc #include "nsStyleStruct.h" // for nsStyleDisplay, nsStyleText, etc
#include "nsStyleStructFwd.h" // for nsIFrame::StyleUIReset, etc #include "nsStyleStructFwd.h" // for nsIFrame::StyleUIReset, etc
#include "nsTextEditUtils.h" // for nsTextEditUtils #include "nsTextEditUtils.h" // for nsTextEditUtils
#include "nsTextNode.h" // for nsTextNode
#include "nsThreadUtils.h" // for nsRunnable #include "nsThreadUtils.h" // for nsRunnable
#include "nsTransactionManager.h" // for nsTransactionManager #include "nsTransactionManager.h" // for nsTransactionManager
#include "prtime.h" // for PR_Now #include "prtime.h" // for PR_Now
@ -2295,100 +2294,141 @@ NS_IMETHODIMP nsEditor::ScrollSelectionIntoView(bool aScrollToAnchor)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP nsEditor::InsertTextImpl(const nsAString& aStringToInsert,
nsEditor::InsertTextImpl(const nsAString& aStringToInsert, nsCOMPtr<nsIDOMNode> *aInOutNode,
nsCOMPtr<nsIDOMNode>* aInOutNode, int32_t *aInOutOffset,
int32_t* aInOutOffset, nsIDOMDocument *aDoc)
nsIDOMDocument* aDoc)
{ {
// NOTE: caller *must* have already used nsAutoTxnsConserveSelection // NOTE: caller *must* have already used nsAutoTxnsConserveSelection stack-based
// stack-based class to turn off txn selection updating. Caller also turned // class to turn off txn selection updating. Caller also turned on rules sniffing
// on rules sniffing if desired. // if desired.
NS_ENSURE_TRUE(aInOutNode && *aInOutNode && aInOutOffset && aDoc, nsresult res;
NS_ERROR_NULL_POINTER); NS_ENSURE_TRUE(aInOutNode && *aInOutNode && aInOutOffset && aDoc, NS_ERROR_NULL_POINTER);
if (!mInIMEMode && aStringToInsert.IsEmpty()) { if (!mInIMEMode && aStringToInsert.IsEmpty()) return NS_OK;
return NS_OK; nsCOMPtr<nsIDOMText> nodeAsText = do_QueryInterface(*aInOutNode);
} if (!nodeAsText && IsPlaintextEditor()) {
nsCOMPtr<nsIDOMNode> rootNode = do_QueryInterface(GetRoot());
nsCOMPtr<nsINode> node = do_QueryInterface(*aInOutNode); // In some cases, aInOutNode is the anonymous DIV, and aInOutOffset is 0.
NS_ENSURE_STATE(node); // To avoid injecting unneeded text nodes, we first look to see if we have
uint32_t offset = static_cast<uint32_t>(*aInOutOffset); // one available. In that case, we'll just adjust aInOutNode and aInOutOffset
// accordingly.
if (!node->IsNodeOfType(nsINode::eTEXT) && IsPlaintextEditor()) { if (*aInOutNode == rootNode && *aInOutOffset == 0) {
nsCOMPtr<nsINode> root = GetRoot(); nsCOMPtr<nsIDOMNode> possibleTextNode;
// In some cases, node is the anonymous DIV, and offset is 0. To avoid res = (*aInOutNode)->GetFirstChild(getter_AddRefs(possibleTextNode));
// injecting unneeded text nodes, we first look to see if we have one if (NS_SUCCEEDED(res)) {
// available. In that case, we'll just adjust node and offset accordingly. nodeAsText = do_QueryInterface(possibleTextNode);
if (node == root && offset == 0 && node->HasChildren() && if (nodeAsText) {
node->GetFirstChild()->IsNodeOfType(nsINode::eTEXT)) { *aInOutNode = possibleTextNode;
node = node->GetFirstChild(); }
}
} }
// In some other cases, node is the anonymous DIV, and offset points to the // In some other cases, aInOutNode is the anonymous DIV, and aInOutOffset points
// terminating mozBR. In that case, we'll adjust aInOutNode and // to the terminating mozBR. In that case, we'll adjust aInOutNode and aInOutOffset
// aInOutOffset to the preceding text node, if any. // to the preceding text node, if any.
if (node == root && offset > 0 && node->GetChildAt(offset - 1) && if (!nodeAsText && *aInOutNode == rootNode && *aInOutOffset > 0) {
node->GetChildAt(offset - 1)->IsNodeOfType(nsINode::eTEXT)) { nsCOMPtr<nsIDOMNodeList> children;
node = node->GetChildAt(offset - 1); res = (*aInOutNode)->GetChildNodes(getter_AddRefs(children));
offset = node->Length(); if (NS_SUCCEEDED(res)) {
nsCOMPtr<nsIDOMNode> possibleMozBRNode;
children->Item(*aInOutOffset, getter_AddRefs(possibleMozBRNode));
if (possibleMozBRNode && nsTextEditUtils::IsMozBR(possibleMozBRNode)) {
nsCOMPtr<nsIDOMNode> possibleTextNode;
res = children->Item(*aInOutOffset - 1, getter_AddRefs(possibleTextNode));
if (NS_SUCCEEDED(res)) {
nodeAsText = do_QueryInterface(possibleTextNode);
if (nodeAsText) {
uint32_t length;
res = nodeAsText->GetLength(&length);
if (NS_SUCCEEDED(res)) {
*aInOutOffset = int32_t(length);
*aInOutNode = possibleTextNode;
}
}
}
} else {
// The selection might be at the end of the last textnode child,
// in which case we can just append to the textnode in question.
nsCOMPtr<nsIDOMNode> possibleTextNode;
res = children->Item(*aInOutOffset - 1, getter_AddRefs(possibleTextNode));
nodeAsText = do_QueryInterface(possibleTextNode);
if (nodeAsText) {
uint32_t length;
res = nodeAsText->GetLength(&length);
if (NS_SUCCEEDED(res)) {
*aInOutOffset = int32_t(length);
*aInOutNode = possibleTextNode;
}
}
}
}
} }
// Sometimes, node is the mozBR element itself. In that case, we'll adjust // Sometimes, aInOutNode is the mozBR element itself. In that case, we'll
// the insertion point to the previous text node, if one exists, or to the // adjust the insertion point to the previous text node, if one exists, or
// parent anonymous DIV. // to the parent anonymous DIV.
if (nsTextEditUtils::IsMozBR(node) && offset == 0) { if (nsTextEditUtils::IsMozBR(*aInOutNode) && *aInOutOffset == 0) {
if (node->GetPreviousSibling() && nsCOMPtr<nsIDOMNode> previous;
node->GetPreviousSibling()->IsNodeOfType(nsINode::eTEXT)) { (*aInOutNode)->GetPreviousSibling(getter_AddRefs(previous));
node = node->GetPreviousSibling(); nodeAsText = do_QueryInterface(previous);
offset = node->Length(); if (nodeAsText) {
} else if (node->GetParentNode() && node->GetParentNode() == root) { uint32_t length;
node = node->GetParentNode(); res = nodeAsText->GetLength(&length);
if (NS_SUCCEEDED(res)) {
*aInOutOffset = int32_t(length);
*aInOutNode = previous;
}
} else {
nsCOMPtr<nsIDOMNode> parent;
(*aInOutNode)->GetParentNode(getter_AddRefs(parent));
if (parent == rootNode) {
*aInOutNode = parent;
}
} }
} }
} }
int32_t offset = *aInOutOffset;
nsresult res; if (mInIMEMode)
if (mInIMEMode) { {
if (!node->IsNodeOfType(nsINode::eTEXT)) { if (!nodeAsText)
{
// create a text node // create a text node
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc); res = aDoc->CreateTextNode(EmptyString(), getter_AddRefs(nodeAsText));
NS_ENSURE_STATE(doc); NS_ENSURE_SUCCESS(res, res);
nsRefPtr<nsTextNode> newNode = doc->CreateTextNode(EmptyString()); NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
// then we insert it into the dom tree nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText);
res = InsertNode(newNode->AsDOMNode(), node->AsDOMNode(), offset); // then we insert it into the dom tree
res = InsertNode(newNode, *aInOutNode, offset);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
node = newNode;
offset = 0; offset = 0;
} }
nsCOMPtr<nsIDOMCharacterData> charDataNode = do_QueryInterface(node); res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
NS_ENSURE_STATE(charDataNode);
res = InsertTextIntoTextNodeImpl(aStringToInsert, charDataNode, offset);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
offset += aStringToInsert.Length(); }
} else { else
if (node->IsNodeOfType(nsINode::eTEXT)) { {
if (nodeAsText)
{
// we are inserting text into an existing text node. // we are inserting text into an existing text node.
nsCOMPtr<nsIDOMCharacterData> charDataNode = do_QueryInterface(node); res = InsertTextIntoTextNodeImpl(aStringToInsert, nodeAsText, offset);
NS_ENSURE_STATE(charDataNode);
res = InsertTextIntoTextNodeImpl(aStringToInsert, charDataNode, offset);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
offset += aStringToInsert.Length(); *aInOutOffset += aStringToInsert.Length();
} else { }
// we are inserting text into a non-text node. first we have to create a else
// textnode (this also populates it with the text) {
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc); // we are inserting text into a non-text node
NS_ENSURE_STATE(doc); // first we have to create a textnode (this also populates it with the text)
nsRefPtr<nsTextNode> newNode = doc->CreateTextNode(aStringToInsert); res = aDoc->CreateTextNode(aStringToInsert, getter_AddRefs(nodeAsText));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_TRUE(nodeAsText, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode> newNode = do_QueryInterface(nodeAsText);
// then we insert it into the dom tree // then we insert it into the dom tree
res = InsertNode(newNode->AsDOMNode(), node->AsDOMNode(), offset); res = InsertNode(newNode, *aInOutNode, offset);
NS_ENSURE_SUCCESS(res, res); NS_ENSURE_SUCCESS(res, res);
node = newNode; *aInOutNode = newNode;
offset = aStringToInsert.Length(); *aInOutOffset = aStringToInsert.Length();
} }
} }
return res;
*aInOutNode = node->AsDOMNode();
*aInOutOffset = static_cast<int32_t>(offset);
return NS_OK;
} }

Просмотреть файл

@ -52,14 +52,12 @@ nsTextEditUtils::IsMozBR(nsIDOMNode *node)
bool bool
nsTextEditUtils::IsMozBR(nsINode* aNode) nsTextEditUtils::IsMozBR(dom::Element* aNode)
{ {
MOZ_ASSERT(aNode); MOZ_ASSERT(aNode);
return aNode->IsElement() && return aNode->IsHTML(nsGkAtoms::br) &&
aNode->AsElement()->IsHTML(nsGkAtoms::br) && aNode->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type, NS_LITERAL_STRING("_moz"), eIgnoreCase);
NS_LITERAL_STRING("_moz"),
eIgnoreCase);
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -24,7 +24,7 @@ public:
static bool IsBody(nsIDOMNode* aNode); static bool IsBody(nsIDOMNode* aNode);
static bool IsBreak(nsIDOMNode* aNode); static bool IsBreak(nsIDOMNode* aNode);
static bool IsMozBR(nsIDOMNode* aNode); static bool IsMozBR(nsIDOMNode* aNode);
static bool IsMozBR(nsINode* aNode); static bool IsMozBR(mozilla::dom::Element* aNode);
static bool HasMozAttr(nsIDOMNode* aNode); static bool HasMozAttr(nsIDOMNode* aNode);
}; };