From b4825dec2f1c2a4a415644ba25adb16fb688d661 Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Wed, 14 Nov 2001 01:53:33 +0000 Subject: [PATCH] FizillaMach: Make the Quit menu item work by checking the command attribute in nsMenuBarX::ExecuteCommand as in nsMenuItemX::DoCommand. b=107212 r=pinkerton sr=sfraser --- widget/src/mac/nsMenuBarX.cpp | 54 ++++++++++++++++++++++++---------- widget/src/mac/nsMenuBarX.h | 2 ++ widget/src/mac/nsMenuItemX.cpp | 32 +------------------- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/widget/src/mac/nsMenuBarX.cpp b/widget/src/mac/nsMenuBarX.cpp index 98023b0ed6da..91581dbac26e 100644 --- a/widget/src/mac/nsMenuBarX.cpp +++ b/widget/src/mac/nsMenuBarX.cpp @@ -398,22 +398,10 @@ nsMenuBarX :: CommandEventHandler ( EventHandlerCallRef inHandlerChain, EventRef nsEventStatus nsMenuBarX :: ExecuteCommand ( nsIContent* inDispatchTo ) { - nsEventStatus status = nsEventStatus_eIgnore; - if ( inDispatchTo ) { - nsCOMPtr webShell = do_QueryReferent(mWebShellWeakRef); - if (!webShell) - return nsEventStatus_eConsumeNoDefault; - nsCOMPtr presContext; - MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext)); + if (!inDispatchTo) + return nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_MOUSE_EVENT; - event.message = NS_XUL_COMMAND; - - inDispatchTo->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - - return status; + return MenuHelpersX::DispatchCommandTo(mWebShellWeakRef, inDispatchTo); } // ExecuteCommand @@ -1052,5 +1040,41 @@ MenuHelpersX::WebShellToPresContext (nsIWebShell* inWebShell, nsIPresContext** o } // WebShellToPresContext +nsEventStatus +MenuHelpersX::DispatchCommandTo(nsIWeakReference* aWebShellWeakRef, + nsIContent* aTargetContent) +{ + NS_PRECONDITION(aTargetContent, "null ptr"); + nsCOMPtr webShell = do_QueryReferent(aWebShellWeakRef); + if (!webShell) + return nsEventStatus_eConsumeNoDefault; + nsCOMPtr presContext; + MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext)); + nsEventStatus status = nsEventStatus_eConsumeNoDefault; + nsMouseEvent event; + event.eventStructType = NS_MOUSE_EVENT; + event.message = NS_XUL_COMMAND; + + // See if we have a command element. If so, we execute on the + // command instead of on our content element. + nsAutoString command; + aTargetContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, command); + if (!command.IsEmpty()) { + nsCOMPtr doc; + aTargetContent->GetDocument(*getter_AddRefs(doc)); + nsCOMPtr domDoc(do_QueryInterface(doc)); + nsCOMPtr commandElt; + domDoc->GetElementById(command, getter_AddRefs(commandElt)); + nsCOMPtr commandContent(do_QueryInterface(commandElt)); + if (commandContent) + commandContent->HandleDOMEvent(presContext, &event, nsnull, + NS_EVENT_FLAG_INIT, &status); + } + else + aTargetContent->HandleDOMEvent(presContext, &event, nsnull, + NS_EVENT_FLAG_INIT, &status); + + return status; +} diff --git a/widget/src/mac/nsMenuBarX.h b/widget/src/mac/nsMenuBarX.h index b52b31220834..010faa0b4999 100644 --- a/widget/src/mac/nsMenuBarX.h +++ b/widget/src/mac/nsMenuBarX.h @@ -65,6 +65,8 @@ namespace MenuHelpersX { // utility routine for getting a PresContext out of a webShell nsresult WebShellToPresContext ( nsIWebShell* inWebShell, nsIPresContext** outContext ) ; + nsEventStatus DispatchCommandTo(nsIWeakReference* aWebShellWeakRef, + nsIContent* aTargetContent); } diff --git a/widget/src/mac/nsMenuItemX.cpp b/widget/src/mac/nsMenuItemX.cpp index 9e5e300d88ea..a07691af1f54 100644 --- a/widget/src/mac/nsMenuItemX.cpp +++ b/widget/src/mac/nsMenuItemX.cpp @@ -256,37 +256,7 @@ nsEventStatus nsMenuItemX::SetRebuild(PRBool aNeedsRebuild) */ NS_METHOD nsMenuItemX::DoCommand() { - nsresult rv = NS_ERROR_FAILURE; - - nsCOMPtr presContext; - nsCOMPtr webShell = do_QueryReferent(mWebShellWeakRef); - if (!webShell) - return nsEventStatus_eConsumeNoDefault; - MenuHelpersX::WebShellToPresContext(webShell, getter_AddRefs(presContext)); - - nsEventStatus status = nsEventStatus_eIgnore; - nsMouseEvent event; - event.eventStructType = NS_MOUSE_EVENT; - event.message = NS_XUL_COMMAND; - - // See if we have a command element. If so, we execute on the command instead - // of on our content element. - nsAutoString command; - mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, command); - if (!command.IsEmpty()) { - nsCOMPtr doc; - mContent->GetDocument(*getter_AddRefs(doc)); - nsCOMPtr domDoc(do_QueryInterface(doc)); - nsCOMPtr commandElt; - domDoc->GetElementById(command, getter_AddRefs(commandElt)); - nsCOMPtr commandContent(do_QueryInterface(commandElt)); - if (commandContent) - commandContent->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - } - else - mContent->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status); - - return nsEventStatus_eConsumeNoDefault; + return MenuHelpersX::DispatchCommandTo(mWebShellWeakRef, mContent); }