From 5e7b3561e2f1a65cf12c930be1662f34359e08bc Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Tue, 10 Oct 2000 12:19:17 +0000 Subject: [PATCH] New context menu listener code. b=55516, r=blizzard@mozilla.org --- .../activex/src/control/MozillaBrowser.cpp | 6 +-- .../webBrowser/nsDocShellTreeOwner.cpp | 52 +++++++++++-------- .../webBrowser/nsIContextMenuListener.idl | 37 ++++++++----- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/embedding/browser/activex/src/control/MozillaBrowser.cpp b/embedding/browser/activex/src/control/MozillaBrowser.cpp index 0642ea74e4d2..49a1c004ce2f 100644 --- a/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -214,7 +214,7 @@ void CMozillaBrowser::ShowContextMenu(PRUint32 aContextFlags) { dwID = ctxMenu1DSelect; } - else if (aContextFlags & nsIContextMenuListener::CONTEXT_DEFAULT) + else { dwID = ctxMenuDefault; } @@ -244,7 +244,7 @@ void CMozillaBrowser::ShowContextMenu(PRUint32 aContextFlags) { pszMenuResource = MAKEINTRESOURCE(IDR_POPUP_TEXT); } - else if (aContextFlags & nsIContextMenuListener::CONTEXT_DEFAULT) + else { pszMenuResource = MAKEINTRESOURCE(IDR_POPUP_DOCUMENT); } @@ -916,7 +916,7 @@ HRESULT CMozillaBrowser::CreateBrowser() // Configure what the web browser can and cannot do nsCOMPtr webBrowserAsSetup(do_QueryInterface(mWebBrowser)); - webBrowserAsSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, aAllowPlugins); + // webBrowserAsSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS, aAllowPlugins); // webBrowserAsSetup->SetProperty(nsIWebBrowserSetup::SETUP_CONTAINS_CHROME, PR_TRUE); // Create the webbrowser window diff --git a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp index b4c59194009b..533ba3c824be 100644 --- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp +++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp @@ -665,7 +665,7 @@ nsresult nsDocShellTreeOwner::HandleEvent(nsIDOMEvent* aEvent) nsresult nsDocShellTreeOwner::MouseDown(nsIDOMEvent* aMouseEvent) { // Don't bother going any further if no one is interested in context menu events - nsCOMPtr menuListener(do_QueryInterface(mTreeOwner)); + nsCOMPtr menuListener(do_QueryInterface(mWebBrowserChrome)); if (!menuListener) { return NS_OK; @@ -700,6 +700,7 @@ nsresult nsDocShellTreeOwner::MouseDown(nsIDOMEvent* aMouseEvent) return NS_ERROR_NULL_POINTER; } + nsCOMPtr targetDOMnode; nsCOMPtr node = do_QueryInterface(targetNode); if (!node) { @@ -712,11 +713,10 @@ nsresult nsDocShellTreeOwner::MouseDown(nsIDOMEvent* aMouseEvent) PRUint32 flags = nsIContextMenuListener::CONTEXT_NONE; nsCOMPtr element; do { - PRUint16 type; - node->GetNodeType(&type); + //PRUint16 type; + //node->GetNodeType(&type); // XXX test for selected text - element = do_QueryInterface(node); if (element) { @@ -724,20 +724,34 @@ nsresult nsDocShellTreeOwner::MouseDown(nsIDOMEvent* aMouseEvent) element->GetTagName(tag); // Test what kind of element we're dealing with here - if (tag.EqualsWithConversion("input", PR_TRUE)) + if (tag.EqualsWithConversion("img", PR_TRUE)) + { + flags |= nsIContextMenuListener::CONTEXT_IMAGE; + targetDOMnode = node; + // if we see an image, keep searching for a possible anchor + } + else if (tag.EqualsWithConversion("input", PR_TRUE)) { // INPUT element - button, combo, checkbox, text etc. flags |= nsIContextMenuListener::CONTEXT_INPUT; + targetDOMnode = node; + break; // exit do-while } - else if (tag.EqualsWithConversion("img", PR_TRUE)) + else if (tag.EqualsWithConversion("textarea", PR_TRUE)) { - // IMG element - flags |= nsIContextMenuListener::CONTEXT_IMAGE; + // text area + flags |= nsIContextMenuListener::CONTEXT_TEXT; + targetDOMnode = node; + break; // exit do-while } - else + else if (tag.EqualsWithConversion("html", PR_TRUE)) { - // Something else - flags |= nsIContextMenuListener::CONTEXT_OTHER; + // only care about this if no other context was found. + if (!flags) { + flags |= nsIContextMenuListener::CONTEXT_DOCUMENT; + targetDOMnode = node; + } + break; // exit do-while } // Test if the element has an associated link @@ -751,25 +765,21 @@ nsresult nsDocShellTreeOwner::MouseDown(nsIDOMEvent* aMouseEvent) if (hrefNode) { flags |= nsIContextMenuListener::CONTEXT_LINK; - break; + if (!targetDOMnode) + targetDOMnode = node; + break; // exit do-while } } } + + // walk-up-the-tree nsCOMPtr parentNode; node->GetParentNode(getter_AddRefs(parentNode)); - - // Test if we're at the top of the document - if (!parentNode) - { - node = nsnull; - flags |= nsIContextMenuListener::CONTEXT_DOCUMENT; - break; - } node = parentNode; } while (node); // Tell the listener all about the event - menuListener->OnShowContextMenu(flags, aMouseEvent, node); + menuListener->OnShowContextMenu(flags, aMouseEvent, targetDOMnode); return NS_OK; } diff --git a/embedding/browser/webBrowser/nsIContextMenuListener.idl b/embedding/browser/webBrowser/nsIContextMenuListener.idl index 178f8e6864bb..35b9f405df9e 100644 --- a/embedding/browser/webBrowser/nsIContextMenuListener.idl +++ b/embedding/browser/webBrowser/nsIContextMenuListener.idl @@ -37,20 +37,33 @@ interface nsIDOMNode; interface nsIContextMenuListener : nsISupports { const unsigned long CONTEXT_NONE = 0; - const unsigned long CONTEXT_DEFAULT = 1; - const unsigned long CONTEXT_LINK = 2; - const unsigned long CONTEXT_IMAGE = 4; - const unsigned long CONTEXT_DOCUMENT = 8; - const unsigned long CONTEXT_TEXT = 16; - const unsigned long CONTEXT_OTHER = 32; - const unsigned long CONTEXT_INPUT = 64; + const unsigned long CONTEXT_LINK = 1; + const unsigned long CONTEXT_IMAGE = 2; + const unsigned long CONTEXT_DOCUMENT = 4; + const unsigned long CONTEXT_TEXT = 8; + const unsigned long CONTEXT_INPUT = 16; /** - * Called when the user attempts to display a context menu, e.g. by - * right-clicking on a link. The combination of flags indicates what was - * clicked on, the DOM event and node objects allow the client to interrogate - * for more information if they like. - */ + * Called when the user attempts to display a context menu, e.g. by + * right-clicking on a link. The combination of flags indicates what was + * clicked on, the DOM event and node objects allow the client to interrogate + * for more information if they like. + * + * The following table describes what aNode points two given a particular + * aContextFlag. No other combinations are possible. + * + * aContextFlag | aNode + * ------------------------------+----------------- + * CONTEXT_LINK | + * CONTEXT_IMAGE | + * CONTEXT_IMAGE | CONTEXT_LINK | * + * CONTEXT_INPUT | + * CONTEXT_TEXT |