#111320 - Add ViewFrameSource/OpenFrameInNewWindo context menus

sr=jst
This commit is contained in:
chak%netscape.com 2002-01-12 15:11:06 +00:00
parent 77c92f7bd9
commit 64158e99f8
6 changed files with 126 additions and 4 deletions

View File

@ -330,6 +330,8 @@ void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame()
pThis->PostMessage(WM_CLOSE);
}
#define GOTO_BUILD_CTX_MENU { bContentHasFrames = FALSE; goto BUILD_CTX_MENU; }
void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode)
{
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
@ -406,9 +408,58 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags,
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Set the new Img Src
}
// Determine if we need to add the Frame related context menu items
// such as "View Frame Source" etc.
//
BOOL bContentHasFrames = FALSE;
if(pThis->m_wndBrowserView.ViewContentContainsFrames())
{
bContentHasFrames = TRUE;
nsAutoString strFrameURL;
pThis->m_wndBrowserView.SetCurrentFrameURL(strFrameURL); // Clear it
//Determine the current Frame URL
//
nsresult rv = NS_OK;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = aNode->GetOwnerDocument(getter_AddRefs(domDoc));
if(NS_FAILED(rv))
GOTO_BUILD_CTX_MENU;
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc(do_QueryInterface(domDoc, &rv));
if(NS_FAILED(rv))
GOTO_BUILD_CTX_MENU;
rv = htmlDoc->GetURL(strFrameURL);
if(NS_FAILED(rv))
GOTO_BUILD_CTX_MENU;
pThis->m_wndBrowserView.SetCurrentFrameURL(strFrameURL); //Set it to the new URL
}
BUILD_CTX_MENU:
CMenu ctxMenu;
if(ctxMenu.LoadMenu(nIDResource))
{
//Append the Frame related menu items if content has frames
if(bContentHasFrames)
{
CMenu* pCtxMenu = ctxMenu.GetSubMenu(0);
if(pCtxMenu)
{
pCtxMenu->AppendMenu(MF_SEPARATOR);
CString strMenuItem;
strMenuItem.LoadString(IDS_VIEW_FRAME_SOURCE);
pCtxMenu->AppendMenu(MF_STRING, ID_VIEW_FRAME_SOURCE, strMenuItem);
strMenuItem.LoadString(IDS_OPEN_FRAME_IN_NEW_WINDOW);
pCtxMenu->AppendMenu(MF_STRING, ID_OPEN_FRAME_IN_NEW_WINDOW, strMenuItem);
}
}
POINT cursorPos;
GetCursorPos(&cursorPos);

View File

@ -75,7 +75,6 @@
// Mozilla Includes
#include "nsIWidget.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
@ -120,8 +119,9 @@ BEGIN_MESSAGE_MAP(CBrowserView, CWnd)
ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
ON_COMMAND(ID_FILE_PRINTPREVIEW, OnFilePrintPreview)
ON_COMMAND(ID_FILE_PRINTSETUP, OnFilePrintSetup)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
ON_REGISTERED_MESSAGE(WM_FINDMSG, OnFindMsg)
ON_COMMAND(ID_VIEW_FRAME_SOURCE, OnViewFrameSource)
ON_COMMAND(ID_OPEN_FRAME_IN_NEW_WINDOW, OnOpenFrameInNewWindow)
// Menu/Toolbar UI update handlers
ON_UPDATE_COMMAND_UI(ID_NAV_BACK, OnUpdateNavBack)
@ -130,6 +130,7 @@ BEGIN_MESSAGE_MAP(CBrowserView, CWnd)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdatePaste)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@ -1130,6 +1131,11 @@ void CBrowserView::SetCtxMenuImageSrc(nsAutoString& strImgSrc)
mCtxMenuImgSrc = strImgSrc;
}
void CBrowserView::SetCurrentFrameURL(nsAutoString& strCurrentFrameURL)
{
mCtxMenuCurrentFrameURL = strCurrentFrameURL;
}
void CBrowserView::Activate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(mWebBrowser));
@ -1162,3 +1168,52 @@ void CBrowserView::ShowSecurityInfo()
::MessageBox(hParent, "To Be Done..........", "MfcEmbed", MB_OK);
}
// Determintes if the currently loaded document
// contains frames
//
BOOL CBrowserView::ViewContentContainsFrames()
{
nsresult rv = NS_OK;
// Get nsIDOMDocument from nsIWebNavigation
nsCOMPtr<nsIDOMDocument> domDoc;
rv = mWebNav->GetDocument(getter_AddRefs(domDoc));
if(NS_FAILED(rv))
return FALSE;
// QI nsIDOMDocument for nsIDOMHTMLDocument
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(domDoc);
if (!htmlDoc)
return FALSE;
// Get the <body> element of the doc
nsCOMPtr<nsIDOMHTMLElement> body;
rv = htmlDoc->GetBody(getter_AddRefs(body));
if(NS_FAILED(rv))
return FALSE;
// Is it of type nsIDOMHTMLFrameSetElement?
nsCOMPtr<nsIDOMHTMLFrameSetElement> frameset = do_QueryInterface(body);
return (frameset != nsnull);
}
void CBrowserView::OnViewFrameSource()
{
USES_CONVERSION;
// Build the view-source: url
//
nsCAutoString viewSrcUrl;
viewSrcUrl.Append("view-source:");
viewSrcUrl.Append(W2T(mCtxMenuCurrentFrameURL.get()));
OpenViewSourceWindow(viewSrcUrl.get());
}
void CBrowserView::OnOpenFrameInNewWindow()
{
if(mCtxMenuCurrentFrameURL.Length())
OpenURLInNewWindow(mCtxMenuCurrentFrameURL.get());
}

View File

@ -110,6 +110,9 @@ public:
void SetCtxMenuImageSrc(nsAutoString& strImgSrc);
nsAutoString mCtxMenuImgSrc;
void SetCurrentFrameURL(nsAutoString& strCurrentFrameURL);
nsString mCtxMenuCurrentFrameURL;
inline void ClearFindDialog() { m_pFindDlg = NULL; }
CFindDialog* m_pFindDlg;
CPrintProgressDialog* m_pPrintProgressDlg;
@ -135,6 +138,8 @@ public:
};
int m_SecurityState;
void ShowSecurityInfo();
BOOL ViewContentContainsFrames();
// Overrides
// ClassWizard generated virtual function overrides
@ -185,6 +190,8 @@ protected:
afx_msg void OnFilePrintSetup();
afx_msg void OnUpdateFilePrint(CCmdUI* pCmdUI);
afx_msg LRESULT OnFindMsg(WPARAM wParam, LPARAM lParam);
afx_msg void OnViewFrameSource();
afx_msg void OnOpenFrameInNewWindow();
// Handlers to keep the toolbar/menu items up to date
//

View File

@ -597,6 +597,8 @@ STRINGTABLE DISCARDABLE
BEGIN
ID_FILE_PRINTPREVIEW "Print Preview"
ID_FILE_PRINTSETUP "Page Setup Dialog"
IDS_VIEW_FRAME_SOURCE "View Frame Source"
IDS_OPEN_FRAME_IN_NEW_WINDOW "Open Frame in New Window"
END
#endif // English (U.S.) resources

View File

@ -104,6 +104,9 @@
#include "nsIDOMNode.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLFrameSetElement.h"
#include "nsReadableUtils.h"
#include "nsIPrompt.h"
#include "nsEmbedAPI.h"

View File

@ -27,6 +27,8 @@
#define IDS_ENCRYPTION_NONE 149
#define IDS_SRCH_STR_NOT_FOUND 150
#define IDD_PRINTSETUP_DIALOG 152
#define IDS_VIEW_FRAME_SOURCE 153
#define IDS_OPEN_FRAME_IN_NEW_WINDOW 154
#define ID_URL_BAR 1001
#define ID_PROG_BAR 1002
#define IDC_PROMPT_ANSWER 1003
@ -94,14 +96,16 @@
#define ID_EDIT_PREFERENCES 32788
#define ID_FILE_PRINTPREVIEW 32789
#define ID_FILE_PRINTSETUP 32790
#define ID_VIEW_FRAME_SOURCE 32791
#define ID_OPEN_FRAME_IN_NEW_WINDOW 32792
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_3D_CONTROLS 1
#define _APS_NEXT_RESOURCE_VALUE 154
#define _APS_NEXT_COMMAND_VALUE 32791
#define _APS_NEXT_RESOURCE_VALUE 155
#define _APS_NEXT_COMMAND_VALUE 32793
#define _APS_NEXT_CONTROL_VALUE 1042
#define _APS_NEXT_SYMED_VALUE 101
#endif