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
--- 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);
}