Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_layers_AsyncPanZoomAnimation_h_
8
#define mozilla_layers_AsyncPanZoomAnimation_h_
9
10
#include "APZUtils.h"
11
#include "base/message_loop.h"
12
#include "mozilla/RefPtr.h"
13
#include "mozilla/TimeStamp.h"
14
#include "nsISupportsImpl.h"
15
#include "nsTArray.h"
16
17
namespace mozilla {
18
namespace layers {
19
20
struct FrameMetrics;
21
22
class WheelScrollAnimation;
23
class KeyboardScrollAnimation;
24
class SmoothScrollAnimation;
25
26
class AsyncPanZoomAnimation {
27
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AsyncPanZoomAnimation)
28
29
public:
30
explicit AsyncPanZoomAnimation() = default;
31
32
virtual bool DoSample(FrameMetrics& aFrameMetrics,
33
const TimeDuration& aDelta) = 0;
34
35
/**
36
* Attempt to handle a main-thread scroll offset update without cancelling
37
* the animation. This may or may not make sense depending on the type of
38
* the animation and whether the scroll update is relative or absolute.
39
*
40
* If the scroll update is relative, |aRelativeDelta| will contain the
41
* delta of the relative update. If the scroll update is absolute,
42
* |aRelativeDelta| will be Nothing() (the animation can check the APZC's
43
* FrameMetrics for the new absolute scroll offset if it wants to handle
44
* and absolute update).
45
*
46
* Returns whether the animation could handle the scroll update. If the
47
* return value is false, the animation will be cancelled.
48
*/
49
virtual bool HandleScrollOffsetUpdate(const Maybe<CSSPoint>& aRelativeDelta) {
50
return false;
51
}
52
53
bool Sample(FrameMetrics& aFrameMetrics, const TimeDuration& aDelta) {
54
// In some situations, particularly when handoff is involved, it's possible
55
// for |aDelta| to be negative on the first call to sample. Ignore such a
56
// sample here, to avoid each derived class having to deal with this case.
57
if (aDelta.ToMilliseconds() <= 0) {
58
return true;
59
}
60
61
return DoSample(aFrameMetrics, aDelta);
62
}
63
64
/**
65
* Get the deferred tasks in |mDeferredTasks| and place them in |aTasks|. See
66
* |mDeferredTasks| for more information. Clears |mDeferredTasks|.
67
*/
68
nsTArray<RefPtr<Runnable>> TakeDeferredTasks() {
69
return std::move(mDeferredTasks);
70
}
71
72
virtual KeyboardScrollAnimation* AsKeyboardScrollAnimation() {
73
return nullptr;
74
}
75
virtual WheelScrollAnimation* AsWheelScrollAnimation() { return nullptr; }
76
virtual SmoothScrollAnimation* AsSmoothScrollAnimation() { return nullptr; }
77
78
virtual bool WantsRepaints() { return true; }
79
80
virtual void Cancel(CancelAnimationFlags aFlags) {}
81
82
protected:
83
// Protected destructor, to discourage deletion outside of Release():
84
virtual ~AsyncPanZoomAnimation() = default;
85
86
/**
87
* Tasks scheduled for execution after the APZC's mMonitor is released.
88
* Derived classes can add tasks here in Sample(), and the APZC can call
89
* ExecuteDeferredTasks() to execute them.
90
*/
91
nsTArray<RefPtr<Runnable>> mDeferredTasks;
92
};
93
94
} // namespace layers
95
} // namespace mozilla
96
97
#endif // mozilla_layers_AsyncPanZoomAnimation_h_