This commit is contained in:
michaelp%netscape.com 1998-11-14 01:58:34 +00:00
Родитель f186598ef5
Коммит d7d8293d07
12 изменённых файлов: 287 добавлений и 90 удалений

Просмотреть файл

@ -354,6 +354,11 @@ public:
* @return error status
*/
NS_IMETHOD EnableRefresh(void) = 0;
//XXX this needs to take parameters to tell
//it what part of the document to display, not just the
//whole thing. MMP
NS_IMETHOD Display(void) = 0;
};
//when the refresh happens, should it be double buffered?

Просмотреть файл

@ -332,7 +332,15 @@ NS_IMETHODIMP nsView :: Paint(nsIRenderingContext& rc, const nsRect& rect,
kid->GetWidget(widget);
hasWidget = (widget != nsnull);
NS_IF_RELEASE(widget);
if (nsnull != widget)
{
void *thing;
thing = widget->GetNativeData(NS_NATIVE_WIDGET);
NS_RELEASE(widget);
if (nsnull == thing)
hasWidget = PR_FALSE;
}
if (!hasWidget)
{
nsRect kidRect;
@ -1139,14 +1147,21 @@ NS_IMETHODIMP nsView :: CreateWidget(const nsIID &aWindowIID,
if (NS_OK == LoadWidget(aWindowIID))
{
if (aNative)
mWindow->Create(aNative, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
else
PRBool usewidgets;
dx->SupportsNativeWidgets(usewidgets);
if (PR_TRUE == usewidgets)
{
nsIWidget *parent;
GetOffsetFromWidget(nsnull, nsnull, parent);
mWindow->Create(parent, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
NS_IF_RELEASE(parent);
if (aNative)
mWindow->Create(aNative, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
else
{
nsIWidget *parent;
GetOffsetFromWidget(nsnull, nsnull, parent);
mWindow->Create(parent, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
NS_IF_RELEASE(parent);
}
}
}

Просмотреть файл

@ -517,42 +517,45 @@ NS_IMETHODIMP nsViewManager :: UpdateView(nsIView *aView, const nsRect &aRect, P
// Get the parent view
widgetView->GetParent(widgetView);
} while (nsnull != widgetView);
NS_ASSERTION(nsnull != widgetView, "no widget");
// NS_ASSERTION(nsnull != widgetView, "no widget"); this assertion not valid for printing...MMP
// Convert damage rect to coordinate space of containing view with
// a widget
// XXX Consolidate this code with the code above...
if (aView != widgetView)
if (nsnull != widgetView)
{
do
// Convert damage rect to coordinate space of containing view with
// a widget
// XXX Consolidate this code with the code above...
if (aView != widgetView)
{
par->GetPosition(&x, &y);
trect.x += x;
trect.y += y;
do
{
par->GetPosition(&x, &y);
trect.x += x;
trect.y += y;
par->GetParent(par);
par->GetParent(par);
}
while ((nsnull != par) && (par != widgetView));
}
while ((nsnull != par) && (par != widgetView));
}
// Add this rect to the widgetView's dirty region.
AddRectToDirtyRegion(widgetView, trect);
// Add this rect to the widgetView's dirty region.
AddRectToDirtyRegion(widgetView, trect);
// See if we should do an immediate refresh or wait
if (aUpdateFlags & NS_VMREFRESH_IMMEDIATE)
{
Composite();
// XXX Composite() should return the top-most view that's dirty so
// we don't have to always use the root window...
mRootWindow->Update();
}
// or if a sync paint is allowed and it's time for the compositor to
// do a refresh
else if ((mFrameRate > 0) && !(aUpdateFlags & NS_VMREFRESH_NO_SYNC))
{
PRInt32 deltams = PR_IntervalToMilliseconds(PR_IntervalNow() - mLastRefresh);
if (deltams > (1000 / (PRInt32)mFrameRate))
// See if we should do an immediate refresh or wait
if (aUpdateFlags & NS_VMREFRESH_IMMEDIATE)
{
Composite();
// XXX Composite() should return the top-most view that's dirty so
// we don't have to always use the root window...
mRootWindow->Update();
}
// or if a sync paint is allowed and it's time for the compositor to
// do a refresh
else if ((mFrameRate > 0) && !(aUpdateFlags & NS_VMREFRESH_NO_SYNC))
{
PRInt32 deltams = PR_IntervalToMilliseconds(PR_IntervalNow() - mLastRefresh);
if (deltams > (1000 / (PRInt32)mFrameRate))
Composite();
}
}
return NS_OK;
@ -1311,3 +1314,40 @@ NS_IMETHODIMP nsViewManager :: EnableRefresh(void)
return NS_OK;
}
NS_IMETHODIMP nsViewManager :: Display(void)
{
nsRect wrect;
nsIRenderingContext *localcx = nsnull;
nsDrawingSurface ds = nsnull;
nsRect trect;
if (PR_FALSE == mRefreshEnabled)
return NS_OK;
NS_ASSERTION(!(PR_TRUE == mPainting), "recursive painting not permitted");
mPainting = PR_TRUE;
mContext->CreateRenderingContext(localcx);
//couldn't get rendering context. this is ok if at startup
if (nsnull == localcx)
{
return NS_ERROR_FAILURE;
}
mRootView->GetBounds(trect);
PRBool result;
localcx->SetClipRect(trect, nsClipCombine_kReplace, result);
// Paint the view. The clipping rect was set above set don't clip again.
mRootView->Paint(*localcx, trect, NS_VIEW_FLAG_CLIP_SET, result);
NS_RELEASE(localcx);
mPainting = PR_FALSE;
return NS_OK;
}

Просмотреть файл

@ -110,6 +110,8 @@ public:
nsDrawingSurface GetDrawingSurface(nsIRenderingContext &aContext, nsRect& aBounds);
NS_IMETHOD Display(void);
private:
virtual ~nsViewManager();
nsIRenderingContext *CreateRenderingContext(nsIView &aView);

Просмотреть файл

@ -68,6 +68,8 @@ public:
virtual void Show() = 0;
virtual void Hide() = 0;
NS_IMETHOD Print(void) = 0;
};
#endif /* nsIContentViewer_h___ */

Просмотреть файл

@ -29,6 +29,7 @@
#include "nsIPresShell.h"
#include "nsIStyleSet.h"
#include "nsIStyleSheet.h"
#include "nsIFrame.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
@ -37,78 +38,83 @@
#include "nsViewsCID.h"
#include "nsWidgetsCID.h"
#include "nsGfxCIID.h"
#include "nsIDeviceContext.h"
#include "nsIDeviceContextSpec.h"
#include "nsIDeviceContextSpecFactory.h"
#include "nsIViewManager.h"
#include "nsIView.h"
#include "nsIPref.h"
#include "nsIURL.h"
class DocumentViewerImpl : public nsIDocumentViewer
{
public:
DocumentViewerImpl();
DocumentViewerImpl(nsIPresContext* aPresContext);
void* operator new(size_t sz) {
void* rv = new char[sz];
nsCRT::zero(rv, sz);
return rv;
}
// nsISupports interface...
NS_DECL_ISUPPORTS
// nsIContentViewer interface...
NS_IMETHOD Init(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext,
nsIPref* aPrefs,
const nsRect& aBounds,
nsScrollPreference aScrolling = nsScrollPreference_kAuto);
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsIContentViewerContainer* aContainer);
NS_IMETHOD GetContainer(nsIContentViewerContainer*& aContainerResult);
virtual nsRect GetBounds();
virtual void SetBounds(const nsRect& aBounds);
virtual void Move(PRInt32 aX, PRInt32 aY);
virtual void Show();
virtual void Hide();
// nsIDocumentViewer interface...
NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet);
DocumentViewerImpl();
DocumentViewerImpl(nsIPresContext* aPresContext);
NS_IMETHOD GetDocument(nsIDocument*& aResult);
NS_IMETHOD GetPresShell(nsIPresShell*& aResult);
NS_IMETHOD GetPresContext(nsIPresContext*& aResult);
void* operator new(size_t sz) {
void* rv = new char[sz];
nsCRT::zero(rv, sz);
return rv;
}
NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext,
nsIDocumentViewer*& aResult);
// nsISupports interface...
NS_DECL_ISUPPORTS
// nsIContentViewer interface...
NS_IMETHOD Init(nsNativeWidget aParent,
nsIDeviceContext* aDeviceContext,
nsIPref* aPrefs,
const nsRect& aBounds,
nsScrollPreference aScrolling = nsScrollPreference_kAuto);
NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand);
NS_IMETHOD SetContainer(nsIContentViewerContainer* aContainer);
NS_IMETHOD GetContainer(nsIContentViewerContainer*& aContainerResult);
virtual nsRect GetBounds();
virtual void SetBounds(const nsRect& aBounds);
virtual void Move(PRInt32 aX, PRInt32 aY);
virtual void Show();
virtual void Hide();
NS_IMETHOD Print(void);
// nsIDocumentViewer interface...
NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet);
NS_IMETHOD GetDocument(nsIDocument*& aResult);
NS_IMETHOD GetPresShell(nsIPresShell*& aResult);
NS_IMETHOD GetPresContext(nsIPresContext*& aResult);
NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext,
nsIDocumentViewer*& aResult);
protected:
virtual ~DocumentViewerImpl();
virtual ~DocumentViewerImpl();
private:
void ForceRefresh(void);
nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet);
nsresult MakeWindow(nsNativeWidget aNativeParent,
const nsRect& aBounds,
nsScrollPreference aScrolling);
void ForceRefresh(void);
nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet);
nsresult MakeWindow(nsNativeWidget aNativeParent,
const nsRect& aBounds,
nsScrollPreference aScrolling);
protected:
nsIViewManager* mViewManager;
nsIView* mView;
nsIWidget* mWindow;
nsIContentViewerContainer* mContainer;
nsIDocument* mDocument;
nsIPresContext* mPresContext;
nsIPresShell* mPresShell;
nsIStyleSheet* mUAStyleSheet;
nsIViewManager* mViewManager;
nsIView* mView;
nsIWidget* mWindow;
nsIContentViewerContainer* mContainer;
nsIDocument* mDocument;
nsIPresContext* mPresContext;
nsIPresShell* mPresShell;
nsIStyleSheet* mUAStyleSheet;
};
//Class IDs
@ -434,6 +440,102 @@ void DocumentViewerImpl::Hide()
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
NS_IMETHODIMP DocumentViewerImpl :: Print(void)
{
nsIDeviceContextSpecFactory *factory = nsnull;
nsRepository::CreateInstance(kDeviceContextSpecFactoryCID, nsnull,
kIDeviceContextSpecFactoryIID, (void **)&factory);
if (nsnull != factory)
{
nsIDeviceContextSpec *devspec = nsnull;
nsIDeviceContext *dx = nsnull;
nsIDeviceContext *newdx = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
dx = mPresContext->GetDeviceContext();
if (NS_OK == dx->GetDeviceContextFor(devspec, newdx))
{
nsIPresShell *ps;
nsIPresContext *cx;
nsIStyleSet *ss;
nsIPref *prefs;
nsIViewManager *vm;
PRInt32 width, height;
nsIView *view;
NS_RELEASE(devspec);
newdx->GetDeviceSurfaceDimensions(width, height);
NS_NewGalleyContext(&cx);
mPresContext->GetPrefs(prefs);
cx->Init(newdx, prefs);
CreateStyleSet(mDocument, &ss);
NS_NewPresShell(&ps);
{
nsresult rv;
rv = nsRepository::CreateInstance(kViewManagerCID,
nsnull,
kIViewManagerIID,
(void **)&vm);
if ((NS_OK != rv) || (NS_OK != vm->Init(newdx))) {
NS_ASSERTION(PR_FALSE, "can't get good VM");
}
nsRect tbounds = nsRect(0, 0, width, height);
// Create a child window of the parent that is our "root view/window"
// Create a view
rv = nsRepository::CreateInstance(kViewCID,
nsnull,
kIViewIID,
(void **)&view);
if ((NS_OK != rv) || (NS_OK != view->Init(vm,
tbounds,
nsnull))) {
NS_ASSERTION(PR_FALSE, "can't get good view");
}
// Setup hierarchical relationship in view manager
vm->SetRootView(view);
}
ps->Init(mDocument, cx, vm, ss);
//lay it out...
ps->InitialReflow(width, height);
newdx->BeginDocument();
newdx->BeginPage();
vm->Display();
newdx->EndPage();
newdx->EndDocument();
NS_RELEASE(ps);
NS_RELEASE(vm);
NS_RELEASE(ss);
NS_RELEASE(newdx);
NS_RELEASE(prefs);
}
NS_RELEASE(dx);
NS_RELEASE(factory);
}
return NS_OK;
}
void DocumentViewerImpl::ForceRefresh()
{

Просмотреть файл

@ -134,6 +134,7 @@ public:
virtual void Move(PRInt32 aX, PRInt32 aY);
virtual void Show();
virtual void Hide();
NS_IMETHOD Print(void);
~PluginViewerImpl();
@ -430,6 +431,11 @@ PluginViewerImpl::Hide()
}
}
NS_IMETHODIMP PluginViewerImpl :: Print(void)
{
return NS_OK;
}
void
PluginViewerImpl::ForceRefresh()
{

Просмотреть файл

@ -444,6 +444,10 @@ nsBrowserWindow::DispatchMenuItem(PRInt32 aID)
case VIEWER_THREE_COLUMN:
ShowPrintPreview(aID);
break;
case VIEWER_PRINT:
DoPrint();
break;
}
return nsEventStatus_eIgnore;
@ -1908,6 +1912,19 @@ nsBrowserWindow::ShowPrintPreview(PRInt32 aID)
}
}
void nsBrowserWindow::DoPrint(void)
{
nsIContentViewer *viewer = nsnull;
mWebShell->GetContentViewer(viewer);
if (nsnull != viewer)
{
viewer->Print();
NS_RELEASE(viewer);
}
}
//----------------------------------------------------------------------
void

Просмотреть файл

@ -138,6 +138,7 @@ public:
NS_IMETHOD ForceRefresh();
void ShowPrintPreview(PRInt32 aID);
void DoPrint(void);
#ifdef NS_DEBUG
void DumpContent(FILE *out = stdout);

Просмотреть файл

@ -97,6 +97,8 @@ static NS_DEFINE_IID(kCFontMetricsIID, NS_FONT_METRICS_CID);
static NS_DEFINE_IID(kCImageIID, NS_IMAGE_CID);
static NS_DEFINE_IID(kCRegionIID, NS_REGION_CID);
static NS_DEFINE_IID(kCBlenderIID, NS_BLENDER_CID);
static NS_DEFINE_IID(kCDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
static NS_DEFINE_IID(kCDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
static NS_DEFINE_IID(kCViewManagerCID, NS_VIEW_MANAGER_CID);
static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID);
static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID);
@ -140,6 +142,8 @@ NS_SetupRegistry()
nsRepository::RegisterFactory(kCImageIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCRegionIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCBlenderIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCDeviceContextSpecCID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCDeviceContextSpecFactoryCID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCViewManagerCID, VIEW_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCViewCID, VIEW_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCScrollingViewCID, VIEW_DLL, PR_FALSE, PR_FALSE);

Просмотреть файл

@ -63,6 +63,8 @@
#define VIEWER_TWO_COLUMN 40041
#define VIEWER_THREE_COLUMN 40042
#define VIEWER_PRINT 40050
#define JS_CONSOLE 40100
#define EDITOR_MODE 40120
#define VIEWER_PREFS 40130

Просмотреть файл

@ -48,6 +48,7 @@ VIEWER MENU DISCARDABLE
MENUITEM "Two Column", VIEWER_TWO_COLUMN
MENUITEM "Three Column", VIEWER_THREE_COLUMN
}
MENUITEM "Print", VIEWER_PRINT
MENUITEM "&Exit", VIEWER_EXIT
}
POPUP "&Edit"