StyleSheetSpecification.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "../../Include/Rocket/Core/StyleSheetSpecification.h"
  29. #include "PropertyParserNumber.h"
  30. #include "PropertyParserAnimation.h"
  31. #include "PropertyParserColour.h"
  32. #include "PropertyParserKeyword.h"
  33. #include "PropertyParserString.h"
  34. #include "PropertyParserTransform.h"
  35. #include "PropertyShorthandDefinition.h"
  36. namespace Rocket {
  37. namespace Core {
  38. template <typename ID>
  39. class IdNameMap {
  40. std::vector<String> name_map; // IDs are indices into the name_map
  41. UnorderedMap<String, ID> reverse_map;
  42. protected:
  43. IdNameMap(size_t num_ids_to_reserve) {
  44. static_assert((int)ID::Invalid == 0, "Invalid id must be zero");
  45. name_map.resize(num_ids_to_reserve);
  46. reverse_map.reserve(num_ids_to_reserve);
  47. AddPair(ID::Invalid, "invalid");
  48. }
  49. public:
  50. void AddPair(ID id, const String& name) {
  51. // Should only be used for defined IDs
  52. ROCKET_ASSERT((size_t)id < name_map.size());
  53. name_map[(size_t)id] = name;
  54. bool inserted = reverse_map.emplace(name, id).second;
  55. ROCKET_ASSERT(inserted);
  56. }
  57. void AssertAllInserted(ID last_property_inserted) const {
  58. ROCKET_ASSERT(name_map.size() == (size_t)last_property_inserted && reverse_map.size() == (size_t)last_property_inserted);
  59. }
  60. ID GetId(const String& name)
  61. {
  62. auto it = reverse_map.find(name);
  63. if (it != reverse_map.end())
  64. return it->second;
  65. return ID::Invalid;
  66. }
  67. const String& GetName(ID id)
  68. {
  69. if (static_cast<size_t>(id) < name_map.size())
  70. return name_map[static_cast<size_t>(id)];
  71. return name_map[static_cast<size_t>(ID::Invalid)];
  72. }
  73. ID GetOrCreateId(const String& name)
  74. {
  75. ID next_id = static_cast<ID>(name_map.size());
  76. // Only insert if not already in list
  77. auto pair = reverse_map.emplace(name, next_id);
  78. const auto& it = pair.first;
  79. bool inserted = pair.second;
  80. if (inserted)
  81. name_map.push_back(name);
  82. // Return the property id that already existed, or the new one if inserted
  83. return it->second;
  84. }
  85. };
  86. class PropertyIdNameMap : public IdNameMap<PropertyId> {
  87. public:
  88. PropertyIdNameMap() : IdNameMap(2*(size_t)PropertyId::NumDefinedIds) {}
  89. };
  90. class ShorthandIdNameMap : public IdNameMap<ShorthandId> {
  91. public:
  92. ShorthandIdNameMap() : IdNameMap(2*(size_t)ShorthandId::NumDefinedIds) {}
  93. };
  94. static PropertyIdNameMap property_id_name_map;
  95. static ShorthandIdNameMap shorthand_id_name_map;
  96. static StyleSheetSpecification* instance = NULL;
  97. StyleSheetSpecification::StyleSheetSpecification()
  98. {
  99. ROCKET_ASSERT(instance == NULL);
  100. instance = this;
  101. }
  102. StyleSheetSpecification::~StyleSheetSpecification()
  103. {
  104. ROCKET_ASSERT(instance == this);
  105. instance = NULL;
  106. }
  107. PropertyDefinition& StyleSheetSpecification::RegisterProperty(PropertyId id, const String& property_name, const String& default_value, bool inherited, bool forces_layout)
  108. {
  109. property_id_name_map.AddPair(id, property_name);
  110. return properties.RegisterProperty(id, default_value, inherited, forces_layout);
  111. }
  112. bool StyleSheetSpecification::RegisterShorthand(ShorthandId id, const String& shorthand_name, const String& property_names, ShorthandType type)
  113. {
  114. shorthand_id_name_map.AddPair(id, shorthand_name);
  115. return properties.RegisterShorthand(id, property_names, type);
  116. }
  117. bool StyleSheetSpecification::Initialise()
  118. {
  119. if (instance == NULL)
  120. {
  121. new StyleSheetSpecification();
  122. instance->RegisterDefaultParsers();
  123. instance->RegisterDefaultProperties();
  124. }
  125. return true;
  126. }
  127. void StyleSheetSpecification::Shutdown()
  128. {
  129. if (instance != NULL)
  130. {
  131. for (ParserMap::iterator iterator = instance->parsers.begin(); iterator != instance->parsers.end(); ++iterator)
  132. (*iterator).second->Release();
  133. delete instance;
  134. }
  135. }
  136. // Registers a parser for use in property definitions.
  137. bool StyleSheetSpecification::RegisterParser(const String& parser_name, PropertyParser* parser)
  138. {
  139. ParserMap::iterator iterator = instance->parsers.find(parser_name);
  140. if (iterator != instance->parsers.end())
  141. (*iterator).second->Release();
  142. instance->parsers[parser_name] = parser;
  143. return true;
  144. }
  145. // Returns the parser registered with a specific name.
  146. PropertyParser* StyleSheetSpecification::GetParser(const String& parser_name)
  147. {
  148. ParserMap::iterator iterator = instance->parsers.find(parser_name);
  149. if (iterator == instance->parsers.end())
  150. return NULL;
  151. return (*iterator).second;
  152. }
  153. // Registers a property with a new definition.
  154. PropertyDefinition& StyleSheetSpecification::RegisterCustomProperty(const String& property_name, const String& default_value, bool inherited, bool forces_layout)
  155. {
  156. PropertyId id = property_id_name_map.GetOrCreateId(property_name);
  157. ROCKET_ASSERTMSG((size_t)id < (size_t)PropertyId::FirstCustomId, "Custom property name matches an internal property, please make a unique name for the given property.");
  158. return instance->properties.RegisterProperty(id, default_value, inherited, forces_layout);
  159. }
  160. // Returns a property definition.
  161. const PropertyDefinition* StyleSheetSpecification::GetProperty(const String& property_name)
  162. {
  163. PropertyId id = property_id_name_map.GetId(property_name);
  164. return instance->properties.GetProperty(id);
  165. }
  166. const PropertyDefinition* StyleSheetSpecification::GetProperty(PropertyId id)
  167. {
  168. return instance->properties.GetProperty(id);
  169. }
  170. // Fetches a list of the names of all registered property definitions.
  171. const PropertyNameList& StyleSheetSpecification::GetRegisteredProperties()
  172. {
  173. return instance->properties.GetRegisteredProperties();
  174. }
  175. const PropertyNameList & StyleSheetSpecification::GetRegisteredInheritedProperties()
  176. {
  177. return instance->properties.GetRegisteredInheritedProperties();
  178. }
  179. // Registers a shorthand property definition.
  180. bool StyleSheetSpecification::RegisterCustomShorthand(const String& shorthand_name, const String& property_names, ShorthandType type)
  181. {
  182. ROCKET_ASSERTMSG(property_id_name_map.GetId(shorthand_name) == PropertyId::Invalid, "Custom shorthand name matches a property name, please make a unique name.");
  183. ShorthandId id = shorthand_id_name_map.GetOrCreateId(shorthand_name);
  184. ROCKET_ASSERTMSG((size_t)id < (size_t)ShorthandId::FirstCustomId, "Custom shorthand name matches an internal shorthand, please make a unique name for the given shorthand property.");
  185. return instance->properties.RegisterShorthand(id, property_names, type);
  186. }
  187. // Returns a shorthand definition.
  188. const ShorthandDefinition* StyleSheetSpecification::GetShorthand(const String& shorthand_name)
  189. {
  190. ShorthandId id = shorthand_id_name_map.GetOrCreateId(shorthand_name);
  191. return instance->properties.GetShorthand(id);
  192. }
  193. const ShorthandDefinition* StyleSheetSpecification::GetShorthand(ShorthandId id)
  194. {
  195. return instance->properties.GetShorthand(id);
  196. }
  197. // Parses a property declaration, setting any parsed and validated properties on the given dictionary.
  198. bool StyleSheetSpecification::ParsePropertyDeclaration(PropertyDictionary& dictionary, const String& property_name, const String& property_value, const String& source_file, int source_line_number)
  199. {
  200. // Try as a property first
  201. PropertyId property_id = GetPropertyId(property_name);
  202. if(property_id != PropertyId::Invalid)
  203. return instance->properties.ParsePropertyDeclaration(dictionary, property_id, property_value, source_file, source_line_number);
  204. // Then, as a shorthand
  205. ShorthandId shorthand_id = GetShorthandId(property_name);
  206. if(shorthand_id != ShorthandId::Invalid)
  207. return instance->properties.ParseShorthandDeclaration(dictionary, shorthand_id, property_value, source_file, source_line_number);
  208. return false;
  209. }
  210. PropertyId StyleSheetSpecification::GetPropertyId(const String& property_name)
  211. {
  212. return property_id_name_map.GetId(property_name);
  213. }
  214. ShorthandId StyleSheetSpecification::GetShorthandId(const String& shorthand_name)
  215. {
  216. return shorthand_id_name_map.GetId(shorthand_name);
  217. }
  218. const String& StyleSheetSpecification::GetPropertyName(PropertyId id)
  219. {
  220. return property_id_name_map.GetName(id);
  221. }
  222. const String& StyleSheetSpecification::GetShorthandName(ShorthandId id)
  223. {
  224. return shorthand_id_name_map.GetName(id);
  225. }
  226. std::vector<PropertyId> StyleSheetSpecification::GetShorthandUnderlyingProperties(ShorthandId id)
  227. {
  228. std::vector<PropertyId> result;
  229. const ShorthandDefinition* shorthand = instance->properties.GetShorthand(id);
  230. if (!shorthand)
  231. return result;
  232. result.reserve(shorthand->items.size());
  233. for (auto& item : shorthand->items)
  234. {
  235. if (item.type == ShorthandItemType::Property)
  236. {
  237. result.push_back(item.property_id);
  238. }
  239. else if (item.type == ShorthandItemType::Shorthand)
  240. {
  241. // When we have a shorthand pointing to another shorthands, call us recursively
  242. std::vector<PropertyId> new_items = GetShorthandUnderlyingProperties(item.shorthand_id);
  243. result.insert(result.end(), new_items.begin(), new_items.end());
  244. }
  245. }
  246. return result;
  247. }
  248. // Registers Rocket's default parsers.
  249. void StyleSheetSpecification::RegisterDefaultParsers()
  250. {
  251. RegisterParser("number", new PropertyParserNumber(Property::NUMBER));
  252. RegisterParser("length", new PropertyParserNumber(Property::LENGTH, Property::PX));
  253. RegisterParser("length_percent", new PropertyParserNumber(Property::LENGTH_PERCENT, Property::PX));
  254. RegisterParser("number_length_percent", new PropertyParserNumber(Property::NUMBER_LENGTH_PERCENT, Property::PX));
  255. RegisterParser("angle", new PropertyParserNumber(Property::ANGLE, Property::RAD));
  256. RegisterParser("keyword", new PropertyParserKeyword());
  257. RegisterParser("string", new PropertyParserString());
  258. RegisterParser(ANIMATION, new PropertyParserAnimation(PropertyParserAnimation::ANIMATION_PARSER));
  259. RegisterParser(TRANSITION, new PropertyParserAnimation(PropertyParserAnimation::TRANSITION_PARSER));
  260. RegisterParser(COLOR, new PropertyParserColour());
  261. RegisterParser(TRANSFORM, new PropertyParserTransform());
  262. }
  263. // Registers Rocket's default style properties.
  264. void StyleSheetSpecification::RegisterDefaultProperties()
  265. {
  266. // Style property specifications (ala RCSS).
  267. RegisterProperty(PropertyId::MarginTop, MARGIN_TOP, "0px", false, true)
  268. .AddParser("keyword", "auto")
  269. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  270. RegisterProperty(PropertyId::MarginRight, MARGIN_RIGHT, "0px", false, true)
  271. .AddParser("keyword", "auto")
  272. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  273. RegisterProperty(PropertyId::MarginBottom, MARGIN_BOTTOM, "0px", false, true)
  274. .AddParser("keyword", "auto")
  275. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  276. RegisterProperty(PropertyId::MarginLeft, MARGIN_LEFT, "0px", false, true)
  277. .AddParser("keyword", "auto")
  278. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  279. RegisterShorthand(ShorthandId::Margin, MARGIN, "margin-top, margin-right, margin-bottom, margin-left", ShorthandType::Box);
  280. RegisterProperty(PropertyId::PaddingTop, PADDING_TOP, "0px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  281. RegisterProperty(PropertyId::PaddingRight, PADDING_RIGHT, "0px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  282. RegisterProperty(PropertyId::PaddingBottom, PADDING_BOTTOM, "0px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  283. RegisterProperty(PropertyId::PaddingLeft, PADDING_LEFT, "0px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  284. RegisterShorthand(ShorthandId::Padding, PADDING, "padding-top, padding-right, padding-bottom, padding-left", ShorthandType::Box);
  285. RegisterProperty(PropertyId::BorderTopWidth, BORDER_TOP_WIDTH, "0px", false, true).AddParser("length");
  286. RegisterProperty(PropertyId::BorderRightWidth, BORDER_RIGHT_WIDTH, "0px", false, true).AddParser("length");
  287. RegisterProperty(PropertyId::BorderBottomWidth, BORDER_BOTTOM_WIDTH, "0px", false, true).AddParser("length");
  288. RegisterProperty(PropertyId::BorderLeftWidth, BORDER_LEFT_WIDTH, "0px", false, true).AddParser("length");
  289. RegisterShorthand(ShorthandId::BorderWidth, BORDER_WIDTH, "border-top-width, border-right-width, border-bottom-width, border-left-width", ShorthandType::Box);
  290. RegisterProperty(PropertyId::BorderTopColor, BORDER_TOP_COLOR, "black", false, false).AddParser(COLOR);
  291. RegisterProperty(PropertyId::BorderRightColor, BORDER_RIGHT_COLOR, "black", false, false).AddParser(COLOR);
  292. RegisterProperty(PropertyId::BorderBottomColor, BORDER_BOTTOM_COLOR, "black", false, false).AddParser(COLOR);
  293. RegisterProperty(PropertyId::BorderLeftColor, BORDER_LEFT_COLOR, "black", false, false).AddParser(COLOR);
  294. RegisterShorthand(ShorthandId::BorderColor, BORDER_COLOR, "border-top-color, border-right-color, border-bottom-color, border-left-color", ShorthandType::Box);
  295. RegisterShorthand(ShorthandId::BorderTop, BORDER_TOP, "border-top-width, border-top-color", ShorthandType::FallThrough);
  296. RegisterShorthand(ShorthandId::BorderRight, BORDER_RIGHT, "border-right-width, border-right-color", ShorthandType::FallThrough);
  297. RegisterShorthand(ShorthandId::BorderBottom, BORDER_BOTTOM, "border-bottom-width, border-bottom-color", ShorthandType::FallThrough);
  298. RegisterShorthand(ShorthandId::BorderLeft, BORDER_LEFT, "border-left-width, border-left-color", ShorthandType::FallThrough);
  299. RegisterShorthand(ShorthandId::Border, BORDER, "border-top, border-right, border-bottom, border-left", ShorthandType::Recursive);
  300. RegisterProperty(PropertyId::Display, DISPLAY, "inline", false, true).AddParser("keyword", "none, block, inline, inline-block");
  301. RegisterProperty(PropertyId::Position, POSITION, "static", false, true).AddParser("keyword", "static, relative, absolute, fixed");
  302. RegisterProperty(PropertyId::Top, TOP, "auto", false, false)
  303. .AddParser("keyword", "auto")
  304. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
  305. RegisterProperty(PropertyId::Right, RIGHT, "auto", false, false)
  306. .AddParser("keyword", "auto")
  307. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  308. RegisterProperty(PropertyId::Bottom, BOTTOM, "auto", false, false)
  309. .AddParser("keyword", "auto")
  310. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
  311. RegisterProperty(PropertyId::Left, LEFT, "auto", false, false)
  312. .AddParser("keyword", "auto")
  313. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  314. RegisterProperty(PropertyId::Float, FLOAT, "none", false, true).AddParser("keyword", "none, left, right");
  315. RegisterProperty(PropertyId::Clear, CLEAR, "none", false, true).AddParser("keyword", "none, left, right, both");
  316. RegisterProperty(PropertyId::ZIndex, Z_INDEX, "auto", false, false)
  317. .AddParser("keyword", "auto")
  318. .AddParser("number");
  319. RegisterProperty(PropertyId::Width, WIDTH, "auto", false, true)
  320. .AddParser("keyword", "auto")
  321. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  322. RegisterProperty(PropertyId::MinWidth, MIN_WIDTH, "0px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  323. RegisterProperty(PropertyId::MaxWidth, MAX_WIDTH, "-1px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockWidth);
  324. RegisterProperty(PropertyId::Height, HEIGHT, "auto", false, true)
  325. .AddParser("keyword", "auto")
  326. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
  327. RegisterProperty(PropertyId::MinHeight, MIN_HEIGHT, "0px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
  328. RegisterProperty(PropertyId::MaxHeight, MAX_HEIGHT, "-1px", false, true).AddParser("length_percent").SetRelativeTarget(RelativeTarget::ContainingBlockHeight);
  329. RegisterProperty(PropertyId::LineHeight, LINE_HEIGHT, "1.2", true, true).AddParser("number_length_percent").SetRelativeTarget(RelativeTarget::FontSize);
  330. RegisterProperty(PropertyId::VerticalAlign, VERTICAL_ALIGN, "baseline", false, true)
  331. .AddParser("keyword", "baseline, middle, sub, super, text-top, text-bottom, top, bottom")
  332. .AddParser("length_percent").SetRelativeTarget(RelativeTarget::LineHeight);
  333. RegisterProperty(PropertyId::OverflowX, OVERFLOW_X, "visible", false, true).AddParser("keyword", "visible, hidden, auto, scroll");
  334. RegisterProperty(PropertyId::OverflowY, OVERFLOW_Y, "visible", false, true).AddParser("keyword", "visible, hidden, auto, scroll");
  335. RegisterShorthand(ShorthandId::Overflow, "overflow", "overflow-x, overflow-y", ShorthandType::Replicate);
  336. RegisterProperty(PropertyId::Clip, CLIP, "auto", true, false).AddParser("keyword", "auto, none").AddParser("number");
  337. RegisterProperty(PropertyId::Visibility, VISIBILITY, "visible", false, false).AddParser("keyword", "visible, hidden");
  338. // Need some work on this if we are to include images.
  339. RegisterProperty(PropertyId::BackgroundColor, BACKGROUND_COLOR, "transparent", false, false).AddParser(COLOR);
  340. RegisterShorthand(ShorthandId::Background, BACKGROUND, BACKGROUND_COLOR, ShorthandType::FallThrough);
  341. RegisterProperty(PropertyId::Color, COLOR, "white", true, false).AddParser(COLOR);
  342. RegisterProperty(PropertyId::ImageColor, IMAGE_COLOR, "white", false, false).AddParser(COLOR);
  343. RegisterProperty(PropertyId::Opacity, OPACITY, "1", true, false).AddParser("number");
  344. RegisterProperty(PropertyId::FontFamily, FONT_FAMILY, "", true, true).AddParser("string");
  345. RegisterProperty(PropertyId::FontCharset, FONT_CHARSET, "U+0020-007E", true, false).AddParser("string");
  346. RegisterProperty(PropertyId::FontStyle, FONT_STYLE, "normal", true, true).AddParser("keyword", "normal, italic");
  347. RegisterProperty(PropertyId::FontWeight, FONT_WEIGHT, "normal", true, true).AddParser("keyword", "normal, bold");
  348. RegisterProperty(PropertyId::FontSize, FONT_SIZE, "12px", true, true).AddParser("length").AddParser("length_percent").SetRelativeTarget(RelativeTarget::ParentFontSize);
  349. RegisterShorthand(ShorthandId::Font, FONT, "font-style, font-weight, font-size, font-family, font-charset", ShorthandType::FallThrough);
  350. RegisterProperty(PropertyId::TextAlign, TEXT_ALIGN, LEFT, true, true).AddParser("keyword", "left, right, center, justify");
  351. RegisterProperty(PropertyId::TextDecoration, TEXT_DECORATION, "none", true, false).AddParser("keyword", "none, underline"/*"none, underline, overline, line-through"*/);
  352. RegisterProperty(PropertyId::TextTransform, TEXT_TRANSFORM, "none", true, true).AddParser("keyword", "none, capitalize, uppercase, lowercase");
  353. RegisterProperty(PropertyId::WhiteSpace, WHITE_SPACE, "normal", true, true).AddParser("keyword", "normal, pre, nowrap, pre-wrap, pre-line");
  354. RegisterProperty(PropertyId::Cursor, CURSOR, "", true, false).AddParser("string");
  355. // Functional property specifications.
  356. RegisterProperty(PropertyId::Drag, DRAG, "none", false, false).AddParser("keyword", "none, drag, drag-drop, block, clone");
  357. RegisterProperty(PropertyId::TabIndex, TAB_INDEX, "none", false, false).AddParser("keyword", "none, auto");
  358. RegisterProperty(PropertyId::Focus, FOCUS, "auto", true, false).AddParser("keyword", "none, auto");
  359. RegisterProperty(PropertyId::ScrollbarMargin, SCROLLBAR_MARGIN, "0", false, false).AddParser("length");
  360. RegisterProperty(PropertyId::PointerEvents, POINTER_EVENTS, "auto", true, false).AddParser("keyword", "none, auto");
  361. // Perspective and Transform specifications
  362. RegisterProperty(PropertyId::Perspective, PERSPECTIVE, "none", false, false).AddParser("keyword", "none").AddParser("length");
  363. RegisterProperty(PropertyId::PerspectiveOriginX, PERSPECTIVE_ORIGIN_X, "50%", false, false).AddParser("keyword", "left, center, right").AddParser("length_percent");
  364. RegisterProperty(PropertyId::PerspectiveOriginY, PERSPECTIVE_ORIGIN_Y, "50%", false, false).AddParser("keyword", "top, center, bottom").AddParser("length_percent");
  365. RegisterShorthand(ShorthandId::PerspectiveOrigin, PERSPECTIVE_ORIGIN, "perspective-origin-x, perspective-origin-y", ShorthandType::FallThrough);
  366. RegisterProperty(PropertyId::Transform, TRANSFORM, "none", false, false).AddParser(TRANSFORM);
  367. RegisterProperty(PropertyId::TransformOriginX, TRANSFORM_ORIGIN_X, "50%", false, false).AddParser("keyword", "left, center, right").AddParser("length_percent");
  368. RegisterProperty(PropertyId::TransformOriginY, TRANSFORM_ORIGIN_Y, "50%", false, false).AddParser("keyword", "top, center, bottom").AddParser("length_percent");
  369. RegisterProperty(PropertyId::TransformOriginZ, TRANSFORM_ORIGIN_Z, "0", false, false).AddParser("length");
  370. RegisterShorthand(ShorthandId::TransformOrigin, TRANSFORM_ORIGIN, "transform-origin-x, transform-origin-y, transform-origin-z", ShorthandType::FallThrough);
  371. RegisterProperty(PropertyId::Transition, TRANSITION, "none", false, false).AddParser(TRANSITION);
  372. RegisterProperty(PropertyId::Animation, ANIMATION, "none", false, false).AddParser(ANIMATION);
  373. property_id_name_map.AssertAllInserted(PropertyId::NumDefinedIds);
  374. shorthand_id_name_map.AssertAllInserted(ShorthandId::NumDefinedIds);
  375. }
  376. }
  377. }