зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1476897 - part 5: Move implementation of TextEditor::InsertAsQuotation() to new method r=m_kato
TextEditor::InsertAsQuotation() is not used as a method of nsIEditorMailSupport, however, this is used internally. So, we need to keep this method's function as a non-virtual method but we can make the method just return NS_ERROR_NOT_IMPLEMENTED. MozReview-Commit-ID: 2CcY4SZGwyr --HG-- extra : rebase_source : d490145b571bea465be5379872b9ea01daa633cc
This commit is contained in:
Родитель
b195745b15
Коммит
a2ecad4a67
|
@ -1780,9 +1780,14 @@ HTMLEditor::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
|
|||
bool aAddCites,
|
||||
nsINode** aNodeInserted)
|
||||
{
|
||||
// get selection
|
||||
if (aNodeInserted) {
|
||||
*aNodeInserted = nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
if (NS_WARN_IF(!selection)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch beginBatching(this);
|
||||
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
|
||||
|
@ -1809,7 +1814,7 @@ HTMLEditor::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
|
|||
// We could use 100vw, but 98vw avoids a horizontal scroll bar where possible.
|
||||
// All this is done to wrap overlong lines to the screen and not to the
|
||||
// container element, the width-restricted body.
|
||||
nsCOMPtr<Element> newNode =
|
||||
RefPtr<Element> newNode =
|
||||
DeleteSelectionAndCreateElement(*nsGkAtoms::span);
|
||||
|
||||
// If this succeeded, then set selection inside the pre
|
||||
|
@ -1832,11 +1837,15 @@ HTMLEditor::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
|
|||
}
|
||||
|
||||
// and set the selection inside it:
|
||||
selection->Collapse(newNode, 0);
|
||||
DebugOnly<nsresult> rv = selection->Collapse(newNode, 0);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to collapse selection into the new node");
|
||||
}
|
||||
|
||||
if (aAddCites) {
|
||||
rv = TextEditor::InsertAsQuotation(aQuotedText, aNodeInserted);
|
||||
rv = InsertWithQuotationsAsSubAction(aQuotedText);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to insert the text with quotations");
|
||||
} else {
|
||||
rv = InsertTextAsAction(aQuotedText);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
|
@ -1847,15 +1856,16 @@ HTMLEditor::InsertAsPlaintextQuotation(const nsAString& aQuotedText,
|
|||
// don't need to know the inserted node.
|
||||
|
||||
if (aNodeInserted && NS_SUCCEEDED(rv)) {
|
||||
*aNodeInserted = newNode;
|
||||
NS_IF_ADDREF(*aNodeInserted);
|
||||
newNode.forget(aNodeInserted);
|
||||
}
|
||||
|
||||
// Set the selection to just after the inserted node:
|
||||
if (NS_SUCCEEDED(rv) && newNode) {
|
||||
EditorRawDOMPoint afterNewNode(newNode);
|
||||
if (afterNewNode.AdvanceOffset()) {
|
||||
selection->Collapse(afterNewNode);
|
||||
DebugOnly<nsresult> rv = selection->Collapse(afterNewNode);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to collapse after the new node");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1876,7 +1876,9 @@ TextEditor::PasteAsQuotation(int32_t aSelectionType)
|
|||
nsAutoString stuffToPaste;
|
||||
textDataObj->GetData ( stuffToPaste );
|
||||
AutoPlaceholderBatch beginBatching(this);
|
||||
rv = InsertAsQuotation(stuffToPaste, 0);
|
||||
rv = InsertWithQuotationsAsSubAction(stuffToPaste);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
||||
"Failed to insert the text with quotations");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1887,6 +1889,12 @@ TextEditor::PasteAsQuotation(int32_t aSelectionType)
|
|||
NS_IMETHODIMP
|
||||
TextEditor::InsertAsQuotation(const nsAString& aQuotedText,
|
||||
nsINode** aNodeInserted)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEditor::InsertWithQuotationsAsSubAction(const nsAString& aQuotedText)
|
||||
{
|
||||
// Protect the edit rules object from dying
|
||||
RefPtr<TextEditRules> rules(mRules);
|
||||
|
@ -1894,7 +1902,9 @@ TextEditor::InsertAsQuotation(const nsAString& aQuotedText,
|
|||
// Let the citer quote it for us:
|
||||
nsString quotedStuff;
|
||||
nsresult rv = InternetCiter::GetCiteString(aQuotedText, quotedStuff);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// It's best to put a blank line after the quoted text so that mails
|
||||
// written without thinking won't be so ugly.
|
||||
|
@ -1902,16 +1912,18 @@ TextEditor::InsertAsQuotation(const nsAString& aQuotedText,
|
|||
quotedStuff.Append(char16_t('\n'));
|
||||
}
|
||||
|
||||
// get selection
|
||||
RefPtr<Selection> selection = GetSelection();
|
||||
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
|
||||
if (NS_WARN_IF(!selection)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
AutoPlaceholderBatch beginBatching(this);
|
||||
AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
|
||||
*this, EditSubAction::eInsertText,
|
||||
nsIEditor::eNext);
|
||||
|
||||
// give rules a chance to handle or cancel
|
||||
// XXX This WillDoAction() usage is hacky. If it returns as handled,
|
||||
// this method cannot work as expected. So, this should have specific
|
||||
// sub-action rather than using eInsertElement.
|
||||
EditSubActionInfo subActionInfo(EditSubAction::eInsertElement);
|
||||
bool cancel, handled;
|
||||
rv = rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
|
||||
|
@ -1921,17 +1933,16 @@ TextEditor::InsertAsQuotation(const nsAString& aQuotedText,
|
|||
if (cancel) {
|
||||
return NS_OK; // Rules canceled the operation.
|
||||
}
|
||||
MOZ_ASSERT(handled, "WillDoAction() shouldn't handle in this case");
|
||||
if (!handled) {
|
||||
// TODO: Use InsertTextAsSubAction() when bug 1467796 is fixed.
|
||||
rv = InsertTextAsAction(quotedStuff);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to insert quoted text");
|
||||
|
||||
// XXX Should set *aNodeInserted to the first node inserted
|
||||
if (aNodeInserted && NS_SUCCEEDED(rv)) {
|
||||
*aNodeInserted = nullptr;
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
// XXX Why don't we call TextEditRules::DidDoAction()?
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -332,6 +332,15 @@ protected: // Shouldn't be used by friend classes
|
|||
int32_t aDestOffset,
|
||||
bool aDoDeleteSelection) override;
|
||||
|
||||
/**
|
||||
* InsertWithQuotationsAsSubAction() inserts aQuotedText with appending ">"
|
||||
* to start of every line.
|
||||
*
|
||||
* @param aQuotedText String to insert. This will be quoted by ">"
|
||||
* automatically.
|
||||
*/
|
||||
nsresult InsertWithQuotationsAsSubAction(const nsAString& aQuotedText);
|
||||
|
||||
/**
|
||||
* Return true if the data is safe to insert as the source and destination
|
||||
* principals match, or we are in a editor context where this doesn't matter.
|
||||
|
|
Загрузка…
Ссылка в новой задаче