Browse Source

Remove some ResolveProperty

Michael Ragazzon 6 years ago
parent
commit
11aa64ffa6

+ 0 - 6
Include/Rocket/Core/Element.h

@@ -219,12 +219,6 @@ public:
 	/// Returns the local properties, excluding any properties from local class.
 	/// @return The local properties for this element, or NULL if no properties defined
 	const PropertyMap* GetLocalProperties();
-	/// Resolves one of this element's properties. If the value is a number or px, this is returned. Angles are returned as radians.
-	/// Precentages are resolved based on the second argument (the base value).
-	/// @param[in] name The name of the property to resolve the value for.
-	/// @param[in] base_value The value that is scaled by the percentage value, if it is a percentage.
-	/// @return The value of this property for this element.
-	float ResolveProperty(const String& name, float base_value);
 	/// Resolves one of this element's non-inherited properties. If the value is a number or px, this is returned. Angles are returned as radians.
 	/// Precentages are resolved based on the second argument (the base value).
 	/// @param[in] name The property to resolve the value for.

+ 1 - 0
Samples/basic/benchmark/src/main.cpp

@@ -96,6 +96,7 @@ public:
 		  Computed layout engine: 90.0   [e18ac30]
 		  Replace style cache by computed values: 96.0
 		  More computed values: 100.0  [edc78bb] !Woo!
+		  Avoid duplicate ToLower++: 103.0  [dec4ef6]
 		  
 		*/
 

+ 0 - 2
Source/Controls/Controls.cpp

@@ -126,8 +126,6 @@ void Initialise()
 	// Prevent double initialisation
 	if (!initialised)
 	{
-		Core::StyleSheetSpecification::RegisterProperty("min-rows", "0", false, false).AddParser("number");
-
 		// Register the element instancers for our custom elements.
 		RegisterElementInstancers();
 

+ 1 - 1
Source/Controls/ElementDataGrid.cpp

@@ -237,7 +237,7 @@ void ElementDataGrid::OnUpdate()
 		DispatchEvent("rowupdate", Rocket::Core::Dictionary());
 	}
 	
-	if (!body_visible && (!any_new_children || root->GetNumLoadedChildren() >= Rocket::Core::Math::RealToInteger(ResolveProperty("min-rows", 0))))
+	if (!body_visible && (!any_new_children || root->GetNumLoadedChildren() >= GetAttribute("min-rows", 0)))
 	{
 		body->SetProperty("display", Core::Property(Core::Style::Display::Block));
 		body_visible = true;

+ 0 - 6
Source/Core/Element.cpp

@@ -620,12 +620,6 @@ const PropertyMap * Element::GetLocalProperties()
 	return style->GetLocalProperties();
 }
 
-// Resolves one of this element's style.
-float Element::ResolveProperty(const String& name, float base_value)
-{
-	return style->ResolveProperty(name, base_value);
-}
-
 // Resolves one of this element's style.
 float Element::ResolveProperty(const Property *property, float base_value)
 {

+ 2 - 2
Source/Core/ElementScroll.cpp

@@ -97,7 +97,7 @@ void ElementScroll::EnableScrollbar(Orientation orientation, float element_width
 		if (box.GetSize().y < 0)
 			scrollbars[orientation].size = box.GetCumulativeEdge(Box::CONTENT, Box::LEFT) +
 										   box.GetCumulativeEdge(Box::CONTENT, Box::RIGHT) +
-										   scrollbars[orientation].element->ResolveProperty(HEIGHT, element_width);
+										   ResolveProperty(scrollbars[orientation].element->GetComputedValues().height, element_width);
 		else
 			scrollbars[orientation].size = box.GetSize(Box::MARGIN).y;
 	}
@@ -192,7 +192,7 @@ void ElementScroll::FormatScrollbars()
 		}
 
 		float slider_length = containing_block[1 - i];
-		float user_scrollbar_margin = scrollbars[i].element->ResolveProperty(SCROLLBAR_MARGIN, slider_length);
+		float user_scrollbar_margin = scrollbars[i].element->GetComputedValues().scrollbar_margin;
 		float min_scrollbar_margin = GetScrollbarSize(i == VERTICAL ? HORIZONTAL : VERTICAL);
 		slider_length -= Math::Max(user_scrollbar_margin, min_scrollbar_margin);
 

+ 8 - 76
Source/Core/ElementStyle.cpp

@@ -476,22 +476,6 @@ float ElementStyle::ResolveAngle(const Property * property)
 	return 0.0f;
 }
 
-float ElementStyle::ResolveNumericProperty(const String& property_name, const Property * property)
-{
-	if ((property->unit & Property::LENGTH) && !(property->unit == Property::EM && property_name == FONT_SIZE))
-	{
-		return ResolveLength(property);
-	}
-
-	auto definition = property->definition;
-	if (!definition) definition = StyleSheetSpecification::GetProperty(property_name);
-	if (!definition) return 0.0f;
-
-	auto relative_target = definition->GetRelativeTarget();
-	
-	return ResolveNumericProperty(property, relative_target);
-}
-
 float ElementStyle::ResolveNumericProperty(const Property * property, RelativeTarget relative_target)
 {
 	// There is an exception on font-size properties, as 'em' units here refer to parent font size instead
@@ -596,60 +580,6 @@ float ElementStyle::ResolveProperty(const Property* property, float base_value)
 	return 0.0f;
 }
 
-// Resolves one of this element's properties.
-float ElementStyle::ResolveProperty(const String& name, float base_value)
-{
-	const Property* property = GetProperty(name);
-	if (!property)
-	{
-		ROCKET_ERROR;
-		return 0.0f;
-	}
-
-	// The calculated value of the font-size property is inherited, so we need to check if this
-	// is an inherited property. If so, then we return our parent's font size instead.
-	if (name == FONT_SIZE && property->unit & Property::RELATIVE_UNIT)
-	{
-		// If the rem unit is used, the font-size is inherited directly from the document,
-		// otherwise we use the parent's font size.
-		if (property->unit & Property::REM)
-		{
-			Rocket::Core::ElementDocument* owner_document = element->GetOwnerDocument();
-			if (owner_document == NULL)
-				return 0;
-
-			base_value = owner_document->ResolveProperty(FONT_SIZE, 0);
-		}
-		else
-		{
-			Rocket::Core::Element* parent = element->GetParentNode();
-			if (parent == NULL)
-				return 0;
-
-			if (GetLocalProperty(FONT_SIZE) == NULL)
-				return parent->ResolveProperty(FONT_SIZE, 0);
-
-			// The base value for font size is always the height of *this* element's parent's font.
-			base_value = parent->ResolveProperty(FONT_SIZE, 0);
-		}
-
-		switch (property->unit)
-		{
-			case Property::PERCENT:
-				return base_value * property->value.Get< float >() * 0.01f;
-
-			case Property::EM:
-				return property->value.Get< float >() * base_value;
-
-			case Property::REM:
-				// If an rem-relative font size is specified, it is expressed relative to the document's
-				// font height.
-				return property->value.Get< float >() * element->GetOwnerDocument()->GetComputedValues().font_size;
-		}
-	}
-
-	return ResolveProperty(property, base_value);
-}
 
 // Iterates over the properties defined on the element.
 bool ElementStyle::IterateProperties(int& index, String& name, const Property*& property, const PseudoClassList** property_pseudo_classes)
@@ -921,22 +851,24 @@ static float ComputeLength(const Property* property, float font_size, float docu
 		return 0.0f;
 	}
 
+	float value = property->value.Get<float>();
+
 	switch (property->unit)
 	{
 	case Property::NUMBER:
 	case Property::PX:
 	case Property::RAD:
-		return property->value.Get< float >();
+		return value;
 
 	case Property::EM:
-		return property->value.Get< float >() * font_size;
+		return value * font_size;
 	case Property::REM:
-		return property->value.Get< float >() * document_font_size;
+		return value * document_font_size;
 	case Property::DP:
-		return property->value.Get< float >() * dp_ratio;
+		return value * dp_ratio;
 
 	case Property::DEG:
-		return Math::DegreesToRadians(property->value.Get< float >());
+		return Math::DegreesToRadians(value);
 	default: 
 		break;
 	}
@@ -944,7 +876,7 @@ static float ComputeLength(const Property* property, float font_size, float docu
 	// Values based on pixels-per-inch.
 	if (property->unit & Property::PPI_UNIT)
 	{
-		float inch = property->value.Get< float >() * pixels_per_inch;
+		float inch = value * pixels_per_inch;
 
 		switch (property->unit)
 		{

+ 1 - 11
Source/Core/ElementStyle.h

@@ -111,10 +111,7 @@ public:
 	
 	/// Resolves an angle to radians
 	static float ResolveAngle(const Property* property);
-
-	/// Resolves a number-length-percentage property to pixels.
-	float ResolveNumericProperty(const String& property_name, const Property* property);
-
+	
 	/// Resolves the canonical unit (pixels) from 'number-length-percent' property.
 	/// 'percentage' and 'number' gets multiplied by the size of the specified relative reference.
 	float ResolveNumericProperty(const Property* property, RelativeTarget relative_target);
@@ -126,13 +123,6 @@ public:
 	/// @param[in] base_value The value that is scaled by the percentage value, if it is a percentage.
 	/// @return The value of this property for this element.
 	float ResolveProperty(const Property *property, float base_value);
-	/// Resolves one of this element's properties. If the value is a number or px, this is returned. If it's a 
-	/// percentage then it is resolved based on the second argument (the base value).
-	/// If it's an angle, it is returned as radians.
-	/// @param[in] name The name of the property to resolve the value for.
-	/// @param[in] base_value The value that is scaled by the percentage value, if it is a percentage.
-	/// @return The value of this property for this element.
-	float ResolveProperty(const String& name, float base_value);
 
 	/// Iterates over the properties defined on the element.
 	/// @param[inout] index Index of the property to fetch. This is incremented to the next valid index after the fetch. Indices are not necessarily incremental.

+ 1 - 0
readme.md

@@ -16,6 +16,7 @@ If upgrading from the original libRocket branch, some breaking changes should be
 
 - Rocket::Core::String has been replaced by std::string, thus, interfacing with the library now requires you to change your string types. This change was motivated by a small performance gain, additionally, it should make it easier to interface with the library especially for users already using std::string in their codebase.
 - Querying the property of an element for size, position and similar may not work as expected right after changes to the document or style. This change is made for performance reasons, see the note below for reasoning and a workaround.
+- The Controls::DataGrid "min-rows" property has been replaced by an attribute of the same name.
 
 ## Performance