This commit is contained in:
conrad%ingress.com 2000-06-26 02:25:16 +00:00
Родитель 9d1f31ba99
Коммит e695347dab
2 изменённых файлов: 159 добавлений и 59 удалений

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

@ -24,12 +24,16 @@
// Local Includes // Local Includes
#include "CWebBrowserChrome.h" #include "CWebBrowserChrome.h"
#include "CBrowserWindow.h" #include "CBrowserWindow.h"
#include "CBrowserShell.h"
#include "nsIGenericFactory.h" #include "nsIGenericFactory.h"
#include "nsString.h" #include "nsString.h"
#include "nsXPIDLString.h" #include "nsXPIDLString.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIWebProgress.h" #include "nsIWebProgress.h"
#include "nsIDocShellTreeItem.h"
#include "nsIRequest.h"
#include "nsIChannel.h"
#include "UMacUnicode.h" #include "UMacUnicode.h"
#include "ApplIDs.h" #include "ApplIDs.h"
@ -43,19 +47,30 @@
// Interfaces needed to be included // Interfaces needed to be included
// CIDs // Constants
const PRInt32 kGrowIconSize = 15;
// Static Variables
vector<CWebBrowserChrome*> CWebBrowserChrome::mgBrowserList;
//***************************************************************************** //*****************************************************************************
//*** CWebBrowserChrome: Object Management //*** CWebBrowserChrome: Object Management
//***************************************************************************** //*****************************************************************************
CWebBrowserChrome::CWebBrowserChrome() : mBrowserWindow(nsnull) CWebBrowserChrome::CWebBrowserChrome() :
mBrowserWindow(nsnull), mBrowserShell(nsnull)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
mgBrowserList.push_back(this);
} }
CWebBrowserChrome::~CWebBrowserChrome() CWebBrowserChrome::~CWebBrowserChrome()
{ {
vector<CWebBrowserChrome*>::iterator iter = find(mgBrowserList.begin(), mgBrowserList.end(), this);
if (iter != mgBrowserList.end())
mgBrowserList.erase(iter);
} }
//***************************************************************************** //*****************************************************************************
@ -113,15 +128,18 @@ NS_IMETHODIMP CWebBrowserChrome::SetOverLink(const PRUnichar* aLink)
NS_IMETHODIMP CWebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser) NS_IMETHODIMP CWebBrowserChrome::GetWebBrowser(nsIWebBrowser** aWebBrowser)
{ {
NS_ENSURE_ARG_POINTER(aWebBrowser); NS_ENSURE_ARG_POINTER(aWebBrowser);
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
*aWebBrowser = mWebBrowser; mBrowserShell->GetWebBrowser(aWebBrowser);
NS_IF_ADDREF(*aWebBrowser);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser) NS_IMETHODIMP CWebBrowserChrome::SetWebBrowser(nsIWebBrowser* aWebBrowser)
{ {
mWebBrowser = aWebBrowser; NS_ENSURE_ARG(aWebBrowser); // Passing nsnull is NOT OK
NS_ENSURE_TRUE(mBrowserShell, NS_ERROR_NOT_INITIALIZED);
mBrowserShell->SetWebBrowser(aWebBrowser);
return NS_OK; return NS_OK;
} }
@ -138,24 +156,65 @@ NS_IMETHODIMP CWebBrowserChrome::SetChromeMask(PRUint32 aChromeMask)
} }
NS_IMETHODIMP CWebBrowserChrome::GetNewBrowser(PRUint32 chromeMask, nsIWebBrowser **webBrowser) NS_IMETHODIMP CWebBrowserChrome::GetNewBrowser(PRUint32 chromeMask, nsIWebBrowser **aWebBrowser)
{ {
NS_ERROR("Haven't Implemented this yet"); NS_ENSURE_ARG_POINTER(aWebBrowser);
return NS_ERROR_FAILURE; *aWebBrowser = nsnull;
// Note: For now, until we can create a window with specific chrome flags, this will
// put up a plain window without navigation controls or location text. This is
// most likely being used to pop up an add.
CBrowserWindow *theWindow;
try
{
// CreateWindow can throw an we're being called from mozilla, so we need to catch
theWindow = dynamic_cast<CBrowserWindow*>(LWindow::CreateWindow(wind_PlainBrowserWindow, LCommander::GetTopCommander()));
}
catch (...)
{
theWindow = nsnull;
}
NS_ENSURE_TRUE(theWindow, NS_ERROR_FAILURE);
CBrowserShell *aBrowserShell = theWindow->GetBrowserShell();
NS_ENSURE_TRUE(aBrowserShell, NS_ERROR_FAILURE);
return aBrowserShell->GetWebBrowser(aWebBrowser);
} }
NS_IMETHODIMP CWebBrowserChrome::FindNamedBrowserItem(const PRUnichar* aName, NS_IMETHODIMP CWebBrowserChrome::FindNamedBrowserItem(const PRUnichar* aName,
nsIDocShellTreeItem ** aWebBrowser) nsIDocShellTreeItem ** aBrowserItem)
{ {
NS_ERROR("Haven't Implemented this yet"); NS_ENSURE_ARG(aName);
return NS_ERROR_FAILURE; NS_ENSURE_ARG_POINTER(aBrowserItem);
*aBrowserItem = nsnull;
vector<CWebBrowserChrome*>::iterator iter = mgBrowserList.begin();
while (iter < mgBrowserList.end())
{
CWebBrowserChrome* aChrome = *iter++;
if (aChrome == this)
continue; // Our tree has already been searched???
NS_ENSURE_TRUE(aChrome->BrowserShell(), NS_ERROR_FAILURE);
nsCOMPtr<nsIWebBrowser> webBrowser;
aChrome->BrowserShell()->GetWebBrowser(getter_AddRefs(webBrowser));
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(webBrowser));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
docShellAsItem->FindItemWithName(aName, NS_STATIC_CAST(nsIWebBrowserChrome*, this), aBrowserItem);
if (*aBrowserItem)
break;
}
return NS_OK; // Return OK even if we didn't find it???
} }
NS_IMETHODIMP CWebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) NS_IMETHODIMP CWebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{ {
NS_ERROR("Haven't Implemented this yet"); mBrowserWindow->ResizeFrameTo(aCX, aCY + kGrowIconSize, true);
return NS_ERROR_FAILURE; return NS_OK;
} }
@ -186,31 +245,28 @@ CWebBrowserChrome::GetPersistence(PRBool* aPersistX, PRBool* aPersistY,
// CWebBrowserChrome::nsIWebProgressListener // CWebBrowserChrome::nsIWebProgressListener
//***************************************************************************** //*****************************************************************************
NS_IMETHODIMP CWebBrowserChrome::OnProgressChange(nsIChannel *channel, PRInt32 curSelfProgress, PRInt32 maxSelfProgress, PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
{
return NS_OK;
}
NS_IMETHODIMP CWebBrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRequest *request, NS_IMETHODIMP CWebBrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRequest *request,
PRInt32 curSelfProgress, PRInt32 maxSelfProgress, PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
PRInt32 curTotalProgress, PRInt32 maxTotalProgress) PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
{ {
return NS_OK; NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
return mBrowserWindow->OnProgressChange(progress, request,
curSelfProgress, maxSelfProgress,
curTotalProgress, maxTotalProgress);
} }
NS_IMETHODIMP CWebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request, NS_IMETHODIMP CWebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
PRInt32 progressStateFlags nsresult status) PRInt32 progressStateFlags, PRUint32 status)
{ {
NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
if (progressStateFlags & flag_is_network) { if (progressStateFlags & flag_is_network) {
if (progressStateFlags & flag_start) if (progressStateFlags & flag_start)
mBrowserWindow->OnStatusNetStart(channel); mBrowserWindow->OnStatusNetStart(progress, request, progressStateFlags, status);
else if (progressStateFlags & flag_stop) else if (progressStateFlags & flag_stop)
mBrowserWindow->OnStatusNetStop(channel); mBrowserWindow->OnStatusNetStop(progress, request, progressStateFlags, status);
} }
/// else if (progressStatusFlags & nsIWebProgress::flag_net_dns)
/// mBrowserWindow->OnStatusDNS(channel);
return NS_OK; return NS_OK;
} }
@ -262,57 +318,81 @@ NS_IMETHODIMP CWebBrowserChrome::Destroy()
NS_IMETHODIMP CWebBrowserChrome::SetPosition(PRInt32 x, PRInt32 y) NS_IMETHODIMP CWebBrowserChrome::SetPosition(PRInt32 x, PRInt32 y)
{ {
//XXX First Check In NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
mBrowserWindow->MoveWindowTo(x, y);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::GetPosition(PRInt32* x, PRInt32* y) NS_IMETHODIMP CWebBrowserChrome::GetPosition(PRInt32* x, PRInt32* y)
{ {
NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ENSURE_ARG_POINTER(x && y); NS_ENSURE_ARG_POINTER(x && y);
//XXX First Check In Rect bounds;
NS_ASSERTION(PR_FALSE, "Not Yet Implemented"); mBrowserWindow->GetGlobalBounds(bounds);
*x = bounds.left;
*y = bounds.top;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint) NS_IMETHODIMP CWebBrowserChrome::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint)
{ {
//XXX First Check In NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
mBrowserWindow->ResizeFrameTo(cx, cy + kGrowIconSize, fRepaint);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::GetSize(PRInt32* cx, PRInt32* cy) NS_IMETHODIMP CWebBrowserChrome::GetSize(PRInt32* cx, PRInt32* cy)
{ {
NS_ENSURE_ARG_POINTER(cx && cy); NS_ENSURE_ARG_POINTER(cx && cy);
NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
//XXX First Check In Rect bounds;
NS_ASSERTION(PR_FALSE, "Not Yet Implemented"); mBrowserWindow->GetGlobalBounds(bounds);
*cx = bounds.right - bounds.left;
*cy = bounds.bottom - bounds.top - kGrowIconSize;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, NS_IMETHODIMP CWebBrowserChrome::SetPositionAndSize(PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy, PRBool fRepaint)
PRInt32 cy, PRBool fRepaint)
{ {
//XXX First Check In NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
Rect bounds;
bounds.top = y;
bounds.left = x;
bounds.bottom = y + cy + kGrowIconSize;
bounds.right = x + cx;
mBrowserWindow->DoSetBounds(bounds);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, NS_IMETHODIMP CWebBrowserChrome::GetPositionAndSize(PRInt32* x, PRInt32* y, PRInt32* cx, PRInt32* cy)
PRInt32* cy)
{ {
NS_ENSURE_ARG_POINTER(x && y && cx && cy);
//XXX First Check In NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
Rect bounds;
mBrowserWindow->GetGlobalBounds(bounds);
*x = bounds.left;
*y = bounds.top;
*cx = bounds.right - bounds.left;
*cy = bounds.bottom - bounds.top - kGrowIconSize;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::Repaint(PRBool aForce) NS_IMETHODIMP CWebBrowserChrome::Repaint(PRBool aForce)
{ {
//XXX First Check In NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
mBrowserWindow->Refresh();
if (aForce)
mBrowserWindow->UpdatePort();
return NS_OK; return NS_OK;
} }
@ -348,16 +428,24 @@ NS_IMETHODIMP CWebBrowserChrome::SetParentNativeWindow(nativeWindow aParentNativ
NS_IMETHODIMP CWebBrowserChrome::GetVisibility(PRBool* aVisibility) NS_IMETHODIMP CWebBrowserChrome::GetVisibility(PRBool* aVisibility)
{ {
NS_ENSURE_ARG_POINTER(aVisibility); NS_ENSURE_ARG_POINTER(aVisibility);
NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
//XXX First Check In *aVisibility = mBrowserWindow->IsVisible();
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::SetVisibility(PRBool aVisibility) NS_IMETHODIMP CWebBrowserChrome::SetVisibility(PRBool aVisibility)
{ {
//XXX First Check In NS_ENSURE_TRUE(mBrowserWindow, NS_ERROR_NOT_INITIALIZED);
NS_ASSERTION(PR_FALSE, "Not Yet Implemented");
if (aVisibility)
{
mBrowserWindow->Show();
mBrowserWindow->Select();
}
else
mBrowserWindow->Hide();
return NS_OK; return NS_OK;
} }
@ -431,6 +519,7 @@ NS_IMETHODIMP CWebBrowserChrome::Alert(const PRUnichar *dialogTitle, const PRUni
msgText->SetDescriptor(aStr); msgText->SetDescriptor(aStr);
theDialog->Show(); theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop while (true) // This is our modal dialog event loop
{ {
@ -457,6 +546,7 @@ NS_IMETHODIMP CWebBrowserChrome::Confirm(const PRUnichar *dialogTitle, const PRU
msgText->SetDescriptor(aStr); msgText->SetDescriptor(aStr);
theDialog->Show(); theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop while (true) // This is our modal dialog event loop
{ {
@ -495,6 +585,7 @@ NS_IMETHODIMP CWebBrowserChrome::ConfirmCheck(const PRUnichar *dialogTitle, cons
checkBox->SetValue(*checkValue ? 1 : 0); checkBox->SetValue(*checkValue ? 1 : 0);
theDialog->Show(); theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop while (true) // This is our modal dialog event loop
{ {
@ -516,7 +607,7 @@ NS_IMETHODIMP CWebBrowserChrome::ConfirmCheck(const PRUnichar *dialogTitle, cons
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP CWebBrowserChrome::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval) NS_IMETHODIMP CWebBrowserChrome::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval)
{ {
NS_ENSURE_ARG_POINTER(result); NS_ENSURE_ARG_POINTER(result);
NS_ENSURE_ARG_POINTER(_retval); NS_ENSURE_ARG_POINTER(_retval);
@ -534,6 +625,7 @@ NS_IMETHODIMP CWebBrowserChrome::Prompt(const PRUnichar *dialogTitle, const PRUn
theDialog->SetLatentSub(responseText); theDialog->SetLatentSub(responseText);
theDialog->Show(); theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop while (true) // This is our modal dialog event loop
{ {
@ -561,7 +653,7 @@ NS_IMETHODIMP CWebBrowserChrome::Prompt(const PRUnichar *dialogTitle, const PRUn
return resultErr; return resultErr;
} }
NS_IMETHODIMP CWebBrowserChrome::PromptUsernameAndPassword(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRBool persistPassword, PRUnichar **user, PRUnichar **pwd, PRBool *_retval) NS_IMETHODIMP CWebBrowserChrome::PromptUsernameAndPassword(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, PRUnichar **user, PRUnichar **pwd, PRBool *_retval)
{ {
NS_ENSURE_ARG_POINTER(user); NS_ENSURE_ARG_POINTER(user);
NS_ENSURE_ARG_POINTER(pwd); NS_ENSURE_ARG_POINTER(pwd);
@ -581,6 +673,7 @@ NS_IMETHODIMP CWebBrowserChrome::PromptUsernameAndPassword(const PRUnichar *dial
theDialog->SetLatentSub(userText); theDialog->SetLatentSub(userText);
theDialog->Show(); theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop while (true) // This is our modal dialog event loop
{ {
@ -615,7 +708,7 @@ NS_IMETHODIMP CWebBrowserChrome::PromptUsernameAndPassword(const PRUnichar *dial
return resultErr; return resultErr;
} }
NS_IMETHODIMP CWebBrowserChrome::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRBool persistPassword, PRUnichar **pwd, PRBool *_retval) NS_IMETHODIMP CWebBrowserChrome::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *passwordRealm, PRUint32 savePassword, PRUnichar **pwd, PRBool *_retval)
{ {
NS_ENSURE_ARG_POINTER(pwd); NS_ENSURE_ARG_POINTER(pwd);
NS_ENSURE_ARG_POINTER(_retval); NS_ENSURE_ARG_POINTER(_retval);
@ -633,6 +726,7 @@ NS_IMETHODIMP CWebBrowserChrome::PromptPassword(const PRUnichar *dialogTitle, co
theDialog->SetLatentSub(pwdText); theDialog->SetLatentSub(pwdText);
theDialog->Show(); theDialog->Show();
theDialog->Select();
while (true) // This is our modal dialog event loop while (true) // This is our modal dialog event loop
{ {
@ -683,13 +777,13 @@ NS_IMETHODIMP CWebBrowserChrome::UniversalDialog(const PRUnichar *inTitleMessage
// CWebBrowserChrome: Accessors // CWebBrowserChrome: Accessors
//***************************************************************************** //*****************************************************************************
void CWebBrowserChrome::BrowserWindow(CBrowserWindow* aBrowserWindow) CBrowserWindow*& CWebBrowserChrome::BrowserWindow()
{
mBrowserWindow = aBrowserWindow;
}
CBrowserWindow* CWebBrowserChrome::BrowserWindow()
{ {
return mBrowserWindow; return mBrowserWindow;
} }
CBrowserShell*& CWebBrowserChrome::BrowserShell()
{
return mBrowserShell;
}

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

@ -37,7 +37,11 @@
// Other // Other
#include "nsIWebBrowser.h" #include "nsIWebBrowser.h"
#include <vector>
using namespace std;
class CBrowserWindow; class CBrowserWindow;
class CBrowserShell;
class CWebBrowserChrome : public nsIWebBrowserChrome, class CWebBrowserChrome : public nsIWebBrowserChrome,
public nsIWebProgressListener, public nsIWebProgressListener,
@ -59,12 +63,14 @@ protected:
CWebBrowserChrome(); CWebBrowserChrome();
virtual ~CWebBrowserChrome(); virtual ~CWebBrowserChrome();
void BrowserWindow(CBrowserWindow* aBrowserWindow); CBrowserWindow*& BrowserWindow();
CBrowserWindow* BrowserWindow(); CBrowserShell*& BrowserShell();
protected: protected:
CBrowserWindow* mBrowserWindow; CBrowserWindow* mBrowserWindow;
nsCOMPtr<nsIWebBrowser> mWebBrowser; CBrowserShell* mBrowserShell;
static vector<CWebBrowserChrome*> mgBrowserList;
}; };
#endif /* __CWebBrowserChrome__ */ #endif /* __CWebBrowserChrome__ */