1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_TextInputListener_h
8 #define mozilla_TextInputListener_h
10 #include "mozilla/WeakPtr.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsIDOMEventListener.h"
13 #include "nsStringFwd.h"
14 #include "nsWeakReference.h"
17 class nsTextControlFrame
;
20 class TextControlElement
;
21 class TextControlState
;
28 class TextInputListener final
: public nsIDOMEventListener
,
29 public nsSupportsWeakReference
{
31 explicit TextInputListener(TextControlElement
* aTextControlElement
);
33 void SetFrame(nsIFrame
* aTextControlFrame
) { mFrame
= aTextControlFrame
; }
34 void SettingValue(bool aValue
) { mSettingValue
= aValue
; }
35 void SetValueChanged(bool aSetValueChanged
) {
36 mSetValueChanged
= aSetValueChanged
;
40 * aFrame is an optional pointer to our frame, if not passed the method will
41 * use mFrame to compute it lazily.
43 void HandleValueChanged(TextEditor
&);
46 * OnEditActionHandled() is called when the editor handles each edit action.
48 [[nodiscard
]] MOZ_CAN_RUN_SCRIPT nsresult
OnEditActionHandled(TextEditor
&);
51 * OnSelectionChange() is called when selection is changed in the editor.
54 void OnSelectionChange(dom::Selection
& aSelection
, int16_t aReason
);
57 * Start to listen or end listening to selection change in the editor.
59 void StartToListenToSelectionChange() { mListeningToSelectionChange
= true; }
60 void EndListeningToSelectionChange() { mListeningToSelectionChange
= false; }
62 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
63 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(TextInputListener
,
65 NS_DECL_NSIDOMEVENTLISTENER
68 virtual ~TextInputListener() = default;
70 nsresult
UpdateTextInputCommands(const nsAString
& aCommandsToUpdate
);
74 TextControlElement
* const mTxtCtrlElement
;
75 WeakPtr
<TextControlState
> const mTextControlState
;
77 bool mSelectionWasCollapsed
;
80 * Whether we had undo items or not the last time we got EditAction()
81 * notification (when this state changes we update undo and redo menus)
85 * Whether we had redo items or not the last time we got EditAction()
86 * notification (when this state changes we update undo and redo menus)
90 * Whether we're in the process of a SetValue call, and should therefore
91 * refrain from calling OnValueChanged.
95 * Whether we are in the process of a SetValue call that doesn't want
96 * |SetValueChanged| to be called.
98 bool mSetValueChanged
;
100 * Whether we're listening to selection change in the editor.
102 bool mListeningToSelectionChange
;
105 } // namespace mozilla
107 #endif // #ifndef mozilla_TextInputListener_h