Bug 1574852 - part 77: Move HTMLEditRules::WillIndent(), HTMLEditRules::WillHTMLIndent() and HTMLEditRules::WillCSSIndent() to HTMLEditor r=m_kato

The caller of `HTMLEditRules::WillDoAction()` is shared with "outdent".
Therefore, this patch is a preparation of makes `HTMLEditor` stop calling it.

Be aware, `HTMLEditRules::WillIndent()` won't cancel the action, and also
always handles the action unless editor has already been destroyed.  Therefore,
we can remove the dead code in `HTMLEditor::IndentOrOutdentAsSubAction()`
right now.

Differential Revision: https://phabricator.services.mozilla.com/D44781

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-09-08 04:35:52 +00:00
parent 67f54f71f8
commit 183c471149
3 changed files with 73 additions and 100 deletions

View File

@ -784,8 +784,15 @@ nsresult HTMLEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
NS_WARNING_ASSERTION(result.Succeeded(),
"HandleDeleteSelection() failed");
return result.Rv();
case EditSubAction::eIndent:
return WillIndent(aCancel, aHandled);
case EditSubAction::eIndent: {
EditActionResult result =
MOZ_KnownLive(HTMLEditorRef()).HandleIndentAtSelection();
*aHandled = result.Handled();
*aCancel = result.Canceled();
NS_WARNING_ASSERTION(result.Succeeded(),
"HandleIndentAtSelection() failed");
return result.Rv();
}
case EditSubAction::eOutdent:
return WillOutdent(aCancel, aHandled);
case EditSubAction::eSetPositionToAbsolute:
@ -4926,62 +4933,50 @@ nsresult HTMLEditor::MaybeInsertPaddingBRElementForEmptyLastLineAtSelection() {
return rv;
}
nsresult HTMLEditRules::WillIndent(bool* aCancel, bool* aHandled) {
MOZ_ASSERT(IsEditorDataAvailable());
if (HTMLEditorRef().IsCSSEnabled()) {
nsresult rv = WillCSSIndent(aCancel, aHandled);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
nsresult rv = WillHTMLIndent(aCancel, aHandled);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
return NS_OK;
}
nsresult HTMLEditRules::WillCSSIndent(bool* aCancel, bool* aHandled) {
MOZ_ASSERT(IsEditorDataAvailable());
if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
return NS_ERROR_INVALID_ARG;
}
EditActionResult HTMLEditor::HandleIndentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
// FYI: Ignore cancel result of WillInsert().
nsresult rv = MOZ_KnownLive(HTMLEditorRef()).WillInsert();
nsresult rv = WillInsert();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
return EditActionResult(NS_ERROR_EDITOR_DESTROYED);
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "WillInsert() failed");
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "WillInsert() failed, but ignored");
*aCancel = false;
*aHandled = true;
if (IsCSSEnabled()) {
nsresult rv = HandleCSSIndentAtSelection();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HandleCSSIndentAtSelection() failed");
return EditActionHandled(rv);
}
rv = HandleHTMLIndentAtSelection();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HandleHTMLIndent() failed");
return EditActionHandled(rv);
}
nsresult HTMLEditor::HandleCSSIndentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
if (!SelectionRefPtr()->IsCollapsed()) {
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
nsresult rv = MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// IndentAroundSelectionWithCSS() creates AutoSelectionRestorer.
// HandleCSSIndentAtSelectionInternal() creates AutoSelectionRestorer.
// Therefore, even if it returns NS_OK, editor might have been destroyed
// at restoring Selection.
rv = MOZ_KnownLive(HTMLEditorRef()).IndentAroundSelectionWithCSS();
if (NS_WARN_IF(!CanHandleEditAction())) {
nsresult rv = HandleCSSIndentAtSelectionInternal();
if (NS_WARN_IF(Destroyed())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HandleCSSIndentAtSelectionInternal() failed");
return rv;
}
nsresult HTMLEditor::IndentAroundSelectionWithCSS() {
nsresult HTMLEditor::HandleCSSIndentAtSelectionInternal() {
MOZ_ASSERT(IsTopLevelEditSubActionDataAvailable());
AutoSelectionRestorer restoreSelectionLater(*this);
@ -5239,45 +5234,29 @@ nsresult HTMLEditor::IndentAroundSelectionWithCSS() {
return NS_OK;
}
nsresult HTMLEditRules::WillHTMLIndent(bool* aCancel, bool* aHandled) {
MOZ_ASSERT(IsEditorDataAvailable());
if (NS_WARN_IF(!aCancel) || NS_WARN_IF(!aHandled)) {
return NS_ERROR_INVALID_ARG;
}
// FYI: Ignore cancel result of WillInsert().
nsresult rv = MOZ_KnownLive(HTMLEditorRef()).WillInsert();
if (NS_WARN_IF(rv == NS_ERROR_EDITOR_DESTROYED)) {
return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "WillInsert() failed");
*aCancel = false;
*aHandled = true;
nsresult HTMLEditor::HandleHTMLIndentAtSelection() {
MOZ_ASSERT(IsEditActionDataAvailable());
if (!SelectionRefPtr()->IsCollapsed()) {
nsresult rv = MOZ_KnownLive(HTMLEditorRef())
.MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
nsresult rv = MaybeExtendSelectionToHardLineEdgesForBlockEditAction();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
// IndentAroundSelectionWithHTML() creates AutoSelectionRestorer.
// HandleHTMLIndentAtSelectionInternal() creates AutoSelectionRestorer.
// Therefore, even if it returns NS_OK, editor might have been destroyed
// at restoring Selection.
rv = MOZ_KnownLive(HTMLEditorRef()).IndentAroundSelectionWithHTML();
if (NS_WARN_IF(!CanHandleEditAction())) {
nsresult rv = HandleHTMLIndentAtSelectionInternal();
if (NS_WARN_IF(Destroyed())) {
return NS_ERROR_EDITOR_DESTROYED;
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"HandleHTMLIndentAtSelectionInternal() failed");
return rv;
}
nsresult HTMLEditor::IndentAroundSelectionWithHTML() {
nsresult HTMLEditor::HandleHTMLIndentAtSelectionInternal() {
MOZ_ASSERT(IsTopLevelEditSubActionDataAvailable());
AutoSelectionRestorer restoreSelectionLater(*this);

View File

@ -125,36 +125,6 @@ class HTMLEditRules : public TextEditRules {
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection();
/**
* Called before indenting around Selection. This method actually tries to
* indent the contents.
*
* @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult WillIndent(bool* aCancel, bool* aHandled);
/**
* Called before indenting around Selection and it's in CSS mode.
* This method actually tries to indent the contents.
*
* @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult WillCSSIndent(bool* aCancel, bool* aHandled);
/**
* Called before indenting around Selection and it's not in CSS mode.
* This method actually tries to indent the contents.
*
* @param aCancel Returns true if the operation is canceled.
* @param aHandled Returns true if the edit action is handled.
*/
MOZ_CAN_RUN_SCRIPT
MOZ_MUST_USE nsresult WillHTMLIndent(bool* aCancel, bool* aHandled);
/**
* Called before outdenting around Selection. This method actually tries
* to indent the contents.

View File

@ -2333,20 +2333,44 @@ class HTMLEditor final : public TextEditor,
ChangeMarginStart(Element& aElement, ChangeMargin aChangeMargin);
/**
* IndentAroundSelectionWithCSS() indents around Selection with CSS.
* HandleCSSIndentAtSelectionInternal() indents around Selection with CSS.
* This method creates AutoSelectionRestorer. Therefore, each caller
* need to check if the editor is still available even if this returns
* NS_OK.
* NOTE: Use HandleCSSIndentAtSelection() instead.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult IndentAroundSelectionWithCSS();
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult HandleCSSIndentAtSelectionInternal();
/**
* IndentAroundSelectionWithHTML() indents around Selection with HTML.
* HandleHTMLIndentAtSelectionInternal() indents around Selection with HTML.
* This method creates AutoSelectionRestorer. Therefore, each caller
* need to check if the editor is still available even if this returns
* NS_OK.
* NOTE: Use HandleHTMLIndentAtSelection() instead.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult IndentAroundSelectionWithHTML();
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult
HandleHTMLIndentAtSelectionInternal();
/**
* HandleCSSIndentAtSelection() indents around Selection with CSS.
* NOTE: This is a helper method of `HandleIndentAtSelection()`. If you
* want to call this directly, you should check whether you need
* do do something which `HandleIndentAtSelection()` does.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult HandleCSSIndentAtSelection();
/**
* HandleHTMLIndentAtSelection() indents around Selection with HTML.
* NOTE: This is a helper method of `HandleIndentAtSelection()`. If you
* want to call this directly, you should check whether you need
* do do something which `HandleIndentAtSelection()` does.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult HandleHTMLIndentAtSelection();
/**
* HandleIndentAtSelection() indents around Selection with HTML or CSS.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult HandleIndentAtSelection();
/**
* OutdentPartOfBlock() outdents the nodes between aStartOfOutdent and