2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
22 #include "CSSPropertyLonghand.h"
24 #include "CSSPropertyNames.h"
25 #include <wtf/HashMap.h>
26 #include <wtf/StdLibExtras.h>
30 typedef HashMap
<int, CSSPropertyLonghand
> ShorthandMap
;
32 static void initShorthandMap(ShorthandMap
& shorthandMap
)
34 #define SET_SHORTHAND_MAP_ENTRY(map, propID, array) \
35 map.set(propID, CSSPropertyLonghand(array, sizeof(array) / sizeof(array[0])))
37 // FIXME: The 'font' property has "shorthand nature" but is not parsed as a shorthand.
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
}
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]);
51 shorthandMap
.set(CSSPropertyBorder
, CSSPropertyLonghand(borderProperties
[0], sizeof(borderProperties
) / sizeof(borderProperties
[0][0])));
53 static const int borderColorProperties
[] = {
54 CSSPropertyBorderTopColor
,
55 CSSPropertyBorderRightColor
,
56 CSSPropertyBorderBottomColor
,
57 CSSPropertyBorderLeftColor
59 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBorderColor
, borderColorProperties
);
61 static const int borderStyleProperties
[] = {
62 CSSPropertyBorderTopStyle
,
63 CSSPropertyBorderRightStyle
,
64 CSSPropertyBorderBottomStyle
,
65 CSSPropertyBorderLeftStyle
67 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBorderStyle
, borderStyleProperties
);
69 static const int borderWidthProperties
[] = {
70 CSSPropertyBorderTopWidth
,
71 CSSPropertyBorderRightWidth
,
72 CSSPropertyBorderBottomWidth
,
73 CSSPropertyBorderLeftWidth
75 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBorderWidth
, borderWidthProperties
);
77 static const int backgroundPositionProperties
[] = { CSSPropertyBackgroundPositionX
, CSSPropertyBackgroundPositionY
};
78 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBackgroundPosition
, backgroundPositionProperties
);
80 static const int backgroundRepeatProperties
[] = { CSSPropertyBackgroundRepeatX
, CSSPropertyBackgroundRepeatY
};
81 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBackgroundRepeat
, backgroundRepeatProperties
);
83 static const int borderSpacingProperties
[] = { CSSPropertyWebkitBorderHorizontalSpacing
, CSSPropertyWebkitBorderVerticalSpacing
};
84 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBorderSpacing
, borderSpacingProperties
);
86 static const int listStyleProperties
[] = {
87 CSSPropertyListStyleImage
,
88 CSSPropertyListStylePosition
,
89 CSSPropertyListStyleType
91 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyListStyle
, listStyleProperties
);
93 static const int marginProperties
[] = {
95 CSSPropertyMarginRight
,
96 CSSPropertyMarginBottom
,
99 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyMargin
, marginProperties
);
101 static const int marginCollapseProperties
[] = { CSSPropertyWebkitMarginTopCollapse
, CSSPropertyWebkitMarginBottomCollapse
};
102 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitMarginCollapse
, marginCollapseProperties
);
104 static const int marqueeProperties
[] = {
105 CSSPropertyWebkitMarqueeDirection
,
106 CSSPropertyWebkitMarqueeIncrement
,
107 CSSPropertyWebkitMarqueeRepetition
,
108 CSSPropertyWebkitMarqueeStyle
,
109 CSSPropertyWebkitMarqueeSpeed
111 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitMarquee
, marqueeProperties
);
113 static const int outlineProperties
[] = {
114 CSSPropertyOutlineColor
,
115 CSSPropertyOutlineOffset
,
116 CSSPropertyOutlineStyle
,
117 CSSPropertyOutlineWidth
119 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyOutline
, outlineProperties
);
121 static const int paddingProperties
[] = {
122 CSSPropertyPaddingTop
,
123 CSSPropertyPaddingRight
,
124 CSSPropertyPaddingBottom
,
125 CSSPropertyPaddingLeft
127 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyPadding
, paddingProperties
);
129 static const int textStrokeProperties
[] = { CSSPropertyWebkitTextStrokeColor
, CSSPropertyWebkitTextStrokeWidth
};
130 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitTextStroke
, textStrokeProperties
);
132 static const int backgroundProperties
[] = {
133 CSSPropertyBackgroundAttachment
,
134 CSSPropertyBackgroundClip
,
135 CSSPropertyBackgroundColor
,
136 CSSPropertyBackgroundImage
,
137 CSSPropertyBackgroundOrigin
,
138 CSSPropertyBackgroundPositionX
,
139 CSSPropertyBackgroundPositionY
,
140 CSSPropertyBackgroundRepeatX
,
141 CSSPropertyBackgroundRepeatY
143 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBackground
, backgroundProperties
);
145 static const int columnsProperties
[] = { CSSPropertyWebkitColumnWidth
, CSSPropertyWebkitColumnCount
};
146 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitColumns
, columnsProperties
);
148 static const int columnRuleProperties
[] = {
149 CSSPropertyWebkitColumnRuleColor
,
150 CSSPropertyWebkitColumnRuleStyle
,
151 CSSPropertyWebkitColumnRuleWidth
153 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitColumnRule
, columnRuleProperties
);
155 static const int overflowProperties
[] = { CSSPropertyOverflowX
, CSSPropertyOverflowY
};
156 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyOverflow
, overflowProperties
);
158 static const int borderRadiusProperties
[] = {
159 CSSPropertyBorderTopRightRadius
,
160 CSSPropertyBorderTopLeftRadius
,
161 CSSPropertyBorderBottomLeftRadius
,
162 CSSPropertyBorderBottomRightRadius
164 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyBorderRadius
, borderRadiusProperties
);
165 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitBorderRadius
, borderRadiusProperties
);
167 static const int maskPositionProperties
[] = { CSSPropertyWebkitMaskPositionX
, CSSPropertyWebkitMaskPositionY
};
168 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitMaskPosition
, maskPositionProperties
);
170 static const int maskRepeatProperties
[] = { CSSPropertyWebkitMaskRepeatX
, CSSPropertyWebkitMaskRepeatY
};
171 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitMaskRepeat
, maskRepeatProperties
);
173 static const int maskProperties
[] = {
174 CSSPropertyWebkitMaskAttachment
,
175 CSSPropertyWebkitMaskClip
,
176 CSSPropertyWebkitMaskImage
,
177 CSSPropertyWebkitMaskOrigin
,
178 CSSPropertyWebkitMaskPositionX
,
179 CSSPropertyWebkitMaskPositionY
,
180 CSSPropertyWebkitMaskRepeatX
,
181 CSSPropertyWebkitMaskRepeatY
183 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitMask
, maskProperties
);
185 static const int animationProperties
[] = {
186 CSSPropertyWebkitAnimationName
,
187 CSSPropertyWebkitAnimationDuration
,
188 CSSPropertyWebkitAnimationTimingFunction
,
189 CSSPropertyWebkitAnimationDelay
,
190 CSSPropertyWebkitAnimationIterationCount
,
191 CSSPropertyWebkitAnimationDirection
193 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitAnimation
, animationProperties
);
195 static const int transitionProperties
[] = {
196 CSSPropertyWebkitTransitionProperty
,
197 CSSPropertyWebkitTransitionDuration
,
198 CSSPropertyWebkitTransitionTimingFunction
,
199 CSSPropertyWebkitTransitionDelay
201 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitTransition
, transitionProperties
);
203 static const int transformOriginProperties
[] = {
204 CSSPropertyWebkitTransformOriginX
,
205 CSSPropertyWebkitTransformOriginY
207 SET_SHORTHAND_MAP_ENTRY(shorthandMap
, CSSPropertyWebkitTransformOrigin
, transformOriginProperties
);
209 #undef SET_SHORTHAND_MAP_ENTRY
212 CSSPropertyLonghand
longhandForProperty(int propertyID
)
214 DEFINE_STATIC_LOCAL(ShorthandMap
, shorthandMap
, ());
215 if (shorthandMap
.isEmpty())
216 initShorthandMap(shorthandMap
);
218 return shorthandMap
.get(propertyID
);
222 } // namespace WebCore