Bug 1467802 - part 1: Create TextEditor::WrapWidth() for internal use of nsIPlaintextEditor::GetWrapWidth() r?m_kato
Let's create non-virtual and simple accessor for TextEditor::mWrapColumn.
MozReview-Commit-ID: 97LhhOgkx4A
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -1399,19 +1399,20 @@ TextEditor::GetTextLength(int32_t* aCoun
*aCount = totalLength;
return NS_OK;
}
NS_IMETHODIMP
TextEditor::GetWrapWidth(int32_t* aWrapColumn)
{
- NS_ENSURE_TRUE( aWrapColumn, NS_ERROR_NULL_POINTER);
-
- *aWrapColumn = mWrapColumn;
+ if (NS_WARN_IF(!aWrapColumn)) {
+ return NS_ERROR_INVALID_ARG;
+ }
+ *aWrapColumn = WrapWidth();
return NS_OK;
}
//
// See if the style value includes this attribute, and if it does,
// cut out everything from the attribute to the next semicolon.
//
static void CutStyle(const char* stylename, nsString& styleValue)
@@ -1742,20 +1743,19 @@ TextEditor::GetAndInitDocEncoder(const n
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
if (!aCharset.IsEmpty() && !aCharset.EqualsLiteral("null")) {
docEncoder->SetCharset(aCharset);
}
- int32_t wc;
- (void) GetWrapWidth(&wc);
- if (wc >= 0) {
- (void) docEncoder->SetWrapColumn(wc);
+ int32_t wrapWidth = WrapWidth();
+ if (wrapWidth >= 0) {
+ Unused << docEncoder->SetWrapColumn(wrapWidth);
}
// Set the selection, if appropriate.
// We do this either if the OutputSelectionOnly flag is set,
// in which case we use our existing selection ...
if (aFlags & nsIDocumentEncoder::OutputSelectionOnly) {
RefPtr<Selection> selection = GetSelection();
if (NS_WARN_IF(!selection)) {
@@ -1962,37 +1962,38 @@ TextEditor::SharedOutputString(uint32_t
// If the selection isn't collapsed, we'll use the whole document.
return OutputToString(NS_LITERAL_STRING("text/plain"), aFlags, aResult);
}
NS_IMETHODIMP
TextEditor::Rewrap(bool aRespectNewlines)
{
- int32_t wrapCol;
- nsresult rv = GetWrapWidth(&wrapCol);
- NS_ENSURE_SUCCESS(rv, NS_OK);
-
// Rewrap makes no sense if there's no wrap column; default to 72.
- if (wrapCol <= 0) {
- wrapCol = 72;
+ int32_t wrapWidth = WrapWidth();
+ if (wrapWidth <= 0) {
+ wrapWidth = 72;
}
nsAutoString current;
bool isCollapsed;
- rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted
- | nsIDocumentEncoder::OutputLFLineBreak,
- &isCollapsed, current);
- NS_ENSURE_SUCCESS(rv, rv);
+ nsresult rv = SharedOutputString(nsIDocumentEncoder::OutputFormatted |
+ nsIDocumentEncoder::OutputLFLineBreak,
+ &isCollapsed, current);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
nsString wrapped;
uint32_t firstLineOffset = 0; // XXX need to reset this if there is a selection
- rv = InternetCiter::Rewrap(current, wrapCol, firstLineOffset,
+ rv = InternetCiter::Rewrap(current, wrapWidth, firstLineOffset,
aRespectNewlines, wrapped);
- NS_ENSURE_SUCCESS(rv, rv);
+ if (NS_WARN_IF(NS_FAILED(rv))) {
+ return rv;
+ }
if (isCollapsed) {
DebugOnly<nsresult> rv = SelectAllInternal();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Failed to select all text");
}
return InsertTextWithQuotations(wrapped);
}
--- a/editor/libeditor/TextEditor.h
+++ b/editor/libeditor/TextEditor.h
@@ -278,16 +278,18 @@ protected: // Called by helper classes.
virtual void OnEndHandlingTopLevelEditSubAction() override;
void BeginEditorInit();
nsresult EndEditorInit();
protected: // Shouldn't be used by friend classes
virtual ~TextEditor();
+ int32_t WrapWidth() const { return mWrapColumn; }
+
/**
* Make the given selection span the entire document.
*/
virtual nsresult SelectEntireDocument(Selection* aSelection) override;
/**
* OnInputText() is called when user inputs text with keyboard or something.
*