From 209e5e101e4d8bfd10b973fc80ae4be398244c4a Mon Sep 17 00:00:00 2001 From: "evaughan%netscape.com" Date: Mon, 3 May 1999 19:04:16 +0000 Subject: [PATCH] Fixed bug #5619. With Chris Hofmann's ok. --- xpfe/appshell/src/nsWebShellWindow.cpp | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index fb656585152b..a40e1d5c7b89 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -701,6 +701,64 @@ void nsWebShellWindow::DynamicLoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aP //fake event nsMenuEvent fake; menuListener->MenuConstruct(fake, aParentWindow, menubarNode, mWebShell); + + // XXX ok this is somewhat of a kludge but it is needed. When the menu bar is added the client area got smaller + // unfortunately the document will already have been flowed. So we need to reflow it to a smaller size. -EDV + // BEGIN REFLOW CODE + nsresult rv = NS_ERROR_FAILURE; + + // do a reflow + nsCOMPtr contentViewerContainer; + contentViewerContainer = do_QueryInterface(mWebShell); + if (!contentViewerContainer) { + NS_ERROR("Webshell doesn't support the content viewer container interface"); + return; + } + + nsCOMPtr contentViewer; + if (NS_FAILED(rv = contentViewerContainer->GetContentViewer(getter_AddRefs(contentViewer)))) { + NS_ERROR("Unable to retrieve content viewer."); + return; + } + + nsCOMPtr docViewer; + docViewer = do_QueryInterface(contentViewer); + if (!docViewer) { + NS_ERROR("Document viewer interface not supported by the content viewer."); + return; + } + + nsCOMPtr presContext; + if (NS_FAILED(rv = docViewer->GetPresContext(*getter_AddRefs(presContext)))) { + NS_ERROR("Unable to retrieve the doc viewer's presentation context."); + return; + } + + nsCOMPtr presShell; + if (NS_FAILED(rv = presContext->GetShell(getter_AddRefs(presShell)))) { + NS_ERROR("Unable to retrieve the shell from the presentation context."); + return; + } + + + nsRect rect; + + if (NS_FAILED(rv = mWindow->GetClientBounds(rect))) { + NS_ERROR("Failed to get web shells bounds"); + return; + } + + // convert to twips + float p2t; + presContext->GetScaledPixelsToTwips(&p2t); + rect.width = NSIntPixelsToTwips(rect.width, p2t); + rect.height = NSIntPixelsToTwips(rect.height, p2t); + + if (NS_FAILED(rv = presShell->ResizeReflow(rect.width,rect.height))) { + NS_ERROR("Failed to reflow the document after the menu was added"); + return; + } + // END REFLOW CODE } // end if ( nsnull != pnsMenuBar ) }