StyleSheetSpecification.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #ifndef ROCKETCORESTYLESHEETSPECIFICATION_H
  28. #define ROCKETCORESTYLESHEETSPECIFICATION_H
  29. #include "Header.h"
  30. #include "PropertySpecification.h"
  31. #include "Types.h"
  32. namespace Rocket {
  33. namespace Core {
  34. class PropertyParser;
  35. /**
  36. @author Peter Curry
  37. */
  38. class ROCKETCORE_API StyleSheetSpecification
  39. {
  40. public:
  41. /// Starts up the specification structure and registers default properties and type parsers.
  42. /// @return True if the specification started up successfully, false if not.
  43. static bool Initialise();
  44. /// Destroys the specification structure and releases the parsers.
  45. static void Shutdown();
  46. /// Registers a parser for use in property definitions.
  47. /// @param[in] parser_name The name to register the new parser under.
  48. /// @param[in] parser The parser to register. This parser will be released by the specification.
  49. /// @return True if the parser was registered successfully, false otherwise.
  50. static bool RegisterParser(const String& parser_name, PropertyParser* parser);
  51. /// Returns the parser registered with a specific name.
  52. /// @param[in] parser_name The name of the desired parser.
  53. /// @return The parser registered under the given name, or NULL if no such parser exists.
  54. static PropertyParser* GetParser(const String& parser_name);
  55. /// Registers a property with a new definition.
  56. /// @param[in] property_name The name to register the new property under.
  57. /// @param[in] default_value The default value to be used for an element if it has no other definition provided.
  58. /// @param[in] inherited True if this property is inherited from parent to child, false otherwise.
  59. /// @param[in] forces_layout True if a change in this property on an element will cause the element's layout to possibly change.
  60. /// @return The new property definition, ready to have parsers attached.
  61. static PropertyDefinition& RegisterProperty(const String& property_name, const String& default_value, bool inherited, bool forces_layout = false);
  62. /// Returns a property definition.
  63. /// @param[in] property_name The name of the desired property.
  64. /// @return The appropriate property definition if it could be found, NULL otherwise.
  65. static const PropertyDefinition* GetProperty(const String& property_name);
  66. /// Returns the list of the names of all registered property definitions.
  67. /// @return The list with stored property names.
  68. static const PropertyNameList & GetRegisteredProperties();
  69. /// Returns the list of the names of all registered inherited property definitions.
  70. /// @return The list with stored property names.
  71. static const PropertyNameList & GetRegisteredInheritedProperties();
  72. /// Registers a shorthand property definition.
  73. /// @param[in] shorthand_name The name to register the new shorthand property under.
  74. /// @param[in] properties A comma-separated list of the properties this definition is shorthand for. The order in which they are specified here is the order in which the values will be processed.
  75. /// @param[in] type The type of shorthand to declare.
  76. /// @param True if all the property names exist, false otherwise.
  77. static bool RegisterShorthand(const String& shorthand_name, const String& property_names, PropertySpecification::ShorthandType type = PropertySpecification::AUTO);
  78. /// Returns a shorthand definition.
  79. /// @param[in] shorthand_name The name of the desired shorthand.
  80. /// @return The appropriate shorthand definition if it could be found, NULL otherwise.
  81. static const PropertyShorthandDefinition* GetShorthand(const String& shorthand_name);
  82. /// Parses a property declaration, setting any parsed and validated properties on the given dictionary.
  83. /// @param[in] dictionary The property dictionary which will hold all declared properties.
  84. /// @param[in] property_name The name of the declared property.
  85. /// @param[in] property_value The values the property is being set to.
  86. /// @param[in] source_file The file where this property was declared. Used for error reporting, debugging and relative paths for referenced assets.
  87. /// @param[in] line_number The location of the source file where this property was declared. Used for error reporting and debugging.
  88. /// @return True if all properties were parsed successfully, false otherwise.
  89. static bool ParsePropertyDeclaration(PropertyDictionary& dictionary, const String& property_name, const String& property_value, const String& source_file = "", int source_line_number = 0);
  90. private:
  91. StyleSheetSpecification();
  92. ~StyleSheetSpecification();
  93. // Registers Rocket's default parsers.
  94. void RegisterDefaultParsers();
  95. // Registers Rocket's default style properties.
  96. void RegisterDefaultProperties();
  97. // Parsers used by all property definitions.
  98. typedef std::map< String, PropertyParser* > ParserMap;
  99. ParserMap parsers;
  100. // The properties defined in the style sheet specification.
  101. PropertySpecification properties;
  102. };
  103. }
  104. }
  105. #endif