Bug 1574852 - part 67-3: Split HTMLEditRules::WillDeleteSelection() to 3 methods r=m_kato

First, we can split it with 3 parts:
1. preparation with current selection part.
2. handling deletion with collapsed selection part.
3. handling deletion with non-collapsed selection part.
The first should leave in `WillDeleteSelection()`, but the others should be
moved to independent methods.

With this change, we need to fix an odd case when there is no visible node
and `GetFirstSelectedTableCellElement()` returned error due to crossing
the method boundary.  The method returns error only when there is no selection
ranges.  In such case, we cannot handle deletion of current selection anyway.
So, it must not be a problem to handle the error immediately after calling
`GetFirstSelectedTableCellElement()`.  Note that this shouldn't occur in
normal cases since `WillDoAction()` checks it before calling
`WillDeleteSelection()`.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-09-05 13:37:57 +00:00
parent b9ab4d13e9
commit f3b99207af
2 changed files with 552 additions and 488 deletions

File diff suppressed because it is too large Load Diff

View File

@ -129,6 +129,39 @@ class HTMLEditRules : public TextEditRules {
WillDeleteSelection(nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers);
/**
* HandleDeleteAroundCollapsedSelection() handles deletion with collapsed
* `Selection`. Callers must guarantee that this is called only when
* `Selection` is collapsed.
*
* @param aDirectionAndAmount Direction of the deletion.
* @param aStripWrappers Must be eStrip or eNoStrip.
*/
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
HandleDeleteAroundCollapsedSelection(
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers);
/**
* HandleDeleteNonCollapsedSelection() handles deletion with non-collapsed
* `Selection`. Callers must guarantee that this is called only when
* `Selection` is NOT collapsed.
*
* @param aDirectionAndAmount Direction of the deletion.
* @param aStripWrappers Must be eStrip or eNoStrip.
* @param aSelectionWasCollpased If the caller extended `Selection`
* from collapsed, set this to `Yes`.
* Otherwise, i.e., `Selection` is not
* collapsed from the beginning, set
* this to `No`.
*/
enum class SelectionWasCollapsed { Yes, No };
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE EditActionResult
HandleDeleteNonCollapsedSelection(
nsIEditor::EDirection aDirectionAndAmount,
nsIEditor::EStripWrappers aStripWrappers,
SelectionWasCollapsed aSelectionWasCollapsed);
/**
* Called after deleting selected content.
* This method removes unnecessary empty nodes and/or inserts <br> if