Fixed context menus to work when right clicking over image links. Detabbed file too. b=114427 r=chak@netscape.com sr=blizzard@mozilla.org

This commit is contained in:
locka%iol.ie 2002-01-08 12:15:09 +00:00
Родитель 61aed7e6fd
Коммит ab43b4f842
1 изменённых файлов: 208 добавлений и 195 удалений

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

@ -71,9 +71,9 @@
void CBrowserFrame::BrowserFrameGlueObj::UpdateStatusBarText(const PRUnichar *aMessage) void CBrowserFrame::BrowserFrameGlueObj::UpdateStatusBarText(const PRUnichar *aMessage)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
nsCString strStatus; nsCString strStatus;
if(aMessage) if(aMessage)
strStatus.AssignWithConversion(aMessage); strStatus.AssignWithConversion(aMessage);
@ -83,21 +83,21 @@ void CBrowserFrame::BrowserFrameGlueObj::UpdateStatusBarText(const PRUnichar *aM
void CBrowserFrame::BrowserFrameGlueObj::UpdateProgress(PRInt32 aCurrent, PRInt32 aMax) void CBrowserFrame::BrowserFrameGlueObj::UpdateProgress(PRInt32 aCurrent, PRInt32 aMax)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->m_wndProgressBar.SetRange32(0, aMax); pThis->m_wndProgressBar.SetRange32(0, aMax);
pThis->m_wndProgressBar.SetPos(aCurrent); pThis->m_wndProgressBar.SetPos(aCurrent);
} }
void CBrowserFrame::BrowserFrameGlueObj::UpdateBusyState(PRBool aBusy) void CBrowserFrame::BrowserFrameGlueObj::UpdateBusyState(PRBool aBusy)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
// Just notify the view of the busy state // Just notify the view of the busy state
// There's code in there which will take care of // There's code in there which will take care of
// updating the STOP toolbar btn. etc // updating the STOP toolbar btn. etc
pThis->m_wndBrowserView.UpdateBusyState(aBusy); pThis->m_wndBrowserView.UpdateBusyState(aBusy);
} }
// Called from the OnLocationChange() method in the nsIWebProgressListener // Called from the OnLocationChange() method in the nsIWebProgressListener
@ -107,306 +107,319 @@ void CBrowserFrame::BrowserFrameGlueObj::UpdateBusyState(PRBool aBusy)
// //
void CBrowserFrame::BrowserFrameGlueObj::UpdateCurrentURI(nsIURI *aLocation) void CBrowserFrame::BrowserFrameGlueObj::UpdateCurrentURI(nsIURI *aLocation)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
if(aLocation) if(aLocation)
{ {
nsXPIDLCString uriString; nsXPIDLCString uriString;
aLocation->GetSpec(getter_Copies(uriString)); aLocation->GetSpec(getter_Copies(uriString));
pThis->m_wndUrlBar.SetCurrentURL(uriString.get()); pThis->m_wndUrlBar.SetCurrentURL(uriString.get());
} }
} }
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameTitle(PRUnichar **aTitle) void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameTitle(PRUnichar **aTitle)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
CString title; CString title;
pThis->GetWindowText(title); pThis->GetWindowText(title);
if(!title.IsEmpty()) if(!title.IsEmpty())
{ {
nsString nsTitle; nsString nsTitle;
nsTitle.AssignWithConversion(title.GetBuffer(0)); nsTitle.AssignWithConversion(title.GetBuffer(0));
*aTitle = ToNewUnicode(nsTitle); *aTitle = ToNewUnicode(nsTitle);
} }
} }
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameTitle(const PRUnichar *aTitle) void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameTitle(const PRUnichar *aTitle)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
USES_CONVERSION; USES_CONVERSION;
if(W2T(aTitle)) if(W2T(aTitle))
{ {
pThis->SetWindowText(W2T(aTitle)); pThis->SetWindowText(W2T(aTitle));
} }
else else
{ {
// Use the AppName i.e. mfcembed as the title if we // Use the AppName i.e. mfcembed as the title if we
// do not get one from GetBrowserWindowTitle() // do not get one from GetBrowserWindowTitle()
// //
CString cs; CString cs;
cs.LoadString(AFX_IDS_APP_TITLE); cs.LoadString(AFX_IDS_APP_TITLE);
pThis->SetWindowText(cs); pThis->SetWindowText(cs);
} }
} }
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY) void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFrameSize(PRInt32 aCX, PRInt32 aCY)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->SetWindowPos(NULL, 0, 0, aCX, aCY, pThis->SetWindowPos(NULL, 0, 0, aCX, aCY,
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER
); );
} }
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY) void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameSize(PRInt32 *aCX, PRInt32 *aCY)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
RECT wndRect; RECT wndRect;
pThis->GetWindowRect(&wndRect); pThis->GetWindowRect(&wndRect);
if (aCX) if (aCX)
*aCX = wndRect.right - wndRect.left; *aCX = wndRect.right - wndRect.left;
if (aCY) if (aCY)
*aCY = wndRect.bottom - wndRect.top; *aCY = wndRect.bottom - wndRect.top;
} }
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePosition(PRInt32 aX, PRInt32 aY) void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePosition(PRInt32 aX, PRInt32 aY)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->SetWindowPos(NULL, aX, aY, 0, 0, pThis->SetWindowPos(NULL, aX, aY, 0, 0,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER); SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
} }
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY) void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePosition(PRInt32 *aX, PRInt32 *aY)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
RECT wndRect; RECT wndRect;
pThis->GetWindowRect(&wndRect); pThis->GetWindowRect(&wndRect);
if (aX) if (aX)
*aX = wndRect.left; *aX = wndRect.left;
if (aY) if (aY)
*aY = wndRect.top; *aY = wndRect.top;
} }
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY) void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFramePositionAndSize(PRInt32 *aX, PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
RECT wndRect; RECT wndRect;
pThis->GetWindowRect(&wndRect); pThis->GetWindowRect(&wndRect);
if (aX) if (aX)
*aX = wndRect.left; *aX = wndRect.left;
if (aY) if (aY)
*aY = wndRect.top; *aY = wndRect.top;
if (aCX) if (aCX)
*aCX = wndRect.right - wndRect.left; *aCX = wndRect.right - wndRect.left;
if (aCY) if (aCY)
*aCY = wndRect.bottom - wndRect.top; *aCY = wndRect.bottom - wndRect.top;
} }
void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint) void CBrowserFrame::BrowserFrameGlueObj::SetBrowserFramePositionAndSize(PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, PRBool fRepaint)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->SetWindowPos(NULL, aX, aY, aCX, aCY, pThis->SetWindowPos(NULL, aX, aY, aCX, aCY,
SWP_NOACTIVATE | SWP_NOZORDER); SWP_NOACTIVATE | SWP_NOZORDER);
} }
void CBrowserFrame::BrowserFrameGlueObj::SetFocus() void CBrowserFrame::BrowserFrameGlueObj::SetFocus()
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->SetFocus(); pThis->SetFocus();
} }
void CBrowserFrame::BrowserFrameGlueObj::FocusAvailable(PRBool *aFocusAvail) void CBrowserFrame::BrowserFrameGlueObj::FocusAvailable(PRBool *aFocusAvail)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
HWND focusWnd = GetFocus()->m_hWnd; HWND focusWnd = GetFocus()->m_hWnd;
if ((focusWnd == pThis->m_hWnd) || ::IsChild(pThis->m_hWnd, focusWnd)) if ((focusWnd == pThis->m_hWnd) || ::IsChild(pThis->m_hWnd, focusWnd))
*aFocusAvail = PR_TRUE; *aFocusAvail = PR_TRUE;
else else
*aFocusAvail = PR_FALSE; *aFocusAvail = PR_FALSE;
} }
void CBrowserFrame::BrowserFrameGlueObj::ShowBrowserFrame(PRBool aShow) void CBrowserFrame::BrowserFrameGlueObj::ShowBrowserFrame(PRBool aShow)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
if(aShow) if(aShow)
{ {
pThis->ShowWindow(SW_SHOW); pThis->ShowWindow(SW_SHOW);
pThis->SetActiveWindow(); pThis->SetActiveWindow();
pThis->UpdateWindow(); pThis->UpdateWindow();
} }
else else
{ {
pThis->ShowWindow(SW_HIDE); pThis->ShowWindow(SW_HIDE);
} }
} }
void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameVisibility(PRBool *aVisible) void CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameVisibility(PRBool *aVisible)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
// Is the current BrowserFrame the active one? // Is the current BrowserFrame the active one?
if (GetActiveWindow()->m_hWnd != pThis->m_hWnd) if (GetActiveWindow()->m_hWnd != pThis->m_hWnd)
{ {
*aVisible = PR_FALSE; *aVisible = PR_FALSE;
return; return;
} }
// We're the active one // We're the active one
//Return FALSE if we're minimized //Return FALSE if we're minimized
WINDOWPLACEMENT wpl; WINDOWPLACEMENT wpl;
pThis->GetWindowPlacement(&wpl); pThis->GetWindowPlacement(&wpl);
if ((wpl.showCmd == SW_RESTORE) || (wpl.showCmd == SW_MAXIMIZE)) if ((wpl.showCmd == SW_RESTORE) || (wpl.showCmd == SW_MAXIMIZE))
*aVisible = PR_TRUE; *aVisible = PR_TRUE;
else else
*aVisible = PR_FALSE; *aVisible = PR_FALSE;
} }
PRBool CBrowserFrame::BrowserFrameGlueObj::CreateNewBrowserFrame(PRUint32 chromeMask, PRBool CBrowserFrame::BrowserFrameGlueObj::CreateNewBrowserFrame(PRUint32 chromeMask,
PRInt32 x, PRInt32 y, PRInt32 x, PRInt32 y,
PRInt32 cx, PRInt32 cy, PRInt32 cx, PRInt32 cy,
nsIWebBrowser** aWebBrowser) nsIWebBrowser** aWebBrowser)
{ {
NS_ENSURE_ARG_POINTER(aWebBrowser); NS_ENSURE_ARG_POINTER(aWebBrowser);
*aWebBrowser = nsnull; *aWebBrowser = nsnull;
CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp(); CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp();
if(!pApp) if(!pApp)
return PR_FALSE; return PR_FALSE;
// Note that we're calling with the last param set to "false" i.e. // Note that we're calling with the last param set to "false" i.e.
// this instructs not to show the frame window // this instructs not to show the frame window
// This is mainly needed when the window size is specified in the window.open() // 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 // 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 // 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 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 // the window size changes on the screen causing an unappealing flicker
// //
CBrowserFrame* pFrm = pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, PR_FALSE); CBrowserFrame* pFrm = pApp->CreateNewBrowserFrame(chromeMask, x, y, cx, cy, PR_FALSE);
if(!pFrm) if(!pFrm)
return PR_FALSE; return PR_FALSE;
// At this stage we have a new CBrowserFrame and a new CBrowserView // At this stage we have a new CBrowserFrame and a new CBrowserView
// objects. The CBrowserView also would have an embedded browser // objects. The CBrowserView also would have an embedded browser
// object created. Get the mWebBrowser member from the CBrowserView // object created. Get the mWebBrowser member from the CBrowserView
// and return it. (See CBrowserView's CreateBrowser() on how the // and return it. (See CBrowserView's CreateBrowser() on how the
// embedded browser gets created and how it's mWebBrowser member // embedded browser gets created and how it's mWebBrowser member
// gets initialized) // gets initialized)
NS_IF_ADDREF(*aWebBrowser = pFrm->m_wndBrowserView.mWebBrowser); NS_IF_ADDREF(*aWebBrowser = pFrm->m_wndBrowserView.mWebBrowser);
return PR_TRUE; return PR_TRUE;
} }
void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame() void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame()
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
pThis->PostMessage(WM_CLOSE); pThis->PostMessage(WM_CLOSE);
} }
void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode) void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode)
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
UINT nIDResource = IDR_CTXMENU_DOCUMENT; UINT nIDResource = IDR_CTXMENU_DOCUMENT;
if(aContextFlags & nsIContextMenuListener::CONTEXT_DOCUMENT) if(aContextFlags & nsIContextMenuListener::CONTEXT_DOCUMENT)
nIDResource = IDR_CTXMENU_DOCUMENT; nIDResource = IDR_CTXMENU_DOCUMENT;
else if(aContextFlags & nsIContextMenuListener::CONTEXT_TEXT) else if(aContextFlags & nsIContextMenuListener::CONTEXT_TEXT)
nIDResource = IDR_CTXMENU_TEXT; nIDResource = IDR_CTXMENU_TEXT;
else if(aContextFlags & nsIContextMenuListener::CONTEXT_LINK) else if(aContextFlags & nsIContextMenuListener::CONTEXT_LINK)
{ {
nIDResource = IDR_CTXMENU_LINK; nIDResource = IDR_CTXMENU_LINK;
// Since we handle all the browser menu/toolbar commands // Since we handle all the browser menu/toolbar commands
// in the View, we basically setup the Link's URL in the // in the View, we basically setup the Link's URL in the
// BrowserView object. When a menu selection in the context // BrowserView object. When a menu selection in the context
// menu is made, the appropriate command handler in the // menu is made, the appropriate command handler in the
// BrowserView will be invoked and the value of the URL // BrowserView will be invoked and the value of the URL
// will be accesible in the view // will be accesible in the view
// Reset the value from the last invocation // Reset the value from the last invocation
// (A new value will be set after we determine it below) // (A new value will be set after we determine it below)
// //
nsAutoString strUrlUcs2; nsAutoString strUrlUcs2;
pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2); pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2);
// Get the URL from the link. This is two step process // Get the URL from the link. This is two step process
// 1. We first get the nsIDOMHTMLAnchorElement // 1. We first get the nsIDOMHTMLAnchorElement
// 2. We then get the URL associated with the link // 2. We then get the URL associated with the link
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(aNode, &rv));
if(NS_FAILED(rv))
return;
rv = linkElement->GetHref(strUrlUcs2); // Search for an anchor element
if(NS_FAILED(rv)) nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement;
return; nsCOMPtr<nsIDOMNode> node = aNode;
while (node)
{
linkElement = do_QueryInterface(node);
if (linkElement)
break;
// Update the view with the new LinkUrl nsCOMPtr<nsIDOMNode> parentNode;
// Note that this string is in UCS2 format node->GetParentNode(getter_AddRefs(parentNode));
pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2); node = parentNode;
} }
else if(aContextFlags & nsIContextMenuListener::CONTEXT_IMAGE) if (!linkElement)
{ return;
nIDResource = IDR_CTXMENU_IMAGE;
nsAutoString strImgSrcUcs2; rv = linkElement->GetHref(strUrlUcs2);
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Clear it if(NS_FAILED(rv))
return;
// Get the IMG SRC // Update the view with the new LinkUrl
nsresult rv = NS_OK; // Note that this string is in UCS2 format
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aNode, &rv)); pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2);
if(NS_FAILED(rv)) }
return; else if(aContextFlags & nsIContextMenuListener::CONTEXT_IMAGE)
{
nIDResource = IDR_CTXMENU_IMAGE;
rv = imgElement->GetSrc(strImgSrcUcs2); nsAutoString strImgSrcUcs2;
if(NS_FAILED(rv)) pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Clear it
return;
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Set the new Img Src // Get the IMG SRC
} nsresult rv = NS_OK;
nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aNode, &rv));
if(NS_FAILED(rv))
return;
CMenu ctxMenu; rv = imgElement->GetSrc(strImgSrcUcs2);
if(ctxMenu.LoadMenu(nIDResource)) if(NS_FAILED(rv))
{ return;
POINT cursorPos;
GetCursorPos(&cursorPos);
(ctxMenu.GetSubMenu(0))->TrackPopupMenu(TPM_LEFTALIGN, cursorPos.x, cursorPos.y, pThis); 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, cursorPos.x, cursorPos.y, pThis);
}
} }
HWND CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameNativeWnd() HWND CBrowserFrame::BrowserFrameGlueObj::GetBrowserFrameNativeWnd()
{ {
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj) METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
return pThis->m_hWnd; return pThis->m_hWnd;
} }
void CBrowserFrame::BrowserFrameGlueObj::UpdateSecurityStatus(PRInt32 aState) void CBrowserFrame::BrowserFrameGlueObj::UpdateSecurityStatus(PRInt32 aState)