• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "config.h"
22 #include "CSSPropertyLonghand.h"
23 
24 #include "CSSPropertyNames.h"
25 #include <wtf/HashMap.h>
26 #include <wtf/StdLibExtras.h>
27 
28 namespace WebCore {
29 
30 typedef HashMap<int, CSSPropertyLonghand> ShorthandMap;
31 
initShorthandMap(ShorthandMap & shorthandMap)32 static void initShorthandMap(ShorthandMap& shorthandMap)
33 {
34     #define SET_SHORTHAND_MAP_ENTRY(map, propID, array) \
35         map.set(propID, CSSPropertyLonghand(array, sizeof(array) / sizeof(array[0])))
36 
37     // FIXME: The 'font' property has "shorthand nature" but is not parsed as a shorthand.
38 
39     // Do not change the order of the following four shorthands, and keep them together.
40     static const int borderProperties[4][3] = {
41         { CSSPropertyBorderTopColor, CSSPropertyBorderTopStyle, CSSPropertyBorderTopWidth },
42         { CSSPropertyBorderRightColor, CSSPropertyBorderRightStyle, CSSPropertyBorderRightWidth },
43         { CSSPropertyBorderBottomColor, CSSPropertyBorderBottomStyle, CSSPropertyBorderBottomWidth },
44         { CSSPropertyBorderLeftColor, CSSPropertyBorderLeftStyle, CSSPropertyBorderLeftWidth }
45     };
46     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderTop, borderProperties[0]);
47     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderRight, borderProperties[1]);
48     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderBottom, borderProperties[2]);
49     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderLeft, borderProperties[3]);
50 
51     shorthandMap.set(CSSPropertyBorder, CSSPropertyLonghand(borderProperties[0], sizeof(borderProperties) / sizeof(borderProperties[0][0])));
52 
53     static const int borderColorProperties[] = {
54         CSSPropertyBorderTopColor,
55         CSSPropertyBorderRightColor,
56         CSSPropertyBorderBottomColor,
57         CSSPropertyBorderLeftColor
58     };
59     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderColor, borderColorProperties);
60 
61     static const int borderStyleProperties[] = {
62         CSSPropertyBorderTopStyle,
63         CSSPropertyBorderRightStyle,
64         CSSPropertyBorderBottomStyle,
65         CSSPropertyBorderLeftStyle
66     };
67     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderStyle, borderStyleProperties);
68 
69     static const int borderWidthProperties[] = {
70         CSSPropertyBorderTopWidth,
71         CSSPropertyBorderRightWidth,
72         CSSPropertyBorderBottomWidth,
73         CSSPropertyBorderLeftWidth
74     };
75     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderWidth, borderWidthProperties);
76 
77     static const int backgroundPositionProperties[] = { CSSPropertyBackgroundPositionX, CSSPropertyBackgroundPositionY };
78     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBackgroundPosition, backgroundPositionProperties);
79 
80     static const int borderSpacingProperties[] = { CSSPropertyWebkitBorderHorizontalSpacing, CSSPropertyWebkitBorderVerticalSpacing };
81     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderSpacing, borderSpacingProperties);
82 
83     static const int listStyleProperties[] = {
84         CSSPropertyListStyleImage,
85         CSSPropertyListStylePosition,
86         CSSPropertyListStyleType
87     };
88     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyListStyle, listStyleProperties);
89 
90     static const int marginProperties[] = {
91         CSSPropertyMarginTop,
92         CSSPropertyMarginRight,
93         CSSPropertyMarginBottom,
94         CSSPropertyMarginLeft
95     };
96     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyMargin, marginProperties);
97 
98     static const int marginCollapseProperties[] = { CSSPropertyWebkitMarginTopCollapse, CSSPropertyWebkitMarginBottomCollapse };
99     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMarginCollapse, marginCollapseProperties);
100 
101     static const int marqueeProperties[] = {
102         CSSPropertyWebkitMarqueeDirection,
103         CSSPropertyWebkitMarqueeIncrement,
104         CSSPropertyWebkitMarqueeRepetition,
105         CSSPropertyWebkitMarqueeStyle,
106         CSSPropertyWebkitMarqueeSpeed
107     };
108     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMarquee, marqueeProperties);
109 
110     static const int outlineProperties[] = {
111         CSSPropertyOutlineColor,
112         CSSPropertyOutlineOffset,
113         CSSPropertyOutlineStyle,
114         CSSPropertyOutlineWidth
115     };
116     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyOutline, outlineProperties);
117 
118     static const int paddingProperties[] = {
119         CSSPropertyPaddingTop,
120         CSSPropertyPaddingRight,
121         CSSPropertyPaddingBottom,
122         CSSPropertyPaddingLeft
123     };
124     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyPadding, paddingProperties);
125 
126     static const int textStrokeProperties[] = { CSSPropertyWebkitTextStrokeColor, CSSPropertyWebkitTextStrokeWidth };
127     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitTextStroke, textStrokeProperties);
128 
129     static const int backgroundProperties[] = {
130         CSSPropertyBackgroundAttachment,
131         CSSPropertyBackgroundClip,
132         CSSPropertyBackgroundColor,
133         CSSPropertyBackgroundImage,
134         CSSPropertyBackgroundOrigin,
135         CSSPropertyBackgroundPositionX,
136         CSSPropertyBackgroundPositionY,
137         CSSPropertyBackgroundRepeat,
138     };
139     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBackground, backgroundProperties);
140 
141     static const int columnsProperties[] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount };
142     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitColumns, columnsProperties);
143 
144     static const int columnRuleProperties[] = {
145         CSSPropertyWebkitColumnRuleColor,
146         CSSPropertyWebkitColumnRuleStyle,
147         CSSPropertyWebkitColumnRuleWidth
148     };
149     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitColumnRule, columnRuleProperties);
150 
151     static const int overflowProperties[] = { CSSPropertyOverflowX, CSSPropertyOverflowY };
152     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyOverflow, overflowProperties);
153 
154     static const int borderRadiusProperties[] = {
155         CSSPropertyBorderTopRightRadius,
156         CSSPropertyBorderTopLeftRadius,
157         CSSPropertyBorderBottomLeftRadius,
158         CSSPropertyBorderBottomRightRadius
159     };
160     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderRadius, borderRadiusProperties);
161     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitBorderRadius, borderRadiusProperties);
162 
163     static const int maskPositionProperties[] = { CSSPropertyWebkitMaskPositionX, CSSPropertyWebkitMaskPositionY };
164     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMaskPosition, maskPositionProperties);
165 
166     static const int maskProperties[] = {
167         CSSPropertyWebkitMaskAttachment,
168         CSSPropertyWebkitMaskClip,
169         CSSPropertyWebkitMaskImage,
170         CSSPropertyWebkitMaskOrigin,
171         CSSPropertyWebkitMaskPositionX,
172         CSSPropertyWebkitMaskPositionY,
173         CSSPropertyWebkitMaskRepeat,
174     };
175     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMask, maskProperties);
176 
177     static const int animationProperties[] = {
178         CSSPropertyWebkitAnimationName,
179         CSSPropertyWebkitAnimationDuration,
180         CSSPropertyWebkitAnimationTimingFunction,
181         CSSPropertyWebkitAnimationDelay,
182         CSSPropertyWebkitAnimationIterationCount,
183         CSSPropertyWebkitAnimationDirection
184     };
185     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitAnimation, animationProperties);
186 
187     static const int transitionProperties[] = {
188         CSSPropertyWebkitTransitionProperty,
189         CSSPropertyWebkitTransitionDuration,
190         CSSPropertyWebkitTransitionTimingFunction,
191         CSSPropertyWebkitTransitionDelay
192     };
193     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitTransition, transitionProperties);
194 
195     static const int transformOriginProperties[] = {
196         CSSPropertyWebkitTransformOriginX,
197         CSSPropertyWebkitTransformOriginY
198     };
199     SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitTransformOrigin, transformOriginProperties);
200 
201     #undef SET_SHORTHAND_MAP_ENTRY
202 }
203 
longhandForProperty(int propertyID)204 CSSPropertyLonghand longhandForProperty(int propertyID)
205 {
206     DEFINE_STATIC_LOCAL(ShorthandMap, shorthandMap, ());
207     if (shorthandMap.isEmpty())
208         initShorthandMap(shorthandMap);
209 
210     return shorthandMap.get(propertyID);
211 }
212 
213 
214 } // namespace WebCore
215