Bug 1337247 - Remove PasteAsCitedQuotation() from nsIEditorMailSupport r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 19 Jul 2018 16:08:00 +0900
changeset 427450 3c2db10f62dedf67dc812b9ec8f5f6c40bce5037
parent 427408 47f713574cb269d5fb0bbb9bbc908131256ad81c
child 427451 c300d08cad3060e250a7ac5eb5dba6537c98d602
push id34306
push usercsabou@mozilla.com
push dateFri, 20 Jul 2018 21:41:18 +0000
treeherdermozilla-central@d6a5e8aea651 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1337247
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1337247 - Remove PasteAsCitedQuotation() from nsIEditorMailSupport r=m_kato nsIEditorMailSupport::PasteAsCitedQuotation() is only used by HTMLEditor::PasteAsQuotation(). So, we can get rid of the method from the interface and merge current implementation with HTMLEditor::PasteAsQuotation(). MozReview-Commit-ID: II5ExMAIOhP
editor/libeditor/HTMLEditorDataTransfer.cpp
editor/libeditor/TextEditor.cpp
editor/nsIEditorMailSupport.idl
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -1549,71 +1549,72 @@ HTMLEditor::CanPasteTransferable(nsITran
     if (NS_SUCCEEDED(rv) && data) {
       return true;
     }
   }
 
   return false;
 }
 
-/**
- * HTML PasteAsQuotation: Paste in a blockquote type=cite.
- */
 NS_IMETHODIMP
 HTMLEditor::PasteAsQuotation(int32_t aSelectionType)
 {
   if (IsPlaintextEditor()) {
     return PasteAsPlaintextQuotation(aSelectionType);
   }
 
-  nsAutoString citation;
-  return PasteAsCitedQuotation(citation, aSelectionType);
-}
+  // If it's not in plain text edit mode, paste text into new
+  // <blockquote type="cite"> element after removing selection.
 
-NS_IMETHODIMP
-HTMLEditor::PasteAsCitedQuotation(const nsAString& aCitation,
-                                  int32_t aSelectionType)
-{
   AutoPlaceholderBatch beginBatching(this);
   AutoTopLevelEditSubActionNotifier maybeTopLevelEditSubAction(
                                       *this, EditSubAction::eInsertQuotation,
                                       nsIEditor::eNext);
 
-  // get selection
   RefPtr<Selection> selection = GetSelection();
-  NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
+  if (NS_WARN_IF(!selection)) {
+    return NS_ERROR_FAILURE;
+  }
 
-  // give rules a chance to handle or cancel
+  // Adjust Selection and clear cached style before inserting <blockquote>.
   EditSubActionInfo subActionInfo(EditSubAction::eInsertElement);
   bool cancel, handled;
-  // Protect the edit rules object from dying
   RefPtr<TextEditRules> rules(mRules);
   nsresult rv =
     rules->WillDoAction(selection, subActionInfo, &cancel, &handled);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   if (cancel || handled) {
-    return NS_OK; // rules canceled the operation
+    return NS_OK;
   }
 
+  // Then, remove Selection and create <blockquote type="cite"> now.
+  // XXX Why don't we insert the <blockquote> into the DOM tree after
+  //     pasting the content in clipboard into it?
   nsCOMPtr<Element> newNode =
     DeleteSelectionAndCreateElement(*nsGkAtoms::blockquote);
-  NS_ENSURE_TRUE(newNode, NS_ERROR_NULL_POINTER);
-
-  // Try to set type=cite.  Ignore it if this fails.
+  if (NS_WARN_IF(!newNode)) {
+    return NS_ERROR_FAILURE;
+  }
   newNode->SetAttr(kNameSpaceID_None, nsGkAtoms::type,
                    NS_LITERAL_STRING("cite"), true);
 
-  // Set the selection to the underneath the node we just inserted:
+  // Collapse Selection in the new <blockquote> element.
   rv = selection->Collapse(newNode, 0);
-  NS_ENSURE_SUCCESS(rv, rv);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
   // XXX Why don't we call HTMLEditRules::DidDoAction() after Paste()?
-  return Paste(aSelectionType);
+  rv = Paste(aSelectionType);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+  return NS_OK;
 }
 
 /**
  * Paste a plaintext quotation.
  */
 nsresult
 HTMLEditor::PasteAsPlaintextQuotation(int32_t aSelectionType)
 {
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -1934,23 +1934,16 @@ TextEditor::InsertAsQuotation(const nsAS
       *aNodeInserted = nullptr;
     }
   }
   // XXX Why don't we call TextEditRules::DidDoAction()?
   return rv;
 }
 
 NS_IMETHODIMP
-TextEditor::PasteAsCitedQuotation(const nsAString& aCitation,
-                                  int32_t aSelectionType)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
 TextEditor::InsertAsCitedQuotation(const nsAString& aQuotedText,
                                    const nsAString& aCitation,
                                    bool aInsertHTML,
                                    nsINode** aNodeInserted)
 {
   return InsertAsQuotation(aQuotedText, aNodeInserted);
 }
 
--- a/editor/nsIEditorMailSupport.idl
+++ b/editor/nsIEditorMailSupport.idl
@@ -35,25 +35,16 @@ interface nsIEditorMailSupport : nsISupp
    * as plaintext quoted blocks.
    * If the selection is not collapsed, the selection is deleted
    * and the insertion takes place at the resulting collapsed selection.
    *
    * @param aString   the string to be inserted
    */
    void insertTextWithQuotations(in DOMString aStringToInsert);
 
-  /** Paste a string as quoted text,
-    * whose representation is dependant on the editor type,
-    * replacing the selected text (if any)
-    * @param aCitation    The "mid" URL of the source message
-    * @param aSelectionType Text or html?
-    */
-  void pasteAsCitedQuotation(in AString aCitation,
-                             in long aSelectionType);
-
   /** Insert a string as quoted text
     * (whose representation is dependant on the editor type),
     * replacing the selected text (if any),
     * including, if possible, a "cite" attribute.
     * @param aQuotedText  The actual text to be quoted
     * @param aCitation    The "mid" URL of the source message
     * @param aInsertHTML  Insert as html?  (vs plaintext)
     * @return             The node which was inserted