Browse Source

Fix specificity for media blocks.

Michael Ragazzon 4 years ago
parent
commit
c263aa7918

+ 5 - 19
Source/Core/StyleSheetContainer.cpp

@@ -47,8 +47,8 @@ StyleSheetContainer::~StyleSheetContainer()
 bool StyleSheetContainer::LoadStyleSheetContainer(Stream* stream, int begin_line_number)
 {
 	StyleSheetParser parser;
-	int rule_count = parser.Parse(media_blocks, stream, begin_line_number);
-	return rule_count >= 0;
+	bool result = parser.Parse(media_blocks, stream, begin_line_number);
+	return result;
 }
 
 bool StyleSheetContainer::UpdateCompiledStyleSheet(float dp_ratio, Vector2f vp_dimensions)
@@ -192,30 +192,16 @@ SharedPtr<StyleSheetContainer> StyleSheetContainer::CombineStyleSheetContainer(c
 	return new_sheet;
 }
 
-void StyleSheetContainer::MergeStyleSheetContainer(const StyleSheetContainer& container)
+void StyleSheetContainer::MergeStyleSheetContainer(const StyleSheetContainer& other)
 {
 	RMLUI_ZoneScoped;
 
 	// Style sheet container must not be merged after it's been compiled. This will invalidate references to the compiled style sheet.
 	RMLUI_ASSERT(!compiled_style_sheet);
 
-	for (const MediaBlock& block_other : container.media_blocks)
+	for (const MediaBlock& block_other : other.media_blocks)
 	{
-		bool block_found = false;
-		for (MediaBlock& block_local : media_blocks)
-		{
-			if (block_other.properties.GetProperties() == block_local.properties.GetProperties())
-			{
-				block_local.stylesheet = block_local.stylesheet->CombineStyleSheet(*block_other.stylesheet);
-				block_found = true;
-				break;
-			}
-		}
-
-		if (!block_found)
-		{
-			media_blocks.emplace_back(block_other.properties, block_other.stylesheet->Clone());
-		}
+		media_blocks.emplace_back(block_other.properties, block_other.stylesheet->Clone());
 	}
 }
 

+ 2 - 2
Source/Core/StyleSheetParser.cpp

@@ -507,7 +507,7 @@ bool StyleSheetParser::ParseMediaFeatureMap(PropertyDictionary& properties, cons
 	return true;
 }
 
-int StyleSheetParser::Parse(MediaBlockList& style_sheets, Stream* _stream, int begin_line_number)
+bool StyleSheetParser::Parse(MediaBlockList& style_sheets, Stream* _stream, int begin_line_number)
 {
 	RMLUI_ZoneScoped;
 
@@ -733,7 +733,7 @@ int StyleSheetParser::Parse(MediaBlockList& style_sheets, Stream* _stream, int b
 		style_sheets.push_back(std::move(current_block));
 	}
 
-	return rule_count;
+	return !style_sheets.empty();
 }
 
 bool StyleSheetParser::ParseProperties(PropertyDictionary& parsed_properties, const String& properties)

+ 3 - 2
Source/Core/StyleSheetParser.h

@@ -59,8 +59,9 @@ public:
 	/// Parses the given stream into the style sheet
 	/// @param style_sheets The collection of style sheets to write into, organized into media blocks
 	/// @param stream The stream to read
-	/// @return The number of parsed rules, or -1 if an error occured.
-	int Parse(MediaBlockList& style_sheets, Stream* stream, int begin_line_number);
+	/// @param begin_line_number The used line number for the first line in the stream, for reporting errors.
+	/// @return True on success, false on failure.
+	bool Parse(MediaBlockList& style_sheets, Stream* stream, int begin_line_number);
 
 	/// Parses the given string into the property dictionary
 	/// @param parsed_properties The properties dictionary the properties will be read into