Bug 1572685 - part 2: Move HTMLEditRules::mDidExplicitlySetInterLine to TopLevelEditSubActionData r=m_kato

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-08-20 01:50:02 +00:00
parent 992c1c0972
commit 396a69a2bc
5 changed files with 23 additions and 23 deletions

View File

@ -615,8 +615,15 @@ class EditorBase : public nsIEditor,
// If we tried to delete selection, set to true.
bool mDidDeleteSelection;
// If we have explicitly set selection inter line, set to true.
// `AfterEdit()` or something shouldn't overwrite it in such case.
bool mDidExplicitlySetInterLine;
private:
void Clear() { mDidDeleteSelection = false; }
void Clear() {
mDidDeleteSelection = false;
mDidExplicitlySetInterLine = false;
}
TopLevelEditSubActionData() = default;
TopLevelEditSubActionData(const TopLevelEditSubActionData& aOther) = delete;

View File

@ -192,7 +192,6 @@ HTMLEditRules::HTMLEditRules()
mInitialized(false),
mListenerEnabled(false),
mReturnInEmptyLIKillsList(false),
mDidExplicitlySetInterline(false),
mDidRangedDelete(false),
mDidEmptyParentBlocksRemoved(false),
mRestoreContentEditableCount(false),
@ -205,7 +204,6 @@ void HTMLEditRules::InitFields() {
mHTMLEditor = nullptr;
mDocChangeRange = nullptr;
mReturnInEmptyLIKillsList = true;
mDidExplicitlySetInterline = false;
mDidRangedDelete = false;
mDidEmptyParentBlocksRemoved = false;
mRestoreContentEditableCount = false;
@ -327,8 +325,6 @@ nsresult HTMLEditRules::BeforeEdit() {
return NS_OK; // We should do nothing if we're being initialized.
}
mDidExplicitlySetInterline = false;
#ifdef DEBUG
mIsHandling = true;
#endif // #ifdef DEBUG
@ -675,7 +671,9 @@ nsresult HTMLEditRules::AfterEditInner() {
}
// adjust selection HINT if needed
if (!mDidExplicitlySetInterline) {
if (!HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidExplicitlySetInterLine) {
CheckInterlinePosition();
}
@ -2640,7 +2638,9 @@ nsresult HTMLEditRules::WillDeleteSelection(
SelectionRefPtr()->SetInterlinePosition(false, ignoredError);
NS_WARNING_ASSERTION(!ignoredError.Failed(),
"Failed to unset interline position");
mDidExplicitlySetInterline = true;
HTMLEditorRef()
.TopLevelEditSubActionDataRef()
.mDidExplicitlySetInterLine = true;
*aHandled = true;
// There is one exception to the move only case. If the <hr> is
@ -3928,9 +3928,7 @@ nsresult HTMLEditRules::DidDeleteSelection() {
}
// call through to base class
nsresult rv = TextEditRules::DidDeleteSelection(
mDidExplicitlySetInterline ? SetSelectionInterLinePosition::No
: SetSelectionInterLinePosition::Yes);
nsresult rv = TextEditRules::DidDeleteSelection();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditRules::DidDeleteSelection() failed");
return rv;

View File

@ -1351,7 +1351,6 @@ class HTMLEditRules : public TextEditRules {
bool mInitialized;
bool mListenerEnabled;
bool mReturnInEmptyLIKillsList;
bool mDidExplicitlySetInterline;
bool mDidRangedDelete;
bool mDidEmptyParentBlocksRemoved;
bool mRestoreContentEditableCount;

View File

@ -293,7 +293,7 @@ nsresult TextEditRules::DidDoAction(EditSubActionInfo& aInfo,
switch (aInfo.mEditSubAction) {
case EditSubAction::eDeleteSelectedContent:
MOZ_ASSERT(!mIsHTMLEditRules);
return DidDeleteSelection(SetSelectionInterLinePosition::Yes);
return DidDeleteSelection();
case EditSubAction::eInsertElement:
case EditSubAction::eUndo:
case EditSubAction::eRedo:
@ -895,8 +895,7 @@ nsresult TextEditRules::WillSetText(bool* aCancel, bool* aHandled,
// If we replaced non-empty value with empty string, we need to delete the
// text node.
if (tString.IsEmpty()) {
DebugOnly<nsresult> rvIgnored =
DidDeleteSelection(SetSelectionInterLinePosition::Yes);
DebugOnly<nsresult> rvIgnored = DidDeleteSelection();
MOZ_ASSERT(rvIgnored != NS_ERROR_EDITOR_DESTROYED);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"DidDeleteSelection() failed");
@ -1022,8 +1021,7 @@ nsresult TextEditRules::DeleteSelectionWithTransaction(
return NS_OK;
}
nsresult TextEditRules::DidDeleteSelection(
SetSelectionInterLinePosition aSetSelectionInterLinePosition) {
nsresult TextEditRules::DidDeleteSelection() {
MOZ_ASSERT(IsEditorDataAvailable());
EditorDOMPoint selectionStartPoint(
@ -1046,7 +1044,10 @@ nsresult TextEditRules::DidDeleteSelection(
}
}
if (aSetSelectionInterLinePosition != SetSelectionInterLinePosition::Yes) {
// Note that this may be true only when this is HTMLEditRules.
if (TextEditorRef()
.TopLevelEditSubActionDataRef()
.mDidExplicitlySetInterLine) {
return NS_OK;
}
// We prevent the caret from sticking on the left of prior BR

View File

@ -214,12 +214,7 @@ class TextEditRules {
* This method may remove empty text node and makes guarantee that caret
* is never at left of <br> element.
*/
enum class SetSelectionInterLinePosition {
Yes,
No,
};
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection(
SetSelectionInterLinePosition aSetSelectionInterLinePosition);
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection();
nsresult WillSetTextProperty(bool* aCancel, bool* aHandled);