Bug 1467802 - part 3: Create EditorBase::GetDocumentCharsetInternal() for internal use of nsIEditor::GetDocumentCharacterSet() r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 18 Jul 2018 21:11:32 +0900
changeset 820223 32117d853d7551b912c72da20dc00975b18999b3
parent 820222 8edbf2fe3c36aad39f21b785ee59cbd6a99e76a0
child 820224 089f2163463146aca58abc5e7f15ad289a849386
push id116753
push usermasayuki@d-toybox.com
push dateThu, 19 Jul 2018 06:22:48 +0000
reviewersm_kato
bugs1467802
milestone63.0a1
Bug 1467802 - part 3: Create EditorBase::GetDocumentCharsetInternal() for internal use of nsIEditor::GetDocumentCharacterSet() r?m_kato This patch creates non-virtual method, EditorBase::GetDocumentCharsetInternal(), for internal use of nsIEditor::GetDocumentCharacterSet() since the virtual call method is redundant and the caller cannot be marked as const. MozReview-Commit-ID: v6kDo2eKg3
editor/libeditor/EditorBase.cpp
editor/libeditor/EditorBase.h
editor/libeditor/TextEditor.cpp
--- a/editor/libeditor/EditorBase.cpp
+++ b/editor/libeditor/EditorBase.cpp
@@ -1127,23 +1127,29 @@ EditorBase::GetDocumentModified(bool* ou
   int32_t  modCount = 0;
   GetModificationCount(&modCount);
 
   *outDocModified = (modCount != 0);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-EditorBase::GetDocumentCharacterSet(nsACString& characterSet)
+EditorBase::GetDocumentCharacterSet(nsACString& aCharset)
+{
+  return GetDocumentCharsetInternal(aCharset);
+}
+
+nsresult
+EditorBase::GetDocumentCharsetInternal(nsACString& aCharset) const
 {
   nsCOMPtr<nsIDocument> document = GetDocument();
   if (NS_WARN_IF(!document)) {
     return NS_ERROR_UNEXPECTED;
   }
-  document->GetDocumentCharacterSet()->Name(characterSet);
+  document->GetDocumentCharacterSet()->Name(aCharset);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 EditorBase::SetDocumentCharacterSet(const nsACString& characterSet)
 {
   nsCOMPtr<nsIDocument> document = GetDocument();
   if (NS_WARN_IF(!document)) {
--- a/editor/libeditor/EditorBase.h
+++ b/editor/libeditor/EditorBase.h
@@ -1646,16 +1646,21 @@ protected: // Called by helper classes.
 protected: // Shouldn't be used by friend classes
   /**
    * The default destructor. This should suffice. Should this be pure virtual
    * for someone to derive from the EditorBase later? I don't believe so.
    */
   virtual ~EditorBase();
 
   /**
+   * GetDocumentCharsetInternal() returns charset of the document.
+   */
+  nsresult GetDocumentCharsetInternal(nsACString& aCharset) const;
+
+  /**
    * SelectAllInternal() should be used instead of SelectAll() in editor
    * because SelectAll() creates AutoEditActionSetter but we should avoid
    * to create it as far as possible.
    */
   virtual nsresult SelectAllInternal();
 
   nsresult DetermineCurrentDirection();
   void FireInputEvent();
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -1806,24 +1806,24 @@ TextEditor::OutputToString(const nsAStri
   if (cancel || NS_FAILED(rv)) {
     return rv;
   }
   if (handled) {
     // This case will get triggered by password fields or single text node only.
     return rv;
   }
 
-  nsAutoCString charsetStr;
-  rv = GetDocumentCharacterSet(charsetStr);
-  if (NS_FAILED(rv) || charsetStr.IsEmpty()) {
-    charsetStr.AssignLiteral("windows-1252");
+  nsAutoCString charset;
+  rv = GetDocumentCharsetInternal(charset);
+  if (NS_FAILED(rv) || charset.IsEmpty()) {
+    charset.AssignLiteral("windows-1252");
   }
 
   nsCOMPtr<nsIDocumentEncoder> encoder =
-    GetAndInitDocEncoder(aFormatType, aFlags, charsetStr);
+    GetAndInitDocEncoder(aFormatType, aFlags, charset);
   if (NS_WARN_IF(!encoder)) {
     return NS_ERROR_FAILURE;
   }
 
   // XXX Why don't we call TextEditRules::DidDoAction() here?
   return encoder->EncodeToString(aOutputString);
 }