2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2019-11-01 23:43:11 +03:00
|
|
|
#ifndef mozilla_TextControlState_h
|
|
|
|
#define mozilla_TextControlState_h
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2019-09-23 14:43:57 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2015-04-17 04:13:24 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-03-04 17:56:13 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2019-11-25 09:35:15 +03:00
|
|
|
#include "mozilla/TextControlElement.h"
|
2017-06-20 16:57:08 +03:00
|
|
|
#include "mozilla/TextEditor.h"
|
2012-10-10 23:22:27 +04:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2019-11-25 09:35:15 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2017-03-09 22:44:06 +03:00
|
|
|
#include "mozilla/dom/HTMLInputElementBinding.h"
|
2017-03-09 22:44:05 +03:00
|
|
|
#include "mozilla/dom/Nullable.h"
|
2019-11-25 09:35:15 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsITextControlFrame.h"
|
2010-04-22 00:17:41 +04:00
|
|
|
|
|
|
|
class nsTextControlFrame;
|
|
|
|
class nsISelectionController;
|
|
|
|
class nsFrameSelection;
|
2014-08-01 04:25:31 +04:00
|
|
|
class nsFrame;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2017-03-09 22:44:04 +03:00
|
|
|
|
2019-11-01 23:47:35 +03:00
|
|
|
class AutoTextControlHandlingState;
|
2017-03-09 22:44:04 +03:00
|
|
|
class ErrorResult;
|
2018-01-24 05:44:34 +03:00
|
|
|
class TextInputListener;
|
2019-11-01 23:43:11 +03:00
|
|
|
class TextInputSelectionController;
|
2017-03-09 22:44:04 +03:00
|
|
|
|
2014-08-01 04:25:31 +04:00
|
|
|
namespace dom {
|
|
|
|
class HTMLInputElement;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2010-04-22 00:17:41 +04:00
|
|
|
|
|
|
|
/**
|
2019-11-01 23:43:11 +03:00
|
|
|
* TextControlState is a class which is responsible for managing the state of
|
2010-04-22 00:17:41 +04:00
|
|
|
* plaintext controls. This currently includes the following HTML elements:
|
|
|
|
* <input type=text>
|
2019-04-09 09:42:15 +03:00
|
|
|
* <input type=search>
|
|
|
|
* <input type=url>
|
|
|
|
* <input type=telephone>
|
|
|
|
* <input type=email>
|
2010-04-22 00:17:41 +04:00
|
|
|
* <input type=password>
|
|
|
|
* <textarea>
|
|
|
|
*
|
2019-11-01 23:43:11 +03:00
|
|
|
* This class is held as a member of HTMLInputElement and HTMLTextAreaElement.
|
|
|
|
* The public functions in this class include the public APIs which dom/
|
2019-11-25 09:35:15 +03:00
|
|
|
* uses. Layout code uses the TextControlElement interface to invoke
|
2010-04-22 00:17:41 +04:00
|
|
|
* functions on this class.
|
|
|
|
*
|
|
|
|
* The design motivation behind this class is maintaining all of the things
|
|
|
|
* which collectively are considered the "state" of the text control in a single
|
|
|
|
* location. This state includes several things:
|
|
|
|
*
|
|
|
|
* * The control's value. This value is stored in the mValue member, and is
|
|
|
|
* only used when there is no frame for the control, or when the editor object
|
|
|
|
* has not been initialized yet.
|
|
|
|
*
|
|
|
|
* * The control's associated frame. This value is stored in the mBoundFrame
|
|
|
|
* member. A text control might never have an associated frame during its life
|
|
|
|
* cycle, or might have several different ones, but at any given moment in time
|
|
|
|
* there is a maximum of 1 bound frame to each text control.
|
|
|
|
*
|
2019-11-01 23:43:11 +03:00
|
|
|
* * The control's associated editor. This value is stored in the mTextEditor
|
|
|
|
* member. An editor is initialized for the control only when necessary (that
|
|
|
|
* is, when either the user is about to interact with the text control, or when
|
|
|
|
* some other code needs to access the editor object. Without a frame bound to
|
|
|
|
* the control, an editor is never initialized. Once initialized, the editor
|
|
|
|
* might outlive the frame, in which case the same editor will be used if a new
|
|
|
|
* frame gets bound to the text control.
|
2010-04-22 00:17:41 +04:00
|
|
|
*
|
|
|
|
* * The anonymous content associated with the text control's frame, including
|
|
|
|
* the value div (the DIV element responsible for holding the value of the text
|
|
|
|
* control) and the placeholder div (the DIV element responsible for holding the
|
|
|
|
* placeholder value of the text control.) These values are stored in the
|
|
|
|
* mRootNode and mPlaceholderDiv members, respectively. They will be created
|
|
|
|
* when a frame is bound to the text control. They will be destroyed when the
|
|
|
|
* frame is unbound from the object. We could try and hold on to the anonymous
|
|
|
|
* content between different frames, but unfortunately that is not currently
|
|
|
|
* possible because they are not unbound from the document in time.
|
|
|
|
*
|
|
|
|
* * The frame selection controller. This value is stored in the mSelCon
|
|
|
|
* member. The frame selection controller is responsible for maintaining the
|
|
|
|
* selection state on a frame. It is created when a frame is bound to the text
|
|
|
|
* control element, and will be destroy when the frame is being unbound from the
|
|
|
|
* text control element. It is created alongside with the frame selection object
|
|
|
|
* which is stored in the mFrameSel member.
|
|
|
|
*
|
|
|
|
* * The editor text listener. This value is stored in the mTextListener
|
|
|
|
* member. Its job is to listen to selection and keyboard events, and act
|
|
|
|
* accordingly. It is created when an a frame is first bound to the control, and
|
|
|
|
* will be destroyed when the frame is unbound from the text control element.
|
|
|
|
*
|
|
|
|
* * The editor's cached value. This value is stored in the mCachedValue
|
|
|
|
* member. It is used to improve the performance of append operations to the
|
2011-03-03 05:36:36 +03:00
|
|
|
* text control. A mutation observer stored in the mMutationObserver has the
|
2010-04-22 00:17:41 +04:00
|
|
|
* job of invalidating this cache when the anonymous contect containing the
|
|
|
|
* value is changed.
|
|
|
|
*
|
2011-07-30 01:31:57 +04:00
|
|
|
* * The editor's cached selection properties. These vales are stored in the
|
|
|
|
* mSelectionProperties member, and include the selection's start, end and
|
|
|
|
* direction. They are only used when there is no frame available for the
|
|
|
|
* text field.
|
|
|
|
*
|
2010-04-22 00:17:41 +04:00
|
|
|
*
|
2019-11-01 23:43:11 +03:00
|
|
|
* As a general rule, TextControlState objects own the value of the text
|
2010-04-22 00:17:41 +04:00
|
|
|
* control, and any attempt to retrieve or set the value must be made through
|
|
|
|
* those objects. Internally, the value can be represented in several different
|
|
|
|
* ways, based on the state the control is in.
|
|
|
|
*
|
|
|
|
* * When the control is first initialized, its value is equal to the default
|
|
|
|
* value of the DOM node. For <input> text controls, this default value is the
|
|
|
|
* value of the value attribute. For <textarea> elements, this default value is
|
|
|
|
* the value of the text node children of the element.
|
|
|
|
*
|
|
|
|
* * If the value has been changed through the DOM node (before the editor for
|
|
|
|
* the object is initialized), the value is stored as a simple string inside the
|
2019-11-01 23:43:11 +03:00
|
|
|
* mValue member of the TextControlState object.
|
2010-04-22 00:17:41 +04:00
|
|
|
*
|
|
|
|
* * If an editor has been initialized for the control, the value is set and
|
2020-01-24 11:33:42 +03:00
|
|
|
* retrievd via the nsIEditor interface, and is internally managed by the
|
|
|
|
* editor as the native anonymous content tree attached to the control's frame.
|
2010-04-22 00:17:41 +04:00
|
|
|
*
|
2019-11-01 23:43:11 +03:00
|
|
|
* * If the text control state object is unbound from the control's frame, the
|
2010-04-22 00:17:41 +04:00
|
|
|
* value is transferred to the mValue member variable, and will be managed there
|
|
|
|
* until a new frame is bound to the text editor state object.
|
|
|
|
*/
|
|
|
|
|
2011-05-21 12:25:27 +04:00
|
|
|
class RestoreSelectionState;
|
|
|
|
|
2019-11-01 23:43:11 +03:00
|
|
|
class TextControlState final : public SupportsWeakPtr<TextControlState> {
|
2010-04-22 00:17:41 +04:00
|
|
|
public:
|
2019-11-01 23:43:11 +03:00
|
|
|
typedef dom::Element Element;
|
|
|
|
typedef dom::HTMLInputElement HTMLInputElement;
|
|
|
|
|
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(TextControlState)
|
|
|
|
|
2019-11-25 09:35:15 +03:00
|
|
|
static TextControlState* Construct(TextControlElement* aOwningElement);
|
2019-11-01 23:51:48 +03:00
|
|
|
|
2019-12-11 06:01:37 +03:00
|
|
|
// Note that this does not run script actually because of `sHasShutDown`
|
|
|
|
// is set to true before calling `DeleteOrCacheForReuse()`.
|
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY static void Shutdown();
|
2019-11-01 23:43:11 +03:00
|
|
|
|
2019-11-01 23:49:12 +03:00
|
|
|
/**
|
|
|
|
* Destroy() deletes the instance immediately or later.
|
|
|
|
*/
|
2019-12-11 06:02:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void Destroy();
|
2019-11-01 23:43:11 +03:00
|
|
|
|
|
|
|
TextControlState() = delete;
|
|
|
|
explicit TextControlState(const TextControlState&) = delete;
|
|
|
|
TextControlState(TextControlState&&) = delete;
|
|
|
|
|
|
|
|
void operator=(const TextControlState&) = delete;
|
|
|
|
void operator=(TextControlState&&) = delete;
|
|
|
|
|
2012-04-24 08:19:26 +04:00
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& cb);
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY void Unlink();
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2019-11-01 23:49:12 +03:00
|
|
|
bool IsBusy() const { return !!mHandlingState || mValueTransferInProgress; }
|
2019-11-01 23:47:35 +03:00
|
|
|
|
2019-12-11 06:03:31 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT TextEditor* GetTextEditor();
|
2019-11-01 23:43:11 +03:00
|
|
|
TextEditor* GetTextEditorWithoutCreation();
|
2010-04-22 00:17:41 +04:00
|
|
|
nsISelectionController* GetSelectionController() const;
|
|
|
|
nsFrameSelection* GetConstFrameSelection();
|
|
|
|
nsresult BindToFrame(nsTextControlFrame* aFrame);
|
2019-12-11 06:04:20 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void UnbindFromFrame(nsTextControlFrame* aFrame);
|
|
|
|
MOZ_CAN_RUN_SCRIPT nsresult PrepareEditor(const nsAString* aValue = nullptr);
|
2010-04-22 00:17:41 +04:00
|
|
|
void InitializeKeyboardEventListeners();
|
|
|
|
|
2019-11-03 05:50:00 +03:00
|
|
|
/**
|
|
|
|
* OnEditActionHandled() is called when mTextEditor handles something
|
|
|
|
* and immediately before dispatching "input" event.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE nsresult OnEditActionHandled();
|
|
|
|
|
2015-06-18 17:56:20 +03:00
|
|
|
enum SetValueFlags {
|
|
|
|
// The call is for internal processing.
|
2019-02-19 12:25:55 +03:00
|
|
|
eSetValue_Internal = 1 << 0,
|
2015-06-18 17:56:20 +03:00
|
|
|
// The value is changed by a call of setUserInput() from chrome.
|
2019-02-19 12:25:55 +03:00
|
|
|
eSetValue_BySetUserInput = 1 << 1,
|
2015-06-18 17:56:20 +03:00
|
|
|
// The value is changed by changing value attribute of the element or
|
|
|
|
// something like setRangeText().
|
2019-02-19 12:25:55 +03:00
|
|
|
eSetValue_ByContent = 1 << 2,
|
2015-06-18 17:56:20 +03:00
|
|
|
// Whether the value change should be notified to the frame/contet nor not.
|
2019-02-19 12:25:55 +03:00
|
|
|
eSetValue_Notify = 1 << 3,
|
2017-03-09 22:44:04 +03:00
|
|
|
// Whether to move the cursor to end of the value (in the case when we have
|
2017-05-01 20:26:21 +03:00
|
|
|
// cached selection offsets), in the case when the value has changed. If
|
2019-04-09 09:42:15 +03:00
|
|
|
// this is not set and
|
|
|
|
// eSetValue_MoveCursorToBeginSetSelectionDirectionForward
|
|
|
|
// is not set, the cached selection offsets will simply be clamped to
|
|
|
|
// be within the length of the new value. In either case, if the value has
|
2017-05-01 20:26:21 +03:00
|
|
|
// not changed the cursor won't move.
|
2019-04-09 09:42:15 +03:00
|
|
|
// TODO(mbrodesser): update comment and enumerator identifier to reflect
|
|
|
|
// that also the direction is set to forward.
|
2019-02-19 12:25:55 +03:00
|
|
|
eSetValue_MoveCursorToEndIfValueChanged = 1 << 4,
|
2017-08-01 19:47:07 +03:00
|
|
|
// The value is changed for a XUL text control as opposed to for an HTML
|
|
|
|
// text control. Such value changes are different in that they preserve the
|
|
|
|
// undo history.
|
2019-02-19 12:25:55 +03:00
|
|
|
eSetValue_ForXUL = 1 << 5,
|
2019-04-09 09:42:15 +03:00
|
|
|
// Whether it should be tried to move the cursor to the beginning of the
|
|
|
|
// text control and set the selection direction to "forward".
|
|
|
|
// TODO(mbrodesser): As soon as "none" is supported
|
|
|
|
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1541454), it should be set
|
|
|
|
// to "none" and only fall back to "forward" if the platform doesn't support
|
|
|
|
// it.
|
|
|
|
eSetValue_MoveCursorToBeginSetSelectionDirectionForward = 1 << 6,
|
2015-06-18 17:56:20 +03:00
|
|
|
};
|
2019-11-25 09:35:17 +03:00
|
|
|
/**
|
|
|
|
* SetValue() sets the value to aValue with replacing \r\n and \r with \n.
|
|
|
|
*
|
|
|
|
* @param aValue The new value. Can contain \r.
|
|
|
|
* @param aOldValue Optional. If you have already know current value,
|
|
|
|
* set this to it. However, this must not contain \r
|
|
|
|
* for the performance.
|
|
|
|
* @param aFlags See SetValueFlags.
|
|
|
|
*/
|
2019-11-01 23:43:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE bool SetValue(const nsAString& aValue,
|
|
|
|
const nsAString* aOldValue,
|
|
|
|
uint32_t aFlags);
|
|
|
|
MOZ_CAN_RUN_SCRIPT MOZ_MUST_USE bool SetValue(const nsAString& aValue,
|
|
|
|
uint32_t aFlags) {
|
2017-06-14 12:21:01 +03:00
|
|
|
return SetValue(aValue, nullptr, aFlags);
|
|
|
|
}
|
2019-11-25 09:35:17 +03:00
|
|
|
/**
|
|
|
|
* GetValue() returns current value either with or without TextEditor.
|
|
|
|
* The result never includes \r.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void GetValue(nsAString& aValue, bool aIgnoreWrap) const;
|
2019-11-25 09:35:17 +03:00
|
|
|
/**
|
|
|
|
* ValueEquals() is designed for internal use so that aValue shouldn't
|
|
|
|
* include \r character. It should be handled before calling this with
|
|
|
|
* nsContentUtils::PlatformToDOMLineBreaks().
|
|
|
|
*/
|
|
|
|
bool ValueEquals(const nsAString& aValue) const;
|
2017-05-11 08:04:18 +03:00
|
|
|
bool HasNonEmptyValue();
|
|
|
|
// The following methods are for textarea element to use whether default
|
|
|
|
// value or not.
|
|
|
|
// XXX We might have to add assertion when it is into editable,
|
|
|
|
// or reconsider fixing bug 597525 to remove these.
|
2013-03-25 23:35:55 +04:00
|
|
|
void EmptyValue() {
|
2019-11-01 23:43:11 +03:00
|
|
|
if (mValue) {
|
|
|
|
mValue->Truncate();
|
|
|
|
}
|
2013-03-25 23:35:55 +04:00
|
|
|
}
|
|
|
|
bool IsEmpty() const { return mValue ? mValue->IsEmpty() : true; }
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2019-11-01 23:43:11 +03:00
|
|
|
Element* GetRootNode();
|
|
|
|
Element* GetPreviewNode();
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsSingleLineTextControl() const {
|
2010-04-22 00:17:41 +04:00
|
|
|
return mTextCtrlElement->IsSingleLineTextControl();
|
|
|
|
}
|
|
|
|
bool IsTextArea() const { return mTextCtrlElement->IsTextArea(); }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsPasswordTextControl() const {
|
2010-04-22 00:17:41 +04:00
|
|
|
return mTextCtrlElement->IsPasswordTextControl();
|
|
|
|
}
|
|
|
|
int32_t GetCols() { return mTextCtrlElement->GetCols(); }
|
2019-09-23 14:43:57 +03:00
|
|
|
int32_t GetWrapCols() {
|
|
|
|
int32_t wrapCols = mTextCtrlElement->GetWrapCols();
|
|
|
|
MOZ_ASSERT(wrapCols >= 0);
|
|
|
|
return wrapCols;
|
|
|
|
}
|
2010-04-22 00:17:41 +04:00
|
|
|
int32_t GetRows() { return mTextCtrlElement->GetRows(); }
|
|
|
|
|
2017-03-30 12:38:59 +03:00
|
|
|
void UpdateOverlayTextVisibility(bool aNotify);
|
|
|
|
|
2010-04-22 00:17:41 +04:00
|
|
|
// placeholder methods
|
2012-11-09 14:22:29 +04:00
|
|
|
bool GetPlaceholderVisibility() { return mPlaceholderVisibility; }
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2017-03-20 19:08:01 +03:00
|
|
|
// preview methods
|
|
|
|
void SetPreviewText(const nsAString& aValue, bool aNotify);
|
|
|
|
void GetPreviewText(nsAString& aValue);
|
2017-03-30 12:38:59 +03:00
|
|
|
bool GetPreviewVisibility() { return mPreviewVisibility; }
|
2011-04-12 06:03:50 +04:00
|
|
|
void HideSelectionIfBlurred();
|
|
|
|
|
2011-07-30 01:31:57 +04:00
|
|
|
struct SelectionProperties {
|
2016-07-21 21:52:49 +03:00
|
|
|
public:
|
|
|
|
SelectionProperties()
|
|
|
|
: mStart(0), mEnd(0), mDirection(nsITextControlFrame::eForward) {}
|
|
|
|
bool IsDefault() const {
|
|
|
|
return mStart == 0 && mEnd == 0 &&
|
|
|
|
mDirection == nsITextControlFrame::eForward;
|
|
|
|
}
|
2017-03-09 22:44:45 +03:00
|
|
|
uint32_t GetStart() const { return mStart; }
|
|
|
|
void SetStart(uint32_t value) {
|
2016-07-21 21:52:49 +03:00
|
|
|
mIsDirty = true;
|
|
|
|
mStart = value;
|
|
|
|
}
|
2017-03-09 22:44:45 +03:00
|
|
|
uint32_t GetEnd() const { return mEnd; }
|
|
|
|
void SetEnd(uint32_t value) {
|
2016-07-21 21:52:49 +03:00
|
|
|
mIsDirty = true;
|
|
|
|
mEnd = value;
|
|
|
|
}
|
|
|
|
nsITextControlFrame::SelectionDirection GetDirection() const {
|
|
|
|
return mDirection;
|
|
|
|
}
|
|
|
|
void SetDirection(nsITextControlFrame::SelectionDirection value) {
|
|
|
|
mIsDirty = true;
|
|
|
|
mDirection = value;
|
|
|
|
}
|
2017-05-01 20:28:54 +03:00
|
|
|
// return true only if mStart, mEnd, or mDirection have been modified,
|
|
|
|
// or if SetIsDirty() was explicitly called.
|
2016-07-21 21:52:49 +03:00
|
|
|
bool IsDirty() const { return mIsDirty; }
|
2017-05-01 20:28:54 +03:00
|
|
|
void SetIsDirty() { mIsDirty = true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-21 21:52:49 +03:00
|
|
|
private:
|
2017-03-09 22:44:45 +03:00
|
|
|
uint32_t mStart, mEnd;
|
2016-07-21 21:52:49 +03:00
|
|
|
bool mIsDirty = false;
|
|
|
|
nsITextControlFrame::SelectionDirection mDirection;
|
2011-07-30 01:31:57 +04:00
|
|
|
};
|
|
|
|
|
2020-01-27 03:00:09 +03:00
|
|
|
bool IsSelectionCached() const { return mSelectionCached; }
|
|
|
|
SelectionProperties& GetSelectionProperties() { return mSelectionProperties; }
|
2019-12-11 06:02:53 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionProperties(SelectionProperties& aProps);
|
2011-10-17 18:59:28 +04:00
|
|
|
void WillInitEagerly() { mSelectionRestoreEagerInit = true; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasNeverInitializedBefore() const { return !mEverInited; }
|
2017-03-09 22:44:04 +03:00
|
|
|
// Sync up our selection properties with our editor prior to being destroyed.
|
|
|
|
// This will invoke UnbindFromFrame() to ensure that we grab whatever
|
|
|
|
// selection state may be at the moment.
|
2019-11-01 23:43:11 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SyncUpSelectionPropertiesBeforeDestruction();
|
2011-07-30 01:31:57 +04:00
|
|
|
|
2017-02-28 20:41:37 +03:00
|
|
|
// Get the selection range start and end points in our text.
|
2017-03-09 22:44:45 +03:00
|
|
|
void GetSelectionRange(uint32_t* aSelectionStart, uint32_t* aSelectionEnd,
|
2019-11-01 23:43:11 +03:00
|
|
|
ErrorResult& aRv);
|
2017-02-28 20:41:37 +03:00
|
|
|
|
|
|
|
// Get the selection direction
|
2017-03-09 22:44:05 +03:00
|
|
|
nsITextControlFrame::SelectionDirection GetSelectionDirection(
|
2019-11-01 23:43:11 +03:00
|
|
|
ErrorResult& aRv);
|
2017-02-28 20:41:37 +03:00
|
|
|
|
2017-03-09 22:44:05 +03:00
|
|
|
// Set the selection range (start, end, direction). aEnd is allowed to be
|
|
|
|
// smaller than aStart; in that case aStart will be reset to the same value as
|
|
|
|
// aEnd. This basically implements
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#set-the-selection-range
|
|
|
|
// but with the start/end already coerced to zero if null (and without the
|
|
|
|
// special infinity value), and the direction already converted to a
|
|
|
|
// SelectionDirection.
|
|
|
|
//
|
|
|
|
// If we have a frame, this method will scroll the selection into view.
|
|
|
|
//
|
|
|
|
// XXXbz This should really take uint32_t, but none of our guts (either the
|
|
|
|
// frame or our cached selection state) work with uint32_t at the moment...
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionRange(
|
|
|
|
uint32_t aStart, uint32_t aEnd,
|
|
|
|
nsITextControlFrame::SelectionDirection aDirection, ErrorResult& aRv);
|
2017-03-09 22:44:05 +03:00
|
|
|
|
2017-03-09 22:44:06 +03:00
|
|
|
// Set the selection range, but with an optional string for the direction.
|
|
|
|
// This will convert aDirection to an nsITextControlFrame::SelectionDirection
|
|
|
|
// and then call our other SetSelectionRange overload.
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionRange(
|
|
|
|
uint32_t aSelectionStart, uint32_t aSelectionEnd,
|
|
|
|
const dom::Optional<nsAString>& aDirection, ErrorResult& aRv);
|
2017-03-09 22:44:06 +03:00
|
|
|
|
2017-03-09 22:44:05 +03:00
|
|
|
// Set the selection start. This basically implements the
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectionstart
|
|
|
|
// setter.
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionStart(
|
|
|
|
const dom::Nullable<uint32_t>& aStart, ErrorResult& aRv);
|
2017-03-09 22:44:05 +03:00
|
|
|
|
2017-03-09 22:44:05 +03:00
|
|
|
// Set the selection end. This basically implements the
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectionend
|
|
|
|
// setter.
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionEnd(const dom::Nullable<uint32_t>& aEnd,
|
|
|
|
ErrorResult& aRv);
|
2017-03-09 22:44:05 +03:00
|
|
|
|
2017-03-09 22:44:06 +03:00
|
|
|
// Get the selection direction as a string. This implements the
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectiondirection
|
|
|
|
// getter.
|
2019-11-01 23:43:11 +03:00
|
|
|
void GetSelectionDirectionString(nsAString& aDirection, ErrorResult& aRv);
|
2017-03-09 22:44:06 +03:00
|
|
|
|
2017-03-09 22:44:06 +03:00
|
|
|
// Set the selection direction. This basically implements the
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-selectiondirection
|
|
|
|
// setter.
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetSelectionDirection(const nsAString& aDirection,
|
|
|
|
ErrorResult& aRv);
|
2017-03-09 22:44:06 +03:00
|
|
|
|
2017-03-09 22:44:06 +03:00
|
|
|
// Set the range text. This basically implements
|
|
|
|
// https://html.spec.whatwg.org/multipage/forms.html#dom-textarea/input-setrangetext
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetRangeText(const nsAString& aReplacement,
|
|
|
|
ErrorResult& aRv);
|
2017-03-09 22:44:06 +03:00
|
|
|
// The last two arguments are -1 if we don't know our selection range;
|
|
|
|
// otherwise they're the start and end of our selection range.
|
2019-12-11 06:01:37 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void SetRangeText(
|
|
|
|
const nsAString& aReplacement, uint32_t aStart, uint32_t aEnd,
|
|
|
|
dom::SelectionMode aSelectMode, ErrorResult& aRv,
|
|
|
|
const Maybe<uint32_t>& aSelectionStart = Nothing(),
|
|
|
|
const Maybe<uint32_t>& aSelectionEnd = Nothing());
|
2017-03-09 22:44:06 +03:00
|
|
|
|
2010-04-22 00:17:41 +04:00
|
|
|
private:
|
2019-11-25 09:35:15 +03:00
|
|
|
explicit TextControlState(TextControlElement* aOwningElement);
|
2019-12-11 06:02:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT ~TextControlState();
|
2019-11-01 23:49:12 +03:00
|
|
|
|
2019-11-01 23:51:48 +03:00
|
|
|
/**
|
|
|
|
* Delete the instance or cache to reuse it if possible.
|
|
|
|
*/
|
2019-12-11 06:02:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void DeleteOrCacheForReuse();
|
2019-11-01 23:51:48 +03:00
|
|
|
|
2019-12-11 06:02:46 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void UnlinkInternal();
|
2019-11-01 23:51:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void ValueWasChanged(bool aNotify);
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2019-05-09 10:37:51 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT void DestroyEditor();
|
|
|
|
MOZ_CAN_RUN_SCRIPT void Clear();
|
2010-04-22 00:17:41 +04:00
|
|
|
|
2011-09-13 23:09:51 +04:00
|
|
|
nsresult InitializeRootNode();
|
|
|
|
|
2015-04-14 19:26:56 +03:00
|
|
|
void FinishedRestoringSelection();
|
2011-05-21 12:25:27 +04:00
|
|
|
|
2015-06-18 17:56:20 +03:00
|
|
|
bool EditorHasComposition();
|
|
|
|
|
2019-11-03 02:23:54 +03:00
|
|
|
/**
|
|
|
|
* SetValueWithTextEditor() modifies the editor value with mTextEditor.
|
|
|
|
* This may cause destroying mTextEditor, mBoundFrame, the TextControlState
|
|
|
|
* itself. Must be called when both mTextEditor and mBoundFrame are not
|
|
|
|
* nullptr.
|
|
|
|
*
|
|
|
|
* @param aHandlingState Must be inner-most handling state for SetValue.
|
2019-11-03 05:50:00 +03:00
|
|
|
* @return false if fallible allocation failed. Otherwise,
|
|
|
|
* true.
|
2019-11-03 02:23:54 +03:00
|
|
|
*/
|
2019-11-03 05:50:00 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT bool SetValueWithTextEditor(
|
2019-11-03 02:23:54 +03:00
|
|
|
AutoTextControlHandlingState& aHandlingState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetValueWithoutTextEditor() modifies the value without editor. I.e.,
|
|
|
|
* modifying the value in this instance and mBoundFrame. Must be called
|
|
|
|
* when at least mTextEditor or mBoundFrame is nullptr.
|
|
|
|
*
|
|
|
|
* @param aHandlingState Must be inner-most handling state for SetValue.
|
|
|
|
* @return false if fallible allocation failed. Otherwise,
|
|
|
|
* true.
|
|
|
|
*/
|
|
|
|
MOZ_CAN_RUN_SCRIPT bool SetValueWithoutTextEditor(
|
|
|
|
AutoTextControlHandlingState& aHandlingState);
|
|
|
|
|
2019-11-01 23:47:35 +03:00
|
|
|
// When this class handles something which may run script, this should be
|
|
|
|
// set to non-nullptr. If so, this class claims that it's busy and that
|
|
|
|
// prevents destroying TextControlState instance.
|
|
|
|
AutoTextControlHandlingState* mHandlingState = nullptr;
|
2010-08-04 22:59:35 +04:00
|
|
|
|
2015-04-17 04:13:24 +03:00
|
|
|
// The text control element owns this object, and ensures that this object
|
2019-11-01 23:49:12 +03:00
|
|
|
// has a smaller lifetime except the owner releases the instance while it
|
|
|
|
// does something with this.
|
2019-11-25 09:35:15 +03:00
|
|
|
TextControlElement* MOZ_NON_OWNING_REF mTextCtrlElement;
|
2019-11-01 23:43:11 +03:00
|
|
|
RefPtr<TextInputSelectionController> mSelCon;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RestoreSelectionState> mRestoringSelection;
|
2019-11-01 23:43:11 +03:00
|
|
|
RefPtr<TextEditor> mTextEditor;
|
2010-04-22 00:17:41 +04:00
|
|
|
nsTextControlFrame* mBoundFrame;
|
2019-11-01 23:43:11 +03:00
|
|
|
RefPtr<TextInputListener> mTextListener;
|
|
|
|
Maybe<nsString> mValue;
|
2015-06-18 17:56:20 +03:00
|
|
|
SelectionProperties mSelectionProperties;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mEverInited; // Have we ever been initialized?
|
|
|
|
bool mEditorInitialized;
|
|
|
|
bool mValueTransferInProgress; // Whether a value is being transferred to the
|
|
|
|
// frame
|
|
|
|
bool mSelectionCached; // Whether mSelectionProperties is valid
|
|
|
|
mutable bool mSelectionRestoreEagerInit; // Whether we're eager initing
|
|
|
|
// because of selection restore
|
2012-11-09 14:22:29 +04:00
|
|
|
bool mPlaceholderVisibility;
|
2017-03-30 12:38:59 +03:00
|
|
|
bool mPreviewVisibility;
|
2019-11-01 23:43:11 +03:00
|
|
|
|
2019-11-01 23:51:48 +03:00
|
|
|
/**
|
|
|
|
* For avoiding allocation cost of the instance, we should reuse instances
|
|
|
|
* as far as possible.
|
2019-11-25 09:33:53 +03:00
|
|
|
*
|
|
|
|
* FYI: `25` is just a magic number considered without enough investigation,
|
|
|
|
* but at least, this value must not make damage for footprint.
|
|
|
|
* Feel free to change it if you find better number.
|
2019-11-01 23:51:48 +03:00
|
|
|
*/
|
2019-11-25 09:33:53 +03:00
|
|
|
static const size_t kMaxCountOfCacheToReuse = 25;
|
|
|
|
static AutoTArray<TextControlState*, kMaxCountOfCacheToReuse>*
|
|
|
|
sReleasedInstances;
|
2019-11-01 23:51:48 +03:00
|
|
|
static bool sHasShutDown;
|
|
|
|
|
2019-11-01 23:47:35 +03:00
|
|
|
friend class AutoTextControlHandlingState;
|
2019-11-01 23:43:11 +03:00
|
|
|
friend class PrepareEditorEvent;
|
|
|
|
friend class RestoreSelectionState;
|
2010-04-22 00:17:41 +04:00
|
|
|
};
|
|
|
|
|
2019-11-01 23:43:11 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef mozilla_TextControlState_h
|