Merge mozilla-central to autoland. a=merge CLOSED TREE
[gecko.git] / dom / html / TextInputListener.h
blobb8f02e4cfac9170dfabd6462e8ee78dbecca360d
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"
16 class nsIFrame;
17 class nsTextControlFrame;
19 namespace mozilla {
20 class TextControlElement;
21 class TextControlState;
22 class TextEditor;
24 namespace dom {
25 class Selection;
26 } // namespace dom
28 class TextInputListener final : public nsIDOMEventListener,
29 public nsSupportsWeakReference {
30 public:
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;
39 /**
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&);
45 /**
46 * OnEditActionHandled() is called when the editor handles each edit action.
48 [[nodiscard]] MOZ_CAN_RUN_SCRIPT nsresult OnEditActionHandled(TextEditor&);
50 /**
51 * OnSelectionChange() is called when selection is changed in the editor.
53 MOZ_CAN_RUN_SCRIPT
54 void OnSelectionChange(dom::Selection& aSelection, int16_t aReason);
56 /**
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,
64 nsIDOMEventListener)
65 NS_DECL_NSIDOMEVENTLISTENER
67 protected:
68 virtual ~TextInputListener() = default;
70 nsresult UpdateTextInputCommands(const nsAString& aCommandsToUpdate);
72 protected:
73 nsIFrame* mFrame;
74 TextControlElement* const mTxtCtrlElement;
75 WeakPtr<TextControlState> const mTextControlState;
77 bool mSelectionWasCollapsed;
79 /**
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)
83 bool mHadUndoItems;
84 /**
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)
88 bool mHadRedoItems;
89 /**
90 * Whether we're in the process of a SetValue call, and should therefore
91 * refrain from calling OnValueChanged.
93 bool mSettingValue;
94 /**
95 * Whether we are in the process of a SetValue call that doesn't want
96 * |SetValueChanged| to be called.
98 bool mSetValueChanged;
99 /**
100 * Whether we're listening to selection change in the editor.
102 bool mListeningToSelectionChange;
105 } // namespace mozilla
107 #endif // #ifndef mozilla_TextInputListener_h