Fix for bug 15048 and 22221. Added a DOM focus listener to the xpmenus menubar listener to help with keeping proper state across alt+tab process changes. r=hyatt

This commit is contained in:
saari%netscape.com 2000-01-10 22:05:27 +00:00
parent 61b99b3b63
commit b7266eb16d
3 changed files with 46 additions and 10 deletions

View File

@ -133,12 +133,18 @@ nsMenuBarFrame::Init(nsIPresContext* aPresContext,
nsCOMPtr<nsIDocument> doc;
aContent->GetDocument(*getter_AddRefs(doc));
nsCOMPtr<nsIDOMEventReceiver> target = do_QueryInterface(doc);
mTarget = target;
target->AddEventListener("keypress", mMenuBarListener, PR_TRUE);
target->AddEventListener("keydown", mMenuBarListener, PR_TRUE);
target->AddEventListener("keyup", mMenuBarListener, PR_TRUE);
// Also hook up the listener to the window listening for focus events. This is so we can keep proper
// state as the user alt-tabs through processes.
target->AddEventListener("blur", (nsIDOMFocusListener*)mMenuBarListener, PR_TRUE);
target->AddEventListener("keypress", (nsIDOMKeyListener*)mMenuBarListener, PR_TRUE);
target->AddEventListener("keydown", (nsIDOMKeyListener*)mMenuBarListener, PR_TRUE);
target->AddEventListener("keyup", (nsIDOMKeyListener*)mMenuBarListener, PR_TRUE);
NS_ADDREF(mMenuBarListener);
return rv;
@ -542,9 +548,11 @@ nsMenuBarFrame::IsDisabled(nsIContent* aContent)
NS_IMETHODIMP
nsMenuBarFrame::Destroy(nsIPresContext* aPresContext)
{
mTarget->RemoveEventListener("keypress", mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keydown", mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keyup", mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("blur", (nsIDOMFocusListener*)mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keypress", (nsIDOMKeyListener*)mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keydown", (nsIDOMKeyListener*)mMenuBarListener, PR_TRUE);
mTarget->RemoveEventListener("keyup", (nsIDOMKeyListener*)mMenuBarListener, PR_TRUE);
NS_IF_RELEASE(mMenuBarListener);

View File

@ -49,7 +49,7 @@
NS_IMPL_ADDREF(nsMenuBarListener)
NS_IMPL_RELEASE(nsMenuBarListener)
NS_IMPL_QUERY_INTERFACE1(nsMenuBarListener, nsIDOMKeyListener)
NS_IMPL_QUERY_INTERFACE2(nsMenuBarListener, nsIDOMKeyListener, nsIDOMFocusListener)
////////////////////////////////////////////////////////////////////////
@ -160,7 +160,29 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK; // means I am NOT consuming event
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::Focus(nsIDOMEvent* aEvent)
{
return NS_OK; // means I am NOT consuming event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::Blur(nsIDOMEvent* aEvent)
{
if(mAltKeyDown)
mAltKeyDown = PR_FALSE;
if(mMenuBarFrame->IsActive()) {
mMenuBarFrame->ToggleMenuActiveState();
}
return NS_OK; // means I am NOT consuming event
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::HandleEvent(nsIDOMEvent* aEvent)
{

View File

@ -25,6 +25,7 @@
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDOMEventReceiver.h"
class nsMenuBarFrame;
@ -32,7 +33,7 @@ class nsIPresContext;
/** editor Implementation of the DragListener interface
*/
class nsMenuBarListener : public nsIDOMKeyListener
class nsMenuBarListener : public nsIDOMKeyListener, nsIDOMFocusListener
{
public:
/** default constructor
@ -48,6 +49,11 @@ public:
virtual nsresult KeyDown(nsIDOMEvent* aMouseEvent);
virtual nsresult KeyPress(nsIDOMEvent* aMouseEvent);
virtual nsresult Focus(nsIDOMEvent* aEvent);
virtual nsresult Blur(nsIDOMEvent* aEvent);
NS_DECL_ISUPPORTS
protected: