michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // michael@0: // nsRepeatService michael@0: // michael@0: #ifndef nsRepeatService_h__ michael@0: #define nsRepeatService_h__ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsITimer.h" michael@0: michael@0: #define INITAL_REPEAT_DELAY 250 michael@0: michael@0: #ifdef XP_MACOSX michael@0: #define REPEAT_DELAY 25 michael@0: #else michael@0: #define REPEAT_DELAY 50 michael@0: #endif michael@0: michael@0: class nsITimer; michael@0: michael@0: class nsRepeatService : public nsITimerCallback michael@0: { michael@0: public: michael@0: michael@0: typedef void (* Callback)(void* aData); michael@0: michael@0: NS_DECL_NSITIMERCALLBACK michael@0: michael@0: // Start dispatching timer events to the callback. There is no memory michael@0: // management of aData here; it is the caller's responsibility to call michael@0: // Stop() before aData's memory is released. michael@0: void Start(Callback aCallback, void* aData, michael@0: uint32_t aInitialDelay = INITAL_REPEAT_DELAY); michael@0: // Stop dispatching timer events to the callback. If the repeat service michael@0: // is not currently configured with the given callback and data, this michael@0: // is just ignored. michael@0: void Stop(Callback aCallback, void* aData); michael@0: michael@0: static nsRepeatService* GetInstance(); michael@0: static void Shutdown(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: virtual ~nsRepeatService(); michael@0: michael@0: protected: michael@0: nsRepeatService(); michael@0: michael@0: private: michael@0: Callback mCallback; michael@0: void* mCallbackData; michael@0: nsCOMPtr mRepeatTimer; michael@0: static nsRepeatService* gInstance; michael@0: michael@0: }; // class nsRepeatService michael@0: michael@0: #endif