Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / layout / base / nsRefreshObservers.h
blob3e2adb81029d7d5c9712c6e6e3b78c815f5f835a
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/. */
7 /*
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_
15 #include <functional>
17 #include "mozilla/Attributes.h"
18 #include "mozilla/TimeStamp.h"
19 #include "nsISupports.h"
21 class nsPresContext;
23 namespace mozilla {
24 class AnimationEventDispatcher;
25 class PendingFullscreenEvent;
26 class PresShell;
27 class RefreshDriverTimer;
28 } // namespace mozilla
30 /**
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 {
36 public:
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;
48 /**
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
52 * destroyed.
54 class nsATimerAdjustmentObserver {
55 public:
56 virtual void NotifyTimerAdjusted(mozilla::TimeStamp aTime) = 0;
59 /**
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 {
65 public:
66 virtual void DidRefresh() = 0;
69 namespace mozilla {
71 /**
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 {
79 public:
80 // Whether the post-refresh observer should be unregistered after it has
81 // fired.
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;
88 void Cancel();
90 protected:
91 virtual ~ManagedPostRefreshObserver();
92 RefPtr<nsPresContext> mPresContext;
93 Action mAction;
96 } // namespace mozilla
98 #endif