瀏覽代碼

Debugger: Some style attributes need to be fetched manually

Michael Ragazzon 6 年之前
父節點
當前提交
acac7fbedf

+ 4 - 1
Include/Rocket/Core/Element.h

@@ -213,7 +213,10 @@ public:
 	/// returned.
 	/// @param[in] name The name of the property to fetch the value for.
 	/// @return The value of this property for this element, or NULL if this property has not been explicitly defined for this element.
-	const Property* GetLocalProperty(const String& name);		
+	const Property* GetLocalProperty(const String& name);
+	/// 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.

+ 1 - 1
Include/Rocket/Core/PropertyDictionary.h

@@ -34,7 +34,7 @@
 namespace Rocket {
 namespace Core {
 
-typedef std::unordered_map< String, Property > PropertyMap;
+
 
 /**
 	A dictionary to property names to values.

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

@@ -93,6 +93,7 @@ typedef ColumnMajorMatrix4f Matrix4f;
 class Element;
 class Dictionary;
 class ElementAnimation;
+class Property;
 
 // Types for external interfaces.
 typedef uintptr_t FileHandle;
@@ -107,6 +108,7 @@ typedef std::unordered_set< String > PropertyNameList;
 typedef std::unordered_set< String > AttributeNameList;
 typedef Dictionary ElementAttributes;
 typedef std::vector< ElementAnimation > ElementAnimationList;
+typedef std::unordered_map< String, Property > PropertyMap;
 
 // Reference types
 typedef std::shared_ptr< Transform > TransformRef;

+ 6 - 0
Source/Core/Element.cpp

@@ -1,3 +1,4 @@
+#include "..\..\Include\Rocket\Core\Element.h"
 /*
  * This source file is part of libRocket, the HTML/CSS Interface Middleware
  *
@@ -546,6 +547,11 @@ const Property* Element::GetLocalProperty(const String& name)
 	return style->GetLocalProperty(name);
 }
 
+const PropertyMap * Element::GetLocalProperties()
+{
+	return style->GetLocalProperties();
+}
+
 // Resolves one of this element's style.
 float Element::ResolveProperty(const String& name, float base_value)
 {

+ 7 - 0
Source/Core/ElementStyle.cpp

@@ -419,6 +419,13 @@ const Property* ElementStyle::GetLocalProperty(const String& name)
 	return GetLocalProperty(name, local_properties, definition, pseudo_classes);
 }
 
+const PropertyMap * ElementStyle::GetLocalProperties() const
+{
+	if (local_properties)
+		return &local_properties->GetProperties();
+	return NULL;
+}
+
 float ElementStyle::ResolveLength(const Property * property)
 {
 	if (!property)

+ 3 - 0
Source/Core/ElementStyle.h

@@ -105,6 +105,9 @@ public:
 	/// @param[in] name The name of the property to fetch the value for.
 	/// @return The value of this property for this element, or NULL if this property has not been explicitly defined for this element.
 	const Property* GetLocalProperty(const String& name);
+	/// 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() const;
 
 
 	/// Resolves a length property to pixels. Note: This excludes percentages.

+ 44 - 1
Source/Debugger/ElementInfo.cpp

@@ -241,8 +241,51 @@ void ElementInfo::UpdateSourceElement()
 
 		if (source_element != NULL)
 		{
+			// The element's attribute list is not always synchronized with its internal values, fetch  
+			// them manually here (see e.g. Element::OnAttributeChange for relevant attributes)
+			{
+				name = "id";
+				value = source_element->GetId();
+				if (!value.Empty())
+					attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
+			}
+			{
+				name = "class";
+				value = source_element->GetClassNames();
+				if (!value.Empty())
+					attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
+			}
+			{
+				// Not actually an attribute, but may be useful
+				name = "pseudo";
+				value.Clear();
+				for (auto str : source_element->GetActivePseudoClasses())
+					value += " :" + str;
+				if (!value.Empty())
+					attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
+			}
+			{
+				name = "style";
+				value = "";
+				auto local_properties = source_element->GetLocalProperties();
+				if (local_properties)
+				{
+					for (auto nvp : *local_properties)
+					{
+						auto& prop_name = nvp.first;
+						auto prop_value = nvp.second.ToString();
+						value.Append(Core::String(prop_name.Length() + prop_value.Length() + 12, "%s: %s; ", prop_name.CString(), prop_value.CString()));
+					}
+				}
+				if (!value.Empty())
+					attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
+			}
+
 			while (source_element->IterateAttributes(index, name, value))
-				attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
+			{
+				if(name != "class" && name != "style" && name != "id") 
+					attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString()));
+			}
 		}
 
 		if (attributes.Empty())