From 64158e99f8dc71162be1bc347c473f821a4057a9 Mon Sep 17 00:00:00 2001 From: "chak%netscape.com" Date: Sat, 12 Jan 2002 15:11:06 +0000 Subject: [PATCH] #111320 - Add ViewFrameSource/OpenFrameInNewWindo context menus sr=jst --- embedding/tests/mfcembed/BrowserFrameGlue.cpp | 51 ++++++++++++++++ embedding/tests/mfcembed/BrowserView.cpp | 59 ++++++++++++++++++- embedding/tests/mfcembed/BrowserView.h | 7 +++ embedding/tests/mfcembed/MfcEmbed.rc | 2 + embedding/tests/mfcembed/StdAfx.h | 3 + embedding/tests/mfcembed/resource.h | 8 ++- 6 files changed, 126 insertions(+), 4 deletions(-) diff --git a/embedding/tests/mfcembed/BrowserFrameGlue.cpp b/embedding/tests/mfcembed/BrowserFrameGlue.cpp index 1f5314add1b4..444937c2f581 100644 --- a/embedding/tests/mfcembed/BrowserFrameGlue.cpp +++ b/embedding/tests/mfcembed/BrowserFrameGlue.cpp @@ -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 domDoc; + rv = aNode->GetOwnerDocument(getter_AddRefs(domDoc)); + if(NS_FAILED(rv)) + GOTO_BUILD_CTX_MENU; + + nsCOMPtr 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); diff --git a/embedding/tests/mfcembed/BrowserView.cpp b/embedding/tests/mfcembed/BrowserView.cpp index 06a981a424e4..c1172391a4b8 100644 --- a/embedding/tests/mfcembed/BrowserView.cpp +++ b/embedding/tests/mfcembed/BrowserView.cpp @@ -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 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 domDoc; + rv = mWebNav->GetDocument(getter_AddRefs(domDoc)); + if(NS_FAILED(rv)) + return FALSE; + + // QI nsIDOMDocument for nsIDOMHTMLDocument + nsCOMPtr htmlDoc = do_QueryInterface(domDoc); + if (!htmlDoc) + return FALSE; + + // Get the element of the doc + nsCOMPtr body; + rv = htmlDoc->GetBody(getter_AddRefs(body)); + if(NS_FAILED(rv)) + return FALSE; + + // Is it of type nsIDOMHTMLFrameSetElement? + nsCOMPtr 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()); +} diff --git a/embedding/tests/mfcembed/BrowserView.h b/embedding/tests/mfcembed/BrowserView.h index 01eac69dfcc2..04b3aef61aec 100644 --- a/embedding/tests/mfcembed/BrowserView.h +++ b/embedding/tests/mfcembed/BrowserView.h @@ -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 // diff --git a/embedding/tests/mfcembed/MfcEmbed.rc b/embedding/tests/mfcembed/MfcEmbed.rc index 112c460c3245..43621b674c33 100644 --- a/embedding/tests/mfcembed/MfcEmbed.rc +++ b/embedding/tests/mfcembed/MfcEmbed.rc @@ -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 diff --git a/embedding/tests/mfcembed/StdAfx.h b/embedding/tests/mfcembed/StdAfx.h index 4ada349317c0..63631a15bbef 100644 --- a/embedding/tests/mfcembed/StdAfx.h +++ b/embedding/tests/mfcembed/StdAfx.h @@ -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" diff --git a/embedding/tests/mfcembed/resource.h b/embedding/tests/mfcembed/resource.h index 52161558470d..f9c217fd7a1f 100644 --- a/embedding/tests/mfcembed/resource.h +++ b/embedding/tests/mfcembed/resource.h @@ -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