Browse Source

Add shorthand for RCSS 'border'

Michael 7 years ago
parent
commit
0b99b36a9c

+ 2 - 0
Include/Rocket/Core/PropertySpecification.h

@@ -56,6 +56,8 @@ public:
 		REPLICATE,
 		// For 'padding', 'margin', etc; up four properties are expected.
 		BOX,
+		// Recursively resolves the full value string on each property, whether it is a normal property or another shorthand.
+		RECURSIVE,
 		// BOX if four properties are shorthanded and they end in '-top', '-right', etc, otherwise FALL_THROUGH.
 		AUTO
 	};

+ 23 - 2
Source/Core/PropertySpecification.cpp

@@ -114,14 +114,22 @@ bool PropertySpecification::RegisterShorthand(const String& shorthand_name, cons
 	for (size_t i = 0; i < properties.size(); i++)
 	{
 		const PropertyDefinition* property = GetProperty(properties[i]);
-		if (property == NULL)
+		bool shorthand_found = false;
+
+		if (property == NULL && type == RECURSIVE)
+		{
+			// See if recursive type points to another shorthand instead
+			const PropertyShorthandDefinition* shorthand = GetShorthand(properties[i]);
+			shorthand_found = (shorthand != NULL);
+		}
+
+		if (property == NULL && !shorthand_found)
 		{
 			Log::Message(Log::LT_ERROR, "Shorthand property '%s' was registered with invalid property '%s'.", shorthand_name.CString(), properties[i].CString());
 			delete property_shorthand;
 
 			return false;
 		}
-
 		property_shorthand->properties.push_back(PropertyShorthandDefinition::PropertyDefinitionList::value_type(properties[i], property));
 	}
 
@@ -266,6 +274,19 @@ bool PropertySpecification::ParsePropertyDeclaration(PropertyDictionary& diction
 				default:	break;
 			}
 		}
+		else if (shorthand_definition->type == RECURSIVE)
+		{
+			bool result = false;
+
+			for (size_t i = 0; i < shorthand_definition->properties.size(); i++)
+			{
+				const auto& property_name = shorthand_definition->properties[i].first;
+				result |= ParsePropertyDeclaration(dictionary, property_name, property_value, source_file, source_line_number);
+			}
+
+			if (!result)
+				return false;
+		}
 		else
 		{
 			size_t value_index = 0;

+ 1 - 0
Source/Core/StringCache.cpp

@@ -57,6 +57,7 @@ const String BORDER_TOP = "border-top";
 const String BORDER_RIGHT = "border-right";
 const String BORDER_BOTTOM = "border-bottom";
 const String BORDER_LEFT = "border-left";
+const String BORDER = "border";
 const String DISPLAY = "display";
 const String POSITION = "position";
 const String TOP = "top";

+ 1 - 0
Source/Core/StringCache.h

@@ -60,6 +60,7 @@ extern const String BORDER_TOP;
 extern const String BORDER_RIGHT;
 extern const String BORDER_BOTTOM;
 extern const String BORDER_LEFT;
+extern const String BORDER;
 extern const String DISPLAY;
 extern const String POSITION;
 extern const String TOP;

+ 1 - 0
Source/Core/StyleSheetSpecification.cpp

@@ -188,6 +188,7 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 	RegisterShorthand(BORDER_RIGHT, "border-right-width, border-right-color");
 	RegisterShorthand(BORDER_BOTTOM, "border-bottom-width, border-bottom-color");
 	RegisterShorthand(BORDER_LEFT, "border-left-width, border-left-color");
+	RegisterShorthand(BORDER, "border-top, border-right, border-bottom, border-left", PropertySpecification::RECURSIVE);
 
 	RegisterProperty(DISPLAY, "inline", false, true).AddParser("keyword", "none, block, inline, inline-block");
 	RegisterProperty(POSITION, "static", false, true).AddParser("keyword", "static, relative, absolute, fixed");