From 2c68c030522a34267ce32b696d6ce6d30d88bc7f Mon Sep 17 00:00:00 2001 From: "dougt%meer.net" Date: Thu, 1 Sep 2005 19:51:58 +0000 Subject: [PATCH] Addresses 305712. There is more worked needed to make this solid with respect to form elements. However, this patch makes it so that you can navigate select elements with the normal up/down arrow keys, and you can use the left/right+modifier to use snav NPODB git-svn-id: svn://10.0.0.236/trunk@179493 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/nsSpatialNavigation.cpp | 85 ++++++++++++------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/mozilla/extensions/spatialnavigation/src/nsSpatialNavigation.cpp b/mozilla/extensions/spatialnavigation/src/nsSpatialNavigation.cpp index faae6d6d01c..bcd1326d7db 100755 --- a/mozilla/extensions/spatialnavigation/src/nsSpatialNavigation.cpp +++ b/mozilla/extensions/spatialnavigation/src/nsSpatialNavigation.cpp @@ -85,47 +85,47 @@ NS_IMETHODIMP nsSpatialNavigation::KeyPress(nsIDOMEvent* aEvent) { + PRInt32 formControlType = -1; // check to see if we are in a text field. + // based on nsTypeAheadFind. + + //nsEvent should be renamed. + nsCOMPtr nsEvent = do_QueryInterface(aEvent); + if (!nsEvent) + return NS_ERROR_FAILURE; - if (!mService->mIgnoreTextFields) + nsCOMPtr domEventTarget; + nsEvent->GetOriginalTarget(getter_AddRefs(domEventTarget)); + + nsCOMPtr targetContent = do_QueryInterface(domEventTarget); + + if (targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) { - // based on nsTypeAheadFind. - - //nsEvent should be renamed. - nsCOMPtr nsEvent = do_QueryInterface(aEvent); - if (!nsEvent) - return NS_ERROR_FAILURE; - - nsCOMPtr domEventTarget; - nsEvent->GetOriginalTarget(getter_AddRefs(domEventTarget)); - - nsCOMPtr targetContent = do_QueryInterface(domEventTarget); - - if (targetContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) - { nsCOMPtr formControl(do_QueryInterface(targetContent)); - PRInt32 controlType = formControl->GetType(); + formControlType = formControl->GetType(); - if (controlType == NS_FORM_TEXTAREA || - controlType == NS_FORM_INPUT_TEXT || - controlType == NS_FORM_INPUT_PASSWORD || - controlType == NS_FORM_INPUT_FILE) + if (!mService->mIgnoreTextFields) { - return NS_OK; + if (formControlType == NS_FORM_TEXTAREA || + formControlType == NS_FORM_INPUT_TEXT || + formControlType == NS_FORM_INPUT_PASSWORD || + formControlType == NS_FORM_INPUT_FILE) + { + return NS_OK; + } } - } - else if (targetContent->IsContentOfType(nsIContent::eHTML)) - { - // Test for isindex, a deprecated kind of text field. We're using a string - // compare because is not considered a form control, so it does - // not support nsIFormControl or eHTML_FORM_CONTROL, and it's not worth - // having a table of atoms just for it. - + } + else if (!mService->mIgnoreTextFields && targetContent->IsContentOfType(nsIContent::eHTML)) + { + // Test for isindex, a deprecated kind of text field. We're using a string + // compare because is not considered a form control, so it does + // not support nsIFormControl or eHTML_FORM_CONTROL, and it's not worth + // having a table of atoms just for it. + if (isContentOfType(targetContent, "isindex")) return NS_OK; - } } - + PRUint32 keyCode; PRBool isModifier; nsCOMPtr keyEvent(do_QueryInterface(aEvent)); @@ -189,6 +189,18 @@ nsSpatialNavigation::KeyPress(nsIDOMEvent* aEvent) if (keyCode == mService->mKeyCodeUp) { + + // If we are going up or down, in a select, lets not + // navigate. + // + // FIX: What we really want to do is determine if we are + // at the start or the end fo the form element, and + // based on the selected position we decide to nav. or + // not. + + if (formControlType == NS_FORM_SELECT) + return NS_OK; + aEvent->StopPropagation(); aEvent->PreventDefault(); return Up(); @@ -196,6 +208,17 @@ nsSpatialNavigation::KeyPress(nsIDOMEvent* aEvent) if (keyCode == mService->mKeyCodeDown) { + // If we are going up or down, in a select, lets not + // navigate. + // + // FIX: What we really want to do is determine if we are + // at the start or the end fo the form element, and + // based on the selected position we decide to nav. or + // not. + + if (formControlType == NS_FORM_SELECT) + return NS_OK; + aEvent->StopPropagation(); // We're using this key, no one else should aEvent->PreventDefault(); return Down();