tor-browser

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

nsRepeatService.h (1988B)


      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 //
      8 // nsRepeatService
      9 //
     10 #ifndef nsRepeatService_h__
     11 #define nsRepeatService_h__
     12 
     13 #include "nsCOMPtr.h"
     14 #include "nsITimer.h"
     15 #include "nsString.h"
     16 
     17 #define INITAL_REPEAT_DELAY 250
     18 
     19 #ifdef XP_MACOSX
     20 #  define REPEAT_DELAY 25
     21 #else
     22 #  define REPEAT_DELAY 50
     23 #endif
     24 
     25 class nsITimer;
     26 
     27 namespace mozilla {
     28 namespace dom {
     29 class Document;
     30 }
     31 }  // namespace mozilla
     32 
     33 class nsRepeatService final {
     34 public:
     35  typedef void (*Callback)(void* aData);
     36 
     37  ~nsRepeatService();
     38 
     39  // Start dispatching timer events to the callback. There is no memory
     40  // management of aData here; it is the caller's responsibility to call
     41  // Stop() before aData's memory is released.
     42  //
     43  // aCallbackName is the label of the callback, used to pass to
     44  // InitWithNamedCallbackFunc.
     45  //
     46  // aDocument is used to get the event target in Start(). We need an event
     47  // target to init mRepeatTimer.
     48  void Start(Callback aCallback, void* aCallbackData,
     49             mozilla::dom::Document* aDocument, const nsACString& aCallbackName,
     50             uint32_t aInitialDelay = INITAL_REPEAT_DELAY);
     51  // Stop dispatching timer events to the callback. If the repeat service
     52  // is not currently configured with the given callback and data, this
     53  // is just ignored.
     54  void Stop(Callback aCallback, void* aData);
     55 
     56  static nsRepeatService* GetInstance();
     57  static void Shutdown();
     58 
     59 protected:
     60  nsRepeatService();
     61 
     62 private:
     63  // helper function to initialize callback function to mRepeatTimer
     64  void InitTimerCallback(uint32_t aInitialDelay);
     65 
     66  Callback mCallback;
     67  void* mCallbackData;
     68  nsCString mCallbackName;
     69  nsCOMPtr<nsITimer> mRepeatTimer;
     70 
     71 };  // class nsRepeatService
     72 
     73 #endif