/platform/external/webkit/WebCore/css/CSSPropertyLonghand.cpp

https://github.com/aharish/totoro-gb-opensource-update2 · C++ · 222 lines · 164 code · 37 blank · 21 comment · 1 complexity · 6969afbe9b599cbb4163fccd6a462b63 MD5 · raw file

  1. /*
  2. * (C) 1999-2003 Lars Knoll (knoll@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. #include "config.h"
  21. #include "CSSPropertyLonghand.h"
  22. #include "CSSPropertyNames.h"
  23. #include <wtf/HashMap.h>
  24. #include <wtf/StdLibExtras.h>
  25. namespace WebCore {
  26. typedef HashMap<int, CSSPropertyLonghand> ShorthandMap;
  27. static void initShorthandMap(ShorthandMap& shorthandMap)
  28. {
  29. #define SET_SHORTHAND_MAP_ENTRY(map, propID, array) \
  30. map.set(propID, CSSPropertyLonghand(array, sizeof(array) / sizeof(array[0])))
  31. // FIXME: The 'font' property has "shorthand nature" but is not parsed as a shorthand.
  32. // Do not change the order of the following four shorthands, and keep them together.
  33. static const int borderProperties[4][3] = {
  34. { CSSPropertyBorderTopColor, CSSPropertyBorderTopStyle, CSSPropertyBorderTopWidth },
  35. { CSSPropertyBorderRightColor, CSSPropertyBorderRightStyle, CSSPropertyBorderRightWidth },
  36. { CSSPropertyBorderBottomColor, CSSPropertyBorderBottomStyle, CSSPropertyBorderBottomWidth },
  37. { CSSPropertyBorderLeftColor, CSSPropertyBorderLeftStyle, CSSPropertyBorderLeftWidth }
  38. };
  39. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderTop, borderProperties[0]);
  40. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderRight, borderProperties[1]);
  41. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderBottom, borderProperties[2]);
  42. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderLeft, borderProperties[3]);
  43. shorthandMap.set(CSSPropertyBorder, CSSPropertyLonghand(borderProperties[0], sizeof(borderProperties) / sizeof(borderProperties[0][0])));
  44. static const int borderColorProperties[] = {
  45. CSSPropertyBorderTopColor,
  46. CSSPropertyBorderRightColor,
  47. CSSPropertyBorderBottomColor,
  48. CSSPropertyBorderLeftColor
  49. };
  50. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderColor, borderColorProperties);
  51. static const int borderStyleProperties[] = {
  52. CSSPropertyBorderTopStyle,
  53. CSSPropertyBorderRightStyle,
  54. CSSPropertyBorderBottomStyle,
  55. CSSPropertyBorderLeftStyle
  56. };
  57. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderStyle, borderStyleProperties);
  58. static const int borderWidthProperties[] = {
  59. CSSPropertyBorderTopWidth,
  60. CSSPropertyBorderRightWidth,
  61. CSSPropertyBorderBottomWidth,
  62. CSSPropertyBorderLeftWidth
  63. };
  64. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderWidth, borderWidthProperties);
  65. static const int backgroundPositionProperties[] = { CSSPropertyBackgroundPositionX, CSSPropertyBackgroundPositionY };
  66. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBackgroundPosition, backgroundPositionProperties);
  67. static const int backgroundRepeatProperties[] = { CSSPropertyBackgroundRepeatX, CSSPropertyBackgroundRepeatY };
  68. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBackgroundRepeat, backgroundRepeatProperties);
  69. static const int borderSpacingProperties[] = { CSSPropertyWebkitBorderHorizontalSpacing, CSSPropertyWebkitBorderVerticalSpacing };
  70. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderSpacing, borderSpacingProperties);
  71. static const int listStyleProperties[] = {
  72. CSSPropertyListStyleImage,
  73. CSSPropertyListStylePosition,
  74. CSSPropertyListStyleType
  75. };
  76. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyListStyle, listStyleProperties);
  77. static const int marginProperties[] = {
  78. CSSPropertyMarginTop,
  79. CSSPropertyMarginRight,
  80. CSSPropertyMarginBottom,
  81. CSSPropertyMarginLeft
  82. };
  83. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyMargin, marginProperties);
  84. static const int marginCollapseProperties[] = { CSSPropertyWebkitMarginTopCollapse, CSSPropertyWebkitMarginBottomCollapse };
  85. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMarginCollapse, marginCollapseProperties);
  86. static const int marqueeProperties[] = {
  87. CSSPropertyWebkitMarqueeDirection,
  88. CSSPropertyWebkitMarqueeIncrement,
  89. CSSPropertyWebkitMarqueeRepetition,
  90. CSSPropertyWebkitMarqueeStyle,
  91. CSSPropertyWebkitMarqueeSpeed
  92. };
  93. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMarquee, marqueeProperties);
  94. static const int outlineProperties[] = {
  95. CSSPropertyOutlineColor,
  96. CSSPropertyOutlineOffset,
  97. CSSPropertyOutlineStyle,
  98. CSSPropertyOutlineWidth
  99. };
  100. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyOutline, outlineProperties);
  101. static const int paddingProperties[] = {
  102. CSSPropertyPaddingTop,
  103. CSSPropertyPaddingRight,
  104. CSSPropertyPaddingBottom,
  105. CSSPropertyPaddingLeft
  106. };
  107. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyPadding, paddingProperties);
  108. static const int textStrokeProperties[] = { CSSPropertyWebkitTextStrokeColor, CSSPropertyWebkitTextStrokeWidth };
  109. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitTextStroke, textStrokeProperties);
  110. static const int backgroundProperties[] = {
  111. CSSPropertyBackgroundAttachment,
  112. CSSPropertyBackgroundClip,
  113. CSSPropertyBackgroundColor,
  114. CSSPropertyBackgroundImage,
  115. CSSPropertyBackgroundOrigin,
  116. CSSPropertyBackgroundPositionX,
  117. CSSPropertyBackgroundPositionY,
  118. CSSPropertyBackgroundRepeatX,
  119. CSSPropertyBackgroundRepeatY
  120. };
  121. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBackground, backgroundProperties);
  122. static const int columnsProperties[] = { CSSPropertyWebkitColumnWidth, CSSPropertyWebkitColumnCount };
  123. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitColumns, columnsProperties);
  124. static const int columnRuleProperties[] = {
  125. CSSPropertyWebkitColumnRuleColor,
  126. CSSPropertyWebkitColumnRuleStyle,
  127. CSSPropertyWebkitColumnRuleWidth
  128. };
  129. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitColumnRule, columnRuleProperties);
  130. static const int overflowProperties[] = { CSSPropertyOverflowX, CSSPropertyOverflowY };
  131. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyOverflow, overflowProperties);
  132. static const int borderRadiusProperties[] = {
  133. CSSPropertyBorderTopRightRadius,
  134. CSSPropertyBorderTopLeftRadius,
  135. CSSPropertyBorderBottomLeftRadius,
  136. CSSPropertyBorderBottomRightRadius
  137. };
  138. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyBorderRadius, borderRadiusProperties);
  139. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitBorderRadius, borderRadiusProperties);
  140. static const int maskPositionProperties[] = { CSSPropertyWebkitMaskPositionX, CSSPropertyWebkitMaskPositionY };
  141. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMaskPosition, maskPositionProperties);
  142. static const int maskRepeatProperties[] = { CSSPropertyWebkitMaskRepeatX, CSSPropertyWebkitMaskRepeatY };
  143. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMaskRepeat, maskRepeatProperties);
  144. static const int maskProperties[] = {
  145. CSSPropertyWebkitMaskAttachment,
  146. CSSPropertyWebkitMaskClip,
  147. CSSPropertyWebkitMaskImage,
  148. CSSPropertyWebkitMaskOrigin,
  149. CSSPropertyWebkitMaskPositionX,
  150. CSSPropertyWebkitMaskPositionY,
  151. CSSPropertyWebkitMaskRepeatX,
  152. CSSPropertyWebkitMaskRepeatY
  153. };
  154. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitMask, maskProperties);
  155. static const int animationProperties[] = {
  156. CSSPropertyWebkitAnimationName,
  157. CSSPropertyWebkitAnimationDuration,
  158. CSSPropertyWebkitAnimationTimingFunction,
  159. CSSPropertyWebkitAnimationDelay,
  160. CSSPropertyWebkitAnimationIterationCount,
  161. CSSPropertyWebkitAnimationDirection
  162. };
  163. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitAnimation, animationProperties);
  164. static const int transitionProperties[] = {
  165. CSSPropertyWebkitTransitionProperty,
  166. CSSPropertyWebkitTransitionDuration,
  167. CSSPropertyWebkitTransitionTimingFunction,
  168. CSSPropertyWebkitTransitionDelay
  169. };
  170. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitTransition, transitionProperties);
  171. static const int transformOriginProperties[] = {
  172. CSSPropertyWebkitTransformOriginX,
  173. CSSPropertyWebkitTransformOriginY
  174. };
  175. SET_SHORTHAND_MAP_ENTRY(shorthandMap, CSSPropertyWebkitTransformOrigin, transformOriginProperties);
  176. #undef SET_SHORTHAND_MAP_ENTRY
  177. }
  178. CSSPropertyLonghand longhandForProperty(int propertyID)
  179. {
  180. DEFINE_STATIC_LOCAL(ShorthandMap, shorthandMap, ());
  181. if (shorthandMap.isEmpty())
  182. initShorthandMap(shorthandMap);
  183. return shorthandMap.get(propertyID);
  184. }
  185. } // namespace WebCore