Bug 1574852 - part 50: Move TextEditRules::UndefineCaretBidiLevel() to EditorBase r=m_kato

It's used both by `TextEditRules` and `HTMLEditRules` so that `EditorBase`
should have it instead.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-09-02 10:08:57 +00:00
parent d6d83bd331
commit b588b7f775
6 changed files with 28 additions and 25 deletions

View File

@ -5211,6 +5211,23 @@ NS_IMETHODIMP EditorBase::GetPasswordMask(nsAString& aPasswordMask) {
return NS_OK; return NS_OK;
} }
void EditorBase::UndefineCaretBidiLevel() const {
MOZ_ASSERT(IsEditActionDataAvailable());
/**
* After inserting text the caret Bidi level must be set to the level of the
* inserted text.This is difficult, because we cannot know what the level is
* until after the Bidi algorithm is applied to the whole paragraph.
*
* So we set the caret Bidi level to UNDEFINED here, and the caret code will
* set it correctly later
*/
nsFrameSelection* frameSelection = SelectionRefPtr()->GetFrameSelection();
if (frameSelection) {
frameSelection->UndefineCaretBidiLevel();
}
}
/****************************************************************************** /******************************************************************************
* EditorBase::AutoSelectionRestorer * EditorBase::AutoSelectionRestorer
*****************************************************************************/ *****************************************************************************/

View File

@ -2035,6 +2035,12 @@ class EditorBase : public nsIEditor,
*/ */
void HideCaret(bool aHide); void HideCaret(bool aHide);
protected: // Edit sub-action handler
/**
* UndefineCaretBidiLevel() resets bidi level of the caret.
*/
void UndefineCaretBidiLevel() const;
protected: // Called by helper classes. protected: // Called by helper classes.
/** /**
* OnStartToHandleTopLevelEditSubAction() is called when * OnStartToHandleTopLevelEditSubAction() is called when

View File

@ -767,12 +767,12 @@ nsresult HTMLEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
switch (aInfo.mEditSubAction) { switch (aInfo.mEditSubAction) {
case EditSubAction::eInsertText: case EditSubAction::eInsertText:
case EditSubAction::eInsertTextComingFromIME: case EditSubAction::eInsertTextComingFromIME:
UndefineCaretBidiLevel(); TextEditorRef().UndefineCaretBidiLevel();
return MOZ_KnownLive(HTMLEditorRef()) return MOZ_KnownLive(HTMLEditorRef())
.WillInsertText(aInfo.mEditSubAction, aCancel, aHandled, .WillInsertText(aInfo.mEditSubAction, aCancel, aHandled,
aInfo.inString, aInfo.outString, aInfo.maxLength); aInfo.inString, aInfo.outString, aInfo.maxLength);
case EditSubAction::eInsertParagraphSeparator: { case EditSubAction::eInsertParagraphSeparator: {
UndefineCaretBidiLevel(); TextEditorRef().UndefineCaretBidiLevel();
EditActionResult result = WillInsertParagraphSeparator(); EditActionResult result = WillInsertParagraphSeparator();
if (NS_WARN_IF(result.Failed())) { if (NS_WARN_IF(result.Failed())) {
return result.Rv(); return result.Rv();

View File

@ -203,7 +203,7 @@ nsresult TextEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
// my kingdom for dynamic cast // my kingdom for dynamic cast
switch (aInfo.mEditSubAction) { switch (aInfo.mEditSubAction) {
case EditSubAction::eInsertLineBreak: { case EditSubAction::eInsertLineBreak: {
UndefineCaretBidiLevel(); TextEditorRef().UndefineCaretBidiLevel();
EditActionResult result = WillInsertLineBreak(aInfo.maxLength); EditActionResult result = WillInsertLineBreak(aInfo.maxLength);
if (NS_WARN_IF(result.Failed())) { if (NS_WARN_IF(result.Failed())) {
return result.Rv(); return result.Rv();
@ -215,11 +215,11 @@ nsresult TextEditRules::WillDoAction(EditSubActionInfo& aInfo, bool* aCancel,
} }
case EditSubAction::eInsertText: case EditSubAction::eInsertText:
case EditSubAction::eInsertTextComingFromIME: case EditSubAction::eInsertTextComingFromIME:
UndefineCaretBidiLevel(); TextEditorRef().UndefineCaretBidiLevel();
return WillInsertText(aInfo.mEditSubAction, aCancel, aHandled, return WillInsertText(aInfo.mEditSubAction, aCancel, aHandled,
aInfo.inString, aInfo.outString, aInfo.maxLength); aInfo.inString, aInfo.outString, aInfo.maxLength);
case EditSubAction::eSetText: case EditSubAction::eSetText:
UndefineCaretBidiLevel(); TextEditorRef().UndefineCaretBidiLevel();
return WillSetText(aCancel, aHandled, aInfo.inString, aInfo.maxLength); return WillSetText(aCancel, aHandled, aInfo.inString, aInfo.maxLength);
case EditSubAction::eDeleteSelectedContent: case EditSubAction::eDeleteSelectedContent:
return WillDeleteSelection(aInfo.collapsedAction, aCancel, aHandled); return WillDeleteSelection(aInfo.collapsedAction, aCancel, aHandled);

View File

@ -249,8 +249,6 @@ class TextEditRules {
nsAString* aOutString, int32_t aMaxLength, nsAString* aOutString, int32_t aMaxLength,
bool* aTruncated); bool* aTruncated);
void UndefineCaretBidiLevel();
nsresult CheckBidiLevelForDeletion(const EditorRawDOMPoint& aSelectionPoint, nsresult CheckBidiLevelForDeletion(const EditorRawDOMPoint& aSelectionPoint,
nsIEditor::EDirection aAction, nsIEditor::EDirection aAction,
bool* aCancel); bool* aCancel);

View File

@ -82,22 +82,4 @@ nsresult TextEditRules::CheckBidiLevelForDeletion(
return NS_OK; return NS_OK;
} }
void TextEditRules::UndefineCaretBidiLevel() {
MOZ_ASSERT(IsEditorDataAvailable());
/**
* After inserting text the caret Bidi level must be set to the level of the
* inserted text.This is difficult, because we cannot know what the level is
* until after the Bidi algorithm is applied to the whole paragraph.
*
* So we set the caret Bidi level to UNDEFINED here, and the caret code will
* set it correctly later
*/
RefPtr<nsFrameSelection> frameSelection =
SelectionRefPtr()->GetFrameSelection();
if (frameSelection) {
frameSelection->UndefineCaretBidiLevel();
}
}
} // namespace mozilla } // namespace mozilla