Bugscape 8854 - allow access to background images for embedding context menu listeners. Adding new interfaces, nsIContextMenuListener2 and nsIContextMenuInfo, to allow access to more information about the menu context. Also fixes bug 163928. r=pinkerton/sr=alecf

This commit is contained in:
ccarlen%netscape.com 2002-09-16 00:13:37 +00:00
parent 293744eaed
commit 8f95a67ae1
17 changed files with 286 additions and 117 deletions

View File

@ -745,6 +745,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIContextMenuListener2.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIWebBrowserSetup.idl</PATH>
@ -847,6 +854,11 @@
<PATH>nsIContextMenuListener.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIContextMenuListener2.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsITooltipListener.idl</PATH>
@ -1586,6 +1598,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIContextMenuListener2.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIWebBrowserSetup.idl</PATH>
@ -1683,6 +1702,11 @@
<PATH>nsIContextMenuListener.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIContextMenuListener2.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIWebBrowserSetup.idl</PATH>
@ -1761,6 +1785,12 @@
<PATH>nsIContextMenuListener.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>embeddingbrowser.xpt</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsIContextMenuListener2.idl</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>embeddingbrowser.xpt</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>

View File

@ -1014,6 +1014,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContextMenuInfo.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStaticDebug.o</PATH>
@ -1078,6 +1085,11 @@
<PATH>nsWebBrowserContentPolicy.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContextMenuInfo.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStaticDebug.o</PATH>
@ -2046,6 +2058,13 @@
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContextMenuInfo.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
<FILEKIND>Text</FILEKIND>
<FILEFLAGS></FILEFLAGS>
</FILE>
<FILE>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStatic.o</PATH>
@ -2110,6 +2129,11 @@
<PATH>nsWebBrowserContentPolicy.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContextMenuInfo.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<PATHTYPE>Name</PATHTYPE>
<PATH>UnicharUtilsStatic.o</PATH>
@ -2170,6 +2194,12 @@
<PATH>nsWebBrowserContentPolicy.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
<FILEREF>
<TARGETNAME>webBrowserDebug.shlb</TARGETNAME>
<PATHTYPE>Name</PATHTYPE>
<PATH>nsContextMenuInfo.cpp</PATH>
<PATHFORMAT>MacOS</PATHFORMAT>
</FILEREF>
</GROUP>
<GROUP><NAME>NS Libraries</NAME>
<GROUP><NAME>Debug</NAME>

View File

@ -41,9 +41,12 @@ resource 'Mcmd' (mcmd_BrowserShellContextMenuCmds, "BrowserShellContextMenu") {
msg_Nothing,
cmd_ViewPageSource,
cmd_ViewImage,
cmd_ViewBackgroundImage,
msg_Nothing,
cmd_SelectAll,
cmd_Copy,
msg_Nothing,
cmd_CopyImage,
cmd_CopyLinkLocation,
cmd_CopyImageLocation,
msg_Nothing,
@ -69,6 +72,8 @@ resource 'MENU' (menu_Buzzwords, "Buzzwords") {
"Stop", noIcon, noKey, noMark, plain,
"View Page Source", noIcon, noKey, noMark, plain,
"View Image", noIcon, noKey, noMark, plain,
"View Background Image", noIcon, noKey, noMark, plain,
"Copy Image", noIcon, noKey, noMark, plain,
"Copy Link Location", noIcon, noKey, noMark, plain,
"Copy Image Location", noIcon, noKey, noMark, plain,
}
@ -82,6 +87,8 @@ resource 'Mcmd' (menu_Buzzwords, "Buzzwords") { {
cmd_Stop,
cmd_ViewPageSource,
cmd_ViewImage,
cmd_ViewBackgroundImage,
cmd_CopyImage,
cmd_CopyLinkLocation,
cmd_CopyImageLocation,
} };

View File

@ -160,6 +160,9 @@ enum {
cmd_ViewPageSource = 'VSrc',
cmd_ViewImage = 'VImg',
cmd_ViewBackgroundImage = 'VBIm',
cmd_CopyImage = 'CpIm',
cmd_CopyLinkLocation = 'CLnk',
cmd_CopyImageLocation = 'CImg',

View File

@ -115,7 +115,7 @@ NS_IMPL_ISUPPORTS8(CBrowserChrome,
nsIWebBrowserChromeFocus,
nsIEmbeddingSiteWindow,
nsIEmbeddingSiteWindow2,
nsIContextMenuListener,
nsIContextMenuListener2,
nsITooltipListener,
nsISupportsWeakReference);
@ -438,16 +438,16 @@ NS_IMETHODIMP CBrowserChrome::Blur(void)
}
//*****************************************************************************
// CBrowserChrome::nsIContextMenuListener
// CBrowserChrome::nsIContextMenuListener2
//*****************************************************************************
NS_IMETHODIMP CBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
NS_IMETHODIMP CBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo)
{
nsresult rv;
try
{
rv = mBrowserShell->OnShowContextMenu(aContextFlags, aEvent, aNode);
rv = mBrowserShell->OnShowContextMenu(aContextFlags, aInfo);
}
catch (...)
{
@ -456,7 +456,6 @@ NS_IMETHODIMP CBrowserChrome::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEv
return rv;
}
//*****************************************************************************
// CBrowserChrome::nsITooltipListener
//*****************************************************************************

View File

@ -47,11 +47,10 @@
// Interfaces Needed
#include "nsIWebBrowserChrome.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIEmbeddingSiteWindow2.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIContextMenuListener.h"
#include "nsIContextMenuListener2.h"
#include "nsITooltipListener.h"
#include "nsWeakReference.h"
@ -67,7 +66,7 @@ class CBrowserChrome : public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow2,
public nsIInterfaceRequestor,
public nsIContextMenuListener,
public nsIContextMenuListener2,
public nsITooltipListener,
public nsSupportsWeakReference,
public LListener
@ -81,7 +80,7 @@ public:
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIEMBEDDINGSITEWINDOW2
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICONTEXTMENULISTENER
NS_DECL_NSICONTEXTMENULISTENER2
NS_DECL_NSITOOLTIPLISTENER
// LListener

View File

@ -47,11 +47,13 @@
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMHTMLLinkElement.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLImageElement.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMLocation.h"
#include "nsIWebBrowserFind.h"
#include "nsIWebBrowserFocus.h"
#include "nsIWebBrowserPersist.h"
#include "imgIContainer.h"
#include "nsIURI.h"
#include "nsWeakPtr.h"
#include "nsRect.h"
@ -65,6 +67,8 @@
#include "nsIMacTextInputEventSink.h"
#include "nsCRT.h"
#include "nsNetUtil.h"
#include "gfxIImageFrame.h"
#include "nsIImage.h"
// Local
#include "ApplIDs.h"
@ -251,7 +255,7 @@ NS_IMETHODIMP CBrowserShellProgressListener::OnSecurityChange(nsIWebProgress *aW
CBrowserShell::CBrowserShell() :
mChromeFlags(nsIWebBrowserChrome::CHROME_DEFAULT), mIsMainContent(true),
mContextMenuContext(nsIContextMenuListener::CONTEXT_NONE), mContextMenuDOMNode(nsnull),
mContextMenuFlags(nsIContextMenuListener2::CONTEXT_NONE),
LDropArea(GetMacWindow())
{
nsresult rv = CommonConstruct();
@ -266,8 +270,7 @@ CBrowserShell::CBrowserShell(const SPaneInfo &inPaneInfo,
const Boolean inIsMainContent) :
LView(inPaneInfo, inViewInfo), LDropArea(GetMacWindow()),
mChromeFlags(inChromeFlags), mIsMainContent(inIsMainContent),
mContextMenuContext(nsIContextMenuListener::CONTEXT_NONE), mContextMenuDOMNode(nsnull)
mContextMenuFlags(nsIContextMenuListener2::CONTEXT_NONE)
{
nsresult rv = CommonConstruct();
if (rv != NS_OK)
@ -277,7 +280,7 @@ CBrowserShell::CBrowserShell(const SPaneInfo &inPaneInfo,
CBrowserShell::CBrowserShell(LStream* inStream) :
LView(inStream), LDropArea(GetMacWindow()),
mContextMenuContext(nsIContextMenuListener::CONTEXT_NONE), mContextMenuDOMNode(nsnull)
mContextMenuFlags(nsIContextMenuListener2::CONTEXT_NONE)
{
*inStream >> mChromeFlags;
*inStream >> mIsMainContent;
@ -600,41 +603,24 @@ Boolean CBrowserShell::ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioPa
break;
case cmd_OpenLinkInNewWindow:
case cmd_CopyLinkLocation:
{
// Get the URL from the link
ThrowIfNil_(mContextMenuDOMNode);
nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(mContextMenuDOMNode));
// If that failed and, if the context of a click was in an image, find the parent
// node of the image which CAN be QI'd to an nsIDOMHTMLAnchorElement.
if (!linkElement && (mContextMenuContext & nsIContextMenuListener::CONTEXT_IMAGE))
{
nsCOMPtr<nsIDOMNode> curr;
mContextMenuDOMNode->GetParentNode(getter_AddRefs(curr));
while (curr)
{
nsCOMPtr<nsIDOMElement> content = do_QueryInterface(curr);
if (!content)
break;
linkElement = do_QueryInterface(content);
if (linkElement)
break;
nsCOMPtr<nsIDOMNode> temp = curr;
temp->GetParentNode(getter_AddRefs(curr));
}
}
ThrowIfNil_(linkElement);
ThrowIfNil_(mContextMenuInfo);
nsAutoString temp;
rv = linkElement->GetHref(temp);
rv = mContextMenuInfo->GetAssociatedLink(temp);
ThrowIfError_(rv);
nsCAutoString urlSpec = NS_ConvertUCS2toUTF8(temp);
nsCAutoString referrer;
rv = GetFocusedWindowURL(temp);
if (NS_SUCCEEDED(rv))
referrer = NS_ConvertUCS2toUTF8(temp);
PostOpenURLEvent(urlSpec, referrer);
if (inCommand == cmd_OpenLinkInNewWindow) {
nsCAutoString referrer;
rv = GetFocusedWindowURL(temp);
if (NS_SUCCEEDED(rv))
referrer = NS_ConvertUCS2toUTF8(temp);
PostOpenURLEvent(urlSpec, referrer);
}
else
UScrap::SetData(kScrapFlavorTypeText, urlSpec.get(), urlSpec.Length());
}
break;
@ -682,7 +668,45 @@ Boolean CBrowserShell::ObeyCommand(PP_PowerPlant::CommandT inCommand, void* ioPa
PostOpenURLEvent(currentURL, nsCString());
}
break;
case cmd_ViewImage:
case cmd_CopyImageLocation:
{
ThrowIfNil_(mContextMenuInfo);
nsCOMPtr<nsIURI> imgURI;
mContextMenuInfo->GetImageSrc(getter_AddRefs(imgURI));
ThrowIfNil_(imgURI);
nsCAutoString temp;
rv = imgURI->GetSpec(temp);
ThrowIfError_(rv);
if (inCommand == cmd_ViewImage)
PostOpenURLEvent(temp, nsCString());
else
UScrap::SetData(kScrapFlavorTypeText, temp.get(), temp.Length());
}
break;
case cmd_ViewBackgroundImage:
{
ThrowIfNil_(mContextMenuInfo);
nsCOMPtr<nsIURI> uri;
rv = mContextMenuInfo->GetBackgroundImageSrc(getter_AddRefs(uri));
ThrowIfNil_(uri);
nsCAutoString temp;
rv = uri->GetSpec(temp);
ThrowIfError_(rv);
PostOpenURLEvent(temp, nsCString());
}
break;
case cmd_CopyImage:
{
GetClipboardHandler(getter_AddRefs(clipCmd));
if (clipCmd)
clipCmd->CopyImageContents();
}
break;
default:
cmdHandled = LCommander::ObeyCommand(inCommand, ioParam);
break;
@ -769,7 +793,7 @@ void CBrowserShell::FindCommandStatus(PP_PowerPlant::CommandT inCommand,
break;
case cmd_OpenLinkInNewWindow:
outEnabled = haveContent && ((mContextMenuContext & nsIContextMenuListener::CONTEXT_LINK) != 0);
outEnabled = haveContent && mContextMenuInfo && ((mContextMenuFlags & nsIContextMenuListener2::CONTEXT_LINK) != 0);
break;
case cmd_ViewPageSource:
@ -777,12 +801,29 @@ void CBrowserShell::FindCommandStatus(PP_PowerPlant::CommandT inCommand,
break;
case cmd_ViewImage:
case cmd_CopyImageLocation:
outEnabled = haveContent && ((mContextMenuContext & nsIContextMenuListener::CONTEXT_IMAGE) != 0);
outEnabled = haveContent && mContextMenuInfo && ((mContextMenuFlags & nsIContextMenuListener2::CONTEXT_IMAGE) != 0);
break;
case cmd_ViewBackgroundImage:
outEnabled = haveContent && mContextMenuInfo && ((mContextMenuFlags & nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE) != 0);
break;
case cmd_CopyImage:
if (haveContent) {
rv = GetClipboardHandler(getter_AddRefs(clipCmd));
if (NS_SUCCEEDED(rv)) {
rv = clipCmd->CanCopyImageContents(&canDo);
outEnabled = NS_SUCCEEDED(rv) && canDo;
}
}
break;
case cmd_CopyLinkLocation:
outEnabled = haveContent && ((mContextMenuContext & nsIContextMenuListener::CONTEXT_LINK) != 0);
outEnabled = haveContent && mContextMenuInfo && ((mContextMenuFlags & nsIContextMenuListener2::CONTEXT_LINK) != 0);
break;
case cmd_CopyImageLocation:
outEnabled = haveContent && mContextMenuInfo && ((mContextMenuFlags & nsIContextMenuListener2::CONTEXT_IMAGE) != 0);
break;
case cmd_SaveFormData:
@ -1270,8 +1311,7 @@ Boolean CBrowserShell::FindNext()
NS_IMETHODIMP CBrowserShell::OnShowContextMenu(PRUint32 aContextFlags,
nsIDOMEvent *aEvent,
nsIDOMNode *aNode)
nsIContextMenuInfo *aInfo)
{
// Find our CWebBrowserCMAttachment, if any
CWebBrowserCMAttachment *aCMAttachment = nsnull;
@ -1295,11 +1335,11 @@ NS_IMETHODIMP CBrowserShell::OnShowContextMenu(PRUint32 aContextFlags,
EventRecord macEvent;
UEventMgr::GetMouseAndModifiers(macEvent);
mContextMenuContext = aContextFlags;
mContextMenuDOMNode = aNode;
mContextMenuFlags = aContextFlags;
mContextMenuInfo = aInfo;
aCMAttachment->DoContextMenuClick(macEvent);
mContextMenuContext = 0;
mContextMenuDOMNode = nsnull;
mContextMenuFlags = 0;
mContextMenuInfo = nsnull;
return NS_OK;
}

View File

@ -47,6 +47,7 @@ class nsIContentViewer;
class nsIClipboardCommands;
class nsIDOMEvent;
class nsIDOMNode;
class nsIContextMenuInfo;
//*****************************************************************************
//*** CBrowserShell
@ -185,8 +186,7 @@ protected:
virtual void DoDragReceive( DragReference inDragRef );
NS_IMETHOD OnShowContextMenu(PRUint32 aContextFlags,
nsIDOMEvent *aEvent,
nsIDOMNode *aNode);
nsIContextMenuInfo *aInfo);
NS_IMETHOD OnShowTooltip(PRInt32 aXCoords,
PRInt32 aYCoords,
@ -229,8 +229,8 @@ protected:
// These are stored only during OnShowContextMenu so that they can
// be used by FindCommandStatus and ObeyCommand which get called
// during OnShowContextMenu.
PRUint32 mContextMenuContext;
nsIDOMNode *mContextMenuDOMNode;
PRUint32 mContextMenuFlags;
nsIContextMenuInfo *mContextMenuInfo;
nsCOMPtr<nsIPrintSettings> mPrintSettings;
};

View File

@ -43,6 +43,9 @@ REQUIRES = xpcom \
appcomps \
webbrowserpersist \
unicharutil \
imglib2 \
gfx2 \
locale \
$(NULL)
include $(DEPTH)/config/autoconf.mk
@ -67,6 +70,7 @@ XPIDLSRCS = \
nsIWebBrowserChromeFocus.idl \
nsICommandHandler.idl \
nsIEmbeddingSiteWindow2.idl \
nsIContextMenuListener2.idl \
nsIWebBrowserFocus.idl \
nsIPrintingPrompt.idl \
nsIPrintingPromptService.idl \
@ -77,6 +81,7 @@ CPPSRCS = \
nsWebBrowser.cpp \
nsCommandHandler.cpp \
nsWebBrowserContentPolicy.cpp \
nsContextMenuInfo.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a

View File

@ -42,6 +42,7 @@
// Interfaces needed to be included
#include "nsIContextMenuListener.h"
#include "nsIContextMenuListener2.h"
#include "nsITooltipListener.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIDOMNode.h"
@ -53,6 +54,7 @@
#include "nsIDOMMouseEvent.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIWebNavigation.h"
#include "nsIDOMHTMLElement.h"
#include "nsIPresShell.h"
@ -68,6 +70,8 @@
#include "nsIWebBrowserChromeFocus.h"
#include "nsIDragDropOverride.h"
#include "nsIContent.h"
#include "imgIContainer.h"
#include "nsContextMenuInfo.h"
//
// GetEventReceiver
@ -806,8 +810,9 @@ nsDocShellTreeOwner :: AddChromeListeners ( )
// install context menus
if ( !mChromeContextMenuListener ) {
nsCOMPtr<nsIContextMenuListener2> contextListener2 ( do_QueryInterface(mWebBrowserChrome) );
nsCOMPtr<nsIContextMenuListener> contextListener ( do_QueryInterface(mWebBrowserChrome) );
if ( contextListener ) {
if ( contextListener2 || contextListener ) {
mChromeContextMenuListener = new ChromeContextMenuListener ( mWebBrowser, mWebBrowserChrome );
if ( mChromeContextMenuListener ) {
NS_ADDREF(mChromeContextMenuListener);
@ -817,7 +822,7 @@ nsDocShellTreeOwner :: AddChromeListeners ( )
rv = NS_ERROR_OUT_OF_MEMORY;
}
}
// install the external dragDrop handler
if ( !mChromeDragHandler ) {
mChromeDragHandler = do_CreateInstance("@mozilla.org:/content/content-area-dragdrop;1", &rv);
@ -1449,13 +1454,12 @@ ChromeContextMenuListener :: AddChromeListeners ( )
// Register the appropriate events for context menus, but only if
// the embedding chrome cares.
nsresult rv = NS_OK;
nsCOMPtr<nsIContextMenuListener2> contextListener2 ( do_QueryInterface(mWebBrowserChrome) );
nsCOMPtr<nsIContextMenuListener> contextListener ( do_QueryInterface(mWebBrowserChrome) );
if ( contextListener && !mContextMenuListenerInstalled ) {
if ( (contextListener || contextListener2) && !mContextMenuListenerInstalled )
rv = AddContextMenuListener();
if ( NS_FAILED(rv) )
return rv;
}
return rv;
} // AddChromeListeners
@ -1505,11 +1509,23 @@ ChromeContextMenuListener :: ContextMenu ( nsIDOMEvent* aMouseEvent )
// Stop the context menu event going to other windows (bug 78396)
aMouseEvent->PreventDefault();
// If the listener is a nsIContextMenuListener2, create the info object
nsCOMPtr<nsIContextMenuListener2> menuListener2(do_QueryInterface(mWebBrowserChrome));
nsContextMenuInfo *menuInfoImpl = nsnull;
nsCOMPtr<nsIContextMenuInfo> menuInfo;
if (menuListener2) {
menuInfoImpl = new nsContextMenuInfo;
if (!menuInfoImpl)
return NS_ERROR_OUT_OF_MEMORY;
menuInfo = menuInfoImpl;
}
// Find the first node to be an element starting with this node and
// working up through its parents.
PRUint32 flags = nsIContextMenuListener::CONTEXT_NONE;
PRUint32 flags2 = nsIContextMenuListener2::CONTEXT_NONE;
nsCOMPtr<nsIDOMHTMLElement> element;
do {
// XXX test for selected text
@ -1523,6 +1539,7 @@ ChromeContextMenuListener :: ContextMenu ( nsIDOMEvent* aMouseEvent )
if (tag.Equals(NS_LITERAL_STRING("img"), nsCaseInsensitiveStringComparator()))
{
flags |= nsIContextMenuListener::CONTEXT_IMAGE;
flags2 |= nsIContextMenuListener2::CONTEXT_IMAGE;
targetDOMnode = node;
// if we see an image, keep searching for a possible anchor
}
@ -1530,21 +1547,42 @@ ChromeContextMenuListener :: ContextMenu ( nsIDOMEvent* aMouseEvent )
{
// INPUT element - button, combo, checkbox, text etc.
flags |= nsIContextMenuListener::CONTEXT_INPUT;
flags2 |= nsIContextMenuListener2::CONTEXT_INPUT;
targetDOMnode = node;
// See if the input type is an image
if (menuListener2) {
nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(node));
if (inputElement) {
nsAutoString inputElemType;
inputElement->GetType(inputElemType);
if (inputElemType.Equals(NS_LITERAL_STRING("image"), nsCaseInsensitiveStringComparator()))
flags2 |= nsIContextMenuListener2::CONTEXT_IMAGE;
}
}
break; // exit do-while
}
else if (tag.Equals(NS_LITERAL_STRING("textarea"), nsCaseInsensitiveStringComparator()))
{
// text area
flags |= nsIContextMenuListener::CONTEXT_TEXT;
flags2 |= nsIContextMenuListener2::CONTEXT_TEXT;
targetDOMnode = node;
break; // exit do-while
}
else if (tag.Equals(NS_LITERAL_STRING("html"), nsCaseInsensitiveStringComparator()))
{
// first check if this is a background image that the user was trying to click on
// and if the listener is ready for that (only nsIContextMenuListener2 and up)
if (menuInfoImpl && menuInfoImpl->HasBackgroundImage(node)) {
flags2 |= nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE;
targetDOMnode = node;
}
if (!flags && !flags2) {
// only care about this if no other context was found.
if (!flags) {
flags |= nsIContextMenuListener::CONTEXT_DOCUMENT;
flags2 |= nsIContextMenuListener2::CONTEXT_DOCUMENT;
targetDOMnode = node;
}
break; // exit do-while
@ -1566,8 +1604,11 @@ ChromeContextMenuListener :: ContextMenu ( nsIDOMEvent* aMouseEvent )
if (hrefNode)
{
flags |= nsIContextMenuListener::CONTEXT_LINK;
flags2 |= nsIContextMenuListener2::CONTEXT_LINK;
if (!targetDOMnode)
targetDOMnode = node;
if (menuInfoImpl)
menuInfoImpl->SetAssociatedLink(node);
break; // exit do-while
}
}
@ -1601,10 +1642,19 @@ ChromeContextMenuListener :: ContextMenu ( nsIDOMEvent* aMouseEvent )
NS_ENSURE_SUCCESS(res, res);
// Tell the listener all about the event
nsCOMPtr<nsIContextMenuListener> menuListener(do_QueryInterface(mWebBrowserChrome));
if ( menuListener )
menuListener->OnShowContextMenu(flags, aMouseEvent, targetDOMnode);
if ( menuListener2 ) {
menuInfoImpl->SetMouseEvent(aMouseEvent);
menuInfoImpl->SetDOMNode(targetDOMnode);
menuListener2->OnShowContextMenu(flags2, menuInfo);
}
else {
nsCOMPtr<nsIContextMenuListener> menuListener(do_QueryInterface(mWebBrowserChrome));
if ( menuListener )
menuListener->OnShowContextMenu(flags, aMouseEvent, targetDOMnode);
}
return NS_OK;
} // MouseDown

View File

@ -324,7 +324,7 @@ void CBrowserFrame::BrowserFrameGlueObj::DestroyBrowserFrame()
#define GOTO_BUILD_CTX_MENU { bContentHasFrames = FALSE; goto BUILD_CTX_MENU; }
void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode)
void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo)
{
METHOD_PROLOGUE(CBrowserFrame, BrowserFrameGlueObj)
@ -341,11 +341,11 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags,
GOTO_BUILD_CTX_MENU;
}
if(aContextFlags & nsIContextMenuListener::CONTEXT_DOCUMENT)
if(aContextFlags & nsIContextMenuListener2::CONTEXT_DOCUMENT)
nIDResource = IDR_CTXMENU_DOCUMENT;
else if(aContextFlags & nsIContextMenuListener::CONTEXT_TEXT)
else if(aContextFlags & nsIContextMenuListener2::CONTEXT_TEXT)
nIDResource = IDR_CTXMENU_TEXT;
else if(aContextFlags & nsIContextMenuListener::CONTEXT_LINK)
else if(aContextFlags & nsIContextMenuListener2::CONTEXT_LINK)
{
nIDResource = IDR_CTXMENU_LINK;
@ -362,28 +362,7 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags,
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;
// Search for an anchor element
nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement;
nsCOMPtr<nsIDOMNode> node = aNode;
while (node)
{
linkElement = do_QueryInterface(node);
if (linkElement)
break;
nsCOMPtr<nsIDOMNode> parentNode;
node->GetParentNode(getter_AddRefs(parentNode));
node = parentNode;
}
if (!linkElement)
return;
rv = linkElement->GetHref(strUrlUcs2);
nsresult rv = aInfo->GetAssociatedLink(strUrlUcs2);
if(NS_FAILED(rv))
return;
@ -391,7 +370,7 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags,
// Note that this string is in UCS2 format
pThis->m_wndBrowserView.SetCtxMenuLinkUrl(strUrlUcs2);
}
else if(aContextFlags & nsIContextMenuListener::CONTEXT_IMAGE)
else if(aContextFlags & nsIContextMenuListener2::CONTEXT_IMAGE)
{
nIDResource = IDR_CTXMENU_IMAGE;
@ -399,17 +378,35 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags,
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))
nsCOMPtr<nsIURI> imgURI;
aInfo->GetImageSrc(getter_AddRefs(imgURI));
if(!imgURI)
return;
nsCAutoString strImgSrcUtf8;
imgURI->GetSpec(strImgSrcUtf8);
if(strImgSrcUtf8.IsEmpty())
return;
strImgSrcUcs2 = NS_ConvertUTF8toUCS2(strImgSrcUtf8);
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Set the new Img Src
}
else if(aContextFlags & nsIContextMenuListener2::CONTEXT_BACKGROUND_IMAGE)
{
nIDResource = IDR_CTXMENU_IMAGE;
nsAutoString strImgSrcUcs2;
pThis->m_wndBrowserView.SetCtxMenuImageSrc(strImgSrcUcs2); // Clear it
// Get the IMG SRC
nsCOMPtr<nsIURI> imgURI;
aInfo->GetBackgroundImageSrc(getter_AddRefs(imgURI));
if (!imgURI)
return;
nsCAutoString uri;
imgURI->GetSpec(uri);
pThis->m_wndBrowserView.SetCtxMenuImageSrc(NS_ConvertUTF8toUCS2(uri)); // Set the new Img Src
}
// Determine if we need to add the Frame related context menu items
// such as "View Frame Source" etc.
@ -424,8 +421,13 @@ void CBrowserFrame::BrowserFrameGlueObj::ShowContextMenu(PRUint32 aContextFlags,
//Determine the current Frame URL
//
nsresult rv = NS_OK;
nsCOMPtr<nsIDOMNode> node;
aInfo->GetTargetNode(getter_AddRefs(node));
if(!node)
GOTO_BUILD_CTX_MENU;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = aNode->GetOwnerDocument(getter_AddRefs(domDoc));
rv = node->GetOwnerDocument(getter_AddRefs(domDoc));
if(NS_FAILED(rv))
GOTO_BUILD_CTX_MENU;

View File

@ -116,7 +116,7 @@ NS_INTERFACE_MAP_BEGIN(CBrowserImpl)
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow2)
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener2)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END

View File

@ -37,12 +37,12 @@
#include "nsICommandParams.h"
class CBrowserImpl : public nsIInterfaceRequestor,
public nsIWebBrowserChrome,
public nsIWebBrowserChrome,
public nsIWebBrowserChromeFocus,
public nsIEmbeddingSiteWindow2,
public nsIWebProgressListener,
public nsIContextMenuListener,
public nsSupportsWeakReference
public nsIEmbeddingSiteWindow2,
public nsIWebProgressListener,
public nsIContextMenuListener2,
public nsSupportsWeakReference
{
public:
CBrowserImpl();
@ -57,7 +57,7 @@ public:
NS_DECL_NSIEMBEDDINGSITEWINDOW
NS_DECL_NSIEMBEDDINGSITEWINDOW2
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSICONTEXTMENULISTENER
NS_DECL_NSICONTEXTMENULISTENER2
protected:

View File

@ -36,13 +36,13 @@
#include "IBrowserFrameGlue.h"
//*****************************************************************************
// CBrowserImpl::nsIContextMenuListener
// CBrowserImpl::nsIContextMenuListener2
//*****************************************************************************
NS_IMETHODIMP CBrowserImpl::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
NS_IMETHODIMP CBrowserImpl::OnShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo)
{
if(m_pBrowserFrameGlue)
m_pBrowserFrameGlue->ShowContextMenu(aContextFlags, aNode);
m_pBrowserFrameGlue->ShowContextMenu(aContextFlags, aInfo);
return NS_OK;
}

View File

@ -72,7 +72,7 @@ struct IBrowserFrameGlue {
virtual void GetBrowserFrameVisibility(PRBool *aVisible) = 0;
// ContextMenu Related Methods
virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode) = 0;
virtual void ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo) = 0;
virtual HWND GetBrowserFrameNativeWnd() = 0;
};
@ -98,7 +98,7 @@ struct IBrowserFrameGlue {
virtual void SetFocus(); \
virtual void FocusAvailable(PRBool *aFocusAvail); \
virtual void GetBrowserFrameVisibility(PRBool *aVisible); \
virtual void ShowContextMenu(PRUint32 aContextFlags, nsIDOMNode *aNode); \
virtual void ShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aInfo); \
virtual HWND GetBrowserFrameNativeWnd();
typedef IBrowserFrameGlue *PBROWSERFRAMEGLUE;

View File

@ -59,6 +59,9 @@ REQUIRES = \
webbrowserpersist \
composer \
commandhandler \
imglib2 \
gfx2 \
webbrwsr \
$(NULL)
CPPSRCS = \

View File

@ -92,7 +92,7 @@
#include "nsIDocShellTreeItem.h"
#include "nsIClipboardCommands.h"
#include "nsIWebBrowserPersist.h"
#include "nsIContextMenuListener.h"
#include "nsIContextMenuListener2.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLAnchorElement.h"
#include "nsIDOMHTMLImageElement.h"
@ -108,6 +108,7 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsIProfileChangeStatus.h"
#include "nsIObserverService.h"
#include "imgIContainer.h"
#ifdef MOZ_OLD_CACHE
#include "nsINetDataCacheManager.h"
#endif