1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 //
7 // nsRepeatService
8 //
9 #ifndef nsRepeatService_h__
10 #define nsRepeatService_h__
11 
12 #include "nsCOMPtr.h"
13 #include "nsITimer.h"
14 
15 #define INITAL_REPEAT_DELAY 250
16 
17 #ifdef XP_MACOSX
18 #define REPEAT_DELAY        25
19 #else
20 #define REPEAT_DELAY        50
21 #endif
22 
23 class nsITimer;
24 
25 class nsRepeatService final : public nsITimerCallback
26 {
27 public:
28 
29   typedef void (* Callback)(void* aData);
30 
31   NS_DECL_NSITIMERCALLBACK
32 
33   // Start dispatching timer events to the callback. There is no memory
34   // management of aData here; it is the caller's responsibility to call
35   // Stop() before aData's memory is released.
36   void Start(Callback aCallback, void* aData,
37              uint32_t aInitialDelay = INITAL_REPEAT_DELAY);
38   // Stop dispatching timer events to the callback. If the repeat service
39   // is not currently configured with the given callback and data, this
40   // is just ignored.
41   void Stop(Callback aCallback, void* aData);
42 
43   static nsRepeatService* GetInstance();
44   static void Shutdown();
45 
46   NS_DECL_ISUPPORTS
47 
48 protected:
49   nsRepeatService();
50   virtual ~nsRepeatService();
51 
52 private:
53   Callback           mCallback;
54   void*              mCallbackData;
55   nsCOMPtr<nsITimer> mRepeatTimer;
56   static nsRepeatService* gInstance;
57 
58 }; // class nsRepeatService
59 
60 #endif
61