Browse Source

Debugger: Display offset parent.

Michael Ragazzon 5 years ago
parent
commit
6b6b108563
3 changed files with 35 additions and 5 deletions
  1. 33 4
      Source/Debugger/ElementInfo.cpp
  2. 1 1
      Source/Debugger/ElementInfo.h
  3. 1 0
      Source/Debugger/InfoSource.h

+ 33 - 4
Source/Debugger/ElementInfo.cpp

@@ -232,6 +232,15 @@ void ElementInfo::ProcessEvent(Event& event)
 						force_update_once = true;
 					}
 				}
+				else if (id == "offset_parent")
+				{
+					if (source_element)
+					{
+						Element* offset_parent = source_element->GetOffsetParent();
+						if (offset_parent)
+							SetSourceElement(offset_parent);
+					}
+				}
 				// Check if the id is in the form "a %d" or "c %d" - these are the ancestor or child labels.
 				else
 				{
@@ -288,6 +297,11 @@ void ElementInfo::ProcessEvent(Event& event)
 					if (source_element != nullptr)
 						hover_element = source_element->GetChild(element_index);
 				}
+				else if (id == "offset_parent")
+				{
+					if (source_element)
+						hover_element = source_element->GetOffsetParent();
+				}
 				else
 				{
 					hover_element = nullptr;
@@ -489,25 +503,40 @@ void ElementInfo::UpdateSourceElement()
 	// Set the position
 	if (Element* position_content = GetElementById("position-content"))
 	{
+		String position;
+
 		// left, top, width, height.
 		if (source_element != nullptr)
 		{
 			const Vector2f element_offset = source_element->GetRelativeOffset(Box::BORDER);
 			const Vector2f element_size = source_element->GetBox().GetSize(Box::BORDER);
+			Element* offset_parent = source_element->GetOffsetParent();
+			const String offset_parent_rml = (offset_parent ? StringUtilities::EncodeRml(offset_parent->GetAddress(false, false)) : String("<em>none</em>"));
 
-			const String positions = 
+			position = 
 				"<span class='name'>left: </span><em>"   + ToString(element_offset.x) + "px</em><br/>" +
 				"<span class='name'>top: </span><em>"    + ToString(element_offset.y) + "px</em><br/>" +
 				"<span class='name'>width: </span><em>"  + ToString(element_size.x)   + "px</em><br/>" +
-				"<span class='name'>height: </span><em>" + ToString(element_size.y)   + "px</em><br/>";
-
-			position_content->SetInnerRML( positions );
+				"<span class='name'>height: </span><em>" + ToString(element_size.y)   + "px</em><br/>" +
+				"<span class='name'>offset parent: </span><p style='display: inline' id='offset_parent'>" + offset_parent_rml + "</p>";
 		}
 		else
 		{
 			while (position_content->HasChildNodes())
 				position_content->RemoveChild(position_content->GetFirstChild());
 		}
+
+		if (position.empty())
+		{
+			while (position_content->HasChildNodes())
+				position_content->RemoveChild(position_content->GetFirstChild());
+			position_rml.clear();
+		}
+		else if (position != position_rml)
+		{
+			position_content->SetInnerRML(position);
+			position_rml = std::move(position);
+		}
 	}
 
 	// Set the ancestors

+ 1 - 1
Source/Debugger/ElementInfo.h

@@ -80,7 +80,7 @@ private:
 
 	double previous_update_time;
 
-	String attributes_rml, properties_rml, events_rml, ancestors_rml, children_rml;
+	String attributes_rml, properties_rml, events_rml, position_rml, ancestors_rml, children_rml;
 
 	// Enables or disables the selection of elements in user context.
 	bool enable_element_select;

+ 1 - 0
Source/Debugger/InfoSource.h

@@ -54,6 +54,7 @@ div#content .name
 {
 	color: #610;
 }
+div#position p:hover,
 div#ancestors p:hover,
 div#children p:hover
 {