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