mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 05:10:49 +00:00
Bug 1451672 - part 16: Rename EditorBase::MoveNode() to EditorBase::MoveNodeWithTransaction() and create EditorBase::MoveNodeToEndWithTransaction() r=m_kato
This patch renames EditorBase::MoveNode() to EditorBase::MoveNodeWithTransaction() and redesign its parameters including replacing a set of container node and offset in it to EditorDOMPointBase. However, it takes magic number -1 as meaning end of the container. Therefore, this patch adds MoveNodeToEndWithTransaction() for keeping the callers simple. MozReview-Commit-ID: BeTq5c7GQNN --HG-- extra : rebase_source : b3a617a5a1a493cb0fcbefe2d9a9708b0257b1a8
This commit is contained in:
parent
71964e6004
commit
2d04b175d7
@ -149,6 +149,12 @@ EditorBase::SplitNodeDeepWithTransaction(
|
||||
nsIContent& aMostAncestorToSplit,
|
||||
const EditorRawDOMPoint& aStartOfDeepestRightNode,
|
||||
SplitAtEdges aSplitAtEdges);
|
||||
template nsresult
|
||||
EditorBase::MoveNodeWithTransaction(nsIContent& aContent,
|
||||
const EditorDOMPoint& aPointToInsert);
|
||||
template nsresult
|
||||
EditorBase::MoveNodeWithTransaction(nsIContent& aContent,
|
||||
const EditorRawDOMPoint& aPointToInsert);
|
||||
|
||||
EditorBase::EditorBase()
|
||||
: mPlaceholderName(nullptr)
|
||||
@ -1838,55 +1844,49 @@ EditorBase::InsertContainerAbove(nsIContent* aNode,
|
||||
return newContainer.forget();
|
||||
}
|
||||
|
||||
/**
|
||||
* MoveNode() moves aNode to {aParent,aOffset}.
|
||||
*/
|
||||
template<typename PT, typename CT>
|
||||
nsresult
|
||||
EditorBase::MoveNode(nsIContent* aNode,
|
||||
nsINode* aParent,
|
||||
int32_t aOffset)
|
||||
EditorBase::MoveNodeWithTransaction(
|
||||
nsIContent& aContent,
|
||||
const EditorDOMPointBase<PT, CT>& aPointToInsert)
|
||||
{
|
||||
MOZ_ASSERT(aNode);
|
||||
MOZ_ASSERT(aParent);
|
||||
MOZ_ASSERT(aOffset == -1 ||
|
||||
(0 <= aOffset &&
|
||||
AssertedCast<uint32_t>(aOffset) <= aParent->Length()));
|
||||
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
|
||||
|
||||
nsCOMPtr<nsINode> oldParent = aNode->GetParentNode();
|
||||
if (NS_WARN_IF(!oldParent)) {
|
||||
EditorDOMPoint oldPoint(&aContent);
|
||||
if (NS_WARN_IF(!oldPoint.IsSet())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
int32_t oldOffset = oldParent->ComputeIndexOf(aNode);
|
||||
|
||||
if (aOffset == -1) {
|
||||
// Magic value meaning "move to end of aParent"
|
||||
aOffset = AssertedCast<int32_t>(aParent->Length());
|
||||
}
|
||||
|
||||
// Don't do anything if it's already in right place
|
||||
if (aParent == oldParent && aOffset == oldOffset) {
|
||||
// Don't do anything if it's already in right place.
|
||||
if (aPointToInsert == oldPoint) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Notify our internal selection state listener
|
||||
AutoMoveNodeSelNotify selNotify(mRangeUpdater, oldParent, oldOffset,
|
||||
aParent, aOffset);
|
||||
|
||||
// Need to adjust aOffset if we're moving aNode later in its current parent
|
||||
if (aParent == oldParent && oldOffset < aOffset) {
|
||||
// When we delete aNode, it will make the offsets after it off by one
|
||||
aOffset--;
|
||||
}
|
||||
EditorDOMPoint newPoint(aPointToInsert);
|
||||
AutoMoveNodeSelNotify selNotify(mRangeUpdater, oldPoint, newPoint);
|
||||
|
||||
// Hold a reference so aNode doesn't go away when we remove it (bug 772282)
|
||||
nsCOMPtr<nsIContent> nodeToBeMoved(aNode);
|
||||
nsresult rv = DeleteNodeWithTransaction(*nodeToBeMoved);
|
||||
nsresult rv = DeleteNodeWithTransaction(aContent);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = InsertNodeWithTransaction(*nodeToBeMoved,
|
||||
EditorRawDOMPoint(aParent, aOffset));
|
||||
// Mutation event listener could break insertion point. Let's check it.
|
||||
EditorRawDOMPoint pointToInsert(selNotify.ComputeInsertionPoint());
|
||||
if (NS_WARN_IF(!pointToInsert.IsSet())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// If some children have removed from the container, let's append to the
|
||||
// container.
|
||||
// XXX Perhaps, if mutation event listener inserts or removes some children
|
||||
// but the child node referring with aPointToInsert is still available,
|
||||
// we should insert aContent before it. However, we should keep
|
||||
// traditional behavior for now.
|
||||
if (NS_WARN_IF(!pointToInsert.IsSetAndValid())) {
|
||||
pointToInsert.SetToEndOf(pointToInsert.GetContainer());
|
||||
}
|
||||
rv = InsertNodeWithTransaction(aContent, pointToInsert);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
@ -470,7 +470,31 @@ public:
|
||||
*/
|
||||
nsresult JoinNodesWithTransaction(nsINode& aLeftNode, nsINode& aRightNode);
|
||||
|
||||
nsresult MoveNode(nsIContent* aNode, nsINode* aParent, int32_t aOffset);
|
||||
/**
|
||||
* MoveNodeWithTransaction() moves aContent to aPointToInsert.
|
||||
*
|
||||
* @param aContent The node to be moved.
|
||||
*/
|
||||
template<typename PT, typename CT>
|
||||
nsresult
|
||||
MoveNodeWithTransaction(nsIContent& aContent,
|
||||
const EditorDOMPointBase<PT, CT>& aPointToInsert);
|
||||
|
||||
/**
|
||||
* MoveNodeToEndWithTransaction() moves aContent to end of aNewContainer.
|
||||
*
|
||||
* @param aContent The node to be moved.
|
||||
* @param aNewContainer The new container which will contain aContent as
|
||||
* its last child.
|
||||
*/
|
||||
nsresult
|
||||
MoveNodeToEndWithTransaction(nsIContent& aContent,
|
||||
nsINode& aNewContainer)
|
||||
{
|
||||
EditorRawDOMPoint pointToInsert;
|
||||
pointToInsert.SetToEndOf(&aNewContainer);
|
||||
return MoveNodeWithTransaction(aContent, pointToInsert);
|
||||
}
|
||||
|
||||
/**
|
||||
* MoveAllChildren() moves all children of aContainer to before
|
||||
|
@ -1956,9 +1956,8 @@ HTMLEditRules::InsertBRElement(Selection& aSelection,
|
||||
EditorDOMPoint atSecondBRElement(maybeSecondBRNode);
|
||||
if (brElement->GetNextSibling() != maybeSecondBRNode) {
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNode(maybeSecondBRNode->AsContent(),
|
||||
afterBRElement.GetContainer(),
|
||||
afterBRElement.Offset());
|
||||
htmlEditor->MoveNodeWithTransaction(*maybeSecondBRNode->AsContent(),
|
||||
afterBRElement);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -3430,11 +3429,20 @@ HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
|
||||
|
||||
// Check if this node can go into the destination node
|
||||
if (htmlEditor->CanContain(aDestElement, aNode)) {
|
||||
// If it can, move it there
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNode(&aNode, &aDestElement, *aInOutDestOffset);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return EditActionIgnored(rv);
|
||||
// If it can, move it there.
|
||||
if (*aInOutDestOffset == -1) {
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNodeToEndWithTransaction(aNode, aDestElement);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return EditActionIgnored(rv);
|
||||
}
|
||||
} else {
|
||||
EditorRawDOMPoint pointToInsert(&aDestElement, *aInOutDestOffset);
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNodeWithTransaction(aNode, pointToInsert);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return EditActionIgnored(rv);
|
||||
}
|
||||
}
|
||||
if (*aInOutDestOffset != -1) {
|
||||
(*aInOutDestOffset)++;
|
||||
@ -3737,8 +3745,10 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
|
||||
// whole list and then RemoveContainerWithTransaction() on the list.
|
||||
// ConvertListType first: that routine handles converting the list
|
||||
// item types, if needed.
|
||||
rv = htmlEditor->MoveNode(curNode, curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode, *curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
newBlock = ConvertListType(curNode->AsElement(), listType, itemType);
|
||||
if (NS_WARN_IF(!newBlock)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -3784,8 +3794,10 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
|
||||
}
|
||||
}
|
||||
// move list item to new list
|
||||
rv = htmlEditor->MoveNode(curNode, curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode, *curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// convert list item type if needed
|
||||
if (!curNode->IsHTMLElement(itemType)) {
|
||||
newBlock =
|
||||
@ -3802,8 +3814,10 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
|
||||
curList = atCurNode.GetContainerAsElement();
|
||||
} else if (atCurNode.GetContainer() != curList) {
|
||||
// move list item to new list
|
||||
rv = htmlEditor->MoveNode(curNode, curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode, *curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
if (!curNode->IsHTMLElement(itemType)) {
|
||||
newBlock =
|
||||
@ -3876,7 +3890,7 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
|
||||
if (IsInlineNode(curNode) && prevListItem) {
|
||||
// this is a continuation of some inline nodes that belong together in
|
||||
// the same list item. use prevListItem
|
||||
rv = htmlEditor->MoveNode(curNode, prevListItem, -1);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode, *prevListItem);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} else {
|
||||
// don't wrap li around a paragraph. instead replace paragraph with li
|
||||
@ -3904,8 +3918,10 @@ HTMLEditRules::WillMakeList(Selection* aSelection,
|
||||
if (listItem) {
|
||||
// if we made a new list item, deal with it: tuck the listItem into the
|
||||
// end of the active list
|
||||
rv = htmlEditor->MoveNode(listItem, curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*listItem, *curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4305,7 +4321,8 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
|
||||
sibling->NodeInfo()->NameAtom() &&
|
||||
atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
|
||||
sibling->NodeInfo()->NamespaceID()) {
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, 0);
|
||||
rv = htmlEditor->MoveNodeWithTransaction(*curNode->AsContent(),
|
||||
EditorRawDOMPoint(sibling, 0));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
continue;
|
||||
}
|
||||
@ -4319,8 +4336,11 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
|
||||
sibling->NodeInfo()->NameAtom() &&
|
||||
atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
|
||||
sibling->NodeInfo()->NamespaceID()) {
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*sibling);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -4352,10 +4372,11 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
|
||||
mNewBlock = curList;
|
||||
}
|
||||
// tuck the node into the end of the active list
|
||||
uint32_t listLen = curList->Length();
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curList, listLen);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -4392,9 +4413,11 @@ HTMLEditRules::WillCSSIndent(Selection* aSelection,
|
||||
}
|
||||
|
||||
// tuck the node into the end of the active blockquote
|
||||
uint32_t quoteLen = curQuote->Length();
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curQuote, quoteLen);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curQuote);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -4514,8 +4537,11 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
|
||||
sibling->NodeInfo()->NameAtom() &&
|
||||
atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
|
||||
sibling->NodeInfo()->NamespaceID()) {
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeWithTransaction(*curNode->AsContent(),
|
||||
EditorRawDOMPoint(sibling, 0));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -4528,8 +4554,11 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
|
||||
sibling->NodeInfo()->NameAtom() &&
|
||||
atCurNode.GetContainer()->NodeInfo()->NamespaceID() ==
|
||||
sibling->NodeInfo()->NamespaceID()) {
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), sibling, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*sibling);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -4561,8 +4590,11 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
|
||||
mNewBlock = curList;
|
||||
}
|
||||
// tuck the node into the end of the active list
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// forget curQuote, if any
|
||||
curQuote = nullptr;
|
||||
|
||||
@ -4611,8 +4643,10 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
|
||||
}
|
||||
}
|
||||
|
||||
rv = htmlEditor->MoveNode(listItem, curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*listItem, *curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// remember we indented this li
|
||||
indentedLI = listItem;
|
||||
@ -4653,8 +4687,11 @@ HTMLEditRules::WillHTMLIndent(Selection* aSelection,
|
||||
}
|
||||
|
||||
// tuck the node into the end of the active blockquote
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curQuote, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curQuote);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// forget curList, if any
|
||||
curList = nullptr;
|
||||
}
|
||||
@ -4849,9 +4886,12 @@ HTMLEditRules::WillOutdent(Selection& aSelection,
|
||||
// We have an embedded list, so move it out from under the parent
|
||||
// list. Be sure to put it after the parent list because this
|
||||
// loop iterates backwards through the parent's list of children.
|
||||
|
||||
rv = htmlEditor->MoveNode(child, curParent, offset + 1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
EditorRawDOMPoint afterCurrentList(curParent, offset + 1);
|
||||
rv = htmlEditor->MoveNodeWithTransaction(*child,
|
||||
afterCurrentList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
} else {
|
||||
// Delete any non-list items for now
|
||||
rv = htmlEditor->DeleteNodeWithTransaction(*child);
|
||||
@ -5425,8 +5465,11 @@ HTMLEditRules::WillAlign(Selection& aSelection,
|
||||
}
|
||||
|
||||
// Tuck the node into the end of the active div
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curDiv, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curDiv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -5502,7 +5545,9 @@ HTMLEditRules::AlignBlockContents(nsINode& aNode,
|
||||
}
|
||||
// tuck the children into the end of the active div
|
||||
while (lastChild && (lastChild != divElem)) {
|
||||
nsresult rv = htmlEditor->MoveNode(lastChild, divElem, 0);
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNodeWithTransaction(*lastChild,
|
||||
EditorRawDOMPoint(divElem, 0));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -6805,9 +6850,10 @@ HTMLEditRules::BustUpInlinesAtBRs(
|
||||
// Move break outside of container and also put in node list
|
||||
EditorRawDOMPoint atNextNode(splitNodeResult.GetNextNode());
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNode(brNode->AsContent(), atNextNode.GetContainer(),
|
||||
atNextNode.Offset());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
htmlEditor->MoveNodeWithTransaction(*brNode->AsContent(), atNextNode);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
aOutArrayOfNodes.AppendElement(*brNode);
|
||||
|
||||
nextNode = splitNodeResult.GetNextNode();
|
||||
@ -7410,12 +7456,16 @@ HTMLEditRules::ReturnInListItem(Selection& aSelection,
|
||||
if (HTMLEditUtils::IsList(atNextSiblingOfLeftList.GetContainer())) {
|
||||
// If so, move item out of this list and into the grandparent list
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNode(&aListItem,
|
||||
atNextSiblingOfLeftList.GetContainer(),
|
||||
atNextSiblingOfLeftList.Offset());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = aSelection.Collapse(&aListItem, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
htmlEditor->MoveNodeWithTransaction(aListItem,
|
||||
atNextSiblingOfLeftList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
ErrorResult error;
|
||||
aSelection.Collapse(RawRangeBoundary(&aListItem, 0), error);
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
return error.StealNSResult();
|
||||
}
|
||||
} else {
|
||||
// Otherwise kill this item
|
||||
nsresult rv = htmlEditor->DeleteNodeWithTransaction(aListItem);
|
||||
@ -7633,8 +7683,12 @@ HTMLEditRules::MakeBlockquote(nsTArray<OwningNonNull<nsINode>>& aNodeArray)
|
||||
// note: doesn't matter if we set mNewBlock multiple times.
|
||||
}
|
||||
|
||||
nsresult rv = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curBlock);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@ -7842,8 +7896,12 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
|
||||
// Remember our new block for postprocessing
|
||||
mNewBlock = curBlock;
|
||||
// Note: doesn't matter if we set mNewBlock multiple times.
|
||||
nsresult rv = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curBlock);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -7889,8 +7947,12 @@ HTMLEditRules::ApplyBlockStyle(nsTArray<OwningNonNull<nsINode>>& aNodeArray,
|
||||
|
||||
// This is a continuation of some inline nodes that belong together in
|
||||
// the same block item. Use curBlock.
|
||||
nsresult rv = htmlEditor->MoveNode(curNode->AsContent(), curBlock, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv =
|
||||
htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curBlock);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
@ -7977,7 +8039,10 @@ HTMLEditRules::JoinNearestEditableNodesWithTransaction(nsIContent& aNodeLeft,
|
||||
if (NS_WARN_IF(!mHTMLEditor)) {
|
||||
return EditorDOMPoint();
|
||||
}
|
||||
nsresult rv = mHTMLEditor->MoveNode(&aNodeRight, parent, parOffset);
|
||||
nsresult rv =
|
||||
mHTMLEditor->MoveNodeWithTransaction(aNodeRight,
|
||||
EditorRawDOMPoint(parent,
|
||||
parOffset));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return EditorDOMPoint();
|
||||
}
|
||||
@ -8892,9 +8957,10 @@ HTMLEditRules::PopListItem(nsIContent& aListItem,
|
||||
}
|
||||
|
||||
nsresult rv =
|
||||
mHTMLEditor->MoveNode(&aListItem, pointToInsertListItem.GetContainer(),
|
||||
pointToInsertListItem.Offset());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mHTMLEditor->MoveNodeWithTransaction(aListItem, pointToInsertListItem);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// unwrap list item contents if they are no longer in a list
|
||||
if (!HTMLEditUtils::IsList(pointToInsertListItem.GetContainer()) &&
|
||||
@ -9635,8 +9701,11 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
|
||||
// new block for postprocessing.
|
||||
}
|
||||
// Tuck the node into the end of the active list
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -9690,8 +9759,10 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
rv = htmlEditor->MoveNode(listItem, curList, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*listItem, *curList);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// Remember we indented this li
|
||||
indentedLI = listItem;
|
||||
continue;
|
||||
@ -9723,7 +9794,8 @@ HTMLEditRules::WillAbsolutePosition(Selection& aSelection,
|
||||
}
|
||||
|
||||
// Tuck the node into the end of the active blockquote
|
||||
rv = htmlEditor->MoveNode(curNode->AsContent(), curPositionedDiv, -1);
|
||||
rv = htmlEditor->MoveNodeToEndWithTransaction(*curNode->AsContent(),
|
||||
*curPositionedDiv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Forget curList, if any
|
||||
curList = nullptr;
|
||||
|
@ -314,12 +314,13 @@ HTMLEditor::SetInlinePropertyOnTextNode(Text& aText,
|
||||
nsIContent* sibling = GetPriorHTMLSibling(textNodeForTheRange);
|
||||
if (IsSimpleModifiableNode(sibling, &aProperty, aAttribute, &aValue)) {
|
||||
// Previous sib is already right kind of inline node; slide this over
|
||||
return MoveNode(textNodeForTheRange, sibling, -1);
|
||||
return MoveNodeToEndWithTransaction(*textNodeForTheRange, *sibling);
|
||||
}
|
||||
sibling = GetNextHTMLSibling(textNodeForTheRange);
|
||||
if (IsSimpleModifiableNode(sibling, &aProperty, aAttribute, &aValue)) {
|
||||
// Following sib is already right kind of inline node; slide this over
|
||||
return MoveNode(textNodeForTheRange, sibling, 0);
|
||||
return MoveNodeWithTransaction(*textNodeForTheRange,
|
||||
EditorRawDOMPoint(sibling, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,8 +364,10 @@ HTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent& aNode,
|
||||
nsCOMPtr<nsIContent> previousSibling = GetPriorHTMLSibling(&aNode);
|
||||
nsCOMPtr<nsIContent> nextSibling = GetNextHTMLSibling(&aNode);
|
||||
if (IsSimpleModifiableNode(previousSibling, &aProperty, aAttribute, &aValue)) {
|
||||
nsresult rv = MoveNode(&aNode, previousSibling, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv = MoveNodeToEndWithTransaction(aNode, *previousSibling);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
|
||||
rv = JoinNodesWithTransaction(*previousSibling, *nextSibling);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
@ -374,8 +377,11 @@ HTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent& aNode,
|
||||
return NS_OK;
|
||||
}
|
||||
if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
|
||||
nsresult rv = MoveNode(&aNode, nextSibling, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv =
|
||||
MoveNodeWithTransaction(aNode, EditorRawDOMPoint(nextSibling, 0));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -652,8 +658,11 @@ HTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode,
|
||||
// leftNode. This is so we you don't revert back to the previous style
|
||||
// if you happen to click at the end of a line.
|
||||
if (savedBR) {
|
||||
rv = MoveNode(savedBR, newSelParent, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = MoveNodeWithTransaction(*savedBR,
|
||||
EditorRawDOMPoint(newSelParent, 0));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
// remove the style on this new hierarchy
|
||||
int32_t newSelOffset = 0;
|
||||
@ -1502,15 +1511,20 @@ HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
|
||||
nsCOMPtr<nsIContent> sibling = GetPriorHTMLSibling(textNodeForTheRange);
|
||||
if (sibling && sibling->IsHTMLElement(nodeType)) {
|
||||
// Previous sib is already right kind of inline node; slide this over
|
||||
nsresult rv = MoveNode(textNodeForTheRange, sibling, -1);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv = MoveNodeToEndWithTransaction(*textNodeForTheRange, *sibling);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
sibling = GetNextHTMLSibling(textNodeForTheRange);
|
||||
if (sibling && sibling->IsHTMLElement(nodeType)) {
|
||||
// Following sib is already right kind of inline node; slide this over
|
||||
nsresult rv = MoveNode(textNodeForTheRange, sibling, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv = MoveNodeWithTransaction(*textNodeForTheRange,
|
||||
EditorRawDOMPoint(sibling, 0));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1613,13 +1627,13 @@ HTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange,
|
||||
nsIContent* sibling = GetPriorHTMLSibling(aNode);
|
||||
if (sibling && sibling->IsHTMLElement(atom)) {
|
||||
// previous sib is already right kind of inline node; slide this over into it
|
||||
return MoveNode(aNode, sibling, -1);
|
||||
return MoveNodeToEndWithTransaction(*aNode, *sibling);
|
||||
}
|
||||
|
||||
sibling = GetNextHTMLSibling(aNode);
|
||||
if (sibling && sibling->IsHTMLElement(atom)) {
|
||||
// following sib is already right kind of inline node; slide this over into it
|
||||
return MoveNode(aNode, sibling, 0);
|
||||
return MoveNodeWithTransaction(*aNode, EditorRawDOMPoint(sibling, 0));
|
||||
}
|
||||
|
||||
// else insert it above aNode
|
||||
|
@ -315,27 +315,18 @@ public:
|
||||
|
||||
class MOZ_STACK_CLASS AutoMoveNodeSelNotify final
|
||||
{
|
||||
private:
|
||||
RangeUpdater& mRangeUpdater;
|
||||
nsINode* mOldParent;
|
||||
nsINode* mNewParent;
|
||||
int32_t mOldOffset;
|
||||
int32_t mNewOffset;
|
||||
|
||||
public:
|
||||
AutoMoveNodeSelNotify(RangeUpdater& aRangeUpdater,
|
||||
nsINode* aOldParent,
|
||||
int32_t aOldOffset,
|
||||
nsINode* aNewParent,
|
||||
int32_t aNewOffset)
|
||||
const EditorDOMPoint& aOldPoint,
|
||||
const EditorDOMPoint& aNewPoint)
|
||||
: mRangeUpdater(aRangeUpdater)
|
||||
, mOldParent(aOldParent)
|
||||
, mNewParent(aNewParent)
|
||||
, mOldOffset(aOldOffset)
|
||||
, mNewOffset(aNewOffset)
|
||||
, mOldParent(aOldPoint.GetContainer())
|
||||
, mNewParent(aNewPoint.GetContainer())
|
||||
, mOldOffset(aOldPoint.Offset())
|
||||
, mNewOffset(aNewPoint.Offset())
|
||||
{
|
||||
MOZ_ASSERT(aOldParent);
|
||||
MOZ_ASSERT(aNewParent);
|
||||
MOZ_ASSERT(mOldParent);
|
||||
MOZ_ASSERT(mNewParent);
|
||||
mRangeUpdater.WillMoveNode();
|
||||
}
|
||||
|
||||
@ -343,6 +334,22 @@ public:
|
||||
{
|
||||
mRangeUpdater.DidMoveNode(mOldParent, mOldOffset, mNewParent, mNewOffset);
|
||||
}
|
||||
|
||||
EditorRawDOMPoint ComputeInsertionPoint() const
|
||||
{
|
||||
if (mOldParent == mNewParent &&
|
||||
mOldOffset < mNewOffset) {
|
||||
return EditorRawDOMPoint(mNewParent, mNewOffset - 1);
|
||||
}
|
||||
return EditorRawDOMPoint(mNewParent, mNewOffset);
|
||||
}
|
||||
|
||||
private:
|
||||
RangeUpdater& mRangeUpdater;
|
||||
nsINode* mOldParent;
|
||||
nsINode* mNewParent;
|
||||
uint32_t mOldOffset;
|
||||
uint32_t mNewOffset;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
Loading…
x
Reference in New Issue
Block a user