Bug 1572681 - part 6: Move TextEditRules::mDidExplicitlySetInterline to HTMLEditRules r=m_kato

`TextEditRules::mDidExplicitlySetInterline` is set to true only by
`HTMLEditRules`, but `TextEditRules::DidDeleteSelection()` refers it.
So, it's enough to make `TextEditRules::DidDeleteSelection()` take the
value and we can move it into `HTMLEditRules`.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-08-13 08:53:45 +00:00
parent 8870cb5d53
commit 0e763a968a
4 changed files with 23 additions and 15 deletions

View File

@ -193,6 +193,7 @@ HTMLEditRules::HTMLEditRules()
mListenerEnabled(false),
mReturnInEmptyLIKillsList(false),
mDidDeleteSelection(false),
mDidExplicitlySetInterline(false),
mDidRangedDelete(false),
mDidEmptyParentBlocksRemoved(false),
mRestoreContentEditableCount(false),
@ -206,6 +207,7 @@ void HTMLEditRules::InitFields() {
mDocChangeRange = nullptr;
mReturnInEmptyLIKillsList = true;
mDidDeleteSelection = false;
mDidExplicitlySetInterline = false;
mDidRangedDelete = false;
mDidEmptyParentBlocksRemoved = false;
mRestoreContentEditableCount = false;
@ -3931,11 +3933,12 @@ nsresult HTMLEditRules::DidDeleteSelection() {
}
// call through to base class
nsresult rv = TextEditRules::DidDeleteSelection();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
nsresult rv = TextEditRules::DidDeleteSelection(
mDidExplicitlySetInterline ? SetSelectionInterLinePosition::No
: SetSelectionInterLinePosition::Yes);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
"TextEditRules::DidDeleteSelection() failed");
return rv;
}
nsresult HTMLEditRules::WillMakeList(const nsAString* aListType,

View File

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

View File

@ -91,14 +91,12 @@ TextEditRules::TextEditRules()
#ifdef DEBUG
mIsHandling(false),
#endif // #ifdef DEBUG
mDidExplicitlySetInterline(false),
mIsHTMLEditRules(false) {
InitFields();
}
void TextEditRules::InitFields() {
mTextEditor = nullptr;
mDidExplicitlySetInterline = false;
}
HTMLEditRules* TextEditRules::AsHTMLEditRules() {
@ -163,8 +161,6 @@ nsresult TextEditRules::BeforeEdit() {
return NS_ERROR_EDITOR_DESTROYED;
}
mDidExplicitlySetInterline = false;
#ifdef DEBUG
mIsHandling = true;
#endif // #ifdef DEBUG
@ -296,7 +292,8 @@ nsresult TextEditRules::DidDoAction(EditSubActionInfo& aInfo,
switch (aInfo.mEditSubAction) {
case EditSubAction::eDeleteSelectedContent:
return DidDeleteSelection();
MOZ_ASSERT(!mIsHTMLEditRules);
return DidDeleteSelection(SetSelectionInterLinePosition::Yes);
case EditSubAction::eInsertElement:
case EditSubAction::eUndo:
case EditSubAction::eRedo:
@ -783,6 +780,7 @@ nsresult TextEditRules::WillSetText(bool* aCancel, bool* aHandled,
const nsAString* aString,
int32_t aMaxLength) {
MOZ_ASSERT(IsEditorDataAvailable());
MOZ_ASSERT(!mIsHTMLEditRules);
MOZ_ASSERT(aCancel);
MOZ_ASSERT(aHandled);
MOZ_ASSERT(aString);
@ -897,7 +895,8 @@ 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();
DebugOnly<nsresult> rvIgnored =
DidDeleteSelection(SetSelectionInterLinePosition::Yes);
MOZ_ASSERT(rvIgnored != NS_ERROR_EDITOR_DESTROYED);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored),
"DidDeleteSelection() failed");
@ -1023,7 +1022,8 @@ nsresult TextEditRules::DeleteSelectionWithTransaction(
return NS_OK;
}
nsresult TextEditRules::DidDeleteSelection() {
nsresult TextEditRules::DidDeleteSelection(
SetSelectionInterLinePosition aSetSelectionInterLinePosition) {
MOZ_ASSERT(IsEditorDataAvailable());
EditorDOMPoint selectionStartPoint(
@ -1046,7 +1046,7 @@ nsresult TextEditRules::DidDeleteSelection() {
}
}
if (mDidExplicitlySetInterline) {
if (aSetSelectionInterLinePosition != SetSelectionInterLinePosition::Yes) {
return NS_OK;
}
// We prevent the caret from sticking on the left of prior BR

View File

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