Commit ca13cd54 authored by timloh@chromium.org's avatar timloh@chromium.org

Add animatable flag to CSSProperties.in

This patch adds the flag 'animatable' to CSSProperties.in, replacing the
existing switch statement in CSSAnimations.cpp. Setting the flag
indicates that the property can be animated by CSS animations and
transitions.

The added code will generate a function in CSSPropertyMetadata, which
will eventually also support functions like isInheritedProperty and
isValidFirstLetterStyleProperty. This means that the individual lines in
CSSProperties.in may start getting a bit long, although a centralized
specification of our supported CSS properties arguably helps developers
add new CSS properties, by reducing the lines they need to add and
adding documentation on what changes need to be made.

BUG=396992

Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=180039

Review URL: https://codereview.chromium.org/454423003

git-svn-id: svn://svn.chromium.org/blink/trunk@180213 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 72f14a8e
...@@ -11,6 +11,7 @@ class CSSProperties(in_generator.Writer): ...@@ -11,6 +11,7 @@ class CSSProperties(in_generator.Writer):
defaults = { defaults = {
'alias_for': None, 'alias_for': None,
'longhands': '', 'longhands': '',
'animatable': False,
'font': False, 'font': False,
'svg': False, 'svg': False,
'name_for_methods': None, 'name_for_methods': None,
...@@ -29,6 +30,7 @@ class CSSProperties(in_generator.Writer): ...@@ -29,6 +30,7 @@ class CSSProperties(in_generator.Writer):
} }
valid_values = { valid_values = {
'animatable': (True, False),
'font': (True, False), 'font': (True, False),
'svg': (True, False), 'svg': (True, False),
'custom_all': (True, False), 'custom_all': (True, False),
......
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import sys
import css_properties
import in_generator
import template_expander
class CSSPropertyMetadataWriter(css_properties.CSSProperties):
def __init__(self, in_file_path):
super(CSSPropertyMetadataWriter, self).__init__(in_file_path)
self._outputs = {'CSSPropertyMetadata.cpp': self.generate_css_property_metadata_cpp}
@template_expander.use_jinja('CSSPropertyMetadata.cpp.tmpl')
def generate_css_property_metadata_cpp(self):
return {
'properties': self._properties,
}
if __name__ == '__main__':
in_generator.Maker(CSSPropertyMetadataWriter).main(sys.argv)
{% from 'macros.tmpl' import license %}
{{license()}}
#include "config.h"
#include "core/css/CSSPropertyMetadata.h"
namespace blink {
bool CSSPropertyMetadata::isAnimatableProperty(CSSPropertyID property)
{
switch(property) {
case CSSPropertyInvalid:
ASSERT_NOT_REACHED();
return false;
{% for property_id, property in properties.items() if property.animatable %}
case {{property_id}}:
{% endfor %}
return true;
default:
return false;
}
}
} // namespace blink
...@@ -414,6 +414,9 @@ source_set("core_generated") { ...@@ -414,6 +414,9 @@ source_set("core_generated") {
# Generated from make_style_builder.py # Generated from make_style_builder.py
"$blink_core_output_dir/StyleBuilder.cpp", "$blink_core_output_dir/StyleBuilder.cpp",
"$blink_core_output_dir/StyleBuilderFunctions.cpp", "$blink_core_output_dir/StyleBuilderFunctions.cpp",
# Generated from make_css_property_metadata.py
"$blink_core_output_dir/CSSPropertyMetadata.cpp",
] ]
configs -= core_config_remove configs -= core_config_remove
...@@ -640,6 +643,17 @@ css_properties("make_core_generated_style_builder") { ...@@ -640,6 +643,17 @@ css_properties("make_core_generated_style_builder") {
] ]
} }
# "CSSPropertyMetadata" in make_core_generated from GYP.
css_properties("make_core_generated_css_property_metadata") {
script = "../build/scripts/make_css_property_metadata.py"
other_inputs = [
"../build/scripts/templates/CSSPropertyMetadata.cpp.tmpl",
]
outputs = [
"$blink_core_output_dir/CSSPropertyMetadata.cpp",
]
}
# "CSSValueKeywords" in make_core_generated from GYP. # "CSSValueKeywords" in make_core_generated from GYP.
process_in_files("make_core_generated_css_value_keywords") { process_in_files("make_core_generated_css_value_keywords") {
script = "../build/scripts/make_css_value_keywords.py" script = "../build/scripts/make_css_value_keywords.py"
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "core/animation/LegacyStyleInterpolation.h" #include "core/animation/LegacyStyleInterpolation.h"
#include "core/animation/LengthStyleInterpolation.h" #include "core/animation/LengthStyleInterpolation.h"
#include "core/animation/css/CSSAnimations.h" #include "core/animation/css/CSSAnimations.h"
#include "core/css/CSSPropertyMetadata.h"
#include "core/css/resolver/StyleResolver.h" #include "core/css/resolver/StyleResolver.h"
#include "core/rendering/style/RenderStyle.h" #include "core/rendering/style/RenderStyle.h"
...@@ -71,7 +72,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: ...@@ -71,7 +72,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value(); CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value();
ValueRange range = ValueRangeAll; ValueRange range = ValueRangeAll;
if (!CSSAnimations::isAnimatableProperty(property)) if (!CSSPropertyMetadata::isAnimatableProperty(property))
return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, property); return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, property);
switch (property) { switch (property) {
......
...@@ -52,10 +52,10 @@ ...@@ -52,10 +52,10 @@
#include "core/animation/animatable/AnimatableTransform.h" #include "core/animation/animatable/AnimatableTransform.h"
#include "core/animation/animatable/AnimatableUnknown.h" #include "core/animation/animatable/AnimatableUnknown.h"
#include "core/animation/animatable/AnimatableVisibility.h" #include "core/animation/animatable/AnimatableVisibility.h"
#include "core/animation/css/CSSAnimations.h"
#include "core/css/CSSCalculationValue.h" #include "core/css/CSSCalculationValue.h"
#include "core/css/CSSPrimitiveValue.h" #include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSPrimitiveValueMappings.h" #include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSPropertyMetadata.h"
#include "core/rendering/style/RenderStyle.h" #include "core/rendering/style/RenderStyle.h"
#include "platform/Length.h" #include "platform/Length.h"
#include "platform/LengthBox.h" #include "platform/LengthBox.h"
...@@ -270,7 +270,7 @@ static PassRefPtrWillBeRawPtr<AnimatableValue> createFromFontWeight(FontWeight f ...@@ -270,7 +270,7 @@ static PassRefPtrWillBeRawPtr<AnimatableValue> createFromFontWeight(FontWeight f
// FIXME: Generate this function. // FIXME: Generate this function.
PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPropertyID property, const RenderStyle& style) PassRefPtrWillBeRawPtr<AnimatableValue> CSSAnimatableValueFactory::create(CSSPropertyID property, const RenderStyle& style)
{ {
ASSERT(CSSAnimations::isAnimatableProperty(property)); ASSERT(CSSPropertyMetadata::isAnimatableProperty(property));
switch (property) { switch (property) {
case CSSPropertyBackgroundColor: case CSSPropertyBackgroundColor:
return createFromColor(property, style); return createFromColor(property, style);
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "core/animation/css/CSSAnimatableValueFactory.h" #include "core/animation/css/CSSAnimatableValueFactory.h"
#include "core/animation/css/CSSPropertyEquality.h" #include "core/animation/css/CSSPropertyEquality.h"
#include "core/css/CSSKeyframeRule.h" #include "core/css/CSSKeyframeRule.h"
#include "core/css/CSSPropertyMetadata.h"
#include "core/css/resolver/CSSToStyleMap.h" #include "core/css/resolver/CSSToStyleMap.h"
#include "core/css/resolver/StyleResolver.h" #include "core/css/resolver/StyleResolver.h"
#include "core/dom/Element.h" #include "core/dom/Element.h"
...@@ -118,7 +119,7 @@ static void resolveKeyframes(StyleResolver* resolver, Element* element, const El ...@@ -118,7 +119,7 @@ static void resolveKeyframes(StyleResolver* resolver, Element* element, const El
else else
timingFunction = CSSToStyleMap::mapAnimationTimingFunction(toCSSValueList(value)->item(0)); timingFunction = CSSToStyleMap::mapAnimationTimingFunction(toCSSValueList(value)->item(0));
keyframe->setEasing(timingFunction.release()); keyframe->setEasing(timingFunction.release());
} else if (CSSAnimations::isAnimatableProperty(property)) { } else if (CSSPropertyMetadata::isAnimatableProperty(property)) {
keyframe->setPropertyValue(property, CSSAnimatableValueFactory::create(property, *keyframeStyle).get()); keyframe->setPropertyValue(property, CSSAnimatableValueFactory::create(property, *keyframeStyle).get());
} }
} }
...@@ -491,7 +492,7 @@ void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const ...@@ -491,7 +492,7 @@ void CSSAnimations::calculateTransitionUpdate(CSSAnimationUpdate* update, const
if (!animateAll) { if (!animateAll) {
id = propertyForAnimation(id); id = propertyForAnimation(id);
if (CSSAnimations::isAnimatableProperty(id)) if (CSSPropertyMetadata::isAnimatableProperty(id))
listedProperties.set(id); listedProperties.set(id);
else else
continue; continue;
...@@ -659,121 +660,6 @@ void CSSAnimations::TransitionEventDelegate::trace(Visitor* visitor) ...@@ -659,121 +660,6 @@ void CSSAnimations::TransitionEventDelegate::trace(Visitor* visitor)
AnimationNode::EventDelegate::trace(visitor); AnimationNode::EventDelegate::trace(visitor);
} }
bool CSSAnimations::isAnimatableProperty(CSSPropertyID property)
{
switch (property) {
case CSSPropertyBackgroundColor:
case CSSPropertyBackgroundImage:
case CSSPropertyBackgroundPositionX:
case CSSPropertyBackgroundPositionY:
case CSSPropertyBackgroundSize:
case CSSPropertyBaselineShift:
case CSSPropertyBorderBottomColor:
case CSSPropertyBorderBottomLeftRadius:
case CSSPropertyBorderBottomRightRadius:
case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderImageOutset:
case CSSPropertyBorderImageSlice:
case CSSPropertyBorderImageSource:
case CSSPropertyBorderImageWidth:
case CSSPropertyBorderLeftColor:
case CSSPropertyBorderLeftWidth:
case CSSPropertyBorderRightColor:
case CSSPropertyBorderRightWidth:
case CSSPropertyBorderTopColor:
case CSSPropertyBorderTopLeftRadius:
case CSSPropertyBorderTopRightRadius:
case CSSPropertyBorderTopWidth:
case CSSPropertyBottom:
case CSSPropertyBoxShadow:
case CSSPropertyClip:
case CSSPropertyColor:
case CSSPropertyFill:
case CSSPropertyFillOpacity:
case CSSPropertyFlexBasis:
case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink:
case CSSPropertyFloodColor:
case CSSPropertyFloodOpacity:
case CSSPropertyFontSize:
case CSSPropertyFontWeight:
case CSSPropertyHeight:
case CSSPropertyLeft:
case CSSPropertyLetterSpacing:
case CSSPropertyLightingColor:
case CSSPropertyLineHeight:
case CSSPropertyListStyleImage:
case CSSPropertyMarginBottom:
case CSSPropertyMarginLeft:
case CSSPropertyMarginRight:
case CSSPropertyMarginTop:
case CSSPropertyMaxHeight:
case CSSPropertyMaxWidth:
case CSSPropertyMinHeight:
case CSSPropertyMinWidth:
case CSSPropertyObjectPosition:
case CSSPropertyOpacity:
case CSSPropertyOrphans:
case CSSPropertyOutlineColor:
case CSSPropertyOutlineOffset:
case CSSPropertyOutlineWidth:
case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft:
case CSSPropertyPaddingRight:
case CSSPropertyPaddingTop:
case CSSPropertyRight:
case CSSPropertyStopColor:
case CSSPropertyStopOpacity:
case CSSPropertyStroke:
case CSSPropertyStrokeDasharray:
case CSSPropertyStrokeDashoffset:
case CSSPropertyStrokeMiterlimit:
case CSSPropertyStrokeOpacity:
case CSSPropertyStrokeWidth:
case CSSPropertyTextDecorationColor:
case CSSPropertyTextIndent:
case CSSPropertyTextShadow:
case CSSPropertyTop:
case CSSPropertyVerticalAlign:
case CSSPropertyVisibility:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyWebkitBorderHorizontalSpacing:
case CSSPropertyWebkitBorderVerticalSpacing:
case CSSPropertyWebkitBoxShadow:
case CSSPropertyWebkitClipPath:
case CSSPropertyWebkitColumnCount:
case CSSPropertyWebkitColumnGap:
case CSSPropertyWebkitColumnRuleColor:
case CSSPropertyWebkitColumnRuleWidth:
case CSSPropertyWebkitColumnWidth:
case CSSPropertyWebkitFilter:
case CSSPropertyWebkitMaskBoxImageOutset:
case CSSPropertyWebkitMaskBoxImageSlice:
case CSSPropertyWebkitMaskBoxImageSource:
case CSSPropertyWebkitMaskBoxImageWidth:
case CSSPropertyWebkitMaskImage:
case CSSPropertyWebkitMaskPositionX:
case CSSPropertyWebkitMaskPositionY:
case CSSPropertyWebkitMaskSize:
case CSSPropertyPerspective:
case CSSPropertyPerspectiveOrigin:
case CSSPropertyShapeOutside:
case CSSPropertyShapeMargin:
case CSSPropertyShapeImageThreshold:
case CSSPropertyWebkitTextStrokeColor:
case CSSPropertyTransform:
case CSSPropertyTransformOrigin:
case CSSPropertyWidows:
case CSSPropertyWidth:
case CSSPropertyWordSpacing:
case CSSPropertyZIndex:
case CSSPropertyZoom:
return true;
default:
return false;
}
}
const StylePropertyShorthand& CSSAnimations::animatableProperties() const StylePropertyShorthand& CSSAnimations::animatableProperties()
{ {
DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ()); DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ());
...@@ -781,7 +667,7 @@ const StylePropertyShorthand& CSSAnimations::animatableProperties() ...@@ -781,7 +667,7 @@ const StylePropertyShorthand& CSSAnimations::animatableProperties()
if (properties.isEmpty()) { if (properties.isEmpty()) {
for (int i = firstCSSProperty; i < lastCSSProperty; ++i) { for (int i = firstCSSProperty; i < lastCSSProperty; ++i) {
CSSPropertyID id = convertToCSSPropertyID(i); CSSPropertyID id = convertToCSSPropertyID(i);
if (isAnimatableProperty(id)) if (CSSPropertyMetadata::isAnimatableProperty(id))
properties.append(id); properties.append(id);
} }
propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, properties.begin(), properties.size()); propertyShorthand = StylePropertyShorthand(CSSPropertyInvalid, properties.begin(), properties.size());
......
...@@ -170,7 +170,6 @@ public: ...@@ -170,7 +170,6 @@ public:
// engine is removed. // engine is removed.
static const StyleRuleKeyframes* matchScopedKeyframesRule(StyleResolver*, const Element*, const StringImpl*); static const StyleRuleKeyframes* matchScopedKeyframesRule(StyleResolver*, const Element*, const StringImpl*);
static bool isAnimatableProperty(CSSPropertyID);
static const StylePropertyShorthand& animatableProperties(); static const StylePropertyShorthand& animatableProperties();
static bool isAllowedAnimation(CSSPropertyID); static bool isAllowedAnimation(CSSPropertyID);
// FIXME: We should change the Element* to a const Element* // FIXME: We should change the Element* to a const Element*
......
...@@ -278,6 +278,9 @@ ...@@ -278,6 +278,9 @@
# Generated from make_style_builder.py # Generated from make_style_builder.py
'<(blink_core_output_dir)/StyleBuilder.cpp', '<(blink_core_output_dir)/StyleBuilder.cpp',
'<(blink_core_output_dir)/StyleBuilderFunctions.cpp', '<(blink_core_output_dir)/StyleBuilderFunctions.cpp',
# Generated from make_css_property_metadata.py
'<(blink_core_output_dir)/CSSPropertyMetadata.cpp',
], ],
'conditions': [ 'conditions': [
['OS=="win" and component=="shared_library"', { ['OS=="win" and component=="shared_library"', {
......
...@@ -350,6 +350,24 @@ ...@@ -350,6 +350,24 @@
'<(blink_core_output_dir)', '<(blink_core_output_dir)',
], ],
}, },
{
'action_name': 'CSSPropertyMetadata',
'inputs': [
'<@(css_properties_files)',
'../build/scripts/make_css_property_metadata.py',
'../build/scripts/templates/CSSPropertyMetadata.cpp.tmpl',
],
'outputs': [
'<(blink_core_output_dir)/CSSPropertyMetadata.cpp',
],
'action': [
'python',
'../build/scripts/make_css_property_metadata.py',
'css/CSSProperties.in',
'--output_dir',
'<(blink_core_output_dir)',
],
},
{ {
'action_name': 'CSSValueKeywords', 'action_name': 'CSSValueKeywords',
'variables': { 'variables': {
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CSSPropertyMetadata_h
#define CSSPropertyMetadata_h
#include "core/CSSPropertyNames.h"
namespace blink {
class CSSPropertyMetadata {
public:
static bool isAnimatableProperty(CSSPropertyID);
};
} // namespace blink
#endif // CSSPropertyMetadata
...@@ -52,8 +52,8 @@ ...@@ -52,8 +52,8 @@
#include "core/animation/animatable/AnimatableUnknown.h" #include "core/animation/animatable/AnimatableUnknown.h"
#include "core/animation/animatable/AnimatableValue.h" #include "core/animation/animatable/AnimatableValue.h"
#include "core/animation/animatable/AnimatableVisibility.h" #include "core/animation/animatable/AnimatableVisibility.h"
#include "core/animation/css/CSSAnimations.h"
#include "core/css/CSSPrimitiveValueMappings.h" #include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSPropertyMetadata.h"
#include "core/css/resolver/StyleBuilder.h" #include "core/css/resolver/StyleBuilder.h"
#include "core/css/resolver/StyleResolverState.h" #include "core/css/resolver/StyleResolverState.h"
#include "core/rendering/style/RenderStyle.h" #include "core/rendering/style/RenderStyle.h"
...@@ -254,7 +254,7 @@ FontWeight animatableValueToFontWeight(const AnimatableValue* value) ...@@ -254,7 +254,7 @@ FontWeight animatableValueToFontWeight(const AnimatableValue* value)
// FIXME: Generate this function. // FIXME: Generate this function.
void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverState& state, const AnimatableValue* value) void AnimatedStyleBuilder::applyProperty(CSSPropertyID property, StyleResolverState& state, const AnimatableValue* value)
{ {
ASSERT(CSSAnimations::isAnimatableProperty(property)); ASSERT(CSSPropertyMetadata::isAnimatableProperty(property));
if (value->isUnknown()) { if (value->isUnknown()) {
StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)->toCSSValue().get()); StyleBuilder::applyProperty(property, state, toAnimatableUnknown(value)->toCSSValue().get());
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment