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