Browse Source

Add IsLayoutDirty method to Element class

Use it to quickly check whether document layout has already been marked as dirty. Makes it possible to skip expensive checks needed to mark it as such in Element::OnPropertyChange
Victor Luchitz 13 years ago
parent
commit
9767f75af5

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

@@ -571,6 +571,9 @@ protected:
 	/// Forces a re-layout of this element, and any other elements required.
 	/// Forces a re-layout of this element, and any other elements required.
 	virtual void DirtyLayout();
 	virtual void DirtyLayout();
 
 
+	/// Returns true if the element has been marked as needing a re-layout.
+	virtual bool IsLayoutDirty();
+
 	/// Forces a reevaluation of applicable font effects.
 	/// Forces a reevaluation of applicable font effects.
 	virtual void DirtyFont();
 	virtual void DirtyFont();
 
 

+ 3 - 0
Include/Rocket/Core/ElementDocument.h

@@ -144,6 +144,9 @@ protected:
 	/// Sets the dirty flag on the layout so the document will format its children before the next render.
 	/// Sets the dirty flag on the layout so the document will format its children before the next render.
 	virtual void DirtyLayout();
 	virtual void DirtyLayout();
 
 
+	/// Returns true if the document has been marked as needing a re-layout.
+	virtual bool IsLayoutDirty();
+
 	/// Processes the 'onpropertychange' event, checking for a change in position or size.
 	/// Processes the 'onpropertychange' event, checking for a change in position or size.
 	virtual void ProcessEvent(Event& event);
 	virtual void ProcessEvent(Event& event);
 
 

+ 24 - 12
Source/Core/Element.cpp

@@ -1350,22 +1350,25 @@ void Element::OnPropertyChange(const PropertyNameList& changed_properties)
 {
 {
 	bool all_dirty = StyleSheetSpecification::GetRegisteredProperties() == changed_properties;
 	bool all_dirty = StyleSheetSpecification::GetRegisteredProperties() == changed_properties;
 
 
-	// Force a relayout if any of the changed properties require it.
-	if (all_dirty)
+	if (!IsLayoutDirty())
 	{
 	{
-		DirtyLayout();
-	}
-	else
-	{
-		for (PropertyNameList::const_iterator i = changed_properties.begin(); i != changed_properties.end(); ++i)
+		if (all_dirty)
 		{
 		{
-			const PropertyDefinition* property_definition = StyleSheetSpecification::GetProperty(*i);
-			if (property_definition)
+			DirtyLayout();
+		}
+		else
+		{
+			// Force a relayout if any of the changed properties require it.
+			for (PropertyNameList::const_iterator i = changed_properties.begin(); i != changed_properties.end(); ++i)
 			{
 			{
-				if (property_definition->IsLayoutForced())
+				const PropertyDefinition* property_definition = StyleSheetSpecification::GetProperty(*i);
+				if (property_definition)
 				{
 				{
-					DirtyLayout();
-					break;
+					if (property_definition->IsLayoutForced())
+					{
+						DirtyLayout();
+						break;
+					}
 				}
 				}
 			}
 			}
 		}
 		}
@@ -1557,6 +1560,15 @@ void Element::DirtyLayout()
 		document->DirtyLayout();
 		document->DirtyLayout();
 }
 }
 
 
+// Forces a re-layout of this element, and any other children required.
+bool Element::IsLayoutDirty()
+{
+	Element* document = GetOwnerDocument();
+	if (document != NULL)
+		return document->IsLayoutDirty();
+	return false;
+}
+
 // Forces a reevaluation of applicable font effects.
 // Forces a reevaluation of applicable font effects.
 void Element::DirtyFont()
 void Element::DirtyFont()
 {
 {

+ 5 - 0
Source/Core/ElementDocument.cpp

@@ -354,6 +354,11 @@ void ElementDocument::DirtyLayout()
 	layout_dirty = true;
 	layout_dirty = true;
 }
 }
 
 
+bool ElementDocument::IsLayoutDirty()
+{
+	return layout_dirty;
+}
+
 // Refreshes the document layout if required.
 // Refreshes the document layout if required.
 void ElementDocument::OnUpdate()
 void ElementDocument::OnUpdate()
 {
 {