Bug 454820. r=smaug sr=bzbarsky

This commit is contained in:
Mats Palmgren 2008-09-16 03:37:13 +02:00
Родитель 60a30fbe2b
Коммит 07665de93e
5 изменённых файлов: 46 добавлений и 43 удалений

Просмотреть файл

@ -67,6 +67,7 @@ class nsIXPConnect;
class nsINode;
class nsIContent;
class nsIDOMNode;
class nsIDOMKeyEvent;
class nsIDocument;
class nsIDocShell;
class nsINameSpaceManager;
@ -1190,19 +1191,19 @@ public:
PRBool aGetCharCode);
/**
* Get the candidates for accelkeys for aDOMEvent.
* Get the candidates for accelkeys for aDOMKeyEvent.
*
* @param aDOMEvent [in] the input event for accelkey handling.
* @param aDOMKeyEvent [in] the key event for accelkey handling.
* @param aCandidates [out] the candidate shortcut key combination list.
* the first item is most preferred.
*/
static void GetAccelKeyCandidates(nsIDOMEvent* aDOMEvent,
static void GetAccelKeyCandidates(nsIDOMKeyEvent* aDOMKeyEvent,
nsTArray<nsShortcutCandidate>& aCandidates);
/**
* Get the candidates for accesskeys for aDOMEvent.
* Get the candidates for accesskeys for aNativeKeyEvent.
*
* @param aNativeKeyEvent [in] the input event for accesskey handling.
* @param aNativeKeyEvent [in] the key event for accesskey handling.
* @param aCandidates [out] the candidate access key list.
* the first item is most preferred.
*/

Просмотреть файл

@ -4002,20 +4002,22 @@ IsCaseChangeableChar(PRUint32 aChar)
/* static */
void
nsContentUtils::GetAccelKeyCandidates(nsIDOMEvent* aDOMEvent,
nsContentUtils::GetAccelKeyCandidates(nsIDOMKeyEvent* aDOMKeyEvent,
nsTArray<nsShortcutCandidate>& aCandidates)
{
NS_PRECONDITION(aCandidates.IsEmpty(), "aCandidates must be empty");
nsAutoString eventType;
aDOMEvent->GetType(eventType);
// Don't process if aDOMEvent is not a keypress event.
aDOMKeyEvent->GetType(eventType);
// Don't process if aDOMKeyEvent is not a keypress event.
if (!eventType.EqualsLiteral("keypress"))
return;
nsKeyEvent* nativeKeyEvent =
static_cast<nsKeyEvent*>(GetNativeEvent(aDOMEvent));
static_cast<nsKeyEvent*>(GetNativeEvent(aDOMKeyEvent));
if (nativeKeyEvent) {
NS_ASSERTION(nativeKeyEvent->eventStructType == NS_KEY_EVENT,
"wrong type of native event");
// nsShortcutCandidate::mCharCode is a candidate charCode.
// nsShoftcutCandidate::mIgnoreShift means the mCharCode should be tried to
// execute a command with/without shift key state. If this is TRUE, the
@ -4092,9 +4094,8 @@ nsContentUtils::GetAccelKeyCandidates(nsIDOMEvent* aDOMEvent,
}
}
} else {
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aDOMEvent));
PRUint32 charCode;
key->GetCharCode(&charCode);
aDOMKeyEvent->GetCharCode(&charCode);
if (charCode) {
nsShortcutCandidate key(charCode, PR_FALSE);
aCandidates.AppendElement(key);

Просмотреть файл

@ -166,9 +166,11 @@ nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
}
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
if (!key)
return NS_OK;
nsAutoTArray<nsShortcutCandidate, 10> accessKeys;
nsContentUtils::GetAccelKeyCandidates(aEvent, accessKeys);
nsContentUtils::GetAccelKeyCandidates(key, accessKeys);
if (accessKeys.IsEmpty()) {
ExecuteMatchedHandlers(key, 0, PR_FALSE);

Просмотреть файл

@ -318,7 +318,7 @@ DoCommandCallback(const char *aCommand, void *aData)
}
nsresult
nsXBLWindowKeyHandler::WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType)
nsXBLWindowKeyHandler::WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType)
{
nsCOMPtr<nsIDOMNSUIEvent> evt = do_QueryInterface(aKeyEvent);
PRBool prevent;
@ -337,11 +337,6 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType)
if (!trustedEvent)
return NS_OK;
// Make sure our event is really a key event
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aKeyEvent));
if (!keyEvent)
return NS_OK;
PRBool isEditor;
nsresult rv = EnsureHandlers(&isEditor);
NS_ENSURE_SUCCESS(rv, rv);
@ -402,19 +397,25 @@ nsXBLWindowKeyHandler::WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType)
return NS_OK;
}
nsresult nsXBLWindowKeyHandler::KeyUp(nsIDOMEvent* aKeyEvent)
nsresult nsXBLWindowKeyHandler::KeyUp(nsIDOMEvent* aEvent)
{
return WalkHandlers(aKeyEvent, nsGkAtoms::keyup);
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
return WalkHandlers(keyEvent, nsGkAtoms::keyup);
}
nsresult nsXBLWindowKeyHandler::KeyDown(nsIDOMEvent* aKeyEvent)
nsresult nsXBLWindowKeyHandler::KeyDown(nsIDOMEvent* aEvent)
{
return WalkHandlers(aKeyEvent, nsGkAtoms::keydown);
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
return WalkHandlers(keyEvent, nsGkAtoms::keydown);
}
nsresult nsXBLWindowKeyHandler::KeyPress(nsIDOMEvent* aKeyEvent)
nsresult nsXBLWindowKeyHandler::KeyPress(nsIDOMEvent* aEvent)
{
return WalkHandlers(aKeyEvent, nsGkAtoms::keypress);
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
NS_ENSURE_TRUE(keyEvent, NS_ERROR_INVALID_ARG);
return WalkHandlers(keyEvent, nsGkAtoms::keypress);
}
@ -425,15 +426,12 @@ nsresult nsXBLWindowKeyHandler::KeyPress(nsIDOMEvent* aKeyEvent)
//
PRBool
nsXBLWindowKeyHandler::EventMatched(nsXBLPrototypeHandler* inHandler,
nsIAtom* inEventType, nsIDOMEvent* inEvent,
nsIAtom* inEventType,
nsIDOMKeyEvent* inEvent,
PRUint32 aCharCode, PRBool aIgnoreShiftKey)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(inEvent));
if (keyEvent)
return inHandler->KeyEventMatched(inEventType, keyEvent, aCharCode,
return inHandler->KeyEventMatched(inEventType, inEvent, aCharCode,
aIgnoreShiftKey);
return PR_FALSE;
}
/* static */ void
@ -487,21 +485,21 @@ nsXBLWindowKeyHandler::IsEditor()
// so.
//
nsresult
nsXBLWindowKeyHandler::WalkHandlersInternal(nsIDOMEvent* aEvent,
nsXBLWindowKeyHandler::WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
nsIAtom* aEventType,
nsXBLPrototypeHandler* aHandler)
{
nsAutoTArray<nsShortcutCandidate, 10> accessKeys;
nsContentUtils::GetAccelKeyCandidates(aEvent, accessKeys);
nsContentUtils::GetAccelKeyCandidates(aKeyEvent, accessKeys);
if (accessKeys.IsEmpty()) {
WalkHandlersAndExecute(aEvent, aEventType, aHandler, 0, PR_FALSE);
WalkHandlersAndExecute(aKeyEvent, aEventType, aHandler, 0, PR_FALSE);
return NS_OK;
}
for (PRUint32 i = 0; i < accessKeys.Length(); ++i) {
nsShortcutCandidate &key = accessKeys[i];
if (WalkHandlersAndExecute(aEvent, aEventType, aHandler,
if (WalkHandlersAndExecute(aKeyEvent, aEventType, aHandler,
key.mCharCode, key.mIgnoreShift))
return NS_OK;
}
@ -509,14 +507,14 @@ nsXBLWindowKeyHandler::WalkHandlersInternal(nsIDOMEvent* aEvent,
}
PRBool
nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMEvent* aEvent,
nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent,
nsIAtom* aEventType,
nsXBLPrototypeHandler* aHandler,
PRUint32 aCharCode,
PRBool aIgnoreShiftKey)
{
nsresult rv;
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aEvent));
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(aKeyEvent));
// Try all of the handlers until we find one that matches the event.
for (nsXBLPrototypeHandler *currHandler = aHandler; currHandler;
@ -528,7 +526,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMEvent* aEvent,
return NS_OK;
}
if (!EventMatched(currHandler, aEventType, aEvent,
if (!EventMatched(currHandler, aEventType, aKeyEvent,
aCharCode, aIgnoreShiftKey))
continue; // try the next one
@ -586,7 +584,7 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMEvent* aEvent,
piTarget = mTarget;
}
rv = currHandler->ExecuteHandler(piTarget, aEvent);
rv = currHandler->ExecuteHandler(piTarget, aKeyEvent);
if (NS_SUCCEEDED(rv)) {
return PR_TRUE;
}

Просмотреть файл

@ -46,6 +46,7 @@
class nsIAtom;
class nsIDOMElement;
class nsIDOMEventTarget;
class nsIDOMKeyEvent;
class nsPIDOMEventTarget;
class nsIXBLDocumentInfo;
class nsXBLSpecialDocInfo;
@ -73,15 +74,15 @@ public:
static NS_HIDDEN_(void) ShutDown();
protected:
nsresult WalkHandlers(nsIDOMEvent* aKeyEvent, nsIAtom* aEventType);
nsresult WalkHandlers(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType);
// walk the handlers, looking for one to handle the event
nsresult WalkHandlersInternal(nsIDOMEvent* aKeyEvent,
nsresult WalkHandlersInternal(nsIDOMKeyEvent* aKeyEvent,
nsIAtom* aEventType,
nsXBLPrototypeHandler* aHandler);
// walk the handlers for aEvent, aCharCode and aIgnoreShiftKey
PRBool WalkHandlersAndExecute(nsIDOMEvent* aEvent, nsIAtom* aEventType,
PRBool WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent, nsIAtom* aEventType,
nsXBLPrototypeHandler* aHandler,
PRUint32 aCharCode, PRBool aIgnoreShiftKey);
@ -91,7 +92,7 @@ protected:
// check if the given handler cares about the given key event
PRBool EventMatched(nsXBLPrototypeHandler* inHandler, nsIAtom* inEventType,
nsIDOMEvent* inEvent, PRUint32 aCharCode,
nsIDOMKeyEvent* inEvent, PRUint32 aCharCode,
PRBool aIgnoreShiftKey);
// are we working with editor or browser?