зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1245748 - Add a variant of StyleAnimationValue::ComputeValues that takes an nsCSSValue; r=heycam
MozReview-Commit-ID: 83popM8E0Q4 --HG-- extra : rebase_source : efef274a8a2a21423e6c1931d9b92739272eb72a
This commit is contained in:
Родитель
b411ad9926
Коммит
a1ae304c59
|
@ -2552,90 +2552,43 @@ BuildStyleRule(nsCSSProperty aProperty,
|
|||
return rule.forget();
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
const nsAString& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
StyleAnimationValue& aComputedValue,
|
||||
bool* aIsContextSensitive)
|
||||
already_AddRefed<css::StyleRule>
|
||||
BuildStyleRule(nsCSSProperty aProperty,
|
||||
dom::Element* aTargetElement,
|
||||
const nsCSSValue& aSpecifiedValue,
|
||||
bool aUseSVGMode)
|
||||
{
|
||||
MOZ_ASSERT(aTargetElement, "null target element");
|
||||
MOZ_ASSERT(!nsCSSProps::IsShorthand(aProperty),
|
||||
"Should be a longhand property");
|
||||
|
||||
// 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) {
|
||||
return false;
|
||||
// Check if longhand failed to parse correctly.
|
||||
if (aSpecifiedValue.GetUnit() == eCSSUnit_Null) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (nsCSSProps::IsShorthand(aProperty) ||
|
||||
nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) {
|
||||
// Just capture the specified value
|
||||
aComputedValue.SetUnparsedStringValue(nsString(aSpecifiedValue));
|
||||
if (aIsContextSensitive) {
|
||||
// Since we're just returning the string as-is, aComputedValue isn't going
|
||||
// to change depending on the context
|
||||
*aIsContextSensitive = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Set up an empty CSS Declaration
|
||||
RefPtr<css::Declaration> declaration(new css::Declaration());
|
||||
declaration->InitializeEmpty();
|
||||
|
||||
AutoTArray<PropertyStyleAnimationValuePair,1> values;
|
||||
bool ok = ComputeValues(aProperty, nsCSSProps::eIgnoreEnabledState,
|
||||
aTargetElement, aStyleContext, styleRule,
|
||||
values, aIsContextSensitive);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
// Add our longhand value
|
||||
nsCSSExpandedDataBlock block;
|
||||
declaration->ExpandTo(&block);
|
||||
block.AddLonghandProperty(aProperty, aSpecifiedValue);
|
||||
declaration->ValueAppended(aProperty);
|
||||
declaration->CompressFrom(&block);
|
||||
|
||||
MOZ_ASSERT(values.Length() == 1);
|
||||
MOZ_ASSERT(values[0].mProperty == aProperty);
|
||||
|
||||
aComputedValue = values[0].mValue;
|
||||
return true;
|
||||
RefPtr<css::StyleRule> rule = new css::StyleRule(nullptr, declaration, 0, 0);
|
||||
return rule.forget();
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
StyleAnimationValue::ComputeValues(nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
const nsAString& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aResult)
|
||||
{
|
||||
MOZ_ASSERT(aTargetElement, "null target element");
|
||||
|
||||
// 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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aResult.Clear();
|
||||
return ComputeValues(aProperty, aEnabledState, aTargetElement,
|
||||
aStyleContext, styleRule, aResult,
|
||||
/* aIsContextSensitive */ nullptr);
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
StyleAnimationValue::ComputeValues(
|
||||
nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
css::StyleRule* aStyleRule,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aValues,
|
||||
bool* aIsContextSensitive)
|
||||
static bool
|
||||
ComputeValuesFromStyleRule(nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
css::StyleRule* aStyleRule,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aValues,
|
||||
bool* aIsContextSensitive)
|
||||
{
|
||||
MOZ_ASSERT(aStyleContext);
|
||||
if (!nsCSSProps::IsEnabled(aProperty, aEnabledState)) {
|
||||
|
@ -2702,8 +2655,8 @@ StyleAnimationValue::ComputeValues(
|
|||
}
|
||||
PropertyStyleAnimationValuePair* pair = aValues.AppendElement();
|
||||
pair->mProperty = *p;
|
||||
if (!ExtractComputedValue(*p, tmpStyleContext,
|
||||
pair->mValue)) {
|
||||
if (!StyleAnimationValue::ExtractComputedValue(*p, tmpStyleContext,
|
||||
pair->mValue)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2711,10 +2664,121 @@ StyleAnimationValue::ComputeValues(
|
|||
} else {
|
||||
PropertyStyleAnimationValuePair* pair = aValues.AppendElement();
|
||||
pair->mProperty = aProperty;
|
||||
return ExtractComputedValue(aProperty, tmpStyleContext, pair->mValue);
|
||||
return StyleAnimationValue::ExtractComputedValue(aProperty, tmpStyleContext,
|
||||
pair->mValue);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
const nsAString& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
StyleAnimationValue& aComputedValue,
|
||||
bool* aIsContextSensitive)
|
||||
{
|
||||
MOZ_ASSERT(aTargetElement, "null target element");
|
||||
|
||||
// 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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nsCSSProps::IsShorthand(aProperty) ||
|
||||
nsCSSProps::kAnimTypeTable[aProperty] == eStyleAnimType_None) {
|
||||
// Just capture the specified value
|
||||
aComputedValue.SetUnparsedStringValue(nsString(aSpecifiedValue));
|
||||
if (aIsContextSensitive) {
|
||||
// Since we're just returning the string as-is, aComputedValue isn't going
|
||||
// to change depending on the context
|
||||
*aIsContextSensitive = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
AutoTArray<PropertyStyleAnimationValuePair,1> values;
|
||||
bool ok = ComputeValuesFromStyleRule(aProperty,
|
||||
nsCSSProps::eIgnoreEnabledState,
|
||||
aTargetElement, aStyleContext, styleRule,
|
||||
values, aIsContextSensitive);
|
||||
if (!ok) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(values.Length() == 1);
|
||||
MOZ_ASSERT(values[0].mProperty == aProperty);
|
||||
|
||||
aComputedValue = values[0].mValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool
|
||||
ComputeValuesFromSpecifiedValue(
|
||||
nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
T& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aResult)
|
||||
{
|
||||
MOZ_ASSERT(aTargetElement, "null target element");
|
||||
|
||||
// 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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aResult.Clear();
|
||||
return ComputeValuesFromStyleRule(aProperty, aEnabledState, aTargetElement,
|
||||
aStyleContext, styleRule, aResult,
|
||||
/* aIsContextSensitive */ nullptr);
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
StyleAnimationValue::ComputeValues(
|
||||
nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
const nsAString& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aResult)
|
||||
{
|
||||
return ComputeValuesFromSpecifiedValue(aProperty, aEnabledState,
|
||||
aTargetElement, aStyleContext,
|
||||
aSpecifiedValue, aUseSVGMode,
|
||||
aResult);
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
StyleAnimationValue::ComputeValues(
|
||||
nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
const nsCSSValue& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aResult)
|
||||
{
|
||||
return ComputeValuesFromSpecifiedValue(aProperty, aEnabledState,
|
||||
aTargetElement, aStyleContext,
|
||||
aSpecifiedValue, aUseSVGMode,
|
||||
aResult);
|
||||
}
|
||||
|
||||
bool
|
||||
StyleAnimationValue::UncomputeValue(nsCSSProperty aProperty,
|
||||
const StyleAnimationValue& aComputedValue,
|
||||
|
|
|
@ -182,6 +182,18 @@ public:
|
|||
bool aUseSVGMode,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aResult);
|
||||
|
||||
/**
|
||||
* A variant on ComputeValues that takes an nsCSSValue as the specified
|
||||
* value. Only longhand properties are supported.
|
||||
*/
|
||||
static bool ComputeValues(nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
mozilla::dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
const nsCSSValue& aSpecifiedValue,
|
||||
bool aUseSVGMode,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aResult);
|
||||
|
||||
/**
|
||||
* Creates a specified value for the given computed value.
|
||||
*
|
||||
|
@ -402,14 +414,6 @@ public:
|
|||
{ return !(*this == aOther); }
|
||||
|
||||
private:
|
||||
static bool ComputeValues(nsCSSProperty aProperty,
|
||||
nsCSSProps::EnabledState aEnabledState,
|
||||
mozilla::dom::Element* aTargetElement,
|
||||
nsStyleContext* aStyleContext,
|
||||
mozilla::css::StyleRule* aStyleRule,
|
||||
nsTArray<PropertyStyleAnimationValuePair>& aValues,
|
||||
bool* aIsContextSensitive);
|
||||
|
||||
void FreeValue();
|
||||
|
||||
static const char16_t* GetBufferValue(nsStringBuffer* aBuffer) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче