mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-02 05:17:31 +09:00
Bug 1316302 - Part 4: Refine HTMLEditRules::TryToJoinBlocks() and HTMLEditRules::MoveNodeSmart() with early return style for making scope of EditActionResult variable smaller
For now, let's make the scope of EditActionResult variable in them smaller without big change. Tag #1563
This commit is contained in:
parent
4731db5173
commit
1a100c40d7
1 changed files with 59 additions and 53 deletions
|
|
@ -2683,7 +2683,6 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
|
|
||||||
// offset below is where you find yourself in rightBlock when you traverse
|
// offset below is where you find yourself in rightBlock when you traverse
|
||||||
// upwards from leftBlock
|
// upwards from leftBlock
|
||||||
EditActionResult ret(NS_OK);
|
|
||||||
if (EditorUtils::IsDescendantOf(leftBlock, rightBlock, &rightOffset)) {
|
if (EditorUtils::IsDescendantOf(leftBlock, rightBlock, &rightOffset)) {
|
||||||
// Tricky case. Left block is inside right block. Do ws adjustment. This
|
// Tricky case. Left block is inside right block. Do ws adjustment. This
|
||||||
// just destroys non-visible ws at boundaries we will be joining.
|
// just destroys non-visible ws at boundaries we will be joining.
|
||||||
|
|
@ -2719,6 +2718,7 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
// Do br adjustment.
|
// Do br adjustment.
|
||||||
nsCOMPtr<Element> brNode =
|
nsCOMPtr<Element> brNode =
|
||||||
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
|
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
|
||||||
|
EditActionResult ret(NS_OK);
|
||||||
if (mergeLists) {
|
if (mergeLists) {
|
||||||
// The idea here is to take all children in rightList that are past
|
// The idea here is to take all children in rightList that are past
|
||||||
// offset, and pull them into leftlist.
|
// offset, and pull them into leftlist.
|
||||||
|
|
@ -2742,9 +2742,12 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
|
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
|
||||||
ret.MarkAsHandled();
|
ret.MarkAsHandled();
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Offset below is where you find yourself in leftBlock when you traverse
|
// Offset below is where you find yourself in leftBlock when you traverse
|
||||||
// upwards from rightBlock
|
// upwards from rightBlock
|
||||||
} else if (EditorUtils::IsDescendantOf(rightBlock, leftBlock, &leftOffset)) {
|
if (EditorUtils::IsDescendantOf(rightBlock, leftBlock, &leftOffset)) {
|
||||||
// Tricky case. Right block is inside left block. Do ws adjustment. This
|
// Tricky case. Right block is inside left block. Do ws adjustment. This
|
||||||
// just destroys non-visible ws at boundaries we will be joining.
|
// just destroys non-visible ws at boundaries we will be joining.
|
||||||
nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
|
nsresult rv = WSRunObject::ScrubBlockBoundary(htmlEditor,
|
||||||
|
|
@ -2779,6 +2782,7 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
// Do br adjustment.
|
// Do br adjustment.
|
||||||
nsCOMPtr<Element> brNode =
|
nsCOMPtr<Element> brNode =
|
||||||
CheckForInvisibleBR(*leftBlock, BRLocation::beforeBlock, leftOffset);
|
CheckForInvisibleBR(*leftBlock, BRLocation::beforeBlock, leftOffset);
|
||||||
|
EditActionResult ret(NS_OK);
|
||||||
if (mergeLists) {
|
if (mergeLists) {
|
||||||
// XXX Why do we ignore the result of MoveContents()?
|
// XXX Why do we ignore the result of MoveContents()?
|
||||||
EditActionResult retMoveContents =
|
EditActionResult retMoveContents =
|
||||||
|
|
@ -2854,7 +2858,9 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
|
if (brNode && NS_SUCCEEDED(htmlEditor->DeleteNode(brNode))) {
|
||||||
ret.MarkAsHandled();
|
ret.MarkAsHandled();
|
||||||
}
|
}
|
||||||
} else {
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Normal case. Blocks are siblings, or at least close enough. An example
|
// Normal case. Blocks are siblings, or at least close enough. An example
|
||||||
// of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The
|
// of the latter is <p>paragraph</p><ul><li>one<li>two<li>three</ul>. The
|
||||||
// first li and the p are not true siblings, but we still want to join them
|
// first li and the p are not true siblings, but we still want to join them
|
||||||
|
|
@ -2869,6 +2875,7 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
// Do br adjustment.
|
// Do br adjustment.
|
||||||
nsCOMPtr<Element> brNode =
|
nsCOMPtr<Element> brNode =
|
||||||
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
|
CheckForInvisibleBR(*leftBlock, BRLocation::blockEnd);
|
||||||
|
EditActionResult ret(NS_OK);
|
||||||
if (mergeLists || leftBlock->NodeInfo()->NameAtom() ==
|
if (mergeLists || leftBlock->NodeInfo()->NameAtom() ==
|
||||||
rightBlock->NodeInfo()->NameAtom()) {
|
rightBlock->NodeInfo()->NameAtom()) {
|
||||||
// Nodes are same type. merge them.
|
// Nodes are same type. merge them.
|
||||||
|
|
@ -2888,14 +2895,13 @@ HTMLEditRules::TryToJoinBlocks(nsIContent& aLeftNode,
|
||||||
}
|
}
|
||||||
if (brNode) {
|
if (brNode) {
|
||||||
rv = htmlEditor->DeleteNode(brNode);
|
rv = htmlEditor->DeleteNode(brNode);
|
||||||
// XXX In other top level if/else-if blocks, the result of DeleteNode()
|
// XXX In other top level if blocks, the result of DeleteNode()
|
||||||
// is ignored. Why does only this result is respected?
|
// is ignored. Why does only this result is respected?
|
||||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return ret.SetResult(rv);
|
return ret.SetResult(rv);
|
||||||
}
|
}
|
||||||
ret.MarkAsHandled();
|
ret.MarkAsHandled();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2970,7 +2976,8 @@ HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
|
||||||
}
|
}
|
||||||
// XXX Should we check if the node is actually moved in this case?
|
// XXX Should we check if the node is actually moved in this case?
|
||||||
return EditActionHandled();
|
return EditActionHandled();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
// If it can't, move its children (if any), and then delete it.
|
// If it can't, move its children (if any), and then delete it.
|
||||||
EditActionResult ret(NS_OK);
|
EditActionResult ret(NS_OK);
|
||||||
if (aNode.IsElement()) {
|
if (aNode.IsElement()) {
|
||||||
|
|
@ -2986,7 +2993,6 @@ HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
|
||||||
}
|
}
|
||||||
return ret.MarkAsHandled();
|
return ret.MarkAsHandled();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
EditActionResult
|
EditActionResult
|
||||||
HTMLEditRules::MoveContents(Element& aElement,
|
HTMLEditRules::MoveContents(Element& aElement,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue