5ce4d1fae3be316598f1b4417a5505a41c4e2b3d
[WebKit-https.git] / Source / WebCore / css / StylePropertyShorthand.cpp
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 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 #include <wtf/StdLibExtras.h>
26
27 // FIXME: How much of this file can we generate?
28
29 namespace WebCore {
30
31 StylePropertyShorthand backgroundShorthand()
32 {
33     static const CSSPropertyID backgroundProperties[] = {
34         CSSPropertyBackgroundImage,
35         CSSPropertyBackgroundPositionX,
36         CSSPropertyBackgroundPositionY,
37         CSSPropertyBackgroundSize,
38         CSSPropertyBackgroundRepeatX,
39         CSSPropertyBackgroundRepeatY,
40         CSSPropertyBackgroundAttachment,
41         CSSPropertyBackgroundOrigin,
42         CSSPropertyBackgroundClip,
43         CSSPropertyBackgroundColor
44     };
45     return StylePropertyShorthand(CSSPropertyBackground, backgroundProperties, WTF_ARRAY_LENGTH(backgroundProperties));
46 }
47
48 StylePropertyShorthand backgroundPositionShorthand()
49 {
50     static const CSSPropertyID backgroundPositionProperties[] = { CSSPropertyBackgroundPositionX, CSSPropertyBackgroundPositionY };
51     return StylePropertyShorthand(CSSPropertyBackgroundPosition, backgroundPositionProperties, WTF_ARRAY_LENGTH(backgroundPositionProperties));
52 }
53
54 StylePropertyShorthand backgroundRepeatShorthand()
55 {
56     static const CSSPropertyID backgroundRepeatProperties[] = { CSSPropertyBackgroundRepeatX, CSSPropertyBackgroundRepeatY };
57     return StylePropertyShorthand(CSSPropertyBackgroundRepeat, backgroundRepeatProperties, WTF_ARRAY_LENGTH(backgroundRepeatProperties));
58 }
59
60 StylePropertyShorthand borderShorthand()
61 {
62     // Do not change the order of the following four shorthands, and keep them together.
63     static const CSSPropertyID borderProperties[4][3] = {
64         { CSSPropertyBorderTopColor, CSSPropertyBorderTopStyle, CSSPropertyBorderTopWidth },
65         { CSSPropertyBorderRightColor, CSSPropertyBorderRightStyle, CSSPropertyBorderRightWidth },
66         { CSSPropertyBorderBottomColor, CSSPropertyBorderBottomStyle, CSSPropertyBorderBottomWidth },
67         { CSSPropertyBorderLeftColor, CSSPropertyBorderLeftStyle, CSSPropertyBorderLeftWidth }
68     };
69     return StylePropertyShorthand(CSSPropertyBorder, borderProperties[0], sizeof(borderProperties) / sizeof(borderProperties[0][0]));
70 }
71
72 StylePropertyShorthand borderAbridgedShorthand()
73 {
74     static const CSSPropertyID borderAbridgedProperties[] = { CSSPropertyBorderWidth, CSSPropertyBorderStyle, CSSPropertyBorderColor };
75     static const StylePropertyShorthand propertiesForInitialization[] = { borderWidthShorthand(), borderStyleShorthand(), borderColorShorthand() };
76     return StylePropertyShorthand(CSSPropertyBorder, borderAbridgedProperties, propertiesForInitialization, WTF_ARRAY_LENGTH(borderAbridgedProperties));
77 }
78
79 StylePropertyShorthand borderBottomShorthand()
80 {
81     static const CSSPropertyID borderBottomProperties[] = { CSSPropertyBorderBottomWidth, CSSPropertyBorderBottomStyle, CSSPropertyBorderBottomColor };
82     return StylePropertyShorthand(CSSPropertyBorderBottom, borderBottomProperties, WTF_ARRAY_LENGTH(borderBottomProperties));
83 }
84
85 StylePropertyShorthand borderColorShorthand()
86 {
87     static const CSSPropertyID borderColorProperties[] = {
88         CSSPropertyBorderTopColor,
89         CSSPropertyBorderRightColor,
90         CSSPropertyBorderBottomColor,
91         CSSPropertyBorderLeftColor
92     };
93     return StylePropertyShorthand(CSSPropertyBorderColor, borderColorProperties, WTF_ARRAY_LENGTH(borderColorProperties));
94 }
95
96 StylePropertyShorthand borderImageShorthand()
97 {
98     static const CSSPropertyID borderImageProperties[] = {
99         CSSPropertyBorderImageSource,
100         CSSPropertyBorderImageSlice,
101         CSSPropertyBorderImageWidth,
102         CSSPropertyBorderImageOutset,
103         CSSPropertyBorderImageRepeat
104     };
105     return StylePropertyShorthand(CSSPropertyBorderImage, borderImageProperties, WTF_ARRAY_LENGTH(borderImageProperties));
106 }
107
108 StylePropertyShorthand borderLeftShorthand()
109 {
110     static const CSSPropertyID borderLeftProperties[] = { CSSPropertyBorderLeftWidth, CSSPropertyBorderLeftStyle, CSSPropertyBorderLeftColor };
111     return StylePropertyShorthand(CSSPropertyBorderLeft, borderLeftProperties, WTF_ARRAY_LENGTH(borderLeftProperties));
112 }
113
114 StylePropertyShorthand borderRadiusShorthand()
115 {
116     static const CSSPropertyID borderRadiusProperties[] = {
117         CSSPropertyBorderTopLeftRadius,
118         CSSPropertyBorderTopRightRadius,
119         CSSPropertyBorderBottomRightRadius,
120         CSSPropertyBorderBottomLeftRadius
121     };
122     return StylePropertyShorthand(CSSPropertyBorderRadius, borderRadiusProperties, WTF_ARRAY_LENGTH(borderRadiusProperties));
123 }
124
125 StylePropertyShorthand webkitBorderRadiusShorthand()
126 {
127     static const CSSPropertyID borderRadiusProperties[] = {
128         CSSPropertyBorderTopLeftRadius,
129         CSSPropertyBorderTopRightRadius,
130         CSSPropertyBorderBottomRightRadius,
131         CSSPropertyBorderBottomLeftRadius
132     };
133     return StylePropertyShorthand(CSSPropertyWebkitBorderRadius, borderRadiusProperties, WTF_ARRAY_LENGTH(borderRadiusProperties));
134 }
135
136 StylePropertyShorthand borderRightShorthand()
137 {
138     static const CSSPropertyID borderRightProperties[] = { CSSPropertyBorderRightWidth, CSSPropertyBorderRightStyle, CSSPropertyBorderRightColor };
139     return StylePropertyShorthand(CSSPropertyBorderRight, borderRightProperties, WTF_ARRAY_LENGTH(borderRightProperties));
140 }
141
142 StylePropertyShorthand borderSpacingShorthand()
143 {
144     static const CSSPropertyID borderSpacingProperties[] = { CSSPropertyWebkitBorderHorizontalSpacing, CSSPropertyWebkitBorderVerticalSpacing };
145     return StylePropertyShorthand(CSSPropertyBorderSpacing, borderSpacingProperties, WTF_ARRAY_LENGTH(borderSpacingProperties));
146 }
147
148 StylePropertyShorthand borderStyleShorthand()
149 {
150     static const CSSPropertyID borderStyleProperties[] = {
151         CSSPropertyBorderTopStyle,
152         CSSPropertyBorderRightStyle,
153         CSSPropertyBorderBottomStyle,
154         CSSPropertyBorderLeftStyle
155     };
156     return StylePropertyShorthand(CSSPropertyBorderStyle, borderStyleProperties, WTF_ARRAY_LENGTH(borderStyleProperties));
157 }
158
159 StylePropertyShorthand borderTopShorthand()
160 {
161     static const CSSPropertyID borderTopProperties[] = { CSSPropertyBorderTopWidth, CSSPropertyBorderTopStyle, CSSPropertyBorderTopColor };
162     return StylePropertyShorthand(CSSPropertyBorderTop, borderTopProperties, WTF_ARRAY_LENGTH(borderTopProperties));
163 }
164
165 StylePropertyShorthand borderWidthShorthand()
166 {
167     static const CSSPropertyID borderWidthProperties[] = {
168         CSSPropertyBorderTopWidth,
169         CSSPropertyBorderRightWidth,
170         CSSPropertyBorderBottomWidth,
171         CSSPropertyBorderLeftWidth
172     };
173     return StylePropertyShorthand(CSSPropertyBorderWidth, borderWidthProperties, WTF_ARRAY_LENGTH(borderWidthProperties));
174 }
175
176 StylePropertyShorthand listStyleShorthand()
177 {
178     static const CSSPropertyID listStyleProperties[] = {
179         CSSPropertyListStyleType,
180         CSSPropertyListStylePosition,
181         CSSPropertyListStyleImage
182     };
183     return StylePropertyShorthand(CSSPropertyListStyle, listStyleProperties, WTF_ARRAY_LENGTH(listStyleProperties));
184 }
185
186 StylePropertyShorthand fontShorthand()
187 {
188     static const CSSPropertyID fontProperties[] = {
189         CSSPropertyFontFamily,
190         CSSPropertyFontSize,
191         CSSPropertyFontStyle,
192         CSSPropertyFontVariant,
193         CSSPropertyFontWeight,
194         CSSPropertyLineHeight
195     };
196     return StylePropertyShorthand(CSSPropertyFont, fontProperties, WTF_ARRAY_LENGTH(fontProperties));
197 }
198
199 StylePropertyShorthand marginShorthand()
200 {
201     static const CSSPropertyID marginProperties[] = {
202         CSSPropertyMarginTop,
203         CSSPropertyMarginRight,
204         CSSPropertyMarginBottom,
205         CSSPropertyMarginLeft
206     };
207     return StylePropertyShorthand(CSSPropertyMargin, marginProperties, WTF_ARRAY_LENGTH(marginProperties));
208 }
209
210 #if ENABLE(SVG)
211 StylePropertyShorthand markerShorthand()
212 {
213     static const CSSPropertyID markerProperties[] = {
214         CSSPropertyMarkerStart,
215         CSSPropertyMarkerMid,
216         CSSPropertyMarkerEnd
217     };
218     return StylePropertyShorthand(CSSPropertyMarker, markerProperties, WTF_ARRAY_LENGTH(markerProperties));
219 }
220 #endif
221
222 StylePropertyShorthand outlineShorthand()
223 {
224     static const CSSPropertyID outlineProperties[] = {
225         CSSPropertyOutlineColor,
226         CSSPropertyOutlineStyle,
227         CSSPropertyOutlineWidth
228     };
229     return StylePropertyShorthand(CSSPropertyOutline, outlineProperties, WTF_ARRAY_LENGTH(outlineProperties));
230 }
231
232 StylePropertyShorthand overflowShorthand()
233 {
234     static const CSSPropertyID overflowProperties[] = { CSSPropertyOverflowX, CSSPropertyOverflowY };
235     return StylePropertyShorthand(CSSPropertyOverflow, overflowProperties, WTF_ARRAY_LENGTH(overflowProperties));
236 }
237
238 StylePropertyShorthand paddingShorthand()
239 {
240     static const CSSPropertyID paddingProperties[] = {
241         CSSPropertyPaddingTop,
242         CSSPropertyPaddingRight,
243         CSSPropertyPaddingBottom,
244         CSSPropertyPaddingLeft
245     };
246     return StylePropertyShorthand(CSSPropertyPadding, paddingProperties, WTF_ARRAY_LENGTH(paddingProperties));
247 }
248
249 StylePropertyShorthand transitionShorthand()
250 {
251     static const CSSPropertyID transitionProperties[] = {
252         CSSPropertyTransitionProperty,
253         CSSPropertyTransitionDuration,
254         CSSPropertyTransitionTimingFunction,
255         CSSPropertyTransitionDelay
256     };
257     return StylePropertyShorthand(CSSPropertyTransition, transitionProperties, WTF_ARRAY_LENGTH(transitionProperties));
258 }
259
260 StylePropertyShorthand webkitAnimationShorthand()
261 {
262     static const CSSPropertyID animationProperties[] = {
263         CSSPropertyWebkitAnimationName,
264         CSSPropertyWebkitAnimationDuration,
265         CSSPropertyWebkitAnimationTimingFunction,
266         CSSPropertyWebkitAnimationDelay,
267         CSSPropertyWebkitAnimationIterationCount,
268         CSSPropertyWebkitAnimationDirection,
269         CSSPropertyWebkitAnimationFillMode
270     };
271     return StylePropertyShorthand(CSSPropertyWebkitAnimation, animationProperties, WTF_ARRAY_LENGTH(animationProperties));
272 }
273
274 StylePropertyShorthand webkitAnimationShorthandForParsing()
275 {
276     // When we parse the animation shorthand we need to look for animation-name
277     // last because otherwise it might match against the keywords for fill mode,
278     // timing functions and infinite iteration. This means that animation names
279     // that are the same as keywords (e.g. 'forwards') won't always match in the
280     // shorthand. In that case the authors should be using longhands (or
281     // reconsidering their approach). This is covered by the animations spec
282     // bug: https://www.w3.org/Bugs/Public/show_bug.cgi?id=14790
283     // And in the spec (editor's draft) at:
284     // http://dev.w3.org/csswg/css3-animations/#animation-shorthand-property
285     static const CSSPropertyID animationPropertiesForParsing[] = {
286         CSSPropertyWebkitAnimationDuration,
287         CSSPropertyWebkitAnimationTimingFunction,
288         CSSPropertyWebkitAnimationDelay,
289         CSSPropertyWebkitAnimationIterationCount,
290         CSSPropertyWebkitAnimationDirection,
291         CSSPropertyWebkitAnimationFillMode,
292         CSSPropertyWebkitAnimationName
293     };
294
295     return StylePropertyShorthand(CSSPropertyWebkitAnimation, animationPropertiesForParsing, WTF_ARRAY_LENGTH(animationPropertiesForParsing));
296 }
297
298 StylePropertyShorthand webkitBorderAfterShorthand()
299 {
300     static const CSSPropertyID borderAfterProperties[] = { CSSPropertyWebkitBorderAfterWidth, CSSPropertyWebkitBorderAfterStyle, CSSPropertyWebkitBorderAfterColor  };
301     return StylePropertyShorthand(CSSPropertyWebkitBorderAfter, borderAfterProperties, WTF_ARRAY_LENGTH(borderAfterProperties));
302 }
303
304 StylePropertyShorthand webkitBorderBeforeShorthand()
305 {
306     static const CSSPropertyID borderBeforeProperties[] = { CSSPropertyWebkitBorderBeforeWidth, CSSPropertyWebkitBorderBeforeStyle, CSSPropertyWebkitBorderBeforeColor  };
307     return StylePropertyShorthand(CSSPropertyWebkitBorderBefore, borderBeforeProperties, WTF_ARRAY_LENGTH(borderBeforeProperties));
308 }
309
310 StylePropertyShorthand webkitBorderEndShorthand()
311 {
312     static const CSSPropertyID borderEndProperties[] = { CSSPropertyWebkitBorderEndWidth, CSSPropertyWebkitBorderEndStyle, CSSPropertyWebkitBorderEndColor };
313     return StylePropertyShorthand(CSSPropertyWebkitBorderEnd, borderEndProperties, WTF_ARRAY_LENGTH(borderEndProperties));
314 }
315
316 StylePropertyShorthand webkitBorderStartShorthand()
317 {
318     static const CSSPropertyID borderStartProperties[] = { CSSPropertyWebkitBorderStartWidth, CSSPropertyWebkitBorderStartStyle, CSSPropertyWebkitBorderStartColor };
319     return StylePropertyShorthand(CSSPropertyWebkitBorderStart, borderStartProperties, WTF_ARRAY_LENGTH(borderStartProperties));
320 }
321
322 StylePropertyShorthand webkitColumnsShorthand()
323 {
324     static const CSSPropertyID columnsProperties[] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount };
325     return StylePropertyShorthand(CSSPropertyWebkitColumns, columnsProperties, WTF_ARRAY_LENGTH(columnsProperties));
326 }
327
328 StylePropertyShorthand webkitColumnRuleShorthand()
329 {
330     static const CSSPropertyID columnRuleProperties[] = {
331         CSSPropertyWebkitColumnRuleWidth,
332         CSSPropertyWebkitColumnRuleStyle,
333         CSSPropertyWebkitColumnRuleColor,
334     };
335     return StylePropertyShorthand(CSSPropertyWebkitColumnRule, columnRuleProperties, WTF_ARRAY_LENGTH(columnRuleProperties));
336 }
337
338 StylePropertyShorthand webkitFlexFlowShorthand()
339 {
340     static const CSSPropertyID flexFlowProperties[] = { CSSPropertyWebkitFlexDirection, CSSPropertyWebkitFlexWrap };
341     return StylePropertyShorthand(CSSPropertyWebkitFlexFlow, flexFlowProperties, WTF_ARRAY_LENGTH(flexFlowProperties));
342 }
343
344 StylePropertyShorthand webkitFlexShorthand()
345 {
346     static const CSSPropertyID flexProperties[] = { CSSPropertyWebkitFlexGrow, CSSPropertyWebkitFlexShrink, CSSPropertyWebkitFlexBasis };
347     return StylePropertyShorthand(CSSPropertyWebkitFlex, flexProperties, WTF_ARRAY_LENGTH(flexProperties));
348 }
349
350 StylePropertyShorthand webkitMarginCollapseShorthand()
351 {
352     static const CSSPropertyID marginCollapseProperties[] = { CSSPropertyWebkitMarginBeforeCollapse, CSSPropertyWebkitMarginAfterCollapse };
353     return StylePropertyShorthand(CSSPropertyWebkitMarginCollapse, marginCollapseProperties, WTF_ARRAY_LENGTH(marginCollapseProperties));
354 }
355
356 StylePropertyShorthand webkitGridAreaShorthand()
357 {
358     static const CSSPropertyID webkitGridAreaProperties[] = {
359         CSSPropertyWebkitGridRowStart,
360         CSSPropertyWebkitGridColumnStart,
361         CSSPropertyWebkitGridRowEnd,
362         CSSPropertyWebkitGridColumnEnd
363     };
364     return StylePropertyShorthand(CSSPropertyWebkitGridArea, webkitGridAreaProperties, WTF_ARRAY_LENGTH(webkitGridAreaProperties));
365 }
366
367 StylePropertyShorthand webkitGridColumnShorthand()
368 {
369     static const CSSPropertyID webkitGridColumnProperties[] = {
370         CSSPropertyWebkitGridColumnStart,
371         CSSPropertyWebkitGridColumnEnd
372     };
373     return StylePropertyShorthand(CSSPropertyWebkitGridColumn, webkitGridColumnProperties, WTF_ARRAY_LENGTH(webkitGridColumnProperties));
374
375 }
376
377 StylePropertyShorthand webkitGridRowShorthand()
378 {
379     static const CSSPropertyID webkitGridRowProperties[] = {
380         CSSPropertyWebkitGridRowStart,
381         CSSPropertyWebkitGridRowEnd
382     };
383     return StylePropertyShorthand(CSSPropertyWebkitGridRow, webkitGridRowProperties, WTF_ARRAY_LENGTH(webkitGridRowProperties));
384
385 }
386
387 StylePropertyShorthand webkitMarqueeShorthand()
388 {
389     static const CSSPropertyID marqueeProperties[] = {
390         CSSPropertyWebkitMarqueeDirection,
391         CSSPropertyWebkitMarqueeIncrement,
392         CSSPropertyWebkitMarqueeRepetition,
393         CSSPropertyWebkitMarqueeStyle,
394         CSSPropertyWebkitMarqueeSpeed
395     };
396     return StylePropertyShorthand(CSSPropertyWebkitMarquee, marqueeProperties, WTF_ARRAY_LENGTH(marqueeProperties));
397 }
398
399 StylePropertyShorthand webkitMaskShorthand()
400 {
401     static const CSSPropertyID maskProperties[] = {
402         CSSPropertyWebkitMaskImage,
403         CSSPropertyWebkitMaskSourceType,
404         CSSPropertyWebkitMaskPositionX,
405         CSSPropertyWebkitMaskPositionY,
406         CSSPropertyWebkitMaskSize,
407         CSSPropertyWebkitMaskRepeatX,
408         CSSPropertyWebkitMaskRepeatY,
409         CSSPropertyWebkitMaskOrigin,
410         CSSPropertyWebkitMaskClip
411     };
412     return StylePropertyShorthand(CSSPropertyWebkitMask, maskProperties, WTF_ARRAY_LENGTH(maskProperties));
413 }
414
415 StylePropertyShorthand webkitMaskPositionShorthand()
416 {
417     static const CSSPropertyID maskPositionProperties[] = { CSSPropertyWebkitMaskPositionX, CSSPropertyWebkitMaskPositionY };
418     return StylePropertyShorthand(CSSPropertyWebkitMaskPosition, maskPositionProperties, WTF_ARRAY_LENGTH(maskPositionProperties));
419 }
420
421 StylePropertyShorthand webkitMaskRepeatShorthand()
422 {
423     static const CSSPropertyID maskRepeatProperties[] = { CSSPropertyWebkitMaskRepeatX, CSSPropertyWebkitMaskRepeatY };
424     return StylePropertyShorthand(CSSPropertyWebkitMaskRepeat, maskRepeatProperties, WTF_ARRAY_LENGTH(maskRepeatProperties));
425 }
426
427 #if ENABLE(CSS3_TEXT)
428 StylePropertyShorthand webkitTextDecorationShorthand()
429 {
430     static const CSSPropertyID textDecorationProperties[] = {
431         CSSPropertyWebkitTextDecorationLine,
432         CSSPropertyWebkitTextDecorationStyle,
433         CSSPropertyWebkitTextDecorationColor
434     };
435     return StylePropertyShorthand(CSSPropertyWebkitTextDecoration, textDecorationProperties, WTF_ARRAY_LENGTH(textDecorationProperties));
436 }
437 #endif
438
439 StylePropertyShorthand webkitTextEmphasisShorthand()
440 {
441     static const CSSPropertyID textEmphasisProperties[] = {
442         CSSPropertyWebkitTextEmphasisStyle,
443         CSSPropertyWebkitTextEmphasisColor
444     };
445     return StylePropertyShorthand(CSSPropertyWebkitTextEmphasis, textEmphasisProperties, WTF_ARRAY_LENGTH(textEmphasisProperties));
446 }
447
448 StylePropertyShorthand webkitTextStrokeShorthand()
449 {
450     static const CSSPropertyID textStrokeProperties[] = { CSSPropertyWebkitTextStrokeWidth, CSSPropertyWebkitTextStrokeColor };
451     return StylePropertyShorthand(CSSPropertyWebkitTextStroke, textStrokeProperties, WTF_ARRAY_LENGTH(textStrokeProperties));
452 }
453
454 StylePropertyShorthand webkitTransitionShorthand()
455 {
456     static const CSSPropertyID transitionProperties[] = {
457         CSSPropertyWebkitTransitionProperty,
458         CSSPropertyWebkitTransitionDuration,
459         CSSPropertyWebkitTransitionTimingFunction,
460         CSSPropertyWebkitTransitionDelay
461     };
462     return StylePropertyShorthand(CSSPropertyWebkitTransition, transitionProperties, WTF_ARRAY_LENGTH(transitionProperties));
463 }
464
465 StylePropertyShorthand webkitTransformOriginShorthand()
466 {
467     static const CSSPropertyID transformOriginProperties[] = {
468         CSSPropertyWebkitTransformOriginX,
469         CSSPropertyWebkitTransformOriginY,
470         CSSPropertyWebkitTransformOriginZ
471     };
472     return StylePropertyShorthand(CSSPropertyWebkitTransformOrigin, transformOriginProperties, WTF_ARRAY_LENGTH(transformOriginProperties));
473 }
474
475 StylePropertyShorthand widthShorthand()
476 {
477     static const CSSPropertyID widthProperties[] = {
478         CSSPropertyMinWidth,
479         CSSPropertyMaxWidth
480     };
481     return StylePropertyShorthand(CSSPropertyWidth, widthProperties, WTF_ARRAY_LENGTH(widthProperties));
482 }
483
484 StylePropertyShorthand heightShorthand()
485 {
486     static const CSSPropertyID heightProperties[] = {
487         CSSPropertyMinHeight,
488         CSSPropertyMaxHeight
489     };
490     return StylePropertyShorthand(CSSPropertyHeight, heightProperties, WTF_ARRAY_LENGTH(heightProperties));
491 }
492
493 // Returns an empty list if the property is not a shorthand.
494 StylePropertyShorthand shorthandForProperty(CSSPropertyID propertyID)
495 {
496     switch (propertyID) {
497     case CSSPropertyBackground:
498         return backgroundShorthand();
499     case CSSPropertyBackgroundPosition:
500         return backgroundPositionShorthand();
501     case CSSPropertyBackgroundRepeat:
502         return backgroundRepeatShorthand();
503     case CSSPropertyBorder:
504         return borderShorthand();
505     case CSSPropertyBorderBottom:
506         return borderBottomShorthand();
507     case CSSPropertyBorderColor:
508         return borderColorShorthand();
509     case CSSPropertyBorderImage:
510         return borderImageShorthand();
511     case CSSPropertyBorderLeft:
512         return borderLeftShorthand();
513     case CSSPropertyBorderRadius:
514         return borderRadiusShorthand();
515     case CSSPropertyBorderRight:
516         return borderRightShorthand();
517     case CSSPropertyBorderSpacing:
518         return borderSpacingShorthand();
519     case CSSPropertyBorderStyle:
520         return borderStyleShorthand();
521     case CSSPropertyBorderTop:
522         return borderTopShorthand();
523     case CSSPropertyBorderWidth:
524         return borderWidthShorthand();
525     case CSSPropertyListStyle:
526         return listStyleShorthand();
527     case CSSPropertyFont:
528         return fontShorthand();
529     case CSSPropertyMargin:
530         return marginShorthand();
531     case CSSPropertyOutline:
532         return outlineShorthand();
533     case CSSPropertyOverflow:
534         return overflowShorthand();
535     case CSSPropertyPadding:
536         return paddingShorthand();
537     case CSSPropertyTransition:
538         return transitionShorthand();
539     case CSSPropertyWebkitAnimation:
540         return webkitAnimationShorthand();
541     case CSSPropertyWebkitBorderAfter:
542         return webkitBorderAfterShorthand();
543     case CSSPropertyWebkitBorderBefore:
544         return webkitBorderBeforeShorthand();
545     case CSSPropertyWebkitBorderEnd:
546         return webkitBorderEndShorthand();
547     case CSSPropertyWebkitBorderStart:
548         return webkitBorderStartShorthand();
549     case CSSPropertyWebkitBorderRadius:
550         return borderRadiusShorthand();
551     case CSSPropertyWebkitColumns:
552         return webkitColumnsShorthand();
553     case CSSPropertyWebkitColumnRule:
554         return webkitColumnRuleShorthand();
555     case CSSPropertyWebkitFlex:
556         return webkitFlexShorthand();
557     case CSSPropertyWebkitFlexFlow:
558         return webkitFlexFlowShorthand();
559     case CSSPropertyWebkitGridArea:
560         return webkitGridAreaShorthand();
561     case CSSPropertyWebkitGridColumn:
562         return webkitGridColumnShorthand();
563     case CSSPropertyWebkitGridRow:
564         return webkitGridRowShorthand();
565     case CSSPropertyWebkitMarginCollapse:
566         return webkitMarginCollapseShorthand();
567     case CSSPropertyWebkitMarquee:
568         return webkitMarqueeShorthand();
569     case CSSPropertyWebkitMask:
570         return webkitMaskShorthand();
571     case CSSPropertyWebkitMaskPosition:
572         return webkitMaskPositionShorthand();
573     case CSSPropertyWebkitMaskRepeat:
574         return webkitMaskRepeatShorthand();
575     case CSSPropertyWebkitTextEmphasis:
576         return webkitTextEmphasisShorthand();
577     case CSSPropertyWebkitTextStroke:
578         return webkitTextStrokeShorthand();
579     case CSSPropertyWebkitTransition:
580         return webkitTransitionShorthand();
581     case CSSPropertyWebkitTransformOrigin:
582         return webkitTransformOriginShorthand();
583 #if ENABLE(CSS3_TEXT)
584     case CSSPropertyWebkitTextDecoration:
585         return webkitTextDecorationShorthand();
586 #endif
587 #if ENABLE(SVG)
588     case CSSPropertyMarker:
589         return markerShorthand();
590 #endif
591     default:
592         return StylePropertyShorthand();
593     }
594 }
595
596 bool isExpandedShorthand(CSSPropertyID id)
597 {
598     // The system fonts bypass the normal style resolution by using RenderTheme,
599     // thus we need to special case it here. FIXME: This is a violation of CSS 3 Fonts
600     // as we should still be able to change the longhands.
601     // DON'T ADD ANY SHORTHAND HERE UNLESS IT ISN'T ALWAYS EXPANDED AT PARSE TIME (which is wrong).
602     if (id == CSSPropertyFont)
603         return false;
604
605     return shorthandForProperty(id).length();
606 }
607
608 static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a)
609 {
610     return Vector<StylePropertyShorthand>(1, a);
611 }
612
613 static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a, const StylePropertyShorthand& b)
614 {
615     Vector<StylePropertyShorthand> vector;
616     vector.reserveInitialCapacity(2);
617     vector.uncheckedAppend(a);
618     vector.uncheckedAppend(b);
619     return vector;
620 }
621
622 static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a, const StylePropertyShorthand& b, const StylePropertyShorthand& c)
623 {
624     Vector<StylePropertyShorthand> vector;
625     vector.reserveInitialCapacity(3);
626     vector.uncheckedAppend(a);
627     vector.uncheckedAppend(b);
628     vector.uncheckedAppend(c);
629     return vector;
630 }
631
632 Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID propertyID)
633 {
634     switch (propertyID) {
635     case CSSPropertyBackgroundImage:
636     case CSSPropertyBackgroundSize:
637     case CSSPropertyBackgroundAttachment:
638     case CSSPropertyBackgroundOrigin:
639     case CSSPropertyBackgroundClip:
640     case CSSPropertyBackgroundColor:
641         return makeVector(backgroundShorthand());
642     case CSSPropertyBackgroundPositionX:
643     case CSSPropertyBackgroundPositionY:
644         return makeVector(backgroundShorthand(), backgroundPositionShorthand());
645     case CSSPropertyBackgroundRepeatX:
646     case CSSPropertyBackgroundRepeatY:
647         return makeVector(backgroundShorthand(), backgroundRepeatShorthand());
648     case CSSPropertyBorderBottomWidth:
649         return makeVector(borderShorthand(), borderBottomShorthand(), borderWidthShorthand());
650     case CSSPropertyBorderTopColor:
651         return makeVector(borderShorthand(), borderTopShorthand(), borderColorShorthand());
652     case CSSPropertyBorderRightColor:
653         return makeVector(borderShorthand(), borderRightShorthand(), borderColorShorthand());
654     case CSSPropertyBorderLeftColor:
655         return makeVector(borderShorthand(), borderLeftShorthand(), borderColorShorthand());
656     case CSSPropertyBorderBottomColor:
657         return makeVector(borderShorthand(), borderBottomShorthand(), borderColorShorthand());
658     case CSSPropertyBorderImageSource:
659     case CSSPropertyBorderImageSlice:
660     case CSSPropertyBorderImageWidth:
661     case CSSPropertyBorderImageOutset:
662     case CSSPropertyBorderImageRepeat:
663         return makeVector(borderImageShorthand());
664     case CSSPropertyBorderLeftWidth:
665         return makeVector(borderShorthand(), borderLeftShorthand(), borderWidthShorthand());
666     case CSSPropertyBorderTopLeftRadius:
667     case CSSPropertyBorderTopRightRadius:
668     case CSSPropertyBorderBottomRightRadius:
669     case CSSPropertyBorderBottomLeftRadius:
670         return makeVector(borderRadiusShorthand(), webkitBorderRadiusShorthand());
671     case CSSPropertyBorderRightWidth:
672         return makeVector(borderShorthand(), borderRightShorthand(), borderWidthShorthand());
673     case CSSPropertyWebkitBorderHorizontalSpacing:
674     case CSSPropertyWebkitBorderVerticalSpacing:
675         return makeVector(borderSpacingShorthand());
676     case CSSPropertyBorderTopStyle:
677         return makeVector(borderShorthand(), borderTopShorthand(), borderStyleShorthand());
678     case CSSPropertyBorderBottomStyle:
679         return makeVector(borderShorthand(), borderBottomShorthand(), borderStyleShorthand());
680     case CSSPropertyBorderLeftStyle:
681         return makeVector(borderShorthand(), borderLeftShorthand(), borderStyleShorthand());
682     case CSSPropertyBorderRightStyle:
683         return makeVector(borderShorthand(), borderRightShorthand(), borderStyleShorthand());
684     case CSSPropertyBorderTopWidth:
685         return makeVector(borderShorthand(), borderTopShorthand(), borderWidthShorthand());
686     case CSSPropertyListStyleType:
687     case CSSPropertyListStylePosition:
688     case CSSPropertyListStyleImage:
689         return makeVector(listStyleShorthand());
690     case CSSPropertyFontFamily:
691     case CSSPropertyFontSize:
692     case CSSPropertyFontStyle:
693     case CSSPropertyFontVariant:
694     case CSSPropertyFontWeight:
695     case CSSPropertyLineHeight:
696         return makeVector(fontShorthand());
697     case CSSPropertyMarginTop:
698     case CSSPropertyMarginRight:
699     case CSSPropertyMarginBottom:
700     case CSSPropertyMarginLeft:
701         return makeVector(marginShorthand());
702     case CSSPropertyOutlineColor:
703     case CSSPropertyOutlineStyle:
704     case CSSPropertyOutlineWidth:
705         return makeVector(outlineShorthand());
706     case CSSPropertyPaddingTop:
707     case CSSPropertyPaddingRight:
708     case CSSPropertyPaddingBottom:
709     case CSSPropertyPaddingLeft:
710         return makeVector(paddingShorthand());
711     case CSSPropertyOverflowX:
712     case CSSPropertyOverflowY:
713         return makeVector(overflowShorthand());
714     case CSSPropertyTransitionProperty:
715     case CSSPropertyTransitionDuration:
716     case CSSPropertyTransitionTimingFunction:
717     case CSSPropertyTransitionDelay:
718         return makeVector(transitionShorthand());
719     case CSSPropertyWebkitAnimationName:
720     case CSSPropertyWebkitAnimationDuration:
721     case CSSPropertyWebkitAnimationTimingFunction:
722     case CSSPropertyWebkitAnimationDelay:
723     case CSSPropertyWebkitAnimationIterationCount:
724     case CSSPropertyWebkitAnimationDirection:
725     case CSSPropertyWebkitAnimationFillMode:
726         return makeVector(webkitAnimationShorthand());
727     case CSSPropertyWebkitBorderAfterWidth:
728     case CSSPropertyWebkitBorderAfterStyle:
729     case CSSPropertyWebkitBorderAfterColor:
730         return makeVector(webkitBorderAfterShorthand());
731     case CSSPropertyWebkitBorderBeforeWidth:
732     case CSSPropertyWebkitBorderBeforeStyle:
733     case CSSPropertyWebkitBorderBeforeColor:
734         return makeVector(webkitBorderBeforeShorthand());
735     case CSSPropertyWebkitBorderEndWidth:
736     case CSSPropertyWebkitBorderEndStyle:
737     case CSSPropertyWebkitBorderEndColor:
738         return makeVector(webkitBorderEndShorthand());
739     case CSSPropertyWebkitBorderStartWidth:
740     case CSSPropertyWebkitBorderStartStyle:
741     case CSSPropertyWebkitBorderStartColor:
742         return makeVector(webkitBorderStartShorthand());
743     case CSSPropertyWebkitColumnWidth:
744     case CSSPropertyWebkitColumnCount:
745         return makeVector(webkitColumnsShorthand());
746     case CSSPropertyWebkitColumnRuleWidth:
747     case CSSPropertyWebkitColumnRuleStyle:
748     case CSSPropertyWebkitColumnRuleColor:
749         return makeVector(webkitColumnRuleShorthand());
750     case CSSPropertyWebkitFlexGrow:
751     case CSSPropertyWebkitFlexShrink:
752     case CSSPropertyWebkitFlexBasis:
753         return makeVector(webkitFlexShorthand());
754     case CSSPropertyWebkitFlexDirection:
755     case CSSPropertyWebkitFlexWrap:
756         return makeVector(webkitFlexFlowShorthand());
757     case CSSPropertyWebkitGridColumnStart:
758     case CSSPropertyWebkitGridColumnEnd:
759         return makeVector(webkitGridColumnShorthand());
760     case CSSPropertyWebkitGridRowStart:
761     case CSSPropertyWebkitGridRowEnd:
762         return makeVector(webkitGridRowShorthand());
763     case CSSPropertyWebkitMarginBeforeCollapse:
764     case CSSPropertyWebkitMarginAfterCollapse:
765         return makeVector(webkitMarginCollapseShorthand());
766     case CSSPropertyWebkitMarqueeDirection:
767     case CSSPropertyWebkitMarqueeIncrement:
768     case CSSPropertyWebkitMarqueeRepetition:
769     case CSSPropertyWebkitMarqueeStyle:
770     case CSSPropertyWebkitMarqueeSpeed:
771         return makeVector(webkitMarqueeShorthand());
772     case CSSPropertyWebkitMaskImage:
773     case CSSPropertyWebkitMaskSourceType:
774     case CSSPropertyWebkitMaskSize:
775     case CSSPropertyWebkitMaskOrigin:
776     case CSSPropertyWebkitMaskClip:
777         return makeVector(webkitMaskShorthand());
778     case CSSPropertyWebkitMaskPositionX:
779     case CSSPropertyWebkitMaskPositionY:
780         return makeVector(webkitMaskPositionShorthand());
781     case CSSPropertyWebkitMaskRepeatX:
782     case CSSPropertyWebkitMaskRepeatY:
783         return makeVector(webkitMaskRepeatShorthand());
784     case CSSPropertyWebkitTextEmphasisStyle:
785     case CSSPropertyWebkitTextEmphasisColor:
786         return makeVector(webkitTextEmphasisShorthand());
787     case CSSPropertyWebkitTextStrokeWidth:
788     case CSSPropertyWebkitTextStrokeColor:
789         return makeVector(webkitTextStrokeShorthand());
790     case CSSPropertyWebkitTransitionProperty:
791     case CSSPropertyWebkitTransitionDuration:
792     case CSSPropertyWebkitTransitionTimingFunction:
793     case CSSPropertyWebkitTransitionDelay:
794         return makeVector(webkitTransitionShorthand());
795     case CSSPropertyWebkitTransformOriginX:
796     case CSSPropertyWebkitTransformOriginY:
797     case CSSPropertyWebkitTransformOriginZ:
798         return makeVector(webkitTransformOriginShorthand());
799     case CSSPropertyMinWidth:
800     case CSSPropertyMaxWidth:
801         return makeVector(widthShorthand());
802     case CSSPropertyMinHeight:
803     case CSSPropertyMaxHeight:
804         return makeVector(heightShorthand());
805 #if ENABLE(CSS3_TEXT)
806     case CSSPropertyWebkitTextDecorationLine:
807     case CSSPropertyWebkitTextDecorationStyle:
808     case CSSPropertyWebkitTextDecorationColor:
809         return makeVector(webkitTextDecorationShorthand());
810 #endif
811 #if ENABLE(SVG)
812     case CSSPropertyMarkerStart:
813     case CSSPropertyMarkerMid:
814     case CSSPropertyMarkerEnd:
815         return makeVector(markerShorthand());
816 #endif
817     default:
818         break;
819     }
820
821     return Vector<StylePropertyShorthand>();
822 }
823
824 unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand>& shorthands)
825 {
826     for (unsigned i = 0, size = shorthands.size(); i < size; ++i) {
827         if (shorthands[i].id() == shorthandID)
828             return i;
829     }
830     ASSERT_NOT_REACHED();
831     return 0;
832 }
833
834 } // namespace WebCore