зеркало из https://github.com/mozilla/gecko-dev.git
More.
This commit is contained in:
Родитель
56d8a45bd8
Коммит
ff21609316
|
@ -1,17 +1,36 @@
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsXBLEventHandler.h"
|
#include "nsXBLEventHandler.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
|
#include "nsIAtom.h"
|
||||||
#include "nsIDOMKeyEvent.h"
|
#include "nsIDOMKeyEvent.h"
|
||||||
|
#include "nsINameSpaceManager.h"
|
||||||
|
|
||||||
|
PRUint32 nsXBLEventHandler::gRefCnt = 0;
|
||||||
|
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
|
||||||
|
nsIAtom* nsXBLEventHandler::kCharCodeAtom = nsnull;
|
||||||
|
nsIAtom* nsXBLEventHandler::kKeyAtom = nsnull;
|
||||||
|
|
||||||
nsXBLEventHandler::nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHandlerElement)
|
nsXBLEventHandler::nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHandlerElement)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
mBoundElement = aBoundElement;
|
mBoundElement = aBoundElement;
|
||||||
mHandlerElement = aHandlerElement;
|
mHandlerElement = aHandlerElement;
|
||||||
|
gRefCnt++;
|
||||||
|
if (gRefCnt == 1) {
|
||||||
|
kKeyCodeAtom = NS_NewAtom("keycode");
|
||||||
|
kKeyAtom = NS_NewAtom("key");
|
||||||
|
kCharCodeAtom = NS_NewAtom("charcode");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsXBLEventHandler::~nsXBLEventHandler()
|
nsXBLEventHandler::~nsXBLEventHandler()
|
||||||
{
|
{
|
||||||
|
gRefCnt--;
|
||||||
|
if (gRefCnt == 0) {
|
||||||
|
NS_RELEASE(kKeyAtom);
|
||||||
|
NS_RELEASE(kKeyCodeAtom);
|
||||||
|
NS_RELEASE(kCharCodeAtom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS2(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener)
|
NS_IMPL_ISUPPORTS2(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener)
|
||||||
|
@ -100,7 +119,33 @@ PRBool
|
||||||
nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
|
nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
|
||||||
{
|
{
|
||||||
nsAutoString trueString = "true";
|
nsAutoString trueString = "true";
|
||||||
nsAutoString falseString = "false";
|
|
||||||
|
// Get the keycode and charcode of the key event.
|
||||||
|
PRUint32 keyCode, charCode;
|
||||||
|
aKeyEvent->GetKeyCode(&keyCode);
|
||||||
|
aKeyEvent->GetCharCode(&charCode);
|
||||||
|
|
||||||
|
PRBool keyMatched = PR_FALSE;
|
||||||
|
|
||||||
|
nsAutoString key;
|
||||||
|
mBoundElement->GetAttribute(kNameSpaceID_None, kKeyAtom, key);
|
||||||
|
if (!key.IsEmpty())
|
||||||
|
keyMatched = IsMatchingCharCode(charCode, key);
|
||||||
|
|
||||||
|
key = "";
|
||||||
|
mBoundElement->GetAttribute(kNameSpaceID_None, kKeyCodeAtom, key);
|
||||||
|
if (!key.IsEmpty())
|
||||||
|
keyMatched = IsMatchingKeyCode(keyCode, key);
|
||||||
|
|
||||||
|
key = "";
|
||||||
|
mBoundElement->GetAttribute(kNameSpaceID_None, kCharCodeAtom, key);
|
||||||
|
if (!key.IsEmpty())
|
||||||
|
keyMatched = IsMatchingCharCode(charCode, key);
|
||||||
|
|
||||||
|
if (!keyMatched)
|
||||||
|
return PR_FALSE;
|
||||||
|
|
||||||
|
// Now check modifier keys
|
||||||
|
|
||||||
return PR_TRUE;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -696,14 +741,14 @@ PRBool nsXBLEventHandler::IsMatchingKeyCode(const PRUint32 aChar, const nsString
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool
|
PRBool
|
||||||
nsXBLEventHandler::IsMatchingCharCode(const nsString& aChar, const nsString& aKeyName)
|
nsXBLEventHandler::IsMatchingCharCode(const PRUint32 aChar, const nsString& aKeyName)
|
||||||
{
|
{
|
||||||
PRBool ret = PR_FALSE;
|
char tempChar[2];
|
||||||
|
tempChar[0] = aChar;
|
||||||
if (aChar == aKeyName)
|
tempChar[1] = 0;
|
||||||
ret = PR_TRUE;
|
nsAutoString tempChar2 = tempChar;
|
||||||
|
|
||||||
return ret;
|
return tempChar2.EqualsIgnoreCase(aKeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -31,6 +31,7 @@ class nsIDOMEvent;
|
||||||
class nsIContent;
|
class nsIContent;
|
||||||
class nsIDOMUIEvent;
|
class nsIDOMUIEvent;
|
||||||
class nsIDOMKeyEvent;
|
class nsIDOMKeyEvent;
|
||||||
|
class nsIAtom;
|
||||||
|
|
||||||
class nsXBLEventHandler : public nsIDOMKeyListener,
|
class nsXBLEventHandler : public nsIDOMKeyListener,
|
||||||
public nsIDOMMouseListener
|
public nsIDOMMouseListener
|
||||||
|
@ -59,10 +60,15 @@ protected:
|
||||||
inline PRBool MouseEventMatched(nsIDOMUIEvent* aMouseEvent);
|
inline PRBool MouseEventMatched(nsIDOMUIEvent* aMouseEvent);
|
||||||
|
|
||||||
inline PRBool IsMatchingKeyCode(const PRUint32 aChar, const nsString& aKeyName);
|
inline PRBool IsMatchingKeyCode(const PRUint32 aChar, const nsString& aKeyName);
|
||||||
inline PRBool IsMatchingCharCode(const nsString& aChar, const nsString& aKeyName);
|
inline PRBool IsMatchingCharCode(const PRUint32 aChar, const nsString& aKeyName);
|
||||||
|
|
||||||
NS_IMETHOD ExecuteHandler();
|
NS_IMETHOD ExecuteHandler();
|
||||||
|
|
||||||
|
static PRUint32 gRefCnt;
|
||||||
|
static nsIAtom* kKeyAtom;
|
||||||
|
static nsIAtom* kKeyCodeAtom;
|
||||||
|
static nsIAtom* kCharCodeAtom;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsIContent* mBoundElement; // Both of these refs are weak.
|
nsIContent* mBoundElement; // Both of these refs are weak.
|
||||||
nsIContent* mHandlerElement;
|
nsIContent* mHandlerElement;
|
||||||
|
|
|
@ -1,17 +1,36 @@
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsXBLEventHandler.h"
|
#include "nsXBLEventHandler.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
|
#include "nsIAtom.h"
|
||||||
#include "nsIDOMKeyEvent.h"
|
#include "nsIDOMKeyEvent.h"
|
||||||
|
#include "nsINameSpaceManager.h"
|
||||||
|
|
||||||
|
PRUint32 nsXBLEventHandler::gRefCnt = 0;
|
||||||
|
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
|
||||||
|
nsIAtom* nsXBLEventHandler::kCharCodeAtom = nsnull;
|
||||||
|
nsIAtom* nsXBLEventHandler::kKeyAtom = nsnull;
|
||||||
|
|
||||||
nsXBLEventHandler::nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHandlerElement)
|
nsXBLEventHandler::nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHandlerElement)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
mBoundElement = aBoundElement;
|
mBoundElement = aBoundElement;
|
||||||
mHandlerElement = aHandlerElement;
|
mHandlerElement = aHandlerElement;
|
||||||
|
gRefCnt++;
|
||||||
|
if (gRefCnt == 1) {
|
||||||
|
kKeyCodeAtom = NS_NewAtom("keycode");
|
||||||
|
kKeyAtom = NS_NewAtom("key");
|
||||||
|
kCharCodeAtom = NS_NewAtom("charcode");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nsXBLEventHandler::~nsXBLEventHandler()
|
nsXBLEventHandler::~nsXBLEventHandler()
|
||||||
{
|
{
|
||||||
|
gRefCnt--;
|
||||||
|
if (gRefCnt == 0) {
|
||||||
|
NS_RELEASE(kKeyAtom);
|
||||||
|
NS_RELEASE(kKeyCodeAtom);
|
||||||
|
NS_RELEASE(kCharCodeAtom);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS2(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener)
|
NS_IMPL_ISUPPORTS2(nsXBLEventHandler, nsIDOMKeyListener, nsIDOMMouseListener)
|
||||||
|
@ -100,7 +119,33 @@ PRBool
|
||||||
nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
|
nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
|
||||||
{
|
{
|
||||||
nsAutoString trueString = "true";
|
nsAutoString trueString = "true";
|
||||||
nsAutoString falseString = "false";
|
|
||||||
|
// Get the keycode and charcode of the key event.
|
||||||
|
PRUint32 keyCode, charCode;
|
||||||
|
aKeyEvent->GetKeyCode(&keyCode);
|
||||||
|
aKeyEvent->GetCharCode(&charCode);
|
||||||
|
|
||||||
|
PRBool keyMatched = PR_FALSE;
|
||||||
|
|
||||||
|
nsAutoString key;
|
||||||
|
mBoundElement->GetAttribute(kNameSpaceID_None, kKeyAtom, key);
|
||||||
|
if (!key.IsEmpty())
|
||||||
|
keyMatched = IsMatchingCharCode(charCode, key);
|
||||||
|
|
||||||
|
key = "";
|
||||||
|
mBoundElement->GetAttribute(kNameSpaceID_None, kKeyCodeAtom, key);
|
||||||
|
if (!key.IsEmpty())
|
||||||
|
keyMatched = IsMatchingKeyCode(keyCode, key);
|
||||||
|
|
||||||
|
key = "";
|
||||||
|
mBoundElement->GetAttribute(kNameSpaceID_None, kCharCodeAtom, key);
|
||||||
|
if (!key.IsEmpty())
|
||||||
|
keyMatched = IsMatchingCharCode(charCode, key);
|
||||||
|
|
||||||
|
if (!keyMatched)
|
||||||
|
return PR_FALSE;
|
||||||
|
|
||||||
|
// Now check modifier keys
|
||||||
|
|
||||||
return PR_TRUE;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -696,14 +741,14 @@ PRBool nsXBLEventHandler::IsMatchingKeyCode(const PRUint32 aChar, const nsString
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool
|
PRBool
|
||||||
nsXBLEventHandler::IsMatchingCharCode(const nsString& aChar, const nsString& aKeyName)
|
nsXBLEventHandler::IsMatchingCharCode(const PRUint32 aChar, const nsString& aKeyName)
|
||||||
{
|
{
|
||||||
PRBool ret = PR_FALSE;
|
char tempChar[2];
|
||||||
|
tempChar[0] = aChar;
|
||||||
if (aChar == aKeyName)
|
tempChar[1] = 0;
|
||||||
ret = PR_TRUE;
|
nsAutoString tempChar2 = tempChar;
|
||||||
|
|
||||||
return ret;
|
return tempChar2.EqualsIgnoreCase(aKeyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -31,6 +31,7 @@ class nsIDOMEvent;
|
||||||
class nsIContent;
|
class nsIContent;
|
||||||
class nsIDOMUIEvent;
|
class nsIDOMUIEvent;
|
||||||
class nsIDOMKeyEvent;
|
class nsIDOMKeyEvent;
|
||||||
|
class nsIAtom;
|
||||||
|
|
||||||
class nsXBLEventHandler : public nsIDOMKeyListener,
|
class nsXBLEventHandler : public nsIDOMKeyListener,
|
||||||
public nsIDOMMouseListener
|
public nsIDOMMouseListener
|
||||||
|
@ -59,10 +60,15 @@ protected:
|
||||||
inline PRBool MouseEventMatched(nsIDOMUIEvent* aMouseEvent);
|
inline PRBool MouseEventMatched(nsIDOMUIEvent* aMouseEvent);
|
||||||
|
|
||||||
inline PRBool IsMatchingKeyCode(const PRUint32 aChar, const nsString& aKeyName);
|
inline PRBool IsMatchingKeyCode(const PRUint32 aChar, const nsString& aKeyName);
|
||||||
inline PRBool IsMatchingCharCode(const nsString& aChar, const nsString& aKeyName);
|
inline PRBool IsMatchingCharCode(const PRUint32 aChar, const nsString& aKeyName);
|
||||||
|
|
||||||
NS_IMETHOD ExecuteHandler();
|
NS_IMETHOD ExecuteHandler();
|
||||||
|
|
||||||
|
static PRUint32 gRefCnt;
|
||||||
|
static nsIAtom* kKeyAtom;
|
||||||
|
static nsIAtom* kKeyCodeAtom;
|
||||||
|
static nsIAtom* kCharCodeAtom;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
nsIContent* mBoundElement; // Both of these refs are weak.
|
nsIContent* mBoundElement; // Both of these refs are weak.
|
||||||
nsIContent* mHandlerElement;
|
nsIContent* mHandlerElement;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче