layout/xul/nsRepeatService.cpp

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

     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/. */
     6 //
     7 // Eric Vaughan
     8 // Netscape Communications
     9 //
    10 // See documentation in associated header file
    11 //
    13 #include "nsRepeatService.h"
    14 #include "nsIServiceManager.h"
    16 nsRepeatService* nsRepeatService::gInstance = nullptr;
    18 nsRepeatService::nsRepeatService()
    19 : mCallback(nullptr), mCallbackData(nullptr)
    20 {
    21 }
    23 nsRepeatService::~nsRepeatService()
    24 {
    25   NS_ASSERTION(!mCallback && !mCallbackData, "Callback was not removed before shutdown");
    26 }
    28 nsRepeatService* 
    29 nsRepeatService::GetInstance()
    30 {
    31   if (!gInstance) {
    32     gInstance = new nsRepeatService();
    33     NS_IF_ADDREF(gInstance);
    34   }
    35   return gInstance;
    36 }
    38 /*static*/ void
    39 nsRepeatService::Shutdown()
    40 {
    41   NS_IF_RELEASE(gInstance);
    42 }
    44 void nsRepeatService::Start(Callback aCallback, void* aCallbackData,
    45                             uint32_t aInitialDelay)
    46 {
    47   NS_PRECONDITION(aCallback != nullptr, "null ptr");
    49   mCallback = aCallback;
    50   mCallbackData = aCallbackData;
    51   nsresult rv;
    52   mRepeatTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
    54   if (NS_SUCCEEDED(rv))  {
    55     mRepeatTimer->InitWithCallback(this, aInitialDelay, nsITimer::TYPE_ONE_SHOT);
    56   }
    57 }
    59 void nsRepeatService::Stop(Callback aCallback, void* aCallbackData)
    60 {
    61   if (mCallback != aCallback || mCallbackData != aCallbackData)
    62     return;
    64   //printf("Stopping repeat timer\n");
    65   if (mRepeatTimer) {
    66      mRepeatTimer->Cancel();
    67      mRepeatTimer = nullptr;
    68   }
    69   mCallback = nullptr;
    70   mCallbackData = nullptr;
    71 }
    73 NS_IMETHODIMP nsRepeatService::Notify(nsITimer *timer)
    74 {
    75   // do callback
    76   if (mCallback)
    77     mCallback(mCallbackData);
    79   // start timer again.
    80   if (mRepeatTimer) {
    81     mRepeatTimer->InitWithCallback(this, REPEAT_DELAY, nsITimer::TYPE_ONE_SHOT);
    82   }
    83   return NS_OK;
    84 }
    86 NS_IMPL_ISUPPORTS(nsRepeatService, nsITimerCallback)

mercurial