Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 : #include "Timeout.h"
8 :
9 : #include "mozilla/dom/TimeoutManager.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 13 : Timeout::Timeout()
15 : : mCleared(false),
16 : mRunning(false),
17 : mIsInterval(false),
18 : mIsTracking(false),
19 : mReason(Reason::eTimeoutOrInterval),
20 : mTimeoutId(0),
21 : mInterval(0),
22 : mFiringId(TimeoutManager::InvalidFiringId),
23 : mNestingLevel(0),
24 13 : mPopupState(openAllowed)
25 : {
26 13 : }
27 :
28 : NS_IMPL_CYCLE_COLLECTION_CLASS(Timeout)
29 :
30 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Timeout)
31 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
32 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mScriptHandler)
33 0 : tmp->remove();
34 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
35 :
36 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Timeout)
37 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
38 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptHandler)
39 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
40 :
41 0 : NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Timeout, AddRef)
42 0 : NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Timeout, Release)
43 :
44 : void
45 13 : Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
46 : const TimeDuration& aDelay)
47 : {
48 13 : MOZ_DIAGNOSTIC_ASSERT(mWindow);
49 :
50 : // If we are frozen simply set mTimeRemaining to be the "time remaining" in
51 : // the timeout (i.e., the interval itself). This will be used to create a
52 : // new mWhen time when the window is thawed. The end effect is that time does
53 : // not appear to pass for frozen windows.
54 13 : if (mWindow->IsFrozen()) {
55 0 : mWhen = TimeStamp();
56 0 : mTimeRemaining = aDelay;
57 0 : return;
58 : }
59 :
60 : // Since we are not frozen we must set a precise mWhen target wakeup
61 : // time. Even if we are suspended we want to use this target time so
62 : // that it appears time passes while suspended.
63 13 : mWhen = aBaseTime + aDelay;
64 13 : mTimeRemaining = TimeDuration(0);
65 : }
66 :
67 : const TimeStamp&
68 113 : Timeout::When() const
69 : {
70 113 : MOZ_DIAGNOSTIC_ASSERT(!mWhen.IsNull());
71 : // Note, mWindow->IsFrozen() can be true here. The Freeze() method calls
72 : // When() to calculate the delay to populate mTimeRemaining.
73 113 : return mWhen;
74 : }
75 :
76 : const TimeDuration&
77 0 : Timeout::TimeRemaining() const
78 : {
79 0 : MOZ_DIAGNOSTIC_ASSERT(mWhen.IsNull());
80 : // Note, mWindow->IsFrozen() can be false here. The Thaw() method calls
81 : // TimeRemaining() to calculate the new When() value.
82 0 : return mTimeRemaining;
83 : }
84 :
85 : } // namespace dom
86 : } // namespace mozilla
|