2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-20 02:16:23 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Eric Vaughan
|
|
|
|
// Netscape Communications
|
|
|
|
//
|
|
|
|
// See documentation in associated header file
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "nsRepeatService.h"
|
2017-03-29 10:54:49 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2017-03-29 11:40:05 +03:00
|
|
|
#include "nsIDocument.h"
|
2002-09-07 09:38:16 +04:00
|
|
|
#include "nsIServiceManager.h"
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2017-03-29 06:48:56 +03:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2017-03-29 10:54:49 +03:00
|
|
|
static StaticAutoPtr<nsRepeatService> gRepeatService;
|
1999-08-20 02:16:23 +04:00
|
|
|
|
|
|
|
nsRepeatService::nsRepeatService()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mCallback(nullptr), mCallbackData(nullptr)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRepeatService::~nsRepeatService()
|
|
|
|
{
|
2008-02-15 05:04:34 +03:00
|
|
|
NS_ASSERTION(!mCallback && !mCallbackData, "Callback was not removed before shutdown");
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2017-03-29 06:48:56 +03:00
|
|
|
/* static */ nsRepeatService*
|
1999-08-20 02:16:23 +04:00
|
|
|
nsRepeatService::GetInstance()
|
|
|
|
{
|
2017-03-29 06:48:56 +03:00
|
|
|
if (!gRepeatService) {
|
|
|
|
gRepeatService = new nsRepeatService();
|
2000-11-08 06:20:22 +03:00
|
|
|
}
|
2017-03-29 06:48:56 +03:00
|
|
|
return gRepeatService;
|
2000-11-08 06:20:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
nsRepeatService::Shutdown()
|
|
|
|
{
|
2017-03-29 06:48:56 +03:00
|
|
|
gRepeatService = nullptr;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2017-03-29 11:32:52 +03:00
|
|
|
void
|
|
|
|
nsRepeatService::Start(Callback aCallback, void* aCallbackData,
|
2017-03-29 11:40:05 +03:00
|
|
|
nsIDocument* aDocument, const nsACString& aCallbackName,
|
2017-03-29 11:32:52 +03:00
|
|
|
uint32_t aInitialDelay)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aCallback != nullptr, "null ptr");
|
2000-01-19 10:40:18 +03:00
|
|
|
|
1999-08-20 02:16:23 +04:00
|
|
|
mCallback = aCallback;
|
2008-02-15 05:04:34 +03:00
|
|
|
mCallbackData = aCallbackData;
|
2017-03-29 11:32:52 +03:00
|
|
|
mCallbackName = aCallbackName;
|
|
|
|
|
2000-05-17 06:49:35 +04:00
|
|
|
nsresult rv;
|
2000-09-14 03:57:52 +04:00
|
|
|
mRepeatTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2008-02-15 05:04:34 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2017-03-29 11:40:05 +03:00
|
|
|
mRepeatTimer->SetTarget(aDocument->EventTargetFor(TaskCategory::Other));
|
2017-03-29 10:40:04 +03:00
|
|
|
InitTimerCallback(aInitialDelay);
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-15 05:04:34 +03:00
|
|
|
void nsRepeatService::Stop(Callback aCallback, void* aCallbackData)
|
1999-08-20 02:16:23 +04:00
|
|
|
{
|
2008-02-15 05:04:34 +03:00
|
|
|
if (mCallback != aCallback || mCallbackData != aCallbackData)
|
|
|
|
return;
|
|
|
|
|
2002-08-03 23:51:51 +04:00
|
|
|
//printf("Stopping repeat timer\n");
|
1999-08-20 02:16:23 +04:00
|
|
|
if (mRepeatTimer) {
|
|
|
|
mRepeatTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mRepeatTimer = nullptr;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mCallback = nullptr;
|
|
|
|
mCallbackData = nullptr;
|
1999-08-20 02:16:23 +04:00
|
|
|
}
|
|
|
|
|
2017-03-29 10:40:04 +03:00
|
|
|
void
|
|
|
|
nsRepeatService::InitTimerCallback(uint32_t aInitialDelay)
|
|
|
|
{
|
2017-03-29 10:54:49 +03:00
|
|
|
if (!mRepeatTimer) {
|
|
|
|
return;
|
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-10 01:02:40 +03:00
|
|
|
}
|
1999-08-20 02:16:23 +04:00
|
|
|
|
2017-03-29 11:32:52 +03:00
|
|
|
mRepeatTimer->InitWithNamedFuncCallback([](nsITimer* aTimer, void* aClosure) {
|
2017-03-29 10:54:49 +03:00
|
|
|
// Use gRepeatService instead of nsRepeatService::GetInstance() (because
|
|
|
|
// we don't want nsRepeatService::GetInstance() to re-create a new instance
|
|
|
|
// for us, if we happen to get invoked after nsRepeatService::Shutdown() has
|
|
|
|
// nulled out gRepeatService).
|
|
|
|
nsRepeatService* rs = gRepeatService;
|
|
|
|
if (!rs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rs->mCallback) {
|
|
|
|
rs->mCallback(rs->mCallbackData);
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->InitTimerCallback(REPEAT_DELAY);
|
2017-03-29 11:32:52 +03:00
|
|
|
}, nullptr, aInitialDelay, nsITimer::TYPE_ONE_SHOT, mCallbackName.Data());
|
2017-03-29 10:54:49 +03:00
|
|
|
}
|