[CSS Grid Layout] Implementation of the grid-template shorthand.
[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 StylePropertyShorthand 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
220 StylePropertyShorthand 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
230 StylePropertyShorthand overflowShorthand()
231 {
232     static const CSSPropertyID overflowProperties[] = { CSSPropertyOverflowX, CSSPropertyOverflowY };
233     return StylePropertyShorthand(CSSPropertyOverflow, overflowProperties, WTF_ARRAY_LENGTH(overflowProperties));
234 }
235
236 StylePropertyShorthand 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
247 StylePropertyShorthand 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
258 StylePropertyShorthand 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
272 StylePropertyShorthand 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
296 StylePropertyShorthand webkitBorderAfterShorthand()
297 {
298     static const CSSPropertyID borderAfterProperties[] = { CSSPropertyWebkitBorderAfterWidth, CSSPropertyWebkitBorderAfterStyle, CSSPropertyWebkitBorderAfterColor  };
299     return StylePropertyShorthand(CSSPropertyWebkitBorderAfter, borderAfterProperties, WTF_ARRAY_LENGTH(borderAfterProperties));
300 }
301
302 StylePropertyShorthand webkitBorderBeforeShorthand()
303 {
304     static const CSSPropertyID borderBeforeProperties[] = { CSSPropertyWebkitBorderBeforeWidth, CSSPropertyWebkitBorderBeforeStyle, CSSPropertyWebkitBorderBeforeColor  };
305     return StylePropertyShorthand(CSSPropertyWebkitBorderBefore, borderBeforeProperties, WTF_ARRAY_LENGTH(borderBeforeProperties));
306 }
307
308 StylePropertyShorthand webkitBorderEndShorthand()
309 {
310     static const CSSPropertyID borderEndProperties[] = { CSSPropertyWebkitBorderEndWidth, CSSPropertyWebkitBorderEndStyle, CSSPropertyWebkitBorderEndColor };
311     return StylePropertyShorthand(CSSPropertyWebkitBorderEnd, borderEndProperties, WTF_ARRAY_LENGTH(borderEndProperties));
312 }
313
314 StylePropertyShorthand webkitBorderStartShorthand()
315 {
316     static const CSSPropertyID borderStartProperties[] = { CSSPropertyWebkitBorderStartWidth, CSSPropertyWebkitBorderStartStyle, CSSPropertyWebkitBorderStartColor };
317     return StylePropertyShorthand(CSSPropertyWebkitBorderStart, borderStartProperties, WTF_ARRAY_LENGTH(borderStartProperties));
318 }
319
320 StylePropertyShorthand webkitColumnsShorthand()
321 {
322     static const CSSPropertyID columnsProperties[] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount };
323     return StylePropertyShorthand(CSSPropertyWebkitColumns, columnsProperties, WTF_ARRAY_LENGTH(columnsProperties));
324 }
325
326 StylePropertyShorthand 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
336 StylePropertyShorthand webkitFlexFlowShorthand()
337 {
338     static const CSSPropertyID flexFlowProperties[] = { CSSPropertyWebkitFlexDirection, CSSPropertyWebkitFlexWrap };
339     return StylePropertyShorthand(CSSPropertyWebkitFlexFlow, flexFlowProperties, WTF_ARRAY_LENGTH(flexFlowProperties));
340 }
341
342 StylePropertyShorthand webkitFlexShorthand()
343 {
344     static const CSSPropertyID flexProperties[] = { CSSPropertyWebkitFlexGrow, CSSPropertyWebkitFlexShrink, CSSPropertyWebkitFlexBasis };
345     return StylePropertyShorthand(CSSPropertyWebkitFlex, flexProperties, WTF_ARRAY_LENGTH(flexProperties));
346 }
347
348 StylePropertyShorthand 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)
355 StylePropertyShorthand webkitGridTemplateShorthand()
356 {
357     static const CSSPropertyID webkitGridTemplateProperties[] = {
358         CSSPropertyWebkitGridTemplateColumns,
359         CSSPropertyWebkitGridTemplateRows,
360         CSSPropertyWebkitGridTemplateAreas
361     };
362     return StylePropertyShorthand(CSSPropertyWebkitGridTemplate, webkitGridTemplateProperties, WTF_ARRAY_LENGTH(webkitGridTemplateProperties));
363 }
364
365 StylePropertyShorthand webkitGridAreaShorthand()
366 {
367     static const CSSPropertyID webkitGridAreaProperties[] = {
368         CSSPropertyWebkitGridRowStart,
369         CSSPropertyWebkitGridColumnStart,
370         CSSPropertyWebkitGridRowEnd,
371         CSSPropertyWebkitGridColumnEnd
372     };
373     return StylePropertyShorthand(CSSPropertyWebkitGridArea, webkitGridAreaProperties, WTF_ARRAY_LENGTH(webkitGridAreaProperties));
374 }
375
376 StylePropertyShorthand webkitGridColumnShorthand()
377 {
378     static const CSSPropertyID webkitGridColumnProperties[] = {
379         CSSPropertyWebkitGridColumnStart,
380         CSSPropertyWebkitGridColumnEnd
381     };
382     return StylePropertyShorthand(CSSPropertyWebkitGridColumn, webkitGridColumnProperties, WTF_ARRAY_LENGTH(webkitGridColumnProperties));
383
384 }
385
386 StylePropertyShorthand webkitGridRowShorthand()
387 {
388     static const CSSPropertyID webkitGridRowProperties[] = {
389         CSSPropertyWebkitGridRowStart,
390         CSSPropertyWebkitGridRowEnd
391     };
392     return StylePropertyShorthand(CSSPropertyWebkitGridRow, webkitGridRowProperties, WTF_ARRAY_LENGTH(webkitGridRowProperties));
393
394 }
395 #endif /* ENABLE(CSS_GRID_LAYOUT) */
396
397 StylePropertyShorthand webkitMarqueeShorthand()
398 {
399     static const CSSPropertyID marqueeProperties[] = {
400         CSSPropertyWebkitMarqueeDirection,
401         CSSPropertyWebkitMarqueeIncrement,
402         CSSPropertyWebkitMarqueeRepetition,
403         CSSPropertyWebkitMarqueeStyle,
404         CSSPropertyWebkitMarqueeSpeed
405     };
406     return StylePropertyShorthand(CSSPropertyWebkitMarquee, marqueeProperties, WTF_ARRAY_LENGTH(marqueeProperties));
407 }
408
409 StylePropertyShorthand webkitMaskShorthand()
410 {
411     static const CSSPropertyID maskProperties[] = {
412         CSSPropertyWebkitMaskImage,
413         CSSPropertyWebkitMaskSourceType,
414         CSSPropertyWebkitMaskPositionX,
415         CSSPropertyWebkitMaskPositionY,
416         CSSPropertyWebkitMaskSize,
417         CSSPropertyWebkitMaskRepeatX,
418         CSSPropertyWebkitMaskRepeatY,
419         CSSPropertyWebkitMaskOrigin,
420         CSSPropertyWebkitMaskClip
421     };
422     return StylePropertyShorthand(CSSPropertyWebkitMask, maskProperties, WTF_ARRAY_LENGTH(maskProperties));
423 }
424
425 StylePropertyShorthand webkitMaskPositionShorthand()
426 {
427     static const CSSPropertyID maskPositionProperties[] = { CSSPropertyWebkitMaskPositionX, CSSPropertyWebkitMaskPositionY };
428     return StylePropertyShorthand(CSSPropertyWebkitMaskPosition, maskPositionProperties, WTF_ARRAY_LENGTH(maskPositionProperties));
429 }
430
431 StylePropertyShorthand webkitMaskRepeatShorthand()
432 {
433     static const CSSPropertyID maskRepeatProperties[] = { CSSPropertyWebkitMaskRepeatX, CSSPropertyWebkitMaskRepeatY };
434     return StylePropertyShorthand(CSSPropertyWebkitMaskRepeat, maskRepeatProperties, WTF_ARRAY_LENGTH(maskRepeatProperties));
435 }
436
437 StylePropertyShorthand webkitTextDecorationShorthand()
438 {
439     static const CSSPropertyID textDecorationProperties[] = {
440         CSSPropertyWebkitTextDecorationLine,
441         CSSPropertyWebkitTextDecorationStyle,
442         CSSPropertyWebkitTextDecorationColor
443     };
444     return StylePropertyShorthand(CSSPropertyWebkitTextDecoration, textDecorationProperties, WTF_ARRAY_LENGTH(textDecorationProperties));
445 }
446
447 StylePropertyShorthand webkitTextEmphasisShorthand()
448 {
449     static const CSSPropertyID textEmphasisProperties[] = {
450         CSSPropertyWebkitTextEmphasisStyle,
451         CSSPropertyWebkitTextEmphasisColor
452     };
453     return StylePropertyShorthand(CSSPropertyWebkitTextEmphasis, textEmphasisProperties, WTF_ARRAY_LENGTH(textEmphasisProperties));
454 }
455
456 StylePropertyShorthand webkitTextStrokeShorthand()
457 {
458     static const CSSPropertyID textStrokeProperties[] = { CSSPropertyWebkitTextStrokeWidth, CSSPropertyWebkitTextStrokeColor };
459     return StylePropertyShorthand(CSSPropertyWebkitTextStroke, textStrokeProperties, WTF_ARRAY_LENGTH(textStrokeProperties));
460 }
461
462 StylePropertyShorthand webkitTransitionShorthand()
463 {
464     static const CSSPropertyID transitionProperties[] = {
465         CSSPropertyWebkitTransitionProperty,
466         CSSPropertyWebkitTransitionDuration,
467         CSSPropertyWebkitTransitionTimingFunction,
468         CSSPropertyWebkitTransitionDelay
469     };
470     return StylePropertyShorthand(CSSPropertyWebkitTransition, transitionProperties, WTF_ARRAY_LENGTH(transitionProperties));
471 }
472
473 StylePropertyShorthand webkitTransformOriginShorthand()
474 {
475     static const CSSPropertyID transformOriginProperties[] = {
476         CSSPropertyWebkitTransformOriginX,
477         CSSPropertyWebkitTransformOriginY,
478         CSSPropertyWebkitTransformOriginZ
479     };
480     return StylePropertyShorthand(CSSPropertyWebkitTransformOrigin, transformOriginProperties, WTF_ARRAY_LENGTH(transformOriginProperties));
481 }
482
483 StylePropertyShorthand widthShorthand()
484 {
485     static const CSSPropertyID widthProperties[] = {
486         CSSPropertyMinWidth,
487         CSSPropertyMaxWidth
488     };
489     return StylePropertyShorthand(CSSPropertyWidth, widthProperties, WTF_ARRAY_LENGTH(widthProperties));
490 }
491
492 StylePropertyShorthand heightShorthand()
493 {
494     static const CSSPropertyID heightProperties[] = {
495         CSSPropertyMinHeight,
496         CSSPropertyMaxHeight
497     };
498     return StylePropertyShorthand(CSSPropertyHeight, heightProperties, WTF_ARRAY_LENGTH(heightProperties));
499 }
500
501 // Returns an empty list if the property is not a shorthand.
502 StylePropertyShorthand shorthandForProperty(CSSPropertyID propertyID)
503 {
504     switch (propertyID) {
505     case CSSPropertyBackground:
506         return backgroundShorthand();
507     case CSSPropertyBackgroundPosition:
508         return backgroundPositionShorthand();
509     case CSSPropertyBackgroundRepeat:
510         return backgroundRepeatShorthand();
511     case CSSPropertyBorder:
512         return borderShorthand();
513     case CSSPropertyBorderBottom:
514         return borderBottomShorthand();
515     case CSSPropertyBorderColor:
516         return borderColorShorthand();
517     case CSSPropertyBorderImage:
518         return borderImageShorthand();
519     case CSSPropertyBorderLeft:
520         return borderLeftShorthand();
521     case CSSPropertyBorderRadius:
522         return borderRadiusShorthand();
523     case CSSPropertyBorderRight:
524         return borderRightShorthand();
525     case CSSPropertyBorderSpacing:
526         return borderSpacingShorthand();
527     case CSSPropertyBorderStyle:
528         return borderStyleShorthand();
529     case CSSPropertyBorderTop:
530         return borderTopShorthand();
531     case CSSPropertyBorderWidth:
532         return borderWidthShorthand();
533     case CSSPropertyListStyle:
534         return listStyleShorthand();
535     case CSSPropertyFont:
536         return fontShorthand();
537     case CSSPropertyMargin:
538         return marginShorthand();
539     case CSSPropertyOutline:
540         return outlineShorthand();
541     case CSSPropertyOverflow:
542         return overflowShorthand();
543     case CSSPropertyPadding:
544         return paddingShorthand();
545     case CSSPropertyTransition:
546         return transitionShorthand();
547     case CSSPropertyWebkitAnimation:
548         return webkitAnimationShorthand();
549     case CSSPropertyWebkitBorderAfter:
550         return webkitBorderAfterShorthand();
551     case CSSPropertyWebkitBorderBefore:
552         return webkitBorderBeforeShorthand();
553     case CSSPropertyWebkitBorderEnd:
554         return webkitBorderEndShorthand();
555     case CSSPropertyWebkitBorderStart:
556         return webkitBorderStartShorthand();
557     case CSSPropertyWebkitBorderRadius:
558         return borderRadiusShorthand();
559     case CSSPropertyWebkitColumns:
560         return webkitColumnsShorthand();
561     case CSSPropertyWebkitColumnRule:
562         return webkitColumnRuleShorthand();
563     case CSSPropertyWebkitFlex:
564         return webkitFlexShorthand();
565     case CSSPropertyWebkitFlexFlow:
566         return webkitFlexFlowShorthand();
567 #if ENABLE(CSS_GRID_LAYOUT)
568     case CSSPropertyWebkitGridArea:
569         return webkitGridAreaShorthand();
570     case CSSPropertyWebkitGridColumn:
571         return webkitGridColumnShorthand();
572     case CSSPropertyWebkitGridRow:
573         return webkitGridRowShorthand();
574 #endif
575     case CSSPropertyWebkitMarginCollapse:
576         return webkitMarginCollapseShorthand();
577     case CSSPropertyWebkitMarquee:
578         return webkitMarqueeShorthand();
579     case CSSPropertyWebkitMask:
580         return webkitMaskShorthand();
581     case CSSPropertyWebkitMaskPosition:
582         return webkitMaskPositionShorthand();
583     case CSSPropertyWebkitMaskRepeat:
584         return webkitMaskRepeatShorthand();
585     case CSSPropertyWebkitTextEmphasis:
586         return webkitTextEmphasisShorthand();
587     case CSSPropertyWebkitTextStroke:
588         return webkitTextStrokeShorthand();
589     case CSSPropertyWebkitTransition:
590         return webkitTransitionShorthand();
591     case CSSPropertyWebkitTransformOrigin:
592         return webkitTransformOriginShorthand();
593     case CSSPropertyWebkitTextDecoration:
594         return webkitTextDecorationShorthand();
595     case CSSPropertyMarker:
596         return markerShorthand();
597     default:
598         return StylePropertyShorthand();
599     }
600 }
601
602 bool isExpandedShorthand(CSSPropertyID id)
603 {
604     // The system fonts bypass the normal style resolution by using RenderTheme,
605     // thus we need to special case it here. FIXME: This is a violation of CSS 3 Fonts
606     // as we should still be able to change the longhands.
607     // DON'T ADD ANY SHORTHAND HERE UNLESS IT ISN'T ALWAYS EXPANDED AT PARSE TIME (which is wrong).
608     if (id == CSSPropertyFont)
609         return false;
610
611     return shorthandForProperty(id).length();
612 }
613
614 static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a)
615 {
616     return Vector<StylePropertyShorthand>(1, a);
617 }
618
619 static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a, const StylePropertyShorthand& b)
620 {
621     Vector<StylePropertyShorthand> vector;
622     vector.reserveInitialCapacity(2);
623     vector.uncheckedAppend(a);
624     vector.uncheckedAppend(b);
625     return vector;
626 }
627
628 static Vector<StylePropertyShorthand> makeVector(const StylePropertyShorthand& a, const StylePropertyShorthand& b, const StylePropertyShorthand& c)
629 {
630     Vector<StylePropertyShorthand> vector;
631     vector.reserveInitialCapacity(3);
632     vector.uncheckedAppend(a);
633     vector.uncheckedAppend(b);
634     vector.uncheckedAppend(c);
635     return vector;
636 }
637
638 Vector<StylePropertyShorthand> matchingShorthandsForLonghand(CSSPropertyID propertyID)
639 {
640     switch (propertyID) {
641     case CSSPropertyBackgroundImage:
642     case CSSPropertyBackgroundSize:
643     case CSSPropertyBackgroundAttachment:
644     case CSSPropertyBackgroundOrigin:
645     case CSSPropertyBackgroundClip:
646     case CSSPropertyBackgroundColor:
647         return makeVector(backgroundShorthand());
648     case CSSPropertyBackgroundPositionX:
649     case CSSPropertyBackgroundPositionY:
650         return makeVector(backgroundShorthand(), backgroundPositionShorthand());
651     case CSSPropertyBackgroundRepeatX:
652     case CSSPropertyBackgroundRepeatY:
653         return makeVector(backgroundShorthand(), backgroundRepeatShorthand());
654     case CSSPropertyBorderBottomWidth:
655         return makeVector(borderShorthand(), borderBottomShorthand(), borderWidthShorthand());
656     case CSSPropertyBorderTopColor:
657         return makeVector(borderShorthand(), borderTopShorthand(), borderColorShorthand());
658     case CSSPropertyBorderRightColor:
659         return makeVector(borderShorthand(), borderRightShorthand(), borderColorShorthand());
660     case CSSPropertyBorderLeftColor:
661         return makeVector(borderShorthand(), borderLeftShorthand(), borderColorShorthand());
662     case CSSPropertyBorderBottomColor:
663         return makeVector(borderShorthand(), borderBottomShorthand(), borderColorShorthand());
664     case CSSPropertyBorderImageSource:
665     case CSSPropertyBorderImageSlice:
666     case CSSPropertyBorderImageWidth:
667     case CSSPropertyBorderImageOutset:
668     case CSSPropertyBorderImageRepeat:
669         return makeVector(borderImageShorthand());
670     case CSSPropertyBorderLeftWidth:
671         return makeVector(borderShorthand(), borderLeftShorthand(), borderWidthShorthand());
672     case CSSPropertyBorderTopLeftRadius:
673     case CSSPropertyBorderTopRightRadius:
674     case CSSPropertyBorderBottomRightRadius:
675     case CSSPropertyBorderBottomLeftRadius:
676         return makeVector(borderRadiusShorthand(), webkitBorderRadiusShorthand());
677     case CSSPropertyBorderRightWidth:
678         return makeVector(borderShorthand(), borderRightShorthand(), borderWidthShorthand());
679     case CSSPropertyWebkitBorderHorizontalSpacing:
680     case CSSPropertyWebkitBorderVerticalSpacing:
681         return makeVector(borderSpacingShorthand());
682     case CSSPropertyBorderTopStyle:
683         return makeVector(borderShorthand(), borderTopShorthand(), borderStyleShorthand());
684     case CSSPropertyBorderBottomStyle:
685         return makeVector(borderShorthand(), borderBottomShorthand(), borderStyleShorthand());
686     case CSSPropertyBorderLeftStyle:
687         return makeVector(borderShorthand(), borderLeftShorthand(), borderStyleShorthand());
688     case CSSPropertyBorderRightStyle:
689         return makeVector(borderShorthand(), borderRightShorthand(), borderStyleShorthand());
690     case CSSPropertyBorderTopWidth:
691         return makeVector(borderShorthand(), borderTopShorthand(), borderWidthShorthand());
692     case CSSPropertyListStyleType:
693     case CSSPropertyListStylePosition:
694     case CSSPropertyListStyleImage:
695         return makeVector(listStyleShorthand());
696     case CSSPropertyFontFamily:
697     case CSSPropertyFontSize:
698     case CSSPropertyFontStyle:
699     case CSSPropertyFontVariant:
700     case CSSPropertyFontWeight:
701     case CSSPropertyLineHeight:
702         return makeVector(fontShorthand());
703     case CSSPropertyMarginTop:
704     case CSSPropertyMarginRight:
705     case CSSPropertyMarginBottom:
706     case CSSPropertyMarginLeft:
707         return makeVector(marginShorthand());
708     case CSSPropertyOutlineColor:
709     case CSSPropertyOutlineStyle:
710     case CSSPropertyOutlineWidth:
711         return makeVector(outlineShorthand());
712     case CSSPropertyPaddingTop:
713     case CSSPropertyPaddingRight:
714     case CSSPropertyPaddingBottom:
715     case CSSPropertyPaddingLeft:
716         return makeVector(paddingShorthand());
717     case CSSPropertyOverflowX:
718     case CSSPropertyOverflowY:
719         return makeVector(overflowShorthand());
720     case CSSPropertyTransitionProperty:
721     case CSSPropertyTransitionDuration:
722     case CSSPropertyTransitionTimingFunction:
723     case CSSPropertyTransitionDelay:
724         return makeVector(transitionShorthand());
725     case CSSPropertyWebkitAnimationName:
726     case CSSPropertyWebkitAnimationDuration:
727     case CSSPropertyWebkitAnimationTimingFunction:
728     case CSSPropertyWebkitAnimationDelay:
729     case CSSPropertyWebkitAnimationIterationCount:
730     case CSSPropertyWebkitAnimationDirection:
731     case CSSPropertyWebkitAnimationFillMode:
732         return makeVector(webkitAnimationShorthand());
733     case CSSPropertyWebkitBorderAfterWidth:
734     case CSSPropertyWebkitBorderAfterStyle:
735     case CSSPropertyWebkitBorderAfterColor:
736         return makeVector(webkitBorderAfterShorthand());
737     case CSSPropertyWebkitBorderBeforeWidth:
738     case CSSPropertyWebkitBorderBeforeStyle:
739     case CSSPropertyWebkitBorderBeforeColor:
740         return makeVector(webkitBorderBeforeShorthand());
741     case CSSPropertyWebkitBorderEndWidth:
742     case CSSPropertyWebkitBorderEndStyle:
743     case CSSPropertyWebkitBorderEndColor:
744         return makeVector(webkitBorderEndShorthand());
745     case CSSPropertyWebkitBorderStartWidth:
746     case CSSPropertyWebkitBorderStartStyle:
747     case CSSPropertyWebkitBorderStartColor:
748         return makeVector(webkitBorderStartShorthand());
749     case CSSPropertyWebkitColumnWidth:
750     case CSSPropertyWebkitColumnCount:
751         return makeVector(webkitColumnsShorthand());
752     case CSSPropertyWebkitColumnRuleWidth:
753     case CSSPropertyWebkitColumnRuleStyle:
754     case CSSPropertyWebkitColumnRuleColor:
755         return makeVector(webkitColumnRuleShorthand());
756     case CSSPropertyWebkitFlexGrow:
757     case CSSPropertyWebkitFlexShrink:
758     case CSSPropertyWebkitFlexBasis:
759         return makeVector(webkitFlexShorthand());
760     case CSSPropertyWebkitFlexDirection:
761     case CSSPropertyWebkitFlexWrap:
762         return makeVector(webkitFlexFlowShorthand());
763 #if ENABLE(CSS_GRID_LAYOUT)
764     case CSSPropertyWebkitGridColumnStart:
765     case CSSPropertyWebkitGridColumnEnd:
766         return makeVector(webkitGridColumnShorthand());
767     case CSSPropertyWebkitGridRowStart:
768     case CSSPropertyWebkitGridRowEnd:
769         return makeVector(webkitGridRowShorthand());
770 #endif
771     case CSSPropertyWebkitMarginBeforeCollapse:
772     case CSSPropertyWebkitMarginAfterCollapse:
773         return makeVector(webkitMarginCollapseShorthand());
774     case CSSPropertyWebkitMarqueeDirection:
775     case CSSPropertyWebkitMarqueeIncrement:
776     case CSSPropertyWebkitMarqueeRepetition:
777     case CSSPropertyWebkitMarqueeStyle:
778     case CSSPropertyWebkitMarqueeSpeed:
779         return makeVector(webkitMarqueeShorthand());
780     case CSSPropertyWebkitMaskImage:
781     case CSSPropertyWebkitMaskSourceType:
782     case CSSPropertyWebkitMaskSize:
783     case CSSPropertyWebkitMaskOrigin:
784     case CSSPropertyWebkitMaskClip:
785         return makeVector(webkitMaskShorthand());
786     case CSSPropertyWebkitMaskPositionX:
787     case CSSPropertyWebkitMaskPositionY:
788         return makeVector(webkitMaskPositionShorthand());
789     case CSSPropertyWebkitMaskRepeatX:
790     case CSSPropertyWebkitMaskRepeatY:
791         return makeVector(webkitMaskRepeatShorthand());
792     case CSSPropertyWebkitTextEmphasisStyle:
793     case CSSPropertyWebkitTextEmphasisColor:
794         return makeVector(webkitTextEmphasisShorthand());
795     case CSSPropertyWebkitTextStrokeWidth:
796     case CSSPropertyWebkitTextStrokeColor:
797         return makeVector(webkitTextStrokeShorthand());
798     case CSSPropertyWebkitTransitionProperty:
799     case CSSPropertyWebkitTransitionDuration:
800     case CSSPropertyWebkitTransitionTimingFunction:
801     case CSSPropertyWebkitTransitionDelay:
802         return makeVector(webkitTransitionShorthand());
803     case CSSPropertyWebkitTransformOriginX:
804     case CSSPropertyWebkitTransformOriginY:
805     case CSSPropertyWebkitTransformOriginZ:
806         return makeVector(webkitTransformOriginShorthand());
807     case CSSPropertyMinWidth:
808     case CSSPropertyMaxWidth:
809         return makeVector(widthShorthand());
810     case CSSPropertyMinHeight:
811     case CSSPropertyMaxHeight:
812         return makeVector(heightShorthand());
813     case CSSPropertyWebkitTextDecorationLine:
814     case CSSPropertyWebkitTextDecorationStyle:
815     case CSSPropertyWebkitTextDecorationColor:
816         return makeVector(webkitTextDecorationShorthand());
817     case CSSPropertyMarkerStart:
818     case CSSPropertyMarkerMid:
819     case CSSPropertyMarkerEnd:
820         return makeVector(markerShorthand());
821     default:
822         break;
823     }
824
825     return Vector<StylePropertyShorthand>();
826 }
827
828 unsigned indexOfShorthandForLonghand(CSSPropertyID shorthandID, const Vector<StylePropertyShorthand>& shorthands)
829 {
830     for (unsigned i = 0, size = shorthands.size(); i < size; ++i) {
831         if (shorthands[i].id() == shorthandID)
832             return i;
833     }
834     ASSERT_NOT_REACHED();
835     return 0;
836 }
837
838 } // namespace WebCore