Bug 1708422: part 6) Change some pointer members of `mozInlineSpellChecker::SpellChec...
[gecko.git] / editor / composer / ComposerCommandsUpdater.h
blob43982d647029a99eccd7cfb081fc747bb1ed7ea6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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_ComposerCommandsUpdater_h
8 #define mozilla_ComposerCommandsUpdater_h
10 #include "nsCOMPtr.h" // for already_AddRefed, nsCOMPtr
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsINamed.h"
13 #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS
14 #include "nsITimer.h" // for NS_DECL_NSITIMERCALLBACK, etc
15 #include "nsITransactionListener.h" // for nsITransactionListener
16 #include "nscore.h" // for NS_IMETHOD, nsresult, etc
18 class nsCommandManager;
19 class nsIDocShell;
20 class nsITransaction;
21 class nsITransactionManager;
22 class nsPIDOMWindowOuter;
24 namespace mozilla {
26 class ComposerCommandsUpdater final : public nsITransactionListener,
27 public nsITimerCallback,
28 public nsINamed {
29 public:
30 ComposerCommandsUpdater();
32 // nsISupports
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ComposerCommandsUpdater,
35 nsITransactionListener)
37 // nsITimerCallback
38 NS_DECL_NSITIMERCALLBACK
40 // nsINamed
41 NS_DECL_NSINAMED
43 // nsITransactionListener
44 NS_DECL_NSITRANSACTIONLISTENER
46 void Init(nsPIDOMWindowOuter& aDOMWindow);
48 /**
49 * OnSelectionChange() is called when selection is changed in the editor.
51 void OnSelectionChange() { PrimeUpdateTimer(); }
53 /**
54 * OnHTMLEditorCreated() is called when `HTMLEditor` is created and
55 * initialized.
57 MOZ_CAN_RUN_SCRIPT void OnHTMLEditorCreated() {
58 UpdateOneCommand("obs_documentCreated");
61 /**
62 * OnBeforeHTMLEditorDestroyed() is called when `HTMLEditor` is being
63 * destroyed.
65 MOZ_CAN_RUN_SCRIPT void OnBeforeHTMLEditorDestroyed() {
66 // cancel any outstanding update timer
67 if (mUpdateTimer) {
68 mUpdateTimer->Cancel();
69 mUpdateTimer = nullptr;
72 // We can't notify the command manager of this right now; it is too late in
73 // some cases and the window is already partially destructed (e.g. JS
74 // objects may be gone).
77 /**
78 * OnHTMLEditorDirtyStateChanged() is called when dirty state of `HTMLEditor`
79 * is changed form or to "dirty".
81 MOZ_CAN_RUN_SCRIPT void OnHTMLEditorDirtyStateChanged(bool aNowDirty) {
82 if (mDirtyState == static_cast<int8_t>(aNowDirty)) {
83 return;
85 UpdateCommandGroup(CommandGroup::Save);
86 UpdateCommandGroup(CommandGroup::Undo);
87 mDirtyState = aNowDirty;
90 protected:
91 virtual ~ComposerCommandsUpdater();
93 enum {
94 eStateUninitialized = -1,
95 eStateOff = 0,
96 eStateOn = 1,
99 bool SelectionIsCollapsed();
100 MOZ_CAN_RUN_SCRIPT nsresult UpdateOneCommand(const char* aCommand);
101 enum class CommandGroup {
102 Save,
103 Style,
104 Undo,
106 MOZ_CAN_RUN_SCRIPT void UpdateCommandGroup(CommandGroup aCommandGroup);
108 nsCommandManager* GetCommandManager();
110 nsresult PrimeUpdateTimer();
111 void TimerCallback();
113 nsCOMPtr<nsITimer> mUpdateTimer;
114 nsCOMPtr<nsPIDOMWindowOuter> mDOMWindow;
115 nsCOMPtr<nsIDocShell> mDocShell;
117 int8_t mDirtyState;
118 int8_t mSelectionCollapsed;
119 bool mFirstDoOfFirstUndo;
122 } // namespace mozilla
124 #endif // #ifndef mozilla_ComposerCommandsUpdater_h