Bug 1166500 - Part 1: Store change hints between from and to for each animation segment. r=dbaron

BuildSegmentsFromValueEntries now needs base nsStyleContext to calculate
the change hints.
If the change hint is not set correctly, we will check it in
CanIgnoreIfNotVisible() introduced in a subsequent patch (part 3).
This commit is contained in:
Hiroyuki Ikezoe 2016-05-24 12:57:42 +09:00
Родитель 617fa803bb
Коммит ad26dd6ea3
2 изменённых файлов: 54 добавлений и 3 удалений

Просмотреть файл

@ -8,6 +8,7 @@
#define mozilla_dom_KeyframeEffect_h
#include "nsAutoPtr.h"
#include "nsChangeHint.h"
#include "nsCSSProperty.h"
#include "nsCSSValue.h"
#include "nsCycleCollectionParticipant.h"
@ -118,6 +119,8 @@ struct AnimationPropertySegment
StyleAnimationValue mFromValue, mToValue;
Maybe<ComputedTimingFunction> mTimingFunction;
nsChangeHint mChangeHint;
bool operator==(const AnimationPropertySegment& aOther) const {
return mFromKey == aOther.mFromKey &&
mToKey == aOther.mToKey &&

Просмотреть файл

@ -373,7 +373,8 @@ static bool
HasValidOffsets(const nsTArray<Keyframe>& aKeyframes);
static void
BuildSegmentsFromValueEntries(nsTArray<KeyframeValueEntry>& aEntries,
BuildSegmentsFromValueEntries(nsStyleContext* aStyleContext,
nsTArray<KeyframeValueEntry>& aEntries,
nsTArray<AnimationProperty>& aResult);
static void
@ -550,7 +551,7 @@ KeyframeUtils::GetAnimationPropertiesFromKeyframes(
}
nsTArray<AnimationProperty> result;
BuildSegmentsFromValueEntries(entries, result);
BuildSegmentsFromValueEntries(aStyleContext, entries, result);
return result;
}
@ -908,12 +909,43 @@ HasValidOffsets(const nsTArray<Keyframe>& aKeyframes)
return true;
}
static already_AddRefed<nsStyleContext>
CreateStyleContextForAnimationValue(nsCSSProperty aProperty,
StyleAnimationValue aValue,
nsStyleContext* aBaseStyleContext)
{
MOZ_ASSERT(aBaseStyleContext,
"CreateStyleContextForAnimationValue needs to be called "
"with a valid nsStyleContext");
RefPtr<AnimValuesStyleRule> styleRule = new AnimValuesStyleRule();
styleRule->AddValue(aProperty, aValue);
nsCOMArray<nsIStyleRule> rules;
rules.AppendObject(styleRule);
MOZ_ASSERT(aBaseStyleContext->PresContext()->StyleSet()->IsGecko(),
"ServoStyleSet should not use StyleAnimationValue for animations");
nsStyleSet* styleSet =
aBaseStyleContext->PresContext()->StyleSet()->AsGecko();
RefPtr<nsStyleContext> styleContext =
styleSet->ResolveStyleByAddingRules(aBaseStyleContext, rules);
// We need to call StyleData to generate cached data for the style context.
// Otherwise CalcStyleDifference returns no meaningful result.
styleContext->StyleData(nsCSSProps::kSIDTable[aProperty]);
return styleContext.forget();
}
/**
* Builds an array of AnimationProperty objects to represent the keyframe
* animation segments in aEntries.
*/
static void
BuildSegmentsFromValueEntries(nsTArray<KeyframeValueEntry>& aEntries,
BuildSegmentsFromValueEntries(nsStyleContext* aStyleContext,
nsTArray<KeyframeValueEntry>& aEntries,
nsTArray<AnimationProperty>& aResult)
{
if (aEntries.IsEmpty()) {
@ -1004,6 +1036,22 @@ BuildSegmentsFromValueEntries(nsTArray<KeyframeValueEntry>& aEntries,
segment->mToValue = aEntries[j].mValue;
segment->mTimingFunction = aEntries[i].mTimingFunction;
RefPtr<nsStyleContext> fromContext =
CreateStyleContextForAnimationValue(animationProperty->mProperty,
segment->mFromValue, aStyleContext);
RefPtr<nsStyleContext> toContext =
CreateStyleContextForAnimationValue(animationProperty->mProperty,
segment->mToValue, aStyleContext);
uint32_t equalStructs = 0;
uint32_t samePointerStructs = 0;
segment->mChangeHint =
fromContext->CalcStyleDifference(toContext,
nsChangeHint(0),
&equalStructs,
&samePointerStructs);
i = j;
}
}