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 nsCommandManager_h__
8 #define nsCommandManager_h__
11 #include "nsClassHashtable.h"
12 #include "nsWeakReference.h"
14 #include "nsICommandManager.h"
15 #include "nsCycleCollectionParticipant.h"
21 class nsCommandManager final
: public nsICommandManager
,
22 public nsSupportsWeakReference
{
24 using ObserverList
= nsTArray
<nsCOMPtr
<nsIObserver
>>;
26 nsCommandManager() = delete;
29 * @param aWindow An window which is what this command manager lives on.
31 explicit nsCommandManager(mozIDOMWindowProxy
* aWindow
);
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCommandManager
, nsICommandManager
)
36 NS_DECL_NSICOMMANDMANAGER
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
43 void CommandStatusChanged(const char* aCommandName
);
45 bool IsCommandEnabled(const nsCString
& aCommandName
,
46 mozIDOMWindowProxy
* aTargetWindow
);
49 virtual ~nsCommandManager();
51 nsresult
GetControllerForCommand(const char* aCommand
,
52 mozIDOMWindowProxy
* aDirectedToThisWindow
,
53 nsIController
** aResult
);
56 nsClassHashtable
<nsCharPtrHashKey
, ObserverList
> mObserversTable
;
58 mozIDOMWindowProxy
* mWindow
; // weak ptr. The window should always outlive us
61 nsCommandManager
* nsICommandManager::AsCommandManager() {
62 return static_cast<nsCommandManager
*>(this);
65 const nsCommandManager
* nsICommandManager::AsCommandManager() const {
66 return static_cast<const nsCommandManager
*>(this);
69 #endif // nsCommandManager_h__