Bug 1156062 - Back out for now, requested by Masayuki at bug 1191356 comment 23

This commit is contained in:
Aryeh Gregor 2016-04-20 20:45:10 +03:00
parent 5ffff818d3
commit 0baa2aa34f
2 changed files with 57 additions and 50 deletions

View File

@ -1568,7 +1568,7 @@ nsHTMLEditRules::WillInsertBreak(Selection& aSelection, bool* aCancel,
// host is the block parent itself, just append a br.
nsCOMPtr<Element> host = mHTMLEditor->GetActiveEditingHost();
if (!nsEditorUtils::IsDescendantOf(blockParent, host)) {
res = StandardBreakImpl(node, offset, aSelection);
res = StandardBreakImpl(GetAsDOMNode(node), offset, &aSelection);
NS_ENSURE_SUCCESS(res, res);
*aHandled = true;
return NS_OK;
@ -1609,85 +1609,92 @@ nsHTMLEditRules::WillInsertBreak(Selection& aSelection, bool* aCancel,
// If not already handled then do the standard thing
if (!(*aHandled)) {
*aHandled = true;
return StandardBreakImpl(node, offset, aSelection);
return StandardBreakImpl(GetAsDOMNode(node), offset, &aSelection);
}
return NS_OK;
}
nsresult
nsHTMLEditRules::StandardBreakImpl(nsINode& aNode, int32_t aOffset,
Selection& aSelection)
nsHTMLEditRules::StandardBreakImpl(nsIDOMNode* aNode, int32_t aOffset,
Selection* aSelection)
{
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
nsCOMPtr<Element> brNode;
nsCOMPtr<nsIDOMNode> brNode;
bool bAfterBlock = false;
bool bBeforeBlock = false;
nsCOMPtr<nsINode> node = &aNode;
nsresult res;
nsresult res = NS_OK;
nsCOMPtr<nsIDOMNode> node(aNode);
if (IsPlaintextEditor()) {
brNode = mHTMLEditor->CreateBR(node, aOffset);
NS_ENSURE_STATE(brNode);
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->CreateBR(node, aOffset, address_of(brNode));
} else {
NS_ENSURE_STATE(mHTMLEditor);
nsWSRunObject wsObj(mHTMLEditor, node, aOffset);
int32_t visOffset = 0;
WSType wsType;
nsCOMPtr<nsINode> visNode;
wsObj.PriorVisibleNode(node, aOffset, address_of(visNode),
nsCOMPtr<nsINode> node_(do_QueryInterface(node)), visNode;
wsObj.PriorVisibleNode(node_, aOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType & WSType::block) {
bAfterBlock = true;
}
wsObj.NextVisibleNode(node, aOffset, address_of(visNode),
wsObj.NextVisibleNode(node_, aOffset, address_of(visNode),
&visOffset, &wsType);
if (wsType & WSType::block) {
bBeforeBlock = true;
}
nsCOMPtr<nsIDOMNode> linkDOMNode;
if (mHTMLEditor->IsInLink(GetAsDOMNode(node), address_of(linkDOMNode))) {
// Split the link
nsCOMPtr<Element> linkNode = do_QueryInterface(linkDOMNode);
NS_ENSURE_STATE(linkNode || !linkDOMNode);
nsCOMPtr<nsINode> linkParent = linkNode->GetParentNode();
aOffset = mHTMLEditor->SplitNodeDeep(*linkNode, *node->AsContent(),
aOffset,
nsHTMLEditor::EmptyContainers::no);
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIDOMNode> linkNode;
if (mHTMLEditor->IsInLink(node, address_of(linkNode))) {
// split the link
nsCOMPtr<nsIDOMNode> linkParent;
res = linkNode->GetParentNode(getter_AddRefs(linkParent));
NS_ENSURE_SUCCESS(res, res);
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIContent> linkNodeContent = do_QueryInterface(linkNode);
NS_ENSURE_STATE(linkNodeContent || !linkNode);
aOffset = mHTMLEditor->SplitNodeDeep(*linkNodeContent,
*node_->AsContent(), aOffset, nsHTMLEditor::EmptyContainers::no);
NS_ENSURE_STATE(aOffset != -1);
node = linkParent;
}
brNode = wsObj.InsertBreak(address_of(node), &aOffset, nsIEditor::eNone);
node_ = do_QueryInterface(node);
nsCOMPtr<Element> br =
wsObj.InsertBreak(address_of(node_), &aOffset, nsIEditor::eNone);
node = GetAsDOMNode(node_);
brNode = GetAsDOMNode(br);
NS_ENSURE_TRUE(brNode, NS_ERROR_FAILURE);
}
node = brNode->GetParentNode();
NS_ENSURE_SUCCESS(res, res);
node = nsEditor::GetNodeLocation(brNode, &aOffset);
NS_ENSURE_TRUE(node, NS_ERROR_NULL_POINTER);
int32_t offset = node->IndexOf(brNode);
if (bAfterBlock && bBeforeBlock) {
// We just placed a br between block boundaries. This is the one case
// we just placed a br between block boundaries. This is the one case
// where we want the selection to be before the br we just placed, as the
// br will be on a new line, rather than at end of prior line.
aSelection.SetInterlinePosition(true);
res = aSelection.Collapse(node, offset);
NS_ENSURE_SUCCESS(res, res);
aSelection->SetInterlinePosition(true);
res = aSelection->Collapse(node, aOffset);
} else {
nsWSRunObject wsObj(mHTMLEditor, node, offset + 1);
NS_ENSURE_STATE(mHTMLEditor);
nsWSRunObject wsObj(mHTMLEditor, node, aOffset+1);
nsCOMPtr<nsINode> secondBR;
int32_t visOffset = 0;
WSType wsType;
wsObj.NextVisibleNode(node, offset + 1, address_of(secondBR),
nsCOMPtr<nsINode> node_(do_QueryInterface(node));
wsObj.NextVisibleNode(node_, aOffset+1, address_of(secondBR),
&visOffset, &wsType);
if (wsType == WSType::br) {
// The next thing after the break we inserted is another break. Move the
// second break to be the first break's sibling. This will prevent them
// the next thing after the break we inserted is another break. Move
// the 2nd break to be the first breaks sibling. This will prevent them
// from being in different inline nodes, which would break
// SetInterlinePosition(). It will also assure that if the user clicks
// away and then clicks back on their new blank line, they will still get
// the style from the line above.
nsCOMPtr<nsINode> brParent = secondBR->GetParentNode();
int32_t brOffset = brParent ? brParent->IndexOf(secondBR) : -1;
if (brParent != node || brOffset != offset + 1) {
res = mHTMLEditor->MoveNode(secondBR->AsContent(), node, offset + 1);
// away and then clicks back on their new blank line, they will still
// get the style from the line above.
int32_t brOffset;
nsCOMPtr<nsIDOMNode> brParent = nsEditor::GetNodeLocation(GetAsDOMNode(secondBR), &brOffset);
if (brParent != node || brOffset != aOffset + 1) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(secondBR->AsContent(), node_, aOffset + 1);
NS_ENSURE_SUCCESS(res, res);
}
}
@ -1698,16 +1705,16 @@ nsHTMLEditRules::StandardBreakImpl(nsINode& aNode, int32_t aOffset,
// An exception to this is if the break has a next sibling that is a block
// node. Then we stick to the left to avoid an uber caret.
nsCOMPtr<nsIContent> siblingNode = brNode->GetNextSibling();
if (siblingNode && IsBlockNode(GetAsDOMNode(siblingNode))) {
aSelection.SetInterlinePosition(false);
nsCOMPtr<nsIDOMNode> siblingNode;
brNode->GetNextSibling(getter_AddRefs(siblingNode));
if (siblingNode && IsBlockNode(siblingNode)) {
aSelection->SetInterlinePosition(false);
} else {
aSelection.SetInterlinePosition(true);
aSelection->SetInterlinePosition(true);
}
res = aSelection.Collapse(node, offset + 1);
NS_ENSURE_SUCCESS(res, res);
res = aSelection->Collapse(node, aOffset+1);
}
return NS_OK;
return res;
}
nsresult

View File

@ -136,8 +136,8 @@ protected:
nsresult WillLoadHTML(mozilla::dom::Selection* aSelection, bool* aCancel);
nsresult WillInsertBreak(mozilla::dom::Selection& aSelection,
bool* aCancel, bool* aHandled);
nsresult StandardBreakImpl(nsINode& aNode, int32_t aOffset,
mozilla::dom::Selection& aSelection);
nsresult StandardBreakImpl(nsIDOMNode* aNode, int32_t aOffset,
mozilla::dom::Selection* aSelection);
nsresult DidInsertBreak(mozilla::dom::Selection* aSelection,
nsresult aResult);
nsresult SplitMailCites(mozilla::dom::Selection* aSelection, bool* aHandled);