2010-06-30 18:54:29 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2009-10-07 20:22:42 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
/* Code to start and animate CSS transitions. */
|
|
|
|
|
|
|
|
#include "nsTransitionManager.h"
|
2012-12-11 13:12:43 -08:00
|
|
|
#include "nsAnimationManager.h"
|
2009-10-07 20:22:42 -07:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSProps.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2009-10-07 20:22:42 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsRuleProcessorData.h"
|
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsCSSPropertySet.h"
|
|
|
|
#include "nsStyleAnimation.h"
|
2009-12-23 11:10:31 -08:00
|
|
|
#include "nsEventDispatcher.h"
|
2013-09-25 04:21:20 -07:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2010-05-14 10:04:51 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-31 10:28:22 -07:00
|
|
|
#include "nsIFrame.h"
|
2012-12-11 13:12:43 -08:00
|
|
|
#include "Layers.h"
|
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
#include "nsDisplayList.h"
|
2013-01-08 20:37:29 -08:00
|
|
|
#include "nsStyleChangeList.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "RestyleManager.h"
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
using mozilla::TimeStamp;
|
|
|
|
using mozilla::TimeDuration;
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::css;
|
2010-05-14 10:04:51 -07:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
ElementTransitions::ElementTransitions(mozilla::dom::Element *aElement,
|
|
|
|
nsIAtom *aElementProperty,
|
|
|
|
nsTransitionManager *aTransitionManager,
|
|
|
|
TimeStamp aNow)
|
|
|
|
: CommonElementAnimationData(aElement, aElementProperty, aTransitionManager)
|
|
|
|
, mFlushGeneration(aNow)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
2012-07-30 11:36:12 -07:00
|
|
|
|
2010-11-10 07:49:53 -08:00
|
|
|
double
|
|
|
|
ElementPropertyTransition::ValuePortionFor(TimeStamp aRefreshTime) const
|
|
|
|
{
|
|
|
|
// Set |timePortion| to the portion of the way we are through the time
|
|
|
|
// input to the transition's timing function (always within the range
|
|
|
|
// 0-1).
|
|
|
|
double duration = mDuration.ToSeconds();
|
|
|
|
NS_ABORT_IF_FALSE(duration >= 0.0, "negative duration forbidden");
|
|
|
|
double timePortion;
|
2012-12-11 13:12:43 -08:00
|
|
|
if (IsRemovedSentinel()) {
|
|
|
|
// The transition is being removed, but we still want an update so that any
|
|
|
|
// new transitions start in the right place.
|
|
|
|
timePortion = 1.0;
|
|
|
|
} else if (duration == 0.0) {
|
2010-11-10 07:49:53 -08:00
|
|
|
// When duration is zero, we can still have a transition when delay
|
|
|
|
// is nonzero. mStartTime already incorporates delay.
|
|
|
|
if (aRefreshTime >= mStartTime) {
|
|
|
|
timePortion = 1.0;
|
2011-01-04 07:10:54 -08:00
|
|
|
} else {
|
|
|
|
timePortion = 0.0;
|
2010-11-10 07:49:53 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timePortion = (aRefreshTime - mStartTime).ToSeconds() / duration;
|
|
|
|
if (timePortion < 0.0)
|
|
|
|
timePortion = 0.0; // use start value during transition-delay
|
|
|
|
if (timePortion > 1.0)
|
|
|
|
timePortion = 1.0; // we might be behind on flushing
|
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:42 -07:00
|
|
|
return mTimingFunction.GetValue(timePortion);
|
2010-11-10 07:49:53 -08:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
static void
|
|
|
|
ElementTransitionsPropertyDtor(void *aObject,
|
|
|
|
nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue,
|
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
ElementTransitions *et = static_cast<ElementTransitions*>(aPropertyValue);
|
2011-04-30 15:16:19 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ABORT_IF_FALSE(!et->mCalledPropertyDtor, "can't call dtor twice");
|
|
|
|
et->mCalledPropertyDtor = true;
|
|
|
|
#endif
|
2009-10-07 20:22:42 -07:00
|
|
|
delete et;
|
|
|
|
}
|
|
|
|
|
2010-07-28 16:43:53 -07:00
|
|
|
void
|
|
|
|
ElementTransitions::EnsureStyleRuleFor(TimeStamp aRefreshTime)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
2010-07-28 16:43:53 -07:00
|
|
|
if (!mStyleRule || mStyleRuleRefreshTime != aRefreshTime) {
|
2011-04-11 23:18:43 -07:00
|
|
|
mStyleRule = new css::AnimValuesStyleRule();
|
2010-07-28 16:43:53 -07:00
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyTransitions.Length(); i < i_end; ++i)
|
2010-07-28 16:43:53 -07:00
|
|
|
{
|
|
|
|
ElementPropertyTransition &pt = mPropertyTransitions[i];
|
|
|
|
if (pt.IsRemovedSentinel()) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-19 19:28:00 -07:00
|
|
|
|
2010-07-28 16:43:53 -07:00
|
|
|
nsStyleAnimation::Value *val = mStyleRule->AddEmptyValue(pt.mProperty);
|
2010-01-12 08:51:37 -08:00
|
|
|
|
2010-11-10 07:49:53 -08:00
|
|
|
double valuePortion = pt.ValuePortionFor(aRefreshTime);
|
2009-10-07 20:22:42 -07:00
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ok =
|
2009-10-07 20:22:42 -07:00
|
|
|
#endif
|
2009-11-14 19:16:58 -08:00
|
|
|
nsStyleAnimation::Interpolate(pt.mProperty,
|
|
|
|
pt.mStartValue, pt.mEndValue,
|
2010-07-28 16:43:53 -07:00
|
|
|
valuePortion, *val);
|
2009-10-07 20:22:42 -07:00
|
|
|
NS_ABORT_IF_FALSE(ok, "could not interpolate values");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
bool
|
2012-08-21 18:48:47 -07:00
|
|
|
ElementPropertyTransition::IsRunningAt(TimeStamp aTime) const {
|
2012-12-11 13:12:43 -08:00
|
|
|
return !IsRemovedSentinel() &&
|
|
|
|
mStartTime <= aTime &&
|
|
|
|
aTime < mStartTime + mDuration;
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-12-11 13:12:43 -08:00
|
|
|
ElementTransitions::HasAnimationOfProperty(nsCSSProperty aProperty) const
|
2012-07-31 10:28:22 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t tranIdx = mPropertyTransitions.Length(); tranIdx-- != 0; ) {
|
2013-09-09 03:21:24 -07:00
|
|
|
const ElementPropertyTransition& pt = mPropertyTransitions[tranIdx];
|
|
|
|
if (aProperty == pt.mProperty && !pt.IsRemovedSentinel()) {
|
2012-07-31 10:28:22 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-12-11 13:12:43 -08:00
|
|
|
ElementTransitions::CanPerformOnCompositorThread(CanAnimateFlags aFlags) const
|
2012-07-31 10:28:22 -07:00
|
|
|
{
|
2013-06-24 22:32:10 -07:00
|
|
|
nsIFrame* frame = nsLayoutUtils::GetStyleFrame(mElement);
|
2012-08-25 18:27:28 -07:00
|
|
|
if (!frame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-21 18:48:47 -07:00
|
|
|
if (mElementProperty != nsGkAtoms::transitionsProperty) {
|
2012-08-24 12:08:18 -07:00
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled()) {
|
2012-08-25 18:27:28 -07:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async transition of pseudoelements not supported. See bug 771367");
|
|
|
|
LogAsyncAnimationFailure(message, mElement);
|
2012-08-24 12:08:18 -07:00
|
|
|
}
|
2012-08-21 18:48:47 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-25 18:27:28 -07:00
|
|
|
|
2012-08-21 18:48:47 -07:00
|
|
|
TimeStamp now = frame->PresContext()->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyTransitions.Length(); i < i_end; ++i) {
|
2012-08-21 18:48:47 -07:00
|
|
|
const ElementPropertyTransition& pt = mPropertyTransitions[i];
|
|
|
|
if (css::IsGeometricProperty(pt.mProperty) && pt.IsRunningAt(now)) {
|
2012-12-11 13:12:43 -08:00
|
|
|
aFlags = CanAnimateFlags(aFlags | CanAnimate_HasGeometricProperty);
|
2012-08-21 18:48:47 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 07:52:30 -07:00
|
|
|
bool hasOpacity = false;
|
|
|
|
bool hasTransform = false;
|
2012-12-11 13:12:43 -08:00
|
|
|
bool existsProperty = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyTransitions.Length(); i < i_end; ++i) {
|
2012-08-21 18:48:47 -07:00
|
|
|
const ElementPropertyTransition& pt = mPropertyTransitions[i];
|
2012-07-31 10:28:22 -07:00
|
|
|
if (pt.IsRemovedSentinel()) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
existsProperty = true;
|
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
if (!css::CommonElementAnimationData::CanAnimatePropertyOnCompositor(mElement,
|
2012-08-21 18:48:47 -07:00
|
|
|
pt.mProperty,
|
2013-10-22 03:30:45 -07:00
|
|
|
aFlags) ||
|
|
|
|
!css::CommonElementAnimationData::IsCompositorAnimationDisabledForFrame(frame)) {
|
2012-07-31 10:28:22 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-25 07:52:30 -07:00
|
|
|
if (pt.mProperty == eCSSProperty_opacity) {
|
|
|
|
hasOpacity = true;
|
|
|
|
} else if (pt.mProperty == eCSSProperty_transform) {
|
|
|
|
hasTransform = true;
|
|
|
|
}
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
// No properties to animate
|
|
|
|
if (!existsProperty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-25 07:52:30 -07:00
|
|
|
// This transition can be done on the compositor. Mark the frame as active, in
|
|
|
|
// case we are able to throttle this transition.
|
|
|
|
if (hasOpacity) {
|
|
|
|
frame->MarkLayersActive(nsChangeHint_UpdateOpacityLayer);
|
|
|
|
}
|
|
|
|
if (hasTransform) {
|
|
|
|
frame->MarkLayersActive(nsChangeHint_UpdateTransformLayer);
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
/*****************************************************************************
|
|
|
|
* nsTransitionManager *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
// reparent :before and :after pseudo elements of aElement
|
|
|
|
static void ReparentBeforeAndAfter(dom::Element* aElement,
|
|
|
|
nsIFrame* aPrimaryFrame,
|
|
|
|
nsStyleContext* aNewStyle,
|
|
|
|
nsStyleSet* aStyleSet)
|
|
|
|
{
|
|
|
|
if (nsIFrame* before = nsLayoutUtils::GetBeforeFrame(aPrimaryFrame)) {
|
|
|
|
nsRefPtr<nsStyleContext> beforeStyle =
|
2013-02-15 21:38:33 -08:00
|
|
|
aStyleSet->ReparentStyleContext(before->StyleContext(),
|
2012-12-11 13:12:43 -08:00
|
|
|
aNewStyle, aElement);
|
2013-07-30 17:36:08 -07:00
|
|
|
before->SetStyleContext(beforeStyle);
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
|
|
|
if (nsIFrame* after = nsLayoutUtils::GetBeforeFrame(aPrimaryFrame)) {
|
|
|
|
nsRefPtr<nsStyleContext> afterStyle =
|
2013-02-15 21:38:33 -08:00
|
|
|
aStyleSet->ReparentStyleContext(after->StyleContext(),
|
2012-12-11 13:12:43 -08:00
|
|
|
aNewStyle, aElement);
|
2013-07-30 17:36:08 -07:00
|
|
|
after->SetStyleContext(afterStyle);
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the next repaint rebuilds the layer tree for aFrame. That
|
|
|
|
// means that changes to animations on aFrame's layer are propagated to
|
|
|
|
// the compositor, which is needed for correct behaviour of new
|
|
|
|
// transitions.
|
|
|
|
static void
|
|
|
|
ForceLayerRerendering(nsIFrame* aFrame, CommonElementAnimationData* aData)
|
|
|
|
{
|
|
|
|
if (aData->HasAnimationOfProperty(eCSSProperty_opacity)) {
|
|
|
|
if (Layer* layer = FrameLayerBuilder::GetDedicatedLayer(
|
|
|
|
aFrame, nsDisplayItem::TYPE_OPACITY)) {
|
|
|
|
layer->RemoveUserData(nsIFrame::LayerIsPrerenderedDataKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData->HasAnimationOfProperty(eCSSProperty_transform)) {
|
|
|
|
if (Layer* layer = FrameLayerBuilder::GetDedicatedLayer(
|
|
|
|
aFrame, nsDisplayItem::TYPE_TRANSFORM)) {
|
|
|
|
layer->RemoveUserData(nsIFrame::LayerIsPrerenderedDataKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleContext*
|
|
|
|
nsTransitionManager::UpdateThrottledStyle(dom::Element* aElement,
|
2013-01-08 20:37:29 -08:00
|
|
|
nsStyleContext* aParentStyle,
|
|
|
|
nsStyleChangeList& aChangeList)
|
2012-12-11 13:12:43 -08:00
|
|
|
{
|
|
|
|
NS_ASSERTION(GetElementTransitions(aElement,
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
|
|
|
false), "element not transitioning");
|
|
|
|
|
2013-06-24 22:32:10 -07:00
|
|
|
nsIFrame* primaryFrame = nsLayoutUtils::GetStyleFrame(aElement);
|
2012-12-11 13:12:43 -08:00
|
|
|
if (!primaryFrame) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-02-15 21:38:33 -08:00
|
|
|
nsStyleContext* oldStyle = primaryFrame->StyleContext();
|
2013-02-16 13:04:53 -08:00
|
|
|
nsRuleNode* ruleNode = oldStyle->RuleNode();
|
2012-12-11 13:12:43 -08:00
|
|
|
nsTArray<nsStyleSet::RuleAndLevel> rules;
|
|
|
|
do {
|
|
|
|
if (ruleNode->IsRoot()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-26 14:42:34 -08:00
|
|
|
nsStyleSet::RuleAndLevel curRule;
|
|
|
|
curRule.mLevel = ruleNode->GetLevel();
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2012-12-26 14:42:34 -08:00
|
|
|
if (curRule.mLevel == nsStyleSet::eAnimationSheet) {
|
2012-12-11 13:12:43 -08:00
|
|
|
ElementAnimations* ea =
|
|
|
|
mPresContext->AnimationManager()->GetElementAnimations(aElement,
|
|
|
|
oldStyle->GetPseudoType(),
|
|
|
|
false);
|
|
|
|
NS_ASSERTION(ea, "Rule has level eAnimationSheet without animation on manager");
|
|
|
|
|
|
|
|
mPresContext->AnimationManager()->EnsureStyleRuleFor(ea);
|
2012-12-26 14:42:34 -08:00
|
|
|
curRule.mRule = ea->mStyleRule;
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2013-01-08 20:37:29 -08:00
|
|
|
// FIXME: maybe not needed anymore:
|
2012-12-11 13:12:43 -08:00
|
|
|
ForceLayerRerendering(primaryFrame, ea);
|
2012-12-26 14:42:34 -08:00
|
|
|
} else if (curRule.mLevel == nsStyleSet::eTransitionSheet) {
|
2012-12-11 13:12:43 -08:00
|
|
|
ElementTransitions *et =
|
|
|
|
GetElementTransitions(aElement, oldStyle->GetPseudoType(), false);
|
|
|
|
NS_ASSERTION(et, "Rule has level eTransitionSheet without transition on manager");
|
|
|
|
|
|
|
|
et->EnsureStyleRuleFor(mPresContext->RefreshDriver()->MostRecentRefresh());
|
2012-12-26 14:42:34 -08:00
|
|
|
curRule.mRule = et->mStyleRule;
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2013-01-08 20:37:29 -08:00
|
|
|
// FIXME: maybe not needed anymore:
|
2012-12-11 13:12:43 -08:00
|
|
|
ForceLayerRerendering(primaryFrame, et);
|
|
|
|
} else {
|
2012-12-26 14:42:34 -08:00
|
|
|
curRule.mRule = ruleNode->GetRule();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curRule.mRule) {
|
|
|
|
rules.AppendElement(curRule);
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
2012-12-12 11:32:29 -08:00
|
|
|
} while ((ruleNode = ruleNode->GetParent()));
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> newStyle = mPresContext->PresShell()->StyleSet()->
|
|
|
|
ResolveStyleForRules(aParentStyle, oldStyle, rules);
|
2013-01-08 20:37:29 -08:00
|
|
|
|
|
|
|
// We absolutely must call CalcStyleDifference in order to ensure the
|
|
|
|
// new context has all the structs cached that the old context had.
|
|
|
|
// We also need it for processing of the changes.
|
|
|
|
nsChangeHint styleChange =
|
|
|
|
oldStyle->CalcStyleDifference(newStyle, nsChangeHint(0));
|
|
|
|
aChangeList.AppendChange(primaryFrame, primaryFrame->GetContent(),
|
|
|
|
styleChange);
|
|
|
|
|
2013-07-30 17:36:08 -07:00
|
|
|
primaryFrame->SetStyleContext(newStyle);
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
ReparentBeforeAndAfter(aElement, primaryFrame, newStyle, mPresContext->PresShell()->StyleSet());
|
|
|
|
|
|
|
|
return newStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::UpdateThrottledStylesForSubtree(nsIContent* aContent,
|
2013-01-08 20:37:29 -08:00
|
|
|
nsStyleContext* aParentStyle,
|
|
|
|
nsStyleChangeList& aChangeList)
|
2012-12-11 13:12:43 -08:00
|
|
|
{
|
|
|
|
dom::Element* element;
|
|
|
|
if (aContent->IsElement()) {
|
|
|
|
element = aContent->AsElement();
|
|
|
|
} else {
|
|
|
|
element = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsStyleContext> newStyle;
|
|
|
|
|
|
|
|
ElementTransitions* et;
|
|
|
|
if (element &&
|
|
|
|
(et = GetElementTransitions(element,
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
|
|
|
false))) {
|
|
|
|
// re-resolve our style
|
2013-01-08 20:37:29 -08:00
|
|
|
newStyle = UpdateThrottledStyle(element, aParentStyle, aChangeList);
|
2012-12-11 13:12:43 -08:00
|
|
|
// remove the current transition from the working set
|
|
|
|
et->mFlushGeneration = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
} else {
|
|
|
|
// reparent the element's style
|
|
|
|
nsStyleSet* styleSet = mPresContext->PresShell()->StyleSet();
|
2013-06-24 22:32:10 -07:00
|
|
|
nsIFrame* primaryFrame = nsLayoutUtils::GetStyleFrame(aContent);
|
2012-12-11 13:12:43 -08:00
|
|
|
if (!primaryFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-15 21:38:33 -08:00
|
|
|
newStyle = styleSet->ReparentStyleContext(primaryFrame->StyleContext(),
|
2012-12-11 13:12:43 -08:00
|
|
|
aParentStyle, element);
|
2013-07-30 17:36:08 -07:00
|
|
|
primaryFrame->SetStyleContext(newStyle);
|
2012-12-11 13:12:43 -08:00
|
|
|
ReparentBeforeAndAfter(element, primaryFrame, newStyle, styleSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk the children
|
|
|
|
if (newStyle) {
|
2012-12-12 11:32:29 -08:00
|
|
|
for (nsIContent *child = aContent->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
2013-01-08 20:37:29 -08:00
|
|
|
UpdateThrottledStylesForSubtree(child, newStyle, aChangeList);
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::UpdateAllThrottledStyles()
|
|
|
|
{
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
// no throttled transitions, leave early
|
|
|
|
mPresContext->TickLastUpdateThrottledStyle();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPresContext->ThrottledStyleIsUpToDate()) {
|
|
|
|
// throttled transitions are up to date, leave early
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPresContext->TickLastUpdateThrottledStyle();
|
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
2013-01-08 20:37:29 -08:00
|
|
|
nsStyleChangeList changeList;
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
// update each transitioning element by finding its root-most ancestor with a
|
|
|
|
// transition, and flushing the style on that ancestor and all its descendants
|
|
|
|
PRCList *next = PR_LIST_HEAD(&mElementData);
|
|
|
|
while (next != &mElementData) {
|
|
|
|
ElementTransitions* et = static_cast<ElementTransitions*>(next);
|
|
|
|
next = PR_NEXT_LINK(next);
|
|
|
|
|
|
|
|
if (et->mFlushGeneration == now) {
|
|
|
|
// this element has been ticked already
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// element is initialised to the starting element (i.e., one we know has
|
|
|
|
// a transition) and ends up with the root-most transitioning ancestor,
|
|
|
|
// that is, the element where we begin updates.
|
|
|
|
dom::Element* element = et->mElement;
|
|
|
|
// make a list of ancestors
|
|
|
|
nsTArray<dom::Element*> ancestors;
|
|
|
|
do {
|
|
|
|
ancestors.AppendElement(element);
|
2013-01-11 00:43:01 -08:00
|
|
|
} while ((element = element->GetParentElement()));
|
2012-12-11 13:12:43 -08:00
|
|
|
|
|
|
|
// walk down the ancestors until we find one with a throttled transition
|
|
|
|
for (int32_t i = ancestors.Length() - 1; i >= 0; --i) {
|
|
|
|
if (GetElementTransitions(ancestors[i],
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement,
|
|
|
|
false)) {
|
|
|
|
element = ancestors[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* primaryFrame;
|
|
|
|
if (element &&
|
2013-06-24 22:32:10 -07:00
|
|
|
(primaryFrame = nsLayoutUtils::GetStyleFrame(element))) {
|
2012-12-11 13:12:43 -08:00
|
|
|
UpdateThrottledStylesForSubtree(element,
|
2013-02-15 21:38:33 -08:00
|
|
|
primaryFrame->StyleContext()->GetParent(), changeList);
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
|
|
|
}
|
2013-01-08 20:37:29 -08:00
|
|
|
|
2013-07-20 12:14:25 -07:00
|
|
|
RestyleManager* restyleManager = mPresContext->RestyleManager();
|
|
|
|
restyleManager->ProcessRestyledFrames(changeList);
|
|
|
|
restyleManager->FlushOverflowChangedTracker();
|
2012-12-11 13:12:43 -08:00
|
|
|
}
|
|
|
|
|
2013-06-25 01:58:46 -07:00
|
|
|
void
|
|
|
|
nsTransitionManager::ElementDataRemoved()
|
|
|
|
{
|
|
|
|
// If we have no transitions or animations left, remove ourselves from
|
|
|
|
// the refresh driver.
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::AddElementData(CommonElementAnimationData* aData)
|
|
|
|
{
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
// We need to observe the refresh driver.
|
|
|
|
nsRefreshDriver *rd = mPresContext->RefreshDriver();
|
|
|
|
rd->AddRefreshObserver(this, Flush_Style);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_INSERT_BEFORE(aData, &mElementData);
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
already_AddRefed<nsIStyleRule>
|
2010-05-14 10:04:51 -07:00
|
|
|
nsTransitionManager::StyleContextChanged(dom::Element *aElement,
|
2009-10-07 20:22:42 -07:00
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsStyleContext *aNewStyleContext)
|
|
|
|
{
|
2009-10-29 14:17:56 -07:00
|
|
|
NS_PRECONDITION(aOldStyleContext->GetPseudo() ==
|
|
|
|
aNewStyleContext->GetPseudo(),
|
2009-10-07 20:22:42 -07:00
|
|
|
"pseudo type mismatch");
|
2010-04-01 23:07:43 -07:00
|
|
|
// If we were called from ReparentStyleContext, this assertion would
|
2009-10-07 20:22:42 -07:00
|
|
|
// actually fire. If we need to be called from there, we can probably
|
|
|
|
// just remove it; the condition probably isn't critical, although
|
|
|
|
// it's worth thinking about some more.
|
|
|
|
NS_PRECONDITION(aOldStyleContext->HasPseudoElementData() ==
|
|
|
|
aNewStyleContext->HasPseudoElementData(),
|
|
|
|
"pseudo type mismatch");
|
|
|
|
|
2013-05-28 23:36:39 -07:00
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore transitions.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2009-12-11 08:13:19 -08:00
|
|
|
// NOTE: Things in this function (and ConsiderStartingTransition)
|
|
|
|
// should never call PeekStyleData because we don't preserve gotten
|
|
|
|
// structs across reframes.
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
// Return sooner (before the startedAny check below) for the most
|
2009-12-21 13:46:25 -08:00
|
|
|
// common case: no transitions specified or running.
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleDisplay *disp = aNewStyleContext->StyleDisplay();
|
2009-12-21 13:46:25 -08:00
|
|
|
nsCSSPseudoElements::Type pseudoType = aNewStyleContext->GetPseudoType();
|
2010-06-30 18:54:29 -07:00
|
|
|
if (pseudoType != nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
if (pseudoType != nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
pseudoType != nsCSSPseudoElements::ePseudo_after) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-30 18:54:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION((pseudoType == nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
aElement->Tag() == nsGkAtoms::mozgeneratedcontentbefore) ||
|
|
|
|
(pseudoType == nsCSSPseudoElements::ePseudo_after &&
|
|
|
|
aElement->Tag() == nsGkAtoms::mozgeneratedcontentafter),
|
|
|
|
"Unexpected aElement coming through");
|
|
|
|
|
|
|
|
// Else the element we want to use from now on is the element the
|
|
|
|
// :before or :after is attached to.
|
|
|
|
aElement = aElement->GetParent()->AsElement();
|
|
|
|
}
|
|
|
|
|
2009-12-21 13:46:25 -08:00
|
|
|
ElementTransitions *et =
|
2011-10-17 07:59:28 -07:00
|
|
|
GetElementTransitions(aElement, pseudoType, false);
|
2009-12-21 13:46:25 -08:00
|
|
|
if (!et &&
|
|
|
|
disp->mTransitionPropertyCount == 1 &&
|
2009-10-07 20:22:42 -07:00
|
|
|
disp->mTransitions[0].GetDelay() == 0.0f &&
|
2009-12-21 13:46:25 -08:00
|
|
|
disp->mTransitions[0].GetDuration() == 0.0f) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
2012-07-30 11:36:12 -07:00
|
|
|
|
2012-07-25 08:37:04 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
if (aNewStyleContext->PresContext()->IsProcessingAnimationStyleChange()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
if (aNewStyleContext->GetParent() &&
|
|
|
|
aNewStyleContext->GetParent()->HasPseudoElementData()) {
|
|
|
|
// Ignore transitions on things that inherit properties from
|
|
|
|
// pseudo-elements.
|
2009-10-15 17:23:19 -07:00
|
|
|
// FIXME (Bug 522599): Add tests for this.
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
2013-05-22 03:31:03 -07:00
|
|
|
NS_WARN_IF_FALSE(!nsLayoutUtils::AreAsyncAnimationsEnabled() ||
|
2012-12-11 13:12:43 -08:00
|
|
|
mPresContext->ThrottledStyleIsUpToDate(),
|
|
|
|
"throttled animations not up to date");
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
// Per http://lists.w3.org/Archives/Public/www-style/2009Aug/0109.html
|
|
|
|
// I'll consider only the transitions from the number of items in
|
|
|
|
// 'transition-property' on down, and later ones will override earlier
|
|
|
|
// ones (tracked using |whichStarted|).
|
2011-09-28 23:19:26 -07:00
|
|
|
bool startedAny = false;
|
2009-10-07 20:22:42 -07:00
|
|
|
nsCSSPropertySet whichStarted;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
|
2009-10-07 20:22:42 -07:00
|
|
|
const nsTransition& t = disp->mTransitions[i];
|
|
|
|
// Check delay and duration first, since they default to zero, and
|
|
|
|
// when they're both zero, we can ignore the transition.
|
|
|
|
if (t.GetDelay() != 0.0f || t.GetDuration() != 0.0f) {
|
|
|
|
// We might have something to transition. See if any of the
|
|
|
|
// properties in question changed and are animatable.
|
2009-12-11 08:13:19 -08:00
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one below.
|
2009-10-07 20:22:42 -07:00
|
|
|
nsCSSProperty property = t.GetProperty();
|
|
|
|
if (property == eCSSPropertyExtra_no_properties ||
|
|
|
|
property == eCSSProperty_UNKNOWN) {
|
|
|
|
// Nothing to do, but need to exclude this from cases below.
|
|
|
|
} else if (property == eCSSPropertyExtra_all_properties) {
|
2012-07-31 10:28:21 -07:00
|
|
|
for (nsCSSProperty p = nsCSSProperty(0);
|
2009-10-07 20:22:42 -07:00
|
|
|
p < eCSSProperty_COUNT_no_shorthands;
|
|
|
|
p = nsCSSProperty(p + 1)) {
|
|
|
|
ConsiderStartingTransition(p, t, aElement, et,
|
|
|
|
aOldStyleContext, aNewStyleContext,
|
|
|
|
&startedAny, &whichStarted);
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::IsShorthand(property)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
|
|
|
|
ConsiderStartingTransition(*subprop, t, aElement, et,
|
|
|
|
aOldStyleContext, aNewStyleContext,
|
|
|
|
&startedAny, &whichStarted);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ConsiderStartingTransition(property, t, aElement, et,
|
|
|
|
aOldStyleContext, aNewStyleContext,
|
|
|
|
&startedAny, &whichStarted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 08:13:19 -08:00
|
|
|
// Stop any transitions for properties that are no longer in
|
|
|
|
// 'transition-property'.
|
2009-12-21 13:46:25 -08:00
|
|
|
// Also stop any transitions for properties that just changed (and are
|
|
|
|
// still in the set of properties to transition), but we didn't just
|
|
|
|
// start the transition because delay and duration are both zero.
|
|
|
|
if (et) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool checkProperties =
|
2009-12-21 13:46:25 -08:00
|
|
|
disp->mTransitions[0].GetProperty() != eCSSPropertyExtra_all_properties;
|
2009-12-11 08:13:19 -08:00
|
|
|
nsCSSPropertySet allTransitionProperties;
|
2009-12-21 13:46:25 -08:00
|
|
|
if (checkProperties) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
|
2009-12-21 13:46:25 -08:00
|
|
|
const nsTransition& t = disp->mTransitions[i];
|
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one above.
|
|
|
|
nsCSSProperty property = t.GetProperty();
|
|
|
|
if (property == eCSSPropertyExtra_no_properties ||
|
|
|
|
property == eCSSProperty_UNKNOWN) {
|
|
|
|
// Nothing to do, but need to exclude this from cases below.
|
|
|
|
} else if (property == eCSSPropertyExtra_all_properties) {
|
2012-07-31 10:28:21 -07:00
|
|
|
for (nsCSSProperty p = nsCSSProperty(0);
|
2009-12-21 13:46:25 -08:00
|
|
|
p < eCSSProperty_COUNT_no_shorthands;
|
|
|
|
p = nsCSSProperty(p + 1)) {
|
|
|
|
allTransitionProperties.AddProperty(p);
|
|
|
|
}
|
|
|
|
} else if (nsCSSProps::IsShorthand(property)) {
|
|
|
|
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
|
|
|
|
allTransitionProperties.AddProperty(*subprop);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
allTransitionProperties.AddProperty(property);
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<ElementPropertyTransition> &pts = et->mPropertyTransitions;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i = pts.Length();
|
2009-12-11 08:13:19 -08:00
|
|
|
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
|
2009-12-21 13:46:25 -08:00
|
|
|
nsStyleAnimation::Value currentValue;
|
2009-12-11 08:13:19 -08:00
|
|
|
do {
|
|
|
|
--i;
|
|
|
|
ElementPropertyTransition &pt = pts[i];
|
2009-12-21 13:46:25 -08:00
|
|
|
// properties no longer in 'transition-property'
|
|
|
|
if ((checkProperties &&
|
|
|
|
!allTransitionProperties.HasProperty(pt.mProperty)) ||
|
|
|
|
// properties whose computed values changed but delay and
|
|
|
|
// duration are both zero
|
2011-04-11 23:18:43 -07:00
|
|
|
!ExtractComputedValueForTransition(pt.mProperty, aNewStyleContext,
|
|
|
|
currentValue) ||
|
2009-12-21 13:46:25 -08:00
|
|
|
currentValue != pt.mEndValue) {
|
|
|
|
// stop the transition
|
2009-12-11 08:13:19 -08:00
|
|
|
pts.RemoveElementAt(i);
|
2012-12-11 13:12:43 -08:00
|
|
|
et->UpdateAnimationGeneration(mPresContext);
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
|
|
|
if (pts.IsEmpty()) {
|
|
|
|
et->Destroy();
|
2012-07-30 07:20:58 -07:00
|
|
|
et = nullptr;
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
if (!startedAny) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(et, "must have element transitions if we started "
|
|
|
|
"any transitions");
|
|
|
|
|
|
|
|
// In the CSS working group discussion (2009 Jul 15 telecon,
|
|
|
|
// http://www.w3.org/mid/4A5E1470.4030904@inkedblade.net ) of
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2009Jun/0121.html ,
|
|
|
|
// the working group decided that a transition property on an
|
|
|
|
// element should not cause any transitions if the property change
|
|
|
|
// is itself inheriting a value that is transitioning on an
|
|
|
|
// ancestor. So, to get the correct behavior, we continue the
|
|
|
|
// restyle that caused this transition using a "covering" rule that
|
|
|
|
// covers up any changes on which we started transitions, so that
|
|
|
|
// descendants don't start their own transitions. (In the case of
|
|
|
|
// negative transition delay, this covering rule produces different
|
|
|
|
// results than applying the transition rule immediately would).
|
|
|
|
// Our caller is responsible for restyling again using this covering
|
|
|
|
// rule.
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
nsRefPtr<css::AnimValuesStyleRule> coverRule = new css::AnimValuesStyleRule;
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
nsTArray<ElementPropertyTransition> &pts = et->mPropertyTransitions;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) {
|
2009-10-07 20:22:42 -07:00
|
|
|
ElementPropertyTransition &pt = pts[i];
|
|
|
|
if (whichStarted.HasProperty(pt.mProperty)) {
|
2010-07-28 16:43:53 -07:00
|
|
|
coverRule->AddValue(pt.mProperty, pt.mStartValue);
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-17 19:18:55 -07:00
|
|
|
et->mStyleRule = nullptr;
|
|
|
|
|
2010-07-28 16:43:53 -07:00
|
|
|
return coverRule.forget();
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::ConsiderStartingTransition(nsCSSProperty aProperty,
|
2012-12-11 13:12:43 -08:00
|
|
|
const nsTransition& aTransition,
|
|
|
|
dom::Element* aElement,
|
|
|
|
ElementTransitions*& aElementTransitions,
|
|
|
|
nsStyleContext* aOldStyleContext,
|
|
|
|
nsStyleContext* aNewStyleContext,
|
|
|
|
bool* aStartedAny,
|
|
|
|
nsCSSPropertySet* aWhichStarted)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
|
|
|
// IsShorthand itself will assert if aProperty is not a property.
|
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
2012-12-11 13:12:43 -08:00
|
|
|
NS_ASSERTION(!aElementTransitions ||
|
|
|
|
aElementTransitions->mElement == aElement, "Element mismatch");
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
if (aWhichStarted->HasProperty(aProperty)) {
|
|
|
|
// A later item in transition-property already started a
|
|
|
|
// transition for this property, so we ignore this one.
|
|
|
|
// See comment above and
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2009Aug/0109.html .
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementPropertyTransition pt;
|
2009-10-20 04:46:16 -07:00
|
|
|
nsStyleAnimation::Value dummyValue;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveValues =
|
2011-04-11 23:18:43 -07:00
|
|
|
ExtractComputedValueForTransition(aProperty, aOldStyleContext,
|
2012-12-11 13:12:43 -08:00
|
|
|
pt.mStartValue) &&
|
2011-04-11 23:18:43 -07:00
|
|
|
ExtractComputedValueForTransition(aProperty, aNewStyleContext,
|
2012-12-11 13:12:43 -08:00
|
|
|
pt.mEndValue);
|
2012-07-31 10:28:22 -07:00
|
|
|
|
|
|
|
bool haveChange = pt.mStartValue != pt.mEndValue;
|
2012-12-11 13:12:43 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldAnimate =
|
2011-01-14 19:57:53 -08:00
|
|
|
haveValues &&
|
2012-12-11 13:12:43 -08:00
|
|
|
haveChange &&
|
2009-10-07 20:22:42 -07:00
|
|
|
// Check that we can interpolate between these values
|
|
|
|
// (If this is ever a performance problem, we could add a
|
|
|
|
// CanInterpolate method, but it seems fine for now.)
|
2009-11-14 19:16:58 -08:00
|
|
|
nsStyleAnimation::Interpolate(aProperty, pt.mStartValue, pt.mEndValue,
|
|
|
|
0.5, dummyValue);
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2013-06-04 17:35:52 -07:00
|
|
|
bool haveCurrentTransition = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t currentIndex = nsTArray<ElementPropertyTransition>::NoIndex;
|
2013-06-04 17:35:52 -07:00
|
|
|
const ElementPropertyTransition *oldPT = nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
if (aElementTransitions) {
|
|
|
|
nsTArray<ElementPropertyTransition> &pts =
|
|
|
|
aElementTransitions->mPropertyTransitions;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) {
|
2009-10-07 20:22:42 -07:00
|
|
|
if (pts[i].mProperty == aProperty) {
|
2013-06-04 17:35:52 -07:00
|
|
|
haveCurrentTransition = true;
|
2009-10-07 20:22:42 -07:00
|
|
|
currentIndex = i;
|
2013-06-04 17:35:52 -07:00
|
|
|
oldPT = &aElementTransitions->mPropertyTransitions[currentIndex];
|
2009-10-07 20:22:42 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 17:35:52 -07:00
|
|
|
// If we got a style change that changed the value to the endpoint
|
|
|
|
// of the currently running transition, we don't want to interrupt
|
|
|
|
// its timing function.
|
|
|
|
// This needs to be before the !shouldAnimate && haveCurrentTransition
|
|
|
|
// case below because we might be close enough to the end of the
|
|
|
|
// transition that the current value rounds to the final value. In
|
|
|
|
// this case, we'll end up with shouldAnimate as false (because
|
|
|
|
// there's no value change), but we need to return early here rather
|
|
|
|
// than cancel the running transition because shouldAnimate is false!
|
|
|
|
if (haveCurrentTransition && haveValues && oldPT->mEndValue == pt.mEndValue) {
|
|
|
|
// WalkTransitionRule already called RestyleForAnimation.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
nsPresContext *presContext = aNewStyleContext->PresContext();
|
|
|
|
|
|
|
|
if (!shouldAnimate) {
|
2013-06-04 17:35:52 -07:00
|
|
|
if (haveCurrentTransition) {
|
2013-06-11 22:43:17 -07:00
|
|
|
// We're in the middle of a transition, and just got a non-transition
|
|
|
|
// style change to something that we can't animate. This might happen
|
|
|
|
// because we got a non-transition style change changing to the current
|
|
|
|
// in-progress value (which is particularly easy to cause when we're
|
|
|
|
// currently in the 'transition-delay'). It also might happen because we
|
|
|
|
// just got a style change to a value that can't be interpolated.
|
|
|
|
nsTArray<ElementPropertyTransition> &pts =
|
|
|
|
aElementTransitions->mPropertyTransitions;
|
2009-10-07 20:22:42 -07:00
|
|
|
pts.RemoveElementAt(currentIndex);
|
2012-12-11 13:12:43 -08:00
|
|
|
aElementTransitions->UpdateAnimationGeneration(mPresContext);
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
if (pts.IsEmpty()) {
|
|
|
|
aElementTransitions->Destroy();
|
|
|
|
// |aElementTransitions| is now a dangling pointer!
|
2012-07-30 07:20:58 -07:00
|
|
|
aElementTransitions = nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
2009-12-11 08:13:19 -08:00
|
|
|
// WalkTransitionRule already called RestyleForAnimation.
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-10 07:49:53 -08:00
|
|
|
TimeStamp mostRecentRefresh =
|
|
|
|
presContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
|
|
|
const nsTimingFunction &tf = aTransition.GetTimingFunction();
|
|
|
|
float delay = aTransition.GetDelay();
|
|
|
|
float duration = aTransition.GetDuration();
|
|
|
|
if (duration < 0.0) {
|
|
|
|
// The spec says a negative duration is treated as zero.
|
|
|
|
duration = 0.0;
|
|
|
|
}
|
|
|
|
pt.mStartForReversingTest = pt.mStartValue;
|
|
|
|
pt.mReversePortion = 1.0;
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2013-06-04 17:35:52 -07:00
|
|
|
// If the new transition reverses an existing one, we'll need to
|
|
|
|
// handle the timing differently.
|
2013-06-04 17:35:52 -07:00
|
|
|
if (haveCurrentTransition &&
|
|
|
|
!oldPT->IsRemovedSentinel() &&
|
|
|
|
oldPT->mStartForReversingTest == pt.mEndValue) {
|
|
|
|
// Compute the appropriate negative transition-delay such that right
|
|
|
|
// now we'd end up at the current position.
|
|
|
|
double valuePortion =
|
|
|
|
oldPT->ValuePortionFor(mostRecentRefresh) * oldPT->mReversePortion +
|
|
|
|
(1.0 - oldPT->mReversePortion);
|
|
|
|
// A timing function with negative y1 (or y2!) might make
|
|
|
|
// valuePortion negative. In this case, we still want to apply our
|
|
|
|
// reversing logic based on relative distances, not make duration
|
|
|
|
// negative.
|
|
|
|
if (valuePortion < 0.0) {
|
|
|
|
valuePortion = -valuePortion;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
2013-06-04 17:35:52 -07:00
|
|
|
// A timing function with y2 (or y1!) greater than one might
|
|
|
|
// advance past its terminal value. It's probably a good idea to
|
|
|
|
// clamp valuePortion to be at most one to preserve the invariant
|
|
|
|
// that a transition will complete within at most its specified
|
|
|
|
// time.
|
|
|
|
if (valuePortion > 1.0) {
|
|
|
|
valuePortion = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Negative delays are essentially part of the transition
|
|
|
|
// function, so reduce them along with the duration, but don't
|
|
|
|
// reduce positive delays.
|
|
|
|
if (delay < 0.0f) {
|
|
|
|
delay *= valuePortion;
|
|
|
|
}
|
|
|
|
|
|
|
|
duration *= valuePortion;
|
|
|
|
|
|
|
|
pt.mStartForReversingTest = oldPT->mEndValue;
|
|
|
|
pt.mReversePortion = valuePortion;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pt.mProperty = aProperty;
|
2010-11-10 07:49:53 -08:00
|
|
|
pt.mStartTime = mostRecentRefresh + TimeDuration::FromMilliseconds(delay);
|
2009-10-07 20:22:42 -07:00
|
|
|
pt.mDuration = TimeDuration::FromMilliseconds(duration);
|
2011-04-11 23:18:42 -07:00
|
|
|
pt.mTimingFunction.Init(tf);
|
2009-10-07 20:22:42 -07:00
|
|
|
if (!aElementTransitions) {
|
|
|
|
aElementTransitions =
|
2009-12-10 23:37:40 -08:00
|
|
|
GetElementTransitions(aElement, aNewStyleContext->GetPseudoType(),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2009-10-07 20:22:42 -07:00
|
|
|
if (!aElementTransitions) {
|
|
|
|
NS_WARNING("allocating ElementTransitions failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
nsTArray<ElementPropertyTransition> &pts =
|
|
|
|
aElementTransitions->mPropertyTransitions;
|
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) {
|
2009-10-07 20:22:42 -07:00
|
|
|
NS_ABORT_IF_FALSE(i == currentIndex ||
|
|
|
|
pts[i].mProperty != aProperty,
|
|
|
|
"duplicate transitions for property");
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-04 17:35:52 -07:00
|
|
|
if (haveCurrentTransition) {
|
2009-10-07 20:22:42 -07:00
|
|
|
pts[currentIndex] = pt;
|
|
|
|
} else {
|
|
|
|
if (!pts.AppendElement(pt)) {
|
|
|
|
NS_WARNING("out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
aElementTransitions->UpdateAnimationGeneration(mPresContext);
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2010-06-30 18:54:29 -07:00
|
|
|
nsRestyleHint hint =
|
|
|
|
aNewStyleContext->GetPseudoType() ==
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement ?
|
|
|
|
eRestyle_Self : eRestyle_Subtree;
|
|
|
|
presContext->PresShell()->RestyleForAnimation(aElement, hint);
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aStartedAny = true;
|
2009-10-07 20:22:42 -07:00
|
|
|
aWhichStarted->AddProperty(aProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementTransitions*
|
2010-05-14 10:04:51 -07:00
|
|
|
nsTransitionManager::GetElementTransitions(dom::Element *aElement,
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCreateIfNeeded)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
2011-04-11 23:18:43 -07:00
|
|
|
if (!aCreateIfNeeded && PR_CLIST_IS_EMPTY(&mElementData)) {
|
2009-12-21 13:46:25 -08:00
|
|
|
// Early return for the most common case.
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-12-21 13:46:25 -08:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
nsIAtom *propName;
|
2009-12-21 13:46:25 -08:00
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
propName = nsGkAtoms::transitionsProperty;
|
|
|
|
} else if (aPseudoType == nsCSSPseudoElements::ePseudo_before) {
|
2009-10-07 20:22:42 -07:00
|
|
|
propName = nsGkAtoms::transitionsOfBeforeProperty;
|
2009-12-10 23:37:40 -08:00
|
|
|
} else if (aPseudoType == nsCSSPseudoElements::ePseudo_after) {
|
2009-10-07 20:22:42 -07:00
|
|
|
propName = nsGkAtoms::transitionsOfAfterProperty;
|
|
|
|
} else {
|
2009-12-21 13:46:25 -08:00
|
|
|
NS_ASSERTION(!aCreateIfNeeded,
|
2009-10-07 20:22:42 -07:00
|
|
|
"should never try to create transitions for pseudo "
|
|
|
|
"other than :before or :after");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
ElementTransitions *et = static_cast<ElementTransitions*>(
|
|
|
|
aElement->GetProperty(propName));
|
|
|
|
if (!et && aCreateIfNeeded) {
|
|
|
|
// FIXME: Consider arena-allocating?
|
2012-12-11 13:12:43 -08:00
|
|
|
et = new ElementTransitions(aElement, propName, this,
|
|
|
|
mPresContext->RefreshDriver()->MostRecentRefresh());
|
2009-10-07 20:22:42 -07:00
|
|
|
nsresult rv = aElement->SetProperty(propName, et,
|
2012-10-09 16:14:42 -07:00
|
|
|
ElementTransitionsPropertyDtor, false);
|
2009-10-07 20:22:42 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("SetProperty failed");
|
|
|
|
delete et;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
if (propName == nsGkAtoms::transitionsProperty) {
|
|
|
|
aElement->SetMayHaveAnimations();
|
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
AddElementData(et);
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return et;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsIStyleRuleProcessor implementation
|
|
|
|
*/
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
void
|
2012-11-14 11:09:01 -08:00
|
|
|
nsTransitionManager::WalkTransitionRule(ElementDependentRuleProcessorData* aData,
|
2009-12-10 23:37:40 -08:00
|
|
|
nsCSSPseudoElements::Type aPseudoType)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
|
|
|
ElementTransitions *et =
|
2011-10-17 07:59:28 -07:00
|
|
|
GetElementTransitions(aData->mElement, aPseudoType, false);
|
2009-10-07 20:22:42 -07:00
|
|
|
if (!et) {
|
2010-07-18 14:20:40 -07:00
|
|
|
return;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
2013-05-28 23:36:39 -07:00
|
|
|
if (!mPresContext->IsDynamic()) {
|
|
|
|
// For print or print preview, ignore animations.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-30 18:54:29 -07:00
|
|
|
if (aData->mPresContext->IsProcessingRestyles() &&
|
|
|
|
!aData->mPresContext->IsProcessingAnimationStyleChange()) {
|
2009-12-11 08:13:19 -08:00
|
|
|
// If we're processing a normal style change rather than one from
|
|
|
|
// animation, don't add the transition rule. This allows us to
|
|
|
|
// compute the new style value rather than having the transition
|
|
|
|
// override it, so that we can start transitioning differently.
|
|
|
|
|
|
|
|
// We need to immediately restyle with animation
|
|
|
|
// after doing this.
|
2013-05-30 17:45:17 -07:00
|
|
|
nsRestyleHint hint =
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ?
|
|
|
|
eRestyle_Self : eRestyle_Subtree;
|
|
|
|
mPresContext->PresShell()->RestyleForAnimation(aData->mElement, hint);
|
2010-07-18 14:20:40 -07:00
|
|
|
return;
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
et->EnsureStyleRuleFor(
|
|
|
|
aData->mPresContext->RefreshDriver()->MostRecentRefresh());
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
aData->mRuleWalker->Forward(et->mStyleRule);
|
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-10-07 20:22:42 -07:00
|
|
|
nsTransitionManager::RulesMatching(ElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aData->mPresContext == mPresContext,
|
|
|
|
"pres context mismatch");
|
2010-07-18 14:20:40 -07:00
|
|
|
WalkTransitionRule(aData,
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsTransitionManager::RulesMatching(PseudoElementRuleProcessorData* aData)
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aData->mPresContext == mPresContext,
|
|
|
|
"pres context mismatch");
|
2009-12-10 23:37:40 -08:00
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
// Note: If we're the only thing keeping a pseudo-element frame alive
|
|
|
|
// (per ProbePseudoStyleContext), we still want to keep it alive, so
|
|
|
|
// this is ok.
|
2010-07-18 14:20:40 -07:00
|
|
|
WalkTransitionRule(aData, aData->mPseudoType);
|
2009-12-10 23:37:40 -08:00
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsTransitionManager::RulesMatching(AnonBoxRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-10 23:37:40 -08:00
|
|
|
nsTransitionManager::RulesMatching(XULTreeRuleProcessorData* aData)
|
2009-12-10 23:37:40 -08:00
|
|
|
{
|
2009-12-10 14:36:06 -08:00
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2009-12-10 14:36:06 -08:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsTransitionManager::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-08 21:01:52 -08:00
|
|
|
{
|
|
|
|
return CommonAnimationManager::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsTransitionManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2011-12-08 21:01:52 -08:00
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-08 21:01:52 -08:00
|
|
|
}
|
|
|
|
|
2009-12-23 11:10:31 -08:00
|
|
|
struct TransitionEventInfo {
|
|
|
|
nsCOMPtr<nsIContent> mElement;
|
2013-09-26 23:20:55 -07:00
|
|
|
InternalTransitionEvent mEvent;
|
2009-12-23 11:10:31 -08:00
|
|
|
|
|
|
|
TransitionEventInfo(nsIContent *aElement, nsCSSProperty aProperty,
|
2013-05-04 07:41:20 -07:00
|
|
|
TimeDuration aDuration, const nsAString& aPseudoElement)
|
2009-12-23 11:10:31 -08:00
|
|
|
: mElement(aElement),
|
2011-10-17 07:59:28 -07:00
|
|
|
mEvent(true, NS_TRANSITION_END,
|
2009-12-23 11:10:31 -08:00
|
|
|
NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aProperty)),
|
2013-05-04 07:41:20 -07:00
|
|
|
aDuration.ToSeconds(), aPseudoElement)
|
2009-12-23 11:10:31 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-26 23:20:55 -07:00
|
|
|
// InternalTransitionEvent doesn't support copy-construction, so we need
|
2009-12-23 11:10:31 -08:00
|
|
|
// to ourselves in order to work with nsTArray
|
|
|
|
TransitionEventInfo(const TransitionEventInfo &aOther)
|
|
|
|
: mElement(aOther.mElement),
|
2011-10-17 07:59:28 -07:00
|
|
|
mEvent(true, NS_TRANSITION_END,
|
2013-05-04 07:41:20 -07:00
|
|
|
aOther.mEvent.propertyName, aOther.mEvent.elapsedTime,
|
|
|
|
aOther.mEvent.pseudoElement)
|
2009-12-23 11:10:31 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
/* virtual */ void
|
|
|
|
nsTransitionManager::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
2009-12-23 11:10:31 -08:00
|
|
|
NS_ABORT_IF_FALSE(mPresContext,
|
|
|
|
"refresh driver should not notify additional observers "
|
|
|
|
"after pres context has been destroyed");
|
2010-09-15 12:40:11 -07:00
|
|
|
if (!mPresContext->GetPresShell()) {
|
|
|
|
// Someone might be keeping mPresContext alive past the point
|
|
|
|
// where it has been torn down; don't bother doing anything in
|
|
|
|
// this case. But do get rid of all our transitions so we stop
|
|
|
|
// triggering refreshes.
|
2011-04-11 23:18:43 -07:00
|
|
|
RemoveAllElementData();
|
2010-09-15 12:40:11 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-12-23 11:10:31 -08:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
FlushTransitions(Can_Throttle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::FlushTransitions(FlushFlags aFlags)
|
|
|
|
{
|
|
|
|
if (PR_CLIST_IS_EMPTY(&mElementData)) {
|
|
|
|
// no transitions, leave early
|
|
|
|
return;
|
|
|
|
}
|
2009-12-23 11:10:31 -08:00
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
nsTArray<TransitionEventInfo> events;
|
|
|
|
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
|
|
|
|
bool didThrottle = false;
|
2012-12-22 20:52:13 -08:00
|
|
|
// Trim transitions that have completed, post restyle events for frames that
|
|
|
|
// are still transitioning, and start transitions with delays.
|
2009-10-07 20:22:42 -07:00
|
|
|
{
|
2011-04-11 23:18:43 -07:00
|
|
|
PRCList *next = PR_LIST_HEAD(&mElementData);
|
|
|
|
while (next != &mElementData) {
|
2009-10-07 20:22:42 -07:00
|
|
|
ElementTransitions *et = static_cast<ElementTransitions*>(next);
|
|
|
|
next = PR_NEXT_LINK(next);
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
bool canThrottleTick = aFlags == Can_Throttle &&
|
|
|
|
et->CanPerformOnCompositorThread(
|
|
|
|
CommonElementAnimationData::CanAnimateFlags(0)) &&
|
|
|
|
et->CanThrottleAnimation(now);
|
|
|
|
|
2009-10-07 20:22:42 -07:00
|
|
|
NS_ABORT_IF_FALSE(et->mElement->GetCurrentDoc() ==
|
|
|
|
mPresContext->Document(),
|
2012-11-14 14:10:08 -08:00
|
|
|
"Element::UnbindFromTree should have "
|
2009-10-07 20:22:42 -07:00
|
|
|
"destroyed the element transitions object");
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i = et->mPropertyTransitions.Length();
|
2009-10-07 20:22:42 -07:00
|
|
|
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
|
2012-12-22 20:52:13 -08:00
|
|
|
bool transitionStartedOrEnded = false;
|
2009-10-07 20:22:42 -07:00
|
|
|
do {
|
|
|
|
--i;
|
|
|
|
ElementPropertyTransition &pt = et->mPropertyTransitions[i];
|
2010-01-12 08:51:37 -08:00
|
|
|
if (pt.IsRemovedSentinel()) {
|
2012-12-11 13:12:43 -08:00
|
|
|
// Actually remove transitions one throttle-able cycle after their
|
|
|
|
// completion. We only clear on a throttle-able cycle because that
|
|
|
|
// means it is a regular restyle tick and thus it is safe to discard
|
|
|
|
// the transition. If the flush is not throttle-able, we might still
|
|
|
|
// have new transitions left to process. See comment below.
|
|
|
|
if (aFlags == Can_Throttle) {
|
|
|
|
et->mPropertyTransitions.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
} else if (pt.mStartTime + pt.mDuration <= now) {
|
2013-05-04 07:41:20 -07:00
|
|
|
nsCSSProperty prop = pt.mProperty;
|
|
|
|
if (nsCSSProps::PropHasFlags(prop, CSS_PROPERTY_REPORT_OTHER_NAME))
|
|
|
|
{
|
|
|
|
prop = nsCSSProps::OtherNameFor(prop);
|
2009-12-23 11:10:31 -08:00
|
|
|
}
|
2013-05-04 07:41:20 -07:00
|
|
|
nsIAtom* ep = et->mElementProperty;
|
|
|
|
NS_NAMED_LITERAL_STRING(before, "::before");
|
|
|
|
NS_NAMED_LITERAL_STRING(after, "::after");
|
|
|
|
events.AppendElement(
|
|
|
|
TransitionEventInfo(et->mElement, prop, pt.mDuration,
|
|
|
|
ep == nsGkAtoms::transitionsProperty ?
|
|
|
|
EmptyString() :
|
|
|
|
ep == nsGkAtoms::transitionsOfBeforeProperty ?
|
|
|
|
before :
|
|
|
|
after));
|
2009-12-23 11:10:31 -08:00
|
|
|
|
2010-01-12 08:51:37 -08:00
|
|
|
// Leave this transition in the list for one more refresh
|
|
|
|
// cycle, since we haven't yet processed its style change, and
|
|
|
|
// if we also have (already, or will have from processing
|
|
|
|
// transitionend events or other refresh driver notifications)
|
|
|
|
// a non-animation style change that would affect it, we need
|
|
|
|
// to know not to start a new transition for the transition
|
|
|
|
// from the almost-completed value to the final value.
|
|
|
|
pt.SetRemovedSentinel();
|
2012-12-11 13:12:43 -08:00
|
|
|
et->UpdateAnimationGeneration(mPresContext);
|
2012-12-22 20:52:13 -08:00
|
|
|
transitionStartedOrEnded = true;
|
|
|
|
} else if (pt.mStartTime <= now && canThrottleTick &&
|
|
|
|
!pt.mIsRunningOnCompositor) {
|
|
|
|
// Start a transition with a delay where we should start the
|
|
|
|
// transition proper.
|
|
|
|
et->UpdateAnimationGeneration(mPresContext);
|
|
|
|
transitionStartedOrEnded = true;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
|
|
|
// We need to restyle even if the transition rule no longer
|
|
|
|
// applies (in which case we just made it not apply).
|
2010-06-30 18:54:29 -07:00
|
|
|
NS_ASSERTION(et->mElementProperty == nsGkAtoms::transitionsProperty ||
|
|
|
|
et->mElementProperty == nsGkAtoms::transitionsOfBeforeProperty ||
|
|
|
|
et->mElementProperty == nsGkAtoms::transitionsOfAfterProperty,
|
|
|
|
"Unexpected element property; might restyle too much");
|
2012-12-22 20:52:13 -08:00
|
|
|
if (!canThrottleTick || transitionStartedOrEnded) {
|
2012-12-11 13:12:43 -08:00
|
|
|
nsRestyleHint hint = et->mElementProperty == nsGkAtoms::transitionsProperty ?
|
|
|
|
eRestyle_Self : eRestyle_Subtree;
|
|
|
|
mPresContext->PresShell()->RestyleForAnimation(et->mElement, hint);
|
|
|
|
} else {
|
|
|
|
didThrottle = true;
|
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
|
|
|
|
if (et->mPropertyTransitions.IsEmpty()) {
|
|
|
|
et->Destroy();
|
|
|
|
// |et| is now a dangling pointer!
|
2012-07-30 07:20:58 -07:00
|
|
|
et = nullptr;
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-11 13:12:43 -08:00
|
|
|
if (didThrottle) {
|
|
|
|
mPresContext->Document()->SetNeedStyleFlush();
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = events.Length(); i < i_end; ++i) {
|
2009-12-23 11:10:31 -08:00
|
|
|
TransitionEventInfo &info = events[i];
|
|
|
|
nsEventDispatcher::Dispatch(info.mElement, mPresContext, &info.mEvent);
|
|
|
|
|
|
|
|
if (!mPresContext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-07 20:22:42 -07:00
|
|
|
}
|