Bug 1717156 - part 6: Get rid of nsIEditor::eEditorDontEchoPassword r=m_kato

It's used only by password field, i.e., only by `TextEditor`, and used
temporarily.  Additionally, there is some space in `TextEditor`.  So, we
can get rid of it, and make `TextEditor` store it directly.

Note that this allows to skip expensive `nsIEditor::SetFlags()` calls by
`AutoRestoreEditorState`.  This may improve setting `<input>.value` performance.

Differential Revision: https://phabricator.services.mozilla.com/D118266
This commit is contained in:
Masayuki Nakano
2021-06-22 00:18:08 +00:00
parent 0da607a288
commit 569104c02d
7 changed files with 26 additions and 19 deletions

View File

@@ -206,7 +206,9 @@ class MOZ_RAII AutoRestoreEditorState final {
MOZ_CAN_RUN_SCRIPT explicit AutoRestoreEditorState(TextEditor* aTextEditor)
: mTextEditor(aTextEditor),
mSavedFlags(mTextEditor->Flags()),
mSavedMaxLength(mTextEditor->MaxTextLength()) {
mSavedMaxLength(mTextEditor->MaxTextLength()),
mSavedEchoingPasswordPrevented(
mTextEditor->EchoingPasswordPrevented()) {
MOZ_ASSERT(mTextEditor);
// EditorBase::SetFlags() is a virtual method. Even though it does nothing
@@ -214,16 +216,19 @@ class MOZ_RAII AutoRestoreEditorState final {
// appearing the method in profile. So, this class should check if it's
// necessary to call.
uint32_t flags = mSavedFlags;
flags &= ~(nsIEditor::eEditorReadonlyMask);
flags |= nsIEditor::eEditorDontEchoPassword;
flags &= ~nsIEditor::eEditorReadonlyMask;
if (mSavedFlags != flags) {
// It's aTextEditor and whose lifetime must be guaranteed by the caller.
MOZ_KnownLive(mTextEditor)->SetFlags(flags);
}
mTextEditor->PreventToEchoPassword();
mTextEditor->SetMaxTextLength(-1);
}
MOZ_CAN_RUN_SCRIPT ~AutoRestoreEditorState() {
if (!mSavedEchoingPasswordPrevented) {
mTextEditor->AllowToEchoPassword();
}
mTextEditor->SetMaxTextLength(mSavedMaxLength);
// mTextEditor's lifetime must be guaranteed by owner of the instance
// since the constructor is marked as `MOZ_CAN_RUN_SCRIPT` and this is
@@ -235,6 +240,7 @@ class MOZ_RAII AutoRestoreEditorState final {
TextEditor* mTextEditor;
uint32_t mSavedFlags;
int32_t mSavedMaxLength;
bool mSavedEchoingPasswordPrevented;
};
/*****************************************************************************

View File

@@ -683,10 +683,6 @@ NS_IMETHODIMP EditorBase::SetFlags(uint32_t aFlags) {
// So, eEditorPasswordMask is available only when we're a `TextEditor`
// instance.
MOZ_ASSERT_IF(IsHTMLEditor(), !(aFlags & nsIEditor::eEditorPasswordMask));
// If we're a password editor, we show the last typed character for
// a while by default. eEditorDontEchoPassword prevents it. So, this flag
// is available only when we're a `TextEditor`.
MOZ_ASSERT_IF(IsHTMLEditor(), !(aFlags & nsIEditor::eEditorDontEchoPassword));
// eEditorMailMask specifies the editing rules of `HTMLEditor`. So, it's
// available only with `HTMLEditor` instance.
MOZ_ASSERT_IF(IsTextEditor(), !(aFlags & nsIEditor::eEditorMailMask));

View File

@@ -769,8 +769,7 @@ EditActionResult TextEditor::MaybeTruncateInsertionStringForMaxLength(
}
bool TextEditor::CanEchoPasswordNow() const {
if (!LookAndFeel::GetEchoPassword() ||
(mFlags & nsIEditor::eEditorDontEchoPassword)) {
if (!LookAndFeel::GetEchoPassword() || EchoingPasswordPrevented()) {
return false;
}

View File

@@ -75,8 +75,9 @@ TextEditor::TextEditor()
: mMaxTextLength(-1),
mUnmaskedStart(UINT32_MAX),
mUnmaskedLength(0),
mIsMaskingPassword(true) {
// printf("Size of TextEditor: %zu\n", sizeof(TextEditor));
mIsMaskingPassword(true),
mEchoingPasswordPrevented(false) {
printf("Size of TextEditor: %zu\n", sizeof(TextEditor));
static_assert(
sizeof(TextEditor) <= 512,
"TextEditor instance should be allocatable in the quantum class bins");

View File

@@ -192,6 +192,14 @@ class TextEditor final : public EditorBase,
*/
static char16_t PasswordMask();
/**
* If you want to prevent to echo password temporarily, use the following
* methods.
*/
bool EchoingPasswordPrevented() const { return mEchoingPasswordPrevented; }
void PreventToEchoPassword() { mEchoingPasswordPrevented = true; }
void AllowToEchoPassword() { mEchoingPasswordPrevented = false; }
protected: // May be called by friends.
/****************************************************************************
* Some friend classes are allowed to call the following protected methods.
@@ -490,6 +498,10 @@ class TextEditor final : public EditorBase,
// without setting `mMaskTimer`, set to false.
bool mIsMaskingPassword;
// Set to true if a manager of the instance wants to disable echoing password
// temporarily.
bool mEchoingPasswordPrevented;
friend class DeleteNodeTransaction;
friend class EditorBase;
friend class InsertNodeTransaction;

View File

@@ -75,12 +75,6 @@ interface nsIEditor : nsISupports
// Note that if this is not specified, link navigation is also enabled in
// the editable content.
const long eEditorAllowInteraction = 0x0200;
// If you want typed character to be immediately masked in password editor,
// specify this flag. If you want to keep last input character(s) visible
// for a while, unset this. If you want to manage the masked range, you
// can use `unmask()` below.
// So, this flag is available only when the instance is a text editor.
const long eEditorDontEchoPassword = 0x0400;
// when this flag is set, the internal direction of the editor is RTL.
// if neither of the direction flags are set, the direction is determined
// from the text control's content node.

View File

@@ -1203,8 +1203,7 @@ function runEditorFlagChangeTests() {
const kIMEStateChangeFlags = Ci.nsIEditor.eEditorReadonlyMask;
const kFlagsNotAllowedWithHTMLEditor =
Ci.nsIEditor.eEditorPasswordMask |
Ci.nsIEditor.eEditorSingleLineMask |
Ci.nsIEditor.eEditorDontEchoPassword;
Ci.nsIEditor.eEditorSingleLineMask;
var editor = window.docShell.editor;
var flags = editor.flags;