2014-05-13 00:22:12 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "AnimationTimeline.h"
|
|
|
|
#include "mozilla/dom/AnimationTimelineBinding.h"
|
|
|
|
#include "nsContentUtils.h"
|
2014-05-13 00:22:12 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsDOMNavigationTiming.h"
|
2014-05-13 00:22:12 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(AnimationTimeline, mDocument)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AnimationTimeline, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationTimeline, Release)
|
|
|
|
|
|
|
|
JSObject*
|
|
|
|
AnimationTimeline::WrapObject(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return AnimationTimelineBinding::Wrap(aCx, this);
|
|
|
|
}
|
|
|
|
|
2014-05-13 00:22:12 -07:00
|
|
|
Nullable<double>
|
|
|
|
AnimationTimeline::GetCurrentTime() const
|
|
|
|
{
|
2014-07-15 17:02:30 -07:00
|
|
|
return ToTimelineTime(GetCurrentTimeStamp());
|
2014-07-15 17:02:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp
|
|
|
|
AnimationTimeline::GetCurrentTimeStamp() const
|
|
|
|
{
|
|
|
|
// Always return the same object to benefit from return-value optimization.
|
2014-07-23 21:37:38 -07:00
|
|
|
TimeStamp result = mLastCurrentTime;
|
|
|
|
|
|
|
|
// If we've never been sampled, initialize the current time to the timeline's
|
|
|
|
// zero time since that is the time we'll use if we don't have a refresh
|
|
|
|
// driver.
|
|
|
|
if (result.IsNull()) {
|
|
|
|
nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
|
|
|
|
if (!timing) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = timing->GetNavigationStartTimeStamp();
|
|
|
|
}
|
2014-07-15 17:02:30 -07:00
|
|
|
|
|
|
|
nsIPresShell* presShell = mDocument->GetShell();
|
|
|
|
if (MOZ_UNLIKELY(!presShell)) {
|
2014-05-13 00:22:12 -07:00
|
|
|
return result;
|
2014-07-15 17:02:30 -07:00
|
|
|
}
|
2014-05-13 00:22:12 -07:00
|
|
|
|
2014-07-15 17:02:30 -07:00
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
|
|
|
if (MOZ_UNLIKELY(!presContext)) {
|
|
|
|
return result;
|
|
|
|
}
|
2014-05-13 00:22:12 -07:00
|
|
|
|
2014-07-15 17:02:30 -07:00
|
|
|
result = presContext->RefreshDriver()->MostRecentRefresh();
|
2014-07-23 21:37:38 -07:00
|
|
|
// FIXME: We would like to assert that:
|
|
|
|
// mLastCurrentTime.IsNull() || result >= mLastCurrentTime
|
|
|
|
// but due to bug 1043078 this will not be the case when the refresh driver
|
|
|
|
// is restored from test control.
|
|
|
|
mLastCurrentTime = result;
|
2014-05-13 00:22:12 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-07-15 17:02:30 -07:00
|
|
|
Nullable<double>
|
|
|
|
AnimationTimeline::ToTimelineTime(const mozilla::TimeStamp& aTimeStamp) const
|
|
|
|
{
|
|
|
|
Nullable<double> result; // Initializes to null
|
|
|
|
if (aTimeStamp.IsNull()) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsDOMNavigationTiming> timing = mDocument->GetNavigationTiming();
|
|
|
|
if (MOZ_UNLIKELY(!timing)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
result.SetValue(timing->TimeStampToDOMHighRes(aTimeStamp));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-05-13 00:22:12 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|