зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1467802 - part 4: Create TextEditor::ComputeValueInternal() for internal use of nsIPlaintextEditor::OutputToString() r=m_kato
For reducing virtual calls of nsIPlaintextEditor::OutputToString(), TextEditor should have new non-virtual public method, ComputeTextValue() and shared code between it and OutputToString() as ComputeValueInternal(). MozReview-Commit-ID: KFeovQ568bf --HG-- extra : rebase_source : a5cfb24cefe44f7c60e649959ed49350ed00d4d6
This commit is contained in:
Родитель
91c0a26b3f
Коммит
3a1344255b
|
@ -2221,8 +2221,8 @@ nsTextEditorState::GetValue(nsAString& aValue, bool aIgnoreWrap) const
|
|||
{ /* Scope for AutoNoJSAPI. */
|
||||
AutoNoJSAPI nojsapi;
|
||||
|
||||
mTextEditor->OutputToString(NS_LITERAL_STRING("text/plain"), flags,
|
||||
aValue);
|
||||
DebugOnly<nsresult> rv = mTextEditor->ComputeTextValue(flags, aValue);
|
||||
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to get value");
|
||||
}
|
||||
// Only when the result doesn't include line breaks caused by hard-wrap,
|
||||
// mCacheValue should cache the value.
|
||||
|
|
|
@ -1786,15 +1786,24 @@ TextEditor::GetAndInitDocEncoder(const nsAString& aFormatType,
|
|||
|
||||
NS_IMETHODIMP
|
||||
TextEditor::OutputToString(const nsAString& aFormatType,
|
||||
uint32_t aFlags,
|
||||
uint32_t aDocumentEncoderFlags,
|
||||
nsAString& aOutputString)
|
||||
{
|
||||
return ComputeValueInternal(aFormatType, aDocumentEncoderFlags,
|
||||
aOutputString);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEditor::ComputeValueInternal(const nsAString& aFormatType,
|
||||
uint32_t aDocumentEncoderFlags,
|
||||
nsAString& aOutputString) const
|
||||
{
|
||||
// Protect the edit rules object from dying
|
||||
RefPtr<TextEditRules> rules(mRules);
|
||||
|
||||
EditSubActionInfo subActionInfo(EditSubAction::eComputeTextToOutput);
|
||||
subActionInfo.outString = &aOutputString;
|
||||
subActionInfo.flags = aFlags;
|
||||
subActionInfo.flags = aDocumentEncoderFlags;
|
||||
subActionInfo.outputFormat = &aFormatType;
|
||||
Selection* selection = GetSelection();
|
||||
if (NS_WARN_IF(!selection)) {
|
||||
|
@ -1818,7 +1827,7 @@ TextEditor::OutputToString(const nsAString& aFormatType,
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIDocumentEncoder> encoder =
|
||||
GetAndInitDocEncoder(aFormatType, aFlags, charset);
|
||||
GetAndInitDocEncoder(aFormatType, aDocumentEncoderFlags, charset);
|
||||
if (NS_WARN_IF(!encoder)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -1959,8 +1968,7 @@ TextEditor::SharedOutputString(uint32_t aFlags,
|
|||
aFlags |= nsIDocumentEncoder::OutputSelectionOnly;
|
||||
}
|
||||
// If the selection isn't collapsed, we'll use the whole document.
|
||||
|
||||
return OutputToString(NS_LITERAL_STRING("text/plain"), aFlags, aResult);
|
||||
return ComputeValueInternal(NS_LITERAL_STRING("text/plain"), aFlags, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -190,6 +190,20 @@ public:
|
|||
*/
|
||||
nsresult OnDrop(dom::DragEvent* aDropEvent);
|
||||
|
||||
/**
|
||||
* ComputeTextValue() computes plaintext value of this editor. This may be
|
||||
* too expensive if it's in hot path.
|
||||
*
|
||||
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
|
||||
* @param aCharset Encoding of the document.
|
||||
*/
|
||||
nsresult ComputeTextValue(uint32_t aDocumentEncoderFlags,
|
||||
nsAString& aOutputString) const
|
||||
{
|
||||
return ComputeValueInternal(NS_LITERAL_STRING("text/plain"),
|
||||
aDocumentEncoderFlags, aOutputString);
|
||||
}
|
||||
|
||||
protected: // May be called by friends.
|
||||
/****************************************************************************
|
||||
* Some classes like TextEditRules, HTMLEditRules, WSRunObject which are
|
||||
|
@ -341,6 +355,18 @@ protected: // Shouldn't be used by friend classes
|
|||
uint32_t aDocumentEncoderFlags,
|
||||
const nsACString& aCharset) const;
|
||||
|
||||
/**
|
||||
* ComputeValueInternal() computes string value of this editor for given
|
||||
* format. This may be too expensive if it's in hot path.
|
||||
*
|
||||
* @param aFormatType MIME type like "text/plain".
|
||||
* @param aDocumentEncoderFlags Flags of nsIDocumentEncoder.
|
||||
* @param aCharset Encoding of the document.
|
||||
*/
|
||||
nsresult ComputeValueInternal(const nsAString& aFormatType,
|
||||
uint32_t aDocumentEncoderFlags,
|
||||
nsAString& aOutputString) const;
|
||||
|
||||
/**
|
||||
* Factored methods for handling insertion of data from transferables
|
||||
* (drag&drop or clipboard).
|
||||
|
|
Загрузка…
Ссылка в новой задаче