Browse Source

Clean up iframe document

(cherry picked from commit 272dbccd340e53d0065b853fbd2527cc5e9c233b)
Michael Ragazzon 6 years ago
parent
commit
0221ea05c7
1 changed files with 13 additions and 2 deletions
  1. 13 2
      Source/Core/Context.cpp

+ 13 - 2
Source/Core/Context.cpp

@@ -823,8 +823,19 @@ void Context::OnElementDetach(Element* element)
 		}
 		}
 	}
 	}
 
 
-	// Focus already cleared by Element::RemoveChild
-	RMLUI_ASSERT(element != focus); 
+	// Focus normally cleared and set by parent during Element::RemoveChild.
+	// However, there are some exceptions, such as when an there are multiple 
+	// ElementDocuments in the hierarchy above the current element.
+	if (element == focus)
+		focus = nullptr;
+
+	// If the element is a document lower down in the hierarchy, we may need to remove it from the focus history.
+	if (element->GetOwnerDocument() == element)
+	{
+		auto it = std::find(document_focus_history.begin(), document_focus_history.end(), element);
+		if (it != document_focus_history.end())
+			document_focus_history.erase(it);
+	}
 }
 }
 
 
 // Internal callback for when a new element gains focus
 // Internal callback for when a new element gains focus