1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include "config.h"
23 #include "StylePropertyShorthand.h"
24
25 namespace WebCore {
26
borderShorthandForParsing()27 const StylePropertyShorthand& borderShorthandForParsing()
28 {
29 static const CSSPropertyID borderShorthandProperties[] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, CSSPropertyBorderColor };
30 static const StylePropertyShorthand* propertiesForInitialization[] = {
31 &borderWidthShorthand(),
32 &borderStyleShorthand(),
33 &borderColorShorthand(),
34 };
35 DEFINE_STATIC_LOCAL(StylePropertyShorthand, borderForParsingLonghands, (CSSPropertyBorder, borderShorthandProperties, propertiesForInitialization, WTF_ARRAY_LENGTH(borderShorthandProperties)));
36 return borderForParsingLonghands;
37 }
38
animationShorthandForParsing()39 const StylePropertyShorthand& animationShorthandForParsing()
40 {
41 // When we parse the animation shorthand we need to look for animation-name
42 // last because otherwise it might match against the keywords for fill mode,
43 // timing functions and infinite iteration. This means that animation names
44 // that are the same as keywords (e.g. 'forwards') won't always match in the
45 // shorthand. In that case the authors should be using longhands (or
46 // reconsidering their approach). This is covered by the animations spec
47 // bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790
48 // And in the spec (editor's draft) at:
49 // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property
50 static const CSSPropertyID animationPropertiesForParsing[] = {
51 CSSPropertyAnimationDuration,
52 CSSPropertyAnimationTimingFunction,
53 CSSPropertyAnimationDelay,
54 CSSPropertyAnimationIterationCount,
55 CSSPropertyAnimationDirection,
56 CSSPropertyAnimationFillMode,
57 CSSPropertyAnimationPlayState,
58 CSSPropertyAnimationName
59 };
60 DEFINE_STATIC_LOCAL(StylePropertyShorthand, webkitAnimationLonghandsForParsing, (CSSPropertyAnimation, animationPropertiesForParsing, WTF_ARRAY_LENGTH(animationPropertiesForParsing)));
61 return webkitAnimationLonghandsForParsing;
62 }
63
webkitAnimationShorthandForParsing()64 const StylePropertyShorthand& webkitAnimationShorthandForParsing()
65 {
66 // When we parse the animation shorthand we need to look for animation-name
67 // last because otherwise it might match against the keywords for fill mode,
68 // timing functions and infinite iteration. This means that animation names
69 // that are the same as keywords (e.g. 'forwards') won't always match in the
70 // shorthand. In that case the authors should be using longhands (or
71 // reconsidering their approach). This is covered by the animations spec
72 // bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790
73 // And in the spec (editor's draft) at:
74 // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property
75 static const CSSPropertyID animationPropertiesForParsing[] = {
76 CSSPropertyWebkitAnimationDuration,
77 CSSPropertyWebkitAnimationTimingFunction,
78 CSSPropertyWebkitAnimationDelay,
79 CSSPropertyWebkitAnimationIterationCount,
80 CSSPropertyWebkitAnimationDirection,
81 CSSPropertyWebkitAnimationFillMode,
82 CSSPropertyWebkitAnimationPlayState,
83 CSSPropertyWebkitAnimationName
84 };
85 DEFINE_STATIC_LOCAL(StylePropertyShorthand, webkitAnimationLonghandsForParsing, (CSSPropertyWebkitAnimation, animationPropertiesForParsing, WTF_ARRAY_LENGTH(animationPropertiesForParsing)));
86 return webkitAnimationLonghandsForParsing;
87 }
88
89 // Returns an empty list if the property is not a shorthand, otherwise the list of longhands for parsing.
parsingShorthandForProperty(CSSPropertyID propertyID)90 const StylePropertyShorthand& parsingShorthandForProperty(CSSPropertyID propertyID)
91 {
92 switch (propertyID) {
93 case CSSPropertyAnimation:
94 return animationShorthandForParsing();
95 case CSSPropertyBorder:
96 return borderShorthandForParsing();
97 case CSSPropertyWebkitAnimation:
98 return webkitAnimationShorthandForParsing();
99 default:
100 return shorthandForProperty(propertyID);
101 }
102 }
103
isExpandedShorthand(CSSPropertyID id)104 bool isExpandedShorthand(CSSPropertyID id)
105 {
106 // The system fonts bypass the normal style resolution by using RenderTheme,
107 // thus we need to special case it here. FIXME: This is a violation of CSS 3 Fonts
108 // as we should still be able to change the longhands.
109 // DON'T ADD ANY SHORTHAND HERE UNLESS IT ISN'T ALWAYS EXPANDED AT PARSE TIME (which is wrong).
110 if (id == CSSPropertyFont)
111 return false;
112
113 return shorthandForProperty(id).length();
114 }
115
indexOfShorthandForLonghand(CSSPropertyID shorthandID,const Vector<StylePropertyShorthand,4> & shorthands)116 unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand, 4>& shorthands)
117 {
118 for (unsigned i = 0; i < shorthands.size(); ++i) {
119 if (shorthands.at(i).id() == shorthandID)
120 return i;
121 }
122 ASSERT_NOT_REACHED();
123 return 0;
124 }
125
126 } // namespace WebCore
127