Implemented a number of the Positioning / Sizing routines.

This commit is contained in:
tbogard@aol.net
1999-11-13 08:09:16 +00:00
parent 85f7dda1c7
commit acb48beafb
2 changed files with 119 additions and 195 deletions

View File

@@ -61,15 +61,14 @@ nsDocShell::nsDocShell() : mCreated(PR_FALSE), mContentListener(nsnull),
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
mBaseInitInfo = new nsDocShellInitInfo();
} }
nsDocShell::~nsDocShell() nsDocShell::~nsDocShell()
{ {
if(mBaseInitInfo) if(mInitInfo)
{ {
delete mBaseInitInfo; delete mInitInfo;
mBaseInitInfo = nsnull; mInitInfo = nsnull;
} }
if(mContentListener) if(mContentListener)
@@ -584,7 +583,8 @@ NS_IMETHODIMP nsDocShell::CutSelection()
NS_IMETHODIMP nsDocShell::GetCutable(PRBool* aCutable) NS_IMETHODIMP nsDocShell::GetCutable(PRBool* aCutable)
{ {
NS_ENSURE_ARG_POINTER(aCutable); NS_ENSURE_ARG_POINTER(aCutable);
//XXX Implement
//XXXIMPL Implement
//Should check to find the current focused object. Then see if it can //Should check to find the current focused object. Then see if it can
//be cut out of. For now the answer is always no since CutSelection() //be cut out of. For now the answer is always no since CutSelection()
// has not been implemented. // has not been implemented.
@@ -599,7 +599,7 @@ NS_IMETHODIMP nsDocShell::Paste()
NS_ENSURE_SUCCESS(GetPasteable(&pasteable), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(GetPasteable(&pasteable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(pasteable, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(pasteable, NS_ERROR_UNEXPECTED);
//XXX Implement //XXXIMPL Implement
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@@ -607,7 +607,7 @@ NS_IMETHODIMP nsDocShell::GetPasteable(PRBool* aPasteable)
{ {
NS_ENSURE_ARG_POINTER(aPasteable); NS_ENSURE_ARG_POINTER(aPasteable);
//XXX Implement //XXXIMPL Implement
//Should check to find the current focused object. Then see if it can //Should check to find the current focused object. Then see if it can
//be pasted into. For now the answer is always no since Paste() //be pasted into. For now the answer is always no since Paste()
// has not been implemented. // has not been implemented.
@@ -626,15 +626,14 @@ NS_IMETHODIMP nsDocShell::Save()
NS_ENSURE_SUCCESS(GetSaveable(&saveable), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(GetSaveable(&saveable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(saveable, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(saveable, NS_ERROR_UNEXPECTED);
//XXX First Check //XXXIMPL
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
NS_IMETHODIMP nsDocShell::GetSaveable(PRBool* saveable) NS_IMETHODIMP nsDocShell::GetSaveable(PRBool* saveable)
{ {
NS_ENSURE_ARG_POINTER(saveable); NS_ENSURE_ARG_POINTER(saveable);
//XXX First Check // XXXIMPL
// XXX Implement
// Should check if a doc is loaded and if it is in a state that that is // Should check if a doc is loaded and if it is in a state that that is
// ready to save. For now the answer is always no since saving isn't // ready to save. For now the answer is always no since saving isn't
// implemented. // implemented.
@@ -650,14 +649,14 @@ NS_IMETHODIMP nsDocShell::Print()
NS_ENSURE_SUCCESS(GetPrintable(&printable), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(GetPrintable(&printable), NS_ERROR_FAILURE);
NS_ENSURE_TRUE(printable, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(printable, NS_ERROR_UNEXPECTED);
//XXX First Check //XXXIMPL
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
NS_IMETHODIMP nsDocShell::GetPrintable(PRBool* printable) NS_IMETHODIMP nsDocShell::GetPrintable(PRBool* printable)
{ {
NS_ENSURE_ARG_POINTER(printable); NS_ENSURE_ARG_POINTER(printable);
// XXX Implement // XXXIMPL
// Should check if a doc is loaded and if it is in a state that that is // Should check if a doc is loaded and if it is in a state that that is
// ready to print. For now the answer is always no since printing isn't // ready to print. For now the answer is always no since printing isn't
// implemented. // implemented.
@@ -666,8 +665,6 @@ NS_IMETHODIMP nsDocShell::GetPrintable(PRBool* printable)
return NS_OK; return NS_OK;
} }
//***************************************************************************** //*****************************************************************************
// nsDocShell::nsIDocShellContainer // nsDocShell::nsIDocShellContainer
//***************************************************************************** //*****************************************************************************
@@ -692,15 +689,18 @@ NS_IMETHODIMP nsDocShell::AddChild(nsIDocShell *aChild)
if (childAsHTMLDocShell) if (childAsHTMLDocShell)
{ {
PRUnichar *defaultCharset=nsnull; PRUnichar *defaultCharset=nsnull;
NS_ENSURE_SUCCESS(GetDefaultCharacterSet(&defaultCharset), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(GetDefaultCharacterSet(&defaultCharset),
NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetDefaultCharacterSet(defaultCharset), NS_ERROR_FAILURE); NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetForceCharacterSet(mForceCharacterSet.GetUnicode()), NS_ERROR_FAILURE); NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetDefaultCharacterSet(
defaultCharset), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(childAsHTMLDocShell->SetForceCharacterSet(
mForceCharacterSet.GetUnicode()), NS_ERROR_FAILURE);
} }
return NS_OK; return NS_OK;
} }
// XXX: tiny semantic change from webshell. aChild is only effected if it was actually a child of this docshell // tiny semantic change from webshell. aChild is only effected if it was actually a child of this docshell
NS_IMETHODIMP nsDocShell::RemoveChild(nsIDocShell *aChild) NS_IMETHODIMP nsDocShell::RemoveChild(nsIDocShell *aChild)
{ {
NS_ENSURE_ARG_POINTER(aChild); NS_ENSURE_ARG_POINTER(aChild);
@@ -766,13 +766,13 @@ NS_IMETHODIMP nsDocShell::InitWindow(nativeWindow parentNativeWindow,
nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy) nsIWidget* parentWidget, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
{ {
NS_ENSURE_ARG(parentWidget); // DocShells must get a widget for a parent NS_ENSURE_ARG(parentWidget); // DocShells must get a widget for a parent
NS_ENSURE_STATE(!mCreated && mBaseInitInfo); NS_ENSURE_STATE(!mCreated && InitInfo());
mParentWidget = parentWidget; mParentWidget = parentWidget;
mBaseInitInfo->x = x; mInitInfo->x = x;
mBaseInitInfo->y = y; mInitInfo->y = y;
mBaseInitInfo->cx = cx; mInitInfo->cx = cx;
mBaseInitInfo->cy = cy; mInitInfo->cy = cy;
return NS_OK; return NS_OK;
} }
@@ -801,37 +801,15 @@ NS_IMETHODIMP nsDocShell::Destroy()
NS_IMETHODIMP nsDocShell::SetPosition(PRInt32 x, PRInt32 y) NS_IMETHODIMP nsDocShell::SetPosition(PRInt32 x, PRInt32 y)
{ {
if(!mCreated) if(mContentViewer)
NS_ENSURE_SUCCESS(mContentViewer->Move(x, y), NS_ERROR_FAILURE);
else if(InitInfo())
{ {
mBaseInitInfo->x = x; mInitInfo->x = x;
mBaseInitInfo->y = y; mInitInfo->y = y;
} }
else else
{ NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
/* XXX Implement below is code from old webShell
We don't have a heavy-weight window, we want to talk to our view I think.
We also don't want to duplicate the bounds locally. No need, let the
view keep up with that.
PRInt32 w, h;
nsresult rv = GetSize(w, h);
if (NS_FAILED(rv)) { return rv; }
PRInt32 borderWidth = 0;
PRInt32 borderHeight = 0;
if (mWindow)
{
mWindow->GetBorderSize(borderWidth, borderHeight);
// Don't have the widget repaint. Layout will generate repaint requests
// during reflow
mWindow->Resize(aX, aY, w, h, PR_FALSE);
}
mBounds.SetRect(aX,aY,w,h); // set the webshells bounds
return rv;
*/
}
return NS_OK; return NS_OK;
} }
@@ -840,75 +818,47 @@ NS_IMETHODIMP nsDocShell::GetPosition(PRInt32* x, PRInt32* y)
{ {
NS_ENSURE_ARG_POINTER(x && y); NS_ENSURE_ARG_POINTER(x && y);
if(!mCreated) if(mContentViewer)
{ {
*x = mBaseInitInfo->x; nsRect bounds;
*y = mBaseInitInfo->y;
NS_ENSURE_SUCCESS(mContentViewer->GetBounds(bounds), NS_ERROR_FAILURE);
*x = bounds.x;
*y = bounds.y;
}
else if(InitInfo())
{
*x = mInitInfo->x;
*y = mInitInfo->y;
} }
else else
{ NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
/* XXX Implement below is code from old webShell
We don't have a heavy-weight window, we want to talk to our view I think.
We also don't want to duplicate the bounds locally. No need, let the
view keep up with that.
nsRect result;
if (nsnull != mWindow) {
mWindow->GetClientBounds(result);
} else {
result = mBounds;
}
*aX = result.x;
*aY = result.y;
return NS_OK;
*/
}
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDocShell::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint) NS_IMETHODIMP nsDocShell::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint)
{ {
if(!mCreated) if(mContentViewer)
{ {
mBaseInitInfo->cx = cx; PRInt32 x;
mBaseInitInfo->cy = cy; PRInt32 y;
NS_ENSURE_SUCCESS(GetPosition(&x, &y), NS_ERROR_FAILURE);
//XXX Border figured in here or is that handled elsewhere?
nsRect bounds(x, y, cx, cy);
NS_ENSURE_SUCCESS(mContentViewer->SetBounds(bounds), NS_ERROR_FAILURE);
}
else if(InitInfo())
{
mInitInfo->cx = cx;
mInitInfo->cy = cy;
} }
else else
{ NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
/* XXX Implement below is code from old webShell
We don't have a heavy-weight window, we want to talk to our view I think.
We also don't want to duplicate the bounds locally. No need, let the
view keep up with that.
PRInt32 x, y;
nsresult rv = GetPosition(x, y);
if (NS_FAILED(rv)) { return rv; }
PRInt32 borderWidth = 0;
PRInt32 borderHeight = 0;
if (mWindow)
{
mWindow->GetBorderSize(borderWidth, borderHeight);
// Don't have the widget repaint. Layout will generate repaint requests
// during reflow
mWindow->Resize(x, y, aCX, aCY, PR_FALSE);
}
mBounds.SetRect(x, y, aCX, aCY); // set the webshells bounds --dwc0001
// Set the size of the content area, which is the size of the window
// minus the borders
if (nsnull != mContentViewer) {
nsRect rr(0, 0, aCX-(borderWidth*2), aCY-(borderHeight*2));
mContentViewer->SetBounds(rr);
}
return rv;
*/
}
return NS_OK; return NS_OK;
} }
@@ -917,31 +867,22 @@ NS_IMETHODIMP nsDocShell::GetSize(PRInt32* cx, PRInt32* cy)
{ {
NS_ENSURE_ARG_POINTER(cx && cy); NS_ENSURE_ARG_POINTER(cx && cy);
if(!mCreated) if(mContentViewer)
{ {
*cx = mBaseInitInfo->cx; nsRect bounds;
*cy = mBaseInitInfo->cy;
NS_ENSURE_SUCCESS(mContentViewer->GetBounds(bounds), NS_ERROR_FAILURE);
*cx = bounds.width;
*cy = bounds.height;
}
else if(InitInfo())
{
*cx = mInitInfo->cx;
*cy = mInitInfo->cy;
} }
else else
{ NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
/* XXX Implement below is code from old webShell
We don't have a heavy-weight window, we want to talk to our view I think.
We also don't want to duplicate the bounds locally. No need, let the
view keep up with that.
nsRect result;
if (nsnull != mWindow) {
mWindow->GetClientBounds(result);
} else {
result = mBounds;
}
*aCX = result.width;
*aCY = result.height;
return NS_OK;
*/
}
return NS_OK; return NS_OK;
} }
@@ -949,51 +890,29 @@ NS_IMETHODIMP nsDocShell::GetSize(PRInt32* cx, PRInt32* cy)
NS_IMETHODIMP nsDocShell::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, NS_IMETHODIMP nsDocShell::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx,
PRInt32 cy, PRBool fRepaint) PRInt32 cy, PRBool fRepaint)
{ {
if(!mCreated) if(mContentViewer)
{ {
mBaseInitInfo->x = x; //XXX Border figured in here or is that handled elsewhere?
mBaseInitInfo->y = y; nsRect bounds(x, y, cx, cy);
mBaseInitInfo->cx = cx;
mBaseInitInfo->cy = cy; NS_ENSURE_SUCCESS(mContentViewer->SetBounds(bounds), NS_ERROR_FAILURE);
}
else if(InitInfo())
{
mInitInfo->x = x;
mInitInfo->y = y;
mInitInfo->cx = cx;
mInitInfo->cy = cy;
} }
else else
{ NS_ENSURE_TRUE(PR_FALSE, NS_ERROR_FAILURE);
// XXX Do normal size and position stuff. Could just call
// Size and then Position, but underlying control probably supports
// some optimized setting of both like this.
/* XXX Implement below is code from old webShell
We don't have a heavy-weight window, we want to talk to our view I think.
We also don't want to duplicate the bounds locally. No need, let the
view keep up with that.
PRInt32 borderWidth = 0;
PRInt32 borderHeight = 0;
if (mWindow)
{
mWindow->GetBorderSize(borderWidth, borderHeight);
// Don't have the widget repaint. Layout will generate repaint requests
// during reflow
mWindow->Resize(aX, aY, aCX, aCY, PR_FALSE);
}
mBounds.SetRect(aX, aY, aCX, aCY); // set the webshells bounds --dwc0001
// Set the size of the content area, which is the size of the window
// minus the borders
if (nsnull != mContentViewer) {
nsRect rr(0, 0, aCX-(borderWidth*2), aCY-(borderHeight*2));
mContentViewer->SetBounds(rr);
}
return rv;
*/
}
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDocShell::Repaint(PRBool fForce) NS_IMETHODIMP nsDocShell::Repaint(PRBool fForce)
{ {
//XXX First Check //XXX First Check
/** /**
* Tell the window to repaint itself * Tell the window to repaint itself
@@ -1061,7 +980,7 @@ NS_IMETHODIMP nsDocShell::GetVisibility(PRBool* aVisibility)
NS_ENSURE_ARG_POINTER(aVisibility); NS_ENSURE_ARG_POINTER(aVisibility);
if(!mCreated) { if(!mCreated) {
*aVisibility = mBaseInitInfo->visible; *aVisibility = mInitInfo->visible;
} }
else else
{ {
@@ -1097,9 +1016,11 @@ NS_IMETHODIMP nsDocShell::GetVisibility(PRBool* aVisibility)
NS_IMETHODIMP nsDocShell::SetVisibility(PRBool visibility) NS_IMETHODIMP nsDocShell::SetVisibility(PRBool visibility)
{ {
if(!mCreated) if(!mCreated)
mBaseInitInfo->visible = visibility; mInitInfo->visible = visibility;
else else
{ {
// NS_ENSURE_SUCCESS(mContentViewer->
// XXX Set underlying control visibility // XXX Set underlying control visibility
} }
@@ -1720,6 +1641,13 @@ NS_IMETHODIMP nsDocShell::HandleUnknownContentType(nsIDocumentLoader* aLoader,
// nsDocShell: Helper Routines // nsDocShell: Helper Routines
//***************************************************************************** //*****************************************************************************
nsDocShellInitInfo* nsDocShell::InitInfo()
{
if(mInitInfo)
return mInitInfo;
return mInitInfo = new nsDocShellInitInfo();
}
nsresult nsDocShell::GetChildOffset(nsIDOMNode *aChild, nsIDOMNode* aParent, nsresult nsDocShell::GetChildOffset(nsIDOMNode *aChild, nsIDOMNode* aParent,
PRInt32* aOffset) PRInt32* aOffset)
{ {
@@ -2053,17 +1981,12 @@ NS_IMETHODIMP nsDocShell::InsertDocumentInDocTree()
NS_IMETHODIMP nsDocShell::DestroyChildren() NS_IMETHODIMP nsDocShell::DestroyChildren()
{ {
PRInt32 i, n = mChildren.Count(); PRInt32 i, n = mChildren.Count();
nsCOMPtr<nsIDocShell> shell;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
nsIDocShell* shell = (nsIDocShell*) mChildren.ElementAt(i); shell = (nsIDocShell*) mChildren.ElementAt(i);
NS_WARN_IF_FALSE(shell, "docshell has null child"); if(!NS_WARN_IF_FALSE(shell, "docshell has null child"))
if (shell)
{
shell->SetParent(nsnull); shell->SetParent(nsnull);
// XXX: will shells have a separate Destroy? See webshell::Destroy for what it does
//shell->Destroy();
NS_RELEASE(shell);
}
} }
mChildren.Clear(); mChildren.Clear();
return NS_OK; return NS_OK;

View File

@@ -106,6 +106,7 @@ protected:
nsDocShell(); nsDocShell();
virtual ~nsDocShell(); virtual ~nsDocShell();
nsDocShellInitInfo* InitInfo();
nsresult GetChildOffset(nsIDOMNode* aChild, nsIDOMNode* aParent, nsresult GetChildOffset(nsIDOMNode* aChild, nsIDOMNode* aParent,
PRInt32* aOffset); PRInt32* aOffset);
nsresult GetRootScrollableView(nsIScrollableView** aOutScrollView); nsresult GetRootScrollableView(nsIScrollableView** aOutScrollView);
@@ -137,7 +138,7 @@ protected:
nsString mName; nsString mName;
nsVoidArray mChildren; nsVoidArray mChildren;
nsDSURIContentListener* mContentListener; nsDSURIContentListener* mContentListener;
nsDocShellInitInfo* mBaseInitInfo; nsDocShellInitInfo* mInitInfo;
nsCOMPtr<nsIContentViewer> mContentViewer; nsCOMPtr<nsIContentViewer> mContentViewer;
nsCOMPtr<nsIDocumentLoader>mDocLoader; nsCOMPtr<nsIDocumentLoader>mDocLoader;
nsCOMPtr<nsIDocumentLoaderObserver> mDocLoaderObserver; nsCOMPtr<nsIDocumentLoaderObserver> mDocLoaderObserver;