nsRepeatService.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // nsRepeatService
  7. //
  8. #ifndef nsRepeatService_h__
  9. #define nsRepeatService_h__
  10. #include "nsCOMPtr.h"
  11. #include "nsITimer.h"
  12. #define INITAL_REPEAT_DELAY 250
  13. #define REPEAT_DELAY 50
  14. class nsITimer;
  15. class nsRepeatService final : public nsITimerCallback
  16. {
  17. public:
  18. typedef void (* Callback)(void* aData);
  19. NS_DECL_NSITIMERCALLBACK
  20. // Start dispatching timer events to the callback. There is no memory
  21. // management of aData here; it is the caller's responsibility to call
  22. // Stop() before aData's memory is released.
  23. void Start(Callback aCallback, void* aData,
  24. uint32_t aInitialDelay = INITAL_REPEAT_DELAY);
  25. // Stop dispatching timer events to the callback. If the repeat service
  26. // is not currently configured with the given callback and data, this
  27. // is just ignored.
  28. void Stop(Callback aCallback, void* aData);
  29. static nsRepeatService* GetInstance();
  30. static void Shutdown();
  31. NS_DECL_ISUPPORTS
  32. protected:
  33. nsRepeatService();
  34. virtual ~nsRepeatService();
  35. private:
  36. Callback mCallback;
  37. void* mCallbackData;
  38. nsCOMPtr<nsITimer> mRepeatTimer;
  39. static nsRepeatService* gInstance;
  40. }; // class nsRepeatService
  41. #endif