Bug 1549319 - Make template methods marked as MOZ_CAN_RUN_SCRIPT take only EditorDOMPoint (i.e., not allow EditorRawDOMPoint) r=m_kato

It'd be better to change copy constructor of `EditorDOMPointBase` to explicit,
but it'd require too many changes in editor code.  So, this patch just changes
each method callers only.

Differential Revision: https://phabricator.services.mozilla.com/D30054

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-05-08 09:40:17 +00:00
Родитель 8eddd573c6
Коммит 4579004eac
17 изменённых файлов: 155 добавлений и 247 удалений

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

@ -123,30 +123,6 @@ using namespace widget;
* mozilla::EditorBase
*****************************************************************************/
template already_AddRefed<Element> EditorBase::CreateNodeWithTransaction(
nsAtom& aTag, const EditorDOMPoint& aPointToInsert);
template already_AddRefed<Element> EditorBase::CreateNodeWithTransaction(
nsAtom& aTag, const EditorRawDOMPoint& aPointToInsert);
template nsresult EditorBase::InsertNodeWithTransaction(
nsIContent& aContentToInsert, const EditorDOMPoint& aPointToInsert);
template nsresult EditorBase::InsertNodeWithTransaction(
nsIContent& aContentToInsert, const EditorRawDOMPoint& aPointToInsert);
template already_AddRefed<nsIContent> EditorBase::SplitNodeWithTransaction(
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aError);
template already_AddRefed<nsIContent> EditorBase::SplitNodeWithTransaction(
const EditorRawDOMPoint& aStartOfRightNode, ErrorResult& aError);
template SplitNodeResult EditorBase::SplitNodeDeepWithTransaction(
nsIContent& aMostAncestorToSplit,
const EditorDOMPoint& aStartOfDeepestRightNode, SplitAtEdges aSplitAtEdges);
template SplitNodeResult 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()
: mEditActionData(nullptr),
mPlaceholderName(nullptr),
@ -1342,9 +1318,8 @@ EditorBase::SetSpellcheckUserOverride(bool enable) {
return NS_OK;
}
template <typename PT, typename CT>
already_AddRefed<Element> EditorBase::CreateNodeWithTransaction(
nsAtom& aTagName, const EditorDOMPointBase<PT, CT>& aPointToInsert) {
nsAtom& aTagName, const EditorDOMPoint& aPointToInsert) {
MOZ_ASSERT(IsEditActionDataAvailable());
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
@ -1414,18 +1389,16 @@ EditorBase::InsertNode(nsINode* aNodeToInsert, nsINode* aContainer,
aOffset < 0
? static_cast<int32_t>(aContainer->Length())
: std::min(aOffset, static_cast<int32_t>(aContainer->Length()));
nsresult rv = InsertNodeWithTransaction(
*contentToInsert, EditorRawDOMPoint(aContainer, offset));
nsresult rv = InsertNodeWithTransaction(*contentToInsert,
EditorDOMPoint(aContainer, offset));
if (NS_WARN_IF(NS_FAILED(rv))) {
return EditorBase::ToGenericNSResult(rv);
}
return NS_OK;
}
template <typename PT, typename CT>
nsresult EditorBase::InsertNodeWithTransaction(
nsIContent& aContentToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert) {
nsIContent& aContentToInsert, const EditorDOMPoint& aPointToInsert) {
MOZ_ASSERT(IsEditActionDataAvailable());
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
@ -1472,7 +1445,7 @@ EditorBase::SplitNode(nsINode* aNode, int32_t aOffset, nsINode** aNewLeftNode) {
std::min(std::max(aOffset, 0), static_cast<int32_t>(aNode->Length()));
ErrorResult error;
nsCOMPtr<nsIContent> newNode =
SplitNodeWithTransaction(EditorRawDOMPoint(aNode, offset), error);
SplitNodeWithTransaction(EditorDOMPoint(aNode, offset), error);
newNode.forget(aNewLeftNode);
if (NS_WARN_IF(error.Failed())) {
return EditorBase::ToGenericNSResult(error.StealNSResult());
@ -1480,9 +1453,8 @@ EditorBase::SplitNode(nsINode* aNode, int32_t aOffset, nsINode** aNewLeftNode) {
return NS_OK;
}
template <typename PT, typename CT>
already_AddRefed<nsIContent> EditorBase::SplitNodeWithTransaction(
const EditorDOMPointBase<PT, CT>& aStartOfRightNode, ErrorResult& aError) {
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aError) {
MOZ_ASSERT(IsEditActionDataAvailable());
if (NS_WARN_IF(!aStartOfRightNode.IsSet()) ||
@ -1712,7 +1684,7 @@ already_AddRefed<Element> EditorBase::ReplaceContainerWithTransactionInternal(
}
rv = InsertNodeWithTransaction(
*child, EditorRawDOMPoint(newContainer, newContainer->Length()));
*child, EditorDOMPoint(newContainer, newContainer->Length()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
@ -1764,8 +1736,8 @@ nsresult EditorBase::RemoveContainerWithTransaction(Element& aElement) {
// use offset here because previous child might have been moved to
// container.
rv = InsertNodeWithTransaction(
*child, EditorRawDOMPoint(pointToInsertChildren.GetContainer(),
pointToInsertChildren.Offset()));
*child, EditorDOMPoint(pointToInsertChildren.GetContainer(),
pointToInsertChildren.Offset()));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1820,8 +1792,7 @@ already_AddRefed<Element> EditorBase::InsertContainerWithTransactionInternal(
{
AutoTransactionsConserveSelection conserveSelection(*this);
rv =
InsertNodeWithTransaction(aContent, EditorRawDOMPoint(newContainer, 0));
rv = InsertNodeWithTransaction(aContent, EditorDOMPoint(newContainer, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
@ -1836,9 +1807,8 @@ already_AddRefed<Element> EditorBase::InsertContainerWithTransactionInternal(
return newContainer.forget();
}
template <typename PT, typename CT>
nsresult EditorBase::MoveNodeWithTransaction(
nsIContent& aContent, const EditorDOMPointBase<PT, CT>& aPointToInsert) {
nsIContent& aContent, const EditorDOMPoint& aPointToInsert) {
MOZ_ASSERT(aPointToInsert.IsSetAndValid());
EditorDOMPoint oldPoint(&aContent);
@ -1852,8 +1822,7 @@ nsresult EditorBase::MoveNodeWithTransaction(
}
// Notify our internal selection state listener
EditorDOMPoint newPoint(aPointToInsert);
AutoMoveNodeSelNotify selNotify(RangeUpdaterRef(), oldPoint, newPoint);
AutoMoveNodeSelNotify selNotify(RangeUpdaterRef(), oldPoint, aPointToInsert);
// Hold a reference so aNode doesn't go away when we remove it (bug 772282)
nsresult rv = DeleteNodeWithTransaction(aContent);
@ -1862,7 +1831,7 @@ nsresult EditorBase::MoveNodeWithTransaction(
}
// Mutation event listener could break insertion point. Let's check it.
EditorRawDOMPoint pointToInsert(selNotify.ComputeInsertionPoint());
EditorDOMPoint pointToInsert(selNotify.ComputeInsertionPoint());
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
}
@ -3728,10 +3697,9 @@ bool EditorBase::IsPreformatted(nsINode* aNode) {
return styleText->WhiteSpaceIsSignificant();
}
template <typename PT, typename CT>
SplitNodeResult EditorBase::SplitNodeDeepWithTransaction(
nsIContent& aMostAncestorToSplit,
const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode,
const EditorDOMPoint& aStartOfDeepestRightNode,
SplitAtEdges aSplitAtEdges) {
MOZ_ASSERT(aStartOfDeepestRightNode.IsSetAndValid());
MOZ_ASSERT(

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

@ -936,10 +936,8 @@ class EditorBase : public nsIEditor,
* container. Otherwise, will insert the node
* before child node referred by this.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT nsresult
InsertNodeWithTransaction(nsIContent& aContentToInsert,
const EditorDOMPointBase<PT, CT>& aPointToInsert);
MOZ_CAN_RUN_SCRIPT nsresult InsertNodeWithTransaction(
nsIContent& aContentToInsert, const EditorDOMPoint& aPointToInsert);
/**
* ReplaceContainerWithTransaction() creates new element whose name is
@ -1071,10 +1069,8 @@ class EditorBase : public nsIEditor,
* @param aError If succeed, returns no error. Otherwise, an
* error.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT already_AddRefed<nsIContent> SplitNodeWithTransaction(
const EditorDOMPointBase<PT, CT>& aStartOfRightNode,
ErrorResult& aResult);
const EditorDOMPoint& aStartOfRightNode, ErrorResult& aResult);
/**
* JoinNodesWithTransaction() joins aLeftNode and aRightNode. Content of
@ -1093,9 +1089,8 @@ class EditorBase : public nsIEditor,
*
* @param aContent The node to be moved.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT nsresult MoveNodeWithTransaction(
nsIContent& aContent, const EditorDOMPointBase<PT, CT>& aPointToInsert);
nsIContent& aContent, const EditorDOMPoint& aPointToInsert);
/**
* MoveNodeToEndWithTransaction() moves aContent to end of aNewContainer.
@ -1107,7 +1102,7 @@ class EditorBase : public nsIEditor,
MOZ_CAN_RUN_SCRIPT
nsresult MoveNodeToEndWithTransaction(nsIContent& aContent,
nsINode& aNewContainer) {
EditorRawDOMPoint pointToInsert;
EditorDOMPoint pointToInsert;
pointToInsert.SetToEndOf(&aNewContainer);
return MoveNodeWithTransaction(aContent, pointToInsert);
}
@ -1243,9 +1238,8 @@ class EditorBase : public nsIEditor,
* child node referred by this.
* @return The created new element node.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> CreateNodeWithTransaction(
nsAtom& aTag, const EditorDOMPointBase<PT, CT>& aPointToInsert);
nsAtom& aTag, const EditorDOMPoint& aPointToInsert);
/**
* Create an aggregate transaction for delete selection. The result may
@ -1390,11 +1384,10 @@ class EditorBase : public nsIEditor,
* be good to insert something if the
* caller want to do it.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT SplitNodeResult SplitNodeDeepWithTransaction(
nsIContent& aMostAncestorToSplit,
const EditorDOMPointBase<PT, CT>& aDeepestStartOfRightNode,
SplitAtEdges aSplitAtEdges);
MOZ_CAN_RUN_SCRIPT SplitNodeResult
SplitNodeDeepWithTransaction(nsIContent& aMostAncestorToSplit,
const EditorDOMPoint& aDeepestStartOfRightNode,
SplitAtEdges aSplitAtEdges);
/**
* JoinNodesDeepWithTransaction() joins aLeftNode and aRightNode "deeply".

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

@ -240,17 +240,17 @@ class MOZ_STACK_CLASS SplitNodeResult final {
* by this instance. Therefore, the life time of both container node
* and child node are guaranteed while using the result temporarily.
*/
EditorRawDOMPoint SplitPoint() const {
EditorDOMPoint SplitPoint() const {
if (Failed()) {
return EditorRawDOMPoint();
return EditorDOMPoint();
}
if (mGivenSplitPoint.IsSet()) {
return EditorRawDOMPoint(mGivenSplitPoint);
return EditorDOMPoint(mGivenSplitPoint);
}
if (!mPreviousNode) {
return EditorRawDOMPoint(mNextNode);
return EditorDOMPoint(mNextNode);
}
EditorRawDOMPoint point(mPreviousNode);
EditorDOMPoint point(mPreviousNode);
DebugOnly<bool> advanced = point.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset to after previous node");

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

@ -519,7 +519,7 @@ nsresult HTMLEditor::SetPositionToAbsolute(Element& aElement) {
nsINode* parentNode = aElement.GetParentNode();
if (parentNode->GetChildCount() == 1) {
RefPtr<Element> newBrElement =
InsertBrElementWithTransaction(EditorRawDOMPoint(parentNode, 0));
InsertBrElementWithTransaction(EditorDOMPoint(parentNode, 0));
if (NS_WARN_IF(!newBrElement)) {
return NS_ERROR_FAILURE;
}

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

@ -1833,7 +1833,7 @@ EditActionResult HTMLEditRules::WillInsertParagraphSeparator() {
// make block have a line. Then code further below will put in a second br.)
if (IsEmptyBlockElement(*blockParent, IgnoreSingleBR::eNo)) {
AutoEditorDOMPointChildInvalidator lockOffset(atStartOfSelection);
EditorRawDOMPoint endOfBlockParent;
EditorDOMPoint endOfBlockParent;
endOfBlockParent.SetToEndOf(blockParent);
RefPtr<Element> brElement =
MOZ_KnownLive(HTMLEditorRef())
@ -2060,7 +2060,7 @@ nsresult HTMLEditRules::InsertBRElement(const EditorDOMPoint& aPointToBreak) {
EditActionResult HTMLEditRules::SplitMailCites() {
MOZ_ASSERT(IsEditorDataAvailable());
EditorRawDOMPoint pointToSplit(EditorBase::GetStartPoint(*SelectionRefPtr()));
EditorDOMPoint pointToSplit(EditorBase::GetStartPoint(*SelectionRefPtr()));
if (NS_WARN_IF(!pointToSplit.IsSet())) {
return EditActionIgnored(NS_ERROR_FAILURE);
}
@ -2128,7 +2128,7 @@ EditActionResult HTMLEditRules::SplitMailCites() {
nsCOMPtr<nsINode> lastChild = previousNodeOfSplitPoint->GetLastChild();
if (lastChild && !lastChild->IsHTMLElement(nsGkAtoms::br)) {
// We ignore the result here.
EditorRawDOMPoint endOfPreviousNodeOfSplitPoint;
EditorDOMPoint endOfPreviousNodeOfSplitPoint;
endOfPreviousNodeOfSplitPoint.SetToEndOf(previousNodeOfSplitPoint);
RefPtr<Element> invisibleBrElement =
MOZ_KnownLive(HTMLEditorRef())
@ -2144,7 +2144,7 @@ EditActionResult HTMLEditRules::SplitMailCites() {
// In most cases, <br> should be inserted after current cite. However, if
// left cite hasn't been created because the split point was start of the
// cite node, <br> should be inserted before the current cite.
EditorRawDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
EditorDOMPoint pointToInsertBrNode(splitCiteNodeResult.SplitPoint());
RefPtr<Element> brElement =
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToInsertBrNode);
@ -2179,8 +2179,8 @@ EditActionResult HTMLEditRules::SplitMailCites() {
// then we will need a 2nd br added to achieve blank line that user expects.
if (IsInlineNode(*citeNode)) {
// Use DOM point which we tried to collapse to.
EditorRawDOMPoint pointToCreateNewBrNode(atBrNode.GetContainer(),
atBrNode.Offset());
EditorDOMPoint pointToCreateNewBrNode(atBrNode.GetContainer(),
atBrNode.Offset());
WSRunObject wsObj(&HTMLEditorRef(), pointToCreateNewBrNode);
WSType wsType;
@ -3168,7 +3168,7 @@ nsresult HTMLEditRules::DeleteNodeIfCollapsedText(nsINode& aNode) {
nsresult HTMLEditRules::InsertBRIfNeeded() {
MOZ_ASSERT(IsEditorDataAvailable());
EditorRawDOMPoint atStartOfSelection(
EditorDOMPoint atStartOfSelection(
EditorBase::GetStartPoint(*SelectionRefPtr()));
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
@ -3687,7 +3687,7 @@ EditActionResult HTMLEditRules::MoveNodeSmart(nsIContent& aNode,
return EditActionIgnored(rv);
}
} else {
EditorRawDOMPoint pointToInsert(&aDestElement, *aInOutDestOffset);
EditorDOMPoint pointToInsert(&aDestElement, *aInOutDestOffset);
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(aNode, pointToInsert);
if (NS_WARN_IF(!CanHandleEditAction())) {
@ -3972,11 +3972,9 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atFirstListItemToInsertBefore(theList, 0);
RefPtr<Element> theListItem =
MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(aItemType,
atFirstListItemToInsertBefore);
.CreateNodeWithTransaction(aItemType, EditorDOMPoint(theList, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -4086,7 +4084,7 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
continue;
}
EditorRawDOMPoint atCurNode(curNode);
EditorDOMPoint atCurNode(curNode);
if (NS_WARN_IF(!atCurNode.IsSet())) {
return NS_ERROR_FAILURE;
}
@ -4111,10 +4109,10 @@ nsresult HTMLEditRules::MakeList(nsAtom& aListType, bool aEntireList,
return error.StealNSResult();
}
newBlock = newLeftNode ? newLeftNode->AsElement() : nullptr;
EditorRawDOMPoint atParentOfCurNode(atCurNode.GetContainer());
curList =
MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(aListType, atParentOfCurNode);
.CreateNodeWithTransaction(
aListType, EditorDOMPoint(atCurNode.GetContainer()));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -4476,7 +4474,7 @@ nsresult HTMLEditRules::MakeBasicBlock(nsAtom& blockType) {
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
EditorRawDOMPoint pointToInsertBrNode(splitNodeResult.SplitPoint());
EditorDOMPoint pointToInsertBrNode(splitNodeResult.SplitPoint());
// Put a <br> element at the split point
brContent = MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(pointToInsertBrNode);
@ -4791,7 +4789,7 @@ nsresult HTMLEditRules::IndentAroundSelectionWithCSS() {
nsresult rv =
MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
EditorRawDOMPoint(sibling, 0));
EditorDOMPoint(sibling, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -5067,7 +5065,7 @@ nsresult HTMLEditRules::IndentAroundSelectionWithHTML() {
sibling->NodeInfo()->NamespaceID()) {
rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(MOZ_KnownLive(*curNode->AsContent()),
EditorRawDOMPoint(sibling, 0));
EditorDOMPoint(sibling, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -5566,7 +5564,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::OutdentAroundSelection() {
// 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.
EditorRawDOMPoint afterCurrentList(curParent, offset + 1);
EditorDOMPoint afterCurrentList(curParent, offset + 1);
rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(*child, afterCurrentList);
if (NS_WARN_IF(!CanHandleEditAction())) {
@ -5675,7 +5673,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::SplitRangeOffFromBlock(
SplitNodeResult splitAtStartResult =
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aBlockElement, EditorRawDOMPoint(&aStartOfMiddleElement),
aBlockElement, EditorDOMPoint(&aStartOfMiddleElement),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return SplitRangeOffFromNodeResult(NS_ERROR_EDITOR_DESTROYED);
@ -5684,7 +5682,7 @@ SplitRangeOffFromNodeResult HTMLEditRules::SplitRangeOffFromBlock(
"Failed to split aBlockElement at start");
// Split at after the end
EditorRawDOMPoint atAfterEnd(&aEndOfMiddleElement);
EditorDOMPoint atAfterEnd(&aEndOfMiddleElement);
DebugOnly<bool> advanced = atAfterEnd.AdvanceOffset();
NS_WARNING_ASSERTION(advanced, "Failed to advance offset after the end node");
SplitNodeResult splitAtEndResult =
@ -5845,7 +5843,7 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
SplitNodeResult splitTextNodeResult =
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*text, EditorRawDOMPoint(text, offset),
*text, EditorDOMPoint(text, offset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -5862,9 +5860,9 @@ nsresult HTMLEditRules::CreateStyleForInsertText(Document& aDocument) {
}
OwningNonNull<Text> newNode =
EditorBase::CreateTextNode(aDocument, EmptyString());
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.InsertNodeWithTransaction(
*newNode, EditorRawDOMPoint(node, offset));
nsresult rv =
MOZ_KnownLive(HTMLEditorRef())
.InsertNodeWithTransaction(*newNode, EditorDOMPoint(node, offset));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -6090,8 +6088,7 @@ nsresult HTMLEditRules::AlignContentsAtSelection(const nsAString& aAlignType) {
return rv;
}
// Put in a moz-br so that it won't get deleted
CreateElementResult createMozBrResult =
CreateMozBR(EditorRawDOMPoint(div, 0));
CreateElementResult createMozBrResult = CreateMozBR(EditorDOMPoint(div, 0));
if (NS_WARN_IF(createMozBrResult.Failed())) {
return createMozBrResult.Rv();
}
@ -6298,10 +6295,9 @@ nsresult HTMLEditRules::AlignBlockContents(nsINode& aNode,
// else we need to put in a div, set the alignment, and toss in all the
// children
EditorRawDOMPoint atStartOfNode(&aNode, 0);
RefPtr<Element> divElem =
MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(*nsGkAtoms::div, atStartOfNode);
RefPtr<Element> divElem = MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(
*nsGkAtoms::div, EditorDOMPoint(&aNode, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -6322,7 +6318,7 @@ nsresult HTMLEditRules::AlignBlockContents(nsINode& aNode,
while (lastChild && (lastChild != divElem)) {
nsresult rv =
MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(*lastChild, EditorRawDOMPoint(divElem, 0));
.MoveNodeWithTransaction(*lastChild, EditorDOMPoint(divElem, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7493,8 +7489,7 @@ nsresult HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& aRangeItem) {
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*endInline,
EditorRawDOMPoint(aRangeItem.mEndContainer,
aRangeItem.mEndOffset),
EditorDOMPoint(aRangeItem.mEndContainer, aRangeItem.mEndOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -7518,8 +7513,8 @@ nsresult HTMLEditRules::BustUpInlinesAtRangeEndpoints(RangeItem& aRangeItem) {
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
*startInline,
EditorRawDOMPoint(aRangeItem.mStartContainer,
aRangeItem.mStartOffset),
EditorDOMPoint(aRangeItem.mStartContainer,
aRangeItem.mStartOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -7560,7 +7555,7 @@ nsresult HTMLEditRules::BustUpInlinesAtBRs(
// Else we need to bust up aNode along all the breaks
nsCOMPtr<nsIContent> nextNode = &aNode;
for (OwningNonNull<nsINode>& brNode : arrayOfBreaks) {
EditorRawDOMPoint atBrNode(brNode);
EditorDOMPoint atBrNode(brNode);
if (NS_WARN_IF(!atBrNode.IsSet())) {
return NS_ERROR_FAILURE;
}
@ -7585,7 +7580,7 @@ nsresult HTMLEditRules::BustUpInlinesAtBRs(
}
// Move break outside of container and also put in node list
EditorRawDOMPoint atNextNode(splitNodeResult.GetNextNode());
EditorDOMPoint atNextNode(splitNodeResult.GetNextNode());
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(
MOZ_KnownLive(*brNode->AsContent()), atNextNode);
@ -7763,7 +7758,7 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
SplitNodeResult splitHeaderResult =
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aHeader, EditorRawDOMPoint(node, aOffset),
aHeader, EditorDOMPoint(node, aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -7782,7 +7777,7 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
}
if (isEmptyNode) {
CreateElementResult createMozBrResult =
CreateMozBR(EditorRawDOMPoint(prevItem, 0));
CreateMozBR(EditorDOMPoint(prevItem, 0));
if (NS_WARN_IF(createMozBrResult.Failed())) {
return createMozBrResult.Rv();
}
@ -7811,7 +7806,7 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
// Create a paragraph
nsAtom& paraAtom = DefaultParagraphSeparator();
// We want a wrapper element even if we separate with <br>
EditorRawDOMPoint nextToHeader(headerParent, offset + 1);
EditorDOMPoint nextToHeader(headerParent, offset + 1);
RefPtr<Element> pNode =
MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(&paraAtom == nsGkAtoms::br
@ -7828,7 +7823,7 @@ nsresult HTMLEditRules::ReturnInHeader(Element& aHeader, nsINode& aNode,
// Append a <br> to it
RefPtr<Element> brElement =
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(EditorRawDOMPoint(pNode, 0));
.InsertBrElementWithTransaction(EditorDOMPoint(pNode, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -7964,7 +7959,7 @@ EditActionResult HTMLEditRules::ReturnInParagraph(Element& aParentDivOrP) {
EditorDOMPoint pointToSplitParentDivOrP(atStartOfSelection);
EditorRawDOMPoint pointToInsertBR;
EditorDOMPoint pointToInsertBR;
if (doesCRCreateNewP && atStartOfSelection.GetContainer() == &aParentDivOrP) {
// We are at the edges of the block, so, we don't need to create new <br>.
brContent = nullptr;
@ -8091,7 +8086,7 @@ nsresult HTMLEditRules::SplitParagraph(
SplitNodeResult splitDivOrPResult =
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aParentDivOrP, EditorRawDOMPoint(selNode, selOffset),
aParentDivOrP, EditorDOMPoint(selNode, selOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -8183,7 +8178,7 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
// Are we the last list item in the list?
if (!HTMLEditorRef().IsLastEditableChild(&aListItem)) {
// We need to split the list!
EditorRawDOMPoint atListItem(&aListItem);
EditorDOMPoint atListItem(&aListItem);
ErrorResult error;
leftListNode = MOZ_KnownLive(HTMLEditorRef())
.SplitNodeWithTransaction(atListItem, error);
@ -8197,7 +8192,7 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
}
// Are we in a sublist?
EditorRawDOMPoint atNextSiblingOfLeftList(leftListNode);
EditorDOMPoint atNextSiblingOfLeftList(leftListNode);
DebugOnly<bool> advanced = atNextSiblingOfLeftList.AdvanceOffset();
NS_WARNING_ASSERTION(advanced,
"Failed to advance offset after the right list node");
@ -8251,7 +8246,7 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
// Append a <br> to it
RefPtr<Element> brElement =
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(EditorRawDOMPoint(pNode, 0));
.InsertBrElementWithTransaction(EditorDOMPoint(pNode, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -8292,7 +8287,7 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
SplitNodeResult splitListItemResult =
MOZ_KnownLive(HTMLEditorRef())
.SplitNodeDeepWithTransaction(
aListItem, EditorRawDOMPoint(selNode, aOffset),
aListItem, EditorDOMPoint(selNode, aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
@ -8313,7 +8308,7 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
}
if (isEmptyNode) {
CreateElementResult createMozBrResult =
CreateMozBR(EditorRawDOMPoint(prevItem, 0));
CreateMozBR(EditorDOMPoint(prevItem, 0));
if (NS_WARN_IF(createMozBrResult.Failed())) {
return createMozBrResult.Rv();
}
@ -8331,8 +8326,8 @@ nsresult HTMLEditRules::ReturnInListItem(Element& aListItem, nsINode& aNode,
nsAtom* listAtom =
nodeAtom == nsGkAtoms::dt ? nsGkAtoms::dd : nsGkAtoms::dt;
MOZ_DIAGNOSTIC_ASSERT(itemOffset != -1);
EditorRawDOMPoint atNextListItem(list, aListItem.GetNextSibling(),
itemOffset + 1);
EditorDOMPoint atNextListItem(list, aListItem.GetNextSibling(),
itemOffset + 1);
RefPtr<Element> newListItem =
MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(MOZ_KnownLive(*listAtom),
@ -8484,10 +8479,9 @@ nsresult HTMLEditRules::MakeBlockquote(
// If no curBlock, make one
if (!curBlock) {
EditorDOMPoint atCurNode(curNode);
SplitNodeResult splitNodeResult =
MaybeSplitAncestorsForInsertWithTransaction(*nsGkAtoms::blockquote,
atCurNode);
EditorDOMPoint(curNode));
if (NS_WARN_IF(splitNodeResult.Failed())) {
return splitNodeResult.Rv();
}
@ -8828,9 +8822,8 @@ nsresult HTMLEditRules::ApplyBlockStyle(
return NS_OK;
}
template <typename PT, typename CT>
SplitNodeResult HTMLEditRules::MaybeSplitAncestorsForInsertWithTransaction(
nsAtom& aTag, const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode) {
nsAtom& aTag, const EditorDOMPoint& aStartOfDeepestRightNode) {
MOZ_ASSERT(IsEditorDataAvailable());
if (NS_WARN_IF(!aStartOfDeepestRightNode.IsSet())) {
@ -8908,7 +8901,7 @@ nsresult HTMLEditRules::JoinNearestEditableNodesWithTransaction(
int32_t parOffset = parent->ComputeIndexOf(&aNodeLeft);
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.MoveNodeWithTransaction(
aNodeRight, EditorRawDOMPoint(parent, parOffset));
aNodeRight, EditorDOMPoint(parent, parOffset));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -9145,7 +9138,7 @@ HTMLEditRules::InsertBRElementToEmptyListItemsAndTableCellsInChangedRange() {
// still pass the "IsEmptyNode" test, and we want the br's to be after
// them. Also, we want the br to be after the selection if the selection
// is in this node.
EditorRawDOMPoint endOfNode;
EditorDOMPoint endOfNode;
endOfNode.SetToEndOf(node);
// XXX This method should return nsreuslt due to may be destroyed by this
// CreateMozBr() call.
@ -9663,7 +9656,7 @@ nsresult HTMLEditRules::RemoveEmptyNodesInChangedRange() {
// but preserve br.
RefPtr<Element> brElement =
MOZ_KnownLive(HTMLEditorRef())
.InsertBrElementWithTransaction(EditorRawDOMPoint(delNode));
.InsertBrElementWithTransaction(EditorDOMPoint(delNode));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -10064,8 +10057,8 @@ nsresult HTMLEditRules::InsertBRIfNeededInternal(nsINode& aNode,
}
CreateElementResult createBrResult =
!aInsertMozBR ? CreateBR(EditorRawDOMPoint(&aNode, 0))
: CreateMozBR(EditorRawDOMPoint(&aNode, 0));
!aInsertMozBR ? CreateBR(EditorDOMPoint(&aNode, 0))
: CreateMozBR(EditorDOMPoint(&aNode, 0));
if (NS_WARN_IF(createBrResult.Failed())) {
return createBrResult.Rv();
}
@ -10380,7 +10373,7 @@ nsresult HTMLEditRules::MakeSureElemStartsOrEndsOnCR(nsINode& aNode,
}
}
if (!foundCR) {
EditorRawDOMPoint pointToInsert;
EditorDOMPoint pointToInsert;
if (!aStarts) {
pointToInsert.SetToEndOf(&aNode);
} else {
@ -10714,7 +10707,7 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
"Failed to create current positioned div element");
*aTargetElement = curPositionedDiv;
}
EditorRawDOMPoint atEndOfCurPositionedDiv;
EditorDOMPoint atEndOfCurPositionedDiv;
atEndOfCurPositionedDiv.SetToEndOf(curPositionedDiv);
curList = MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(MOZ_KnownLive(*containerName),
@ -10774,10 +10767,10 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
return splitNodeResult.Rv();
}
if (!curPositionedDiv) {
EditorRawDOMPoint atListItemParent(atListItem.GetContainer());
curPositionedDiv =
MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(*nsGkAtoms::div, atListItemParent);
curPositionedDiv = MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(
*nsGkAtoms::div,
EditorDOMPoint(atListItem.GetContainer()));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -10786,7 +10779,7 @@ nsresult HTMLEditRules::PrepareToMakeElementAbsolutePosition(
"Failed to create current positioned div element");
*aTargetElement = curPositionedDiv;
}
EditorRawDOMPoint atEndOfCurPositionedDiv;
EditorDOMPoint atEndOfCurPositionedDiv;
atEndOfCurPositionedDiv.SetToEndOf(curPositionedDiv);
curList = MOZ_KnownLive(HTMLEditorRef())
.CreateNodeWithTransaction(MOZ_KnownLive(*containerName),

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

@ -1087,10 +1087,9 @@ class HTMLEditRules : public TextEditRules {
* @return When succeeded, SplitPoint() returns
* the point to insert the element.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE SplitNodeResult
MaybeSplitAncestorsForInsertWithTransaction(
nsAtom& aTag, const EditorDOMPointBase<PT, CT>& aStartOfDeepestRightNode);
nsAtom& aTag, const EditorDOMPoint& aStartOfDeepestRightNode);
/**
* JoinNearestEditableNodesWithTransaction() joins two editable nodes which

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

@ -133,13 +133,6 @@ bool HTMLEditorPrefs::sUserWantsToEnableResizingUIByDefault = false;
bool HTMLEditorPrefs::sUserWantsToEnableInlineTableEditingUIByDefault = false;
bool HTMLEditorPrefs::sUserWantsToEnableAbsolutePositioningUIByDefault = false;
template EditorDOMPoint HTMLEditor::InsertNodeIntoProperAncestorWithTransaction(
nsIContent& aNode, const EditorDOMPoint& aPointToInsert,
SplitAtEdges aSplitAtEdges);
template EditorDOMPoint HTMLEditor::InsertNodeIntoProperAncestorWithTransaction(
nsIContent& aNode, const EditorRawDOMPoint& aPointToInsert,
SplitAtEdges aSplitAtEdges);
HTMLEditor::HTMLEditor()
: mCRInParagraphCreatesParagraph(false),
mCSSAware(false),
@ -1184,7 +1177,7 @@ nsresult HTMLEditor::InsertBrElementAtSelectionWithTransaction() {
}
}
EditorRawDOMPoint atStartOfSelection(
EditorDOMPoint atStartOfSelection(
EditorBase::GetStartPoint(*SelectionRefPtr()));
if (NS_WARN_IF(!atStartOfSelection.IsSet())) {
return NS_ERROR_FAILURE;
@ -1298,7 +1291,7 @@ nsresult HTMLEditor::ReplaceHeadContentsWithSourceWithTransaction(
// Loop over the contents of the fragment and move into the document
while (nsCOMPtr<nsIContent> child = documentFragment->GetFirstChild()) {
nsresult rv = InsertNodeWithTransaction(
*child, EditorRawDOMPoint(headNode, offsetOfNewNode++));
*child, EditorDOMPoint(headNode, offsetOfNewNode++));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1611,7 +1604,7 @@ HTMLEditor::InsertElementAtSelection(Element* aElement, bool aDeleteSelection) {
if (SelectionRefPtr()->GetAnchorNode()) {
EditorRawDOMPoint atAnchor(SelectionRefPtr()->AnchorRef());
// Adjust position based on the node we are going to insert.
EditorRawDOMPoint pointToInsert =
EditorDOMPoint pointToInsert =
GetBetterInsertionPointFor(*aElement, atAnchor);
if (NS_WARN_IF(!pointToInsert.IsSet())) {
return NS_ERROR_FAILURE;
@ -1654,9 +1647,8 @@ HTMLEditor::InsertElementAtSelection(Element* aElement, bool aDeleteSelection) {
return NS_OK;
}
template <typename PT, typename CT>
EditorDOMPoint HTMLEditor::InsertNodeIntoProperAncestorWithTransaction(
nsIContent& aNode, const EditorDOMPointBase<PT, CT>& aPointToInsert,
nsIContent& aNode, const EditorDOMPoint& aPointToInsert,
SplitAtEdges aSplitAtEdges) {
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return EditorDOMPoint();
@ -2120,7 +2112,7 @@ HTMLEditor::MakeOrChangeList(const nsAString& aListType, bool entireList,
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
EditorDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet()) ||
NS_WARN_IF(!atStartOfSelection.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
@ -2160,9 +2152,8 @@ HTMLEditor::MakeOrChangeList(const nsAString& aListType, bool entireList,
return NS_ERROR_FAILURE;
}
// make a list item
EditorRawDOMPoint atStartOfNewList(newList, 0);
RefPtr<Element> newItem =
CreateNodeWithTransaction(*nsGkAtoms::li, atStartOfNewList);
CreateNodeWithTransaction(*nsGkAtoms::li, EditorDOMPoint(newList, 0));
if (NS_WARN_IF(!newItem)) {
return NS_ERROR_FAILURE;
}
@ -2296,7 +2287,7 @@ nsresult HTMLEditor::InsertBasicBlockWithTransaction(nsAtom& aTagName) {
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
EditorDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet()) ||
NS_WARN_IF(!atStartOfSelection.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
@ -2436,7 +2427,7 @@ nsresult HTMLEditor::IndentOrOutdentAsSubAction(
return NS_ERROR_FAILURE;
}
EditorRawDOMPoint atStartOfSelection(firstRange->StartRef());
EditorDOMPoint atStartOfSelection(firstRange->StartRef());
if (NS_WARN_IF(!atStartOfSelection.IsSet()) ||
NS_WARN_IF(!atStartOfSelection.GetContainerAsContent())) {
return NS_ERROR_FAILURE;
@ -3834,7 +3825,7 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
!sibling->IsHTMLElement(nsGkAtoms::br) && !IsBlockNode(child)) {
// Insert br node
RefPtr<Element> brElement =
InsertBrElementWithTransaction(EditorRawDOMPoint(&aElement, 0));
InsertBrElementWithTransaction(EditorDOMPoint(&aElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -3852,7 +3843,7 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
MOZ_ASSERT(child, "aNode has first editable child but not last?");
if (!IsBlockNode(child) && !child->IsHTMLElement(nsGkAtoms::br)) {
// Insert br node
EditorRawDOMPoint endOfNode;
EditorDOMPoint endOfNode;
endOfNode.SetToEndOf(&aElement);
RefPtr<Element> brElement = InsertBrElementWithTransaction(endOfNode);
if (NS_WARN_IF(!brElement)) {
@ -3875,7 +3866,7 @@ nsresult HTMLEditor::RemoveBlockContainerWithTransaction(Element& aElement) {
!sibling->IsHTMLElement(nsGkAtoms::br)) {
// Insert br node
RefPtr<Element> brElement =
InsertBrElementWithTransaction(EditorRawDOMPoint(&aElement, 0));
InsertBrElementWithTransaction(EditorDOMPoint(&aElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}
@ -4562,9 +4553,8 @@ nsresult HTMLEditor::CopyLastEditableChildStylesWithTransaction(
nsAtom* tagName = elementInPreviousBlock->NodeInfo()->NameAtom();
// At first time, just create the most descendant inline container element.
if (!firstClonsedElement) {
EditorRawDOMPoint atStartOfNewBlock(newBlock, 0);
firstClonsedElement = lastClonedElement =
CreateNodeWithTransaction(MOZ_KnownLive(*tagName), atStartOfNewBlock);
firstClonsedElement = lastClonedElement = CreateNodeWithTransaction(
MOZ_KnownLive(*tagName), EditorDOMPoint(newBlock, 0));
if (NS_WARN_IF(!firstClonsedElement)) {
return NS_ERROR_FAILURE;
}
@ -4591,7 +4581,7 @@ nsresult HTMLEditor::CopyLastEditableChildStylesWithTransaction(
}
RefPtr<Element> brElement =
InsertBrElementWithTransaction(EditorRawDOMPoint(firstClonsedElement, 0));
InsertBrElementWithTransaction(EditorDOMPoint(firstClonsedElement, 0));
if (NS_WARN_IF(!brElement)) {
return NS_ERROR_FAILURE;
}

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

@ -1479,9 +1479,8 @@ class HTMLEditor final : public TextEditor,
* @return Returns inserted point if succeeded.
* Otherwise, the result is not set.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT EditorDOMPoint InsertNodeIntoProperAncestorWithTransaction(
nsIContent& aNode, const EditorDOMPointBase<PT, CT>& aPointToInsert,
nsIContent& aNode, const EditorDOMPoint& aPointToInsert,
SplitAtEdges aSplitAtEdges);
/**

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

@ -646,7 +646,7 @@ nsresult HTMLEditor::DoInsertHTMLWithContext(
// in a BR that is not visible. If so, the code above just placed
// selection inside that. So I split it instead.
SplitNodeResult splitLinkResult = SplitNodeDeepWithTransaction(
*linkContent, EditorRawDOMPoint(selNode, selOffset),
*linkContent, EditorDOMPoint(selNode, selOffset),
SplitAtEdges::eDoNotCreateEmptyContainer);
NS_WARNING_ASSERTION(splitLinkResult.Succeeded(),
"Failed to split the link");

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

@ -364,7 +364,7 @@ nsresult HTMLEditor::SetInlinePropertyOnTextNode(
nsCOMPtr<nsIContent> textNodeForTheRange = &aText;
// Split at the end of the range.
EditorRawDOMPoint atEnd(textNodeForTheRange, aEndOffset);
EditorDOMPoint atEnd(textNodeForTheRange, aEndOffset);
if (!atEnd.IsEndOfContainer()) {
// We need to split off back of text node
ErrorResult error;
@ -375,7 +375,7 @@ nsresult HTMLEditor::SetInlinePropertyOnTextNode(
}
// Split at the start of the range.
EditorRawDOMPoint atStart(textNodeForTheRange, aStartOffset);
EditorDOMPoint atStart(textNodeForTheRange, aStartOffset);
if (!atStart.IsStartOfContainer()) {
// We need to split off front of text node
ErrorResult error;
@ -397,7 +397,7 @@ nsresult HTMLEditor::SetInlinePropertyOnTextNode(
if (IsSimpleModifiableNode(sibling, &aProperty, aAttribute, &aValue)) {
// Following sib is already right kind of inline node; slide this over
return MoveNodeWithTransaction(*textNodeForTheRange,
EditorRawDOMPoint(sibling, 0));
EditorDOMPoint(sibling, 0));
}
}
@ -453,7 +453,7 @@ nsresult HTMLEditor::SetInlinePropertyOnNodeImpl(nsIContent& aNode,
}
if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
nsresult rv =
MoveNodeWithTransaction(aNode, EditorRawDOMPoint(nextSibling, 0));
MoveNodeWithTransaction(aNode, EditorDOMPoint(nextSibling, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -641,7 +641,7 @@ nsresult HTMLEditor::SplitStyleAbovePoint(
isSet) {
// Found a style node we need to split
SplitNodeResult splitNodeResult = SplitNodeDeepWithTransaction(
*node, EditorRawDOMPoint(*aNode, *aOffset),
*node, EditorDOMPoint(*aNode, *aOffset),
SplitAtEdges::eAllowToCreateEmptyContainer);
NS_WARNING_ASSERTION(splitNodeResult.Succeeded(),
"Failed to split the node");
@ -732,8 +732,7 @@ nsresult HTMLEditor::ClearStyle(nsCOMPtr<nsINode>* aNode, int32_t* aOffset,
// 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 =
MoveNodeWithTransaction(*savedBR, EditorRawDOMPoint(newSelParent, 0));
rv = MoveNodeWithTransaction(*savedBR, EditorDOMPoint(newSelParent, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1641,7 +1640,7 @@ nsresult HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
nsCOMPtr<nsIContent> textNodeForTheRange = &aTextNode;
// Split at the end of the range.
EditorRawDOMPoint atEnd(textNodeForTheRange, aEndOffset);
EditorDOMPoint atEnd(textNodeForTheRange, aEndOffset);
if (!atEnd.IsEndOfContainer()) {
// We need to split off back of text node
ErrorResult error;
@ -1652,7 +1651,7 @@ nsresult HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
}
// Split at the start of the range.
EditorRawDOMPoint atStart(textNodeForTheRange, aStartOffset);
EditorDOMPoint atStart(textNodeForTheRange, aStartOffset);
if (!atStart.IsStartOfContainer()) {
// We need to split off front of text node
ErrorResult error;
@ -1678,7 +1677,7 @@ nsresult HTMLEditor::RelativeFontChangeOnTextNode(FontSize aDir,
if (sibling && sibling->IsHTMLElement(nodeType)) {
// Following sib is already right kind of inline node; slide this over
nsresult rv = MoveNodeWithTransaction(*textNodeForTheRange,
EditorRawDOMPoint(sibling, 0));
EditorDOMPoint(sibling, 0));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1789,7 +1788,7 @@ nsresult HTMLEditor::RelativeFontChangeOnNode(int32_t aSizeChange,
if (sibling && sibling->IsHTMLElement(atom)) {
// following sib is already right kind of inline node; slide this over
// into it
return MoveNodeWithTransaction(*aNode, EditorRawDOMPoint(sibling, 0));
return MoveNodeWithTransaction(*aNode, EditorDOMPoint(sibling, 0));
}
// else insert it above aNode

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

@ -2799,8 +2799,8 @@ nsresult HTMLEditor::MergeCells(RefPtr<Element> aTargetCell,
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = InsertNodeWithTransaction(
*cellChild, EditorRawDOMPoint(aTargetCell, insertIndex));
rv = InsertNodeWithTransaction(*cellChild,
EditorDOMPoint(aTargetCell, insertIndex));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -44,11 +44,6 @@ namespace mozilla {
using namespace dom;
template CreateElementResult TextEditRules::CreateBRInternal(
const EditorDOMPoint& aPointToInsert, bool aCreateMozBR);
template CreateElementResult TextEditRules::CreateBRInternal(
const EditorRawDOMPoint& aPointToInsert, bool aCreateMozBR);
#define CANCEL_OPERATION_IF_READONLY_OR_DISABLED \
if (IsReadonly() || IsDisabled()) { \
*aCancel = true; \
@ -982,7 +977,7 @@ nsresult TextEditRules::WillSetText(bool* aCancel, bool* aHandled,
}
nsresult rv = MOZ_KnownLive(TextEditorRef())
.InsertNodeWithTransaction(
*newNode, EditorRawDOMPoint(rootElement, 0));
*newNode, EditorDOMPoint(rootElement, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -1473,7 +1468,7 @@ nsresult TextEditRules::CreateTrailingBRIfNeeded() {
if (!lastChild->IsHTMLElement(nsGkAtoms::br)) {
AutoTransactionsConserveSelection dontChangeMySelection(TextEditorRef());
EditorRawDOMPoint endOfRoot;
EditorDOMPoint endOfRoot;
endOfRoot.SetToEndOf(rootElement);
CreateElementResult createMozBrResult = CreateMozBR(endOfRoot);
if (NS_WARN_IF(createMozBrResult.Failed())) {
@ -1558,8 +1553,8 @@ nsresult TextEditRules::CreateBogusNodeIfNeeded() {
// Put the node in the document.
nsresult rv = MOZ_KnownLive(TextEditorRef())
.InsertNodeWithTransaction(
*newBrElement, EditorRawDOMPoint(rootElement, 0));
.InsertNodeWithTransaction(*newBrElement,
EditorDOMPoint(rootElement, 0));
if (NS_WARN_IF(!CanHandleEditAction())) {
return NS_ERROR_EDITOR_DESTROYED;
}
@ -1770,9 +1765,8 @@ void TextEditRules::FillBufWithPWChars(nsAString* aOutString, int32_t aLength) {
}
}
template <typename PT, typename CT>
CreateElementResult TextEditRules::CreateBRInternal(
const EditorDOMPointBase<PT, CT>& aPointToInsert, bool aCreateMozBR) {
const EditorDOMPoint& aPointToInsert, bool aCreateMozBR) {
MOZ_ASSERT(IsEditorDataAvailable());
if (NS_WARN_IF(!aPointToInsert.IsSet())) {

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

@ -312,9 +312,8 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* @return Returns created <br> element or an error code
* if couldn't create new <br> element.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT CreateElementResult
CreateBR(const EditorDOMPointBase<PT, CT>& aPointToInsert) {
CreateBR(const EditorDOMPoint& aPointToInsert) {
CreateElementResult ret = CreateBRInternal(aPointToInsert, false);
#ifdef DEBUG
// If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
@ -333,9 +332,8 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* @return Returns created <br> element or an error code
* if couldn't create new <br> element.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT CreateElementResult
CreateMozBR(const EditorDOMPointBase<PT, CT>& aPointToInsert) {
CreateMozBR(const EditorDOMPoint& aPointToInsert) {
CreateElementResult ret = CreateBRInternal(aPointToInsert, true);
#ifdef DEBUG
// If editor is destroyed, it must return NS_ERROR_EDITOR_DESTROYED.
@ -391,9 +389,8 @@ class TextEditRules : public nsITimerCallback, public nsINamed {
* @return Returns created <br> element and error code.
* If it succeeded, never returns nullptr.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT CreateElementResult CreateBRInternal(
const EditorDOMPointBase<PT, CT>& aPointToInsert, bool aCreateMozBR);
MOZ_CAN_RUN_SCRIPT CreateElementResult
CreateBRInternal(const EditorDOMPoint& aPointToInsert, bool aCreateMozBR);
protected:
/**

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

@ -64,11 +64,6 @@ namespace mozilla {
using namespace dom;
template already_AddRefed<Element> TextEditor::InsertBrElementWithTransaction(
const EditorDOMPoint& aPointToInsert, EDirection aSelect);
template already_AddRefed<Element> TextEditor::InsertBrElementWithTransaction(
const EditorRawDOMPoint& aPointToInsert, EDirection aSelect);
TextEditor::TextEditor()
: mWrapColumn(0),
mMaxTextLength(-1),
@ -242,9 +237,8 @@ TextEditor::SetDocumentCharacterSet(const nsACString& characterSet) {
}
// Create a new meta charset tag
EditorRawDOMPoint atStartOfHeadNode(headNode, 0);
RefPtr<Element> metaElement =
CreateNodeWithTransaction(*nsGkAtoms::meta, atStartOfHeadNode);
CreateNodeWithTransaction(*nsGkAtoms::meta, EditorDOMPoint(headNode, 0));
if (NS_WARN_IF(!metaElement)) {
return NS_OK;
}
@ -436,10 +430,8 @@ nsresult TextEditor::InsertLineBreakAsAction() {
return NS_OK;
}
template <typename PT, typename CT>
already_AddRefed<Element> TextEditor::InsertBrElementWithTransaction(
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect /* = eNone */) {
const EditorDOMPoint& aPointToInsert, EDirection aSelect /* = eNone */) {
MOZ_ASSERT(IsEditActionDataAvailable());
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
@ -869,7 +861,7 @@ already_AddRefed<Element> TextEditor::DeleteSelectionAndCreateElement(
return nullptr;
}
EditorRawDOMPoint pointToInsert(SelectionRefPtr()->AnchorRef());
EditorDOMPoint pointToInsert(SelectionRefPtr()->AnchorRef());
if (!pointToInsert.IsSet()) {
return nullptr;
}

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

@ -354,10 +354,8 @@ class TextEditor : public EditorBase, public nsIPlaintextEditor {
* @return The new <br> node. If failed to create new
* <br> node, returns nullptr.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT already_AddRefed<Element> InsertBrElementWithTransaction(
const EditorDOMPointBase<PT, CT>& aPointToInsert,
EDirection aSelect = eNone);
const EditorDOMPoint& aPointToInsert, EDirection aSelect = eNone);
/**
* Extends the selection for given deletion operation

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

@ -55,12 +55,6 @@ template void WSRunObject::NextVisibleNode(const EditorRawDOMPoint& aPoint,
nsCOMPtr<nsINode>* outVisNode,
int32_t* outVisOffset,
WSType* outType) const;
template already_AddRefed<Element> WSRunObject::InsertBreak(
Selection& aSelection, const EditorDOMPoint& aPointToInsert,
nsIEditor::EDirection aSelect);
template already_AddRefed<Element> WSRunObject::InsertBreak(
Selection& aSelection, const EditorRawDOMPoint& aPointToInsert,
nsIEditor::EDirection aSelect);
template void WSRunObject::GetASCIIWhitespacesBounds(
int16_t aDir, const EditorDOMPoint& aPoint, dom::Text** outStartNode,
int32_t* outStartOffset, dom::Text** outEndNode, int32_t* outEndOffset);
@ -171,9 +165,8 @@ nsresult WSRunObject::PrepareToSplitAcrossBlocks(HTMLEditor* aHTMLEditor,
return wsObj.PrepareToSplitAcrossBlocksPriv();
}
template <typename PT, typename CT>
already_AddRefed<Element> WSRunObject::InsertBreak(
Selection& aSelection, const EditorDOMPointBase<PT, CT>& aPointToInsert,
Selection& aSelection, const EditorDOMPoint& aPointToInsert,
nsIEditor::EDirection aSelect) {
if (NS_WARN_IF(!aPointToInsert.IsSet())) {
return nullptr;
@ -393,8 +386,8 @@ nsresult WSRunObject::DeleteWSBackward() {
// Easy case, preformatted ws.
if (mPRE && (nsCRT::IsAsciiSpace(point.mChar) || point.mChar == kNBSP)) {
nsresult rv =
DeleteRange(EditorRawDOMPoint(point.mTextNode, point.mOffset),
EditorRawDOMPoint(point.mTextNode, point.mOffset + 1));
DeleteRange(EditorDOMPoint(point.mTextNode, point.mOffset),
EditorDOMPoint(point.mTextNode, point.mOffset + 1));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -420,8 +413,8 @@ nsresult WSRunObject::DeleteWSBackward() {
NS_ENSURE_SUCCESS(rv, rv);
// finally, delete that ws
rv = DeleteRange(EditorRawDOMPoint(startNode, startOffset),
EditorRawDOMPoint(endNode, endOffset));
rv = DeleteRange(EditorDOMPoint(startNode, startOffset),
EditorDOMPoint(endNode, endOffset));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -439,8 +432,8 @@ nsresult WSRunObject::DeleteWSBackward() {
NS_ENSURE_SUCCESS(rv, rv);
// finally, delete that ws
rv = DeleteRange(EditorRawDOMPoint(node, startOffset),
EditorRawDOMPoint(node, endOffset));
rv = DeleteRange(EditorDOMPoint(node, startOffset),
EditorDOMPoint(node, endOffset));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -457,8 +450,8 @@ nsresult WSRunObject::DeleteWSForward() {
// Easy case, preformatted ws.
if (mPRE && (nsCRT::IsAsciiSpace(point.mChar) || point.mChar == kNBSP)) {
nsresult rv =
DeleteRange(EditorRawDOMPoint(point.mTextNode, point.mOffset),
EditorRawDOMPoint(point.mTextNode, point.mOffset + 1));
DeleteRange(EditorDOMPoint(point.mTextNode, point.mOffset),
EditorDOMPoint(point.mTextNode, point.mOffset + 1));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -483,8 +476,8 @@ nsresult WSRunObject::DeleteWSForward() {
NS_ENSURE_SUCCESS(rv, rv);
// Finally, delete that ws
rv = DeleteRange(EditorRawDOMPoint(startNode, startOffset),
EditorRawDOMPoint(endNode, endOffset));
rv = DeleteRange(EditorDOMPoint(startNode, startOffset),
EditorDOMPoint(endNode, endOffset));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -502,8 +495,8 @@ nsresult WSRunObject::DeleteWSForward() {
NS_ENSURE_SUCCESS(rv, rv);
// Finally, delete that ws
rv = DeleteRange(EditorRawDOMPoint(node, startOffset),
EditorRawDOMPoint(node, endOffset));
rv = DeleteRange(EditorDOMPoint(node, startOffset),
EditorDOMPoint(node, endOffset));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -1302,10 +1295,8 @@ nsresult WSRunObject::PrepareToSplitAcrossBlocksPriv() {
return NS_OK;
}
template <typename PT1, typename CT1, typename PT2, typename CT2>
nsresult WSRunObject::DeleteRange(
const EditorDOMPointBase<PT1, CT1>& aStartPoint,
const EditorDOMPointBase<PT2, CT2>& aEndPoint) {
nsresult WSRunObject::DeleteRange(const EditorDOMPoint& aStartPoint,
const EditorDOMPoint& aEndPoint) {
if (NS_WARN_IF(!aStartPoint.IsSet()) || NS_WARN_IF(!aEndPoint.IsSet())) {
return NS_ERROR_INVALID_ARG;
}
@ -1884,9 +1875,8 @@ nsresult WSRunObject::CheckTrailingNBSPOfRun(WSFragment* aRun) {
return NS_OK;
}
template <typename PT, typename CT>
nsresult WSRunObject::ReplacePreviousNBSPIfUnncessary(
WSFragment* aRun, const EditorDOMPointBase<PT, CT>& aPoint) {
WSFragment* aRun, const EditorDOMPoint& aPoint) {
if (NS_WARN_IF(!aRun) || NS_WARN_IF(!aPoint.IsSet())) {
return NS_ERROR_INVALID_ARG;
}

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

@ -240,9 +240,8 @@ class MOZ_STACK_CLASS WSRunObject final {
* @return The new <br> node. If failed to create new <br>
* node, returns nullptr.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT already_AddRefed<dom::Element> InsertBreak(
Selection& aSelection, const EditorDOMPointBase<PT, CT>& aPointToInsert,
Selection& aSelection, const EditorDOMPoint& aPointToInsert,
nsIEditor::EDirection aSelect);
/**
@ -387,10 +386,8 @@ class MOZ_STACK_CLASS WSRunObject final {
* When aEndPoint is in a text node, removes the text data before the point.
* Removes any nodes between them.
*/
template <typename PT1, typename CT1, typename PT2, typename CT2>
MOZ_CAN_RUN_SCRIPT nsresult
DeleteRange(const EditorDOMPointBase<PT1, CT1>& aStartPoint,
const EditorDOMPointBase<PT2, CT2>& aEndPoint);
MOZ_CAN_RUN_SCRIPT nsresult DeleteRange(const EditorDOMPoint& aStartPoint,
const EditorDOMPoint& aEndPoint);
/**
* GetNextCharPoint() returns next character's point of aPoint. If there is
@ -492,9 +489,8 @@ class MOZ_STACK_CLASS WSRunObject final {
* @param aPoint Current insertion point. Its previous character is
* unnecessary NBSP will be checked.
*/
template <typename PT, typename CT>
MOZ_CAN_RUN_SCRIPT nsresult ReplacePreviousNBSPIfUnncessary(
WSFragment* aRun, const EditorDOMPointBase<PT, CT>& aPoint);
WSFragment* aRun, const EditorDOMPoint& aPoint);
MOZ_CAN_RUN_SCRIPT
nsresult CheckLeadingNBSP(WSFragment* aRun, nsINode* aNode, int32_t aOffset);
@ -502,11 +498,11 @@ class MOZ_STACK_CLASS WSRunObject final {
MOZ_CAN_RUN_SCRIPT nsresult Scrub();
bool IsBlockNode(nsINode* aNode);
EditorRawDOMPoint StartPoint() const {
return EditorRawDOMPoint(mStartNode, mStartOffset);
EditorDOMPoint StartPoint() const {
return EditorDOMPoint(mStartNode, mStartOffset);
}
EditorRawDOMPoint EndPoint() const {
return EditorRawDOMPoint(mEndNode, mEndOffset);
EditorDOMPoint EndPoint() const {
return EditorDOMPoint(mEndNode, mEndOffset);
}
// The node passed to our constructor.