From 21dd9765213fdfcc1909afcf230ce99bba554591 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Sun, 12 Sep 2004 20:53:27 +0000 Subject: [PATCH] Make sure to flush restyles _before_ we start grabbing layout objects like presshells, not after... Bug 258032, r+sr=jst --- .../html/content/src/nsGenericHTMLElement.cpp | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index d4ea7678a36..568d7113505 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -590,6 +590,11 @@ nsGenericHTMLElement::GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent) return; } + // Flush all pending notifications so that our frames are up to date. Make + // sure to do this first thing, since it may end up destroying our document's + // presshell. + document->FlushPendingNotifications(Flush_Layout); + // Get Presentation shell 0 nsIPresShell *presShell = document->GetShellAt(0); @@ -603,9 +608,6 @@ nsGenericHTMLElement::GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent) return; } - // Flush all pending notifications so that our frames are uptodate - document->FlushPendingNotifications(Flush_Layout); - // Get the Frame for our content nsIFrame* frame = nsnull; presShell->GetPrimaryFrameFor(this, &frame); @@ -962,6 +964,9 @@ nsGenericHTMLElement::GetScrollInfo(nsIScrollableView **aScrollableView, return; } + // Flush all pending notifications so that our frames are up to date. Make + // sure to do this first thing, since it may end up destroying our document's + // presshell. document->FlushPendingNotifications(Flush_Layout); // Get the presentation shell @@ -1256,20 +1261,23 @@ nsGenericHTMLElement::GetClientWidth(PRInt32* aClientWidth) nsresult nsGenericHTMLElement::ScrollIntoView(PRBool aTop) { - if (!IsInDoc()) { + nsIDocument *document = GetCurrentDoc(); + + if (!document) { return NS_OK; } + // Flush all pending notifications so that our frames are up to date. Make + // sure to do this first thing, since it may end up destroying our document's + // presshell. + document->FlushPendingNotifications(Flush_Layout); + // Get the presentation shell - nsIDocument *document = GetOwnerDoc(); nsIPresShell *presShell = document->GetShellAt(0); if (!presShell) { return NS_OK; } - // Now flush to make sure things are up to date - document->FlushPendingNotifications(Flush_Layout); - // Get the primary frame for this element nsIFrame *frame = nsnull; presShell->GetPrimaryFrameFor(this, &frame);