mirror of https://github.com/roytam1/kmeleon.git
parent
4789751aca
commit
61a02eb63e
13 changed files with 3591 additions and 0 deletions
@ -0,0 +1,533 @@ |
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* |
||||
* The contents of this file are subject to the Netscape Public |
||||
* License Version 1.1 (the "License"); you may not use this file |
||||
* except in compliance with the License. You may obtain a copy of |
||||
* the License at http://www.mozilla.org/NPL/
|
||||
* |
||||
* Software distributed under the License is distributed on an "AS |
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
||||
* implied. See the License for the specific language governing |
||||
* rights and limitations under the License. |
||||
* |
||||
* The Original Code is mozilla.org code. |
||||
* |
||||
* The Initial Developer of the Original Code is Netscape |
||||
* Communications Corporation. Portions created by Netscape are |
||||
* Copyright (C) 1998 Netscape Communications Corporation. All |
||||
* Rights Reserved. |
||||
* |
||||
* Contributor(s):
|
||||
* Chak Nanga <chak@netscape.com>
|
||||
*/ |
||||
|
||||
// File Overview....
|
||||
//
|
||||
// This file has the IBrowserFrameGlueObj implementation
|
||||
// This frame glue object is nested inside of the BrowserFrame
|
||||
// object(See BrowserFrm.h for more info)
|
||||
//
|
||||
// This is the place where all the platform specific interaction
|
||||
// with the browser frame window takes place in response to
|
||||
// callbacks from Gecko interface methods
|
||||
//
|
||||
// The main purpose of this interface is to separate the cross
|
||||
// platform code in BrowserImpl*.cpp from the platform specific
|
||||
// code(which is in this file)
|
||||
//
|
||||
// You'll also notice the use of a macro named "METHOD_PROLOGUE"
|
||||
// through out this file. This macro essentially makes the pointer
|
||||
// to a "containing" class available inside of the class which is
|
||||
// being contained via a var named "pThis". In our case, the
|
||||
// BrowserFrameGlue object is contained inside of the BrowserFrame
|
||||
// object so "pThis" will be a pointer to a BrowserFrame object
|
||||
// Refer to MFC docs for more info on METHOD_PROLOGUE macro
|
||||
|
||||
|
||||
#include "stdafx.h" |
||||
#include "MfcEmbed.h" |
||||
#include "BrowserFrm.h" |
||||
#include "Dialogs.h" |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// IBrowserFrameGlue implementation
|
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::UpdateStatusBarText(const PRUnichar *aMessage) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
nsCString strStatus;
|
||||
|
||||
if(aMessage) |
||||
strStatus.AssignWithConversion(aMessage); |
||||
|
||||
pThis->m_wndStatusBar.SetPaneText(0, strStatus.GetBuffer()); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::UpdateProgress(PRInt32 aCurrent, PRInt32 aMax) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
pThis->m_wndProgressBar.SetRange32(0, aMax); |
||||
pThis->m_wndProgressBar.SetPos(aCurrent); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::UpdateBusyState(PRBool aBusy) |
||||
{
|
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
// Just notify the view of the busy state
|
||||
// There's code in there which will take care of
|
||||
// updating the STOP toolbar btn. etc
|
||||
|
||||
pThis->m_wndBrowserView.UpdateBusyState(aBusy); |
||||
} |
||||
|
||||
// Called from the OnLocationChange() method in the nsIWebProgressListener
|
||||
// interface implementation in CBrowserImpl to update the current URI
|
||||
// Will get called after a URI is successfully loaded in the browser
|
||||
// We use this info to update the URL bar's edit box
|
||||
//
|
||||
void CBrowserFrame::BrowserFrameGlueObj::UpdateCurrentURI(nsIURI *aLocation) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
if(aLocation) { |
||||
nsXPIDLCString uriString; |
||||
aLocation->GetSpec(getter_Copies(uriString)); |
||||
|
||||
pThis->m_wndUrlBar.SetCurrentURL(uriString.get()); |
||||
} |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameTitle(PRUnichar **aTitle) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
CString title; |
||||
pThis->GetWindowText(title); |
||||
|
||||
if(!title.IsEmpty()) |
||||
{ |
||||
nsString nsTitle; |
||||
nsTitle.AssignWithConversion(title.GetBuffer(0)); |
||||
|
||||
*aTitle = nsTitle.ToNewUnicode(); |
||||
} |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameTitle(const PRUnichar *aTitle) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
USES_CONVERSION; |
||||
|
||||
CString cs; |
||||
cs.LoadString(AFX_IDS_APP_TITLE); |
||||
|
||||
CString title = W2T(aTitle); |
||||
|
||||
if (title.IsEmpty()){ |
||||
pThis->m_wndUrlBar.GetEnteredURL(title); |
||||
} |
||||
|
||||
title += " (" + cs + ')'; |
||||
pThis->SetWindowText(title); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
pThis->SetWindowPos(NULL, 0, 0, aCX, aCY,
|
||||
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER |
||||
); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
RECT wndRect; |
||||
pThis->GetWindowRect(&wndRect); |
||||
|
||||
if (aCX) |
||||
*aCX = wndRect.right - wndRect.left; |
||||
|
||||
if (aCY) |
||||
*aCY = wndRect.bottom - wndRect.top; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePosition(PRInt32 aX, PRInt32 aY) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
|
||||
|
||||
pThis->SetWindowPos(NULL, aX, aY, 0, 0,
|
||||
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
RECT wndRect; |
||||
pThis->GetWindowRect(&wndRect); |
||||
|
||||
if (aX) |
||||
*aX = wndRect.left; |
||||
|
||||
if (aY) |
||||
*aY = wndRect.top; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
RECT wndRect; |
||||
pThis->GetWindowRect(&wndRect); |
||||
|
||||
if (aX) |
||||
*aX = wndRect.left; |
||||
|
||||
if (aY) |
||||
*aY = wndRect.top; |
||||
|
||||
if (aCX) |
||||
*aCX = wndRect.right - wndRect.left; |
||||
|
||||
if (aCY) |
||||
*aCY = wndRect.bottom - wndRect.top; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
pThis->SetWindowPos(NULL, aX, aY, aCX, aCY,
|
||||
SWP_NOACTIVATE | SWP_NOZORDER); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::SetFocus() |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
pThis->SetFocus(); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::FocusAvailable(PRBool *aFocusAvail) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
HWND focusWnd = GetFocus()->m_hWnd; |
||||
|
||||
if ((focusWnd == pThis->m_hWnd) || ::IsChild(pThis->m_hWnd, focusWnd)) |
||||
*aFocusAvail = PR_TRUE; |
||||
else |
||||
*aFocusAvail = PR_FALSE; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::ShowBrowserFrame(PRBool aShow) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
if(aShow) |
||||
{ |
||||
pThis->ShowWindow(SW_SHOW); |
||||
pThis->SetActiveWindow(); |
||||
pThis->UpdateWindow(); |
||||
} |
||||
else |
||||
{ |
||||
pThis->ShowWindow(SW_HIDE); |
||||
} |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameVisibility(PRBool *aVisible) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
// Is the current BrowserFrame the active one?
|
||||
if (GetActiveWindow()->m_hWnd != pThis->m_hWnd) |
||||
{ |
||||
*aVisible = PR_FALSE; |
||||
return; |
||||
} |
||||
|
||||
// We're the active one
|
||||
//Return FALSE if we're minimized
|
||||
WINDOWPLACEMENT wpl; |
||||
pThis->GetWindowPlacement(&wpl); |
||||
|
||||
if ((wpl.showCmd == SW_RESTORE) || (wpl.showCmd == SW_MAXIMIZE)) |
||||
*aVisible = PR_TRUE; |
||||
else |
||||
*aVisible = PR_FALSE; |
||||
} |
||||
|
||||
PRBool CBrowserFrame::BrowserFrameGlueObj::CreateNewBrowserFrame(PRUint32 chromeMask,
|
||||
PRInt32 x, PRInt32 y,
|
||||
PRInt32 cx, PRInt32 cy, |
||||
nsIWebBrowser** aWebBrowser) |
||||
{ |
||||
NS_ENSURE_ARG_POINTER(aWebBrowser); |
||||
|
||||
*aWebBrowser = nsnull; |
||||
|
||||
CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); |
||||
if(!pApp) |
||||
return PR_FALSE; |
||||
|
||||
// Note that we're calling with the last param set to "false" i.e.
|
||||
// this instructs not to show the frame window
|
||||
// This is mainly needed when the window size is specified in the window.open()
|
||||
// JS call. In those cases Gecko calls us to create the browser with a default
|
||||
// size (all are -1) and then it calls the SizeBrowserTo() method to set
|
||||
// the proper window size. If this window were to be visible then you'll see
|
||||
// the window size changes on the screen causing an unappealing flicker
|
||||
//
|
||||
// Changing the last param back to TRUE since the latest nsIWebBrowserSiteWindow
|
||||
// changes have gotten rid of the SetVisibility() method which we were using
|
||||
// to finally show the browser window. I think we need that functionality
|
||||
// back in
|
||||
// Chak
|
||||
// Feb 2, 2001
|
||||
|
||||
CBrowserFrame* pFrm = pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, PR_TRUE); |
||||
if(!pFrm) |
||||
return PR_FALSE; |
||||
|
||||
// At this stage we have a new CBrowserFrame and a new CBrowserView
|
||||
// objects. The CBrowserView also would have an embedded browser
|
||||
// object created. Get the mWebBrowser member from the CBrowserView
|
||||
// and return it. (See CBrowserView's CreateBrowser() on how the
|
||||
// embedded browser gets created and how it's mWebBrowser member
|
||||
// gets initialized)
|
||||
|
||||
NS_IF_ADDREF(*aWebBrowser = pFrm->m_wndBrowserView.mWebBrowser); |
||||
|
||||
return PR_TRUE; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame() |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
pThis->PostMessage(WM_CLOSE); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
UINT nIDResource = IDR_CTXMENU_DOCUMENT; |
||||
|
||||
if(aContextFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) |
||||
nIDResource = IDR_CTXMENU_DOCUMENT; |
||||
else if(aContextFlags & nsIContextMenuListener::CONTEXT_TEXT)
|
||||
nIDResource = IDR_CTXMENU_TEXT; |
||||
else if(aContextFlags & nsIContextMenuListener::CONTEXT_LINK) |
||||
{ |
||||
nIDResource = IDR_CTXMENU_LINK; |
||||
|
||||
// Since we handle all the browser menu/toolbar commands
|
||||
// in the View, we basically setup the Link's URL in the
|
||||
// BrowserView object. When a menu selection in the context
|
||||
// menu is made, the appropriate command handler in the
|
||||
// BrowserView will be invoked and the value of the URL
|
||||
// will be accesible in the view
|
||||
|
||||
// Reset the value from the last invocation
|
||||
// (A new value will be set after we determine it below)
|
||||
//
|
||||
nsAutoString strUrlUcs2; |
||||
pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2); |
||||
|
||||
// Get the URL from the link. This is two step process
|
||||
// 1. We first get the nsIDOMHTMLAnchorElement
|
||||
// 2. We then get the URL associated with the link
|
||||
nsresult rv = NS_OK; |
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(aNode, &rv)); |
||||
if(NS_FAILED(rv)) |
||||
return; |
||||
|
||||
rv = linkElement->GetHref(strUrlUcs2); |
||||
if(NS_FAILED(rv)) |
||||
return; |
||||
|
||||
// Update the view with the new LinkUrl
|
||||
// Note that this string is in UCS2 format
|
||||
pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2); |
||||
} |
||||
else if(aContextFlags & nsIContextMenuListener::CONTEXT_IMAGE) { |
||||
nIDResource = IDR_CTXMENU_IMAGE; |
||||
|
||||
nsAutoString strImgSrcUcs2; |
||||
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Clear it
|
||||
|
||||
// Get the IMG SRC
|
||||
nsresult rv = NS_OK; |
||||
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aNode, &rv)); |
||||
if(NS_FAILED(rv)) |
||||
return; |
||||
|
||||
rv = imgElement->GetSrc(strImgSrcUcs2); |
||||
if(NS_FAILED(rv)) |
||||
return; |
||||
|
||||
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Set the new Img Src
|
||||
} |
||||
|
||||
CMenu ctxMenu; |
||||
if(ctxMenu.LoadMenu(nIDResource)) |
||||
{ |
||||
POINT cursorPos; |
||||
GetCursorPos(&cursorPos); |
||||
|
||||
(ctxMenu.GetSubMenu(0))->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, cursorPos.x, cursorPos.y, pThis); |
||||
} |
||||
} |
||||
|
||||
nsresult CBrowserFrame::BrowserFrameGlueObj::FindNamedBrowserItem(const PRUnichar *aName, nsIWebBrowserChrome* aWebBrowserChrome, nsIDocShellTreeItem ** aBrowserItem) |
||||
{ |
||||
NS_ENSURE_ARG(aName); |
||||
NS_ENSURE_ARG_POINTER(aBrowserItem); |
||||
|
||||
*aBrowserItem = nsnull; |
||||
|
||||
// Get pointer to our App
|
||||
CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); |
||||
if(!pApp) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
// Now walk thru' all frames to see if we can find the
|
||||
// named item
|
||||
//
|
||||
CBrowserFrame* pFrm = NULL; |
||||
POSITION pos = pApp->m_FrameWndLst.GetHeadPosition(); |
||||
while( pos != NULL ) |
||||
{ |
||||
pFrm = (CBrowserFrame *) pApp->m_FrameWndLst.GetNext(pos); |
||||
if(pFrm) |
||||
{ |
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(pFrm->m_wndBrowserView.mWebBrowser)); |
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); |
||||
|
||||
docShellAsItem->FindItemWithName(aName, aWebBrowserChrome, aBrowserItem); |
||||
|
||||
if(*aBrowserItem) |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::Alert(const PRUnichar *dialogTitle, const PRUnichar *text) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
USES_CONVERSION; |
||||
|
||||
pThis->MessageBox(W2T(text), W2T(dialogTitle), MB_OK | MB_ICONEXCLAMATION); |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::Confirm(const PRUnichar *dialogTitle, const PRUnichar *text, PRBool *retval) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
USES_CONVERSION; |
||||
|
||||
int iChoice = pThis->MessageBox(W2T(text), W2T(dialogTitle), MB_YESNO | MB_ICONEXCLAMATION); |
||||
|
||||
*retval = (iChoice == IDYES) ? PR_TRUE : PR_FALSE; |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text, |
||||
const PRUnichar *defaultEditText, PRUnichar **result, PRBool *retval) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
USES_CONVERSION; |
||||
|
||||
CPromptDialog dlg(pThis, W2T(dialogTitle), W2T(text), W2T(defaultEditText)); |
||||
if(dlg.DoModal() == IDOK) |
||||
{ |
||||
// Get the value entered in the editbox of the PromptDlg
|
||||
nsString csPromptEditValue; |
||||
csPromptEditValue.AssignWithConversion(dlg.m_csPromptAnswer.GetBuffer(0)); |
||||
|
||||
*result = csPromptEditValue.ToNewUnicode(); |
||||
|
||||
*retval = PR_TRUE; |
||||
} |
||||
else |
||||
{ |
||||
*retval = PR_FALSE; |
||||
} |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::PromptPassword(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text, const PRUnichar *checkboxMsg,
|
||||
PRBool *checkboxState, PRUnichar **result, PRBool *retval) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
USES_CONVERSION; |
||||
|
||||
CPromptPasswordDialog dlg(pThis, W2T(dialogTitle), W2T(text), W2T(checkboxMsg)); |
||||
if(dlg.DoModal() == IDOK) |
||||
{ |
||||
// Get the password entered
|
||||
nsString csPassword; |
||||
csPassword.AssignWithConversion(dlg.m_csPassword.GetBuffer(0)); |
||||
*result = csPassword.ToNewUnicode(); |
||||
|
||||
if(checkboxState) //Checkbox will be hidden in non single sign-on case
|
||||
*checkboxState = dlg.m_bSavePassword; |
||||
|
||||
*retval = PR_TRUE; |
||||
} |
||||
else |
||||
{ |
||||
*retval = PR_FALSE; |
||||
} |
||||
} |
||||
|
||||
void CBrowserFrame::BrowserFrameGlueObj::PromptUserNamePassword(const PRUnichar *dialogTitle,
|
||||
const PRUnichar *text, const PRUnichar *userNameLabel,
|
||||
const PRUnichar *passwordLabel, const PRUnichar *checkboxMsg,
|
||||
PRBool *checkboxState, PRUnichar **username, PRUnichar **password,
|
||||
PRBool *retval) |
||||
{ |
||||
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) |
||||
|
||||
USES_CONVERSION; |
||||
|
||||
CPromptUsernamePasswordDialog dlg(pThis, W2T(dialogTitle), W2T(text),
|
||||
W2T(userNameLabel), W2T(passwordLabel),
|
||||
W2T(checkboxMsg)); |
||||
|
||||
if(dlg.DoModal() == IDOK) |
||||
{ |
||||
// Get the username entered
|
||||
nsString csUserName; |
||||
csUserName.AssignWithConversion(dlg.m_csUserName.GetBuffer(0)); |
||||
*username = csUserName.ToNewUnicode(); |
||||
|
||||
// Get the password entered
|
||||
nsString csPassword; |
||||
csPassword.AssignWithConversion(dlg.m_csPassword.GetBuffer(0)); |
||||
*password = csPassword.ToNewUnicode(); |
||||
|
||||
if(checkboxState) //Checkbox will be hidden in non single sign-on case
|
||||
*checkboxState = dlg.m_bSavePassword; |
||||
|
||||
*retval = PR_TRUE; |
||||
|
||||
} |
||||
else |
||||
{ |
||||
*retval = PR_FALSE; |
||||
} |
||||
} |
@ -0,0 +1,468 @@ |
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* |
||||
* The contents of this file are subject to the Netscape Public |
||||
* License Version 1.1 (the "License"); you may not use this file |
||||
* except in compliance with the License. You may obtain a copy of |
||||
* the License at http://www.mozilla.org/NPL/
|
||||
* |
||||
* Software distributed under the License is distributed on an "AS |
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
||||
* implied. See the License for the specific language governing |
||||
* rights and limitations under the License. |
||||
* |
||||
* The Original Code is mozilla.org code. |
||||
* |
||||
* The Initial Developer of the Original Code is Netscape |
||||
* Communications Corporation. Portions created by Netscape are |
||||
* Copyright (C) 1998 Netscape Communications Corporation. All |
||||
* Rights Reserved. |
||||
* |
||||
* Contributor(s):
|
||||
* Chak Nanga <chak@netscape.com>
|
||||
*/ |
||||
|
||||
// File Overview....
|
||||
//
|
||||
// The typical MFC View, toolbar, statusbar creation done
|
||||
// in CBrowserFrame::OnCreate()
|
||||
//
|
||||
// Code to update the Status/Tool bars in response to the
|
||||
// Web page loading progress(called from methods in CBrowserImpl)
|
||||
//
|
||||
// SetupFrameChrome() determines what, if any, UI elements this Frame
|
||||
// will sport based on the current "chromeMask"
|
||||
//
|
||||
// Also take a look at OnClose() which gets used when you close a browser
|
||||
// window. This needs to be overrided mainly to handle supporting multiple
|
||||
// browser frame windows via the "New Browser Window" menu item
|
||||
// Without this being overridden the MFC framework handles the OnClose and
|
||||
// shutsdown the complete application when a frame window is closed.
|
||||
// In our case, we want the app to shutdown when the File/Exit menu is chosen
|
||||
//
|
||||
// Another key functionality this object implements is the IBrowserFrameGlue
|
||||
// interface - that's the interface the Gecko embedding interfaces call
|
||||
// upong to update the status bar etc.
|
||||
// (Take a look at IBrowserFrameGlue.h for the interface definition and
|
||||
// the BrowserFrm.h to see how we implement this interface - as a nested
|
||||
// class)
|
||||
// We pass this Glue object pointer to the CBrowserView object via the
|
||||
// SetBrowserFrameGlue() method. The CBrowserView passes this on to the
|
||||
// embedding interface implementaion
|
||||
//
|
||||
// Please note the use of the macro METHOD_PROLOGUE in the implementation
|
||||
// of the nested BrowserFrameGlue object. Essentially what this macro does
|
||||
// is to get you access to the outer (or the object which is containing the
|
||||
// nested object) object via the pThis pointer.
|
||||
// Refer to the AFXDISP.H file in VC++ include dirs
|
||||
//
|
||||
// Next suggested file to look at : BrowserView.cpp
|
||||
|
||||
#include "stdafx.h" |
||||
|
||||
#include "MfcEmbed.h" |
||||
extern CMfcEmbedApp theApp; |
||||
|
||||
#include "BrowserFrm.h" |
||||
|
||||
#ifdef _DEBUG |
||||
#define new DEBUG_NEW |
||||
#undef THIS_FILE |
||||
static char THIS_FILE[] = __FILE__; |
||||
#endif |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CBrowserFrame
|
||||
|
||||
IMPLEMENT_DYNAMIC(CBrowserFrame, CFrameWnd) |
||||
|
||||
BEGIN_MESSAGE_MAP(CBrowserFrame, CFrameWnd) |
||||
//{{AFX_MSG_MAP(CBrowserFrame)
|
||||
ON_WM_CREATE() |
||||
ON_WM_SETFOCUS() |
||||
ON_WM_SIZE() |
||||
ON_WM_CLOSE() |
||||
ON_WM_SYSCOLORCHANGE() |
||||
//}}AFX_MSG_MAP
|
||||
END_MESSAGE_MAP() |
||||
|
||||
static UINT indicators[] = |
||||
{ |
||||
ID_SEPARATOR, // For the Status line
|
||||
ID_SEPARATOR, // For the Progress Bar
|
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CBrowserFrame construction/destruction
|
||||
|
||||
CBrowserFrame::CBrowserFrame(PRUint32 chromeMask) |
||||
{ |
||||
// Save the chromeMask off. It'll be used
|
||||
// later to determine whether this browser frame
|
||||
// will have menubar, toolbar, statusbar etc.
|
||||
|
||||
m_chromeMask = chromeMask; |
||||
} |
||||
|
||||
CBrowserFrame::~CBrowserFrame() |
||||
{ |
||||
} |
||||
|
||||
void CBrowserFrame::OnClose() |
||||
{ |
||||
// if we don't do this, then our menu will be destroyed when the first window is.
|
||||
// that's bad because our menu is shared between all windows
|
||||
SetMenu(NULL); |
||||
|
||||
CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); |
||||
pApp->RemoveFrameFromList(this); |
||||
|
||||
DestroyWindow(); |
||||
} |
||||
|
||||
#undef TRACE0 |
||||
#define TRACE0(msg) MessageBox(msg); |
||||
|
||||
// This is where the UrlBar, ToolBar, StatusBar, ProgressBar
|
||||
// get created
|
||||
//
|
||||
int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) |
||||
{ |
||||
if (CFrameWnd::OnCreate(lpCreateStruct) == -1) |
||||
return -1; |
||||
|
||||
// Pass "this" to the View for later callbacks
|
||||
// and/or access to any public data members, if needed
|
||||
//
|
||||
m_wndBrowserView.SetBrowserFrame(this); |
||||
|
||||
// Pass on the BrowserFrameGlue also to the View which
|
||||
// it will use during the Init() process after creation
|
||||
// of the BrowserImpl obj. Essentially, the View object
|
||||
// hooks up the Embedded browser's callbacks to the BrowserFrame
|
||||
// via this BrowserFrameGlue object
|
||||
m_wndBrowserView.SetBrowserFrameGlue((PBROWSERFRAMEGLUE)&m_xBrowserFrameGlueObj); |
||||
|
||||
// create a view to occupy the client area of the frame
|
||||
// This will be the view in which the embedded browser will
|
||||
// be displayed in
|
||||
//
|
||||
if (!m_wndBrowserView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, |
||||
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL)) |
||||
{ |
||||
TRACE0("Failed to create view window\n"); |
||||
return -1; |
||||
} |
||||
|
||||
// create the URL bar (essentially a ComboBoxEx object)
|
||||
if (!m_wndUrlBar.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 150), this, ID_URL_BAR)) |
||||
{ |
||||
TRACE0("Failed to create URL Bar\n"); |
||||
return -1; // fail to create
|
||||
} |
||||
|
||||
// Create the toolbar with Back, Fwd, Stop, etc. buttons..
|
||||
if (!m_wndToolBar.CreateEx (this, 0x40 | /*CCS_NOPARENTALIGN | CCS_NORESIZE | */ TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | TBSTYLE_AUTOSIZE | TBSTYLE_TOOLTIPS) ) |
||||
{ |
||||
TRACE0("Failed to create toolbar\n"); |
||||
return -1; // fail to create
|
||||
} |
||||
// back, forward, stop, reload, home, search
|
||||
UINT buttons[6] = { |
||||
ID_NAV_BACK, |
||||
ID_NAV_FORWARD, |
||||
ID_NAV_STOP, |
||||
ID_NAV_RELOAD, |
||||
ID_NAV_HOME, |
||||
ID_NAV_SEARCH |
||||
}; |
||||
|
||||
m_toolbarColdImageList.Create(IDB_TOOLBAR_COLD, 16, 3, RGB(255, 0, 255)); |
||||
m_wndToolBar.GetToolBarCtrl().SetImageList(&m_toolbarColdImageList); |
||||
|
||||
m_toolbarHotImageList.Create(IDB_TOOLBAR_HOT, 16, 8, RGB(255, 0, 255)); |
||||
m_wndToolBar.GetToolBarCtrl().SetHotImageList(&m_toolbarHotImageList); |
||||
|
||||
m_toolbarDisabledImageList.Create(IDB_TOOLBAR_DISABLED, 16, 8, RGB(255, 0, 255)); |
||||
m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&m_toolbarDisabledImageList); |
||||
|
||||
m_wndToolBar.SetButtons(buttons, 6); |
||||
|
||||
// Create the animation control..
|
||||
if (!m_wndAnimate.Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 10, 10), this, AFX_IDW_TOOLBAR + 2) || |
||||
!m_wndAnimate.Open(IDR_MFCAVI)) |
||||
{ |
||||
TRACE0("Failed to create aimation\n"); |
||||
return -1; // fail to create
|
||||
} |
||||
|
||||
// Create a ReBar window to which the toolbar and UrlBar
|
||||
// will be added
|
||||
if (!m_wndReBar.Create(this)) |
||||
{ |
||||
TRACE0("Failed to create ReBar\n"); |
||||
return -1; // fail to create
|
||||
} |
||||
|
||||
//Add the ToolBar and UrlBar windows to the rebar
|
||||
m_wndReBar.AddBar(&m_wndToolBar, NULL); |
||||
m_wndReBar.AddBar(&m_wndUrlBar, "URL:"); |
||||
m_wndReBar.AddBar(&m_wndAnimate, NULL, NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP); |
||||
|
||||
//--------------------------------------------------------------
|
||||
// Set up min/max sizes and ideal sizes for pieces of the rebar:
|
||||
//--------------------------------------------------------------
|
||||
CReBarCtrl *rebarControl = &m_wndReBar.GetReBarCtrl(); |
||||
|
||||
REBARBANDINFO rbbi; |
||||
|
||||
// Address Bar
|
||||
CRect rectAddress; |
||||
m_wndUrlBar.GetEditCtrl()->GetWindowRect(&rectAddress); |
||||
|
||||
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE;; |
||||
rbbi.cxMinChild = 0; |
||||
rbbi.cyMinChild = rectAddress.Height() + 7; |
||||
rbbi.cxIdeal = 200; |
||||
rbbi.cx = 200; |
||||
rebarControl->SetBandInfo (1, &rbbi); |
||||
|
||||
rebarControl->MaximizeBand(1); |
||||
|
||||
// Toolbar
|
||||
CRect rectToolBar; |
||||
m_wndToolBar.GetItemRect(0, &rectToolBar); |
||||
|
||||
rbbi.cbSize = sizeof(rbbi); |
||||
rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE; |
||||
rbbi.cxMinChild = 0; |
||||
rbbi.cyMinChild = rectToolBar.Height(); |
||||
rbbi.cxIdeal = rectToolBar.Width() * m_wndToolBar.GetCount(); |
||||
rbbi.cx = rbbi.cxIdeal + 10; |
||||
rebarControl->SetBandInfo (0, &rbbi); |
||||
|
||||
theApp.plugins.DoRebars(m_wndReBar.GetReBarCtrl().m_hWnd); |
||||
|
||||
LoadBackImage(); |
||||
SetBackImage(); |
||||
|
||||
// Create the status bar with two panes - one pane for actual status
|
||||
// text msgs. and the other for the progress control
|
||||
if (!m_wndStatusBar.Create(this) || |
||||
!m_wndStatusBar.SetIndicators(indicators, |
||||
sizeof(indicators)/sizeof(UINT))) |
||||
{ |
||||
TRACE0("Failed to create status bar\n"); |
||||
return -1; // fail to create
|
||||
} |
||||
|
||||
// Create the progress bar as a child of the status bar.
|
||||
// Note that the ItemRect which we'll get at this stage
|
||||
// is bogus since the status bar panes are not fully
|
||||
// positioned yet i.e. we'll be passing in an invalid rect
|
||||
// to the Create function below
|
||||
// The actual positioning of the progress bar will be done
|
||||
// in response to OnSize()
|
||||
RECT rc; |
||||
m_wndStatusBar.GetItemRect (1, &rc); |
||||
if (!m_wndProgressBar.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH, rc, &m_wndStatusBar, ID_PROG_BAR)) |
||||
{ |
||||
TRACE0("Failed to create progress bar\n"); |
||||
return -1; // fail to create
|
||||
} |
||||
|
||||
// Based on the "chromeMask" we were supplied during construction
|
||||
// hide any requested UI elements - statusbar, menubar etc...
|
||||
// Note that the window styles (WM_RESIZE etc) are set inside
|
||||
// of PreCreateWindow()
|
||||
|
||||
SetupFrameChrome();
|
||||
|
||||
return 0; |
||||
} |
||||
|
||||
void CBrowserFrame::SetupFrameChrome() |
||||
{ |
||||
if(m_chromeMask == nsIWebBrowserChrome::CHROME_ALL) |
||||
return; |
||||
|
||||
if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_MENUBAR) ) |
||||
SetMenu(NULL); // Hide the MenuBar
|
||||
|
||||
if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_TOOLBAR) ) |
||||
m_wndReBar.ShowWindow(SW_HIDE); // Hide the ToolBar
|
||||
|
||||
if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) ) |
||||
m_wndStatusBar.ShowWindow(SW_HIDE); // Hide the StatusBar
|
||||
} |
||||
|
||||
BOOL CBrowserFrame::PreCreateWindow(CREATESTRUCT& cs) |
||||
{ |
||||
if( !CFrameWnd::PreCreateWindow(cs) ) |
||||
return FALSE; |
||||
|
||||
cs.dwExStyle &= ~WS_EX_CLIENTEDGE; |
||||
|
||||
// Change window style based on the chromeMask
|
||||
|
||||
if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR) ) |
||||
cs.style &= ~WS_CAPTION; // No caption
|
||||
|
||||
if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) ) |
||||
{ |
||||
// Can't resize this window
|
||||
cs.style &= ~WS_SIZEBOX; |
||||
cs.style &= ~WS_THICKFRAME; |
||||
cs.style &= ~WS_MINIMIZEBOX; |
||||
cs.style &= ~WS_MAXIMIZEBOX; |
||||
} |
||||
|
||||
cs.lpszClass = AfxRegisterWndClass(0); |
||||
|
||||
// this function is actually called twice per window.
|
||||
// the first time hInstance is 0
|
||||
if (cs.hInstance){ |
||||
if (theApp.menus.GetMenu("Main")){ |
||||
cs.hMenu = theApp.menus.GetMenu("Main")->m_hMenu; |
||||
} |
||||
} |
||||
|
||||
return TRUE; |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CBrowserFrame message handlers
|
||||
void CBrowserFrame::OnSetFocus(CWnd* pOldWnd) |
||||
{ |
||||
// forward focus to the view window
|
||||
m_wndBrowserView.SetFocus(); |
||||
} |
||||
|
||||
LRESULT CBrowserFrame::WindowProc( UINT message, WPARAM wParam, LPARAM lParam ){ |
||||
LRESULT result = theApp.plugins.OnMessage( this->m_hWnd, message, wParam, lParam ); |
||||
|
||||
LRESULT result2 = CFrameWnd::WindowProc( message, wParam, lParam ); |
||||
|
||||
if (!result) |
||||
return result2; |
||||
else |
||||
return result; |
||||
} |
||||
|
||||
BOOL CBrowserFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) |
||||
{ |
||||
if (nCode == CN_COMMAND){ |
||||
if (pHandlerInfo && theApp.plugins.OnUpdate(nID)){ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
// let the view have first crack at the command
|
||||
if (m_wndBrowserView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) |
||||
return TRUE; |
||||
|
||||
// otherwise, do default handling
|
||||
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); |
||||
} |
||||
|
||||
// Needed to properly position/resize the progress bar
|
||||
//
|
||||
void CBrowserFrame::OnSize(UINT nType, int cx, int cy)
|
||||
{ |
||||
CFrameWnd::OnSize(nType, cx, cy); |
||||
|
||||
// Get the ItemRect of the status bar's Pane 1
|
||||
// That's where the progress bar will be located
|
||||
RECT rc; |
||||
m_wndStatusBar.GetItemRect(1, &rc); |
||||
|
||||
// Move the progress bar into it's correct location
|
||||
//
|
||||
m_wndProgressBar.MoveWindow(&rc); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void CBrowserFrame::OnSysColorChange()
|
||||
{ |
||||
CFrameWnd::OnSysColorChange(); |
||||
|
||||
//-------------------------
|
||||
// Reload background image:
|
||||
//-------------------------
|
||||
LoadBackImage (); |
||||
SetBackImage (); |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void CBrowserFrame::SetBackImage () |
||||
{ |
||||
CReBarCtrl& rc = m_wndReBar.GetReBarCtrl (); |
||||
|
||||
for (UINT i = 0; i < rc.GetBandCount(); i++) |
||||
{ |
||||
REBARBANDINFO info; |
||||
memset (&info, 0, sizeof (REBARBANDINFO)); |
||||
info.cbSize = sizeof (info); |
||||
info.fMask = RBBIM_BACKGROUND; |
||||
info.hbmBack = theApp.preferences.bToolbarBackground ? (HBITMAP)m_bmpBack : NULL; |
||||
rc.SetBandInfo (i, &info); |
||||
|
||||
CRect rectBand; |
||||
rc.GetRect (i, rectBand); |
||||
|
||||
rc.InvalidateRect (rectBand); |
||||
rc.UpdateWindow (); |
||||
|
||||
info.fMask = RBBIM_CHILD; |
||||
rc.GetBandInfo (i, &info); |
||||
|
||||
if (info.hwndChild != NULL) |
||||
{ |
||||
::InvalidateRect (info.hwndChild, NULL, TRUE); |
||||
::UpdateWindow (info.hwndChild); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void CBrowserFrame::LoadBackImage () |
||||
{ |
||||
//------------------------------------
|
||||
// Load control bars background image:
|
||||
//------------------------------------
|
||||
|
||||
if (m_bmpBack.GetSafeHandle () != NULL) |
||||
{ |
||||
m_bmpBack.DeleteObject (); |
||||
} |
||||
|
||||
HBITMAP hbmp; |
||||
if (theApp.preferences.toolbarBackground.IsEmpty()){ |
||||
hbmp = (HBITMAP) ::LoadImage (AfxGetResourceHandle (), |
||||
MAKEINTRESOURCE (IDB_BACK), |
||||
IMAGE_BITMAP, |
||||
0, 0, |
||||
LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT); |
||||
}else{ |
||||
hbmp = (HBITMAP) ::LoadImage (AfxGetResourceHandle (), |
||||
theApp.preferences.toolbarBackground, |
||||
IMAGE_BITMAP, |
||||
0, 0, |
||||
LR_LOADMAP3DCOLORS | LR_LOADFROMFILE); |
||||
} |
||||
|
||||
m_bmpBack.Attach (hbmp); |
||||
} |
||||
|
||||
#ifdef _DEBUG |
||||
void CBrowserFrame::AssertValid() const |
||||
{ |
||||
CFrameWnd::AssertValid(); |
||||
} |
||||
|
||||
void CBrowserFrame::Dump(CDumpContext& dc) const |
||||
{ |
||||
CFrameWnd::Dump(dc); |
||||
} |
||||
|
||||
#endif //_DEBUG
|
||||
|
@ -0,0 +1,147 @@ |
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* |
||||
* The contents of this file are subject to the Netscape Public |
||||
* License Version 1.1 (the "License"); you may not use this file |
||||
* except in compliance with the License. You may obtain a copy of |
||||
* the License at http://www.mozilla.org/NPL/
|
||||
* |
||||
* Software distributed under the License is distributed on an "AS |
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
||||
* implied. See the License for the specific language governing |
||||
* rights and limitations under the License. |
||||
* |
||||
* The Original Code is mozilla.org code. |
||||
* |
||||
* The Initial Developer of the Original Code is Netscape |
||||
* Communications Corporation. Portions created by Netscape are |
||||
* Copyright (C) 1998 Netscape Communications Corporation. All |
||||
* Rights Reserved. |
||||
* |
||||
* Contributor(s):
|
||||
* Chak Nanga <chak@netscape.com>
|
||||
*/ |
||||
|
||||
// BrowserFrm.h : interface of the CBrowserFrame class
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _IBROWSERFRM_H |
||||
#define _IBROWSERFRM_H |
||||
|
||||
#if _MSC_VER > 1000 |
||||
#pragma once |
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#include "BrowserView.h" |
||||
#include "IBrowserFrameGlue.h" |
||||
|
||||
// A simple UrlBar class...
|
||||
class CUrlBar : public CComboBoxEx |
||||
{ |
||||
public: |
||||
inline GetEnteredURL(CString& url) { |
||||
GetEditCtrl()->GetWindowText(url); |
||||
} |
||||
inline GetSelectedURL(CString& url) { |
||||
GetLBText(GetCurSel(), url); |
||||
} |
||||
inline SetCurrentURL(LPCTSTR pUrl) { |
||||
SetWindowText(pUrl); |
||||
} |
||||
inline AddURLToList(CString& url) { |
||||
COMBOBOXEXITEM ci; |
||||
ci.mask = CBEIF_TEXT; ci.iItem = -1; |
||||
ci.pszText = (LPTSTR)(LPCTSTR)url; |
||||
InsertItem(&ci); |
||||
} |
||||
}; |
||||
|
||||
class CBrowserFrame : public CFrameWnd |
||||
{
|
||||
public: |
||||
CBrowserFrame(PRUint32 chromeMask); |
||||
|
||||
protected:
|
||||
DECLARE_DYNAMIC(CBrowserFrame) |
||||
|
||||
public: |
||||
CToolBar m_wndToolBar; |
||||
CStatusBar m_wndStatusBar; |
||||
CProgressCtrl m_wndProgressBar; |
||||
CUrlBar m_wndUrlBar; |
||||
CReBar m_wndReBar; |
||||
CAnimateCtrl m_wndAnimate; |
||||
|
||||
CImageList m_toolbarHotImageList; |
||||
CImageList m_toolbarColdImageList; |
||||
CImageList m_toolbarDisabledImageList; |
||||
|
||||
CBitmap m_bmpBack; |
||||
|
||||
// The view inside which the embedded browser will
|
||||
// be displayed in
|
||||
CBrowserView m_wndBrowserView; |
||||
|
||||
// This specifies what UI elements this frame will sport
|
||||
// w.r.t. toolbar, statusbar, urlbar etc.
|
||||
PRUint32 m_chromeMask; |
||||
|
||||
protected: |
||||
//
|
||||
// This nested class implements the IBrowserFramGlue interface
|
||||
// The Gecko embedding interfaces call on this interface
|
||||
// to update the status bars etc.
|
||||
//
|
||||
class BrowserFrameGlueObj : public IBrowserFrameGlue
|
||||
{ |
||||
//
|
||||
// NS_DECL_BROWSERFRAMEGLUE below is a macro which expands
|
||||
// to the function prototypes of methods in IBrowserFrameGlue
|
||||
// Take a look at IBrowserFrameGlue.h for this macro define
|
||||
//
|
||||
|
||||
NS_DECL_BROWSERFRAMEGLUE |
||||
|
||||
} m_xBrowserFrameGlueObj; |
||||
friend class BrowserFrameGlueObj; |
||||
|
||||
public: |
||||
void SetupFrameChrome(); |
||||
|
||||
void LoadBackImage (); |
||||
void SetBackImage (); |
||||
|
||||
// Overrides
|
||||
// ClassWizard generated virtual function overrides
|
||||
//{{AFX_VIRTUAL(CBrowserFrame)
|
||||
virtual BOOL PreCreateWindow(CREATESTRUCT& cs); |
||||
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo); |
||||
virtual LRESULT WindowProc( UINT message, WPARAM wParam, LPARAM lParam ); |
||||
//}}AFX_VIRTUAL
|
||||
|
||||
// Implementation
|
||||
public: |
||||
virtual ~CBrowserFrame(); |
||||
#ifdef _DEBUG |
||||
virtual void AssertValid() const; |
||||
virtual void Dump(CDumpContext& dc) const; |
||||
#endif |
||||
|
||||
// Generated message map functions
|
||||
protected: |
||||
//{{AFX_MSG(CBrowserFrame)
|
||||
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); |
||||
afx_msg void OnSetFocus(CWnd *pOldWnd); |
||||
afx_msg void OnSize(UINT nType, int cx, int cy); |
||||
afx_msg void OnClose(); |
||||
afx_msg void OnSysColorChange(); |
||||
//}}AFX_MSG
|
||||
DECLARE_MESSAGE_MAP() |
||||
}; |
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif //_IBROWSERFRM_H
|
@ -0,0 +1,411 @@ |
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* |
||||
* The contents of this file are subject to the Netscape Public |
||||
* License Version 1.1 (the "License"); you may not use this file |
||||
* except in compliance with the License. You may obtain a copy of |
||||
* the License at http://www.mozilla.org/NPL/
|
||||
* |
||||
* Software distributed under the License is distributed on an "AS |
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
||||
* implied. See the License for the specific language governing |
||||
* rights and limitations under the License. |
||||
* |
||||
* The Original Code is mozilla.org code. |
||||
* |
||||
* The Initial Developer of the Original Code is Netscape |
||||
* Communications Corporation. Portions created by Netscape are |
||||
* Copyright (C) 1998 Netscape Communications Corporation. All |
||||
* Rights Reserved. |
||||
* |
||||
* Contributor(s):
|
||||
* Chak Nanga <chak@netscape.com>
|
||||
*/ |
||||
|
||||
// File Overview....
|
||||
// This is the class which implements all the interfaces
|
||||
// required(and optional) by the mozilla embeddable browser engine
|
||||
//
|
||||
// Note that this obj gets passed in the IBrowserFrameGlue* using the
|
||||
// Init() method. Many of the interface implementations use this
|
||||
// to get the actual task done. Ex: to update the status bar
|
||||
//
|
||||
// Look at the INTERFACE_MAP_ENTRY's below for the list of
|
||||
// the currently implemented interfaces
|
||||
//
|
||||
// This file currently has the implementation for all the interfaces
|
||||
// which are required of an app embedding Gecko
|
||||
// Implementation of other optional interfaces are in separate files
|
||||
// so as to avoid cluttering this one. For ex, implementation of
|
||||
// nsIPrompt is in BrowserImplPrompt.cpp etc.
|
||||
//
|
||||
// nsIWebBrowserChrome - This is a required interface to be implemented
|
||||
// by embeddors
|
||||
//
|
||||
// nsIWebBrowserSiteWindow - This is a required interface to be implemented
|
||||
// by embeddors
|
||||
// - SetTitle() gets called after a document
|
||||
// load giving us the chance to update our
|
||||
// titlebar
|
||||
//
|
||||
// Some points to note...
|
||||
//
|
||||
// nsIWebBrowserChrome interface's SetStatus() gets called when a user
|
||||
// mouses over the links on a page
|
||||
//
|
||||
// nsIWebProgressListener interface's OnStatusChange() gets called
|
||||
// to indicate progress when a page is being loaded
|
||||
//
|
||||
// Next suggested file(s) to look at :
|
||||
// Any of the BrowserImpl*.cpp files for other interface
|
||||
// implementation details
|
||||
//
|
||||
|
||||
#include "stdafx.h" |
||||
|
||||
#include "BrowserImpl.h" |
||||
|
||||
CBrowserImpl::CBrowserImpl() |
||||
{ |
||||
NS_INIT_ISUPPORTS(); |
||||
|
||||
m_pBrowserFrameGlue = NULL; |
||||
mWebBrowser = nsnull; |
||||
} |
||||
|
||||
|
||||
CBrowserImpl::~CBrowserImpl() |
||||
{ |
||||
} |
||||
|
||||
// It's very important that the creator of this CBrowserImpl object
|
||||
// Call on this Init() method with proper values after creation
|
||||
//
|
||||
NS_METHOD CBrowserImpl::Init(PBROWSERFRAMEGLUE pBrowserFrameGlue,
|
||||
nsIWebBrowser* aWebBrowser) |
||||
{ |
||||
m_pBrowserFrameGlue = pBrowserFrameGlue; |
||||
|
||||
SetWebBrowser(aWebBrowser); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
//*****************************************************************************
|
||||
// CBrowserImpl::nsISupports
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMPL_ADDREF(CBrowserImpl) |
||||
NS_IMPL_RELEASE(CBrowserImpl) |
||||
|
||||
NS_INTERFACE_MAP_BEGIN(CBrowserImpl) |
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome) |
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) |
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) |
||||
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserSiteWindow) |
||||
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) |
||||
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener) |
||||
NS_INTERFACE_MAP_ENTRY(nsIPrompt) |
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) |
||||
NS_INTERFACE_MAP_END |
||||
|
||||
//*****************************************************************************
|
||||
// CBrowserImpl::nsIInterfaceRequestor
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP CBrowserImpl::GetInterface(const nsIID &aIID, void** aInstancePtr) |
||||
{ |
||||
// Note that we're wrapping our nsIPrompt impl. with the
|
||||
// nsISingleSignOnPrompt - if USE_SINGLE_SIGN_ON is defined
|
||||
// (and if single sign-on support dll's are present and enabled)
|
||||
// This allows the embedding app to use the password save
|
||||
// feature. When signing on to a host which needs authentication
|
||||
// the Single sign-on service will check to see if the auth. info
|
||||
// is already saved and if so uses it to pre-fill the sign-on form
|
||||
// If not, our nsIPrompt impl will be called
|
||||
// to present the auth UI and return the required auth info.
|
||||
// If we do not compile with single sign-on support or if that
|
||||
// service is missing we just fall back to the regular
|
||||
// implementation of nsIPrompt
|
||||
|
||||
if(aIID.Equals(NS_GET_IID(nsIPrompt))) |
||||
{ |
||||
if (!mPrompter) |
||||
{ |
||||
#ifdef USE_SINGLE_SIGN_ON |
||||
nsresult rv; |
||||
nsCOMPtr<nsISingleSignOnPrompt> siPrompt = do_CreateInstance(NS_SINGLESIGNONPROMPT_CONTRACTID, &rv); |
||||
if (NS_SUCCEEDED(rv)) |
||||
{ |
||||
siPrompt->SetPromptDialogs(NS_STATIC_CAST(nsIPrompt*, this)); |
||||
mPrompter = siPrompt; |
||||
} |
||||
else |
||||
#endif |
||||
mPrompter = NS_STATIC_CAST(nsIPrompt*, this); |
||||
} |
||||
NS_ENSURE_TRUE(mPrompter, NS_ERROR_FAILURE); |
||||
return mPrompter->QueryInterface(aIID, aInstancePtr); |
||||
} |
||||
else |
||||
return QueryInterface(aIID, aInstancePtr); |
||||
} |
||||
|
||||
//*****************************************************************************
|
||||
// CBrowserImpl::nsIWebBrowserChrome
|
||||
//*****************************************************************************
|
||||
|
||||
//Gets called when you mouseover links etc. in a web page
|
||||
//
|
||||
NS_IMETHODIMP CBrowserImpl::SetStatus(PRUint32 aType, const PRUnichar* aStatus) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
m_pBrowserFrameGlue->UpdateStatusBarText(aStatus); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::GetWebBrowser(nsIWebBrowser** aWebBrowser) |
||||
{ |
||||
NS_ENSURE_ARG_POINTER(aWebBrowser); |
||||
|
||||
*aWebBrowser = mWebBrowser; |
||||
|
||||
NS_IF_ADDREF(*aWebBrowser); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
// Currently called from Init(). I'm not sure who else
|
||||
// calls this
|
||||
//
|
||||
NS_IMETHODIMP CBrowserImpl::SetWebBrowser(nsIWebBrowser* aWebBrowser) |
||||
{ |
||||
NS_ENSURE_ARG_POINTER(aWebBrowser); |
||||
|
||||
mWebBrowser = aWebBrowser; |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::GetChromeFlags(PRUint32* aChromeMask) |
||||
{ |
||||
return NS_ERROR_NOT_IMPLEMENTED; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::SetChromeFlags(PRUint32 aChromeMask) |
||||
{ |
||||
return NS_ERROR_NOT_IMPLEMENTED; |
||||
} |
||||
|
||||
// Gets called in response to create a new browser window.
|
||||
// Ex: In response to a JavaScript Window.Open() call
|
||||
//
|
||||
//
|
||||
NS_IMETHODIMP CBrowserImpl::CreateBrowserWindow(PRUint32 chromeMask, PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nsIWebBrowser **aWebBrowser) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
if(m_pBrowserFrameGlue->CreateNewBrowserFrame(chromeMask,
|
||||
aX, aY, aCX, aCY, aWebBrowser)) |
||||
return NS_OK; |
||||
else |
||||
return NS_ERROR_FAILURE; |
||||
} |
||||
|
||||
// Gets called in response to create a new browser window.
|
||||
// Ex: In response to a JavaScript Window.Open() call of
|
||||
// the form
|
||||
//
|
||||
// window.open("http://www.mozilla.org", "theWin", ...);
|
||||
//
|
||||
// Here "theWin" is the "targetName" of the window where this URL
|
||||
// is to be loaded into
|
||||
//
|
||||
// So, we get called to see if a target by that name already exists
|
||||
//
|
||||
#if 0 |
||||
/* I didn't really want to mess with your code, but this method has
|
||||
been removed from nsIWebBrowserChrome per the API review meeting |
||||
on 5 Feb 01. |
||||
*/ |
||||
NS_IMETHODIMP CBrowserImpl::FindNamedBrowserItem(const PRUnichar *aName, |
||||
nsIDocShellTreeItem ** aBrowserItem) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
return m_pBrowserFrameGlue->FindNamedBrowserItem(aName, NS_STATIC_CAST(nsIWebBrowserChrome*, this), aBrowserItem); |
||||
} |
||||
#endif |
||||
|
||||
// Gets called in response to set the size of a window
|
||||
// Ex: In response to a JavaScript Window.Open() call of
|
||||
// the form
|
||||
//
|
||||
// window.open("http://www.mozilla.org", "theWin", "width=200, height=400");
|
||||
//
|
||||
// First the CreateBrowserWindow() call will be made followed by a
|
||||
// call to this method to resize the window
|
||||
//
|
||||
NS_IMETHODIMP CBrowserImpl::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
m_pBrowserFrameGlue->SetBrowserFrameSize(aCX, aCY); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::ShowAsModal(void) |
||||
{ |
||||
return NS_ERROR_NOT_IMPLEMENTED; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::IsWindowModal(PRBool *retval) |
||||
{ |
||||
// We're not modal
|
||||
*retval = PR_FALSE; |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::ExitModalEventLoop(nsresult aStatus) |
||||
{ |
||||
return NS_OK; |
||||
} |
||||
|
||||
|
||||
NS_IMETHODIMP |
||||
CBrowserImpl::SetPersistence(PRBool aPersistX, PRBool aPersistY, |
||||
PRBool aPersistCX, PRBool aPersistCY, |
||||
PRBool aPersistSizeMode) |
||||
{ |
||||
return NS_ERROR_NOT_IMPLEMENTED; |
||||
} |
||||
|
||||
NS_IMETHODIMP |
||||
CBrowserImpl::GetPersistence(PRBool* aPersistX, PRBool* aPersistY, |
||||
PRBool* aPersistCX, PRBool* aPersistCY, |
||||
PRBool* aPersistSizeMode) |
||||
{ |
||||
return NS_ERROR_NOT_IMPLEMENTED; |
||||
} |
||||
|
||||
//*****************************************************************************
|
||||
// CBrowserImpl::nsIWebBrowserSiteWindow
|
||||
//*****************************************************************************
|
||||
|
||||
// Will get called in response to JavaScript window.close()
|
||||
//
|
||||
NS_IMETHODIMP CBrowserImpl::Destroy() |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
m_pBrowserFrameGlue->DestroyBrowserFrame(); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::SetPosition(PRInt32 x, PRInt32 y) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
m_pBrowserFrameGlue->SetBrowserFramePosition(x, y); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
NS_IMETHODIMP CBrowserImpl::GetPosition(PRInt32* x, PRInt32* y) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
m_pBrowserFrameGlue->GetBrowserFramePosition(x, y); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
// Gets called when using JavaScript ResizeTo()/ResizeBy() methods
|
||||
//
|
||||
NS_IMETHODIMP CBrowserImpl::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint) |
||||
{ |
||||
if(! m_pBrowserFrameGlue) |
||||
return NS_ERROR_FAILURE; |
||||
|
||||
m_pBrowserFrameGlue->SetBrowserFrameSize(cx, cy); |
||||
|
||||
return NS_OK; |
||||
} |
||||
|
||||
// Gets called when using JavaScript ResizeTo()/ResizeBy() methods
|
||||
//
|
||||