moved content-specific data and methods from nsIWebShell to appropriate content viewer interface

no bug number, this is for webshell redesign work
r=rickg, travis
This commit is contained in:
buster%netscape.com 1999-11-19 07:35:27 +00:00
Родитель 38d2b703cc
Коммит 93551f1751
34 изменённых файлов: 4996 добавлений и 1493 удалений

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

@ -24,6 +24,8 @@
#include "nsCRT.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsIContentViewerContainer.h"
#include "nsIDocumentViewer.h"
#include "nsIImageGroup.h"
@ -54,6 +56,9 @@
#include "nsIPageSequenceFrame.h"
#include "nsIURL.h"
#include "nsIWebShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestor.h"
@ -71,6 +76,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
#endif
class DocumentViewerImpl : public nsIDocumentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile,
public nsIMarkupDocumentViewer,
public nsIImageGroupObserver
{
public:
@ -97,8 +105,6 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD Print(void);
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext);
NS_IMETHOD SetEnableRendering(PRBool aOn);
NS_IMETHOD GetEnableRendering(PRBool* aResult);
@ -110,6 +116,15 @@ public:
NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext,
nsIDocumentViewer*& aResult);
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
// nsIContentViewerFile
NS_DECL_NSICONTENTVIEWERFILE
// nsIMarkupDocumentViewer
NS_DECL_NSIMARKUPDOCUMENTVIEWER
// nsIImageGroupObserver interface...
virtual void Notify(nsIImageGroup *aImageGroup,
nsImageGroupNotification aNotificationType);
@ -166,6 +181,17 @@ protected:
nsIViewManager *mPrintVM;
nsIView *mPrintView;
// document management data
// these items are specific to markup documents (html and xml)
// may consider splitting these out into a subclass
PRBool mAllowPlugins;
PRPackedBool mIsFrame;
/* character set member data */
nsString mDefaultCharacterSet;
nsString mHintCharset;
nsCharsetSource mHintCharsetSource;
nsString mForceCharacterSet;
};
// Class IDs
@ -213,6 +239,11 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
: mPresContext(dont_QueryInterface(aPresContext))
{
NS_INIT_REFCNT();
mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized;
mForceCharacterSet = "";
mAllowPlugins = PR_TRUE;
mIsFrame = PR_FALSE;
}
// ISupports implementation...
@ -238,6 +269,12 @@ DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMarkupDocumentViewer::GetIID())) {
nsIMarkupDocumentViewer* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsIContentViewer* tmp1 = this;
nsISupports* tmp2 = tmp1;
@ -509,194 +546,31 @@ DocumentViewerImpl::Hide(void)
return NS_OK;
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::Print(void)
{
nsCOMPtr<nsIWebShell> webContainer;
nsCOMPtr<nsIDeviceContextSpecFactory> factory;
PRInt32 width,height;
nsCOMPtr<nsIPref> prefs;
nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,
nsnull,
kIDeviceContextSpecFactoryIID,
(void **)getter_AddRefs(factory));
if (factory) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
#endif
nsIDeviceContextSpec *devspec = nsnull;
nsCOMPtr<nsIDeviceContext> dx;
mPrintDC = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
if (nsnull != devspec) {
mPresContext->GetDeviceContext(getter_AddRefs(dx));
nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(devspec);
// Get the webshell for this documentviewer
webContainer = do_QueryInterface(mContainer);
if(webContainer) {
// load the document and do the initial reflow on the entire document
rv = NS_NewPrintContext(&mPrintPC);
if(NS_FAILED(rv)){
return rv;
}
mPrintDC->GetDeviceSurfaceDimensions(width,height);
mPresContext->GetPrefs(getter_AddRefs(prefs));
mPrintPC->Init(mPrintDC,prefs);
CreateStyleSet(mDocument,&mPrintSS);
rv = NS_NewPresShell(&mPrintPS);
if(NS_FAILED(rv)){
return rv;
}
rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM);
if(NS_FAILED(rv)) {
return rv;
}
rv = mPrintVM->Init(mPrintDC);
if(NS_FAILED(rv)) {
return rv;
}
rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView);
if(NS_FAILED(rv)) {
return rv;
}
nsRect tbounds = nsRect(0,0,width,height);
rv = mPrintView->Init(mPrintVM,tbounds,nsnull);
if(NS_FAILED(rv)) {
return rv;
}
// setup hierarchical relationship in view manager
mPrintVM->SetRootView(mPrintView);
mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);
nsCOMPtr<nsIImageGroup> imageGroup;
mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));
if (imageGroup) {
imageGroup->AddObserver(this);
}
mPrintPS->InitialReflow(width,height);
#ifdef DEBUG_dcone
float a1,a2;
PRInt32 i1,i2;
printf("CRITICAL PRINTING INFORMATION\n");
printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);
// DEVICE CONTEXT INFORMATION from PresContext
printf("DeviceContext of Presentation Context(%x)\n",dx);
dx->GetDevUnitsToTwips(a1);
dx->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
dx->GetAppUnitsToDevUnits(a1);
dx->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
dx->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
dx->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
dx->GetZoom(a1);
printf(" Zoom = %f\n",a1);
dx->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
dx->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
// DEVICE CONTEXT INFORMATION
printf("DeviceContext created for print(%x)\n",mPrintDC);
mPrintDC->GetDevUnitsToTwips(a1);
mPrintDC->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
mPrintDC->GetAppUnitsToDevUnits(a1);
mPrintDC->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
mPrintDC->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
mPrintDC->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
mPrintDC->GetZoom(a1);
printf(" Zoom = %f\n",a1);
mPrintDC->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
#endif
//
// The mIsPrinting flag is set when the ImageGroup observer is
// notified that images must be loaded as a result of the
// InitialReflow...
//
if(!mIsPrinting){
DocumentReadyForPrinting();
#ifdef DEBUG_dcone
printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
} else {
// use the observer mechanism to finish the printing
#ifdef DEBUG_dcone
printf("PRINTING OBSERVER STARTED\n");
#endif
}
}
}
}
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext)
{
nsCOMPtr<nsIStyleSet> ss;
nsCOMPtr<nsIPref> prefs;
nsCOMPtr<nsIViewManager> vm;
PRInt32 width, height;
nsIView *view;
nsresult rv;
PRInt32 count,i;
nsIWebShell *childWebShell;
nsIContentViewer *viewer;
NS_ENSURE_ARG_POINTER(aParent);
NS_ENSURE_ARG_POINTER(aDContext);
nsCOMPtr<nsIStyleSet> ss;
nsCOMPtr<nsIPref> prefs;
nsCOMPtr<nsIViewManager> vm;
PRInt32 width, height;
nsIView *view;
nsresult rv;
PRInt32 count,i;
nsCOMPtr<nsIWebShell> childWebShell;
nsCOMPtr<nsIContentViewer> viewer;
aParent->GetChildCount(count);
if(count> 0) {
for(i=0;i<count;i++) {
aParent->ChildAt(i,childWebShell);
childWebShell->GetContentViewer(&viewer);
viewer->PrintContent(childWebShell,aDContext);
NS_RELEASE(childWebShell);
NS_RELEASE(viewer);
aParent->ChildAt(i, *(getter_AddRefs(childWebShell)));
childWebShell->GetContentViewer(getter_AddRefs(viewer));
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE);
}
}
} else {
aDContext->BeginDocument();
@ -1025,7 +899,8 @@ void DocumentViewerImpl::DocumentReadyForPrinting()
//
// Send the document to the printer...
//
PrintContent(webContainer,mPrintDC);
nsresult rv = PrintContent(webContainer, mPrintDC);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent");
// printing is complete, clean up now
mIsPrinting = PR_FALSE;
@ -1039,3 +914,590 @@ void DocumentViewerImpl::DocumentReadyForPrinting()
}
}
/* ========================================================================================
* nsIContentViewerFile
* ======================================================================================== */
NS_IMETHODIMP DocumentViewerImpl::Search()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::ClearSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::SelectAll()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::CopySelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::CutSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::Paste()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* ========================================================================================
* nsIContentViewerEdit
* ======================================================================================== */
NS_IMETHODIMP
DocumentViewerImpl::Save()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
DocumentViewerImpl::GetSaveable(PRBool *aSaveable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::Print()
{
nsCOMPtr<nsIWebShell> webContainer;
nsCOMPtr<nsIDeviceContextSpecFactory> factory;
PRInt32 width,height;
nsCOMPtr<nsIPref> prefs;
nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,
nsnull,
kIDeviceContextSpecFactoryIID,
(void **)getter_AddRefs(factory));
if (factory) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
#endif
nsIDeviceContextSpec *devspec = nsnull;
nsCOMPtr<nsIDeviceContext> dx;
mPrintDC = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
if (nsnull != devspec) {
mPresContext->GetDeviceContext(getter_AddRefs(dx));
nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(devspec);
// Get the webshell for this documentviewer
webContainer = do_QueryInterface(mContainer);
if(webContainer) {
// load the document and do the initial reflow on the entire document
rv = NS_NewPrintContext(&mPrintPC);
if(NS_FAILED(rv)){
return rv;
}
mPrintDC->GetDeviceSurfaceDimensions(width,height);
mPresContext->GetPrefs(getter_AddRefs(prefs));
mPrintPC->Init(mPrintDC,prefs);
CreateStyleSet(mDocument,&mPrintSS);
rv = NS_NewPresShell(&mPrintPS);
if(NS_FAILED(rv)){
return rv;
}
rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM);
if(NS_FAILED(rv)) {
return rv;
}
rv = mPrintVM->Init(mPrintDC);
if(NS_FAILED(rv)) {
return rv;
}
rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView);
if(NS_FAILED(rv)) {
return rv;
}
nsRect tbounds = nsRect(0,0,width,height);
rv = mPrintView->Init(mPrintVM,tbounds,nsnull);
if(NS_FAILED(rv)) {
return rv;
}
// setup hierarchical relationship in view manager
mPrintVM->SetRootView(mPrintView);
mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);
nsCOMPtr<nsIImageGroup> imageGroup;
mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));
if (imageGroup) {
imageGroup->AddObserver(this);
}
mPrintPS->InitialReflow(width,height);
#ifdef DEBUG_dcone
float a1,a2;
PRInt32 i1,i2;
printf("CRITICAL PRINTING INFORMATION\n");
printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);
// DEVICE CONTEXT INFORMATION from PresContext
printf("DeviceContext of Presentation Context(%x)\n",dx);
dx->GetDevUnitsToTwips(a1);
dx->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
dx->GetAppUnitsToDevUnits(a1);
dx->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
dx->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
dx->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
dx->GetZoom(a1);
printf(" Zoom = %f\n",a1);
dx->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
dx->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
// DEVICE CONTEXT INFORMATION
printf("DeviceContext created for print(%x)\n",mPrintDC);
mPrintDC->GetDevUnitsToTwips(a1);
mPrintDC->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
mPrintDC->GetAppUnitsToDevUnits(a1);
mPrintDC->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
mPrintDC->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
mPrintDC->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
mPrintDC->GetZoom(a1);
printf(" Zoom = %f\n",a1);
mPrintDC->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
#endif
//
// The mIsPrinting flag is set when the ImageGroup observer is
// notified that images must be loaded as a result of the
// InitialReflow...
//
if(!mIsPrinting){
DocumentReadyForPrinting();
#ifdef DEBUG_dcone
printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
} else {
// use the observer mechanism to finish the printing
#ifdef DEBUG_dcone
printf("PRINTING OBSERVER STARTED\n");
#endif
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
DocumentViewerImpl::GetPrintable(PRBool *aPrintable)
{
NS_ENSURE_ARG_POINTER(aPrintable);
*aPrintable = PR_TRUE;
return NS_OK;
}
//*****************************************************************************
// nsIMarkupDocumentViewer
//*****************************************************************************
NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode)
{
NS_ENSURE_ARG(aNode);
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
// Get the nsIContent interface, because that's what we need to
// get the primary frame
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
// Get the primary frame
nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their
// own special little world.
NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame),
NS_ERROR_FAILURE);
// tell the pres shell to scroll to the frame
NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame,
NS_PRESSHELL_SCROLL_TOP,
NS_PRESSHELL_SCROLL_ANYWHERE),
NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins)
{
NS_ENSURE_ARG_POINTER(aAllowPlugins);
*aAllowPlugins = mAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins)
{
mAllowPlugins = aAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetIsFrame(PRBool* aIsFrame)
{
NS_ENSURE_ARG_POINTER(aIsFrame);
*aIsFrame = mIsFrame;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetIsFrame(PRBool aIsFrame)
{
mIsFrame = aIsFrame;
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aDefaultCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet)
{
NS_ENSURE_ARG_POINTER(aDefaultCharacterSet);
NS_ENSURE_STATE(mContainer);
static char *gDefCharset = nsnull; // XXX: memory leak!
if (0 == mDefaultCharacterSet.Length())
{
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
{
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIPref> prefs;
NS_ENSURE_SUCCESS(webShell->GetPrefs(*(getter_AddRefs(prefs))), NS_ERROR_FAILURE);
if(prefs)
prefs->CopyCharPref("intl.charset.default", &gDefCharset);
}
}
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
mDefaultCharacterSet = "ISO-8859-1";
else
mDefaultCharacterSet = gDefCharset;
}
*aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
// now set the default char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetDefaultCharacterSet(aDefaultCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aForceCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet)
{
NS_ENSURE_ARG_POINTER(aForceCharacterSet);
nsAutoString emptyStr;
if (mForceCharacterSet.Equals(emptyStr)) {
*aForceCharacterSet = nsnull;
}
else {
*aForceCharacterSet = mForceCharacterSet.ToNewUnicode();
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet)
{
mForceCharacterSet = aForceCharacterSet;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetForceCharacterSet(aForceCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aHintCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSet);
if(kCharsetUninitialized == mHintCharsetSource) {
*aHintCharacterSet = nsnull;
} else {
*aHintCharacterSet = mHintCharset.ToNewUnicode();
// this can't possibly be right. we can't set a value just because somebody got a related value!
//mHintCharsetSource = kCharsetUninitialized;
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
*aHintCharacterSetSource = mHintCharsetSource;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource)
{
mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetHintCharacterSetSource(aHintCharacterSetSource);
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet)
{
mHintCharset = aHintCharacterSet;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetHintCharacterSet(aHintCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: poor error checking
NS_IMETHODIMP DocumentViewerImpl::SizeToContent()
{
// XXX: for now, just call the webshell's SizeToContent
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
return webShell->SizeToContent();
}
else {
return NS_ERROR_FAILURE;
}
#ifdef NEW_DOCSHELL_INTERFACES
// get the presentation shell
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsRect shellArea;
PRInt32 width, height;
float pixelScale;
NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
NS_ERROR_FAILURE);
// so how big is it?
nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(GetPresContext(*(getter_AddRefs(presContext))),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
presContext->GetVisibleArea(shellArea);
presContext->GetTwipsToPixels(&pixelScale);
width = PRInt32((float)shellArea.width*pixelScale);
height = PRInt32((float)shellArea.height*pixelScale);
// if we're the outermost webshell for this window, size the window
/* XXX: how do we do this now?
if (mContainer)
{
nsCOMPtr<nsIBrowserWindow> browser = do_QueryInterface(mContainer);
if (browser)
{
nsCOMPtr<nsIDocShell> browserWebShell;
PRInt32 oldX, oldY, oldWidth, oldHeight,
widthDelta, heightDelta;
nsRect windowBounds;
GetBounds(oldX, oldY, oldWidth, oldHeight);
widthDelta = width - oldWidth;
heightDelta = height - oldHeight;
browser->GetWindowBounds(windowBounds);
browser->SizeWindowTo(windowBounds.width + widthDelta,
windowBounds.height + heightDelta);
}
}
*/
NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
//return NS_OK;
#endif
}

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

@ -33,6 +33,7 @@
#include "nsIPresContext.h"
#include "nsIViewManager.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsHTMLTokens.h"
#include "nsHTMLEntities.h"
#include "nsCRT.h"
@ -2694,7 +2695,16 @@ HTMLContentSink::StartLayout()
}
else if (mBody) {
PRBool isFrameDoc = PR_FALSE;
mWebShell->GetIsFrame(isFrameDoc);
nsCOMPtr<nsIContentViewer> cv;
mWebShell->GetContentViewer(getter_AddRefs(cv));
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV)
{
muCV->GetIsFrame(&isFrameDoc);
}
}
// a <frame> webshell will have its scrolling set by the parent nsFramesetFrame.
// a <body> webshell is reset here just for safety.
if (!isFrameDoc) {

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

@ -49,6 +49,9 @@
#include "nsIIOService.h"
#include "nsIURL.h"
#include "nsNeckoUtil.h"
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIWebShell.h"
#include "nsIWebShellServices.h"
#include "nsIDocumentLoader.h"
@ -392,7 +395,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
nsIWebShell* webShell;
nsCOMPtr<nsIWebShell> webShell;
nsAutoString charset = "ISO-8859-1"; // fallback value in case webShell return error
nsCharsetSource charsetSource = kCharsetFromWeakDocTypeDefault;
@ -503,7 +506,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (NS_OK == rv) {
nsIHTMLContentSink* sink;
const PRUnichar* requestCharset = nsnull;
PRUnichar* requestCharset = nsnull;
nsCharsetSource requestCharsetSource = kCharsetUninitialized;
nsIParserFilter *cdetflt = nsnull;
@ -513,104 +516,123 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
rv = NS_New_HTML_ContentSinkStream(&sink,&outString,0);
#else
NS_PRECONDITION(nsnull != aContainer, "No content viewer container");
aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);
aContainer->QueryInterface(kIWebShellIID, getter_AddRefs(webShell));
rv = NS_NewHTMLContentSink(&sink, this, aURL, webShell);
if (NS_SUCCEEDED(rv)) {
if(kCharsetFromUserDefault > charsetSource) {
const PRUnichar* defaultCharsetFromWebShell = NULL;
rv = webShell->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
if(NS_SUCCEEDED(rv)) {
charset = defaultCharsetFromWebShell;
charsetSource = kCharsetFromUserDefault;
}
}
// for html, we need to find out the Meta tag from the hint.
rv = webShell->GetCharacterSetHint(&requestCharset, &requestCharsetSource);
if(NS_SUCCEEDED(rv)) {
if(requestCharsetSource > charsetSource)
{
charsetSource = requestCharsetSource;
charset = requestCharset;
}
}
if(kCharsetFromPreviousLoading > charsetSource)
{
const PRUnichar* forceCharsetFromWebShell = NULL;
rv = webShell->GetForceCharacterSet(&forceCharsetFromWebShell);
if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell)) {
charset = forceCharsetFromWebShell;
//TODO: we should define appropriate constant for force charset
charsetSource = kCharsetFromPreviousLoading;
}
}
nsresult rv_detect = NS_OK;
if(! gInitDetector)
{
nsIPref* pref = nsnull;
if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref)
{
char* detector_name = nsnull;
if(NS_SUCCEEDED(
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIMarkupDocumentViewer> muCV;
nsCOMPtr<nsIContentViewer> cv;
webShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
muCV = do_QueryInterface(cv);
}
if(kCharsetFromUserDefault > charsetSource)
{
PRUnichar* defaultCharsetFromWebShell = NULL;
if (muCV) {
rv = muCV->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
}
if(NS_SUCCEEDED(rv)) {
charset = defaultCharsetFromWebShell;
Recycle(defaultCharsetFromWebShell);
charsetSource = kCharsetFromUserDefault;
}
// for html, we need to find out the Meta tag from the hint.
if (muCV) {
rv = muCV->GetHintCharacterSet(&requestCharset);
if(NS_SUCCEEDED(rv)) {
rv = muCV->GetHintCharacterSetSource((PRInt32*)(&requestCharsetSource));
}
}
if(NS_SUCCEEDED(rv))
{
if(requestCharsetSource > charsetSource)
{
charsetSource = requestCharsetSource;
charset = requestCharset;
Recycle(requestCharset);
}
}
if(kCharsetFromPreviousLoading > charsetSource)
{
PRUnichar* forceCharsetFromWebShell = NULL;
if (muCV) {
rv = muCV->GetForceCharacterSet(&forceCharsetFromWebShell);
}
if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell))
{
charset = forceCharsetFromWebShell;
Recycle(forceCharsetFromWebShell);
//TODO: we should define appropriate constant for force charset
charsetSource = kCharsetFromPreviousLoading;
}
}
nsresult rv_detect = NS_OK;
if(! gInitDetector)
{
nsIPref* pref = nsnull;
if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref)
{
char* detector_name = nsnull;
if(NS_SUCCEEDED(
rv_detect = pref->CopyCharPref("intl.charset.detector",
&detector_name)))
{
PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX);
PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX);
gPlugDetector = PR_TRUE;
PR_FREEIF(detector_name);
}
pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull);
}
NS_IF_RELEASE(pref);
gInitDetector = PR_TRUE;
}
{
PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX);
PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX);
gPlugDetector = PR_TRUE;
PR_FREEIF(detector_name);
}
pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull);
}
NS_IF_RELEASE(pref);
gInitDetector = PR_TRUE;
}
if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector)
{
// we could do charset detection
nsICharsetDetector *cdet = nsnull;
nsIWebShellServices *wss = nsnull;
nsICharsetDetectionAdaptor *adp = nsnull;
if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector)
{
// we could do charset detection
nsICharsetDetector *cdet = nsnull;
nsIWebShellServices *wss = nsnull;
nsICharsetDetectionAdaptor *adp = nsnull;
if(NS_SUCCEEDED( rv_detect =
if(NS_SUCCEEDED( rv_detect =
nsComponentManager::CreateInstance(g_detector_progid, nsnull,
nsICharsetDetector::GetIID(), (void**)&cdet)))
{
if(NS_SUCCEEDED( rv_detect =
{
if(NS_SUCCEEDED( rv_detect =
nsComponentManager::CreateInstance(
NS_CHARSET_DETECTION_ADAPTOR_PROGID, nsnull,
kIParserFilterIID, (void**)&cdetflt)))
{
if(cdetflt &&
{
if(cdetflt &&
NS_SUCCEEDED( rv_detect=
cdetflt->QueryInterface(
nsICharsetDetectionAdaptor::GetIID(),(void**) &adp)))
{
if( NS_SUCCEEDED( rv_detect=
{
if( NS_SUCCEEDED( rv_detect=
webShell->QueryInterface(
nsIWebShellServices::GetIID(),(void**) &wss)))
{
rv_detect = adp->Init(wss, cdet, aCommand);
}
}
{
rv_detect = adp->Init(wss, cdet, aCommand);
}
}
} else {
// IF we cannot create the detector, don't bother to
// create one next time.
gPlugDetector = PR_FALSE;
}
NS_IF_RELEASE(wss);
NS_IF_RELEASE(cdet);
NS_IF_RELEASE(adp);
// NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter
}
}
}
else
{
// IF we cannot create the detector, don't bother to
// create one next time.
gPlugDetector = PR_FALSE;
}
NS_IF_RELEASE(wss);
NS_IF_RELEASE(cdet);
NS_IF_RELEASE(adp);
// NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter
}
}
}
NS_IF_RELEASE(webShell);
#endif
if (NS_SUCCEEDED(rv)) {

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

@ -29,7 +29,10 @@
#include "nsIXMLContentSink.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIWebShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIDocumentLoader.h"
#include "nsIHTMLContent.h"
#include "nsHTMLParts.h"
@ -263,20 +266,31 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
rv = aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);
if(NS_SUCCEEDED(rv) && (nsnull != webShell)) {
if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source
const PRUnichar* hintCharset = nsnull;
nsCharsetSource hintSource = kCharsetUninitialized;
rv = webShell->GetCharacterSetHint(&hintCharset, &hintSource);
if(NS_SUCCEEDED(rv)) {
if(hintSource > charsetSource) {
charset = hintCharset;
charsetSource = hintSource;
nsCOMPtr<nsIContentViewer> cv;
webShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV) {
if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source
PRUnichar* hintCharset = nsnull;
nsCharsetSource hintSource = kCharsetUninitialized;
rv = muCV->GetHintCharacterSet(&hintCharset);
if(NS_SUCCEEDED(rv)) {
rv = muCV->GetHintCharacterSetSource((PRInt32 *)(&hintSource));
if(NS_SUCCEEDED(rv)) {
if(hintSource > charsetSource) {
charset = hintCharset;
Recycle(hintCharset);
charsetSource = hintSource;
}
}
}
}
if(NS_SUCCEEDED(rv))
rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell);
NS_IF_RELEASE(webShell);
}
}
}
}
if(NS_SUCCEEDED(rv))
rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell);
NS_IF_RELEASE(webShell);
}
if (NS_OK == rv) {

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

@ -28,6 +28,9 @@ XPIDLSRCS= \
.\nsIDocShellContainer.idl \
.\nsIDocShellFile.idl \
.\nsIDocShellEdit.idl \
.\nsIContentViewerEdit.idl \
.\nsIContentViewerFile.idl \
.\nsIMarkupDocumentViewer.idl \
.\nsIScrollable.idl \
.\nsITextScroll.idl \
$(NULL)

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

@ -34,7 +34,7 @@
#include "nsRect.h"
#include "prprf.h"
#include "nsIFrame.h"
#include "nsIContent.h"
#include "nsIMarkupDocumentViewer.h"
#ifdef XXX_NS_DEBUG // XXX: we'll need a logging facility for debugging
#define WEB_TRACE(_bit,_args) \
@ -54,11 +54,11 @@
//*** nsDocShell: Object Management
//*****************************************************************************
nsDocShell::nsDocShell() : mCreated(PR_FALSE), mContentListener(nsnull),
//XXX Remove HTML Specific ones
mAllowPlugins(PR_TRUE), mMarginWidth(0), mMarginHeight(0),
mIsFrame(PR_FALSE)
nsDocShell::nsDocShell() :
mCreated(PR_FALSE),
mContentListener(nsnull),
mMarginWidth(0),
mMarginHeight(0)
{
NS_INIT_REFCNT();
}
@ -103,9 +103,6 @@ NS_IMPL_RELEASE(nsDocShell)
NS_IMPL_QUERY_HEAD(nsDocShell)
NS_IMPL_QUERY_BODY(nsIDocShell)
NS_IMPL_QUERY_BODY(nsIHTMLDocShell)
NS_IMPL_QUERY_BODY(nsIDocShellEdit)
NS_IMPL_QUERY_BODY(nsIDocShellFile)
NS_IMPL_QUERY_BODY(nsIBaseWindow)
NS_IMPL_QUERY_BODY(nsIScrollable)
NS_IMPL_QUERY_BODY(nsITextScroll)
@ -459,6 +456,42 @@ nsDocShell::SetDocLoaderObserver(nsIDocumentLoaderObserver * aDocLoaderObserver)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetMarginWidth(PRInt32* aWidth)
{
NS_ENSURE_ARG_POINTER(aWidth);
*aWidth = mMarginWidth;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetMarginWidth(PRInt32 aWidth)
{
mMarginWidth = aWidth;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetMarginHeight(PRInt32* aHeight)
{
NS_ENSURE_ARG_POINTER(aHeight);
*aHeight = mMarginHeight;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetMarginHeight(PRInt32 aHeight)
{
mMarginHeight = aHeight;
return NS_OK;
}
// the following code is to be removed. It will show up on content viewer classes
#if 0
//*****************************************************************************
// nsDocShell::nsIDocShellEdit
//*****************************************************************************
@ -686,6 +719,7 @@ NS_IMETHODIMP nsDocShell::GetPrintable(PRBool* printable)
*printable = PR_FALSE;
return NS_OK;
}
#endif
//*****************************************************************************
// nsDocShell::nsIDocShellContainer
@ -700,26 +734,38 @@ NS_IMETHODIMP nsDocShell::GetChildCount(PRInt32 *aChildCount)
NS_IMETHODIMP nsDocShell::AddChild(nsIDocShell *aChild)
{
NS_ENSURE_ARG_POINTER(aChild);
NS_ENSURE_ARG_POINTER(aChild);
NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE);
mChildren.AppendElement(aChild);
NS_ADDREF(aChild);
NS_ENSURE_SUCCESS(aChild->SetParent(this), NS_ERROR_FAILURE);
mChildren.AppendElement(aChild);
NS_ADDREF(aChild);
//XXX HTML Specifics need to be moved out.
nsCOMPtr<nsIHTMLDocShell> childAsHTMLDocShell = do_QueryInterface(aChild);
if (childAsHTMLDocShell)
PRUnichar *defaultCharset=nsnull;
PRUnichar *forceCharset=nsnull;
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE);
}
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(aChild->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> childmuDV = do_QueryInterface(cv);
if (childmuDV)
{
PRUnichar *defaultCharset=nsnull;
NS_ENSURE_SUCCESS(GetDefaultCharacterSet(&defaultCharset),
NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetDefaultCharacterSet(
defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetForceCharacterSet(
mForceCharacterSet.GetUnicode()), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(childmuDV->SetDefaultCharacterSet(defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(childmuDV->SetForceCharacterSet(forceCharset), NS_ERROR_FAILURE);
}
}
}
return NS_OK;
return NS_OK;
}
// tiny semantic change from webshell. aChild is only effected if it was actually a child of this docshell
@ -730,7 +776,7 @@ NS_IMETHODIMP nsDocShell::RemoveChild(nsIDocShell *aChild)
PRBool childRemoved = mChildren.RemoveElement(aChild);
if (PR_TRUE==childRemoved)
{
aChild->SetParent(nsnull);
NS_ENSURE_SUCCESS(aChild->SetParent(nsnull), NS_ERROR_FAILURE);
NS_RELEASE(aChild);
}
return NS_OK;
@ -1320,246 +1366,6 @@ NS_IMETHODIMP nsDocShell::ScrollByPages(PRInt32 numPages)
return NS_OK;
}
//*****************************************************************************
// nsDocShell::nsIHTMLDocShell
//*****************************************************************************
NS_IMETHODIMP nsDocShell::ScrollToNode(nsIDOMNode* aNode)
{
NS_ENSURE_ARG(aNode);
NS_ENSURE_STATE(mContentViewer);
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);
// Get the nsIContent interface, because that's what we need to
// get the primary frame
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
// Get the primary frame
nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their
// own special little world.
NS_ENSURE_SUCCESS(GetPrimaryFrameFor(content, &frame),
NS_ERROR_FAILURE);
// tell the pres shell to scroll to the frame
NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame,
NS_PRESSHELL_SCROLL_TOP, NS_PRESSHELL_SCROLL_ANYWHERE), NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetAllowPlugins(PRBool* aAllowPlugins)
{
NS_ENSURE_ARG_POINTER(aAllowPlugins);
*aAllowPlugins = mAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetAllowPlugins(PRBool aAllowPlugins)
{
mAllowPlugins = aAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetMarginWidth(PRInt32* aMarginWidth)
{
NS_ENSURE_ARG_POINTER(aMarginWidth);
*aMarginWidth = mMarginWidth;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetMarginWidth(PRInt32 aMarginWidth)
{
mMarginWidth = aMarginWidth;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetMarginHeight(PRInt32* aMarginHeight)
{
NS_ENSURE_ARG_POINTER(aMarginHeight);
*aMarginHeight = mMarginHeight;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetMarginHeight(PRInt32 aMarginHeight)
{
mMarginHeight = aMarginHeight;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetIsFrame(PRBool* aIsFrame)
{
NS_ENSURE_ARG_POINTER(aIsFrame);
*aIsFrame = mIsFrame;
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetIsFrame(PRBool aIsFrame)
{
mIsFrame = aIsFrame;
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aDefaultCharacterSet)
NS_IMETHODIMP nsDocShell::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet)
{
NS_ENSURE_ARG_POINTER(aDefaultCharacterSet);
static char *gDefCharset = nsnull; // XXX: memory leak!
if (0 == mDefaultCharacterSet.Length())
{
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
{
if(mPrefs)
mPrefs->CopyCharPref("intl.charset.default", &gDefCharset);
}
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
mDefaultCharacterSet = "ISO-8859-1";
else
mDefaultCharacterSet = gDefCharset;
}
*aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++)
{
nsIDocShell* child = (nsIDocShell*) mChildren.ElementAt(i);
NS_WARN_IF_FALSE(child, "null child in docshell");
if (child)
{
nsCOMPtr<nsIHTMLDocShell> childAsHTMLDocShell = do_QueryInterface(child);
if (childAsHTMLDocShell) {
childAsHTMLDocShell->SetDefaultCharacterSet(aDefaultCharacterSet);
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aForceCharacterSet)
NS_IMETHODIMP nsDocShell::GetForceCharacterSet(PRUnichar** aForceCharacterSet)
{
NS_ENSURE_ARG_POINTER(aForceCharacterSet);
nsAutoString emptyStr;
if (mForceCharacterSet.Equals(emptyStr)) {
*aForceCharacterSet = nsnull;
}
else {
*aForceCharacterSet = mForceCharacterSet.ToNewUnicode();
}
return NS_OK;
}
NS_IMETHODIMP nsDocShell::SetForceCharacterSet(const PRUnichar* aForceCharacterSet)
{
mForceCharacterSet = aForceCharacterSet;
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++) {
nsIDocShell* child = (nsIDocShell*) mChildren.ElementAt(i);
NS_WARN_IF_FALSE(child, "null child in docshell");
if (child)
{
nsCOMPtr<nsIHTMLDocShell> childAsHTMLDocShell = do_QueryInterface(child);
if (childAsHTMLDocShell) {
childAsHTMLDocShell->SetForceCharacterSet(aForceCharacterSet);
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aHintCharacterSet)
NS_IMETHODIMP nsDocShell::GetHintCharacterSet(PRUnichar * *aHintCharacterSet)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSet);
if(kCharsetUninitialized == mHintCharsetSource) {
*aHintCharacterSet = nsnull;
} else {
*aHintCharacterSet = mHintCharset.ToNewUnicode();
mHintCharsetSource = kCharsetUninitialized;
}
return NS_OK;
}
NS_IMETHODIMP nsDocShell::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
*aHintCharacterSetSource = mHintCharsetSource;
return NS_OK;
}
// XXX: poor error checking
NS_IMETHODIMP nsDocShell::SizeToContent()
{
// get the presentation shell
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(getter_AddRefs(presShell)), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsRect shellArea;
PRInt32 width, height;
float pixelScale;
NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
NS_ERROR_FAILURE);
// so how big is it?
nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(GetPresContext(getter_AddRefs(presContext)),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
presContext->GetVisibleArea(shellArea);
presContext->GetTwipsToPixels(&pixelScale);
width = PRInt32((float)shellArea.width*pixelScale);
height = PRInt32((float)shellArea.height*pixelScale);
// if we're the outermost webshell for this window, size the window
/* XXX: how do we do this now?
if (mContainer)
{
nsCOMPtr<nsIBrowserWindow> browser = do_QueryInterface(mContainer);
if (browser)
{
nsCOMPtr<nsIDocShell> browserWebShell;
PRInt32 oldX, oldY, oldWidth, oldHeight,
widthDelta, heightDelta;
nsRect windowBounds;
GetBounds(oldX, oldY, oldWidth, oldHeight);
widthDelta = width - oldWidth;
heightDelta = height - oldHeight;
browser->GetWindowBounds(windowBounds);
browser->SizeWindowTo(windowBounds.width + widthDelta,
windowBounds.height + heightDelta);
}
}
*/
NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
//return NS_OK;
}
//*****************************************************************************
// nsDocShell::nsIContentViewerContainer
//*****************************************************************************
@ -2007,3 +1813,4 @@ NS_IMETHODIMP nsDocShell::GetInterface(const nsIID& anIID, void** aSink)
{
return QueryInterface(anIID, aSink);
}

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

@ -59,14 +59,11 @@ public:
};
class nsDocShell : public nsIDocShell,
public nsIDocShellEdit,
public nsIDocShellFile,
public nsIDocShellContainer,
public nsIBaseWindow,
public nsIScrollable,
public nsITextScroll,
public nsIContentViewerContainer,
public nsIHTMLDocShell
public nsIDocShellContainer,
public nsIBaseWindow,
public nsIScrollable,
public nsITextScroll,
public nsIContentViewerContainer
{
friend class nsDSURIContentListener;
@ -74,13 +71,10 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOCSHELL
NS_DECL_NSIDOCSHELLEDIT
NS_DECL_NSIDOCSHELLFILE
NS_DECL_NSIDOCSHELLCONTAINER
NS_DECL_NSIBASEWINDOW
NS_DECL_NSISCROLLABLE
NS_DECL_NSITEXTSCROLL
NS_DECL_NSIHTMLDOCSHELL
NS_DECL_NSIINTERFACEREQUESTOR
// XXX: move to a macro
@ -145,6 +139,8 @@ protected:
nsCOMPtr<nsIScriptGlobalObject> mScriptGlobal;
nsCOMPtr<nsIScriptContext> mScriptContext;
nsCOMPtr<nsISupports> mLoadCookie;
PRInt32 mMarginWidth;
PRInt32 mMarginHeight;
/* Note this can not be nsCOMPtr as that that would cause an addref on the
parent thus a cycle. A weak reference would work, but not required as the
@ -152,18 +148,6 @@ protected:
releasing the interface.*/
nsIDocShell* mParent;
/*
XXX HTML Specific stuff
*/
PRBool mAllowPlugins;
PRInt32 mMarginWidth;
PRInt32 mMarginHeight;
PRBool mIsFrame;
/* character set member data */
nsString mDefaultCharacterSet;
nsString mHintCharset;
nsCharsetSource mHintCharsetSource;
nsString mForceCharacterSet;
};
#endif /* nsDocShell_h__ */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -161,22 +161,7 @@ interface nsIDocShell : nsISupports
* no zoom.
*/
attribute float zoom;
};
/**
* The nsIHTMLDocShell - XXX This is going away.
*/
[scriptable, uuid(69E5DE03-7B8B-11d3-AF61-00A024FFC08C)]
interface nsIHTMLDocShell : nsISupports
{
/*
Scrolls to a given DOM content node.
*/
void scrollToNode(in nsIDOMNode node);
/** if true, plugins are allowed within the doc shell. default = true */
attribute boolean allowPlugins;
/*
XXX Comment here!
@ -187,39 +172,5 @@ interface nsIHTMLDocShell : nsISupports
XXX Comment here!
*/
attribute long marginHeight;
/*
XXX Comment here!
*/
attribute boolean isFrame;
/*
XXX Comment here!
*/
attribute wstring defaultCharacterSet;
/*
XXX Comment here!
*/
attribute wstring forceCharacterSet;
/*
XXX Comment here!
*/
readonly attribute wstring hintCharacterSet;
/*
XXX Comment here!
*/
readonly attribute PRInt32 hintCharacterSetSource;
/* the following is the hacky access method
Commented out as nsCharsetSource should be something IDL like
void GetCharacterSetHint(in wstring hintCharset, in nsCharsetSource charsetSource);
*/
/**
* Tell the window to shrink-to-fit or grow-to-fit its contents
*/
void sizeToContent();
};

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

@ -24,6 +24,7 @@
#include "nsIDocumentLoader.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIClipboardCommands.h"
#include "nsIDeviceContext.h"
#include "nsILinkHandler.h"
@ -225,14 +226,14 @@ public:
NS_IMETHOD GetContainingChromeElement(nsIContent** aResult);
NS_IMETHOD SetContainingChromeElement(nsIContent* aChromeElement);
NS_IMETHOD GetMarginWidth (PRInt32& aWidth);
NS_IMETHOD SetMarginWidth (PRInt32 aWidth);
NS_IMETHOD GetMarginHeight(PRInt32& aWidth);
NS_IMETHOD SetMarginHeight(PRInt32 aHeight);
NS_IMETHOD GetScrolling(PRInt32& aScrolling);
NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE);
NS_IMETHOD GetIsFrame(PRBool& aIsFrame);
NS_IMETHOD SetIsFrame(PRBool aIsFrame);
NS_IMETHOD GetMarginWidth (PRInt32* aWidth);
NS_IMETHOD SetMarginWidth (PRInt32 aWidth);
NS_IMETHOD GetMarginHeight(PRInt32* aWidth);
NS_IMETHOD SetMarginHeight(PRInt32 aHeight);
NS_IMETHOD SetZoom(float aZoom);
NS_IMETHOD GetZoom(float *aZoom);
@ -402,13 +403,6 @@ public:
nsresult DestroyPluginHost(void);
NS_IMETHOD IsBusy(PRBool& aResult);
NS_IMETHOD GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet);
NS_IMETHOD SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet);
NS_IMETHOD GetForceCharacterSet (const PRUnichar** aForceCharacterSet);
NS_IMETHOD SetForceCharacterSet (const PRUnichar* aForceCharacterSet);
NS_IMETHOD GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource);
NS_IMETHOD SetSessionHistory(nsISessionHistory * aSHist);
NS_IMETHOD GetSessionHistory(nsISessionHistory *& aResult);
@ -464,12 +458,13 @@ protected:
nsString mOverTarget;
PRPackedBool mIsInSHist;
PRPackedBool mIsFrame;
PRPackedBool mFailedToLoadHistoryService;
nsScrollPreference mScrollPref;
PRInt32 mMarginWidth;
PRInt32 mMarginHeight;
PRInt32 mScrolling[2];
nsVoidArray mRefreshments;
@ -507,11 +502,14 @@ protected:
PRBool mProcessedEndDocumentLoad;
// XXX store mHintCharset and mHintCharsetSource here untill we find out a good cood path
/*
nsString mHintCharset;
nsCharsetSource mHintCharsetSource;
PRBool mViewSource;
nsString mForceCharacterSet;
*/
PRBool mViewSource;
// if there is no mWindow, this will keep track of the bounds --dwc0001
nsRect mBounds;
@ -657,7 +655,6 @@ nsWebShell::nsWebShell()
mScriptContext = nsnull;
mThreadEventQueue = nsnull;
InitFrameData(PR_TRUE);
mIsFrame = PR_FALSE;
mWebShellType = nsWebShellContent;
mChromeElement = nsnull;
mSHist = nsnull;
@ -665,11 +662,8 @@ nsWebShell::nsWebShell()
mFailedToLoadHistoryService = PR_FALSE;
mDefaultCharacterSet = "";
mProcessedEndDocumentLoad = PR_FALSE;
mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized;
mCharsetReloadState = eCharsetReloadInit;
mViewSource=PR_FALSE;
mForceCharacterSet = "";
mHistoryService = nsnull;
mHistoryState = nsnull;
mParentContentListener = nsnull;
@ -713,7 +707,6 @@ nsWebShell::~nsWebShell()
}
InitFrameData(PR_TRUE);
mIsFrame = PR_FALSE;
// XXX Because we hold references to the children and they hold references
// to us we never get destroyed. See Destroy() instead...
@ -747,8 +740,8 @@ void nsWebShell::InitFrameData(PRBool aCompleteInitScrolling)
if (aCompleteInitScrolling) {
mScrolling[0] = -1;
mScrolling[1] = -1;
mMarginWidth = -1;
mMarginHeight = -1;
SetMarginWidth(-1);
SetMarginHeight(-1);
}
else {
mScrolling[1] = mScrolling[0];
@ -838,6 +831,41 @@ nsWebShell::Embed(nsIContentViewer* aContentViewer,
("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p",
this, aContentViewer, aCommand ? aCommand : "", aExtraInfo));
if (mContentViewer && (eCharsetReloadInit!=mCharsetReloadState))
{ // get any interesting state from the old content viewer
// XXX: it would be far better to just reuse the document viewer ,
// since we know we're just displaying the same document as before
PRUnichar *defaultCharset=nsnull;
PRUnichar *forceCharset=nsnull;
PRUnichar *hintCharset=nsnull;
PRInt32 hintCharsetSource;
nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV = do_QueryInterface(mContentViewer);
nsCOMPtr<nsIMarkupDocumentViewer> newMUDV = do_QueryInterface(aContentViewer);
if (oldMUDV && newMUDV)
{
NS_ENSURE_SUCCESS(oldMUDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSet (&hintCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource (&hintCharsetSource), NS_ERROR_FAILURE);
// set the old state onto the new content viewer
NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet (defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet (forceCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet (hintCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSetSource (hintCharsetSource), NS_ERROR_FAILURE);
if (defaultCharSet) {
Recycle(defaultCharSet);
}
if (forceCharset) {
Recycle(forceCharset);
}
if (hintCharset) {
Recycle(hintCharset);
}
}
}
NS_IF_RELEASE(mContentViewer);
if (nsnull != mScriptContext) {
mScriptContext->GC();
@ -1586,10 +1614,30 @@ nsWebShell::AddChild(nsIWebShell* aChild)
}
mChildren.AppendElement(aChild);
aChild->SetParent(this);
const PRUnichar *defaultCharset=nsnull;
if(NS_SUCCEEDED(this->GetDefaultCharacterSet (&defaultCharset)))
aChild->SetDefaultCharacterSet(defaultCharset);
aChild->SetForceCharacterSet(mForceCharacterSet.GetUnicode());
PRUnichar *defaultCharset=nsnull;
PRUnichar *forceCharset=nsnull;
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE);
}
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(aChild->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> childmuDV = do_QueryInterface(cv);
if (childmuDV)
{
childmuDV->SetDefaultCharacterSet(defaultCharset);
childmuDV->SetForceCharacterSet(forceCharset);
}
}
}
NS_ADDREF(aChild);
return NS_OK;
@ -1736,9 +1784,11 @@ nsWebShell::SetContainingChromeElement(nsIContent* aChromeElement)
}
NS_IMETHODIMP
nsWebShell::GetMarginWidth(PRInt32& aWidth)
nsWebShell::GetMarginWidth(PRInt32* aWidth)
{
aWidth = mMarginWidth;
NS_ENSURE_ARG_POINTER(aWidth);
*aWidth = mMarginWidth;
return NS_OK;
}
@ -1750,9 +1800,11 @@ nsWebShell::SetMarginWidth(PRInt32 aWidth)
}
NS_IMETHODIMP
nsWebShell::GetMarginHeight(PRInt32& aHeight)
nsWebShell::GetMarginHeight(PRInt32* aHeight)
{
aHeight = mMarginHeight;
NS_ENSURE_ARG_POINTER(aHeight);
*aHeight = mMarginHeight;
return NS_OK;
}
@ -1780,20 +1832,6 @@ nsWebShell::SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial)
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::GetIsFrame(PRBool& aIsFrame)
{
aIsFrame = mIsFrame;
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetIsFrame(PRBool aIsFrame)
{
mIsFrame = aIsFrame;
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetZoom(float aZoom)
{
@ -1944,6 +1982,7 @@ nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode)
if (!doc) { return NS_ERROR_OUT_OF_MEMORY; }
NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE), NS_ERROR_FAILURE);
doc->SetRootContent(rootContent);
rootContent->SetDocument(doc, PR_TRUE);
// (6) reflow the document
SetScrolling(-1, PR_FALSE);
@ -2960,16 +2999,27 @@ nsWebShell::LoadDocument(const char* aURL,
nsCharsetSource aSource)
{
// XXX hack. kee the aCharset and aSource wait to pick it up
if( aSource > mHintCharsetSource ) {
mHintCharset = aCharset;
mHintCharsetSource = aSource;
if(eCharsetReloadRequested != mCharsetReloadState)
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
mCharsetReloadState = eCharsetReloadRequested;
nsAutoString url(aURL);
LoadURL(url.GetUnicode());
nsCharsetSource hint;
muDV->GetHintCharacterSetSource((PRInt32 *)(&hint));
if( aSource > hint )
{
nsAutoString inputCharSet(aCharset);
muDV->SetHintCharacterSet(inputCharSet.GetUnicode());
muDV->SetHintCharacterSetSource((PRInt32)aSource);
if(eCharsetReloadRequested != mCharsetReloadState)
{
mCharsetReloadState = eCharsetReloadRequested;
nsAutoString url(aURL);
LoadURL(url.GetUnicode());
}
}
}
}
return NS_OK;
@ -2982,15 +3032,28 @@ nsWebShell::ReloadDocument(const char* aCharset,
{
// XXX hack. kee the aCharset and aSource wait to pick it up
if( aSource > mHintCharsetSource ) {
mHintCharset = aCharset;
mHintCharsetSource = aSource;
mViewSource = (0==PL_strcmp("view-source", aCmd));
if(eCharsetReloadRequested != mCharsetReloadState)
{
mCharsetReloadState = eCharsetReloadRequested;
return Reload(nsIChannel::LOAD_NORMAL);
}
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
nsCharsetSource hint;
muDV->GetHintCharacterSetSource((PRInt32 *)(&hint));
if( aSource > hint )
{
nsAutoString inputCharSet(aCharset);
muDV->SetHintCharacterSet(inputCharSet.GetUnicode());
muDV->SetHintCharacterSetSource((PRInt32)aSource);
mViewSource = (0==PL_strcmp("view-source", aCmd));
if(eCharsetReloadRequested != mCharsetReloadState)
{
mCharsetReloadState = eCharsetReloadRequested;
return Reload(nsIChannel::LOAD_NORMAL);
}
}
}
}
return NS_OK;
}
@ -4185,77 +4248,6 @@ nsWebShell::SelectNone(void)
return NS_ERROR_FAILURE;
}
static char *gDefCharset = nsnull;
NS_IMETHODIMP
nsWebShell::GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet)
{
if (0 == mDefaultCharacterSet.Length()) {
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) {
if(mPrefs)
mPrefs->CopyCharPref("intl.charset.default", &gDefCharset);
}
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
mDefaultCharacterSet = "ISO-8859-1";
else
mDefaultCharacterSet = gDefCharset;
}
*aDefaultCharacterSet = mDefaultCharacterSet.GetUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet;
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++) {
nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i);
if (nsnull != child) {
child->SetDefaultCharacterSet(aDefaultCharacterSet);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::GetForceCharacterSet (const PRUnichar** aForceCharacterSet)
{
nsAutoString emptyStr;
if (mForceCharacterSet.Equals(emptyStr)) {
*aForceCharacterSet = nsnull;
}
else {
*aForceCharacterSet = mForceCharacterSet.GetUnicode();
}
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetForceCharacterSet (const PRUnichar* aForceCharacterSet)
{
mForceCharacterSet = aForceCharacterSet;
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++) {
nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i);
if (nsnull != child) {
child->SetForceCharacterSet(aForceCharacterSet);
}
}
return NS_OK;
}
NS_IMETHODIMP nsWebShell::GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource)
{
*oSource = mHintCharsetSource;
if(kCharsetUninitialized == mHintCharsetSource) {
*oHintCharset = nsnull;
} else {
*oHintCharset = mHintCharset.GetUnicode();
mHintCharsetSource = kCharsetUninitialized;
}
return NS_OK;
}
//----------------------------------------------------
NS_IMETHODIMP

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

@ -62,6 +62,7 @@
#include "nsRect.h"
#include "nsIPrompt.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
#include "nsIDocumentViewer.h"
#include "nsIPresShell.h"
#include "nsIScrollableView.h"
@ -1411,13 +1412,13 @@ GlobalWindowImpl::Print()
{
nsresult result = NS_OK;
if (nsnull != mWebShell) {
nsIContentViewer *viewer = nsnull;
mWebShell->GetContentViewer(&viewer);
nsCOMPtr<nsIContentViewer> viewer;
mWebShell->GetContentViewer(getter_AddRefs(viewer));
if (nsnull != viewer) {
result = viewer->Print();
NS_RELEASE(viewer);
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
result = viewerFile->Print();
}
}
}
@ -2616,18 +2617,19 @@ GlobalWindowImpl::GetBrowserWindowInterface(
nsIBrowserWindow*& aBrowser,
nsIWebShell *aWebShell)
{
aBrowser = nsnull;
aBrowser = nsnull;
if (nsnull == aWebShell)
if (nsnull == aWebShell)
aWebShell = mWebShell;
NS_ENSURE_TRUE(aWebShell, NS_ERROR_UNEXPECTED);
NS_ENSURE_TRUE(aWebShell, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
nsCOMPtr<nsIWebShellContainer> topLevelWindow;
NS_ENSURE_SUCCESS(aWebShell->GetTopLevelWindow(
getter_AddRefs(topLevelWindow)), NS_ERROR_FAILURE);
aWebShell->GetTopLevelWindow(getter_AddRefs(topLevelWindow));
if(!topLevelWindow)
return NS_ERROR_FAILURE;
return topLevelWindow->QueryInterface(NS_GET_IID(nsIBrowserWindow), (void**)&aBrowser);
if(!topLevelWindow)
return NS_ERROR_FAILURE;
return topLevelWindow->QueryInterface(NS_GET_IID(nsIBrowserWindow), (void**)&aBrowser);
}
PRBool

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

@ -25,6 +25,7 @@
#include "nsEditorShell.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIContentViewerFile.h"
#include "pratom.h"
#include "prprf.h"
#include "nsIComponentManager.h"
@ -1570,16 +1571,18 @@ nsEditorShell::Print()
if (!mContentAreaWebShell)
return NS_ERROR_NOT_INITIALIZED;
nsIContentViewer *viewer = nsnull;
mContentAreaWebShell->GetContentViewer(&viewer);
if (nsnull != viewer) {
viewer->Print();
NS_RELEASE(viewer);
nsCOMPtr<nsIContentViewer> viewer;
mContentAreaWebShell->GetContentViewer(getter_AddRefs(viewer));
if (nsnull != viewer)
{
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
NS_ENSURE_SUCCESS(viewerFile->Print(), NS_ERROR_FAILURE);
}
}
return NS_OK;
}
// NO LONGER CALLED Global JS method goQuitApplication() is called instead
NS_IMETHODIMP
nsEditorShell::Exit()

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

@ -25,6 +25,7 @@
#include "nsEditorShell.h"
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIContentViewerFile.h"
#include "pratom.h"
#include "prprf.h"
#include "nsIComponentManager.h"
@ -1570,16 +1571,18 @@ nsEditorShell::Print()
if (!mContentAreaWebShell)
return NS_ERROR_NOT_INITIALIZED;
nsIContentViewer *viewer = nsnull;
mContentAreaWebShell->GetContentViewer(&viewer);
if (nsnull != viewer) {
viewer->Print();
NS_RELEASE(viewer);
nsCOMPtr<nsIContentViewer> viewer;
mContentAreaWebShell->GetContentViewer(getter_AddRefs(viewer));
if (nsnull != viewer)
{
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
NS_ENSURE_SUCCESS(viewerFile->Print(), NS_ERROR_FAILURE);
}
}
return NS_OK;
}
// NO LONGER CALLED Global JS method goQuitApplication() is called instead
NS_IMETHODIMP
nsEditorShell::Exit()

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

@ -24,6 +24,8 @@
#include "nsCRT.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsIContentViewerContainer.h"
#include "nsIDocumentViewer.h"
#include "nsIImageGroup.h"
@ -54,6 +56,9 @@
#include "nsIPageSequenceFrame.h"
#include "nsIURL.h"
#include "nsIWebShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestor.h"
@ -71,6 +76,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
#endif
class DocumentViewerImpl : public nsIDocumentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile,
public nsIMarkupDocumentViewer,
public nsIImageGroupObserver
{
public:
@ -97,8 +105,6 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD Print(void);
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext);
NS_IMETHOD SetEnableRendering(PRBool aOn);
NS_IMETHOD GetEnableRendering(PRBool* aResult);
@ -110,6 +116,15 @@ public:
NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext,
nsIDocumentViewer*& aResult);
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
// nsIContentViewerFile
NS_DECL_NSICONTENTVIEWERFILE
// nsIMarkupDocumentViewer
NS_DECL_NSIMARKUPDOCUMENTVIEWER
// nsIImageGroupObserver interface...
virtual void Notify(nsIImageGroup *aImageGroup,
nsImageGroupNotification aNotificationType);
@ -166,6 +181,17 @@ protected:
nsIViewManager *mPrintVM;
nsIView *mPrintView;
// document management data
// these items are specific to markup documents (html and xml)
// may consider splitting these out into a subclass
PRBool mAllowPlugins;
PRPackedBool mIsFrame;
/* character set member data */
nsString mDefaultCharacterSet;
nsString mHintCharset;
nsCharsetSource mHintCharsetSource;
nsString mForceCharacterSet;
};
// Class IDs
@ -213,6 +239,11 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
: mPresContext(dont_QueryInterface(aPresContext))
{
NS_INIT_REFCNT();
mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized;
mForceCharacterSet = "";
mAllowPlugins = PR_TRUE;
mIsFrame = PR_FALSE;
}
// ISupports implementation...
@ -238,6 +269,12 @@ DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMarkupDocumentViewer::GetIID())) {
nsIMarkupDocumentViewer* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsIContentViewer* tmp1 = this;
nsISupports* tmp2 = tmp1;
@ -509,194 +546,31 @@ DocumentViewerImpl::Hide(void)
return NS_OK;
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::Print(void)
{
nsCOMPtr<nsIWebShell> webContainer;
nsCOMPtr<nsIDeviceContextSpecFactory> factory;
PRInt32 width,height;
nsCOMPtr<nsIPref> prefs;
nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,
nsnull,
kIDeviceContextSpecFactoryIID,
(void **)getter_AddRefs(factory));
if (factory) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
#endif
nsIDeviceContextSpec *devspec = nsnull;
nsCOMPtr<nsIDeviceContext> dx;
mPrintDC = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
if (nsnull != devspec) {
mPresContext->GetDeviceContext(getter_AddRefs(dx));
nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(devspec);
// Get the webshell for this documentviewer
webContainer = do_QueryInterface(mContainer);
if(webContainer) {
// load the document and do the initial reflow on the entire document
rv = NS_NewPrintContext(&mPrintPC);
if(NS_FAILED(rv)){
return rv;
}
mPrintDC->GetDeviceSurfaceDimensions(width,height);
mPresContext->GetPrefs(getter_AddRefs(prefs));
mPrintPC->Init(mPrintDC,prefs);
CreateStyleSet(mDocument,&mPrintSS);
rv = NS_NewPresShell(&mPrintPS);
if(NS_FAILED(rv)){
return rv;
}
rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM);
if(NS_FAILED(rv)) {
return rv;
}
rv = mPrintVM->Init(mPrintDC);
if(NS_FAILED(rv)) {
return rv;
}
rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView);
if(NS_FAILED(rv)) {
return rv;
}
nsRect tbounds = nsRect(0,0,width,height);
rv = mPrintView->Init(mPrintVM,tbounds,nsnull);
if(NS_FAILED(rv)) {
return rv;
}
// setup hierarchical relationship in view manager
mPrintVM->SetRootView(mPrintView);
mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);
nsCOMPtr<nsIImageGroup> imageGroup;
mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));
if (imageGroup) {
imageGroup->AddObserver(this);
}
mPrintPS->InitialReflow(width,height);
#ifdef DEBUG_dcone
float a1,a2;
PRInt32 i1,i2;
printf("CRITICAL PRINTING INFORMATION\n");
printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);
// DEVICE CONTEXT INFORMATION from PresContext
printf("DeviceContext of Presentation Context(%x)\n",dx);
dx->GetDevUnitsToTwips(a1);
dx->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
dx->GetAppUnitsToDevUnits(a1);
dx->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
dx->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
dx->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
dx->GetZoom(a1);
printf(" Zoom = %f\n",a1);
dx->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
dx->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
// DEVICE CONTEXT INFORMATION
printf("DeviceContext created for print(%x)\n",mPrintDC);
mPrintDC->GetDevUnitsToTwips(a1);
mPrintDC->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
mPrintDC->GetAppUnitsToDevUnits(a1);
mPrintDC->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
mPrintDC->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
mPrintDC->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
mPrintDC->GetZoom(a1);
printf(" Zoom = %f\n",a1);
mPrintDC->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
#endif
//
// The mIsPrinting flag is set when the ImageGroup observer is
// notified that images must be loaded as a result of the
// InitialReflow...
//
if(!mIsPrinting){
DocumentReadyForPrinting();
#ifdef DEBUG_dcone
printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
} else {
// use the observer mechanism to finish the printing
#ifdef DEBUG_dcone
printf("PRINTING OBSERVER STARTED\n");
#endif
}
}
}
}
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext)
{
nsCOMPtr<nsIStyleSet> ss;
nsCOMPtr<nsIPref> prefs;
nsCOMPtr<nsIViewManager> vm;
PRInt32 width, height;
nsIView *view;
nsresult rv;
PRInt32 count,i;
nsIWebShell *childWebShell;
nsIContentViewer *viewer;
NS_ENSURE_ARG_POINTER(aParent);
NS_ENSURE_ARG_POINTER(aDContext);
nsCOMPtr<nsIStyleSet> ss;
nsCOMPtr<nsIPref> prefs;
nsCOMPtr<nsIViewManager> vm;
PRInt32 width, height;
nsIView *view;
nsresult rv;
PRInt32 count,i;
nsCOMPtr<nsIWebShell> childWebShell;
nsCOMPtr<nsIContentViewer> viewer;
aParent->GetChildCount(count);
if(count> 0) {
for(i=0;i<count;i++) {
aParent->ChildAt(i,childWebShell);
childWebShell->GetContentViewer(&viewer);
viewer->PrintContent(childWebShell,aDContext);
NS_RELEASE(childWebShell);
NS_RELEASE(viewer);
aParent->ChildAt(i, *(getter_AddRefs(childWebShell)));
childWebShell->GetContentViewer(getter_AddRefs(viewer));
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE);
}
}
} else {
aDContext->BeginDocument();
@ -1025,7 +899,8 @@ void DocumentViewerImpl::DocumentReadyForPrinting()
//
// Send the document to the printer...
//
PrintContent(webContainer,mPrintDC);
nsresult rv = PrintContent(webContainer, mPrintDC);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent");
// printing is complete, clean up now
mIsPrinting = PR_FALSE;
@ -1039,3 +914,590 @@ void DocumentViewerImpl::DocumentReadyForPrinting()
}
}
/* ========================================================================================
* nsIContentViewerFile
* ======================================================================================== */
NS_IMETHODIMP DocumentViewerImpl::Search()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::ClearSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::SelectAll()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::CopySelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::CutSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::Paste()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* ========================================================================================
* nsIContentViewerEdit
* ======================================================================================== */
NS_IMETHODIMP
DocumentViewerImpl::Save()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
DocumentViewerImpl::GetSaveable(PRBool *aSaveable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::Print()
{
nsCOMPtr<nsIWebShell> webContainer;
nsCOMPtr<nsIDeviceContextSpecFactory> factory;
PRInt32 width,height;
nsCOMPtr<nsIPref> prefs;
nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,
nsnull,
kIDeviceContextSpecFactoryIID,
(void **)getter_AddRefs(factory));
if (factory) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
#endif
nsIDeviceContextSpec *devspec = nsnull;
nsCOMPtr<nsIDeviceContext> dx;
mPrintDC = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
if (nsnull != devspec) {
mPresContext->GetDeviceContext(getter_AddRefs(dx));
nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(devspec);
// Get the webshell for this documentviewer
webContainer = do_QueryInterface(mContainer);
if(webContainer) {
// load the document and do the initial reflow on the entire document
rv = NS_NewPrintContext(&mPrintPC);
if(NS_FAILED(rv)){
return rv;
}
mPrintDC->GetDeviceSurfaceDimensions(width,height);
mPresContext->GetPrefs(getter_AddRefs(prefs));
mPrintPC->Init(mPrintDC,prefs);
CreateStyleSet(mDocument,&mPrintSS);
rv = NS_NewPresShell(&mPrintPS);
if(NS_FAILED(rv)){
return rv;
}
rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM);
if(NS_FAILED(rv)) {
return rv;
}
rv = mPrintVM->Init(mPrintDC);
if(NS_FAILED(rv)) {
return rv;
}
rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView);
if(NS_FAILED(rv)) {
return rv;
}
nsRect tbounds = nsRect(0,0,width,height);
rv = mPrintView->Init(mPrintVM,tbounds,nsnull);
if(NS_FAILED(rv)) {
return rv;
}
// setup hierarchical relationship in view manager
mPrintVM->SetRootView(mPrintView);
mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);
nsCOMPtr<nsIImageGroup> imageGroup;
mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));
if (imageGroup) {
imageGroup->AddObserver(this);
}
mPrintPS->InitialReflow(width,height);
#ifdef DEBUG_dcone
float a1,a2;
PRInt32 i1,i2;
printf("CRITICAL PRINTING INFORMATION\n");
printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);
// DEVICE CONTEXT INFORMATION from PresContext
printf("DeviceContext of Presentation Context(%x)\n",dx);
dx->GetDevUnitsToTwips(a1);
dx->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
dx->GetAppUnitsToDevUnits(a1);
dx->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
dx->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
dx->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
dx->GetZoom(a1);
printf(" Zoom = %f\n",a1);
dx->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
dx->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
// DEVICE CONTEXT INFORMATION
printf("DeviceContext created for print(%x)\n",mPrintDC);
mPrintDC->GetDevUnitsToTwips(a1);
mPrintDC->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
mPrintDC->GetAppUnitsToDevUnits(a1);
mPrintDC->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
mPrintDC->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
mPrintDC->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
mPrintDC->GetZoom(a1);
printf(" Zoom = %f\n",a1);
mPrintDC->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
#endif
//
// The mIsPrinting flag is set when the ImageGroup observer is
// notified that images must be loaded as a result of the
// InitialReflow...
//
if(!mIsPrinting){
DocumentReadyForPrinting();
#ifdef DEBUG_dcone
printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
} else {
// use the observer mechanism to finish the printing
#ifdef DEBUG_dcone
printf("PRINTING OBSERVER STARTED\n");
#endif
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
DocumentViewerImpl::GetPrintable(PRBool *aPrintable)
{
NS_ENSURE_ARG_POINTER(aPrintable);
*aPrintable = PR_TRUE;
return NS_OK;
}
//*****************************************************************************
// nsIMarkupDocumentViewer
//*****************************************************************************
NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode)
{
NS_ENSURE_ARG(aNode);
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
// Get the nsIContent interface, because that's what we need to
// get the primary frame
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
// Get the primary frame
nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their
// own special little world.
NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame),
NS_ERROR_FAILURE);
// tell the pres shell to scroll to the frame
NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame,
NS_PRESSHELL_SCROLL_TOP,
NS_PRESSHELL_SCROLL_ANYWHERE),
NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins)
{
NS_ENSURE_ARG_POINTER(aAllowPlugins);
*aAllowPlugins = mAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins)
{
mAllowPlugins = aAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetIsFrame(PRBool* aIsFrame)
{
NS_ENSURE_ARG_POINTER(aIsFrame);
*aIsFrame = mIsFrame;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetIsFrame(PRBool aIsFrame)
{
mIsFrame = aIsFrame;
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aDefaultCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet)
{
NS_ENSURE_ARG_POINTER(aDefaultCharacterSet);
NS_ENSURE_STATE(mContainer);
static char *gDefCharset = nsnull; // XXX: memory leak!
if (0 == mDefaultCharacterSet.Length())
{
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
{
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIPref> prefs;
NS_ENSURE_SUCCESS(webShell->GetPrefs(*(getter_AddRefs(prefs))), NS_ERROR_FAILURE);
if(prefs)
prefs->CopyCharPref("intl.charset.default", &gDefCharset);
}
}
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
mDefaultCharacterSet = "ISO-8859-1";
else
mDefaultCharacterSet = gDefCharset;
}
*aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
// now set the default char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetDefaultCharacterSet(aDefaultCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aForceCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet)
{
NS_ENSURE_ARG_POINTER(aForceCharacterSet);
nsAutoString emptyStr;
if (mForceCharacterSet.Equals(emptyStr)) {
*aForceCharacterSet = nsnull;
}
else {
*aForceCharacterSet = mForceCharacterSet.ToNewUnicode();
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet)
{
mForceCharacterSet = aForceCharacterSet;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetForceCharacterSet(aForceCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aHintCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSet);
if(kCharsetUninitialized == mHintCharsetSource) {
*aHintCharacterSet = nsnull;
} else {
*aHintCharacterSet = mHintCharset.ToNewUnicode();
// this can't possibly be right. we can't set a value just because somebody got a related value!
//mHintCharsetSource = kCharsetUninitialized;
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
*aHintCharacterSetSource = mHintCharsetSource;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource)
{
mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetHintCharacterSetSource(aHintCharacterSetSource);
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet)
{
mHintCharset = aHintCharacterSet;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetHintCharacterSet(aHintCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: poor error checking
NS_IMETHODIMP DocumentViewerImpl::SizeToContent()
{
// XXX: for now, just call the webshell's SizeToContent
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
return webShell->SizeToContent();
}
else {
return NS_ERROR_FAILURE;
}
#ifdef NEW_DOCSHELL_INTERFACES
// get the presentation shell
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsRect shellArea;
PRInt32 width, height;
float pixelScale;
NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
NS_ERROR_FAILURE);
// so how big is it?
nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(GetPresContext(*(getter_AddRefs(presContext))),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
presContext->GetVisibleArea(shellArea);
presContext->GetTwipsToPixels(&pixelScale);
width = PRInt32((float)shellArea.width*pixelScale);
height = PRInt32((float)shellArea.height*pixelScale);
// if we're the outermost webshell for this window, size the window
/* XXX: how do we do this now?
if (mContainer)
{
nsCOMPtr<nsIBrowserWindow> browser = do_QueryInterface(mContainer);
if (browser)
{
nsCOMPtr<nsIDocShell> browserWebShell;
PRInt32 oldX, oldY, oldWidth, oldHeight,
widthDelta, heightDelta;
nsRect windowBounds;
GetBounds(oldX, oldY, oldWidth, oldHeight);
widthDelta = width - oldWidth;
heightDelta = height - oldHeight;
browser->GetWindowBounds(windowBounds);
browser->SizeWindowTo(windowBounds.width + widthDelta,
windowBounds.height + heightDelta);
}
}
*/
NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
//return NS_OK;
#endif
}

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

@ -24,6 +24,8 @@
#include "nsCRT.h"
#include "nsString.h"
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsIContentViewerContainer.h"
#include "nsIDocumentViewer.h"
#include "nsIImageGroup.h"
@ -54,6 +56,9 @@
#include "nsIPageSequenceFrame.h"
#include "nsIURL.h"
#include "nsIWebShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIInterfaceRequestor.h"
@ -71,6 +76,9 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
#endif
class DocumentViewerImpl : public nsIDocumentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile,
public nsIMarkupDocumentViewer,
public nsIImageGroupObserver
{
public:
@ -97,8 +105,6 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD Print(void);
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext);
NS_IMETHOD SetEnableRendering(PRBool aOn);
NS_IMETHOD GetEnableRendering(PRBool* aResult);
@ -110,6 +116,15 @@ public:
NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext,
nsIDocumentViewer*& aResult);
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
// nsIContentViewerFile
NS_DECL_NSICONTENTVIEWERFILE
// nsIMarkupDocumentViewer
NS_DECL_NSIMARKUPDOCUMENTVIEWER
// nsIImageGroupObserver interface...
virtual void Notify(nsIImageGroup *aImageGroup,
nsImageGroupNotification aNotificationType);
@ -166,6 +181,17 @@ protected:
nsIViewManager *mPrintVM;
nsIView *mPrintView;
// document management data
// these items are specific to markup documents (html and xml)
// may consider splitting these out into a subclass
PRBool mAllowPlugins;
PRPackedBool mIsFrame;
/* character set member data */
nsString mDefaultCharacterSet;
nsString mHintCharset;
nsCharsetSource mHintCharsetSource;
nsString mForceCharacterSet;
};
// Class IDs
@ -213,6 +239,11 @@ DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext)
: mPresContext(dont_QueryInterface(aPresContext))
{
NS_INIT_REFCNT();
mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized;
mForceCharacterSet = "";
mAllowPlugins = PR_TRUE;
mIsFrame = PR_FALSE;
}
// ISupports implementation...
@ -238,6 +269,12 @@ DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIMarkupDocumentViewer::GetIID())) {
nsIMarkupDocumentViewer* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsIContentViewer* tmp1 = this;
nsISupports* tmp2 = tmp1;
@ -509,194 +546,31 @@ DocumentViewerImpl::Hide(void)
return NS_OK;
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::Print(void)
{
nsCOMPtr<nsIWebShell> webContainer;
nsCOMPtr<nsIDeviceContextSpecFactory> factory;
PRInt32 width,height;
nsCOMPtr<nsIPref> prefs;
nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,
nsnull,
kIDeviceContextSpecFactoryIID,
(void **)getter_AddRefs(factory));
if (factory) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
#endif
nsIDeviceContextSpec *devspec = nsnull;
nsCOMPtr<nsIDeviceContext> dx;
mPrintDC = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
if (nsnull != devspec) {
mPresContext->GetDeviceContext(getter_AddRefs(dx));
nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(devspec);
// Get the webshell for this documentviewer
webContainer = do_QueryInterface(mContainer);
if(webContainer) {
// load the document and do the initial reflow on the entire document
rv = NS_NewPrintContext(&mPrintPC);
if(NS_FAILED(rv)){
return rv;
}
mPrintDC->GetDeviceSurfaceDimensions(width,height);
mPresContext->GetPrefs(getter_AddRefs(prefs));
mPrintPC->Init(mPrintDC,prefs);
CreateStyleSet(mDocument,&mPrintSS);
rv = NS_NewPresShell(&mPrintPS);
if(NS_FAILED(rv)){
return rv;
}
rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM);
if(NS_FAILED(rv)) {
return rv;
}
rv = mPrintVM->Init(mPrintDC);
if(NS_FAILED(rv)) {
return rv;
}
rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView);
if(NS_FAILED(rv)) {
return rv;
}
nsRect tbounds = nsRect(0,0,width,height);
rv = mPrintView->Init(mPrintVM,tbounds,nsnull);
if(NS_FAILED(rv)) {
return rv;
}
// setup hierarchical relationship in view manager
mPrintVM->SetRootView(mPrintView);
mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);
nsCOMPtr<nsIImageGroup> imageGroup;
mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));
if (imageGroup) {
imageGroup->AddObserver(this);
}
mPrintPS->InitialReflow(width,height);
#ifdef DEBUG_dcone
float a1,a2;
PRInt32 i1,i2;
printf("CRITICAL PRINTING INFORMATION\n");
printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);
// DEVICE CONTEXT INFORMATION from PresContext
printf("DeviceContext of Presentation Context(%x)\n",dx);
dx->GetDevUnitsToTwips(a1);
dx->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
dx->GetAppUnitsToDevUnits(a1);
dx->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
dx->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
dx->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
dx->GetZoom(a1);
printf(" Zoom = %f\n",a1);
dx->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
dx->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
// DEVICE CONTEXT INFORMATION
printf("DeviceContext created for print(%x)\n",mPrintDC);
mPrintDC->GetDevUnitsToTwips(a1);
mPrintDC->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
mPrintDC->GetAppUnitsToDevUnits(a1);
mPrintDC->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
mPrintDC->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
mPrintDC->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
mPrintDC->GetZoom(a1);
printf(" Zoom = %f\n",a1);
mPrintDC->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
#endif
//
// The mIsPrinting flag is set when the ImageGroup observer is
// notified that images must be loaded as a result of the
// InitialReflow...
//
if(!mIsPrinting){
DocumentReadyForPrinting();
#ifdef DEBUG_dcone
printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
} else {
// use the observer mechanism to finish the printing
#ifdef DEBUG_dcone
printf("PRINTING OBSERVER STARTED\n");
#endif
}
}
}
}
}
return NS_OK;
}
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext)
{
nsCOMPtr<nsIStyleSet> ss;
nsCOMPtr<nsIPref> prefs;
nsCOMPtr<nsIViewManager> vm;
PRInt32 width, height;
nsIView *view;
nsresult rv;
PRInt32 count,i;
nsIWebShell *childWebShell;
nsIContentViewer *viewer;
NS_ENSURE_ARG_POINTER(aParent);
NS_ENSURE_ARG_POINTER(aDContext);
nsCOMPtr<nsIStyleSet> ss;
nsCOMPtr<nsIPref> prefs;
nsCOMPtr<nsIViewManager> vm;
PRInt32 width, height;
nsIView *view;
nsresult rv;
PRInt32 count,i;
nsCOMPtr<nsIWebShell> childWebShell;
nsCOMPtr<nsIContentViewer> viewer;
aParent->GetChildCount(count);
if(count> 0) {
for(i=0;i<count;i++) {
aParent->ChildAt(i,childWebShell);
childWebShell->GetContentViewer(&viewer);
viewer->PrintContent(childWebShell,aDContext);
NS_RELEASE(childWebShell);
NS_RELEASE(viewer);
aParent->ChildAt(i, *(getter_AddRefs(childWebShell)));
childWebShell->GetContentViewer(getter_AddRefs(viewer));
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell,aDContext), NS_ERROR_FAILURE);
}
}
} else {
aDContext->BeginDocument();
@ -1025,7 +899,8 @@ void DocumentViewerImpl::DocumentReadyForPrinting()
//
// Send the document to the printer...
//
PrintContent(webContainer,mPrintDC);
nsresult rv = PrintContent(webContainer, mPrintDC);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent");
// printing is complete, clean up now
mIsPrinting = PR_FALSE;
@ -1039,3 +914,590 @@ void DocumentViewerImpl::DocumentReadyForPrinting()
}
}
/* ========================================================================================
* nsIContentViewerFile
* ======================================================================================== */
NS_IMETHODIMP DocumentViewerImpl::Search()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::ClearSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::SelectAll()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::CopySelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::CutSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::Paste()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* ========================================================================================
* nsIContentViewerEdit
* ======================================================================================== */
NS_IMETHODIMP
DocumentViewerImpl::Save()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
DocumentViewerImpl::GetSaveable(PRBool *aSaveable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
static NS_DEFINE_IID(kIDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
/** ---------------------------------------------------
* See documentation above in the DocumentViewerImpl class definition
* @update 07/09/99 dwc
*/
NS_IMETHODIMP
DocumentViewerImpl::Print()
{
nsCOMPtr<nsIWebShell> webContainer;
nsCOMPtr<nsIDeviceContextSpecFactory> factory;
PRInt32 width,height;
nsCOMPtr<nsIPref> prefs;
nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID,
nsnull,
kIDeviceContextSpecFactoryIID,
(void **)getter_AddRefs(factory));
if (factory) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
#endif
nsIDeviceContextSpec *devspec = nsnull;
nsCOMPtr<nsIDeviceContext> dx;
mPrintDC = nsnull;
factory->CreateDeviceContextSpec(nsnull, devspec, PR_FALSE);
if (nsnull != devspec) {
mPresContext->GetDeviceContext(getter_AddRefs(dx));
nsresult rv = dx->GetDeviceContextFor(devspec, mPrintDC);
if (NS_SUCCEEDED(rv)) {
NS_RELEASE(devspec);
// Get the webshell for this documentviewer
webContainer = do_QueryInterface(mContainer);
if(webContainer) {
// load the document and do the initial reflow on the entire document
rv = NS_NewPrintContext(&mPrintPC);
if(NS_FAILED(rv)){
return rv;
}
mPrintDC->GetDeviceSurfaceDimensions(width,height);
mPresContext->GetPrefs(getter_AddRefs(prefs));
mPrintPC->Init(mPrintDC,prefs);
CreateStyleSet(mDocument,&mPrintSS);
rv = NS_NewPresShell(&mPrintPS);
if(NS_FAILED(rv)){
return rv;
}
rv = nsComponentManager::CreateInstance(kViewManagerCID,nsnull,kIViewManagerIID,(void**)&mPrintVM);
if(NS_FAILED(rv)) {
return rv;
}
rv = mPrintVM->Init(mPrintDC);
if(NS_FAILED(rv)) {
return rv;
}
rv = nsComponentManager::CreateInstance(kViewCID,nsnull,kIViewIID,(void**)&mPrintView);
if(NS_FAILED(rv)) {
return rv;
}
nsRect tbounds = nsRect(0,0,width,height);
rv = mPrintView->Init(mPrintVM,tbounds,nsnull);
if(NS_FAILED(rv)) {
return rv;
}
// setup hierarchical relationship in view manager
mPrintVM->SetRootView(mPrintView);
mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS);
nsCOMPtr<nsIImageGroup> imageGroup;
mPrintPC->GetImageGroup(getter_AddRefs(imageGroup));
if (imageGroup) {
imageGroup->AddObserver(this);
}
mPrintPS->InitialReflow(width,height);
#ifdef DEBUG_dcone
float a1,a2;
PRInt32 i1,i2;
printf("CRITICAL PRINTING INFORMATION\n");
printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n",
mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView);
// DEVICE CONTEXT INFORMATION from PresContext
printf("DeviceContext of Presentation Context(%x)\n",dx);
dx->GetDevUnitsToTwips(a1);
dx->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
dx->GetAppUnitsToDevUnits(a1);
dx->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
dx->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
dx->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
dx->GetZoom(a1);
printf(" Zoom = %f\n",a1);
dx->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
dx->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
// DEVICE CONTEXT INFORMATION
printf("DeviceContext created for print(%x)\n",mPrintDC);
mPrintDC->GetDevUnitsToTwips(a1);
mPrintDC->GetTwipsToDevUnits(a2);
printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2);
mPrintDC->GetAppUnitsToDevUnits(a1);
mPrintDC->GetDevUnitsToAppUnits(a2);
printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2);
mPrintDC->GetCanonicalPixelScale(a1);
printf(" GetCanonicalPixelScale = %f\n",a1);
mPrintDC->GetScrollBarDimensions(a1, a2);
printf(" ScrollBar x = %f y = %f\n",a1,a2);
mPrintDC->GetZoom(a1);
printf(" Zoom = %f\n",a1);
mPrintDC->GetDepth((PRUint32&)i1);
printf(" Depth = %d\n",i1);
mPrintDC->GetDeviceSurfaceDimensions(i1,i2);
printf(" DeviceDimension w = %d h = %d\n",i1,i2);
#endif
//
// The mIsPrinting flag is set when the ImageGroup observer is
// notified that images must be loaded as a result of the
// InitialReflow...
//
if(!mIsPrinting){
DocumentReadyForPrinting();
#ifdef DEBUG_dcone
printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n");
#endif
} else {
// use the observer mechanism to finish the printing
#ifdef DEBUG_dcone
printf("PRINTING OBSERVER STARTED\n");
#endif
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP
DocumentViewerImpl::GetPrintable(PRBool *aPrintable)
{
NS_ENSURE_ARG_POINTER(aPrintable);
*aPrintable = PR_TRUE;
return NS_OK;
}
//*****************************************************************************
// nsIMarkupDocumentViewer
//*****************************************************************************
NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode)
{
NS_ENSURE_ARG(aNode);
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
// Get the nsIContent interface, because that's what we need to
// get the primary frame
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
// Get the primary frame
nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their
// own special little world.
NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame),
NS_ERROR_FAILURE);
// tell the pres shell to scroll to the frame
NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame,
NS_PRESSHELL_SCROLL_TOP,
NS_PRESSHELL_SCROLL_ANYWHERE),
NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins)
{
NS_ENSURE_ARG_POINTER(aAllowPlugins);
*aAllowPlugins = mAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins)
{
mAllowPlugins = aAllowPlugins;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetIsFrame(PRBool* aIsFrame)
{
NS_ENSURE_ARG_POINTER(aIsFrame);
*aIsFrame = mIsFrame;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetIsFrame(PRBool aIsFrame)
{
mIsFrame = aIsFrame;
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aDefaultCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet)
{
NS_ENSURE_ARG_POINTER(aDefaultCharacterSet);
NS_ENSURE_STATE(mContainer);
static char *gDefCharset = nsnull; // XXX: memory leak!
if (0 == mDefaultCharacterSet.Length())
{
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
{
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIPref> prefs;
NS_ENSURE_SUCCESS(webShell->GetPrefs(*(getter_AddRefs(prefs))), NS_ERROR_FAILURE);
if(prefs)
prefs->CopyCharPref("intl.charset.default", &gDefCharset);
}
}
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
mDefaultCharacterSet = "ISO-8859-1";
else
mDefaultCharacterSet = gDefCharset;
}
*aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode();
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet
// now set the default char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetDefaultCharacterSet(aDefaultCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aForceCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet)
{
NS_ENSURE_ARG_POINTER(aForceCharacterSet);
nsAutoString emptyStr;
if (mForceCharacterSet.Equals(emptyStr)) {
*aForceCharacterSet = nsnull;
}
else {
*aForceCharacterSet = mForceCharacterSet.ToNewUnicode();
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet)
{
mForceCharacterSet = aForceCharacterSet;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetForceCharacterSet(aForceCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: SEMANTIC CHANGE!
// returns a copy of the string. Caller is responsible for freeing result
// using Recycle(aHintCharacterSet)
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSet);
if(kCharsetUninitialized == mHintCharsetSource) {
*aHintCharacterSet = nsnull;
} else {
*aHintCharacterSet = mHintCharset.ToNewUnicode();
// this can't possibly be right. we can't set a value just because somebody got a related value!
//mHintCharsetSource = kCharsetUninitialized;
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource)
{
NS_ENSURE_ARG_POINTER(aHintCharacterSetSource);
*aHintCharacterSetSource = mHintCharsetSource;
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource)
{
mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetHintCharacterSetSource(aHintCharacterSetSource);
}
}
}
}
}
return NS_OK;
}
NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet)
{
mHintCharset = aHintCharacterSet;
// now set the force char set on all children of mContainer
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
nsCOMPtr<nsIWebShell> childWebShell;
PRInt32 i;
PRInt32 n;
webShell->GetChildCount(n);
for (i=0; i < n; i++)
{
webShell->ChildAt(i, *(getter_AddRefs(childWebShell)));
NS_WARN_IF_FALSE(childWebShell, "null child in docshell");
if (childWebShell)
{
nsCOMPtr<nsIContentViewer> childCV;
childWebShell->GetContentViewer(getter_AddRefs(childCV));
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
markupCV->SetHintCharacterSet(aHintCharacterSet);
}
}
}
}
}
return NS_OK;
}
// XXX: poor error checking
NS_IMETHODIMP DocumentViewerImpl::SizeToContent()
{
// XXX: for now, just call the webshell's SizeToContent
nsCOMPtr<nsIWebShell> webShell;
webShell = do_QueryInterface(mContainer);
if (webShell)
{
return webShell->SizeToContent();
}
else {
return NS_ERROR_FAILURE;
}
#ifdef NEW_DOCSHELL_INTERFACES
// get the presentation shell
nsCOMPtr<nsIPresShell> presShell;
NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsRect shellArea;
PRInt32 width, height;
float pixelScale;
NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE),
NS_ERROR_FAILURE);
// so how big is it?
nsCOMPtr<nsIPresContext> presContext;
NS_ENSURE_SUCCESS(GetPresContext(*(getter_AddRefs(presContext))),
NS_ERROR_FAILURE);
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
presContext->GetVisibleArea(shellArea);
presContext->GetTwipsToPixels(&pixelScale);
width = PRInt32((float)shellArea.width*pixelScale);
height = PRInt32((float)shellArea.height*pixelScale);
// if we're the outermost webshell for this window, size the window
/* XXX: how do we do this now?
if (mContainer)
{
nsCOMPtr<nsIBrowserWindow> browser = do_QueryInterface(mContainer);
if (browser)
{
nsCOMPtr<nsIDocShell> browserWebShell;
PRInt32 oldX, oldY, oldWidth, oldHeight,
widthDelta, heightDelta;
nsRect windowBounds;
GetBounds(oldX, oldY, oldWidth, oldHeight);
widthDelta = width - oldWidth;
heightDelta = height - oldHeight;
browser->GetWindowBounds(windowBounds);
browser->SizeWindowTo(windowBounds.width + widthDelta,
windowBounds.height + heightDelta);
}
}
*/
NS_ASSERTION(PR_FALSE, "NOT YET IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
//return NS_OK;
#endif
}

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

@ -33,6 +33,8 @@
#include "nsWidgetsCID.h"
#include "nsILinkHandler.h"
#include "nsIWebShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsIBrowserWindow.h"
#include "nsIContent.h"
#include "nsIDocument.h"
@ -110,7 +112,9 @@ private:
PluginViewerImpl *mViewer; //we do not addref this...
};
class PluginViewerImpl : public nsIContentViewer
class PluginViewerImpl : public nsIContentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile
{
public:
PluginViewerImpl(const char* aCommand);
@ -136,11 +140,15 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD Print();
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext);
NS_IMETHOD SetEnableRendering(PRBool aOn);
NS_IMETHOD GetEnableRendering(PRBool* aResult);
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
// nsIContentViewerFile
NS_DECL_NSICONTENTVIEWERFILE
virtual ~PluginViewerImpl();
nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds,
@ -221,8 +229,9 @@ PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsISupports* tmp = this;
*aInstancePtr = (void*)tmp;
nsIContentViewer* tmp1 = this;
nsISupports* tmp2 = tmp1;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
@ -489,23 +498,6 @@ PluginViewerImpl::Hide()
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::Print(void)
{
// need to call the plugin from here somehow
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext)
{
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::SetEnableRendering(PRBool aOn)
{
@ -541,6 +533,114 @@ nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument)
return NS_OK;
}
/* ========================================================================================
* nsIContentViewerFile
* ======================================================================================== */
NS_IMETHODIMP PluginViewerImpl::Search()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::ClearSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::SelectAll()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::CopySelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::CutSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::Paste()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* ========================================================================================
* nsIContentViewerEdit
* ======================================================================================== */
NS_IMETHODIMP
PluginViewerImpl::Save()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PluginViewerImpl::GetSaveable(PRBool *aSaveable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PluginViewerImpl::Print()
{
return NS_OK; // XXX: hey, plug in guys! implement me!
}
NS_IMETHODIMP
PluginViewerImpl::GetPrintable(PRBool *aPrintable)
{
NS_ENSURE_ARG_POINTER(aPrintable);
*aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me!
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext)
{
NS_ENSURE_ARG_POINTER(aParent);
NS_ENSURE_ARG_POINTER(aDContext);
return NS_OK;
}
//----------------------------------------------------------------------
PluginListener::PluginListener(PluginViewerImpl* aViewer)

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

@ -24,6 +24,8 @@
#include "nsHTMLContainerFrame.h"
#include "nsIHTMLContent.h"
#include "nsIWebShell.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsHTMLIIDs.h"
@ -692,8 +694,6 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext,
nsCompatibility mode;
aPresContext.GetCompatibilityMode(&mode);
mWebShell->SetScrolling(GetScrolling(content, mode));
mWebShell->SetIsFrame(PR_TRUE);
nsString frameName;
if (GetName(content, frameName)) {
mWebShell->SetName(frameName.GetUnicode());
@ -875,6 +875,18 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext& aPresContext,
TempMakeAbsURL(content, url, absURL);
rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data
if (NS_SUCCEEDED(rv))
{ // tell the content viewer that it's an HTML frame
nsCOMPtr<nsIContentViewer> cv;
mWebShell->GetContentViewer(getter_AddRefs(cv));
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV) {
muCV->SetIsFrame(PR_TRUE);
}
}
}
}
} else {
mCreatingViewer = PR_TRUE;

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

@ -24,6 +24,8 @@
#include "nsHTMLContainerFrame.h"
#include "nsIHTMLContent.h"
#include "nsIWebShell.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIPresContext.h"
#include "nsIPresShell.h"
#include "nsHTMLIIDs.h"
@ -692,8 +694,6 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext& aPresContext,
nsCompatibility mode;
aPresContext.GetCompatibilityMode(&mode);
mWebShell->SetScrolling(GetScrolling(content, mode));
mWebShell->SetIsFrame(PR_TRUE);
nsString frameName;
if (GetName(content, frameName)) {
mWebShell->SetName(frameName.GetUnicode());
@ -875,6 +875,18 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext& aPresContext,
TempMakeAbsURL(content, url, absURL);
rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data
if (NS_SUCCEEDED(rv))
{ // tell the content viewer that it's an HTML frame
nsCOMPtr<nsIContentViewer> cv;
mWebShell->GetContentViewer(getter_AddRefs(cv));
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV) {
muCV->SetIsFrame(PR_TRUE);
}
}
}
}
} else {
mCreatingViewer = PR_TRUE;

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

@ -33,6 +33,7 @@
#include "nsIPresContext.h"
#include "nsIViewManager.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsHTMLTokens.h"
#include "nsHTMLEntities.h"
#include "nsCRT.h"
@ -2694,7 +2695,16 @@ HTMLContentSink::StartLayout()
}
else if (mBody) {
PRBool isFrameDoc = PR_FALSE;
mWebShell->GetIsFrame(isFrameDoc);
nsCOMPtr<nsIContentViewer> cv;
mWebShell->GetContentViewer(getter_AddRefs(cv));
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV)
{
muCV->GetIsFrame(&isFrameDoc);
}
}
// a <frame> webshell will have its scrolling set by the parent nsFramesetFrame.
// a <body> webshell is reset here just for safety.
if (!isFrameDoc) {

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

@ -49,6 +49,9 @@
#include "nsIIOService.h"
#include "nsIURL.h"
#include "nsNeckoUtil.h"
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIWebShell.h"
#include "nsIWebShellServices.h"
#include "nsIDocumentLoader.h"
@ -392,7 +395,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
nsIWebShell* webShell;
nsCOMPtr<nsIWebShell> webShell;
nsAutoString charset = "ISO-8859-1"; // fallback value in case webShell return error
nsCharsetSource charsetSource = kCharsetFromWeakDocTypeDefault;
@ -503,7 +506,7 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
if (NS_OK == rv) {
nsIHTMLContentSink* sink;
const PRUnichar* requestCharset = nsnull;
PRUnichar* requestCharset = nsnull;
nsCharsetSource requestCharsetSource = kCharsetUninitialized;
nsIParserFilter *cdetflt = nsnull;
@ -513,104 +516,123 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
rv = NS_New_HTML_ContentSinkStream(&sink,&outString,0);
#else
NS_PRECONDITION(nsnull != aContainer, "No content viewer container");
aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);
aContainer->QueryInterface(kIWebShellIID, getter_AddRefs(webShell));
rv = NS_NewHTMLContentSink(&sink, this, aURL, webShell);
if (NS_SUCCEEDED(rv)) {
if(kCharsetFromUserDefault > charsetSource) {
const PRUnichar* defaultCharsetFromWebShell = NULL;
rv = webShell->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
if(NS_SUCCEEDED(rv)) {
charset = defaultCharsetFromWebShell;
charsetSource = kCharsetFromUserDefault;
}
}
// for html, we need to find out the Meta tag from the hint.
rv = webShell->GetCharacterSetHint(&requestCharset, &requestCharsetSource);
if(NS_SUCCEEDED(rv)) {
if(requestCharsetSource > charsetSource)
{
charsetSource = requestCharsetSource;
charset = requestCharset;
}
}
if(kCharsetFromPreviousLoading > charsetSource)
{
const PRUnichar* forceCharsetFromWebShell = NULL;
rv = webShell->GetForceCharacterSet(&forceCharsetFromWebShell);
if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell)) {
charset = forceCharsetFromWebShell;
//TODO: we should define appropriate constant for force charset
charsetSource = kCharsetFromPreviousLoading;
}
}
nsresult rv_detect = NS_OK;
if(! gInitDetector)
{
nsIPref* pref = nsnull;
if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref)
{
char* detector_name = nsnull;
if(NS_SUCCEEDED(
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIMarkupDocumentViewer> muCV;
nsCOMPtr<nsIContentViewer> cv;
webShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
muCV = do_QueryInterface(cv);
}
if(kCharsetFromUserDefault > charsetSource)
{
PRUnichar* defaultCharsetFromWebShell = NULL;
if (muCV) {
rv = muCV->GetDefaultCharacterSet(&defaultCharsetFromWebShell);
}
if(NS_SUCCEEDED(rv)) {
charset = defaultCharsetFromWebShell;
Recycle(defaultCharsetFromWebShell);
charsetSource = kCharsetFromUserDefault;
}
// for html, we need to find out the Meta tag from the hint.
if (muCV) {
rv = muCV->GetHintCharacterSet(&requestCharset);
if(NS_SUCCEEDED(rv)) {
rv = muCV->GetHintCharacterSetSource((PRInt32*)(&requestCharsetSource));
}
}
if(NS_SUCCEEDED(rv))
{
if(requestCharsetSource > charsetSource)
{
charsetSource = requestCharsetSource;
charset = requestCharset;
Recycle(requestCharset);
}
}
if(kCharsetFromPreviousLoading > charsetSource)
{
PRUnichar* forceCharsetFromWebShell = NULL;
if (muCV) {
rv = muCV->GetForceCharacterSet(&forceCharsetFromWebShell);
}
if(NS_SUCCEEDED(rv) && (nsnull != forceCharsetFromWebShell))
{
charset = forceCharsetFromWebShell;
Recycle(forceCharsetFromWebShell);
//TODO: we should define appropriate constant for force charset
charsetSource = kCharsetFromPreviousLoading;
}
}
nsresult rv_detect = NS_OK;
if(! gInitDetector)
{
nsIPref* pref = nsnull;
if(NS_SUCCEEDED(webShell->GetPrefs(pref)) && pref)
{
char* detector_name = nsnull;
if(NS_SUCCEEDED(
rv_detect = pref->CopyCharPref("intl.charset.detector",
&detector_name)))
{
PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX);
PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX);
gPlugDetector = PR_TRUE;
PR_FREEIF(detector_name);
}
pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull);
}
NS_IF_RELEASE(pref);
gInitDetector = PR_TRUE;
}
{
PL_strncpy(g_detector_progid, NS_CHARSET_DETECTOR_PROGID_BASE,DETECTOR_PROGID_MAX);
PL_strncat(g_detector_progid, detector_name,DETECTOR_PROGID_MAX);
gPlugDetector = PR_TRUE;
PR_FREEIF(detector_name);
}
pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, nsnull);
}
NS_IF_RELEASE(pref);
gInitDetector = PR_TRUE;
}
if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector)
{
// we could do charset detection
nsICharsetDetector *cdet = nsnull;
nsIWebShellServices *wss = nsnull;
nsICharsetDetectionAdaptor *adp = nsnull;
if((kCharsetFromAutoDetection > charsetSource ) && gPlugDetector)
{
// we could do charset detection
nsICharsetDetector *cdet = nsnull;
nsIWebShellServices *wss = nsnull;
nsICharsetDetectionAdaptor *adp = nsnull;
if(NS_SUCCEEDED( rv_detect =
if(NS_SUCCEEDED( rv_detect =
nsComponentManager::CreateInstance(g_detector_progid, nsnull,
nsICharsetDetector::GetIID(), (void**)&cdet)))
{
if(NS_SUCCEEDED( rv_detect =
{
if(NS_SUCCEEDED( rv_detect =
nsComponentManager::CreateInstance(
NS_CHARSET_DETECTION_ADAPTOR_PROGID, nsnull,
kIParserFilterIID, (void**)&cdetflt)))
{
if(cdetflt &&
{
if(cdetflt &&
NS_SUCCEEDED( rv_detect=
cdetflt->QueryInterface(
nsICharsetDetectionAdaptor::GetIID(),(void**) &adp)))
{
if( NS_SUCCEEDED( rv_detect=
{
if( NS_SUCCEEDED( rv_detect=
webShell->QueryInterface(
nsIWebShellServices::GetIID(),(void**) &wss)))
{
rv_detect = adp->Init(wss, cdet, aCommand);
}
}
{
rv_detect = adp->Init(wss, cdet, aCommand);
}
}
} else {
// IF we cannot create the detector, don't bother to
// create one next time.
gPlugDetector = PR_FALSE;
}
NS_IF_RELEASE(wss);
NS_IF_RELEASE(cdet);
NS_IF_RELEASE(adp);
// NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter
}
}
}
else
{
// IF we cannot create the detector, don't bother to
// create one next time.
gPlugDetector = PR_FALSE;
}
NS_IF_RELEASE(wss);
NS_IF_RELEASE(cdet);
NS_IF_RELEASE(adp);
// NO NS_IF_RELEASE(cdetflt); here, do it after mParser->SetParserFilter
}
}
}
NS_IF_RELEASE(webShell);
#endif
if (NS_SUCCEEDED(rv)) {

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

@ -29,7 +29,10 @@
#include "nsIXMLContentSink.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContentViewerContainer.h"
#include "nsIContentViewer.h"
#include "nsIWebShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIDocumentLoader.h"
#include "nsIHTMLContent.h"
#include "nsHTMLParts.h"
@ -263,20 +266,31 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
rv = aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);
if(NS_SUCCEEDED(rv) && (nsnull != webShell)) {
if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source
const PRUnichar* hintCharset = nsnull;
nsCharsetSource hintSource = kCharsetUninitialized;
rv = webShell->GetCharacterSetHint(&hintCharset, &hintSource);
if(NS_SUCCEEDED(rv)) {
if(hintSource > charsetSource) {
charset = hintCharset;
charsetSource = hintSource;
nsCOMPtr<nsIContentViewer> cv;
webShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {
nsCOMPtr<nsIMarkupDocumentViewer> muCV = do_QueryInterface(cv);
if (muCV) {
if(0 == nsCRT::strcmp("view-source", aCommand)) { // only do this for view-source
PRUnichar* hintCharset = nsnull;
nsCharsetSource hintSource = kCharsetUninitialized;
rv = muCV->GetHintCharacterSet(&hintCharset);
if(NS_SUCCEEDED(rv)) {
rv = muCV->GetHintCharacterSetSource((PRInt32 *)(&hintSource));
if(NS_SUCCEEDED(rv)) {
if(hintSource > charsetSource) {
charset = hintCharset;
Recycle(hintCharset);
charsetSource = hintSource;
}
}
}
}
if(NS_SUCCEEDED(rv))
rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell);
NS_IF_RELEASE(webShell);
}
}
}
}
if(NS_SUCCEEDED(rv))
rv = NS_NewXMLContentSink(&sink, this, aUrl, webShell);
NS_IF_RELEASE(webShell);
}
if (NS_OK == rv) {

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

@ -33,6 +33,8 @@
#include "nsWidgetsCID.h"
#include "nsILinkHandler.h"
#include "nsIWebShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsIBrowserWindow.h"
#include "nsIContent.h"
#include "nsIDocument.h"
@ -110,7 +112,9 @@ private:
PluginViewerImpl *mViewer; //we do not addref this...
};
class PluginViewerImpl : public nsIContentViewer
class PluginViewerImpl : public nsIContentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile
{
public:
PluginViewerImpl(const char* aCommand);
@ -136,11 +140,15 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD Print();
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext);
NS_IMETHOD SetEnableRendering(PRBool aOn);
NS_IMETHOD GetEnableRendering(PRBool* aResult);
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
// nsIContentViewerFile
NS_DECL_NSICONTENTVIEWERFILE
virtual ~PluginViewerImpl();
nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds,
@ -221,8 +229,9 @@ PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsISupports* tmp = this;
*aInstancePtr = (void*)tmp;
nsIContentViewer* tmp1 = this;
nsISupports* tmp2 = tmp1;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
@ -489,23 +498,6 @@ PluginViewerImpl::Hide()
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::Print(void)
{
// need to call the plugin from here somehow
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext)
{
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::SetEnableRendering(PRBool aOn)
{
@ -541,6 +533,114 @@ nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument)
return NS_OK;
}
/* ========================================================================================
* nsIContentViewerFile
* ======================================================================================== */
NS_IMETHODIMP PluginViewerImpl::Search()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::ClearSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::SelectAll()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::CopySelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::CutSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::Paste()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* ========================================================================================
* nsIContentViewerEdit
* ======================================================================================== */
NS_IMETHODIMP
PluginViewerImpl::Save()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PluginViewerImpl::GetSaveable(PRBool *aSaveable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PluginViewerImpl::Print()
{
return NS_OK; // XXX: hey, plug in guys! implement me!
}
NS_IMETHODIMP
PluginViewerImpl::GetPrintable(PRBool *aPrintable)
{
NS_ENSURE_ARG_POINTER(aPrintable);
*aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me!
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext)
{
NS_ENSURE_ARG_POINTER(aParent);
NS_ENSURE_ARG_POINTER(aDContext);
return NS_OK;
}
//----------------------------------------------------------------------
PluginListener::PluginListener(PluginViewerImpl* aViewer)

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

@ -33,6 +33,8 @@
#include "nsWidgetsCID.h"
#include "nsILinkHandler.h"
#include "nsIWebShell.h"
#include "nsIContentViewerEdit.h"
#include "nsIContentViewerFile.h"
#include "nsIBrowserWindow.h"
#include "nsIContent.h"
#include "nsIDocument.h"
@ -110,7 +112,9 @@ private:
PluginViewerImpl *mViewer; //we do not addref this...
};
class PluginViewerImpl : public nsIContentViewer
class PluginViewerImpl : public nsIContentViewer,
public nsIContentViewerEdit,
public nsIContentViewerFile
{
public:
PluginViewerImpl(const char* aCommand);
@ -136,11 +140,15 @@ public:
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
NS_IMETHOD Show();
NS_IMETHOD Hide();
NS_IMETHOD Print();
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext);
NS_IMETHOD SetEnableRendering(PRBool aOn);
NS_IMETHOD GetEnableRendering(PRBool* aResult);
// nsIContentViewerEdit
NS_DECL_NSICONTENTVIEWEREDIT
// nsIContentViewerFile
NS_DECL_NSICONTENTVIEWERFILE
virtual ~PluginViewerImpl();
nsresult CreatePlugin(nsIPluginHost* aHost, const nsRect& aBounds,
@ -221,8 +229,9 @@ PluginViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsISupports* tmp = this;
*aInstancePtr = (void*)tmp;
nsIContentViewer* tmp1 = this;
nsISupports* tmp2 = tmp1;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
@ -489,23 +498,6 @@ PluginViewerImpl::Hide()
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::Print(void)
{
// need to call the plugin from here somehow
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext)
{
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::SetEnableRendering(PRBool aOn)
{
@ -541,6 +533,114 @@ nsresult PluginViewerImpl::GetDocument(nsIDocument* *aDocument)
return NS_OK;
}
/* ========================================================================================
* nsIContentViewerFile
* ======================================================================================== */
NS_IMETHODIMP PluginViewerImpl::Search()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetSearchable(PRBool *aSearchable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::ClearSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::SelectAll()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::CopySelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetCopyable(PRBool *aCopyable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::CutSelection()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetCutable(PRBool *aCutable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::Paste()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP PluginViewerImpl::GetPasteable(PRBool *aPasteable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* ========================================================================================
* nsIContentViewerEdit
* ======================================================================================== */
NS_IMETHODIMP
PluginViewerImpl::Save()
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PluginViewerImpl::GetSaveable(PRBool *aSaveable)
{
NS_ASSERTION(0, "NOT IMPLEMENTED");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PluginViewerImpl::Print()
{
return NS_OK; // XXX: hey, plug in guys! implement me!
}
NS_IMETHODIMP
PluginViewerImpl::GetPrintable(PRBool *aPrintable)
{
NS_ENSURE_ARG_POINTER(aPrintable);
*aPrintable = PR_FALSE; // XXX: hey, plug in guys! implement me!
return NS_OK;
}
NS_IMETHODIMP
PluginViewerImpl::PrintContent(nsIWebShell *aParent, nsIDeviceContext *aDContext)
{
NS_ENSURE_ARG_POINTER(aParent);
NS_ENSURE_ARG_POINTER(aDContext);
return NS_OK;
}
//----------------------------------------------------------------------
PluginListener::PluginListener(PluginViewerImpl* aViewer)

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

@ -15,3 +15,6 @@ nsIUrlDispatcher.h
nsIWebShell.h
nsIWebShellServices.h
nsweb.h
nsIContentViewerEdit.h
nsIContentViewerFile.h
nsIMarkupDocumentViewer.h

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

@ -42,6 +42,9 @@ EXPORTS = \
nsIWebShellServices.h \
nsweb.h \
nsIRefreshURI.h \
nsIContentViewerEdit.h \
nsIContentViewerFile.h \
nsIMarkupDocumentViewer.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

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

@ -43,6 +43,9 @@ EXPORTS = \
!ifdef NECKO
nsIRefreshURI.h \
!endif
nsIContentViewerEdit.h \
nsIContentViewerFile.h \
nsIMarkupDocumentViewer.h \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -79,26 +79,6 @@ public:
NS_IMETHOD Hide(void) = 0;
/**
* Top lever print for the Content viewer,
* this is called by the chrome, etc for printing this Content view
* @update 05/13/99 dwc
* @return Success or failure of the routine
*/
NS_IMETHOD Print(void) = 0;
/**
* Prints the actual content only if the container WebShell is a leaf..
* If it is not a leaf node, it will visit all the childern and call the PrintConent for each child.
* this method should only be called by the Print or PrintContext, so it is not really used by any
* embedding application or object, etc.
* @update 05/13/99 dwc
* @param aParent -- Parent WebShell of this ContentViewer
* @param aDCContext -- The device context to use for printing.
* @return Success or failure of the routine
*/
NS_IMETHOD PrintContent(nsIWebShell *aParent,nsIDeviceContext *aDContext) = 0;
NS_IMETHOD SetEnableRendering(PRBool aOn) = 0;
NS_IMETHOD GetEnableRendering(PRBool* aResult) = 0;

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

@ -0,0 +1,81 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIContentViewerEdit.idl
*/
#ifndef __gen_nsIContentViewerEdit_h__
#define __gen_nsIContentViewerEdit_h__
#include "nsISupports.h"
#include "nsrootidl.h"
/* starting interface: nsIContentViewerEdit */
#define NS_ICONTENTVIEWEREDIT_IID_STR "42d5215c-9bc7-11d3-bccc-0060b0fc76bd"
#define NS_ICONTENTVIEWEREDIT_IID \
{0x42d5215c, 0x9bc7, 0x11d3, \
{ 0xbc, 0xcc, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xbd }}
class nsIContentViewerEdit : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTVIEWEREDIT_IID)
/* void Search (); */
NS_IMETHOD Search(void) = 0;
/* readonly attribute boolean searchable; */
NS_IMETHOD GetSearchable(PRBool *aSearchable) = 0;
/* void ClearSelection (); */
NS_IMETHOD ClearSelection(void) = 0;
/* void SelectAll (); */
NS_IMETHOD SelectAll(void) = 0;
/* void CopySelection (); */
NS_IMETHOD CopySelection(void) = 0;
/* readonly attribute boolean copyable; */
NS_IMETHOD GetCopyable(PRBool *aCopyable) = 0;
/* void CutSelection (); */
NS_IMETHOD CutSelection(void) = 0;
/* readonly attribute boolean cutable; */
NS_IMETHOD GetCutable(PRBool *aCutable) = 0;
/* void Paste (); */
NS_IMETHOD Paste(void) = 0;
/* readonly attribute boolean pasteable; */
NS_IMETHOD GetPasteable(PRBool *aPasteable) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSICONTENTVIEWEREDIT \
NS_IMETHOD Search(void); \
NS_IMETHOD GetSearchable(PRBool *aSearchable); \
NS_IMETHOD ClearSelection(void); \
NS_IMETHOD SelectAll(void); \
NS_IMETHOD CopySelection(void); \
NS_IMETHOD GetCopyable(PRBool *aCopyable); \
NS_IMETHOD CutSelection(void); \
NS_IMETHOD GetCutable(PRBool *aCutable); \
NS_IMETHOD Paste(void); \
NS_IMETHOD GetPasteable(PRBool *aPasteable);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_NSICONTENTVIEWEREDIT(_to) \
NS_IMETHOD Search(void) { return _to ## Search(); } \
NS_IMETHOD GetSearchable(PRBool *aSearchable) { return _to ## GetSearchable(aSearchable); } \
NS_IMETHOD ClearSelection(void) { return _to ## ClearSelection(); } \
NS_IMETHOD SelectAll(void) { return _to ## SelectAll(); } \
NS_IMETHOD CopySelection(void) { return _to ## CopySelection(); } \
NS_IMETHOD GetCopyable(PRBool *aCopyable) { return _to ## GetCopyable(aCopyable); } \
NS_IMETHOD CutSelection(void) { return _to ## CutSelection(); } \
NS_IMETHOD GetCutable(PRBool *aCutable) { return _to ## GetCutable(aCutable); } \
NS_IMETHOD Paste(void) { return _to ## Paste(); } \
NS_IMETHOD GetPasteable(PRBool *aPasteable) { return _to ## GetPasteable(aPasteable); }
#endif /* __gen_nsIContentViewerEdit_h__ */

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

@ -0,0 +1,58 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIContentViewerFile.idl
*/
#ifndef __gen_nsIContentViewerFile_h__
#define __gen_nsIContentViewerFile_h__
#include "nsISupports.h"
#include "nsrootidl.h"
#include "nsIWebShell.h"
#include "nsIDeviceContext.h"
/* starting interface: nsIContentViewerFile */
#define NS_ICONTENTVIEWERFILE_IID_STR "6317f32c-9bc7-11d3-bccc-0060b0fc76bd"
#define NS_ICONTENTVIEWERFILE_IID \
{0x6317f32c, 0x9bc7, 0x11d3, \
{ 0xbc, 0xcc, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xbd }}
class nsIContentViewerFile : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTVIEWERFILE_IID)
/* void Save (); */
NS_IMETHOD Save(void) = 0;
/* readonly attribute boolean saveable; */
NS_IMETHOD GetSaveable(PRBool *aSaveable) = 0;
/* void Print (); */
NS_IMETHOD Print(void) = 0;
/* [noscript] void PrintContent (in nsIWebShell parent, in nsIDeviceContext DContext); */
NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext) = 0;
/* readonly attribute boolean printable; */
NS_IMETHOD GetPrintable(PRBool *aPrintable) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSICONTENTVIEWERFILE \
NS_IMETHOD Save(void); \
NS_IMETHOD GetSaveable(PRBool *aSaveable); \
NS_IMETHOD Print(void); \
NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext); \
NS_IMETHOD GetPrintable(PRBool *aPrintable);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_NSICONTENTVIEWERFILE(_to) \
NS_IMETHOD Save(void) { return _to ## Save(); } \
NS_IMETHOD GetSaveable(PRBool *aSaveable) { return _to ## GetSaveable(aSaveable); } \
NS_IMETHOD Print(void) { return _to ## Print(); } \
NS_IMETHOD PrintContent(nsIWebShell * parent, nsIDeviceContext * DContext) { return _to ## PrintContent(parent, DContext); } \
NS_IMETHOD GetPrintable(PRBool *aPrintable) { return _to ## GetPrintable(aPrintable); }
#endif /* __gen_nsIContentViewerFile_h__ */

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

@ -0,0 +1,90 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIMarkupDocumentViewer.idl
*/
#ifndef __gen_nsIMarkupDocumentViewer_h__
#define __gen_nsIMarkupDocumentViewer_h__
#include "nsISupports.h"
#include "domstubs.h"
#include "nsrootidl.h"
/* starting interface: nsIMarkupDocumentViewer */
#define NS_IMARKUPDOCUMENTVIEWER_IID_STR "69e5de03-7b8b-11d3-af61-00a024ffc08c"
#define NS_IMARKUPDOCUMENTVIEWER_IID \
{0x69e5de03, 0x7b8b, 0x11d3, \
{ 0xaf, 0x61, 0x00, 0xa0, 0x24, 0xff, 0xc0, 0x8c }}
class nsIMarkupDocumentViewer : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IMARKUPDOCUMENTVIEWER_IID)
/* void scrollToNode (in nsIDOMNode node); */
NS_IMETHOD ScrollToNode(nsIDOMNode *node) = 0;
/* attribute boolean allowPlugins; */
NS_IMETHOD GetAllowPlugins(PRBool *aAllowPlugins) = 0;
NS_IMETHOD SetAllowPlugins(PRBool aAllowPlugins) = 0;
/* attribute boolean isFrame; */
NS_IMETHOD GetIsFrame(PRBool *aIsFrame) = 0;
NS_IMETHOD SetIsFrame(PRBool aIsFrame) = 0;
/* attribute wstring defaultCharacterSet; */
NS_IMETHOD GetDefaultCharacterSet(PRUnichar * *aDefaultCharacterSet) = 0;
NS_IMETHOD SetDefaultCharacterSet(const PRUnichar * aDefaultCharacterSet) = 0;
/* attribute wstring forceCharacterSet; */
NS_IMETHOD GetForceCharacterSet(PRUnichar * *aForceCharacterSet) = 0;
NS_IMETHOD SetForceCharacterSet(const PRUnichar * aForceCharacterSet) = 0;
/* attribute wstring hintCharacterSet; */
NS_IMETHOD GetHintCharacterSet(PRUnichar * *aHintCharacterSet) = 0;
NS_IMETHOD SetHintCharacterSet(const PRUnichar * aHintCharacterSet) = 0;
/* attribute PRInt32 hintCharacterSetSource; */
NS_IMETHOD GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) = 0;
NS_IMETHOD SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) = 0;
/* void sizeToContent (); */
NS_IMETHOD SizeToContent(void) = 0;
};
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIMARKUPDOCUMENTVIEWER \
NS_IMETHOD ScrollToNode(nsIDOMNode *node); \
NS_IMETHOD GetAllowPlugins(PRBool *aAllowPlugins); \
NS_IMETHOD SetAllowPlugins(PRBool aAllowPlugins); \
NS_IMETHOD GetIsFrame(PRBool *aIsFrame); \
NS_IMETHOD SetIsFrame(PRBool aIsFrame); \
NS_IMETHOD GetDefaultCharacterSet(PRUnichar * *aDefaultCharacterSet); \
NS_IMETHOD SetDefaultCharacterSet(const PRUnichar * aDefaultCharacterSet); \
NS_IMETHOD GetForceCharacterSet(PRUnichar * *aForceCharacterSet); \
NS_IMETHOD SetForceCharacterSet(const PRUnichar * aForceCharacterSet); \
NS_IMETHOD GetHintCharacterSet(PRUnichar * *aHintCharacterSet); \
NS_IMETHOD SetHintCharacterSet(const PRUnichar * aHintCharacterSet); \
NS_IMETHOD GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource); \
NS_IMETHOD SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource); \
NS_IMETHOD SizeToContent(void);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_NSIMARKUPDOCUMENTVIEWER(_to) \
NS_IMETHOD ScrollToNode(nsIDOMNode *node) { return _to ## ScrollToNode(node); } \
NS_IMETHOD GetAllowPlugins(PRBool *aAllowPlugins) { return _to ## GetAllowPlugins(aAllowPlugins); } \
NS_IMETHOD SetAllowPlugins(PRBool aAllowPlugins) { return _to ## SetAllowPlugins(aAllowPlugins); } \
NS_IMETHOD GetIsFrame(PRBool *aIsFrame) { return _to ## GetIsFrame(aIsFrame); } \
NS_IMETHOD SetIsFrame(PRBool aIsFrame) { return _to ## SetIsFrame(aIsFrame); } \
NS_IMETHOD GetDefaultCharacterSet(PRUnichar * *aDefaultCharacterSet) { return _to ## GetDefaultCharacterSet(aDefaultCharacterSet); } \
NS_IMETHOD SetDefaultCharacterSet(const PRUnichar * aDefaultCharacterSet) { return _to ## SetDefaultCharacterSet(aDefaultCharacterSet); } \
NS_IMETHOD GetForceCharacterSet(PRUnichar * *aForceCharacterSet) { return _to ## GetForceCharacterSet(aForceCharacterSet); } \
NS_IMETHOD SetForceCharacterSet(const PRUnichar * aForceCharacterSet) { return _to ## SetForceCharacterSet(aForceCharacterSet); } \
NS_IMETHOD GetHintCharacterSet(PRUnichar * *aHintCharacterSet) { return _to ## GetHintCharacterSet(aHintCharacterSet); } \
NS_IMETHOD SetHintCharacterSet(const PRUnichar * aHintCharacterSet) { return _to ## SetHintCharacterSet(aHintCharacterSet); } \
NS_IMETHOD GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) { return _to ## GetHintCharacterSetSource(aHintCharacterSetSource); } \
NS_IMETHOD SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) { return _to ## SetHintCharacterSetSource(aHintCharacterSetSource); } \
NS_IMETHOD SizeToContent(void) { return _to ## SizeToContent(); }
#endif /* __gen_nsIMarkupDocumentViewer_h__ */

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

@ -24,11 +24,11 @@
#include "nsweb.h"
#include "nsIWidget.h"
#include "nsIParser.h"
#include "nsIScrollableView.h"
#include "nsIContentViewerContainer.h"
#include "nsIChannel.h"
#include "nsIScrollableView.h"
#include "nsIParser.h" // for nsCharsetSource only
#include "nsISessionHistory.h"
#include "nsIUrlDispatcher.h"
@ -175,11 +175,6 @@ public:
*/
NS_IMETHOD SetBounds(PRInt32 x, PRInt32 y, PRInt32 w, PRInt32 h) = 0;
/**
* Shrink-to-fit the WebShell to its contents
*/
NS_IMETHOD SizeToContent() = 0;
NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY) = 0;
/**
@ -423,13 +418,20 @@ public:
// SetStatusBar
NS_IMETHOD SetContentViewer(nsIContentViewer* aViewer) = 0;
// XXX these are here until there a better way to pass along info to a sub doc
NS_IMETHOD GetMarginWidth (PRInt32& aWidth) = 0;
NS_IMETHOD SetMarginWidth (PRInt32 aWidth) = 0;
NS_IMETHOD GetMarginHeight(PRInt32& aWidth) = 0;
NS_IMETHOD SetMarginHeight(PRInt32 aHeight) = 0;
NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE) = 0;
NS_IMETHOD GetScrolling(PRInt32& aScrolling) = 0;
// XXX these are here until there a better way to pass along info to a sub doc
NS_IMETHOD GetMarginWidth (PRInt32* aWidth) = 0;
NS_IMETHOD SetMarginWidth (PRInt32 aWidth) = 0;
NS_IMETHOD GetMarginHeight(PRInt32* aWidth) = 0;
NS_IMETHOD SetMarginHeight(PRInt32 aHeight) = 0;
/* ============ moved to nsIMarkupDocumentViewer =================== */
/*
NS_IMETHOD SetIsFrame(PRBool aIsFrame) = 0;
NS_IMETHOD GetIsFrame(PRBool& aIsFrame) = 0;
@ -439,9 +441,15 @@ public:
NS_IMETHOD GetForceCharacterSet (const PRUnichar** aForceCharacterSet) = 0;
NS_IMETHOD SetForceCharacterSet (const PRUnichar* aForceCharacterSet) = 0;
/* the following is the hacky access method */
// the following is the hacky access method
NS_IMETHOD GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource) = 0;
*/
// XXX this will go away, replaced by a new content viewer method
NS_IMETHOD SizeToContent() = 0;
/**
* Set/Get the document scale factor
*/

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

@ -24,6 +24,7 @@
#include "nsIDocumentLoader.h"
#include "nsIContentViewer.h"
#include "nsIDocumentViewer.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIClipboardCommands.h"
#include "nsIDeviceContext.h"
#include "nsILinkHandler.h"
@ -225,14 +226,14 @@ public:
NS_IMETHOD GetContainingChromeElement(nsIContent** aResult);
NS_IMETHOD SetContainingChromeElement(nsIContent* aChromeElement);
NS_IMETHOD GetMarginWidth (PRInt32& aWidth);
NS_IMETHOD SetMarginWidth (PRInt32 aWidth);
NS_IMETHOD GetMarginHeight(PRInt32& aWidth);
NS_IMETHOD SetMarginHeight(PRInt32 aHeight);
NS_IMETHOD GetScrolling(PRInt32& aScrolling);
NS_IMETHOD SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial = PR_TRUE);
NS_IMETHOD GetIsFrame(PRBool& aIsFrame);
NS_IMETHOD SetIsFrame(PRBool aIsFrame);
NS_IMETHOD GetMarginWidth (PRInt32* aWidth);
NS_IMETHOD SetMarginWidth (PRInt32 aWidth);
NS_IMETHOD GetMarginHeight(PRInt32* aWidth);
NS_IMETHOD SetMarginHeight(PRInt32 aHeight);
NS_IMETHOD SetZoom(float aZoom);
NS_IMETHOD GetZoom(float *aZoom);
@ -402,13 +403,6 @@ public:
nsresult DestroyPluginHost(void);
NS_IMETHOD IsBusy(PRBool& aResult);
NS_IMETHOD GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet);
NS_IMETHOD SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet);
NS_IMETHOD GetForceCharacterSet (const PRUnichar** aForceCharacterSet);
NS_IMETHOD SetForceCharacterSet (const PRUnichar* aForceCharacterSet);
NS_IMETHOD GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource);
NS_IMETHOD SetSessionHistory(nsISessionHistory * aSHist);
NS_IMETHOD GetSessionHistory(nsISessionHistory *& aResult);
@ -464,12 +458,13 @@ protected:
nsString mOverTarget;
PRPackedBool mIsInSHist;
PRPackedBool mIsFrame;
PRPackedBool mFailedToLoadHistoryService;
nsScrollPreference mScrollPref;
PRInt32 mMarginWidth;
PRInt32 mMarginHeight;
PRInt32 mScrolling[2];
nsVoidArray mRefreshments;
@ -507,11 +502,14 @@ protected:
PRBool mProcessedEndDocumentLoad;
// XXX store mHintCharset and mHintCharsetSource here untill we find out a good cood path
/*
nsString mHintCharset;
nsCharsetSource mHintCharsetSource;
PRBool mViewSource;
nsString mForceCharacterSet;
*/
PRBool mViewSource;
// if there is no mWindow, this will keep track of the bounds --dwc0001
nsRect mBounds;
@ -657,7 +655,6 @@ nsWebShell::nsWebShell()
mScriptContext = nsnull;
mThreadEventQueue = nsnull;
InitFrameData(PR_TRUE);
mIsFrame = PR_FALSE;
mWebShellType = nsWebShellContent;
mChromeElement = nsnull;
mSHist = nsnull;
@ -665,11 +662,8 @@ nsWebShell::nsWebShell()
mFailedToLoadHistoryService = PR_FALSE;
mDefaultCharacterSet = "";
mProcessedEndDocumentLoad = PR_FALSE;
mHintCharset = "";
mHintCharsetSource = kCharsetUninitialized;
mCharsetReloadState = eCharsetReloadInit;
mViewSource=PR_FALSE;
mForceCharacterSet = "";
mHistoryService = nsnull;
mHistoryState = nsnull;
mParentContentListener = nsnull;
@ -713,7 +707,6 @@ nsWebShell::~nsWebShell()
}
InitFrameData(PR_TRUE);
mIsFrame = PR_FALSE;
// XXX Because we hold references to the children and they hold references
// to us we never get destroyed. See Destroy() instead...
@ -747,8 +740,8 @@ void nsWebShell::InitFrameData(PRBool aCompleteInitScrolling)
if (aCompleteInitScrolling) {
mScrolling[0] = -1;
mScrolling[1] = -1;
mMarginWidth = -1;
mMarginHeight = -1;
SetMarginWidth(-1);
SetMarginHeight(-1);
}
else {
mScrolling[1] = mScrolling[0];
@ -838,6 +831,41 @@ nsWebShell::Embed(nsIContentViewer* aContentViewer,
("nsWebShell::Embed: this=%p aDocViewer=%p aCommand=%s aExtraInfo=%p",
this, aContentViewer, aCommand ? aCommand : "", aExtraInfo));
if (mContentViewer && (eCharsetReloadInit!=mCharsetReloadState))
{ // get any interesting state from the old content viewer
// XXX: it would be far better to just reuse the document viewer ,
// since we know we're just displaying the same document as before
PRUnichar *defaultCharset=nsnull;
PRUnichar *forceCharset=nsnull;
PRUnichar *hintCharset=nsnull;
PRInt32 hintCharsetSource;
nsCOMPtr<nsIMarkupDocumentViewer> oldMUDV = do_QueryInterface(mContentViewer);
nsCOMPtr<nsIMarkupDocumentViewer> newMUDV = do_QueryInterface(aContentViewer);
if (oldMUDV && newMUDV)
{
NS_ENSURE_SUCCESS(oldMUDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSet (&hintCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(oldMUDV->GetHintCharacterSetSource (&hintCharsetSource), NS_ERROR_FAILURE);
// set the old state onto the new content viewer
NS_ENSURE_SUCCESS(newMUDV->SetDefaultCharacterSet (defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetForceCharacterSet (forceCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSet (hintCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(newMUDV->SetHintCharacterSetSource (hintCharsetSource), NS_ERROR_FAILURE);
if (defaultCharSet) {
Recycle(defaultCharSet);
}
if (forceCharset) {
Recycle(forceCharset);
}
if (hintCharset) {
Recycle(hintCharset);
}
}
}
NS_IF_RELEASE(mContentViewer);
if (nsnull != mScriptContext) {
mScriptContext->GC();
@ -1586,10 +1614,30 @@ nsWebShell::AddChild(nsIWebShell* aChild)
}
mChildren.AppendElement(aChild);
aChild->SetParent(this);
const PRUnichar *defaultCharset=nsnull;
if(NS_SUCCEEDED(this->GetDefaultCharacterSet (&defaultCharset)))
aChild->SetDefaultCharacterSet(defaultCharset);
aChild->SetForceCharacterSet(mForceCharacterSet.GetUnicode());
PRUnichar *defaultCharset=nsnull;
PRUnichar *forceCharset=nsnull;
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
NS_ENSURE_SUCCESS(muDV->GetDefaultCharacterSet (&defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(muDV->GetForceCharacterSet (&forceCharset), NS_ERROR_FAILURE);
}
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(aChild->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> childmuDV = do_QueryInterface(cv);
if (childmuDV)
{
childmuDV->SetDefaultCharacterSet(defaultCharset);
childmuDV->SetForceCharacterSet(forceCharset);
}
}
}
NS_ADDREF(aChild);
return NS_OK;
@ -1736,9 +1784,11 @@ nsWebShell::SetContainingChromeElement(nsIContent* aChromeElement)
}
NS_IMETHODIMP
nsWebShell::GetMarginWidth(PRInt32& aWidth)
nsWebShell::GetMarginWidth(PRInt32* aWidth)
{
aWidth = mMarginWidth;
NS_ENSURE_ARG_POINTER(aWidth);
*aWidth = mMarginWidth;
return NS_OK;
}
@ -1750,9 +1800,11 @@ nsWebShell::SetMarginWidth(PRInt32 aWidth)
}
NS_IMETHODIMP
nsWebShell::GetMarginHeight(PRInt32& aHeight)
nsWebShell::GetMarginHeight(PRInt32* aHeight)
{
aHeight = mMarginHeight;
NS_ENSURE_ARG_POINTER(aHeight);
*aHeight = mMarginHeight;
return NS_OK;
}
@ -1780,20 +1832,6 @@ nsWebShell::SetScrolling(PRInt32 aScrolling, PRBool aSetCurrentAndInitial)
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::GetIsFrame(PRBool& aIsFrame)
{
aIsFrame = mIsFrame;
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetIsFrame(PRBool aIsFrame)
{
mIsFrame = aIsFrame;
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetZoom(float aZoom)
{
@ -1944,6 +1982,7 @@ nsWebShell::SetDocument(nsIDOMDocument *aDOMDoc, nsIDOMElement *aRootNode)
if (!doc) { return NS_ERROR_OUT_OF_MEMORY; }
NS_ENSURE_SUCCESS(rootContent->SetDocument(doc, PR_FALSE), NS_ERROR_FAILURE);
doc->SetRootContent(rootContent);
rootContent->SetDocument(doc, PR_TRUE);
// (6) reflow the document
SetScrolling(-1, PR_FALSE);
@ -2960,16 +2999,27 @@ nsWebShell::LoadDocument(const char* aURL,
nsCharsetSource aSource)
{
// XXX hack. kee the aCharset and aSource wait to pick it up
if( aSource > mHintCharsetSource ) {
mHintCharset = aCharset;
mHintCharsetSource = aSource;
if(eCharsetReloadRequested != mCharsetReloadState)
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
mCharsetReloadState = eCharsetReloadRequested;
nsAutoString url(aURL);
LoadURL(url.GetUnicode());
nsCharsetSource hint;
muDV->GetHintCharacterSetSource((PRInt32 *)(&hint));
if( aSource > hint )
{
nsAutoString inputCharSet(aCharset);
muDV->SetHintCharacterSet(inputCharSet.GetUnicode());
muDV->SetHintCharacterSetSource((PRInt32)aSource);
if(eCharsetReloadRequested != mCharsetReloadState)
{
mCharsetReloadState = eCharsetReloadRequested;
nsAutoString url(aURL);
LoadURL(url.GetUnicode());
}
}
}
}
return NS_OK;
@ -2982,15 +3032,28 @@ nsWebShell::ReloadDocument(const char* aCharset,
{
// XXX hack. kee the aCharset and aSource wait to pick it up
if( aSource > mHintCharsetSource ) {
mHintCharset = aCharset;
mHintCharsetSource = aSource;
mViewSource = (0==PL_strcmp("view-source", aCmd));
if(eCharsetReloadRequested != mCharsetReloadState)
{
mCharsetReloadState = eCharsetReloadRequested;
return Reload(nsIChannel::LOAD_NORMAL);
}
nsCOMPtr<nsIContentViewer> cv;
NS_ENSURE_SUCCESS(GetContentViewer(getter_AddRefs(cv)), NS_ERROR_FAILURE);
if (cv)
{
nsCOMPtr<nsIMarkupDocumentViewer> muDV = do_QueryInterface(cv);
if (muDV)
{
nsCharsetSource hint;
muDV->GetHintCharacterSetSource((PRInt32 *)(&hint));
if( aSource > hint )
{
nsAutoString inputCharSet(aCharset);
muDV->SetHintCharacterSet(inputCharSet.GetUnicode());
muDV->SetHintCharacterSetSource((PRInt32)aSource);
mViewSource = (0==PL_strcmp("view-source", aCmd));
if(eCharsetReloadRequested != mCharsetReloadState)
{
mCharsetReloadState = eCharsetReloadRequested;
return Reload(nsIChannel::LOAD_NORMAL);
}
}
}
}
return NS_OK;
}
@ -4185,77 +4248,6 @@ nsWebShell::SelectNone(void)
return NS_ERROR_FAILURE;
}
static char *gDefCharset = nsnull;
NS_IMETHODIMP
nsWebShell::GetDefaultCharacterSet (const PRUnichar** aDefaultCharacterSet)
{
if (0 == mDefaultCharacterSet.Length()) {
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) {
if(mPrefs)
mPrefs->CopyCharPref("intl.charset.default", &gDefCharset);
}
if ((nsnull == gDefCharset) || (nsnull == *gDefCharset))
mDefaultCharacterSet = "ISO-8859-1";
else
mDefaultCharacterSet = gDefCharset;
}
*aDefaultCharacterSet = mDefaultCharacterSet.GetUnicode();
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetDefaultCharacterSet (const PRUnichar* aDefaultCharacterSet)
{
mDefaultCharacterSet = aDefaultCharacterSet;
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++) {
nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i);
if (nsnull != child) {
child->SetDefaultCharacterSet(aDefaultCharacterSet);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::GetForceCharacterSet (const PRUnichar** aForceCharacterSet)
{
nsAutoString emptyStr;
if (mForceCharacterSet.Equals(emptyStr)) {
*aForceCharacterSet = nsnull;
}
else {
*aForceCharacterSet = mForceCharacterSet.GetUnicode();
}
return NS_OK;
}
NS_IMETHODIMP
nsWebShell::SetForceCharacterSet (const PRUnichar* aForceCharacterSet)
{
mForceCharacterSet = aForceCharacterSet;
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++) {
nsIWebShell* child = (nsIWebShell*) mChildren.ElementAt(i);
if (nsnull != child) {
child->SetForceCharacterSet(aForceCharacterSet);
}
}
return NS_OK;
}
NS_IMETHODIMP nsWebShell::GetCharacterSetHint (const PRUnichar** oHintCharset, nsCharsetSource* oSource)
{
*oSource = mHintCharsetSource;
if(kCharsetUninitialized == mHintCharsetSource) {
*oHintCharset = nsnull;
} else {
*oHintCharset = mHintCharset.GetUnicode();
mHintCharsetSource = kCharsetUninitialized;
}
return NS_OK;
}
//----------------------------------------------------
NS_IMETHODIMP

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

@ -56,6 +56,7 @@
#include "nsLayoutCID.h"
#include "nsIDocumentViewer.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
@ -2373,7 +2374,10 @@ void nsBrowserWindow::DoPrint(void)
if (viewer)
{
viewer->Print();
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
viewerFile->Print();
}
}
}

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

@ -26,6 +26,7 @@
#include "nsIBrowserWindow.h"
#include "nsIWebShell.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIClipboardCommands.h"
#include "pratom.h"
#include "prprf.h"
@ -94,6 +95,7 @@ static NS_DEFINE_IID(kWalletServiceCID, NS_WALLETSERVICE_CID);
#include "nsIXULWindowCallbacks.h"
#include "nsIDocumentObserver.h"
#include "nsIContent.h"
#include "nsIContentViewerFile.h"
#include "nsINameSpaceManager.h"
#include "nsFileStream.h"
@ -167,6 +169,7 @@ nsBrowserAppCore::~nsBrowserAppCore()
NS_IMPL_ADDREF(nsBrowserAppCore)
NS_IMPL_RELEASE(nsBrowserAppCore)
NS_IMPL_QUERY_HEAD(nsBrowserAppCore)
NS_IMPL_QUERY_BODY(nsIBrowserInstance)
NS_IMPL_QUERY_BODY(nsIDocumentLoaderObserver)
@ -174,6 +177,7 @@ NS_IMPL_QUERY_HEAD(nsBrowserAppCore)
NS_IMPL_QUERY_BODY(nsIURIContentListener)
NS_IMPL_QUERY_TAIL(nsIBrowserInstance)
static
nsIPresShell*
GetPresShellFor(nsIWebShell* aWebShell)
@ -237,14 +241,20 @@ nsBrowserAppCore::SetDocumentCharset(const PRUnichar *aCharset)
return NS_ERROR_FAILURE;
}
nsIWebShell * webShell;
globalObj->GetWebShell(&webShell);
if (nsnull != webShell) {
webShell->SetDefaultCharacterSet( aCharset );
NS_RELEASE(webShell);
nsCOMPtr<nsIWebShell> webShell;
globalObj->GetWebShell(getter_AddRefs(webShell));
if (webShell)
{
nsCOMPtr<nsIContentViewer> childCV;
NS_ENSURE_SUCCESS(webShell->GetContentViewer(getter_AddRefs(childCV)), NS_ERROR_FAILURE);
if (childCV)
{
nsCOMPtr<nsIMarkupDocumentViewer> markupCV = do_QueryInterface(childCV);
if (markupCV) {
NS_ENSURE_SUCCESS(markupCV->SetDefaultCharacterSet(aCharset), NS_ERROR_FAILURE);
}
}
}
return NS_OK;
}
@ -1904,14 +1914,14 @@ nsBrowserAppCore::Copy()
NS_IMETHODIMP
nsBrowserAppCore::Print()
{
if (nsnull != mContentAreaWebShell) {
nsIContentViewer *viewer = nsnull;
mContentAreaWebShell->GetContentViewer(&viewer);
if (mContentAreaWebShell) {
nsCOMPtr<nsIContentViewer> viewer;
mWebShell->GetContentViewer(getter_AddRefs(viewer));
if (nsnull != viewer) {
viewer->Print();
NS_RELEASE(viewer);
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
if (viewerFile) {
NS_ENSURE_SUCCESS(viewerFile->Print(), NS_ERROR_FAILURE);
}
}
}
return NS_OK;