Changed nsHTMLFrameInnerFrame to hold on to a subShell that is an nsIBaseWindow instead of a webShell. This paves the way for holding different types of objects. Also gets rid of that stupid nsIWebShell interface. :) When creating the docShell use the new docShell interfaces rather than the old webShell ones.

git-svn-id: svn://10.0.0.236/trunk@62571 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
tbogard%aol.net 2000-03-11 00:41:04 +00:00
parent e0ccbcff63
commit 2011f00f70
2 changed files with 122 additions and 122 deletions

View File

@ -29,6 +29,7 @@
#include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeNode.h"
#include "nsIDocShellTreeOwner.h" #include "nsIDocShellTreeOwner.h"
#include "nsIWebNavigation.h"
#include "nsIBaseWindow.h" #include "nsIBaseWindow.h"
#include "nsIContentViewer.h" #include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h" #include "nsIMarkupDocumentViewer.h"
@ -62,9 +63,7 @@
class nsHTMLFrame; class nsHTMLFrame;
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID);
@ -186,7 +185,7 @@ public:
nsresult ReloadURL(); nsresult ReloadURL();
protected: protected:
nsresult CreateWebShell(nsIPresContext* aPresContext, const nsSize& aSize); nsresult CreateDocShell(nsIPresContext* aPresContext, const nsSize& aSize);
virtual ~nsHTMLFrameInnerFrame(); virtual ~nsHTMLFrameInnerFrame();
@ -194,7 +193,7 @@ protected:
const nsHTMLReflowState& aReflowState, const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize); nsHTMLReflowMetrics& aDesiredSize);
nsCOMPtr<nsIWebShell> mWebShell; nsCOMPtr<nsIBaseWindow> mSubShell;
PRBool mCreatingViewer; PRBool mCreatingViewer;
}; };
@ -446,10 +445,9 @@ nsHTMLFrameInnerFrame::~nsHTMLFrameInnerFrame()
{ {
//printf("nsHTMLFrameInnerFrame destructor %X \n", this); //printf("nsHTMLFrameInnerFrame destructor %X \n", this);
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell)); if(mSubShell)
if(webShellWin) mSubShell->Destroy();
webShellWin->Destroy(); mSubShell = nsnull; // This is the location it was released before...
mWebShell = nsnull; // This is the location it was released before...
// Not sure if there is ordering depending on this. // Not sure if there is ordering depending on this.
} }
@ -613,7 +611,7 @@ nsHTMLFrameInnerFrame::Paint(nsIPresContext* aPresContext,
//printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); //printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
// if there is not web shell paint based on our background color, // if there is not web shell paint based on our background color,
// otherwise let the web shell paint the sub document // otherwise let the web shell paint the sub document
if (!mWebShell) { if (!mSubShell) {
const nsStyleColor* color = const nsStyleColor* color =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
aRenderingContext.SetColor(color->mBackgroundColor); aRenderingContext.SetColor(color->mBackgroundColor);
@ -686,53 +684,57 @@ nsHTMLFrameInnerFrame::DidReflow(nsIPresContext* aPresContext,
} }
nsresult nsresult
nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext, nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext,
const nsSize& aSize) const nsSize& aSize)
{ {
nsresult rv; nsresult rv;
nsIContent* content; nsCOMPtr<nsIContent> parentContent;
GetParentContent(content); GetParentContent(*getter_AddRefs(parentContent));
mWebShell = do_CreateInstance(kWebShellCID); mSubShell = do_CreateInstance(kWebShellCID);
NS_ENSURE_TRUE(mWebShell, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mSubShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mWebShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
// notify the pres shell that a docshell has been created // notify the pres shell that a docshell has been created
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
aPresContext->GetShell(getter_AddRefs(presShell)); aPresContext->GetShell(getter_AddRefs(presShell));
if (presShell) if (presShell)
{ {
nsCOMPtr<nsISupports> webShellAsSupports(do_QueryInterface(mWebShell)); nsCOMPtr<nsISupports> subShellAsSupports(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(webShellAsSupports, NS_ERROR_FAILURE); NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE);
presShell->SetSubShellFor(mContent, webShellAsSupports); presShell->SetSubShellFor(mContent, subShellAsSupports);
} }
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
// pass along marginwidth, marginheight, scrolling so sub document can use it // pass along marginwidth, marginheight, scrolling so sub document can use it
mWebShell->SetMarginWidth(GetMarginWidth(aPresContext, content)); docShell->SetMarginWidth(GetMarginWidth(aPresContext, parentContent));
mWebShell->SetMarginHeight(GetMarginHeight(aPresContext, content)); docShell->SetMarginHeight(GetMarginHeight(aPresContext, parentContent));
nsCompatibility mode; nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode); aPresContext->GetCompatibilityMode(&mode);
// Current and initial scrolling is set so that all succeeding docs // Current and initial scrolling is set so that all succeeding docs
// will use the scrolling value set here, regardless if scrolling is // will use the scrolling value set here, regardless if scrolling is
// set by viewing a particular document (e.g. XUL turns off scrolling) // set by viewing a particular document (e.g. XUL turns off scrolling)
nsCOMPtr<nsIScrollable> scrollableContainer = do_QueryInterface(mWebShell, &rv); nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryInterface(mSubShell));
if (NS_SUCCEEDED(rv) && scrollableContainer) { if (scrollableContainer) {
scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y, GetScrolling(content, mode)); scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X, GetScrolling(content, mode)); GetScrolling(parentContent, mode));
scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
GetScrolling(parentContent, mode));
} }
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
nsString frameName; nsString frameName;
if (GetName(content, frameName)) { if (GetName(parentContent, frameName)) {
docShellAsItem->SetName(frameName.GetUnicode()); docShellAsItem->SetName(frameName.GetUnicode());
} }
// If our container is a web-shell, inform it that it has a new // If our container is a web-shell, inform it that it has a new
// child. If it's not a web-shell then some things will not operate // child. If it's not a web-shell then some things will not operate
// properly. // properly.
nsISupports* container; nsCOMPtr<nsISupports> container;
aPresContext->GetContainer(&container); aPresContext->GetContainer(getter_AddRefs(container));
if (nsnull != container) { if (container) {
nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(container)); nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(container));
if (parentAsNode) { if (parentAsNode) {
nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsNode)); nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsNode));
@ -744,7 +746,8 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
PRBool isContent; PRBool isContent;
isContent = PR_FALSE; isContent = PR_FALSE;
if (NS_SUCCEEDED(content->GetAttribute(kNameSpaceID_None, typeAtom, value))) { if (NS_SUCCEEDED(parentContent->GetAttribute(kNameSpaceID_None,
typeAtom, value))) {
// we accept "content" and "content-xxx" values. // we accept "content" and "content-xxx" values.
// at time of writing, we expect "xxx" to be "primary", but // at time of writing, we expect "xxx" to be "primary", but
@ -776,9 +779,10 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
value.GetUnicode()); value.GetUnicode());
} }
// connect the container... // connect the container...
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mSubShell));
nsCOMPtr<nsIWebShellContainer> outerContainer(do_QueryInterface(container)); nsCOMPtr<nsIWebShellContainer> outerContainer(do_QueryInterface(container));
if (outerContainer) if (outerContainer)
mWebShell->SetContainer(outerContainer); webShell->SetContainer(outerContainer);
// Make sure all shells have links back to the content element in the // Make sure all shells have links back to the content element in the
@ -797,9 +801,8 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler)); parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler));
} }
mWebShell->SetChromeEventHandler(chromeEventHandler); docShell->SetChromeEventHandler(chromeEventHandler);
} }
NS_RELEASE(container);
} }
float t2p; float t2p;
@ -833,20 +836,14 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
view->SetVisibility(nsViewVisibility_kHide); view->SetVisibility(nsViewVisibility_kHide);
} }
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));
NS_ENSURE_TRUE(webShellWin, NS_ERROR_FAILURE);
nsCOMPtr<nsIWidget> widget; nsCOMPtr<nsIWidget> widget;
view->GetWidget(*getter_AddRefs(widget)); view->GetWidget(*getter_AddRefs(widget));
nsRect webBounds(0, 0, NSToCoordRound(aSize.width * t2p),
NSToCoordRound(aSize.height * t2p));
mWebShell->Init(widget->GetNativeData(NS_NATIVE_WIDGET), mSubShell->InitWindow(nsnull, widget, 0, 0, NSToCoordRound(aSize.width * t2p),
webBounds.x, webBounds.y, NSToCoordRound(aSize.height * t2p));
webBounds.width, webBounds.height); mSubShell->Create();
//GetScrolling(content, PR_FALSE));
NS_RELEASE(content);
webShellWin->SetVisibility(PR_TRUE); mSubShell->SetVisibility(PR_TRUE);
return NS_OK; return NS_OK;
} }
@ -868,8 +865,8 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
// use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size // use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size
if (!mCreatingViewer) { if (!mCreatingViewer) {
nsIContent* content; nsCOMPtr<nsIContent> content;
GetParentContent(content); GetParentContent(*getter_AddRefs(content));
nsAutoString url; nsAutoString url;
PRBool hasURL = GetURL(content, url); PRBool hasURL = GetURL(content, url);
@ -877,9 +874,9 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
// create the web shell // create the web shell
// we do this even if the size is not positive (bug 11762) // we do this even if the size is not positive (bug 11762)
// we do this even if there is no src (bug 16218) // we do this even if there is no src (bug 16218)
if (!mWebShell) { if (!mSubShell) {
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight); nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
rv = CreateWebShell(aPresContext, maxSize); rv = CreateDocShell(aPresContext, maxSize);
#ifdef INCLUDE_XUL #ifdef INCLUDE_XUL
// The URL can be destructively altered when a content shell is made. // The URL can be destructively altered when a content shell is made.
// Refetch it to ensure we have the actual URL to load. // Refetch it to ensure we have the actual URL to load.
@ -887,7 +884,7 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
#endif // INCLUDE_XUL #endif // INCLUDE_XUL
} }
if (mWebShell) { if (mSubShell) {
mCreatingViewer=PR_TRUE; mCreatingViewer=PR_TRUE;
if (hasURL) { if (hasURL) {
// load the document // load the document
@ -906,11 +903,12 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
rv = securityManager->CheckLoadURI(baseURI, newURI, PR_FALSE); rv = securityManager->CheckLoadURI(baseURI, newURI, PR_FALSE);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
webNav->LoadURI(absURL.GetUnicode()); // URL string with a default nsnull value for post Data
} }
} }
} }
NS_RELEASE(content);
} }
aDesiredSize.width = aReflowState.availableWidth; aDesiredSize.width = aReflowState.availableWidth;
@ -925,18 +923,17 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
aStatus = NS_FRAME_COMPLETE; aStatus = NS_FRAME_COMPLETE;
// resize the sub document // resize the sub document
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell)); if(mSubShell) {
if(webShellWin) {
float t2p; float t2p;
aPresContext->GetTwipsToPixels(&t2p); aPresContext->GetTwipsToPixels(&t2p);
nsRect subBounds;
webShellWin->GetPositionAndSize(&subBounds.x, &subBounds.y, PRInt32 x = 0;
&subBounds.width, &subBounds.height); PRInt32 y = 0;
subBounds.width = NSToCoordRound(aDesiredSize.width * t2p);
subBounds.height = NSToCoordRound(aDesiredSize.height * t2p); mSubShell->GetPositionAndSize(&x, &y, nsnull, nsnull);
webShellWin->SetPositionAndSize(subBounds.x, subBounds.y, PRInt32 cx = NSToCoordRound(aDesiredSize.width * t2p);
subBounds.width, subBounds.height, PR_FALSE); PRInt32 cy = NSToCoordRound(aDesiredSize.height * t2p);
mSubShell->SetPositionAndSize(x, y, cx, cy, PR_FALSE);
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x", ("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x",
@ -959,14 +956,17 @@ nsHTMLFrameInnerFrame::ReloadURL()
// load a new url if the size is not 0 // load a new url if the size is not 0
if ((mRect.width > 0) && (mRect.height > 0)) { if ((mRect.width > 0) && (mRect.height > 0)) {
if (mWebShell) { if (mSubShell) {
mCreatingViewer=PR_TRUE; mCreatingViewer=PR_TRUE;
// load the document // load the document
nsString absURL; nsString absURL;
TempMakeAbsURL(content, url, absURL); TempMakeAbsURL(content, url, absURL);
rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
rv = webNav->LoadURI(absURL.GetUnicode()); // URL string with a default nsnull value for post Data
} }
} else { } else {
mCreatingViewer = PR_TRUE; mCreatingViewer = PR_TRUE;

View File

@ -29,6 +29,7 @@
#include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h" #include "nsIDocShellTreeNode.h"
#include "nsIDocShellTreeOwner.h" #include "nsIDocShellTreeOwner.h"
#include "nsIWebNavigation.h"
#include "nsIBaseWindow.h" #include "nsIBaseWindow.h"
#include "nsIContentViewer.h" #include "nsIContentViewer.h"
#include "nsIMarkupDocumentViewer.h" #include "nsIMarkupDocumentViewer.h"
@ -62,9 +63,7 @@
class nsHTMLFrame; class nsHTMLFrame;
static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID);
@ -186,7 +185,7 @@ public:
nsresult ReloadURL(); nsresult ReloadURL();
protected: protected:
nsresult CreateWebShell(nsIPresContext* aPresContext, const nsSize& aSize); nsresult CreateDocShell(nsIPresContext* aPresContext, const nsSize& aSize);
virtual ~nsHTMLFrameInnerFrame(); virtual ~nsHTMLFrameInnerFrame();
@ -194,7 +193,7 @@ protected:
const nsHTMLReflowState& aReflowState, const nsHTMLReflowState& aReflowState,
nsHTMLReflowMetrics& aDesiredSize); nsHTMLReflowMetrics& aDesiredSize);
nsCOMPtr<nsIWebShell> mWebShell; nsCOMPtr<nsIBaseWindow> mSubShell;
PRBool mCreatingViewer; PRBool mCreatingViewer;
}; };
@ -446,10 +445,9 @@ nsHTMLFrameInnerFrame::~nsHTMLFrameInnerFrame()
{ {
//printf("nsHTMLFrameInnerFrame destructor %X \n", this); //printf("nsHTMLFrameInnerFrame destructor %X \n", this);
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell)); if(mSubShell)
if(webShellWin) mSubShell->Destroy();
webShellWin->Destroy(); mSubShell = nsnull; // This is the location it was released before...
mWebShell = nsnull; // This is the location it was released before...
// Not sure if there is ordering depending on this. // Not sure if there is ordering depending on this.
} }
@ -613,7 +611,7 @@ nsHTMLFrameInnerFrame::Paint(nsIPresContext* aPresContext,
//printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height); //printf("inner paint %X (%d,%d,%d,%d) \n", this, aDirtyRect.x, aDirtyRect.y, aDirtyRect.width, aDirtyRect.height);
// if there is not web shell paint based on our background color, // if there is not web shell paint based on our background color,
// otherwise let the web shell paint the sub document // otherwise let the web shell paint the sub document
if (!mWebShell) { if (!mSubShell) {
const nsStyleColor* color = const nsStyleColor* color =
(const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color); (const nsStyleColor*)mStyleContext->GetStyleData(eStyleStruct_Color);
aRenderingContext.SetColor(color->mBackgroundColor); aRenderingContext.SetColor(color->mBackgroundColor);
@ -686,53 +684,57 @@ nsHTMLFrameInnerFrame::DidReflow(nsIPresContext* aPresContext,
} }
nsresult nsresult
nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext, nsHTMLFrameInnerFrame::CreateDocShell(nsIPresContext* aPresContext,
const nsSize& aSize) const nsSize& aSize)
{ {
nsresult rv; nsresult rv;
nsIContent* content; nsCOMPtr<nsIContent> parentContent;
GetParentContent(content); GetParentContent(*getter_AddRefs(parentContent));
mWebShell = do_CreateInstance(kWebShellCID); mSubShell = do_CreateInstance(kWebShellCID);
NS_ENSURE_TRUE(mWebShell, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mSubShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mWebShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
// notify the pres shell that a docshell has been created // notify the pres shell that a docshell has been created
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
aPresContext->GetShell(getter_AddRefs(presShell)); aPresContext->GetShell(getter_AddRefs(presShell));
if (presShell) if (presShell)
{ {
nsCOMPtr<nsISupports> webShellAsSupports(do_QueryInterface(mWebShell)); nsCOMPtr<nsISupports> subShellAsSupports(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(webShellAsSupports, NS_ERROR_FAILURE); NS_ENSURE_TRUE(subShellAsSupports, NS_ERROR_FAILURE);
presShell->SetSubShellFor(mContent, webShellAsSupports); presShell->SetSubShellFor(mContent, subShellAsSupports);
} }
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
// pass along marginwidth, marginheight, scrolling so sub document can use it // pass along marginwidth, marginheight, scrolling so sub document can use it
mWebShell->SetMarginWidth(GetMarginWidth(aPresContext, content)); docShell->SetMarginWidth(GetMarginWidth(aPresContext, parentContent));
mWebShell->SetMarginHeight(GetMarginHeight(aPresContext, content)); docShell->SetMarginHeight(GetMarginHeight(aPresContext, parentContent));
nsCompatibility mode; nsCompatibility mode;
aPresContext->GetCompatibilityMode(&mode); aPresContext->GetCompatibilityMode(&mode);
// Current and initial scrolling is set so that all succeeding docs // Current and initial scrolling is set so that all succeeding docs
// will use the scrolling value set here, regardless if scrolling is // will use the scrolling value set here, regardless if scrolling is
// set by viewing a particular document (e.g. XUL turns off scrolling) // set by viewing a particular document (e.g. XUL turns off scrolling)
nsCOMPtr<nsIScrollable> scrollableContainer = do_QueryInterface(mWebShell, &rv); nsCOMPtr<nsIScrollable> scrollableContainer(do_QueryInterface(mSubShell));
if (NS_SUCCEEDED(rv) && scrollableContainer) { if (scrollableContainer) {
scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y, GetScrolling(content, mode)); scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_Y,
scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X, GetScrolling(content, mode)); GetScrolling(parentContent, mode));
scrollableContainer->SetDefaultScrollbarPreferences(nsIScrollable::ScrollOrientation_X,
GetScrolling(parentContent, mode));
} }
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
nsString frameName; nsString frameName;
if (GetName(content, frameName)) { if (GetName(parentContent, frameName)) {
docShellAsItem->SetName(frameName.GetUnicode()); docShellAsItem->SetName(frameName.GetUnicode());
} }
// If our container is a web-shell, inform it that it has a new // If our container is a web-shell, inform it that it has a new
// child. If it's not a web-shell then some things will not operate // child. If it's not a web-shell then some things will not operate
// properly. // properly.
nsISupports* container; nsCOMPtr<nsISupports> container;
aPresContext->GetContainer(&container); aPresContext->GetContainer(getter_AddRefs(container));
if (nsnull != container) { if (container) {
nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(container)); nsCOMPtr<nsIDocShellTreeNode> parentAsNode(do_QueryInterface(container));
if (parentAsNode) { if (parentAsNode) {
nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsNode)); nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(parentAsNode));
@ -744,7 +746,8 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
PRBool isContent; PRBool isContent;
isContent = PR_FALSE; isContent = PR_FALSE;
if (NS_SUCCEEDED(content->GetAttribute(kNameSpaceID_None, typeAtom, value))) { if (NS_SUCCEEDED(parentContent->GetAttribute(kNameSpaceID_None,
typeAtom, value))) {
// we accept "content" and "content-xxx" values. // we accept "content" and "content-xxx" values.
// at time of writing, we expect "xxx" to be "primary", but // at time of writing, we expect "xxx" to be "primary", but
@ -776,9 +779,10 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
value.GetUnicode()); value.GetUnicode());
} }
// connect the container... // connect the container...
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mSubShell));
nsCOMPtr<nsIWebShellContainer> outerContainer(do_QueryInterface(container)); nsCOMPtr<nsIWebShellContainer> outerContainer(do_QueryInterface(container));
if (outerContainer) if (outerContainer)
mWebShell->SetContainer(outerContainer); webShell->SetContainer(outerContainer);
// Make sure all shells have links back to the content element in the // Make sure all shells have links back to the content element in the
@ -797,9 +801,8 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler)); parentShell->GetChromeEventHandler(getter_AddRefs(chromeEventHandler));
} }
mWebShell->SetChromeEventHandler(chromeEventHandler); docShell->SetChromeEventHandler(chromeEventHandler);
} }
NS_RELEASE(container);
} }
float t2p; float t2p;
@ -833,20 +836,14 @@ nsHTMLFrameInnerFrame::CreateWebShell(nsIPresContext* aPresContext,
view->SetVisibility(nsViewVisibility_kHide); view->SetVisibility(nsViewVisibility_kHide);
} }
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell));
NS_ENSURE_TRUE(webShellWin, NS_ERROR_FAILURE);
nsCOMPtr<nsIWidget> widget; nsCOMPtr<nsIWidget> widget;
view->GetWidget(*getter_AddRefs(widget)); view->GetWidget(*getter_AddRefs(widget));
nsRect webBounds(0, 0, NSToCoordRound(aSize.width * t2p),
NSToCoordRound(aSize.height * t2p));
mWebShell->Init(widget->GetNativeData(NS_NATIVE_WIDGET), mSubShell->InitWindow(nsnull, widget, 0, 0, NSToCoordRound(aSize.width * t2p),
webBounds.x, webBounds.y, NSToCoordRound(aSize.height * t2p));
webBounds.width, webBounds.height); mSubShell->Create();
//GetScrolling(content, PR_FALSE));
NS_RELEASE(content);
webShellWin->SetVisibility(PR_TRUE); mSubShell->SetVisibility(PR_TRUE);
return NS_OK; return NS_OK;
} }
@ -868,8 +865,8 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
// use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size // use the max size set in aReflowState by the nsHTMLFrameOuterFrame as our size
if (!mCreatingViewer) { if (!mCreatingViewer) {
nsIContent* content; nsCOMPtr<nsIContent> content;
GetParentContent(content); GetParentContent(*getter_AddRefs(content));
nsAutoString url; nsAutoString url;
PRBool hasURL = GetURL(content, url); PRBool hasURL = GetURL(content, url);
@ -877,9 +874,9 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
// create the web shell // create the web shell
// we do this even if the size is not positive (bug 11762) // we do this even if the size is not positive (bug 11762)
// we do this even if there is no src (bug 16218) // we do this even if there is no src (bug 16218)
if (!mWebShell) { if (!mSubShell) {
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight); nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
rv = CreateWebShell(aPresContext, maxSize); rv = CreateDocShell(aPresContext, maxSize);
#ifdef INCLUDE_XUL #ifdef INCLUDE_XUL
// The URL can be destructively altered when a content shell is made. // The URL can be destructively altered when a content shell is made.
// Refetch it to ensure we have the actual URL to load. // Refetch it to ensure we have the actual URL to load.
@ -887,7 +884,7 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
#endif // INCLUDE_XUL #endif // INCLUDE_XUL
} }
if (mWebShell) { if (mSubShell) {
mCreatingViewer=PR_TRUE; mCreatingViewer=PR_TRUE;
if (hasURL) { if (hasURL) {
// load the document // load the document
@ -906,11 +903,12 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
rv = securityManager->CheckLoadURI(baseURI, newURI, PR_FALSE); rv = securityManager->CheckLoadURI(baseURI, newURI, PR_FALSE);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
webNav->LoadURI(absURL.GetUnicode()); // URL string with a default nsnull value for post Data
} }
} }
} }
NS_RELEASE(content);
} }
aDesiredSize.width = aReflowState.availableWidth; aDesiredSize.width = aReflowState.availableWidth;
@ -925,18 +923,17 @@ nsHTMLFrameInnerFrame::Reflow(nsIPresContext* aPresContext,
aStatus = NS_FRAME_COMPLETE; aStatus = NS_FRAME_COMPLETE;
// resize the sub document // resize the sub document
nsCOMPtr<nsIBaseWindow> webShellWin(do_QueryInterface(mWebShell)); if(mSubShell) {
if(webShellWin) {
float t2p; float t2p;
aPresContext->GetTwipsToPixels(&t2p); aPresContext->GetTwipsToPixels(&t2p);
nsRect subBounds;
webShellWin->GetPositionAndSize(&subBounds.x, &subBounds.y, PRInt32 x = 0;
&subBounds.width, &subBounds.height); PRInt32 y = 0;
subBounds.width = NSToCoordRound(aDesiredSize.width * t2p);
subBounds.height = NSToCoordRound(aDesiredSize.height * t2p); mSubShell->GetPositionAndSize(&x, &y, nsnull, nsnull);
webShellWin->SetPositionAndSize(subBounds.x, subBounds.y, PRInt32 cx = NSToCoordRound(aDesiredSize.width * t2p);
subBounds.width, subBounds.height, PR_FALSE); PRInt32 cy = NSToCoordRound(aDesiredSize.height * t2p);
mSubShell->SetPositionAndSize(x, y, cx, cy, PR_FALSE);
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x", ("exit nsHTMLFrameInnerFrame::Reflow: size=%d,%d rv=%x",
@ -959,14 +956,17 @@ nsHTMLFrameInnerFrame::ReloadURL()
// load a new url if the size is not 0 // load a new url if the size is not 0
if ((mRect.width > 0) && (mRect.height > 0)) { if ((mRect.width > 0) && (mRect.height > 0)) {
if (mWebShell) { if (mSubShell) {
mCreatingViewer=PR_TRUE; mCreatingViewer=PR_TRUE;
// load the document // load the document
nsString absURL; nsString absURL;
TempMakeAbsURL(content, url, absURL); TempMakeAbsURL(content, url, absURL);
rv = mWebShell->LoadURL(absURL.GetUnicode()); // URL string with a default nsnull value for post Data nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mSubShell));
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
rv = webNav->LoadURI(absURL.GetUnicode()); // URL string with a default nsnull value for post Data
} }
} else { } else {
mCreatingViewer = PR_TRUE; mCreatingViewer = PR_TRUE;