1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * Code to notify things that animate before a refresh, at an appropriate
9 * refresh rate. (Perhaps temporary, until replaced by compositor.)
12 #ifndef LAYOUT_BASE_NSREFRESHOBSERVERS_H_
13 #define LAYOUT_BASE_NSREFRESHOBSERVERS_H_
17 #include "mozilla/Attributes.h"
18 #include "mozilla/TimeStamp.h"
19 #include "nsISupports.h"
24 class AnimationEventDispatcher
;
25 class PendingFullscreenEvent
;
27 class RefreshDriverTimer
;
28 } // namespace mozilla
31 * An abstract base class to be implemented by callers wanting to be
32 * notified at refresh times. When nothing needs to be painted, callers
33 * may not be notified.
35 class nsARefreshObserver
{
37 // AddRef and Release signatures that match nsISupports. Implementors
38 // must implement reference counting, and those that do implement
39 // nsISupports will already have methods with the correct signature.
41 // The refresh driver does NOT hold references to refresh observers
42 // except while it is notifying them.
43 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
45 MOZ_CAN_RUN_SCRIPT
virtual void WillRefresh(mozilla::TimeStamp aTime
) = 0;
49 * An abstract base class to be implemented by callers wanting to be notified
50 * when the observing refresh driver updated mMostRecentRefresh due to active
51 * timer changes. Callers must ensure an observer is removed before it is
54 class nsATimerAdjustmentObserver
{
56 virtual void NotifyTimerAdjusted(mozilla::TimeStamp aTime
) = 0;
60 * An abstract base class to be implemented by callers wanting to be notified
61 * that a refresh has occurred. Callers must ensure an observer is removed
62 * before it is destroyed.
64 class nsAPostRefreshObserver
{
66 virtual void DidRefresh() = 0;
72 * A wrapper for nsAPostRefreshObserver that's refcounted and might unregister
73 * itself after firing.
75 * Note, while the observer unregisters itself, the registering still needs to
76 * be done by the caller.
78 class ManagedPostRefreshObserver
: public nsAPostRefreshObserver
{
80 // Whether the post-refresh observer should be unregistered after it has
82 enum class Unregister
: bool { No
, Yes
};
83 using Action
= std::function
<Unregister(bool aWasCanceled
)>;
84 NS_INLINE_DECL_REFCOUNTING(ManagedPostRefreshObserver
)
85 ManagedPostRefreshObserver(nsPresContext
*, Action
&&);
86 explicit ManagedPostRefreshObserver(nsPresContext
*);
87 void DidRefresh() override
;
91 virtual ~ManagedPostRefreshObserver();
92 RefPtr
<nsPresContext
> mPresContext
;
96 } // namespace mozilla