/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef mozilla_TextControlState_h #define mozilla_TextControlState_h #include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/EnumSet.h" #include "mozilla/Maybe.h" #include "mozilla/TextControlElement.h" #include "mozilla/UniquePtr.h" #include "mozilla/WeakPtr.h" #include "mozilla/dom/HTMLInputElementBinding.h" #include "mozilla/dom/Nullable.h" #include "nsCycleCollectionParticipant.h" #include "nsITextControlFrame.h" #include "nsITimer.h" class nsTextControlFrame; class nsISelectionController; class nsFrameSelection; class nsFrame; namespace mozilla { class AutoTextControlHandlingState; class ErrorResult; class IMEContentObserver; class TextEditor; class TextInputListener; class TextInputSelectionController; namespace dom { class Element; class HTMLInputElement; } // namespace dom /** * PasswordMaskData stores making information and necessary timer for * `TextEditor` instances. */ struct PasswordMaskData final { // Timer to mask unmasked characters automatically. Used only when it's // a password field. nsCOMPtr mTimer; // Unmasked character range. Used only when it's a password field. // If mUnmaskedLength is 0, it means there is no unmasked characters. uint32_t mUnmaskedStart = UINT32_MAX; uint32_t mUnmaskedLength = 0; // Set to true if all characters are masked or waiting notification from // `mTimer`. Otherwise, i.e., part of or all of password is unmasked // without setting `mTimer`, set to false. bool mIsMaskingPassword = true; // Set to true if a manager of the instance wants to disable echoing // password temporarily. bool mEchoingPasswordPrevented = false; MOZ_ALWAYS_INLINE bool IsAllMasked() const { return mUnmaskedStart == UINT32_MAX && mUnmaskedLength == 0; } MOZ_ALWAYS_INLINE uint32_t UnmaskedEnd() const { return mUnmaskedStart + mUnmaskedLength; } MOZ_ALWAYS_INLINE void MaskAll() { mUnmaskedStart = UINT32_MAX; mUnmaskedLength = 0; } MOZ_ALWAYS_INLINE void Reset() { MaskAll(); mIsMaskingPassword = true; } enum class ReleaseTimer { No, Yes }; MOZ_ALWAYS_INLINE void CancelTimer(ReleaseTimer aReleaseTimer) { if (mTimer) { mTimer->Cancel(); if (aReleaseTimer == ReleaseTimer::Yes) { mTimer = nullptr; } } if (mIsMaskingPassword) { MaskAll(); } } }; /** * TextControlState is a class which is responsible for managing the state of * plaintext controls. This currently includes the following HTML elements: * * * * * * *