Bug 393582, Improve naNavigationDirection code, patch=karunasagark@gmail.com,r=enn,sr=bz

This commit is contained in:
Neil Deakin 2008-12-30 08:30:51 -05:00
parent 36c00fde37
commit a686e28c9e
3 changed files with 36 additions and 42 deletions

View File

@ -41,6 +41,8 @@
#ifndef nsXULPopupManager_h__
#define nsXULPopupManager_h__
#include "prlog.h"
#include "nsGUIEvent.h"
#include "nsIContent.h"
#include "nsIWidget.h"
#include "nsIRollupListener.h"
@ -51,6 +53,7 @@
#include "nsTArray.h"
#include "nsITimer.h"
#include "nsThreadUtils.h"
#include "nsStyleConsts.h"
/**
* There are two types that are used:
@ -126,33 +129,23 @@ enum nsNavigationDirection {
#define NS_DIRECTION_IS_BLOCK_TO_EDGE(dir) (dir == eNavigationDirection_First || \
dir == eNavigationDirection_Last)
/**
* DirectionFromKeyCode_lr_tb: an array that maps keycodes to values of
* nsNavigationDirection for left-to-right and top-to-bottom flow orientation
* This is defined in nsXULPopupManager.cpp.
*/
extern nsNavigationDirection DirectionFromKeyCode_lr_tb [6];
PR_STATIC_ASSERT(NS_STYLE_DIRECTION_LTR == 0 && NS_STYLE_DIRECTION_RTL == 1);
PR_STATIC_ASSERT((NS_VK_HOME == NS_VK_END + 1) &&
(NS_VK_LEFT == NS_VK_END + 2) &&
(NS_VK_UP == NS_VK_END + 3) &&
(NS_VK_RIGHT == NS_VK_END + 4) &&
(NS_VK_DOWN == NS_VK_END + 5));
/**
* DirectionFromKeyCode_rl_tb: an array that maps keycodes to values of
* nsNavigationDirection for right-to-left and top-to-bottom flow orientation
* This is defined in nsXULPopupManager.cpp.
* DirectionFromKeyCodeTable: two arrays, the first for left-to-right and the
* other for right-to-left, that map keycodes to values of
* nsNavigationDirection.
*/
extern nsNavigationDirection DirectionFromKeyCode_rl_tb [6];
extern const nsNavigationDirection DirectionFromKeyCodeTable[2][6];
#define NS_DIRECTION_FROM_KEY_CODE(frame, direction, keycode) \
NS_ASSERTION(NS_VK_HOME == NS_VK_END + 1, "Broken ordering"); \
NS_ASSERTION(NS_VK_LEFT == NS_VK_END + 2, "Broken ordering"); \
NS_ASSERTION(NS_VK_UP == NS_VK_END + 3, "Broken ordering"); \
NS_ASSERTION(NS_VK_RIGHT == NS_VK_END + 4, "Broken ordering"); \
NS_ASSERTION(NS_VK_DOWN == NS_VK_END + 5, "Broken ordering"); \
NS_ASSERTION(keycode >= NS_VK_END && keycode <= NS_VK_DOWN, \
"Illegal key code"); \
const nsStyleVisibility* vis = frame->GetStyleVisibility(); \
if (vis->mDirection == NS_STYLE_DIRECTION_RTL) \
direction = DirectionFromKeyCode_rl_tb[keycode - NS_VK_END]; \
else \
direction = DirectionFromKeyCode_lr_tb[keycode - NS_VK_END];
#define NS_DIRECTION_FROM_KEY_CODE(frame, keycode) \
(DirectionFromKeyCodeTable[frame->GetStyleVisibility()->mDirection] \
[keycode - NS_VK_END])
// nsMenuChainItem holds info about an open popup. Items are stored in a
// doubly linked list. Note that the linked list is stored beginning from

View File

@ -147,7 +147,7 @@ NS_IMETHODIMP nsMenuBoxObject::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent, PRBool*
case NS_VK_END:
{
nsNavigationDirection theDirection;
NS_DIRECTION_FROM_KEY_CODE(popupFrame, theDirection, keyCode);
theDirection = NS_DIRECTION_FROM_KEY_CODE(popupFrame, keyCode);
*aHandledFlag =
pm->HandleKeyboardNavigationInPopup(popupFrame, theDirection);
return NS_OK;

View File

@ -68,23 +68,23 @@
#include "nsIDocument.h"
#include "nsPIDOMWindow.h"
// See matching definitions in nsXULPopupManager.h
nsNavigationDirection DirectionFromKeyCode_lr_tb [6] = {
eNavigationDirection_Last, // NS_VK_END
eNavigationDirection_First, // NS_VK_HOME
eNavigationDirection_Start, // NS_VK_LEFT
eNavigationDirection_Before, // NS_VK_UP
eNavigationDirection_End, // NS_VK_RIGHT
eNavigationDirection_After // NS_VK_DOWN
};
nsNavigationDirection DirectionFromKeyCode_rl_tb [6] = {
eNavigationDirection_Last, // NS_VK_END
eNavigationDirection_First, // NS_VK_HOME
eNavigationDirection_End, // NS_VK_LEFT
eNavigationDirection_Before, // NS_VK_UP
eNavigationDirection_Start, // NS_VK_RIGHT
eNavigationDirection_After // NS_VK_DOWN
const nsNavigationDirection DirectionFromKeyCodeTable[2][6] = {
{
eNavigationDirection_Last, // NS_VK_END
eNavigationDirection_First, // NS_VK_HOME
eNavigationDirection_Start, // NS_VK_LEFT
eNavigationDirection_Before, // NS_VK_UP
eNavigationDirection_End, // NS_VK_RIGHT
eNavigationDirection_After // NS_VK_DOWN
},
{
eNavigationDirection_Last, // NS_VK_END
eNavigationDirection_First, // NS_VK_HOME
eNavigationDirection_End, // NS_VK_LEFT
eNavigationDirection_Before, // NS_VK_UP
eNavigationDirection_Start, // NS_VK_RIGHT
eNavigationDirection_After // NS_VK_DOWN
}
};
nsXULPopupManager* nsXULPopupManager::sInstance = nsnull;
@ -1604,7 +1604,8 @@ nsXULPopupManager::HandleKeyboardNavigation(PRUint32 aKeyCode)
return PR_FALSE;
nsNavigationDirection theDirection;
NS_DIRECTION_FROM_KEY_CODE(itemFrame, theDirection, aKeyCode);
NS_ASSERTION(aKeyCode >= NS_VK_END && aKeyCode <= NS_VK_DOWN, "Illegal key code");
theDirection = NS_DIRECTION_FROM_KEY_CODE(itemFrame, aKeyCode);
// if a popup is open, first check for navigation within the popup
if (item && HandleKeyboardNavigationInPopup(item, theDirection))