Reorganized the viewer app to separate the platform specific code from the
cross-platform code. Converted as much of the WIN32 specific code to cross-platform code as possible. git-svn-id: svn://10.0.0.236/trunk@2813 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
76c18f5955
commit
f0ed4e7b76
38
mozilla/webshell/tests/viewer/main.cpp
Normal file
38
mozilla/webshell/tests/viewer/main.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsViewer.h"
|
||||
|
||||
nsresult ExecuteViewer(nsViewer* aViewer)
|
||||
{
|
||||
nsIWidget *mainWindow = nsnull;
|
||||
nsDocLoader* dl = aViewer->SetupViewer(&mainWindow);
|
||||
nsresult result = aViewer->Run();
|
||||
aViewer->CleanupViewer(dl);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void main(int argc, char **argv)
|
||||
{
|
||||
nsViewer* viewer = new nsViewer();
|
||||
SetViewer(viewer);
|
||||
viewer->ProcessArguments(argc, argv);
|
||||
ExecuteViewer(viewer);
|
||||
}
|
||||
|
||||
@ -22,33 +22,34 @@ MAKE_OBJ_TYPE = EXE
|
||||
PROGRAM = .\$(OBJDIR)\viewer.exe
|
||||
RESFILE = viewer.res
|
||||
|
||||
MISCDEP= \
|
||||
$(DIST)\lib\DebugRobot.lib \
|
||||
$(DIST)\lib\raptorweb.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(LIBNSPR) \
|
||||
MISCDEP= \
|
||||
$(DIST)\lib\DebugRobot.lib \
|
||||
$(DIST)\lib\raptorweb.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\libplc21.lib
|
||||
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\winmain.obj \
|
||||
.\$(OBJDIR)\nsViewer.obj \
|
||||
.\$(OBJDIR)\JSConsole.obj \
|
||||
.\$(OBJDIR)\nsDocLoader.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\raptor -I$(PUBLIC)\xpcom -I$(PUBLIC)\dom -I$(PUBLIC)\js -I$(PUBLIC)\netlib
|
||||
MYLIBS= \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\raptorgfx.lib \
|
||||
$(DIST)\lib\raptorhtml.lib \
|
||||
$(DIST)\lib\raptorweb.lib \
|
||||
$(DIST)\lib\DebugRobot.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\js3240.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
comdlg32.lib \
|
||||
MYLIBS= \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\raptorgfx.lib \
|
||||
$(DIST)\lib\raptorhtml.lib \
|
||||
$(DIST)\lib\raptorweb.lib \
|
||||
$(DIST)\lib\DebugRobot.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\js3240.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
comdlg32.lib \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= $(MYLIBS) \
|
||||
|
||||
778
mozilla/webshell/tests/viewer/nsViewer.cpp
Normal file
778
mozilla/webshell/tests/viewer/nsViewer.cpp
Normal file
@ -0,0 +1,778 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Only cross-platform code should reside in this file.
|
||||
* winmain.cpp (Win32) and main.cpp (Unix) contain the platform specific code.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "nsViewer.h"
|
||||
#include "resources.h" // #defines ID's for menu items
|
||||
#include "nsIWidget.h"
|
||||
#include "nsGlobalVariables.h"
|
||||
#include "nsIWebWidget.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prthread.h"
|
||||
#include "prprf.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "nsViewsCID.h"
|
||||
#include "nsString.h"
|
||||
#include "plevent.h"
|
||||
#include "prenv.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsDocLoader.h"
|
||||
#include "nsIFileWidget.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
|
||||
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
|
||||
static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID);
|
||||
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
||||
static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID);
|
||||
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
||||
static NS_DEFINE_IID(kCWindowIID, NS_WINDOW_CID);
|
||||
static NS_DEFINE_IID(kCScrollbarIID, NS_VERTSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCHScrollbarIID, NS_HORZSCROLLBAR_CID);
|
||||
static NS_DEFINE_IID(kCButtonIID, NS_BUTTON_CID);
|
||||
static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID);
|
||||
static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID);
|
||||
static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID);
|
||||
static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID);
|
||||
static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID);
|
||||
static NS_DEFINE_IID(kCCheckButtonIID, NS_CHECKBUTTON_CID);
|
||||
static NS_DEFINE_IID(kCChildIID, NS_CHILD_CID);
|
||||
static NS_DEFINE_IID(kCRenderingContextIID, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCDeviceContextIID, NS_DEVICE_CONTEXT_CID);
|
||||
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(kCViewManagerCID, NS_VIEW_MANAGER_CID);
|
||||
static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID);
|
||||
static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID);
|
||||
|
||||
|
||||
#define SAMPLES_BASE_URL "resource:/res/samples"
|
||||
#define START_URL SAMPLES_BASE_URL "/test0.html"
|
||||
|
||||
nsViewer* gTheViewer = nsnull;
|
||||
nsIAppShell *gAppShell= nsnull;
|
||||
static char* startURL;
|
||||
static nsVoidArray* gWindows;
|
||||
static PRBool gDoPurify; // run in Purify auto mode
|
||||
static PRBool gDoQuantify; // run in Quantify auto mode
|
||||
static PRBool gLoadTestFromFile; // run in auto mode by pulling URLs from a file (gInputFileName)
|
||||
static PRInt32 gDelay=1; // if running in an auto mode, this is the delay between URL loads
|
||||
static PRInt32 gRepeatCount=1; // if running in an auto mode, this is the number of times to cycle through the input
|
||||
static PRInt32 gNumSamples=9; // if running in an auto mode that uses the samples, this is the last sample to load
|
||||
static char gInputFileName[_MAX_PATH+1];
|
||||
|
||||
|
||||
// Temporary Netlib stuff...
|
||||
/* XXX: Don't include net.h... */
|
||||
extern "C" {
|
||||
extern int NET_PollSockets();
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENTOBSERVER_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(DocObserver, kIDocumentObserverIID);
|
||||
|
||||
// Pass title information through to all of the web widgets that
|
||||
// belong to this document.
|
||||
NS_IMETHODIMP DocObserver::SetTitle(const nsString& aTitle)
|
||||
{
|
||||
PRInt32 i, n = gWindows->Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
WindowData* wd = (WindowData*) gWindows->ElementAt(i);
|
||||
if (wd->ww == mWebWidget) {
|
||||
wd->windowWidget->SetTitle(aTitle);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static DocObserver* NewObserver(nsIWebWidget* ww)
|
||||
{
|
||||
nsISupports* oldContainer;
|
||||
nsresult rv = ww->GetContainer(&oldContainer);
|
||||
if (NS_OK == rv) {
|
||||
if (nsnull == oldContainer) {
|
||||
DocObserver* it = new DocObserver(ww);
|
||||
NS_ADDREF(it);
|
||||
ww->SetContainer(it);
|
||||
return it;
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(oldContainer);
|
||||
}
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
|
||||
{
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
switch(aEvent->message) {
|
||||
case NS_SIZE:
|
||||
{
|
||||
struct WindowData *wd = gTheViewer->FindWindowData(aEvent->widget);
|
||||
nsSizeEvent* sizeEvent = (nsSizeEvent*)aEvent;
|
||||
if (wd->ww) {
|
||||
nsRect rr(0, 0, sizeEvent->windowSize->width, sizeEvent->windowSize->height);
|
||||
wd->ww->SetBounds(rr);
|
||||
}
|
||||
}
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
|
||||
case NS_DESTROY:
|
||||
{
|
||||
struct WindowData *wd = gTheViewer->FindWindowData(aEvent->widget);
|
||||
gTheViewer->Destroy(wd);
|
||||
|
||||
if (gWindows->Count() == 0) {
|
||||
gTheViewer->Stop();
|
||||
|
||||
}
|
||||
return nsEventStatus_eConsumeDoDefault;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
return(gTheViewer->DispatchMenuItem(aEvent));
|
||||
break;
|
||||
}
|
||||
|
||||
return(nsEventStatus_eIgnore);
|
||||
}
|
||||
|
||||
void ReleaseMemory()
|
||||
{
|
||||
nsGlobalVariables::Release();
|
||||
delete gWindows;
|
||||
}
|
||||
|
||||
void PrintHelpInfo(char **argv)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-p][-q][-md #][-f filename][-d #] [starting url]\n", argv[0]);
|
||||
fprintf(stderr, "\t-p[#] -- run purify, optionally with a # that says which sample to stop at. For example, -p2 says to run samples 0, 1, and 2.\n");
|
||||
fprintf(stderr, "\t-q -- run quantify\n");
|
||||
fprintf(stderr, "\t-md # -- set the crt debug flags to #\n");
|
||||
fprintf(stderr, "\t-d # -- set the delay between URL loads to # (in milliseconds)\n");
|
||||
fprintf(stderr, "\t-r # -- set the repeat count, which is the number of times the URLs will be loaded in batch mode.\n");
|
||||
fprintf(stderr, "\t-f filename -- read a list of URLs from <filename>\n");
|
||||
}
|
||||
|
||||
void nsViewer::ProcessArguments(int argc, char **argv)
|
||||
{
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
if (strncmp(argv[i], "-p", 2) == 0) {
|
||||
gDoPurify = PR_TRUE;
|
||||
char *optionalSampleStopIndex = &(argv[i][2]);
|
||||
if (nsnull!=*optionalSampleStopIndex)
|
||||
{
|
||||
if (1!=sscanf(optionalSampleStopIndex, "%d", &gNumSamples))
|
||||
{
|
||||
PrintHelpInfo(argv);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], "-q") == 0) {
|
||||
gDoQuantify = PR_TRUE;
|
||||
}
|
||||
else if (strcmp(argv[i], "-f") == 0) {
|
||||
gLoadTestFromFile = PR_TRUE;
|
||||
i++;
|
||||
if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i]))
|
||||
{
|
||||
PrintHelpInfo(argv);
|
||||
exit(-1);
|
||||
}
|
||||
strcpy(gInputFileName, argv[i]);
|
||||
}
|
||||
else if (strcmp(argv[i], "-d") == 0) {
|
||||
i++;
|
||||
if (i>=argc || 1!=sscanf(argv[i], "%d", &gDelay))
|
||||
{
|
||||
PrintHelpInfo(argv);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
else if (strcmp(argv[i], "-md") == 0) {
|
||||
if (i == argc - 1) {
|
||||
PrintHelpInfo(argv);
|
||||
exit(-1);
|
||||
}
|
||||
PRUint32 newFlags = atoi(argv[++i]);
|
||||
CrtSetDebug(newFlags);
|
||||
}
|
||||
else if (strcmp(argv[i], "-r") == 0) {
|
||||
i++;
|
||||
if (i>=argc || 1!=sscanf(argv[i], "%d", &gRepeatCount))
|
||||
{
|
||||
PrintHelpInfo(argv);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PrintHelpInfo(argv);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (i < argc) {
|
||||
startURL = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsViewer Implementation
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Purify methods
|
||||
*/
|
||||
|
||||
void nsViewer::AddTestDocs(nsDocLoader* aDocLoader)
|
||||
{
|
||||
char url[500];
|
||||
for (int docnum = 0; docnum < gNumSamples; docnum++)
|
||||
{
|
||||
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, docnum);
|
||||
aDocLoader->AddURL(url);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SelfTest methods
|
||||
*/
|
||||
void nsViewer::AddTestDocsFromFile(nsDocLoader* aDocLoader, char *aFileName)
|
||||
{
|
||||
/* Steve's table test code.
|
||||
Assumes you have a file in the current working directory called aFileName
|
||||
that contains a list of URLs, one per line, of files to load.
|
||||
*/
|
||||
|
||||
PRFileDesc* input = PR_Open(aFileName, PR_RDONLY, 0);
|
||||
if (nsnull==input)
|
||||
{
|
||||
printf("FAILED TO OPEN %s!", aFileName);
|
||||
return;
|
||||
}
|
||||
// read one line of input and pass it in as a URL
|
||||
char *inputString = new char[10000];
|
||||
if (nsnull==inputString)
|
||||
{
|
||||
printf("couldn't allocate buffer, insufficient memory\n");
|
||||
exit (-1);
|
||||
}
|
||||
nsCRT::memset(inputString, 0, 10000);
|
||||
PR_Read(input, inputString, 10000);
|
||||
PR_Close(input);
|
||||
|
||||
char *nextInput = inputString;
|
||||
while (nsnull!=nextInput && nsnull!=*nextInput)
|
||||
{
|
||||
char * endOfLine = PL_strchr(nextInput, '\n');
|
||||
if (nsnull!=nextInput)
|
||||
{
|
||||
if (nsnull!=endOfLine)
|
||||
{
|
||||
char save = *endOfLine;
|
||||
*endOfLine = nsnull;
|
||||
}
|
||||
if ('#' != *nextInput) // use '#' as a comment character
|
||||
{
|
||||
aDocLoader->AddURL(nextInput);
|
||||
}
|
||||
if (nsnull!=endOfLine)
|
||||
{
|
||||
nextInput = endOfLine+1;
|
||||
}
|
||||
else
|
||||
nextInput = nsnull;
|
||||
}
|
||||
}
|
||||
if (nsnull!=inputString)
|
||||
delete [] inputString;
|
||||
}
|
||||
|
||||
void nsViewer::DestroyAllWindows()
|
||||
{
|
||||
if (nsnull != gWindows) {
|
||||
PRInt32 n = gWindows->Count();
|
||||
for (PRInt32 i = 0; i < n; i++) {
|
||||
WindowData* wd = (WindowData*) gWindows->ElementAt(i);
|
||||
wd->windowWidget->Destroy();
|
||||
}
|
||||
gWindows->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
struct WindowData* nsViewer::FindWindowData(nsIWidget* aWidget)
|
||||
{
|
||||
PRInt32 i, n = gWindows->Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
WindowData* wd = (WindowData*) gWindows->ElementAt(i);
|
||||
if (wd->windowWidget == aWidget) {
|
||||
return(wd);
|
||||
}
|
||||
}
|
||||
return(nsnull);
|
||||
}
|
||||
|
||||
#define FILE_PROTOCOL "file://"
|
||||
|
||||
// Displays the Open common dialog box and lets the user specify an HTML file
|
||||
// to open.
|
||||
PRBool nsViewer::GetFileNameFromFileSelector(nsIWidget* aParentWindow, nsString* aFileName)
|
||||
{
|
||||
PRBool selectedFileName = PR_FALSE;
|
||||
nsIFileWidget *fileWidget;
|
||||
nsString title("Open HTML");
|
||||
|
||||
NSRepository::CreateInstance(kCFileWidgetCID, nsnull, kIFileWidgetIID, (void**)&fileWidget);
|
||||
nsString titles[] = {"all files","html" };
|
||||
nsString filters[] = {"*.*", "*.html"};
|
||||
fileWidget->SetFilterList(2, titles, filters);
|
||||
fileWidget->Create(aParentWindow,
|
||||
title,
|
||||
eMode_load,
|
||||
nsnull,
|
||||
nsnull);
|
||||
|
||||
PRUint32 result = fileWidget->Show();
|
||||
if (result) {
|
||||
fileWidget->GetFile(*aFileName);
|
||||
selectedFileName = PR_TRUE;
|
||||
}
|
||||
|
||||
NS_RELEASE(fileWidget);
|
||||
return(selectedFileName);
|
||||
}
|
||||
|
||||
// Displays the Open common dialog box and lets the user specify an HTML file
|
||||
// to open. Then passes the filename along to the Web widget.
|
||||
void nsViewer::OpenHTMLFile(WindowData* wd)
|
||||
{
|
||||
nsString fileName;
|
||||
char szFile[_MAX_PATH];
|
||||
|
||||
if (GetFileNameFromFileSelector(wd->windowWidget, &fileName)) {
|
||||
|
||||
|
||||
fileName.ToCString(szFile, _MAX_PATH);
|
||||
PRInt32 len = strlen(szFile);
|
||||
char* lpszFileURL = (char*)malloc(len + sizeof(FILE_PROTOCOL));
|
||||
|
||||
// Translate '\' to '/'
|
||||
for (PRInt32 i = 0; i < len; i++) {
|
||||
if (szFile[i] == '\\') {
|
||||
szFile[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Build the file URL
|
||||
PR_snprintf(lpszFileURL, _MAX_PATH, "%s%s", FILE_PROTOCOL, szFile);
|
||||
|
||||
// Ask the Web widget to load the file URL
|
||||
wd->ww->LoadURL(lpszFileURL);
|
||||
free(lpszFileURL);
|
||||
}
|
||||
}
|
||||
|
||||
// Selects all the Content
|
||||
void nsViewer::SelectAll(WindowData* wd)
|
||||
{
|
||||
if (wd->ww != nsnull) {
|
||||
nsIDocument* doc = wd->ww->GetDocument();
|
||||
if (doc != nsnull) {
|
||||
doc->SelectAll();
|
||||
wd->ww->ShowFrameBorders(PR_FALSE);
|
||||
/*PRInt32 numShells = doc->GetNumberOfShells();
|
||||
for (PRInt32 i=0;i<numShells;i++) {
|
||||
nsIPresShell * shell = doc->GetShellAt(i);
|
||||
//nsIViewManager * viewMgr = shell->GetViewManager();
|
||||
nsIFrame * frame = shell->GetRootFrame();
|
||||
nsRect rect;
|
||||
nsIView * view;
|
||||
nsPoint pnt;
|
||||
frame->GetOffsetFromView(pnt, view);
|
||||
frame->GetRect(rect);
|
||||
rect.x = pnt.x;
|
||||
rect.y = pnt.y;
|
||||
if (view != nsnull) {
|
||||
nsIViewManager * viewMgr = view->GetViewManager();
|
||||
if (viewMgr != nsnull) {
|
||||
viewMgr->UpdateView(view, rect, 0);
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(shell);
|
||||
//NS_IF_RELEASE(frame);
|
||||
}*/
|
||||
|
||||
NS_IF_RELEASE(doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a top level window
|
||||
*/
|
||||
|
||||
WindowData* nsViewer::CreateTopLevel(const char* title,
|
||||
int aWidth, int aHeight)
|
||||
{
|
||||
WindowData* wd = new WindowData();
|
||||
nsIWidget* window = nsnull;
|
||||
NSRepository::CreateInstance(kCWindowCID, nsnull, kIWidgetIID, (void**)&window);
|
||||
nsRect rect(100, 100, aWidth, aHeight);
|
||||
|
||||
window->Create((nsIWidget*)NULL, rect, HandleEvent, nsnull);
|
||||
window->SetTitle(title);
|
||||
wd->windowWidget = window;
|
||||
gWindows->AppendElement(wd);
|
||||
window->Show(PR_TRUE);
|
||||
|
||||
return wd;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsViewer::ShowPrintPreview(nsIWebWidget* web, PRIntn aColumns)
|
||||
{
|
||||
if (nsnull != web) {
|
||||
nsIDocument* doc = web->GetDocument();
|
||||
if (nsnull != doc) {
|
||||
nsIPresContext* cx;
|
||||
nsresult rv = NS_NewPrintPreviewContext(&cx);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
WindowData* wd = CreateTopLevel("Print Preview", 500, 300);
|
||||
|
||||
nsRect bounds;
|
||||
wd->windowWidget->GetBounds(bounds);
|
||||
nsRect rr(0, 0, bounds.width, bounds.height);
|
||||
|
||||
rv = NS_NewWebWidget(&wd->ww);
|
||||
rv = wd->ww->Init(wd->windowWidget->GetNativeData(NS_NATIVE_WINDOW), rr, doc, cx);
|
||||
wd->ww->Show();
|
||||
wd->observer = NewObserver(wd->ww);
|
||||
|
||||
NS_RELEASE(cx);
|
||||
NS_RELEASE(doc);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsEventStatus nsViewer::DispatchMenuItem(nsGUIEvent *aEvent)
|
||||
{
|
||||
nsEventStatus result = nsEventStatus_eIgnore;
|
||||
|
||||
switch(aEvent->message) {
|
||||
|
||||
case NS_MENU_SELECTED:
|
||||
nsMenuEvent* menuEvent = (nsMenuEvent*)aEvent;
|
||||
WindowData* wd = FindWindowData(aEvent->widget);
|
||||
switch(menuEvent->menuItem) {
|
||||
|
||||
case VIEWER_EXIT:
|
||||
DestroyAllWindows();
|
||||
Stop();
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
|
||||
case PREVIEW_CLOSE:
|
||||
aEvent->widget->Destroy();
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
|
||||
case VIEWER_FILE_OPEN:
|
||||
OpenHTMLFile(wd);
|
||||
break;
|
||||
|
||||
case VIEWER_EDIT_CUT:
|
||||
break;
|
||||
|
||||
case VIEWER_EDIT_COPY:
|
||||
CopySelection(wd);
|
||||
break;
|
||||
|
||||
case VIEWER_EDIT_PASTE:
|
||||
break;
|
||||
|
||||
case VIEWER_EDIT_SELECTALL:
|
||||
SelectAll(wd);
|
||||
break;
|
||||
|
||||
case VIEWER_EDIT_FINDINPAGE:
|
||||
break;
|
||||
|
||||
case VIEWER_DEMO0:
|
||||
case VIEWER_DEMO1:
|
||||
case VIEWER_DEMO2:
|
||||
case VIEWER_DEMO3:
|
||||
case VIEWER_DEMO4:
|
||||
case VIEWER_DEMO5:
|
||||
case VIEWER_DEMO6:
|
||||
case VIEWER_DEMO7:
|
||||
case VIEWER_DEMO8:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
PRIntn ix = menuEvent->menuItem - VIEWER_DEMO0;
|
||||
char* url = new char[500];
|
||||
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, ix);
|
||||
wd->ww->LoadURL(url);
|
||||
delete url;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIEWER_VISUAL_DEBUGGING:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
wd->ww->ShowFrameBorders(PRBool(!wd->ww->GetShowFrameBorders()));
|
||||
}
|
||||
break;
|
||||
|
||||
case VIEWER_DUMP_CONTENT:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
wd->ww->DumpContent();
|
||||
}
|
||||
break;
|
||||
case VIEWER_DUMP_FRAMES:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
wd->ww->DumpFrames();
|
||||
}
|
||||
break;
|
||||
case VIEWER_DUMP_VIEWS:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
wd->ww->DumpViews();
|
||||
}
|
||||
break;
|
||||
case VIEWER_DUMP_STYLE_SHEETS:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
wd->ww->DumpStyleSheets();
|
||||
}
|
||||
break;
|
||||
case VIEWER_DUMP_STYLE_CONTEXTS:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
wd->ww->DumpStyleContexts();
|
||||
}
|
||||
break;
|
||||
|
||||
case VIEWER_DEBUGROBOT:
|
||||
DoDebugRobot(wd);
|
||||
break;
|
||||
|
||||
case VIEWER_ONE_COLUMN:
|
||||
case VIEWER_TWO_COLUMN:
|
||||
case VIEWER_THREE_COLUMN:
|
||||
if ((nsnull != wd) && (nsnull != wd->ww)) {
|
||||
ShowPrintPreview(wd->ww, menuEvent->menuItem - VIEWER_ONE_COLUMN + 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case JS_CONSOLE:
|
||||
ShowConsole(wd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
void nsViewer::CleanupViewer(nsDocLoader* aDl)
|
||||
{
|
||||
if (aDl != nsnull)
|
||||
delete aDl;
|
||||
ReleaseMemory();
|
||||
}
|
||||
|
||||
nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow)
|
||||
{
|
||||
PL_InitializeEventsLib("");
|
||||
|
||||
gWindows = new nsVoidArray();
|
||||
|
||||
NSRepository::RegisterFactory(kCWindowIID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCScrollbarIID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCHScrollbarIID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCButtonIID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCComboBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCFileWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCListBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCRadioButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCTextAreaCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCTextFieldCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCCheckButtonIID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCChildIID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCAppShellCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCRenderingContextIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCDeviceContextIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCFontMetricsIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCImageIID, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
||||
NSRepository::RegisterFactory(kCRegionIID, 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);
|
||||
|
||||
// Create an application shell
|
||||
NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID, (void**)&gAppShell);
|
||||
gAppShell->Create();
|
||||
gAppShell->SetDispatchListener(this);
|
||||
|
||||
// Create a top level window for the WebWidget
|
||||
WindowData* wd = CreateTopLevel("Raptor HTML Viewer", 620, 400);
|
||||
*aMainWindow = wd->windowWidget;
|
||||
|
||||
// Attach a menu to the top level window
|
||||
AddMenu(wd->windowWidget);
|
||||
|
||||
// Now embed the web widget in it
|
||||
nsresult rv = NS_NewWebWidget(&wd->ww);
|
||||
nsRect bounds;
|
||||
wd->windowWidget->GetBounds(bounds);
|
||||
nsRect rr(0, 0, bounds.width, bounds.height);
|
||||
rv = wd->ww->Init(wd->windowWidget->GetNativeData(NS_NATIVE_WINDOW), rr);
|
||||
wd->ww->Show();
|
||||
wd->observer = NewObserver(wd->ww);
|
||||
|
||||
|
||||
// Determine if we should run the purify test
|
||||
nsDocLoader* dl = nsnull;
|
||||
if (gDoPurify) {
|
||||
dl = new nsDocLoader(wd->ww, gDelay);
|
||||
|
||||
// Add the documents to the loader
|
||||
for (PRInt32 i=0; i<gRepeatCount; i++)
|
||||
AddTestDocs(dl);
|
||||
|
||||
// Start the timer
|
||||
dl->StartTimedLoading();
|
||||
}
|
||||
else if (gLoadTestFromFile) {
|
||||
dl = new nsDocLoader(wd->ww, gDelay);
|
||||
for (PRInt32 i=0; i<gRepeatCount; i++)
|
||||
AddTestDocsFromFile(dl, gInputFileName);
|
||||
dl->StartTimedLoading();
|
||||
}
|
||||
else {
|
||||
// Load the starting url if we have one
|
||||
wd->ww->LoadURL(startURL ? startURL : START_URL);
|
||||
if (gDoQuantify) {
|
||||
// Synthesize 20 ResizeReflow commands (+/- 10 pixels) and then
|
||||
// exit.
|
||||
#define kNumReflows 20
|
||||
for (PRIntn i = 0; i < kNumReflows; i++) {
|
||||
nsRect r = wd->ww->GetBounds();
|
||||
if (i & 1) {
|
||||
r.width -= 10;
|
||||
}
|
||||
else {
|
||||
r.width += 10;
|
||||
}
|
||||
wd->ww->SetBounds(r);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
return(dl);
|
||||
}
|
||||
|
||||
void nsViewer::AfterDispatch()
|
||||
{
|
||||
NET_PollSockets();
|
||||
}
|
||||
|
||||
void nsViewer::AddMenu(nsIWidget* aMainWindow)
|
||||
{
|
||||
printf("Menu not implemented\n");
|
||||
}
|
||||
|
||||
void nsViewer::ShowConsole(WindowData* aWindata)
|
||||
{
|
||||
printf("ShowConsole not implemented\n");
|
||||
}
|
||||
|
||||
void nsViewer::CloseConsole()
|
||||
{
|
||||
printf("CloseConsole not implemented\n");
|
||||
}
|
||||
|
||||
void nsViewer::DoDebugRobot(WindowData* aWinData)
|
||||
{
|
||||
printf("DebugRobot not implemented\n");
|
||||
}
|
||||
|
||||
void nsViewer::CopySelection(WindowData* aWindata)
|
||||
{
|
||||
printf("CopySelection not implemented\n");
|
||||
}
|
||||
|
||||
void nsViewer::CrtSetDebug(PRUint32 aNewFlags)
|
||||
{
|
||||
printf("CrtSetDebug not implemented\n");
|
||||
}
|
||||
|
||||
void nsViewer::Destroy(WindowData* aWinData)
|
||||
{
|
||||
if (nsnull != aWinData) {
|
||||
if (nsnull != aWinData->ww) {
|
||||
aWinData->ww->SetContainer(nsnull); // release the doc observer
|
||||
NS_RELEASE(aWinData->ww);
|
||||
}
|
||||
if (nsnull != aWinData->observer) {
|
||||
NS_RELEASE(aWinData->observer);
|
||||
}
|
||||
gWindows->RemoveElement(aWinData);
|
||||
delete aWinData;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsViewer::Run()
|
||||
{
|
||||
return(gAppShell->Run());
|
||||
}
|
||||
|
||||
void nsViewer::Stop()
|
||||
{
|
||||
gAppShell->Exit();
|
||||
}
|
||||
|
||||
void SetViewer(nsViewer* aViewer)
|
||||
{
|
||||
gTheViewer = aViewer;
|
||||
}
|
||||
|
||||
113
mozilla/webshell/tests/viewer/nsViewer.h
Normal file
113
mozilla/webshell/tests/viewer/nsViewer.h
Normal file
@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsViewer_h___
|
||||
#define nsViewer_h___
|
||||
|
||||
#include "nsIWebWidget.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsDocLoader.h"
|
||||
#include "nsIAppShell.h"
|
||||
|
||||
#define WIDGET_DLL "raptorwidget.dll"
|
||||
#define GFXWIN_DLL "raptorgfxwin.dll"
|
||||
#define VIEW_DLL "raptorview.dll"
|
||||
|
||||
class DocObserver : public nsIDocumentObserver {
|
||||
public:
|
||||
DocObserver(nsIWebWidget* aWebWidget) {
|
||||
NS_INIT_REFCNT();
|
||||
mWebWidget = aWebWidget;
|
||||
NS_ADDREF(aWebWidget);
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS;
|
||||
|
||||
NS_IMETHOD SetTitle(const nsString& aTitle);
|
||||
|
||||
virtual void BeginUpdate() { }
|
||||
virtual void EndUpdate() { }
|
||||
virtual void ContentChanged(nsIContent* aContent,
|
||||
nsISupports* aSubContent) {}
|
||||
virtual void ContentAppended(nsIContent* aContainer) { }
|
||||
virtual void ContentInserted(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { }
|
||||
virtual void ContentReplaced(nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer) { }
|
||||
virtual void ContentWillBeRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { }
|
||||
virtual void ContentHasBeenRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { }
|
||||
virtual void StyleSheetAdded(nsIStyleSheet* aStyleSheet) { }
|
||||
|
||||
|
||||
protected:
|
||||
~DocObserver() {
|
||||
NS_RELEASE(mWebWidget);
|
||||
}
|
||||
|
||||
nsIWebWidget* mWebWidget;
|
||||
};
|
||||
|
||||
struct WindowData {
|
||||
nsIWebWidget* ww;
|
||||
DocObserver* observer;
|
||||
nsIWidget *windowWidget;
|
||||
|
||||
WindowData() {
|
||||
ww = nsnull;
|
||||
}
|
||||
};
|
||||
|
||||
class nsViewer : public nsDispatchListener {
|
||||
public:
|
||||
virtual void AddMenu(nsIWidget* aMainWindow);
|
||||
virtual void ShowConsole(WindowData* aWindata);
|
||||
virtual void CloseConsole();
|
||||
virtual void DoDebugRobot(WindowData* aWindata);
|
||||
virtual void CopySelection(WindowData* aWindata);
|
||||
virtual nsresult Run();
|
||||
virtual void Destroy(WindowData* wd);
|
||||
virtual void Stop();
|
||||
virtual void AfterDispatch();
|
||||
virtual void CrtSetDebug(PRUint32 aNewFlags);
|
||||
|
||||
virtual nsDocLoader* SetupViewer(nsIWidget **aMainWindow);
|
||||
virtual void CleanupViewer(nsDocLoader* aDl);
|
||||
virtual nsEventStatus DispatchMenuItem(nsGUIEvent *aEvent);
|
||||
virtual nsresult ShowPrintPreview(nsIWebWidget* web, PRIntn aColumns);
|
||||
virtual WindowData* CreateTopLevel(const char* title, int aWidth, int aHeight);
|
||||
virtual void AddTestDocs(nsDocLoader* aDocLoader);
|
||||
virtual void AddTestDocsFromFile(nsDocLoader* aDocLoader, char *aFileName);
|
||||
virtual void DestroyAllWindows();
|
||||
virtual struct WindowData* FindWindowData(nsIWidget* aWidget);
|
||||
virtual PRBool GetFileNameFromFileSelector(nsIWidget* aParentWindow, nsString* aFileName);
|
||||
virtual void OpenHTMLFile(WindowData* wd);
|
||||
virtual void SelectAll(WindowData* wd);
|
||||
virtual void ProcessArguments(int argc, char **argv);
|
||||
};
|
||||
|
||||
// Set the single viewer.
|
||||
extern void SetViewer(nsViewer* aViewer);
|
||||
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user