Fix for painting problems in embedding apps when window is moved offscreen and back on. b=78412 r=ccarlen@netscape.com sr=blizzard@mozilla.org

This commit is contained in:
locka%iol.ie 2001-05-07 13:49:59 +00:00
parent 4b6d35d108
commit cadbd61379
2 changed files with 20 additions and 44 deletions

View File

@ -30,7 +30,6 @@
//Interfaces Needed
#include "nsIComponentManager.h"
#include "nsIDeviceContext.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMWindow.h"
@ -45,6 +44,10 @@
#include "nsIWebBrowserFocus.h"
#include "nsIPresShell.h"
// for painting the background window
#include "nsIDeviceContext.h"
#include "nsIRenderingContext.h"
// Printing Includes
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
@ -52,12 +55,11 @@
#include "nsIPrintOptions.h"
#include "nsGfxCIID.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID);
static NS_DEFINE_CID(kWebShellCID, NS_WEB_SHELL_CID);
static NS_DEFINE_IID(kChildCID, NS_CHILD_CID);
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
//*****************************************************************************
//*** nsWebBrowser: Object Management
@ -748,19 +750,6 @@ NS_IMETHODIMP nsWebBrowser::Create()
nsCOMPtr<nsIWidget> docShellParentWidget(mParentWidget);
if(!mParentWidget) // We need to create a widget
{
nsCOMPtr<nsIDeviceContext> deviceContext =
do_CreateInstance(kDeviceContextCID);
NS_ENSURE_TRUE(deviceContext, NS_ERROR_FAILURE);
deviceContext->Init(mParentNativeWindow);
float dev2twip;
deviceContext->GetDevUnitsToTwips(dev2twip);
deviceContext->SetDevUnitsToAppUnits(dev2twip);
float twip2dev;
deviceContext->GetTwipsToDevUnits(twip2dev);
deviceContext->SetAppUnitsToDevUnits(twip2dev);
deviceContext->SetGamma(1.0f);
// Create the widget
NS_ENSURE_TRUE(mInternalWidget = do_CreateInstance(kChildCID), NS_ERROR_FAILURE);
@ -773,20 +762,17 @@ NS_IMETHODIMP nsWebBrowser::Create()
mInternalWidget->SetClientData(NS_STATIC_CAST(nsWebBrowser *, this));
mInternalWidget->Create(mParentNativeWindow, bounds, nsWebBrowser::HandleEvent,
deviceContext, nsnull, nsnull, &widgetInit);
nsnull, nsnull, nsnull, &widgetInit);
}
// create a rendering context and device context for this widget
mDC = do_CreateInstance(kDeviceContextCID);
mDC->Init(mInternalWidget->GetNativeData(NS_NATIVE_WINDOW));
mRC = do_CreateInstance(kRenderingContextCID);
mRC->Init(mDC, mInternalWidget.get());
// get the default background color for painting later
// get the system default window background colour
nsCOMPtr<nsIDeviceContext> dc = do_CreateInstance(kDeviceContextCID);
dc->Init(mInternalWidget->GetNativeData(NS_NATIVE_WINDOW));
SystemAttrStruct info;
info.mColor = &mBackgroundColor;
mDC->GetSystemAttribute(eSystemAttr_Color_WindowBackground, &info);
dc->GetSystemAttribute(eSystemAttr_Color_WindowBackground, &info);
dc = nsnull;
nsCOMPtr<nsIDocShell> docShell(do_CreateInstance(kWebShellCID));
NS_ENSURE_SUCCESS(SetDocShell(docShell), NS_ERROR_FAILURE);
@ -1303,13 +1289,6 @@ NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner()
return NS_OK;
}
NS_IMETHODIMP nsWebBrowser::FillBackground(const nsRect &aRect)
{
mRC->SetColor(mBackgroundColor);
mRC->FillRect(aRect);
return NS_OK;
}
/* static */
nsEventStatus PR_CALLBACK nsWebBrowser::HandleEvent(nsGUIEvent *aEvent)
{
@ -1329,8 +1308,13 @@ nsEventStatus PR_CALLBACK nsWebBrowser::HandleEvent(nsGUIEvent *aEvent)
switch(aEvent->message) {
case NS_PAINT: {
nsRect *rect = NS_STATIC_CAST(nsPaintEvent *, aEvent)->rect;
browser->FillBackground(*rect);
nsPaintEvent *paintEvent = NS_STATIC_CAST(nsPaintEvent *, aEvent);
nsIRenderingContext *rc = paintEvent->renderingContext;
nscolor oldColor;
rc->GetColor(oldColor);
rc->SetColor(browser->mBackgroundColor);
rc->FillRect(*paintEvent->rect);
rc->SetColor(oldColor);
break;
}

View File

@ -49,10 +49,6 @@
#include "nsIWebBrowserPrint.h"
#include "nsIWindowWatcher.h"
// for painting the background window
#include "nsIDeviceContext.h"
#include "nsIRenderingContext.h"
#include "nsVoidArray.h"
#include "nsWeakPtr.h"
@ -123,8 +119,6 @@ protected:
NS_IMETHOD BindListener(nsISupports *aListener, const nsIID& aIID);
NS_IMETHOD UnBindListener(nsISupports *aListener, const nsIID& aIID);
NS_IMETHOD FillBackground(const nsRect &aRect);
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
protected:
@ -144,9 +138,7 @@ protected:
nsIWebBrowserPersistProgress *mProgressListener;
nsCOMPtr<nsIWebProgress> mWebProgress;
// so that we can draw when we get expose events
nsCOMPtr<nsIRenderingContext> mRC;
nsCOMPtr<nsIDeviceContext> mDC;
// cached background color
nscolor mBackgroundColor;
//Weak Reference interfaces...