From 614a854ff4a0b3e99a57a52364c8312edebcf9b0 Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Fri, 23 Apr 2010 12:26:38 +1200 Subject: [PATCH] Bug 550330. Try harder to find a document with a layer manager that we can use to create our ImageContainer. r=mats --- .../html/content/src/nsHTMLMediaElement.cpp | 51 ++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 97165ac43a6..74404b0e219 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -85,6 +85,7 @@ #include "nsVideoFrame.h" #include "BasicLayers.h" #include +#include "nsIDocShellTreeItem.h" #ifdef MOZ_OGG #include "nsOggDecoder.h" @@ -1752,26 +1753,42 @@ void nsHTMLMediaElement::NotifyAutoplayDataReady() */ static already_AddRefed GetLayerManagerForDoc(nsIDocument* aDoc) { - while (aDoc) { - nsIDocument* displayDoc = aDoc->GetDisplayDocument(); - if (displayDoc) { - aDoc = displayDoc; - continue; - } + nsIDocument* doc = aDoc; + nsIDocument* displayDoc = doc->GetDisplayDocument(); + if (displayDoc) { + doc = displayDoc; + } - nsIPresShell* shell = aDoc->GetPrimaryShell(); - if (shell) { - nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame(); - if (rootFrame) { - nsIWidget* widget = - nsLayoutUtils::GetDisplayRootFrame(rootFrame)->GetWindow(); - if (widget) { - nsRefPtr manager = widget->GetLayerManager(); - return manager.forget(); - } + nsIPresShell* shell = doc->GetPrimaryShell(); + nsCOMPtr container = doc->GetContainer(); + nsCOMPtr docShellTreeItem = do_QueryInterface(container); + while (!shell && docShellTreeItem) { + // We may be in a display:none subdocument, or we may not have a presshell + // created yet. + // Walk the docshell tree to find the nearest container that has a presshell, + // and find the root widget from that. + nsCOMPtr docShell = do_QueryInterface(docShellTreeItem); + nsCOMPtr presShell; + docShell->GetPresShell(getter_AddRefs(presShell)); + if (presShell) { + shell = presShell; + } else { + nsCOMPtr parent; + docShellTreeItem->GetParent(getter_AddRefs(parent)); + docShellTreeItem = parent; + } + } + + if (shell) { + nsIFrame* rootFrame = shell->FrameManager()->GetRootFrame(); + if (rootFrame) { + nsIWidget* widget = + nsLayoutUtils::GetDisplayRootFrame(rootFrame)->GetWindow(); + if (widget) { + nsRefPtr manager = widget->GetLayerManager(); + return manager.forget(); } } - aDoc = aDoc->GetParentDocument(); } nsRefPtr manager = new BasicLayerManager(nsnull);