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/. */
10 #ifndef nsRepeatService_h__
11 #define nsRepeatService_h__
17 #define INITAL_REPEAT_DELAY 250
20 # define REPEAT_DELAY 25
22 # define REPEAT_DELAY 50
31 } // namespace mozilla
33 class nsRepeatService final
{
35 typedef void (*Callback
)(void* aData
);
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.
43 // aCallbackName is the label of the callback, used to pass to
44 // InitWithNamedCallbackFunc.
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
54 void Stop(Callback aCallback
, void* aData
);
56 static nsRepeatService
* GetInstance();
57 static void Shutdown();
63 // helper function to initialize callback function to mRepeatTimer
64 void InitTimerCallback(uint32_t aInitialDelay
);
68 nsCString mCallbackName
;
69 nsCOMPtr
<nsITimer
> mRepeatTimer
;
71 }; // class nsRepeatService