2010-07-01 05:54:29 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2009-10-08 07:22:42 +04:00
|
|
|
/* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
|
2012-05-21 15:12:37 +04: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-08 07:22:42 +04:00
|
|
|
|
|
|
|
/* Code to start and animate CSS transitions. */
|
|
|
|
|
|
|
|
#include "nsTransitionManager.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsCSSProps.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
#include "nsRuleProcessorData.h"
|
|
|
|
#include "nsIStyleRule.h"
|
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsRuleData.h"
|
|
|
|
#include "gfxColor.h"
|
|
|
|
#include "nsCSSPropertySet.h"
|
|
|
|
#include "nsStyleAnimation.h"
|
2009-12-23 22:10:31 +03:00
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsGUIEvent.h"
|
2010-05-14 21:04:51 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
|
|
|
|
using mozilla::TimeStamp;
|
|
|
|
using mozilla::TimeDuration;
|
|
|
|
|
2010-05-14 21:04:51 +04:00
|
|
|
namespace dom = mozilla::dom;
|
2011-04-12 10:18:43 +04:00
|
|
|
namespace css = mozilla::css;
|
2010-05-14 21:04:51 +04:00
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
ElementTransitions::ElementTransitions(mozilla::dom::Element *aElement, nsIAtom *aElementProperty,
|
|
|
|
nsTransitionManager *aTransitionManager)
|
|
|
|
: CommonElementAnimationData(aElement, aElementProperty,
|
|
|
|
aTransitionManager)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2012-07-30 22:36:12 +04:00
|
|
|
|
2010-11-10 18:49:53 +03: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;
|
|
|
|
if (duration == 0.0) {
|
|
|
|
// 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 18:10:54 +03:00
|
|
|
} else {
|
|
|
|
timePortion = 0.0;
|
2010-11-10 18:49:53 +03: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-12 10:18:42 +04:00
|
|
|
return mTimingFunction.GetValue(timePortion);
|
2010-11-10 18:49:53 +03:00
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
static void
|
|
|
|
ElementTransitionsPropertyDtor(void *aObject,
|
|
|
|
nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue,
|
|
|
|
void *aData)
|
|
|
|
{
|
|
|
|
ElementTransitions *et = static_cast<ElementTransitions*>(aPropertyValue);
|
2011-05-01 02:16:19 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ABORT_IF_FALSE(!et->mCalledPropertyDtor, "can't call dtor twice");
|
|
|
|
et->mCalledPropertyDtor = true;
|
|
|
|
#endif
|
2009-10-08 07:22:42 +04:00
|
|
|
delete et;
|
|
|
|
}
|
|
|
|
|
2010-07-29 03:43:53 +04:00
|
|
|
void
|
|
|
|
ElementTransitions::EnsureStyleRuleFor(TimeStamp aRefreshTime)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
2010-07-29 03:43:53 +04:00
|
|
|
if (!mStyleRule || mStyleRuleRefreshTime != aRefreshTime) {
|
2011-04-12 10:18:43 +04:00
|
|
|
mStyleRule = new css::AnimValuesStyleRule();
|
2010-07-29 03:43:53 +04:00
|
|
|
mStyleRuleRefreshTime = aRefreshTime;
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyTransitions.Length(); i < i_end; ++i)
|
2010-07-29 03:43:53 +04:00
|
|
|
{
|
|
|
|
ElementPropertyTransition &pt = mPropertyTransitions[i];
|
|
|
|
if (pt.IsRemovedSentinel()) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-20 06:28:00 +04:00
|
|
|
|
2010-07-29 03:43:53 +04:00
|
|
|
nsStyleAnimation::Value *val = mStyleRule->AddEmptyValue(pt.mProperty);
|
2010-01-12 19:51:37 +03:00
|
|
|
|
2010-11-10 18:49:53 +03:00
|
|
|
double valuePortion = pt.ValuePortionFor(aRefreshTime);
|
2009-10-08 07:22:42 +04:00
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ok =
|
2009-10-08 07:22:42 +04:00
|
|
|
#endif
|
2009-11-15 06:16:58 +03:00
|
|
|
nsStyleAnimation::Interpolate(pt.mProperty,
|
|
|
|
pt.mStartValue, pt.mEndValue,
|
2010-07-29 03:43:53 +04:00
|
|
|
valuePortion, *val);
|
2009-10-08 07:22:42 +04:00
|
|
|
NS_ABORT_IF_FALSE(ok, "could not interpolate values");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 21:28:22 +04:00
|
|
|
bool
|
2012-08-22 05:48:47 +04:00
|
|
|
ElementPropertyTransition::IsRunningAt(TimeStamp aTime) const {
|
|
|
|
return !IsRemovedSentinel() && mStartTime < aTime && aTime < mStartTime + mDuration;
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ElementTransitions::HasTransitionOfProperty(nsCSSProperty aProperty) const
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t tranIdx = mPropertyTransitions.Length(); tranIdx-- != 0; ) {
|
2012-07-31 21:28:22 +04:00
|
|
|
if (aProperty == mPropertyTransitions[tranIdx].mProperty) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ElementTransitions::CanPerformOnCompositorThread() const
|
|
|
|
{
|
2012-08-26 05:27:28 +04:00
|
|
|
nsIFrame* frame = mElement->GetPrimaryFrame();
|
|
|
|
if (!frame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
if (mElementProperty != nsGkAtoms::transitionsProperty) {
|
2012-08-24 23:08:18 +04:00
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled()) {
|
2012-08-26 05:27:28 +04:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Gecko bug: Async transition of pseudoelements not supported. See bug 771367");
|
|
|
|
LogAsyncAnimationFailure(message, mElement);
|
2012-08-24 23:08:18 +04:00
|
|
|
}
|
2012-08-22 05:48:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-26 05:27:28 +04:00
|
|
|
|
2012-08-22 05:48:47 +04:00
|
|
|
TimeStamp now = frame->PresContext()->RefreshDriver()->MostRecentRefresh();
|
|
|
|
|
2012-08-25 18:52:30 +04:00
|
|
|
bool hasGeometricProperty = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyTransitions.Length(); i < i_end; ++i) {
|
2012-08-22 05:48:47 +04:00
|
|
|
const ElementPropertyTransition& pt = mPropertyTransitions[i];
|
|
|
|
if (css::IsGeometricProperty(pt.mProperty) && pt.IsRunningAt(now)) {
|
|
|
|
hasGeometricProperty = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-25 18:52:30 +04:00
|
|
|
bool hasOpacity = false;
|
|
|
|
bool hasTransform = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mPropertyTransitions.Length(); i < i_end; ++i) {
|
2012-08-22 05:48:47 +04:00
|
|
|
const ElementPropertyTransition& pt = mPropertyTransitions[i];
|
2012-07-31 21:28:22 +04:00
|
|
|
if (pt.IsRemovedSentinel()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!css::CommonElementAnimationData::CanAnimatePropertyOnCompositor(mElement,
|
2012-08-22 05:48:47 +04:00
|
|
|
pt.mProperty,
|
|
|
|
hasGeometricProperty)) {
|
2012-07-31 21:28:22 +04:00
|
|
|
return false;
|
|
|
|
}
|
2012-08-25 18:52:30 +04:00
|
|
|
if (pt.mProperty == eCSSProperty_opacity) {
|
|
|
|
hasOpacity = true;
|
|
|
|
} else if (pt.mProperty == eCSSProperty_transform) {
|
|
|
|
hasTransform = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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 21:28:22 +04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
/*****************************************************************************
|
|
|
|
* nsTransitionManager *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
already_AddRefed<nsIStyleRule>
|
2010-05-14 21:04:51 +04:00
|
|
|
nsTransitionManager::StyleContextChanged(dom::Element *aElement,
|
2009-10-08 07:22:42 +04:00
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsStyleContext *aNewStyleContext)
|
|
|
|
{
|
2009-10-30 00:17:56 +03:00
|
|
|
NS_PRECONDITION(aOldStyleContext->GetPseudo() ==
|
|
|
|
aNewStyleContext->GetPseudo(),
|
2009-10-08 07:22:42 +04:00
|
|
|
"pseudo type mismatch");
|
2010-04-02 10:07:43 +04:00
|
|
|
// If we were called from ReparentStyleContext, this assertion would
|
2009-10-08 07:22:42 +04: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");
|
|
|
|
|
2009-12-11 19:13:19 +03:00
|
|
|
// NOTE: Things in this function (and ConsiderStartingTransition)
|
|
|
|
// should never call PeekStyleData because we don't preserve gotten
|
|
|
|
// structs across reframes.
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
// Return sooner (before the startedAny check below) for the most
|
2009-12-22 00:46:25 +03:00
|
|
|
// common case: no transitions specified or running.
|
2009-10-08 07:22:42 +04:00
|
|
|
const nsStyleDisplay *disp = aNewStyleContext->GetStyleDisplay();
|
2009-12-22 00:46:25 +03:00
|
|
|
nsCSSPseudoElements::Type pseudoType = aNewStyleContext->GetPseudoType();
|
2010-07-01 05:54:29 +04:00
|
|
|
if (pseudoType != nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
if (pseudoType != nsCSSPseudoElements::ePseudo_before &&
|
|
|
|
pseudoType != nsCSSPseudoElements::ePseudo_after) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-07-01 05:54:29 +04: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-22 00:46:25 +03:00
|
|
|
ElementTransitions *et =
|
2011-10-17 18:59:28 +04:00
|
|
|
GetElementTransitions(aElement, pseudoType, false);
|
2009-12-22 00:46:25 +03:00
|
|
|
if (!et &&
|
|
|
|
disp->mTransitionPropertyCount == 1 &&
|
2009-10-08 07:22:42 +04:00
|
|
|
disp->mTransitions[0].GetDelay() == 0.0f &&
|
2009-12-22 00:46:25 +03:00
|
|
|
disp->mTransitions[0].GetDuration() == 0.0f) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2012-07-30 22:36:12 +04:00
|
|
|
|
2012-07-25 19:37:04 +04:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
if (aNewStyleContext->PresContext()->IsProcessingAnimationStyleChange()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
if (aNewStyleContext->GetParent() &&
|
|
|
|
aNewStyleContext->GetParent()->HasPseudoElementData()) {
|
|
|
|
// Ignore transitions on things that inherit properties from
|
|
|
|
// pseudo-elements.
|
2009-10-16 04:23:19 +04:00
|
|
|
// FIXME (Bug 522599): Add tests for this.
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-08 07:22:42 +04: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-29 10:19:26 +04:00
|
|
|
bool startedAny = false;
|
2009-10-08 07:22:42 +04:00
|
|
|
nsCSSPropertySet whichStarted;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
|
2009-10-08 07:22:42 +04: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 19:13:19 +03:00
|
|
|
// FIXME: Would be good to find a way to share code between this
|
|
|
|
// interpretation of transition-property and the one below.
|
2009-10-08 07:22:42 +04: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 21:28:21 +04:00
|
|
|
for (nsCSSProperty p = nsCSSProperty(0);
|
2009-10-08 07:22:42 +04: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 19:13:19 +03:00
|
|
|
// Stop any transitions for properties that are no longer in
|
|
|
|
// 'transition-property'.
|
2009-12-22 00:46:25 +03: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-29 10:19:26 +04:00
|
|
|
bool checkProperties =
|
2009-12-22 00:46:25 +03:00
|
|
|
disp->mTransitions[0].GetProperty() != eCSSPropertyExtra_all_properties;
|
2009-12-11 19:13:19 +03:00
|
|
|
nsCSSPropertySet allTransitionProperties;
|
2009-12-22 00:46:25 +03:00
|
|
|
if (checkProperties) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = disp->mTransitionPropertyCount; i-- != 0; ) {
|
2009-12-22 00:46:25 +03: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 21:28:21 +04:00
|
|
|
for (nsCSSProperty p = nsCSSProperty(0);
|
2009-12-22 00:46:25 +03: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 19:13:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<ElementPropertyTransition> &pts = et->mPropertyTransitions;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i = pts.Length();
|
2009-12-11 19:13:19 +03:00
|
|
|
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
|
2009-12-22 00:46:25 +03:00
|
|
|
nsStyleAnimation::Value currentValue;
|
2009-12-11 19:13:19 +03:00
|
|
|
do {
|
|
|
|
--i;
|
|
|
|
ElementPropertyTransition &pt = pts[i];
|
2009-12-22 00:46:25 +03: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-12 10:18:43 +04:00
|
|
|
!ExtractComputedValueForTransition(pt.mProperty, aNewStyleContext,
|
|
|
|
currentValue) ||
|
2009-12-22 00:46:25 +03:00
|
|
|
currentValue != pt.mEndValue) {
|
|
|
|
// stop the transition
|
2009-12-11 19:13:19 +03:00
|
|
|
pts.RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
} while (i != 0);
|
|
|
|
|
|
|
|
if (pts.IsEmpty()) {
|
|
|
|
et->Destroy();
|
2012-07-30 18:20:58 +04:00
|
|
|
et = nullptr;
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!startedAny) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-08 07:22:42 +04: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-12 10:18:43 +04:00
|
|
|
nsRefPtr<css::AnimValuesStyleRule> coverRule = new css::AnimValuesStyleRule;
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
nsTArray<ElementPropertyTransition> &pts = et->mPropertyTransitions;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) {
|
2009-10-08 07:22:42 +04:00
|
|
|
ElementPropertyTransition &pt = pts[i];
|
|
|
|
if (whichStarted.HasProperty(pt.mProperty)) {
|
2010-07-29 03:43:53 +04:00
|
|
|
coverRule->AddValue(pt.mProperty, pt.mStartValue);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-29 03:43:53 +04:00
|
|
|
return coverRule.forget();
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTransitionManager::ConsiderStartingTransition(nsCSSProperty aProperty,
|
|
|
|
const nsTransition& aTransition,
|
2010-05-14 21:04:51 +04:00
|
|
|
dom::Element *aElement,
|
2009-10-08 07:22:42 +04:00
|
|
|
ElementTransitions *&aElementTransitions,
|
|
|
|
nsStyleContext *aOldStyleContext,
|
|
|
|
nsStyleContext *aNewStyleContext,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aStartedAny,
|
2009-10-08 07:22:42 +04:00
|
|
|
nsCSSPropertySet *aWhichStarted)
|
|
|
|
{
|
|
|
|
// IsShorthand itself will assert if aProperty is not a property.
|
|
|
|
NS_ABORT_IF_FALSE(!nsCSSProps::IsShorthand(aProperty),
|
|
|
|
"property out of range");
|
|
|
|
|
|
|
|
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 15:46:16 +04:00
|
|
|
nsStyleAnimation::Value dummyValue;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveValues =
|
2011-04-12 10:18:43 +04:00
|
|
|
ExtractComputedValueForTransition(aProperty, aOldStyleContext,
|
|
|
|
pt.mStartValue) &&
|
|
|
|
ExtractComputedValueForTransition(aProperty, aNewStyleContext,
|
|
|
|
pt.mEndValue);
|
2012-07-31 21:28:22 +04:00
|
|
|
|
|
|
|
bool haveChange = pt.mStartValue != pt.mEndValue;
|
|
|
|
bool haveOMTA = false;
|
|
|
|
if (!aNewStyleContext->GetPseudoType()) {
|
|
|
|
ElementTransitions* et = nsTransitionManager::GetTransitions(aElement);
|
|
|
|
if (et) {
|
|
|
|
haveOMTA = et->CanPerformOnCompositorThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool shouldAnimate =
|
2011-01-15 06:57:53 +03:00
|
|
|
haveValues &&
|
2012-07-31 21:28:22 +04:00
|
|
|
(haveChange || haveOMTA) &&
|
2009-10-08 07:22:42 +04: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-15 06:16:58 +03:00
|
|
|
nsStyleAnimation::Interpolate(aProperty, pt.mStartValue, pt.mEndValue,
|
|
|
|
0.5, dummyValue);
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t currentIndex = nsTArray<ElementPropertyTransition>::NoIndex;
|
2009-10-08 07:22:42 +04:00
|
|
|
if (aElementTransitions) {
|
|
|
|
nsTArray<ElementPropertyTransition> &pts =
|
|
|
|
aElementTransitions->mPropertyTransitions;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) {
|
2009-10-08 07:22:42 +04:00
|
|
|
if (pts[i].mProperty == aProperty) {
|
|
|
|
currentIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext *presContext = aNewStyleContext->PresContext();
|
|
|
|
|
|
|
|
if (!shouldAnimate) {
|
2011-01-15 06:57:53 +03:00
|
|
|
nsTArray<ElementPropertyTransition> &pts =
|
|
|
|
aElementTransitions->mPropertyTransitions;
|
|
|
|
if (currentIndex != nsTArray<ElementPropertyTransition>::NoIndex &&
|
|
|
|
(!haveValues || pts[currentIndex].mEndValue != pt.mEndValue)) {
|
2009-10-08 07:22:42 +04:00
|
|
|
// We're in the middle of a transition, but just got a
|
|
|
|
// non-transition style change changing to exactly the
|
|
|
|
// current in-progress value. (This is quite easy to cause
|
|
|
|
// using 'transition-delay'.)
|
2011-01-15 06:57:53 +03:00
|
|
|
//
|
|
|
|
// We also check that this current in-progress value is different
|
|
|
|
// from the end value; we don't want to cancel a transition that
|
|
|
|
// is almost done (and whose current value rounds to its end
|
|
|
|
// value) just because we got an unrelated style change.
|
2009-10-08 07:22:42 +04:00
|
|
|
pts.RemoveElementAt(currentIndex);
|
|
|
|
if (pts.IsEmpty()) {
|
|
|
|
aElementTransitions->Destroy();
|
|
|
|
// |aElementTransitions| is now a dangling pointer!
|
2012-07-30 18:20:58 +04:00
|
|
|
aElementTransitions = nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2009-12-11 19:13:19 +03:00
|
|
|
// WalkTransitionRule already called RestyleForAnimation.
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-10 18:49:53 +03: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-08 07:22:42 +04:00
|
|
|
|
|
|
|
// We need to check two things if we have a currently running
|
2010-11-10 18:49:53 +03:00
|
|
|
// transition for this property.
|
2009-10-08 07:22:42 +04:00
|
|
|
if (currentIndex != nsTArray<ElementPropertyTransition>::NoIndex) {
|
2010-01-12 19:51:37 +03:00
|
|
|
const ElementPropertyTransition &oldPT =
|
|
|
|
aElementTransitions->mPropertyTransitions[currentIndex];
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2010-01-12 19:51:37 +03:00
|
|
|
if (oldPT.mEndValue == pt.mEndValue) {
|
2009-10-08 07:22:42 +04: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.
|
2009-12-11 19:13:19 +03:00
|
|
|
// WalkTransitionRule already called RestyleForAnimation.
|
2009-10-08 07:22:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-10 18:49:53 +03:00
|
|
|
// If the new transition reverses the old one, we'll need to handle
|
|
|
|
// the timing differently.
|
2010-01-12 19:51:37 +03:00
|
|
|
if (!oldPT.IsRemovedSentinel() &&
|
2010-11-10 18:49:53 +03:00
|
|
|
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 +
|
2012-07-31 21:28:21 +04:00
|
|
|
(1.0 - oldPT.mReversePortion);
|
For transition reversing computations, ensure valuePortion is within 0.0-1.0. (Bug 611238) r=bzbarsky a=blocking2.0:final
Without the change to ensure that valuePortion is nonnegative, duration
might become negative, which it's not allowed to be. Without this
change, this can happen when a transition starts off moving into
negative value space, which happens when y1 in the timing function is
negative. The result that we want should come from using the absolute
value (rather than clamping to zero): if we reverse the transition when
it's in this negative space, we want the same movement we'd get if it
were the same distance into positive value space, just in the opposite
direction.
Additionally, I'm clamping valuePortion to be at most 1. This affects
"bouncy" transitions where the timing function's y2 is greater than
one. This is less critical, but ensures the invariant that a transition
will never take longer than its specified time, which seems like a good
thing to ensure.
I believe doing this computation at this stage is preferable to doing it
before the multiplication by oldPT.mReversePortion, since we should be
clamping the value within the range of the complete transition, not just
relative to the most recent reverse.
2010-12-16 19:53:17 +03:00
|
|
|
// 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;
|
|
|
|
// 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;
|
2010-11-10 18:49:53 +03:00
|
|
|
|
|
|
|
// 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;
|
2012-07-31 21:28:22 +04:00
|
|
|
|
2010-11-10 18:49:53 +03:00
|
|
|
duration *= valuePortion;
|
|
|
|
|
|
|
|
pt.mStartForReversingTest = oldPT.mEndValue;
|
|
|
|
pt.mReversePortion = valuePortion;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pt.mProperty = aProperty;
|
2010-11-10 18:49:53 +03:00
|
|
|
pt.mStartTime = mostRecentRefresh + TimeDuration::FromMilliseconds(delay);
|
2009-10-08 07:22:42 +04:00
|
|
|
pt.mDuration = TimeDuration::FromMilliseconds(duration);
|
2011-04-12 10:18:42 +04:00
|
|
|
pt.mTimingFunction.Init(tf);
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!aElementTransitions) {
|
|
|
|
aElementTransitions =
|
2009-12-11 10:37:40 +03:00
|
|
|
GetElementTransitions(aElement, aNewStyleContext->GetPseudoType(),
|
2011-10-17 18:59:28 +04:00
|
|
|
true);
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!aElementTransitions) {
|
|
|
|
NS_WARNING("allocating ElementTransitions failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
nsTArray<ElementPropertyTransition> &pts =
|
|
|
|
aElementTransitions->mPropertyTransitions;
|
|
|
|
#ifdef DEBUG
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) {
|
2009-10-08 07:22:42 +04:00
|
|
|
NS_ABORT_IF_FALSE(i == currentIndex ||
|
|
|
|
pts[i].mProperty != aProperty,
|
|
|
|
"duplicate transitions for property");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (currentIndex != nsTArray<ElementPropertyTransition>::NoIndex) {
|
|
|
|
pts[currentIndex] = pt;
|
|
|
|
} else {
|
|
|
|
if (!pts.AppendElement(pt)) {
|
|
|
|
NS_WARNING("out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 05:54:29 +04:00
|
|
|
nsRestyleHint hint =
|
|
|
|
aNewStyleContext->GetPseudoType() ==
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement ?
|
|
|
|
eRestyle_Self : eRestyle_Subtree;
|
|
|
|
presContext->PresShell()->RestyleForAnimation(aElement, hint);
|
2012-07-31 21:28:22 +04:00
|
|
|
// XXXdz: invalidate the frame here, once animations are throttled.
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aStartedAny = true;
|
2009-10-08 07:22:42 +04:00
|
|
|
aWhichStarted->AddProperty(aProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
ElementTransitions*
|
2010-05-14 21:04:51 +04:00
|
|
|
nsTransitionManager::GetElementTransitions(dom::Element *aElement,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aPseudoType,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCreateIfNeeded)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
2011-04-12 10:18:43 +04:00
|
|
|
if (!aCreateIfNeeded && PR_CLIST_IS_EMPTY(&mElementData)) {
|
2009-12-22 00:46:25 +03:00
|
|
|
// Early return for the most common case.
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-22 00:46:25 +03:00
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
nsIAtom *propName;
|
2009-12-22 00:46:25 +03:00
|
|
|
if (aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement) {
|
|
|
|
propName = nsGkAtoms::transitionsProperty;
|
|
|
|
} else if (aPseudoType == nsCSSPseudoElements::ePseudo_before) {
|
2009-10-08 07:22:42 +04:00
|
|
|
propName = nsGkAtoms::transitionsOfBeforeProperty;
|
2009-12-11 10:37:40 +03:00
|
|
|
} else if (aPseudoType == nsCSSPseudoElements::ePseudo_after) {
|
2009-10-08 07:22:42 +04:00
|
|
|
propName = nsGkAtoms::transitionsOfAfterProperty;
|
|
|
|
} else {
|
2009-12-22 00:46:25 +03:00
|
|
|
NS_ASSERTION(!aCreateIfNeeded,
|
2009-10-08 07:22:42 +04:00
|
|
|
"should never try to create transitions for pseudo "
|
|
|
|
"other than :before or :after");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
ElementTransitions *et = static_cast<ElementTransitions*>(
|
|
|
|
aElement->GetProperty(propName));
|
|
|
|
if (!et && aCreateIfNeeded) {
|
|
|
|
// FIXME: Consider arena-allocating?
|
|
|
|
et = new ElementTransitions(aElement, propName, this);
|
|
|
|
nsresult rv = aElement->SetProperty(propName, et,
|
2012-07-30 18:20:58 +04:00
|
|
|
ElementTransitionsPropertyDtor, nullptr);
|
2009-10-08 07:22:42 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("SetProperty failed");
|
|
|
|
delete et;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2012-07-31 21:28:22 +04:00
|
|
|
if (propName == nsGkAtoms::transitionsProperty) {
|
|
|
|
aElement->SetMayHaveAnimations();
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
AddElementData(et);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return et;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsIStyleRuleProcessor implementation
|
|
|
|
*/
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
void
|
2009-10-08 07:22:42 +04:00
|
|
|
nsTransitionManager::WalkTransitionRule(RuleProcessorData* aData,
|
2009-12-11 10:37:40 +03:00
|
|
|
nsCSSPseudoElements::Type aPseudoType)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
|
|
|
ElementTransitions *et =
|
2011-10-17 18:59:28 +04:00
|
|
|
GetElementTransitions(aData->mElement, aPseudoType, false);
|
2009-10-08 07:22:42 +04:00
|
|
|
if (!et) {
|
2010-07-19 01:20:40 +04:00
|
|
|
return;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2010-07-01 05:54:29 +04:00
|
|
|
if (aData->mPresContext->IsProcessingRestyles() &&
|
|
|
|
!aData->mPresContext->IsProcessingAnimationStyleChange()) {
|
2009-12-11 19:13:19 +03: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.
|
|
|
|
if (et) {
|
2010-07-01 05:54:29 +04:00
|
|
|
nsRestyleHint hint =
|
|
|
|
aPseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement ?
|
|
|
|
eRestyle_Self : eRestyle_Subtree;
|
|
|
|
mPresContext->PresShell()->RestyleForAnimation(aData->mElement, hint);
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
2010-07-19 01:20:40 +04:00
|
|
|
return;
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
et->EnsureStyleRuleFor(
|
|
|
|
aData->mPresContext->RefreshDriver()->MostRecentRefresh());
|
2009-10-08 07:22:42 +04:00
|
|
|
|
|
|
|
aData->mRuleWalker->Forward(et->mStyleRule);
|
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-10-08 07:22:42 +04:00
|
|
|
nsTransitionManager::RulesMatching(ElementRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aData->mPresContext == mPresContext,
|
|
|
|
"pres context mismatch");
|
2010-07-19 01:20:40 +04:00
|
|
|
WalkTransitionRule(aData,
|
|
|
|
nsCSSPseudoElements::ePseudo_NotPseudoElement);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsTransitionManager::RulesMatching(PseudoElementRuleProcessorData* aData)
|
2009-10-08 07:22:42 +04:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aData->mPresContext == mPresContext,
|
|
|
|
"pres context mismatch");
|
2009-12-11 10:37:40 +03:00
|
|
|
|
2009-10-08 07:22:42 +04: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-19 01:20:40 +04:00
|
|
|
WalkTransitionRule(aData, aData->mPseudoType);
|
2009-12-11 10:37:40 +03:00
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsTransitionManager::RulesMatching(AnonBoxRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-11 10:37:40 +03:00
|
|
|
nsTransitionManager::RulesMatching(XULTreeRuleProcessorData* aData)
|
2009-12-11 10:37:40 +03:00
|
|
|
{
|
2009-12-11 01:36:06 +03:00
|
|
|
}
|
2009-12-11 10:37:40 +03:00
|
|
|
#endif
|
2009-12-11 01:36:06 +03:00
|
|
|
|
2011-12-09 09:01:52 +04:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsTransitionManager::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return CommonAnimationManager::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
nsTransitionManager::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-09 09:01:52 +04:00
|
|
|
}
|
|
|
|
|
2009-12-23 22:10:31 +03:00
|
|
|
struct TransitionEventInfo {
|
|
|
|
nsCOMPtr<nsIContent> mElement;
|
|
|
|
nsTransitionEvent mEvent;
|
|
|
|
|
|
|
|
TransitionEventInfo(nsIContent *aElement, nsCSSProperty aProperty,
|
|
|
|
TimeDuration aDuration)
|
|
|
|
: mElement(aElement),
|
2011-10-17 18:59:28 +04:00
|
|
|
mEvent(true, NS_TRANSITION_END,
|
2009-12-23 22:10:31 +03:00
|
|
|
NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aProperty)),
|
|
|
|
aDuration.ToSeconds())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsTransitionEvent doesn't support copy-construction, so we need
|
|
|
|
// to ourselves in order to work with nsTArray
|
|
|
|
TransitionEventInfo(const TransitionEventInfo &aOther)
|
|
|
|
: mElement(aOther.mElement),
|
2011-10-17 18:59:28 +04:00
|
|
|
mEvent(true, NS_TRANSITION_END,
|
2009-12-23 22:10:31 +03:00
|
|
|
aOther.mEvent.propertyName, aOther.mEvent.elapsedTime)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
/* virtual */ void
|
|
|
|
nsTransitionManager::WillRefresh(mozilla::TimeStamp aTime)
|
|
|
|
{
|
2009-12-23 22:10:31 +03:00
|
|
|
NS_ABORT_IF_FALSE(mPresContext,
|
|
|
|
"refresh driver should not notify additional observers "
|
|
|
|
"after pres context has been destroyed");
|
2010-09-15 23:40:11 +04: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-12 10:18:43 +04:00
|
|
|
RemoveAllElementData();
|
2010-09-15 23:40:11 +04:00
|
|
|
return;
|
|
|
|
}
|
2009-12-23 22:10:31 +03:00
|
|
|
|
2009-12-23 22:10:31 +03:00
|
|
|
nsTArray<TransitionEventInfo> events;
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
// Trim transitions that have completed, and post restyle events for
|
|
|
|
// frames that are still transitioning.
|
|
|
|
{
|
2011-04-12 10:18:43 +04:00
|
|
|
PRCList *next = PR_LIST_HEAD(&mElementData);
|
|
|
|
while (next != &mElementData) {
|
2009-10-08 07:22:42 +04:00
|
|
|
ElementTransitions *et = static_cast<ElementTransitions*>(next);
|
|
|
|
next = PR_NEXT_LINK(next);
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(et->mElement->GetCurrentDoc() ==
|
|
|
|
mPresContext->Document(),
|
|
|
|
"nsGenericElement::UnbindFromTree should have "
|
|
|
|
"destroyed the element transitions object");
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i = et->mPropertyTransitions.Length();
|
2009-10-08 07:22:42 +04:00
|
|
|
NS_ABORT_IF_FALSE(i != 0, "empty transitions list?");
|
|
|
|
do {
|
|
|
|
--i;
|
|
|
|
ElementPropertyTransition &pt = et->mPropertyTransitions[i];
|
2010-01-12 19:51:37 +03:00
|
|
|
if (pt.IsRemovedSentinel()) {
|
|
|
|
// Actually remove transitions one cycle after their
|
|
|
|
// completion. See comment below.
|
|
|
|
et->mPropertyTransitions.RemoveElementAt(i);
|
|
|
|
} else if (pt.mStartTime + pt.mDuration <= aTime) {
|
2010-07-03 08:18:55 +04:00
|
|
|
// Fire transitionend events only for transitions on elements
|
|
|
|
// and not those on pseudo-elements, since we can't target an
|
|
|
|
// event at pseudo-elements.
|
|
|
|
if (et->mElementProperty == nsGkAtoms::transitionsProperty) {
|
|
|
|
nsCSSProperty prop = pt.mProperty;
|
|
|
|
if (nsCSSProps::PropHasFlags(prop, CSS_PROPERTY_REPORT_OTHER_NAME))
|
|
|
|
{
|
|
|
|
prop = nsCSSProps::OtherNameFor(prop);
|
|
|
|
}
|
|
|
|
events.AppendElement(
|
|
|
|
TransitionEventInfo(et->mElement, prop, pt.mDuration));
|
2009-12-23 22:10:31 +03:00
|
|
|
}
|
|
|
|
|
2010-01-12 19:51:37 +03: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();
|
2009-10-08 07:22:42 +04: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-07-01 05:54:29 +04:00
|
|
|
NS_ASSERTION(et->mElementProperty == nsGkAtoms::transitionsProperty ||
|
|
|
|
et->mElementProperty == nsGkAtoms::transitionsOfBeforeProperty ||
|
|
|
|
et->mElementProperty == nsGkAtoms::transitionsOfAfterProperty,
|
|
|
|
"Unexpected element property; might restyle too much");
|
|
|
|
nsRestyleHint hint = et->mElementProperty == nsGkAtoms::transitionsProperty ?
|
|
|
|
eRestyle_Self : eRestyle_Subtree;
|
|
|
|
mPresContext->PresShell()->RestyleForAnimation(et->mElement, hint);
|
2012-07-31 21:28:22 +04:00
|
|
|
// XXXdz: if we have started a transition since the last tick and are
|
|
|
|
// performing the transition off the main thread, we need to invalidate
|
|
|
|
// the frame once we start throttling animation ticks.
|
2009-10-08 07:22:42 +04:00
|
|
|
|
|
|
|
if (et->mPropertyTransitions.IsEmpty()) {
|
|
|
|
et->Destroy();
|
|
|
|
// |et| is now a dangling pointer!
|
2012-07-30 18:20:58 +04:00
|
|
|
et = nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We might have removed transitions above.
|
2011-04-12 10:18:43 +04:00
|
|
|
ElementDataRemoved();
|
2009-12-23 22:10:31 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = events.Length(); i < i_end; ++i) {
|
2009-12-23 22:10:31 +03:00
|
|
|
TransitionEventInfo &info = events[i];
|
|
|
|
nsEventDispatcher::Dispatch(info.mElement, mPresContext, &info.mEvent);
|
|
|
|
|
|
|
|
if (!mPresContext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|