Cleaned up code style, indentation, replaced tabs with spaces. Added dummy implementations of nsITooltipListener and nsIContextMenuListener.

This commit is contained in:
locka%iol.ie 2001-03-28 11:20:18 +00:00
Родитель c236e8b164
Коммит 0807b595b9
5 изменённых файлов: 322 добавлений и 228 удалений

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
@ -19,6 +19,7 @@
* Contributor(s):
*/
// XXX Windows.h should not be needed. This file is meant to be platform neutral
#include <windows.h> // for cheesy nsIPrompt implementation
// Mozilla Includes
@ -46,7 +47,7 @@
WebBrowserChrome::WebBrowserChrome()
{
NS_INIT_REFCNT();
NS_INIT_REFCNT();
mNativeWindow = nsnull;
}
@ -92,7 +93,8 @@ nsresult WebBrowserChrome::CreateBrowser(PRInt32 aX, PRInt32 aY,
// The window has been created. Now register for history notifications
mWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsISHistoryListener));
if (mWebBrowser) {
if (mWebBrowser)
{
*aBrowser = mWebBrowser;
NS_ADDREF(*aBrowser);
return NS_OK;
@ -117,6 +119,8 @@ NS_INTERFACE_MAP_BEGIN(WebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIPrompt)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_END
//*****************************************************************************
@ -125,15 +129,18 @@ NS_INTERFACE_MAP_END
NS_IMETHODIMP WebBrowserChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
NS_ENSURE_ARG_POINTER(aInstancePtr);
*aInstancePtr = 0;
if (aIID.Equals(NS_GET_IID(nsIDOMWindow))) {
if (mWebBrowser)
return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
return NS_ERROR_NOT_INITIALIZED;
}
return QueryInterface(aIID, aInstancePtr);
*aInstancePtr = 0;
if (aIID.Equals(NS_GET_IID(nsIDOMWindow)))
{
if (mWebBrowser)
{
return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
}
return NS_ERROR_NOT_INITIALIZED;
}
return QueryInterface(aIID, aInstancePtr);
}
//*****************************************************************************
@ -177,53 +184,53 @@ NS_IMETHODIMP WebBrowserChrome::CreateBrowserWindow(PRUint32 aChromeFlags,
PRInt32 aCX, PRInt32 aCY,
nsIWebBrowser **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
NS_ENSURE_ARG_POINTER(_retval);
*_retval = nsnull;
// Create the chrome object. Note that it leaves this function
// with an extra reference so that it can released correctly during
// destruction (via Win32UI::Destroy)
// Create the chrome object. Note that it leaves this function
// with an extra reference so that it can released correctly during
// destruction (via Win32UI::Destroy)
nsresult rv;
nsresult rv;
nsIWebBrowserChrome *newChrome = nsnull;
rv = ::CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, nsnull, &newChrome);
if (NS_SUCCEEDED(rv))
{
newChrome->GetWebBrowser(_retval);
}
nsIWebBrowserChrome *newChrome = nsnull;
rv = ::CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, nsnull, &newChrome);
if (NS_SUCCEEDED(rv))
{
newChrome->GetWebBrowser(_retval);
}
return rv;
return rv;
}
NS_IMETHODIMP WebBrowserChrome::DestroyBrowserWindow(void)
{
WebBrowserChromeUI::Destroy(this);
return NS_OK;
WebBrowserChromeUI::Destroy(this);
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::ShowAsModal(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::IsWindowModal(PRBool *_retval)
{
*_retval = PR_FALSE;
return NS_ERROR_NOT_IMPLEMENTED;
*_retval = PR_FALSE;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::ExitModalEventLoop(nsresult aStatus)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
//*****************************************************************************
@ -292,117 +299,123 @@ WebBrowserChrome::OnSecurityChange(nsIWebProgress *aWebProgress,
NS_IMETHODIMP
WebBrowserChrome::OnHistoryNewEntry(nsIURI * aNewURI)
{
return SendHistoryStatusMessage(aNewURI, "add");
return SendHistoryStatusMessage(aNewURI, "add");
}
NS_IMETHODIMP
WebBrowserChrome::OnHistoryGoBack(nsIURI * aBackURI, PRBool * aContinue)
{
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aBackURI, "back");
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aBackURI, "back");
}
NS_IMETHODIMP
WebBrowserChrome::OnHistoryGoForward(nsIURI * aForwardURI, PRBool * aContinue)
{
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aForwardURI, "forward");
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aForwardURI, "forward");
}
NS_IMETHODIMP
WebBrowserChrome::OnHistoryGotoIndex(PRInt32 aIndex, nsIURI * aGotoURI, PRBool * aContinue)
{
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aGotoURI, "goto", aIndex);
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aGotoURI, "goto", aIndex);
}
NS_IMETHODIMP
WebBrowserChrome::OnHistoryReload(nsIURI * aURI, PRUint32 aReloadFlags, PRBool * aContinue)
{
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aURI, "reload", 0 /* no info to pass here */, aReloadFlags);
// For now, let the operation continue
*aContinue = PR_TRUE;
return SendHistoryStatusMessage(aURI, "reload", 0 /* no info to pass here */, aReloadFlags);
}
NS_IMETHODIMP
WebBrowserChrome::OnHistoryPurge(PRInt32 aNumEntries, PRBool *aContinue)
{
// For now let the operation continue
*aContinue = PR_FALSE;
return SendHistoryStatusMessage(nsnull, "purge", aNumEntries);
// For now let the operation continue
*aContinue = PR_FALSE;
return SendHistoryStatusMessage(nsnull, "purge", aNumEntries);
}
nsresult
WebBrowserChrome::SendHistoryStatusMessage(nsIURI * aURI, char * operation, PRInt32 info1, PRUint32 aReloadFlags)
{
nsXPIDLCString uriCStr;
if (aURI)
aURI->GetSpec(getter_Copies(uriCStr));
nsString uriAStr;
if(!(nsCRT::strcmp(operation, "back"))) {
// Going back. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2("Going back to url:"));
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (!(nsCRT::strcmp(operation, "forward"))) {
// Going forward. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2("Going forward to url:"));
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (!(nsCRT::strcmp(operation, "reload"))) {
// Reloading. XXX Get string from a resource file
if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY &&
aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE)
nsXPIDLCString uriCStr;
if (aURI)
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url,(bypassing proxy and cache) :"));
aURI->GetSpec(getter_Copies(uriCStr));
}
else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY)
nsString uriAStr;
if(!(nsCRT::strcmp(operation, "back")))
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url, (bypassing proxy):"));
// Going back. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2("Going back to url:"));
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE)
else if (!(nsCRT::strcmp(operation, "forward")))
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url, (bypassing cache):"));
// Going forward. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2("Going forward to url:"));
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else
else if (!(nsCRT::strcmp(operation, "reload")))
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url, (normal):"));
// Reloading. XXX Get string from a resource file
if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY &&
aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE)
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url,(bypassing proxy and cache) :"));
}
else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY)
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url, (bypassing proxy):"));
}
else if (aReloadFlags & nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE)
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url, (bypassing cache):"));
}
else
{
uriAStr.Append(NS_ConvertASCIItoUCS2("Reloading url, (normal):"));
}
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (!(nsCRT::strcmp(operation, "add")))
{
// Adding new entry. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
uriAStr.Append(NS_ConvertASCIItoUCS2(" added to session History"));
}
else if (!(nsCRT::strcmp(operation, "goto")))
{
// Goto. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2("Going to HistoryIndex:"));
uriAStr.AppendInt(info1);
uriAStr.Append(NS_ConvertASCIItoUCS2(" Url:"));
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (!(nsCRT::strcmp(operation, "purge")))
{
// Purging old entries
uriAStr.AppendInt(info1);
uriAStr.Append(NS_ConvertASCIItoUCS2(" purged from Session History"));
}
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (!(nsCRT::strcmp(operation, "add"))) {
// Adding new entry. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
uriAStr.Append(NS_ConvertASCIItoUCS2(" added to session History"));
}
else if (!(nsCRT::strcmp(operation, "goto"))) {
// Goto. XXX Get string from a resource file
uriAStr.Append(NS_ConvertASCIItoUCS2("Going to HistoryIndex:"));
uriAStr.AppendInt(info1);
uriAStr.Append(NS_ConvertASCIItoUCS2(" Url:"));
uriAStr.Append(NS_ConvertASCIItoUCS2(uriCStr));
}
else if (!(nsCRT::strcmp(operation, "purge"))) {
// Purging old entries
uriAStr.AppendInt(info1);
uriAStr.Append(NS_ConvertASCIItoUCS2(" purged from Session History"));
}
PRUnichar * uriStr = nsnull;
uriStr = uriAStr.ToNewUnicode();
WebBrowserChromeUI::UpdateStatusBarText(this, uriStr);
nsCRT::free(uriStr);
return NS_OK;
PRUnichar * uriStr = nsnull;
uriStr = uriAStr.ToNewUnicode();
WebBrowserChromeUI::UpdateStatusBarText(this, uriStr);
nsCRT::free(uriStr);
return NS_OK;
}
//*****************************************************************************
@ -480,14 +493,43 @@ NS_IMETHODIMP WebBrowserChrome::GetSiteWindow(void * *aSiteWindow)
NS_IMETHODIMP WebBrowserChrome::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData)
{
nsresult rv = NS_OK;
if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-change-teardown").get()) == 0)
if (nsCRT::strcmp(aTopic, NS_LITERAL_STRING("profile-change-teardown").get()) == 0)
{
// A profile change means death for this window
WebBrowserChromeUI::Destroy(this);
// A profile change means death for this window
WebBrowserChromeUI::Destroy(this);
}
return rv;
}
//*****************************************************************************
// WebBrowserChrome::nsIContextMenuListener
//*****************************************************************************
/* void OnShowContextMenu (in unsigned long aContextFlags, in nsIDOMEvent aEvent, in nsIDOMNode aNode); */
NS_IMETHODIMP WebBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
{
WebBrowserChromeUI::ShowContextMenu(this, aContextFlags, aEvent, aNode);
return NS_OK;
}
//*****************************************************************************
// WebBrowserChrome::nsITooltipListener
//*****************************************************************************
/* void OnShowTooltip (in long aXCoords, in long aYCoords, in wstring aTipText); */
NS_IMETHODIMP WebBrowserChrome::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
{
WebBrowserChromeUI::ShowTooltip(this, aXCoords, aYCoords, aTipText);
return NS_OK;
}
/* void OnHideTooltip (); */
NS_IMETHODIMP WebBrowserChrome::OnHideTooltip()
{
WebBrowserChromeUI::HideTooltip(this);
return NS_OK;
}
//*****************************************************************************
// WebBrowserChrome::nsIPrompt
@ -497,76 +539,80 @@ A real app would want better. */
NS_IMETHODIMP WebBrowserChrome::Alert(const PRUnichar* dialogTitle, const PRUnichar *text)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_OK | MB_ICONEXCLAMATION);
nsMemory::Free(ctitle);
nsMemory::Free(ctext);
return NS_OK;
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_OK | MB_ICONEXCLAMATION);
nsMemory::Free(ctitle);
nsMemory::Free(ctext);
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::AlertCheck(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_OK | MB_ICONEXCLAMATION);
*checkValue = PR_FALSE; // yeah, well, it's not a real implementation
delete ctitle;
delete ctext;
return NS_OK;
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_OK | MB_ICONEXCLAMATION);
*checkValue = PR_FALSE; // yeah, well, it's not a real implementation
delete ctitle;
delete ctext;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::Confirm(const PRUnichar* dialogTitle, const PRUnichar *text, PRBool *_retval)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
int answer = ::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_YESNO | MB_ICONQUESTION);
delete ctitle;
delete ctext;
*_retval = answer == IDYES ? PR_TRUE : PR_FALSE;
return NS_OK;
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
int answer = ::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_YESNO | MB_ICONQUESTION);
delete ctitle;
delete ctext;
*_retval = answer == IDYES ? PR_TRUE : PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::ConfirmCheck(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar *checkMsg, PRBool *checkValue, PRBool *_retval)
{
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
int answer = ::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_YESNO | MB_ICONQUESTION);
delete ctitle;
delete ctext;
*_retval = answer == IDYES ? PR_TRUE : PR_FALSE;
return NS_OK;
nsAutoString stext(text);
nsAutoString stitle(dialogTitle);
char *ctext = stext.ToNewCString();
char *ctitle = stitle.ToNewCString();
// XXX platform specific user-interface code should happen in WebBrowserChromeUI
int answer = ::MessageBox((HWND)mNativeWindow, ctext, ctitle, MB_YESNO | MB_ICONQUESTION);
delete ctitle;
delete ctext;
*_retval = answer == IDYES ? PR_TRUE : PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP WebBrowserChrome::Prompt(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar* passwordRealm, PRUint32 savePassword, const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::PromptUsernameAndPassword(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar* passwordRealm, PRUint32 savePassword, PRUnichar **user, PRUnichar **pwd, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::PromptPassword(const PRUnichar* dialogTitle, const PRUnichar *text, const PRUnichar* passwordRealm, PRUint32 savePassword, PRUnichar **pwd, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::Select(const PRUnichar *inDialogTitle, const PRUnichar *inMsg, PRUint32 inCount, const PRUnichar **inList, PRInt32 *outSelection, PRBool *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP WebBrowserChrome::UniversalDialog(const PRUnichar *titleMessage, const PRUnichar *dialogTitle, const PRUnichar *text, const PRUnichar *checkboxMsg, const PRUnichar *button0Text, const PRUnichar *button1Text, const PRUnichar *button2Text, const PRUnichar *button3Text, const PRUnichar *editfield1Msg, const PRUnichar *editfield2Msg, PRUnichar **editfield1Value, PRUnichar **editfield2Value, const PRUnichar *iconURL, PRBool *checkboxState, PRInt32 numberButtons, PRInt32 numberEditfields, PRInt32 editField1Password, PRInt32 *buttonPressed)
{
return NS_ERROR_NOT_IMPLEMENTED;
return NS_ERROR_NOT_IMPLEMENTED;
}

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

@ -40,18 +40,23 @@
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsISHistoryListener.h"
#include "nsIContextMenuListener.h"
#include "nsITooltipListener.h"
class WebBrowserChromeUI
{
public:
static nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome);
static void Destroy(nsIWebBrowserChrome* chrome);
static void Destroyed(nsIWebBrowserChrome* chrome);
static void Destroy(nsIWebBrowserChrome* chrome);
static void Destroyed(nsIWebBrowserChrome* chrome);
static void UpdateStatusBarText(nsIWebBrowserChrome *aChrome, const PRUnichar* aStatusText);
static void UpdateCurrentURI(nsIWebBrowserChrome *aChrome);
static void UpdateBusyState(nsIWebBrowserChrome *aChrome, PRBool aBusy);
static void UpdateProgress(nsIWebBrowserChrome *aChrome, PRInt32 aCurrent, PRInt32 aMax);
static void GetResourceStringById(PRInt32 aID, char ** aReturn);
static void ShowContextMenu(nsIWebBrowserChrome *aChrome, PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode);
static void ShowTooltip(nsIWebBrowserChrome *aChrome, PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText);
static void HideTooltip(nsIWebBrowserChrome *aChrome);
};
class WebBrowserChrome : public nsIWebBrowserChrome,
@ -60,7 +65,9 @@ class WebBrowserChrome : public nsIWebBrowserChrome,
public nsIPrompt,
public nsIInterfaceRequestor,
public nsISHistoryListener,
public nsIObserver,
public nsIObserver,
public nsIContextMenuListener,
public nsITooltipListener,
public nsSupportsWeakReference
{
@ -76,18 +83,20 @@ public:
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSISHISTORYLISTENER
NS_DECL_NSIOBSERVER
NS_DECL_NSICONTEXTMENULISTENER
NS_DECL_NSITOOLTIPLISTENER
nsresult CreateBrowser(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY,
nsIWebBrowser **aBrowser);
protected:
nsresult SendHistoryStatusMessage(nsIURI * aURI, char * operation, PRInt32 info1=0, PRUint32 info2=0);
nsresult SendHistoryStatusMessage(nsIURI * aURI, char * operation, PRInt32 info1=0, PRUint32 info2=0);
nativeWindow mNativeWindow;
PRUint32 mChromeFlags;
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
nativeWindow mNativeWindow;
PRUint32 mChromeFlags;
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
};
#endif /* __WebBrowserChrome__ */

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

@ -24,11 +24,13 @@
#include "WindowCreator.h"
#include "winEmbed.h"
WindowCreator::WindowCreator() {
NS_INIT_REFCNT();
WindowCreator::WindowCreator()
{
NS_INIT_REFCNT();
}
WindowCreator::~WindowCreator() {
WindowCreator::~WindowCreator()
{
}
NS_IMPL_ISUPPORTS1(WindowCreator, nsIWindowCreator)
@ -38,7 +40,7 @@ WindowCreator::CreateChromeWindow(nsIWebBrowserChrome *parent,
PRUint32 chromeFlags,
nsIWebBrowserChrome **_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
::CreateBrowserWindow(PRInt32(chromeFlags), parent, _retval);
return *_retval ? NS_OK : NS_ERROR_FAILURE;
NS_ENSURE_ARG_POINTER(_retval);
::CreateBrowserWindow(PRInt32(chromeFlags), parent, _retval);
return *_retval ? NS_OK : NS_ERROR_FAILURE;
}

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

@ -29,11 +29,11 @@ class WindowCreator :
public nsIWindowCreator
{
public:
WindowCreator();
virtual ~WindowCreator();
WindowCreator();
virtual ~WindowCreator();
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
};
#endif

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

@ -278,19 +278,22 @@ NS_IMETHODIMP ProfileChangeObserver::Observe(nsISupports *aSubject, const PRUnic
new windows under these circumstances. */
nsresult InitializeWindowCreator()
{
// create an nsWindowCreator and give it to the WindowWatcher service
WindowCreator *creatorCallback = new WindowCreator();
if (creatorCallback) {
nsCOMPtr<nsIWindowCreator> windowCreator(dont_QueryInterface(NS_STATIC_CAST(nsIWindowCreator *, creatorCallback)));
if (windowCreator) {
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch) {
wwatch->SetWindowCreator(windowCreator);
return NS_OK;
}
// create an nsWindowCreator and give it to the WindowWatcher service
WindowCreator *creatorCallback = new WindowCreator();
if (creatorCallback)
{
nsCOMPtr<nsIWindowCreator> windowCreator(dont_QueryInterface(NS_STATIC_CAST(nsIWindowCreator *, creatorCallback)));
if (windowCreator)
{
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (wwatch)
{
wwatch->SetWindowCreator(windowCreator);
return NS_OK;
}
}
}
}
return NS_ERROR_FAILURE;
return NS_ERROR_FAILURE;
}
//-----------------------------------------------------------------------------
@ -303,52 +306,55 @@ nsresult InitializeWindowCreator()
//
nsresult OpenWebPage(const char *url)
{
nsresult rv;
nsresult rv;
// Create the chrome object. Note that it leaves this function
// with an extra reference so that it can released correctly during
// destruction (via Win32UI::Destroy)
// Create the chrome object. Note that it leaves this function
// with an extra reference so that it can released correctly during
// destruction (via Win32UI::Destroy)
nsIWebBrowserChrome *chrome = nsnull;
rv = CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, nsnull, &chrome);
if (NS_SUCCEEDED(rv))
{
// Start loading a page
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->GetWebBrowser(getter_AddRefs(newBrowser));
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser));
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE);
}
nsIWebBrowserChrome *chrome = nsnull;
rv = CreateBrowserWindow(nsIWebBrowserChrome::CHROME_ALL, nsnull, &chrome);
if (NS_SUCCEEDED(rv))
{
// Start loading a page
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->GetWebBrowser(getter_AddRefs(newBrowser));
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser));
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode(),
nsIWebNavigation::LOAD_FLAGS_NONE);
}
return rv;
return rv;
}
nsresult CreateBrowserWindow(PRUint32 aChromeFlags, nsIWebBrowserChrome *aParent, nsIWebBrowserChrome **aNewWindow)
{
WebBrowserChrome * chrome = new WebBrowserChrome();
if (!chrome)
WebBrowserChrome * chrome = new WebBrowserChrome();
if (!chrome)
{
return NS_ERROR_FAILURE;
}
CallQueryInterface(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome), aNewWindow);
chrome->SetChromeFlags(aChromeFlags);
// Insert the browser
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->CreateBrowser(-1, -1, -1, -1, getter_AddRefs(newBrowser));
if (!newBrowser)
return NS_ERROR_FAILURE;
CallQueryInterface(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome), aNewWindow);
// Place it where we want it.
ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
chrome->SetChromeFlags(aChromeFlags);
// Subscribe new window to profile changes so it can kill itself when one happens
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, chrome), NS_LITERAL_STRING("profile-change-teardown").get());
// Insert the browser
nsCOMPtr<nsIWebBrowser> newBrowser;
chrome->CreateBrowser(-1, -1, -1, -1, getter_AddRefs(newBrowser));
if (!newBrowser)
return NS_ERROR_FAILURE;
// Place it where we want it.
ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
// Subscribe new window to profile changes so it can kill itself when one happens
nsresult rv;
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
observerService->AddObserver(NS_STATIC_CAST(nsIObserver *, chrome), NS_LITERAL_STRING("profile-change-teardown").get());
return NS_OK;
return NS_OK;
}
//
@ -571,16 +577,16 @@ void UpdateUI(nsIWebBrowserChrome *aChrome)
if (hmenu)
{
EnableMenuItem(hmenu, MOZ_GoBack, MF_BYCOMMAND |
((canGoBack) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
((canGoBack) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
EnableMenuItem(hmenu, MOZ_GoForward, MF_BYCOMMAND |
((canGoForward) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
((canGoForward) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
EnableMenuItem(hmenu, MOZ_Cut, MF_BYCOMMAND |
((canCutSelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
((canCutSelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
EnableMenuItem(hmenu, MOZ_Copy, MF_BYCOMMAND |
((canCopySelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
((canCopySelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
EnableMenuItem(hmenu, MOZ_Paste, MF_BYCOMMAND |
((canPaste) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
((canPaste) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED)));
}
HWND button;
@ -667,8 +673,11 @@ BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
{
TCHAR szURL[2048];
memset(szURL, 0, sizeof(szURL));
GetDlgItemText(hwndDlg, IDC_ADDRESS, szURL, sizeof(szURL) / sizeof(szURL[0]) - 1);
webNavigation->LoadURI(NS_ConvertASCIItoUCS2(szURL).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE);
GetDlgItemText(hwndDlg, IDC_ADDRESS, szURL,
sizeof(szURL) / sizeof(szURL[0]) - 1);
webNavigation->LoadURI(
NS_ConvertASCIItoUCS2(szURL).GetUnicode(),
nsIWebNavigation::LOAD_FLAGS_NONE);
}
break;
@ -1202,10 +1211,10 @@ void WebBrowserChromeUI::UpdateBusyState(nsIWebBrowserChrome *aChrome, PRBool aB
HWND button;
button = GetDlgItem(hwndDlg, IDC_STOP);
if (button)
EnableWindow(button, aBusy);
EnableWindow(button, aBusy);
button = GetDlgItem(hwndDlg, IDC_GO);
if (button)
EnableWindow(button, !aBusy);
EnableWindow(button, !aBusy);
UpdateUI(aChrome);
}
@ -1234,6 +1243,35 @@ void WebBrowserChromeUI::UpdateProgress(nsIWebBrowserChrome *aChrome, PRInt32 aC
}
}
//
// FUNCTION: ShowContextMenu()
//
// PURPOSE: Display a context menu for the given node
//
void WebBrowserChromeUI::ShowContextMenu(nsIWebBrowserChrome *aChrome, PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
{
// TODO code to test context flags and display a popup menu should go here
}
//
// FUNCTION: ShowTooltip()
//
// PURPOSE: Show a tooltip
//
void WebBrowserChromeUI::ShowTooltip(nsIWebBrowserChrome *aChrome, PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
{
// TODO code to show a tooltip should go here
}
//
// FUNCTION: HideTooltip()
//
// PURPOSE: Hide the tooltip
//
void WebBrowserChromeUI::HideTooltip(nsIWebBrowserChrome *aChrome)
{
// TODO code to hide a tooltip should go here
}
//
// FUNCTION: GetResourceStringByID()
@ -1242,16 +1280,15 @@ void WebBrowserChromeUI::UpdateProgress(nsIWebBrowserChrome *aChrome, PRInt32 aC
//
void WebBrowserChromeUI::GetResourceStringById(PRInt32 aID, char ** aReturn)
{
char resBuf[MAX_LOADSTRING];
int retval = LoadString( ghInstanceResources, aID, (LPTSTR)resBuf, sizeof(resBuf) );
if (retval != 0)
{
int resLen = strlen(resBuf);
*aReturn = (char *)calloc(resLen+1, sizeof(char *));
if (!*aReturn) return;
PL_strncpy(*aReturn, (char *) resBuf, resLen);
}
return;
char resBuf[MAX_LOADSTRING];
int retval = LoadString( ghInstanceResources, aID, (LPTSTR)resBuf, sizeof(resBuf) );
if (retval != 0)
{
int resLen = strlen(resBuf);
*aReturn = (char *)calloc(resLen+1, sizeof(char *));
if (!*aReturn) return;
PL_strncpy(*aReturn, (char *) resBuf, resLen);
}
return;
}