Fix for bug 38757. Need to use a focus listenner in order to make inheriance of focus handlers working. R=hyatt

This commit is contained in:
ducarroz%netscape.com 2000-05-12 06:25:48 +00:00
parent 95c604b7cc
commit 3bb8acf4c3
8 changed files with 78 additions and 6 deletions

View File

@ -216,6 +216,7 @@ protected:
PRBool IsMouseHandler(const nsString& aName);
PRBool IsKeyHandler(const nsString& aName);
PRBool IsFocusHandler(const nsString& aName);
PRBool IsXULHandler(const nsString& aName);
static void GetEventHandlerIID(nsIAtom* aName, nsIID* aIID, PRBool* aFound);
@ -605,11 +606,12 @@ nsXBLBinding::InstallEventHandlers(nsIContent* aBoundElement)
// Add an event listener for mouse and key events only.
PRBool mouse = IsMouseHandler(type);
PRBool key = IsKeyHandler(type);
PRBool focus = IsFocusHandler(type);
PRBool xul = IsXULHandler(type);
nsCOMPtr<nsIDOMEventReceiver> receiver = do_QueryInterface(mBoundElement);
if (mouse || key || xul) {
if (mouse || key || focus || xul) {
// Create a new nsXBLEventHandler.
nsXBLEventHandler* handler;
NS_NewXBLEventHandler(mBoundElement, child, type, &handler);
@ -626,6 +628,8 @@ nsXBLBinding::InstallEventHandlers(nsIContent* aBoundElement)
receiver->AddEventListener(type, (nsIDOMMouseListener*)handler, useCapture);
else if(key)
receiver->AddEventListener(type, (nsIDOMKeyListener*)handler, useCapture);
else if(focus)
receiver->AddEventListener(type, (nsIDOMFocusListener*)handler, useCapture);
else
receiver->AddEventListener(type, (nsIDOMMenuListener*)handler, useCapture);
@ -1372,6 +1376,12 @@ nsXBLBinding::IsKeyHandler(const nsString& aName)
return ((aName.EqualsWithConversion("keypress")) || (aName.EqualsWithConversion("keydown")) || (aName.EqualsWithConversion("keyup")));
}
PRBool
nsXBLBinding::IsFocusHandler(const nsString& aName)
{
return ((aName.EqualsWithConversion("focus")) || (aName.EqualsWithConversion("blur")));
}
PRBool
nsXBLBinding::IsXULHandler(const nsString& aName)
{

View File

@ -91,7 +91,7 @@ nsXBLEventHandler::~nsXBLEventHandler()
}
}
NS_IMPL_ISUPPORTS3(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener, nsIDOMMenuListener)
NS_IMPL_ISUPPORTS4(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener, nsIDOMMenuListener, nsIDOMFocusListener)
nsresult nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent)
{
@ -198,6 +198,26 @@ nsresult nsXBLEventHandler::MouseOut(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
nsresult nsXBLEventHandler::Focus(nsIDOMEvent* aEvent)
{
if (!mEventName.EqualsWithConversion("focus"))
return NS_OK;
ExecuteHandler(NS_ConvertASCIItoUCS2("focus"), aEvent);
return NS_OK;
}
nsresult nsXBLEventHandler::Blur(nsIDOMEvent* aEvent)
{
if (!mEventName.EqualsWithConversion("blur"))
return NS_OK;
ExecuteHandler(NS_ConvertASCIItoUCS2("blur"), aEvent);
return NS_OK;
}
nsresult nsXBLEventHandler::Action(nsIDOMEvent* aEvent)
{
if (!mEventName.EqualsWithConversion("command"))

View File

@ -28,6 +28,7 @@
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMenuListener.h"
#include "nsIDOMFocusListener.h"
class nsIXBLBinding;
class nsIDOMEvent;
@ -39,7 +40,8 @@ class nsIController;
class nsXBLEventHandler : public nsIDOMKeyListener,
public nsIDOMMouseListener,
public nsIDOMMenuListener
public nsIDOMMenuListener,
public nsIDOMFocusListener
{
public:
nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHandlerElement, const nsString& aEventName);
@ -58,6 +60,9 @@ public:
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
virtual nsresult Focus(nsIDOMEvent* aMouseEvent);
virtual nsresult Blur(nsIDOMEvent* aMouseEvent);
NS_IMETHOD Create(nsIDOMEvent* aEvent);
NS_IMETHOD Close(nsIDOMEvent* aEvent);
NS_IMETHOD Destroy(nsIDOMEvent* aEvent);

View File

@ -409,6 +409,7 @@ NS_IMETHODIMP nsXBLService::GetBinding(const nsCString& aURLStr, nsIXBLBinding**
PRInt32 count;
root->ChildCount(count);
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> child;
root->ChildAt(i, *getter_AddRefs(child));

View File

@ -216,6 +216,7 @@ protected:
PRBool IsMouseHandler(const nsString& aName);
PRBool IsKeyHandler(const nsString& aName);
PRBool IsFocusHandler(const nsString& aName);
PRBool IsXULHandler(const nsString& aName);
static void GetEventHandlerIID(nsIAtom* aName, nsIID* aIID, PRBool* aFound);
@ -605,11 +606,12 @@ nsXBLBinding::InstallEventHandlers(nsIContent* aBoundElement)
// Add an event listener for mouse and key events only.
PRBool mouse = IsMouseHandler(type);
PRBool key = IsKeyHandler(type);
PRBool focus = IsFocusHandler(type);
PRBool xul = IsXULHandler(type);
nsCOMPtr<nsIDOMEventReceiver> receiver = do_QueryInterface(mBoundElement);
if (mouse || key || xul) {
if (mouse || key || focus || xul) {
// Create a new nsXBLEventHandler.
nsXBLEventHandler* handler;
NS_NewXBLEventHandler(mBoundElement, child, type, &handler);
@ -626,6 +628,8 @@ nsXBLBinding::InstallEventHandlers(nsIContent* aBoundElement)
receiver->AddEventListener(type, (nsIDOMMouseListener*)handler, useCapture);
else if(key)
receiver->AddEventListener(type, (nsIDOMKeyListener*)handler, useCapture);
else if(focus)
receiver->AddEventListener(type, (nsIDOMFocusListener*)handler, useCapture);
else
receiver->AddEventListener(type, (nsIDOMMenuListener*)handler, useCapture);
@ -1372,6 +1376,12 @@ nsXBLBinding::IsKeyHandler(const nsString& aName)
return ((aName.EqualsWithConversion("keypress")) || (aName.EqualsWithConversion("keydown")) || (aName.EqualsWithConversion("keyup")));
}
PRBool
nsXBLBinding::IsFocusHandler(const nsString& aName)
{
return ((aName.EqualsWithConversion("focus")) || (aName.EqualsWithConversion("blur")));
}
PRBool
nsXBLBinding::IsXULHandler(const nsString& aName)
{

View File

@ -91,7 +91,7 @@ nsXBLEventHandler::~nsXBLEventHandler()
}
}
NS_IMPL_ISUPPORTS3(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener, nsIDOMMenuListener)
NS_IMPL_ISUPPORTS4(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener, nsIDOMMenuListener, nsIDOMFocusListener)
nsresult nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent)
{
@ -198,6 +198,26 @@ nsresult nsXBLEventHandler::MouseOut(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
nsresult nsXBLEventHandler::Focus(nsIDOMEvent* aEvent)
{
if (!mEventName.EqualsWithConversion("focus"))
return NS_OK;
ExecuteHandler(NS_ConvertASCIItoUCS2("focus"), aEvent);
return NS_OK;
}
nsresult nsXBLEventHandler::Blur(nsIDOMEvent* aEvent)
{
if (!mEventName.EqualsWithConversion("blur"))
return NS_OK;
ExecuteHandler(NS_ConvertASCIItoUCS2("blur"), aEvent);
return NS_OK;
}
nsresult nsXBLEventHandler::Action(nsIDOMEvent* aEvent)
{
if (!mEventName.EqualsWithConversion("command"))

View File

@ -28,6 +28,7 @@
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMenuListener.h"
#include "nsIDOMFocusListener.h"
class nsIXBLBinding;
class nsIDOMEvent;
@ -39,7 +40,8 @@ class nsIController;
class nsXBLEventHandler : public nsIDOMKeyListener,
public nsIDOMMouseListener,
public nsIDOMMenuListener
public nsIDOMMenuListener,
public nsIDOMFocusListener
{
public:
nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHandlerElement, const nsString& aEventName);
@ -58,6 +60,9 @@ public:
virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent);
virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent);
virtual nsresult Focus(nsIDOMEvent* aMouseEvent);
virtual nsresult Blur(nsIDOMEvent* aMouseEvent);
NS_IMETHOD Create(nsIDOMEvent* aEvent);
NS_IMETHOD Close(nsIDOMEvent* aEvent);
NS_IMETHOD Destroy(nsIDOMEvent* aEvent);

View File

@ -409,6 +409,7 @@ NS_IMETHODIMP nsXBLService::GetBinding(const nsCString& aURLStr, nsIXBLBinding**
PRInt32 count;
root->ChildCount(count);
for (PRInt32 i = 0; i < count; i++) {
nsCOMPtr<nsIContent> child;
root->ChildAt(i, *getter_AddRefs(child));