Bug 1451672 - part 10: Rename TextEditor::DeleteSelectionImpl() to TextEditor::DeleteSelectionWithTransaction() r=m_kato

MozReview-Commit-ID: 8nypHV8X3js

--HG--
extra : rebase_source : 8ca989bd8d5b9e824ed48a0fafa76993a575d0d0
This commit is contained in:
Masayuki Nakano 2018-04-11 19:11:15 +09:00
Родитель 80c2ea82ed
Коммит c3efa1de72
6 изменённых файлов: 54 добавлений и 40 удалений

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

@ -2719,19 +2719,24 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
}
{
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_FAILURE;
}
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
// Track location of where we are deleting
NS_ENSURE_STATE(mHTMLEditor);
AutoTrackDOMPoint startTracker(mHTMLEditor->mRangeUpdater,
AutoTrackDOMPoint startTracker(htmlEditor->mRangeUpdater,
address_of(startNode), &startOffset);
AutoTrackDOMPoint endTracker(mHTMLEditor->mRangeUpdater,
AutoTrackDOMPoint endTracker(htmlEditor->mRangeUpdater,
address_of(endNode), &endOffset);
// We are handling all ranged deletions directly now.
*aHandled = true;
if (endNode == startNode) {
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
NS_ENSURE_SUCCESS(rv, rv);
rv = htmlEditor->DeleteSelectionWithTransaction(aAction, aStripWrappers);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
// Figure out mailcite ancestors
nsCOMPtr<Element> startCiteNode = GetTopEnclosingMailCite(*startNode);
@ -2747,14 +2752,13 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
}
// Figure out block parents
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> leftParent = HTMLEditor::GetBlock(*startNode);
nsCOMPtr<Element> rightParent = HTMLEditor::GetBlock(*endNode);
// Are endpoint block parents the same? Use default deletion
if (leftParent && leftParent == rightParent) {
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
htmlEditor->DeleteSelectionWithTransaction(aAction, aStripWrappers);
} else {
// Deleting across blocks. Are the blocks of same type?
NS_ENSURE_STATE(leftParent && rightParent);
@ -2764,22 +2768,22 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
nsCOMPtr<nsINode> rightBlockParent = rightParent->GetParentNode();
// MOOSE: this could conceivably screw up a table.. fix me.
NS_ENSURE_STATE(mHTMLEditor);
if (leftBlockParent == rightBlockParent &&
mHTMLEditor->AreNodesSameType(leftParent, rightParent) &&
htmlEditor->AreNodesSameType(leftParent, rightParent) &&
// XXX What's special about these three types of block?
(leftParent->IsHTMLElement(nsGkAtoms::p) ||
HTMLEditUtils::IsListItem(leftParent) ||
HTMLEditUtils::IsHeader(*leftParent))) {
// First delete the selection
NS_ENSURE_STATE(mHTMLEditor);
rv = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
NS_ENSURE_SUCCESS(rv, rv);
rv = htmlEditor->DeleteSelectionWithTransaction(aAction,
aStripWrappers);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Join blocks
NS_ENSURE_STATE(mHTMLEditor);
EditorDOMPoint pt =
mHTMLEditor->JoinNodesDeepWithTransaction(*leftParent,
*rightParent);
htmlEditor->JoinNodesDeepWithTransaction(*leftParent,
*rightParent);
if (NS_WARN_IF(!pt.IsSet())) {
return NS_ERROR_FAILURE;
}
@ -2822,12 +2826,10 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
}
nsCOMPtr<nsIContent> content = somenode->AsContent();
if (Text* text = content->GetAsText()) {
NS_ENSURE_STATE(mHTMLEditor);
join = !mHTMLEditor->IsInVisibleTextFrames(*text);
join = !htmlEditor->IsInVisibleTextFrames(*text);
} else {
NS_ENSURE_STATE(mHTMLEditor);
join = content->IsHTMLElement(nsGkAtoms::br) &&
!mHTMLEditor->IsVisibleBRElement(somenode);
!htmlEditor->IsVisibleBRElement(somenode);
}
}
}
@ -2839,10 +2841,6 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
// node was already handled (we wouldn't be here)
if (startNode->GetAsText() &&
startNode->Length() > static_cast<uint32_t>(startOffset)) {
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_FAILURE;
}
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
// Delete to last character
OwningNonNull<CharacterData> dataNode =
*static_cast<CharacterData*>(startNode.get());
@ -2854,10 +2852,6 @@ HTMLEditRules::WillDeleteSelection(Selection* aSelection,
}
}
if (endNode->GetAsText() && endOffset) {
if (NS_WARN_IF(!mHTMLEditor)) {
return NS_ERROR_FAILURE;
}
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
// Delete to first character
OwningNonNull<CharacterData> dataNode =
*static_cast<CharacterData*>(endNode.get());

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

@ -3142,12 +3142,13 @@ HTMLEditor::GetEmbeddedObjects(nsIArray** aNodeList)
}
nsresult
HTMLEditor::DeleteSelectionImpl(EDirection aAction,
EStripWrappers aStripWrappers)
HTMLEditor::DeleteSelectionWithTransaction(EDirection aAction,
EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);
nsresult rv = TextEditor::DeleteSelectionImpl(aAction, aStripWrappers);
nsresult rv =
TextEditor::DeleteSelectionWithTransaction(aAction, aStripWrappers);
NS_ENSURE_SUCCESS(rv, rv);
// If we weren't asked to strip any wrappers, we're done.

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

@ -383,8 +383,17 @@ public:
virtual bool AreNodesSameType(nsIContent* aNode1,
nsIContent* aNode2) override;
virtual nsresult DeleteSelectionImpl(EDirection aAction,
EStripWrappers aStripWrappers) override;
/**
* DeleteSelectionWithTransaction() removes selected content or content
* around caret with transactions.
*
* @param aDirection How much range should be removed.
* @param aStripWrappers Whether the parent blocks should be removed
* when they become empty.
*/
virtual nsresult
DeleteSelectionWithTransaction(EDirection aAction,
EStripWrappers aStripWrappers) override;
/**
* DeleteNodeWithTransaction() removes aNode from the DOM tree if it's

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

@ -1070,7 +1070,8 @@ TextEditRules::WillDeleteSelection(Selection* aSelection,
NS_ENSURE_STATE(mTextEditor);
nsresult rv =
mTextEditor->DeleteSelectionImpl(aCollapsedAction, nsIEditor::eStrip);
mTextEditor->DeleteSelectionWithTransaction(aCollapsedAction,
nsIEditor::eStrip);
NS_ENSURE_SUCCESS(rv, rv);
*aHandled = true;

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

@ -565,7 +565,7 @@ TextEditor::ExtendSelectionForDelete(Selection* aSelection,
switch (*aAction) {
case eNextWord: {
nsresult rv = selCont->WordExtendForDelete(true);
// DeleteSelectionImpl doesn't handle these actions
// DeleteSelectionWithTransaction() doesn't handle these actions
// because it's inside batching, so don't confuse it:
*aAction = eNone;
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -715,7 +715,7 @@ TextEditor::DeleteSelectionAsAction(EDirection aDirection,
nsresult rv = rules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
NS_ENSURE_SUCCESS(rv, rv);
if (!cancel && !handled) {
rv = DeleteSelectionImpl(aDirection, aStripWrappers);
rv = DeleteSelectionWithTransaction(aDirection, aStripWrappers);
}
if (!cancel) {
// post-process
@ -725,8 +725,8 @@ TextEditor::DeleteSelectionAsAction(EDirection aDirection,
}
nsresult
TextEditor::DeleteSelectionImpl(EDirection aDirection,
EStripWrappers aStripWrappers)
TextEditor::DeleteSelectionWithTransaction(EDirection aDirection,
EStripWrappers aStripWrappers)
{
MOZ_ASSERT(aStripWrappers == eStrip || aStripWrappers == eNoStrip);

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

@ -151,8 +151,17 @@ public:
nsresult DeleteSelectionAsAction(EDirection aDirection,
EStripWrappers aStripWrappers);
virtual nsresult DeleteSelectionImpl(EDirection aAction,
EStripWrappers aStripWrappers);
/**
* DeleteSelectionWithTransaction() removes selected content or content
* around caret with transactions.
*
* @param aDirection How much range should be removed.
* @param aStripWrappers Whether the parent blocks should be removed
* when they become empty.
*/
virtual nsresult
DeleteSelectionWithTransaction(EDirection aAction,
EStripWrappers aStripWrappers);
// Utility Routines, not part of public API
NS_IMETHOD TypedText(const nsAString& aString, ETypingAction aAction);