Bug 1174575 - Part 5: Support pseudo-element type in StyleAnimation. r=birtles

Add one more argument, nsCSSPseudoElement::Type, for
StyleAnimation::ComputeValue and StyleAnimation::ComputeValues
This commit is contained in:
Boris Chiou 2016-02-09 05:04:00 +01:00
parent 5ccf150f8b
commit e472e5cc4b
5 changed files with 75 additions and 36 deletions

View File

@ -1197,12 +1197,14 @@ GenerateValueEntries(Element* aTarget,
// Parse the property's string value and produce a KeyframeValueEntry (or
// more than one, for shorthands) for it.
nsTArray<PropertyStyleAnimationValuePair> values;
if (StyleAnimationValue::ComputeValues(pair.mProperty,
nsCSSProps::eEnabledForAllContent,
aTarget,
pair.mValues[0],
/* aUseSVGMode */ false,
values)) {
if (StyleAnimationValue::ComputeValues(
pair.mProperty,
nsCSSProps::eEnabledForAllContent,
aTarget,
nsCSSPseudoElements::ePseudo_NotPseudoElement,
pair.mValues[0],
/* aUseSVGMode */ false,
values)) {
for (auto& value : values) {
// If we already got a value for this property on the keyframe,
// skip this one.
@ -1477,12 +1479,14 @@ BuildAnimationPropertyListFromPropertyIndexedKeyframes(
// value instead.
nsTArray<PropertyStyleAnimationValuePair> fromValues;
float fromKey = 0.0f;
if (!StyleAnimationValue::ComputeValues(pair.mProperty,
nsCSSProps::eEnabledForAllContent,
aTarget,
pair.mValues[0],
/* aUseSVGMode */ false,
fromValues)) {
if (!StyleAnimationValue::ComputeValues(
pair.mProperty,
nsCSSProps::eEnabledForAllContent,
aTarget,
nsCSSPseudoElements::ePseudo_NotPseudoElement,
pair.mValues[0],
/* aUseSVGMode */ false,
fromValues)) {
// We need to throw for an invalid first value, since that would imply an
// additive animation, which we don't support yet.
aRv.Throw(NS_ERROR_DOM_ANIM_MISSING_PROPS_ERR);
@ -1529,12 +1533,14 @@ BuildAnimationPropertyListFromPropertyIndexedKeyframes(
for (size_t i = 0; i < count - 1; ++i) {
nsTArray<PropertyStyleAnimationValuePair> toValues;
float toKey = (i + 1) * portion;
if (!StyleAnimationValue::ComputeValues(pair.mProperty,
nsCSSProps::eEnabledForAllContent,
aTarget,
pair.mValues[i + 1],
/* aUseSVGMode */ false,
toValues)) {
if (!StyleAnimationValue::ComputeValues(
pair.mProperty,
nsCSSProps::eEnabledForAllContent,
aTarget,
nsCSSPseudoElements::ePseudo_NotPseudoElement,
pair.mValues[i + 1],
/* aUseSVGMode */ false,
toValues)) {
if (i + 1 == count - 1) {
// We need to throw for an invalid last value, since that would
// imply an additive animation, which we don't support yet.

View File

@ -2247,8 +2247,13 @@ ComputeAnimationValue(nsCSSProperty aProperty,
StyleAnimationValue& aOutput)
{
if (!StyleAnimationValue::ComputeValue(aProperty, aElement, aInput,
false, aOutput)) {
if (!StyleAnimationValue::ComputeValue(
aProperty,
aElement,
nsCSSPseudoElements::ePseudo_NotPseudoElement,
aInput,
false,
aOutput)) {
return false;
}

View File

@ -360,9 +360,14 @@ ValueFromStringHelper(nsCSSProperty aPropID,
}
}
nsDependentSubstring subString(aString, subStringBegin);
if (!StyleAnimationValue::ComputeValue(aPropID, aTargetElement, subString,
true, aStyleAnimValue,
aIsContextSensitive)) {
if (!StyleAnimationValue::ComputeValue(
aPropID,
aTargetElement,
nsCSSPseudoElements::ePseudo_NotPseudoElement,
subString,
true,
aStyleAnimValue,
aIsContextSensitive)) {
return false;
}
if (isNegative) {

View File

@ -2525,19 +2525,25 @@ BuildStyleRule(nsCSSProperty aProperty,
inline
already_AddRefed<nsStyleContext>
LookupStyleContext(dom::Element* aElement)
LookupStyleContext(dom::Element* aElement,
nsCSSPseudoElements::Type aPseudoType)
{
nsIDocument* doc = aElement->GetCurrentDoc();
nsIPresShell* shell = doc->GetShell();
if (!shell) {
return nullptr;
}
return nsComputedDOMStyle::GetStyleContextForElement(aElement, nullptr, shell);
nsIAtom* pseudo =
aPseudoType < nsCSSPseudoElements::ePseudo_PseudoElementCount ?
nsCSSPseudoElements::GetPseudoAtom(aPseudoType) : nullptr;
return nsComputedDOMStyle::GetStyleContextForElement(aElement, pseudo, shell);
}
/* static */ bool
StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
dom::Element* aTargetElement,
nsCSSPseudoElements::Type aPseudoType,
const nsAString& aSpecifiedValue,
bool aUseSVGMode,
StyleAnimationValue& aComputedValue,
@ -2549,6 +2555,9 @@ StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
"are in a document");
// Parse specified value into a temporary css::StyleRule
// Note: BuildStyleRule needs an element's OwnerDoc, BaseURI, and Principal.
// If it is a pseudo element, use its parent element's OwnerDoc, BaseURI,
// and Principal.
RefPtr<css::StyleRule> styleRule =
BuildStyleRule(aProperty, aTargetElement, aSpecifiedValue, aUseSVGMode);
if (!styleRule) {
@ -2569,7 +2578,7 @@ StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
AutoTArray<PropertyStyleAnimationValuePair,1> values;
bool ok = ComputeValues(aProperty, nsCSSProps::eIgnoreEnabledState,
aTargetElement, styleRule, values,
aTargetElement, aPseudoType, styleRule, values,
aIsContextSensitive);
if (!ok) {
return false;
@ -2586,6 +2595,7 @@ StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
StyleAnimationValue::ComputeValues(nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState,
dom::Element* aTargetElement,
nsCSSPseudoElements::Type aPseudoType,
const nsAString& aSpecifiedValue,
bool aUseSVGMode,
nsTArray<PropertyStyleAnimationValuePair>& aResult)
@ -2596,6 +2606,9 @@ StyleAnimationValue::ComputeValues(nsCSSProperty aProperty,
"are in a document");
// Parse specified value into a temporary css::StyleRule
// Note: BuildStyleRule needs an element's OwnerDoc, BaseURI, and Principal.
// If it is a pseudo element, use its parent element's OwnerDoc, BaseURI,
// and Principal.
RefPtr<css::StyleRule> styleRule =
BuildStyleRule(aProperty, aTargetElement, aSpecifiedValue, aUseSVGMode);
if (!styleRule) {
@ -2603,8 +2616,8 @@ StyleAnimationValue::ComputeValues(nsCSSProperty aProperty,
}
aResult.Clear();
return ComputeValues(aProperty, aEnabledState, aTargetElement, styleRule,
aResult, /* aIsContextSensitive */ nullptr);
return ComputeValues(aProperty, aEnabledState, aTargetElement, aPseudoType,
styleRule, aResult, /* aIsContextSensitive */ nullptr);
}
/* static */ bool
@ -2612,6 +2625,7 @@ StyleAnimationValue::ComputeValues(
nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState,
dom::Element* aTargetElement,
nsCSSPseudoElements::Type aPseudoType,
css::StyleRule* aStyleRule,
nsTArray<PropertyStyleAnimationValuePair>& aValues,
bool* aIsContextSensitive)
@ -2620,8 +2634,9 @@ StyleAnimationValue::ComputeValues(
return false;
}
// Look up style context for our target element
RefPtr<nsStyleContext> styleContext = LookupStyleContext(aTargetElement);
// Look up style context for our target, element:psuedo pair
RefPtr<nsStyleContext> styleContext = LookupStyleContext(aTargetElement,
aPseudoType);
if (!styleContext) {
return false;
}

View File

@ -14,6 +14,7 @@
#include "nsCoord.h"
#include "nsColor.h"
#include "nsCSSProps.h"
#include "nsCSSPseudoElements.h"
#include "nsCSSValue.h"
class nsIFrame;
@ -133,7 +134,11 @@ public:
*
* @param aProperty The property whose value we're computing.
* @param aTargetElement The content node to which our computed value is
* applicable.
* applicable. For pseudo-elements, this is the parent
* element to which the pseudo is attached, not the
* generated content node.
* @param aPseudoType The type of pseudo-element to which the computed
* value is applicable.
* @param aSpecifiedValue The specified value, from which we'll build our
* computed value.
* @param aUseSVGMode A flag to indicate whether we should parse
@ -150,11 +155,12 @@ public:
* @return true on success, false on failure.
*/
static bool ComputeValue(nsCSSProperty aProperty,
mozilla::dom::Element* aTargetElement,
const nsAString& aSpecifiedValue,
bool aUseSVGMode,
StyleAnimationValue& aComputedValue,
bool* aIsContextSensitive = nullptr);
mozilla::dom::Element* aTargetElement,
nsCSSPseudoElements::Type aPseudoType,
const nsAString& aSpecifiedValue,
bool aUseSVGMode,
StyleAnimationValue& aComputedValue,
bool* aIsContextSensitive = nullptr);
/**
* Like ComputeValue, but returns an array of StyleAnimationValues.
@ -169,6 +175,7 @@ public:
static bool ComputeValues(nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState,
mozilla::dom::Element* aTargetElement,
nsCSSPseudoElements::Type aPseudoType,
const nsAString& aSpecifiedValue,
bool aUseSVGMode,
nsTArray<PropertyStyleAnimationValuePair>& aResult);
@ -396,6 +403,7 @@ private:
static bool ComputeValues(nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState,
mozilla::dom::Element* aTargetElement,
nsCSSPseudoElements::Type aPseudoType,
mozilla::css::StyleRule* aStyleRule,
nsTArray<PropertyStyleAnimationValuePair>& aValues,
bool* aIsContextSensitive);