tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsCommandManager.h (2137B)


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