Forráskód Böngészése

Change document positioning so that inset properties now properly set the margin position of the document

Michael Ragazzon 2 éve
szülő
commit
2be642f969
2 módosított fájl, 17 hozzáadás és 14 törlés
  1. 14 11
      Source/Core/ElementDocument.cpp
  2. 3 3
      Source/Core/ElementScroll.cpp

+ 14 - 11
Source/Core/ElementDocument.cpp

@@ -440,7 +440,7 @@ void ElementDocument::UpdateLayout()
 // Updates the position of the document based on the style properties.
 void ElementDocument::UpdatePosition()
 {
-	if(position_dirty)
+	if (position_dirty)
 	{
 		RMLUI_ZoneScoped;
 
@@ -448,29 +448,32 @@ void ElementDocument::UpdatePosition()
 
 		Element* root = GetParentNode();
 
-		// We only position ourselves if we are a child of our context's root element. That is, we don't want to proceed if we are unparented or an iframe document.
+		// We only position ourselves if we are a child of our context's root element. That is, we don't want to proceed
+		// if we are unparented or an iframe document.
 		if (!root || !context || (root != context->GetRootElement()))
 			return;
 
-		Vector2f position;
 		// Work out our containing block; relative offsets are calculated against it.
-		Vector2f containing_block = root->GetBox().GetSize(Box::CONTENT);
-
+		const Vector2f containing_block = root->GetBox().GetSize();
 		auto& computed = GetComputedValues();
+		const Box& box = GetBox();
+
+		Vector2f position;
 
 		if (computed.left().type != Style::Left::Auto)
 			position.x = ResolveValue(computed.left(), containing_block.x);
 		else if (computed.right().type != Style::Right::Auto)
-			position.x = (containing_block.x - GetBox().GetSize(Box::MARGIN).x) - ResolveValue(computed.right(), containing_block.x);
-		else
-			position.x = GetBox().GetEdge(Box::MARGIN, Box::LEFT);
+			position.x = containing_block.x - (box.GetSize(Box::MARGIN).x + ResolveValue(computed.right(), containing_block.x));
 
 		if (computed.top().type != Style::Top::Auto)
 			position.y = ResolveValue(computed.top(), containing_block.y);
 		else if (computed.bottom().type != Style::Bottom::Auto)
-			position.y = (containing_block.y - GetBox().GetSize(Box::MARGIN).y) - ResolveValue(computed.bottom(), containing_block.y);
-		else
-			position.y = GetBox().GetEdge(Box::MARGIN, Box::TOP);
+			position.y = containing_block.y - (box.GetSize(Box::MARGIN).y + ResolveValue(computed.bottom(), containing_block.y));
+
+		// Add the margin edge to the position, since inset properties (top/right/bottom/left) set the margin edge
+		// position, while offsets use the border edge.
+		position.x += box.GetEdge(Box::MARGIN, Box::LEFT);
+		position.y += box.GetEdge(Box::MARGIN, Box::TOP);
 
 		SetOffset(position, nullptr);
 	}

+ 3 - 3
Source/Core/ElementScroll.cpp

@@ -201,7 +201,6 @@ void ElementScroll::FormatScrollbars()
 		corner_box.SetContent(Vector2f(scrollbars[VERTICAL].size, scrollbars[HORIZONTAL].size));
 		corner->SetBox(corner_box);
 		corner->SetOffset(containing_block + element_box.GetPosition(Box::PADDING) - Vector2f(scrollbars[VERTICAL].size, scrollbars[HORIZONTAL].size), element, true);
-		corner->SetProperty(PropertyId::Clip, Property(1, Property::NUMBER));
 
 		corner->SetProperty(PropertyId::Visibility, Property(Style::Visibility::Visible));
 	}
@@ -213,7 +212,7 @@ bool ElementScroll::CreateScrollbar(Orientation orientation)
 	if (scrollbars[orientation].element &&
 		scrollbars[orientation].widget)
 		return true;
-
+	
 	ElementPtr scrollbar_element = Factory::InstanceElement(element, "*", orientation == VERTICAL ? "scrollbarvertical" : "scrollbarhorizontal", XMLAttributes());
 	scrollbars[orientation].element = scrollbar_element.get();
 	scrollbars[orientation].element->SetProperty(PropertyId::Clip, Property(1, Property::NUMBER));
@@ -236,8 +235,9 @@ bool ElementScroll::CreateCorner()
 
 	ElementPtr corner_element = Factory::InstanceElement(element, "*", "scrollbarcorner", XMLAttributes());
 	corner = corner_element.get();
-	Element* child = element->AppendChild(std::move(corner_element), false);
+	corner->SetProperty(PropertyId::Clip, Property(1, Property::NUMBER));
 
+	Element* child = element->AppendChild(std::move(corner_element), false);
 	UpdateScrollElementProperties(child);
 
 	return true;