no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / layout / xul / nsRepeatService.h
blob158e7ffd31631d2250529b4a5c12f67ab9a03fee
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 //
8 // nsRepeatService
9 //
10 #ifndef nsRepeatService_h__
11 #define nsRepeatService_h__
13 #include "nsCOMPtr.h"
14 #include "nsITimer.h"
15 #include "nsString.h"
17 #define INITAL_REPEAT_DELAY 250
19 #ifdef XP_MACOSX
20 # define REPEAT_DELAY 25
21 #else
22 # define REPEAT_DELAY 50
23 #endif
25 class nsITimer;
27 namespace mozilla {
28 namespace dom {
29 class Document;
31 } // namespace mozilla
33 class nsRepeatService final {
34 public:
35 typedef void (*Callback)(void* aData);
37 ~nsRepeatService();
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
53 // is just ignored.
54 void Stop(Callback aCallback, void* aData);
56 static nsRepeatService* GetInstance();
57 static void Shutdown();
59 protected:
60 nsRepeatService();
62 private:
63 // helper function to initialize callback function to mRepeatTimer
64 void InitTimerCallback(uint32_t aInitialDelay);
66 Callback mCallback;
67 void* mCallbackData;
68 nsCString mCallbackName;
69 nsCOMPtr<nsITimer> mRepeatTimer;
71 }; // class nsRepeatService
73 #endif