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. // If we tried to delete selection, set to true.
bool mDidDeleteSelection; 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: private:
void Clear() { mDidDeleteSelection = false; } void Clear() {
mDidDeleteSelection = false;
mDidExplicitlySetInterLine = false;
}
TopLevelEditSubActionData() = default; TopLevelEditSubActionData() = default;
TopLevelEditSubActionData(const TopLevelEditSubActionData& aOther) = delete; TopLevelEditSubActionData(const TopLevelEditSubActionData& aOther) = delete;

View File

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

View File

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

View File

@ -293,7 +293,7 @@ nsresult TextEditRules::DidDoAction(EditSubActionInfo& aInfo,
switch (aInfo.mEditSubAction) { switch (aInfo.mEditSubAction) {
case EditSubAction::eDeleteSelectedContent: case EditSubAction::eDeleteSelectedContent:
MOZ_ASSERT(!mIsHTMLEditRules); MOZ_ASSERT(!mIsHTMLEditRules);
return DidDeleteSelection(SetSelectionInterLinePosition::Yes); return DidDeleteSelection();
case EditSubAction::eInsertElement: case EditSubAction::eInsertElement:
case EditSubAction::eUndo: case EditSubAction::eUndo:
case EditSubAction::eRedo: 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 // If we replaced non-empty value with empty string, we need to delete the
// text node. // text node.
if (tString.IsEmpty()) { if (tString.IsEmpty()) {
DebugOnly<nsresult> rvIgnored = DebugOnly<nsresult> rvIgnored = DidDeleteSelection();
DidDeleteSelection(SetSelectionInterLinePosition::Yes);
MOZ_ASSERT(rvIgnored != NS_ERROR_EDITOR_DESTROYED); MOZ_ASSERT(rvIgnored != NS_ERROR_EDITOR_DESTROYED);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"DidDeleteSelection() failed"); "DidDeleteSelection() failed");
@ -1022,8 +1021,7 @@ nsresult TextEditRules::DeleteSelectionWithTransaction(
return NS_OK; return NS_OK;
} }
nsresult TextEditRules::DidDeleteSelection( nsresult TextEditRules::DidDeleteSelection() {
SetSelectionInterLinePosition aSetSelectionInterLinePosition) {
MOZ_ASSERT(IsEditorDataAvailable()); MOZ_ASSERT(IsEditorDataAvailable());
EditorDOMPoint selectionStartPoint( 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; return NS_OK;
} }
// We prevent the caret from sticking on the left of prior BR // 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 * This method may remove empty text node and makes guarantee that caret
* is never at left of <br> element. * is never at left of <br> element.
*/ */
enum class SetSelectionInterLinePosition { MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection();
Yes,
No,
};
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult DidDeleteSelection(
SetSelectionInterLinePosition aSetSelectionInterLinePosition);
nsresult WillSetTextProperty(bool* aCancel, bool* aHandled); nsresult WillSetTextProperty(bool* aCancel, bool* aHandled);