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/. */
6
7 #ifndef nsCommandManager_h__
8 #define nsCommandManager_h__
9
10 #include "nsString.h"
11 #include "nsClassHashtable.h"
12 #include "nsWeakReference.h"
13
14 #include "nsICommandManager.h"
15 #include "nsCycleCollectionParticipant.h"
16
17 class nsIController;
18 template <class E>
19 class nsCOMArray;
20
21 class nsCommandManager final : public nsICommandManager,
22 public nsSupportsWeakReference {
23 public:
24 typedef nsTArray<nsCOMPtr<nsIObserver> > ObserverList;
25
26 nsCommandManager() = delete;
27
28 /**
29 * @param aWindow An window which is what this command manager lives on.
30 */
31 explicit nsCommandManager(mozIDOMWindowProxy* aWindow);
32
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCommandManager, nsICommandManager)
35
36 NS_DECL_NSICOMMANDMANAGER
37
38 /**
39 * Notify the command manager that the status of a command changed. It may
40 * have changed from enabled to disabled, or vice versa, or become toggled
41 * etc.
42 */
43 void CommandStatusChanged(const char* aCommandName);
44
45 bool IsCommandEnabled(const nsCString& aCommandName,
46 mozIDOMWindowProxy* aTargetWindow);
47
48 protected:
49 virtual ~nsCommandManager();
50
51 nsresult GetControllerForCommand(const char* aCommand,
52 mozIDOMWindowProxy* aDirectedToThisWindow,
53 nsIController** aResult);
54
55 protected:
56 nsClassHashtable<nsCharPtrHashKey, ObserverList> mObserversTable;
57
58 mozIDOMWindowProxy* mWindow; // weak ptr. The window should always outlive us
59 };
60
AsCommandManager()61 nsCommandManager* nsICommandManager::AsCommandManager() {
62 return static_cast<nsCommandManager*>(this);
63 }
64
AsCommandManager()65 const nsCommandManager* nsICommandManager::AsCommandManager() const {
66 return static_cast<const nsCommandManager*>(this);
67 }
68
69 #endif // nsCommandManager_h__
70