2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-19 22:16:23 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsRepeatService.h"
|
2002-09-07 05:38:16 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsRepeatService* nsRepeatService::gInstance = nullptr;
|
1999-08-19 22:16:23 +00:00
|
|
|
|
|
|
|
nsRepeatService::nsRepeatService()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mCallback(nullptr), mCallbackData(nullptr)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRepeatService::~nsRepeatService()
|
|
|
|
{
|
2008-02-15 02:04:34 +00:00
|
|
|
NS_ASSERTION(!mCallback && !mCallbackData, "Callback was not removed before shutdown");
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRepeatService*
|
|
|
|
nsRepeatService::GetInstance()
|
|
|
|
{
|
2000-11-08 03:20:22 +00:00
|
|
|
if (!gInstance) {
|
|
|
|
gInstance = new nsRepeatService();
|
|
|
|
NS_IF_ADDREF(gInstance);
|
|
|
|
}
|
|
|
|
return gInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
nsRepeatService::Shutdown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(gInstance);
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
|
2009-12-11 22:03:31 +00:00
|
|
|
void nsRepeatService::Start(Callback aCallback, void* aCallbackData,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aInitialDelay)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_PRECONDITION(aCallback != nullptr, "null ptr");
|
2000-01-19 07:40:18 +00:00
|
|
|
|
1999-08-19 22:16:23 +00:00
|
|
|
mCallback = aCallback;
|
2008-02-15 02:04:34 +00:00
|
|
|
mCallbackData = aCallbackData;
|
2000-05-17 02:49:35 +00:00
|
|
|
nsresult rv;
|
2000-09-13 23:57:52 +00:00
|
|
|
mRepeatTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
1999-08-19 22:16:23 +00:00
|
|
|
|
2008-02-15 02:04:34 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2009-12-11 22:03:31 +00:00
|
|
|
mRepeatTimer->InitWithCallback(this, aInitialDelay, nsITimer::TYPE_ONE_SHOT);
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-15 02:04:34 +00:00
|
|
|
void nsRepeatService::Stop(Callback aCallback, void* aCallbackData)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
2008-02-15 02:04:34 +00:00
|
|
|
if (mCallback != aCallback || mCallbackData != aCallbackData)
|
|
|
|
return;
|
|
|
|
|
2002-08-03 19:51:51 +00:00
|
|
|
//printf("Stopping repeat timer\n");
|
1999-08-19 22:16:23 +00:00
|
|
|
if (mRepeatTimer) {
|
|
|
|
mRepeatTimer->Cancel();
|
2012-07-30 14:20:58 +00:00
|
|
|
mRepeatTimer = nullptr;
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
mCallback = nullptr;
|
|
|
|
mCallbackData = nullptr;
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
|
2002-09-07 05:38:16 +00:00
|
|
|
NS_IMETHODIMP nsRepeatService::Notify(nsITimer *timer)
|
1999-08-19 22:16:23 +00:00
|
|
|
{
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
// do callback
|
2000-01-19 07:40:18 +00:00
|
|
|
if (mCallback)
|
2008-02-15 02:04:34 +00:00
|
|
|
mCallback(mCallbackData);
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
|
|
|
|
// start timer again.
|
2002-08-03 19:51:51 +00:00
|
|
|
if (mRepeatTimer) {
|
2008-02-15 02:04:34 +00:00
|
|
|
mRepeatTimer->InitWithCallback(this, REPEAT_DELAY, nsITimer::TYPE_ONE_SHOT);
|
1) implememted box reflow coelescing.
2) implemented gfx scrollbars for list boxes
3) fixed progess meter to be an animated gif
4) fixed bugs 23521, 24721, 19114, 20546, 24385, 24457, 23156, 20226, 22543
-r hyatt, troy, rod
2000-02-09 22:02:40 +00:00
|
|
|
}
|
2002-09-07 05:38:16 +00:00
|
|
|
return NS_OK;
|
1999-08-19 22:16:23 +00:00
|
|
|
}
|
|
|
|
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(nsRepeatService, nsITimerCallback)
|