layout/xul/nsRepeatService.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsRepeatService.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//
    1.10 +// nsRepeatService
    1.11 +//
    1.12 +#ifndef nsRepeatService_h__
    1.13 +#define nsRepeatService_h__
    1.14 +
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsITimer.h"
    1.17 +
    1.18 +#define INITAL_REPEAT_DELAY 250
    1.19 +
    1.20 +#ifdef XP_MACOSX
    1.21 +#define REPEAT_DELAY        25
    1.22 +#else
    1.23 +#define REPEAT_DELAY        50
    1.24 +#endif
    1.25 +
    1.26 +class nsITimer;
    1.27 +
    1.28 +class nsRepeatService : public nsITimerCallback
    1.29 +{
    1.30 +public:
    1.31 +
    1.32 +  typedef void (* Callback)(void* aData);
    1.33 +    
    1.34 +  NS_DECL_NSITIMERCALLBACK
    1.35 +
    1.36 +  // Start dispatching timer events to the callback. There is no memory
    1.37 +  // management of aData here; it is the caller's responsibility to call
    1.38 +  // Stop() before aData's memory is released.
    1.39 +  void Start(Callback aCallback, void* aData,
    1.40 +             uint32_t aInitialDelay = INITAL_REPEAT_DELAY);
    1.41 +  // Stop dispatching timer events to the callback. If the repeat service
    1.42 +  // is not currently configured with the given callback and data, this
    1.43 +  // is just ignored.
    1.44 +  void Stop(Callback aCallback, void* aData);
    1.45 +
    1.46 +  static nsRepeatService* GetInstance();
    1.47 +  static void Shutdown();
    1.48 +
    1.49 +  NS_DECL_ISUPPORTS
    1.50 +  virtual ~nsRepeatService();
    1.51 +
    1.52 +protected:
    1.53 +  nsRepeatService();
    1.54 +
    1.55 +private:
    1.56 +  Callback           mCallback;
    1.57 +  void*              mCallbackData;
    1.58 +  nsCOMPtr<nsITimer> mRepeatTimer;
    1.59 +  static nsRepeatService* gInstance;
    1.60 +
    1.61 +}; // class nsRepeatService
    1.62 +
    1.63 +#endif

mercurial