23587: Make accelerator and menu access keys settable through a pref. r=saari

This commit is contained in:
akkana%netscape.com 2000-08-17 00:09:16 +00:00
Родитель 83dac351cb
Коммит 5b58ac4fc2
15 изменённых файлов: 399 добавлений и 389 удалений

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

@ -45,6 +45,10 @@
#include "nsIDOMEventReceiver.h"
#include "nsXBLBinding.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
PRUint32 nsXBLEventHandler::gRefCnt = 0;
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
@ -71,6 +75,7 @@ nsXBLEventHandler::nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHan
mEventName.Assign(aEventName);
mNextHandler = nsnull;
gRefCnt++;
mAccessKey = -1;
if (gRefCnt == 1) {
kKeyCodeAtom = NS_NewAtom("keycode");
kKeyAtom = NS_NewAtom("key");
@ -371,7 +376,38 @@ nsresult nsXBLEventHandler::Destroy(nsIDOMEvent* aEvent)
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Get the menu access key from prefs.
// XXX Eventually pick up using CSS3 key-equivalent property or somesuch
void
nsXBLEventHandler::InitAccessKey()
{
if (mAccessKey >= 0)
return;
// Compiled-in defaults, in case we can't get the pref --
// mac doesn't have menu shortcuts, other platforms use alt.
#ifndef XP_MAC
mAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
#else
mAccessKey = 0;
#endif
// Get the menu access key value from prefs, overriding the default:
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
rv = prefs->GetIntPref("ui.key.menuAccessKey", &mAccessKey);
}
#ifdef DEBUG_akkana
if (NS_FAILED(rv))
{
NS_ASSERTION(PR_FALSE,"XBLEventHandler couldn't get menu access key from prefs!\n");
}
#endif
}
PRBool
nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
@ -409,31 +445,31 @@ nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
// Now check modifier keys
nsAutoString modifier;
PRBool isModifierPresent;
mHandlerElement->GetAttribute(kNameSpaceID_None, kPrimaryAtom, modifier);
if (modifier == trueString) {
// The XUL key must be set. Hard code for now.
// XXX Eventually pick up using CSS3 key-equivalent property or somesuch
#ifdef XP_MAC
aKeyEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aKeyEvent->GetAltKey(&isModifierPresent);
#else
aKeyEvent->GetCtrlKey(&isModifierPresent);
#endif
// Get the xulkey.
InitAccessKey();
PRBool isModifierPresent = PR_FALSE;
switch (mAccessKey)
{
case nsIDOMKeyEvent::DOM_VK_META:
aKeyEvent->GetMetaKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_ALT:
aKeyEvent->GetAltKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_CONTROL:
default:
aKeyEvent->GetCtrlKey(&isModifierPresent);
}
if (modifier == trueString) {
if (!isModifierPresent)
return PR_FALSE;
}
else if (modifier == falseString) {
#ifdef XP_MAC
aKeyEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aKeyEvent->GetAltKey(&isModifierPresent);
#else
aKeyEvent->GetCtrlKey(&isModifierPresent);
#endif
if (isModifierPresent)
return PR_FALSE;
}
@ -505,31 +541,30 @@ nsXBLEventHandler::MouseEventMatched(nsIDOMMouseEvent* aMouseEvent)
// XXX Check for button and modifier keys.
// Now check modifier keys
nsAutoString modifier;
PRBool isModifierPresent;
mHandlerElement->GetAttribute(kNameSpaceID_None, kPrimaryAtom, modifier);
if (modifier == trueString) {
// The XUL key must be set. Hard code for now.
// XXX Eventually pick up using CSS3 key-equivalent property or somesuch
#ifdef XP_MAC
aMouseEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aMouseEvent->GetAltKey(&isModifierPresent);
#else
aMouseEvent->GetCtrlKey(&isModifierPresent);
#endif
// Get the xulkey
InitAccessKey();
PRBool isModifierPresent = PR_FALSE;
switch (mAccessKey)
{
case nsIDOMKeyEvent::DOM_VK_META:
aMouseEvent->GetMetaKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_ALT:
aMouseEvent->GetAltKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_CONTROL:
default:
aMouseEvent->GetCtrlKey(&isModifierPresent);
}
if (modifier == trueString) {
if (!isModifierPresent)
return PR_FALSE;
}
else if (modifier == falseString) {
#ifdef XP_MAC
aMouseEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aMouseEvent->GetAltKey(&isModifierPresent);
#else
aMouseEvent->GetCtrlKey(&isModifierPresent);
#endif
if (isModifierPresent)
return PR_FALSE;
}

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

@ -130,6 +130,9 @@ protected:
nsIContent* mHandlerElement;
nsAutoString mEventName;
void InitAccessKey();
PRInt32 mAccessKey; // the default access key or "xulkey"
nsXBLEventHandler* mNextHandler; // Handlers are chained for easy unloading later.
};

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

@ -150,7 +150,8 @@ public:
DOM_VK_OPEN_BRACKET = 219,
DOM_VK_BACK_SLASH = 220,
DOM_VK_CLOSE_BRACKET = 221,
DOM_VK_QUOTE = 222
DOM_VK_QUOTE = 222,
DOM_VK_META = 224
};
NS_IMETHOD GetCharCode(PRUint32* aCharCode)=0;

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

@ -1,177 +0,0 @@
interface KeyEvent : UIEvent {
/* IID: { 0x028e0e6e, 0x8b01, 0x11d3, \
{ 0xaa, 0xe7, 0x00, 0x10, 0x83, 0x8a, 0x31, 0x23 } } */
const unsigned long DOM_VK_CANCEL = 0x03;
const unsigned long DOM_VK_BACK_SPACE = 0x08;
const unsigned long DOM_VK_TAB = 0x09;
const unsigned long DOM_VK_CLEAR = 0x0C;
const unsigned long DOM_VK_RETURN = 0x0D;
const unsigned long DOM_VK_ENTER = 0x0E;
const unsigned long DOM_VK_SHIFT = 0x10;
const unsigned long DOM_VK_CONTROL = 0x11;
const unsigned long DOM_VK_ALT = 0x12;
const unsigned long DOM_VK_PAUSE = 0x13;
const unsigned long DOM_VK_CAPS_LOCK = 0x14;
const unsigned long DOM_VK_ESCAPE = 0x1B;
const unsigned long DOM_VK_SPACE = 0x20;
const unsigned long DOM_VK_PAGE_UP = 0x21;
const unsigned long DOM_VK_PAGE_DOWN = 0x22;
const unsigned long DOM_VK_END = 0x23;
const unsigned long DOM_VK_HOME = 0x24;
const unsigned long DOM_VK_LEFT = 0x25;
const unsigned long DOM_VK_UP = 0x26;
const unsigned long DOM_VK_RIGHT = 0x27;
const unsigned long DOM_VK_DOWN = 0x28;
const unsigned long DOM_VK_PRINTSCREEN = 0x2C;
const unsigned long DOM_VK_INSERT = 0x2D;
const unsigned long DOM_VK_DELETE = 0x2E;
// DOM_VK_0 - DOM_VK_9 match their ascii values
const unsigned long DOM_VK_0 = 0x30;
const unsigned long DOM_VK_1 = 0x31;
const unsigned long DOM_VK_2 = 0x32;
const unsigned long DOM_VK_3 = 0x33;
const unsigned long DOM_VK_4 = 0x34;
const unsigned long DOM_VK_5 = 0x35;
const unsigned long DOM_VK_6 = 0x36;
const unsigned long DOM_VK_7 = 0x37;
const unsigned long DOM_VK_8 = 0x38;
const unsigned long DOM_VK_9 = 0x39;
const unsigned long DOM_VK_SEMICOLON = 0x3B;
const unsigned long DOM_VK_EQUALS = 0x3D;
// DOM_VK_A - DOM_VK_Z match their ascii values
const unsigned long DOM_VK_A = 0x41;
const unsigned long DOM_VK_B = 0x42;
const unsigned long DOM_VK_C = 0x43;
const unsigned long DOM_VK_D = 0x44;
const unsigned long DOM_VK_E = 0x45;
const unsigned long DOM_VK_F = 0x46;
const unsigned long DOM_VK_G = 0x47;
const unsigned long DOM_VK_H = 0x48;
const unsigned long DOM_VK_I = 0x49;
const unsigned long DOM_VK_J = 0x4A;
const unsigned long DOM_VK_K = 0x4B;
const unsigned long DOM_VK_L = 0x4C;
const unsigned long DOM_VK_M = 0x4D;
const unsigned long DOM_VK_N = 0x4E;
const unsigned long DOM_VK_O = 0x4F;
const unsigned long DOM_VK_P = 0x50;
const unsigned long DOM_VK_Q = 0x51;
const unsigned long DOM_VK_R = 0x52;
const unsigned long DOM_VK_S = 0x53;
const unsigned long DOM_VK_T = 0x54;
const unsigned long DOM_VK_U = 0x55;
const unsigned long DOM_VK_V = 0x56;
const unsigned long DOM_VK_W = 0x57;
const unsigned long DOM_VK_X = 0x58;
const unsigned long DOM_VK_Y = 0x59;
const unsigned long DOM_VK_Z = 0x5A;
const unsigned long DOM_VK_NUMPAD0 = 0x60;
const unsigned long DOM_VK_NUMPAD1 = 0x61;
const unsigned long DOM_VK_NUMPAD2 = 0x62;
const unsigned long DOM_VK_NUMPAD3 = 0x63;
const unsigned long DOM_VK_NUMPAD4 = 0x64;
const unsigned long DOM_VK_NUMPAD5 = 0x65;
const unsigned long DOM_VK_NUMPAD6 = 0x66;
const unsigned long DOM_VK_NUMPAD7 = 0x67;
const unsigned long DOM_VK_NUMPAD8 = 0x68;
const unsigned long DOM_VK_NUMPAD9 = 0x69;
const unsigned long DOM_VK_MULTIPLY = 0x6A;
const unsigned long DOM_VK_ADD = 0x6B;
const unsigned long DOM_VK_SEPARATOR = 0x6C;
const unsigned long DOM_VK_SUBTRACT = 0x6D;
const unsigned long DOM_VK_DECIMAL = 0x6E;
const unsigned long DOM_VK_DIVIDE = 0x6F;
const unsigned long DOM_VK_F1 = 0x70;
const unsigned long DOM_VK_F2 = 0x71;
const unsigned long DOM_VK_F3 = 0x72;
const unsigned long DOM_VK_F4 = 0x73;
const unsigned long DOM_VK_F5 = 0x74;
const unsigned long DOM_VK_F6 = 0x75;
const unsigned long DOM_VK_F7 = 0x76;
const unsigned long DOM_VK_F8 = 0x77;
const unsigned long DOM_VK_F9 = 0x78;
const unsigned long DOM_VK_F10 = 0x79;
const unsigned long DOM_VK_F11 = 0x7A;
const unsigned long DOM_VK_F12 = 0x7B;
const unsigned long DOM_VK_F13 = 0x7C;
const unsigned long DOM_VK_F14 = 0x7D;
const unsigned long DOM_VK_F15 = 0x7E;
const unsigned long DOM_VK_F16 = 0x7F;
const unsigned long DOM_VK_F17 = 0x80;
const unsigned long DOM_VK_F18 = 0x81;
const unsigned long DOM_VK_F19 = 0x82;
const unsigned long DOM_VK_F20 = 0x83;
const unsigned long DOM_VK_F21 = 0x84;
const unsigned long DOM_VK_F22 = 0x85;
const unsigned long DOM_VK_F23 = 0x86;
const unsigned long DOM_VK_F24 = 0x87;
const unsigned long DOM_VK_NUM_LOCK = 0x90;
const unsigned long DOM_VK_SCROLL_LOCK = 0x91;
const unsigned long DOM_VK_COMMA = 0xBC;
const unsigned long DOM_VK_PERIOD = 0xBE;
const unsigned long DOM_VK_SLASH = 0xBF;
const unsigned long DOM_VK_BACK_QUOTE = 0xC0;
const unsigned long DOM_VK_OPEN_BRACKET = 0xDB;
const unsigned long DOM_VK_BACK_SLASH = 0xDC;
const unsigned long DOM_VK_CLOSE_BRACKET = 0xDD;
const unsigned long DOM_VK_QUOTE = 0xDE;
readonly attribute unsigned long charCode;
readonly attribute unsigned long keyCode;
readonly attribute boolean altKey;
readonly attribute boolean ctrlKey;
readonly attribute boolean shiftKey;
readonly attribute boolean metaKey;
void initKeyEvent(in DOMString typeArg,
in boolean canBubbleArg,
in boolean cancelableArg,
in boolean ctrlKeyArg,
in boolean altKeyArg,
in boolean shiftKeyArg,
in boolean metaKeyArg,
in unsigned long keyCodeArg,
in unsigned long charCodeArg,
in AbstractView viewArg);
};
interface MouseEvent : UIEvent {
/* IID: { 0xff751edc, 0x8b02, 0xaae7, \
{ 0x00, 0x10, 0x83, 0x01, 0x83, 0x8a, 0x31, 0x23 } } */
readonly attribute int screenX;
readonly attribute int screenY;
readonly attribute int clientX;
readonly attribute int clientY;
noscript readonly attribute boolean altKey;
noscript readonly attribute boolean ctrlKey;
noscript readonly attribute boolean shiftKey;
noscript readonly attribute boolean metaKey;
readonly attribute unsigned short button;
readonly attribute EventTarget relatedTarget;
void initMouseEvent(in DOMString typeArg,
in boolean ctrlKeyArg,
in boolean altKeyArg,
in boolean shiftKeyArg,
in boolean metaKeyArg,
in long screenXArg,
in long screenYArg,
in long clientXArg,
in long clientYArg,
in unsigned short buttonArg,
in unsigned short detailArg);
};

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

@ -45,6 +45,10 @@
#include "nsIDOMEventReceiver.h"
#include "nsXBLBinding.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
PRUint32 nsXBLEventHandler::gRefCnt = 0;
nsIAtom* nsXBLEventHandler::kKeyCodeAtom = nsnull;
@ -71,6 +75,7 @@ nsXBLEventHandler::nsXBLEventHandler(nsIContent* aBoundElement, nsIContent* aHan
mEventName.Assign(aEventName);
mNextHandler = nsnull;
gRefCnt++;
mAccessKey = -1;
if (gRefCnt == 1) {
kKeyCodeAtom = NS_NewAtom("keycode");
kKeyAtom = NS_NewAtom("key");
@ -371,7 +376,38 @@ nsresult nsXBLEventHandler::Destroy(nsIDOMEvent* aEvent)
return NS_OK;
}
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Get the menu access key from prefs.
// XXX Eventually pick up using CSS3 key-equivalent property or somesuch
void
nsXBLEventHandler::InitAccessKey()
{
if (mAccessKey >= 0)
return;
// Compiled-in defaults, in case we can't get the pref --
// mac doesn't have menu shortcuts, other platforms use alt.
#ifndef XP_MAC
mAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
#else
mAccessKey = 0;
#endif
// Get the menu access key value from prefs, overriding the default:
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
rv = prefs->GetIntPref("ui.key.menuAccessKey", &mAccessKey);
}
#ifdef DEBUG_akkana
if (NS_FAILED(rv))
{
NS_ASSERTION(PR_FALSE,"XBLEventHandler couldn't get menu access key from prefs!\n");
}
#endif
}
PRBool
nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
@ -409,31 +445,31 @@ nsXBLEventHandler::KeyEventMatched(nsIDOMKeyEvent* aKeyEvent)
// Now check modifier keys
nsAutoString modifier;
PRBool isModifierPresent;
mHandlerElement->GetAttribute(kNameSpaceID_None, kPrimaryAtom, modifier);
if (modifier == trueString) {
// The XUL key must be set. Hard code for now.
// XXX Eventually pick up using CSS3 key-equivalent property or somesuch
#ifdef XP_MAC
aKeyEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aKeyEvent->GetAltKey(&isModifierPresent);
#else
aKeyEvent->GetCtrlKey(&isModifierPresent);
#endif
// Get the xulkey.
InitAccessKey();
PRBool isModifierPresent = PR_FALSE;
switch (mAccessKey)
{
case nsIDOMKeyEvent::DOM_VK_META:
aKeyEvent->GetMetaKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_ALT:
aKeyEvent->GetAltKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_CONTROL:
default:
aKeyEvent->GetCtrlKey(&isModifierPresent);
}
if (modifier == trueString) {
if (!isModifierPresent)
return PR_FALSE;
}
else if (modifier == falseString) {
#ifdef XP_MAC
aKeyEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aKeyEvent->GetAltKey(&isModifierPresent);
#else
aKeyEvent->GetCtrlKey(&isModifierPresent);
#endif
if (isModifierPresent)
return PR_FALSE;
}
@ -505,31 +541,30 @@ nsXBLEventHandler::MouseEventMatched(nsIDOMMouseEvent* aMouseEvent)
// XXX Check for button and modifier keys.
// Now check modifier keys
nsAutoString modifier;
PRBool isModifierPresent;
mHandlerElement->GetAttribute(kNameSpaceID_None, kPrimaryAtom, modifier);
if (modifier == trueString) {
// The XUL key must be set. Hard code for now.
// XXX Eventually pick up using CSS3 key-equivalent property or somesuch
#ifdef XP_MAC
aMouseEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aMouseEvent->GetAltKey(&isModifierPresent);
#else
aMouseEvent->GetCtrlKey(&isModifierPresent);
#endif
// Get the xulkey
InitAccessKey();
PRBool isModifierPresent = PR_FALSE;
switch (mAccessKey)
{
case nsIDOMKeyEvent::DOM_VK_META:
aMouseEvent->GetMetaKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_ALT:
aMouseEvent->GetAltKey(&isModifierPresent);
break;
case nsIDOMKeyEvent::DOM_VK_CONTROL:
default:
aMouseEvent->GetCtrlKey(&isModifierPresent);
}
if (modifier == trueString) {
if (!isModifierPresent)
return PR_FALSE;
}
else if (modifier == falseString) {
#ifdef XP_MAC
aMouseEvent->GetMetaKey(&isModifierPresent);
#elif XP_UNIX
aMouseEvent->GetAltKey(&isModifierPresent);
#else
aMouseEvent->GetCtrlKey(&isModifierPresent);
#endif
if (isModifierPresent)
return PR_FALSE;
}

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

@ -130,6 +130,9 @@ protected:
nsIContent* mHandlerElement;
nsAutoString mEventName;
void InitAccessKey();
PRInt32 mAccessKey; // the default access key or "xulkey"
nsXBLEventHandler* mNextHandler; // Handlers are chained for easy unloading later.
};

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

@ -46,6 +46,10 @@
#include "nsIView.h"
#include "nsISupportsArray.h"
#include "nsIPref.h"
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
/*
* nsMenuBarListener implementation
*/
@ -58,7 +62,7 @@ NS_IMPL_QUERY_INTERFACE3(nsMenuBarListener, nsIDOMKeyListener, nsIDOMFocusListen
////////////////////////////////////////////////////////////////////////
nsMenuBarListener::nsMenuBarListener(nsMenuBarFrame* aMenuBar)
:mAltKeyDown(PR_FALSE)
:mAccessKeyDown(PR_FALSE), mAccessKey(-1)
{
NS_INIT_REFCNT();
mMenuBarFrame = aMenuBar;
@ -69,34 +73,64 @@ nsMenuBarListener::~nsMenuBarListener()
{
}
void nsMenuBarListener::InitAccessKey()
{
if (mAccessKey >= 0)
return;
// Compiled-in defaults, in case we can't get LookAndFeel --
// mac doesn't have menu shortcuts, other platforms use alt.
#ifndef XP_MAC
mAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
#else
mAccessKey = 0;
#endif
// Get the menu access key value from prefs, overriding the default:
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
rv = prefs->GetIntPref("ui.key.menuAccessKey", &mAccessKey);
}
#ifdef DEBUG_akkana
if (NS_FAILED(rv))
{
NS_ASSERTION(PR_FALSE,"Menubar listener couldn't get accel key from prefs!\n");
}
#endif
}
////////////////////////////////////////////////////////////////////////
nsresult
nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
{
// On a press of the ALT key by itself, we toggle the menu's
// active/inactive state.
// Get the ascii key code.
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
InitAccessKey();
#if !defined(XP_UNIX) || defined(NTO)
if (theChar == NS_VK_ALT && mAltKeyDown) {
// The ALT key was down and is now up.
mMenuBarFrame->ToggleMenuActiveState();
if (mAccessKey)
{
// On a press of the ALT key by itself, we toggle the menu's
// active/inactive state.
// Get the ascii key code.
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
if (mAccessKeyDown && (PRInt32)theChar == mAccessKey)
{
// The access key was down and is now up.
mMenuBarFrame->ToggleMenuActiveState();
}
mAccessKeyDown = PR_FALSE;
PRBool active = mMenuBarFrame->IsActive();
if (active) {
aKeyEvent->PreventBubble();
aKeyEvent->PreventCapture();
aKeyEvent->PreventDefault();
return NS_ERROR_BASE; // I am consuming event
}
}
mAltKeyDown = PR_FALSE;
#endif
PRBool active = mMenuBarFrame->IsActive();
if (active) {
aKeyEvent->PreventBubble();
aKeyEvent->PreventCapture();
aKeyEvent->PreventDefault();
return NS_ERROR_BASE; // I am consuming event
}
return NS_OK; // means I am NOT consuming event
}
@ -105,36 +139,39 @@ nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
nsresult
nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
{
#if !defined(XP_UNIX) || defined(NTO)
nsCOMPtr<nsIDOMNSUIEvent> nsUIEvent = do_QueryInterface(aKeyEvent);
PRBool preventDefault;
InitAccessKey();
nsUIEvent->GetPreventDefault(&preventDefault);
if (!preventDefault) {
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
if (mAccessKey)
{
nsCOMPtr<nsIDOMNSUIEvent> nsUIEvent = do_QueryInterface(aKeyEvent);
PRBool preventDefault;
if (mAltKeyDown && (theChar != NS_VK_ALT)) {
mAltKeyDown = PR_FALSE;
nsUIEvent->GetPreventDefault(&preventDefault);
if (!preventDefault) {
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
// Do shortcut navigation.
// A letter was pressed. We want to see if a shortcut gets matched. If
// so, we'll know the menu got activated.
keyEvent->GetCharCode(&theChar);
if (mAccessKeyDown && ((PRInt32)theChar != mAccessKey)) {
mAccessKeyDown = PR_FALSE;
PRBool active = PR_FALSE;
mMenuBarFrame->ShortcutNavigation(theChar, active);
// Do shortcut navigation.
// A letter was pressed. We want to see if a shortcut gets matched. If
// so, we'll know the menu got activated.
keyEvent->GetCharCode(&theChar);
if (active) {
aKeyEvent->PreventBubble();
aKeyEvent->PreventCapture();
aKeyEvent->PreventDefault();
}
return NS_ERROR_BASE; // I am consuming event
}
}
#endif
PRBool active = PR_FALSE;
mMenuBarFrame->ShortcutNavigation(theChar, active);
if (active) {
aKeyEvent->PreventBubble();
aKeyEvent->PreventCapture();
aKeyEvent->PreventDefault();
}
return NS_ERROR_BASE; // I am consuming event
}
}
}
return NS_OK;
}
@ -142,31 +179,56 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
nsresult
nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
{
#if !defined(XP_UNIX) || defined(NTO)
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
PRBool alt;
keyEvent->GetAltKey(&alt);
if (theChar == NS_VK_TAB && mAltKeyDown) {
mAltKeyDown = PR_FALSE;
}
InitAccessKey();
if (theChar == NS_VK_ALT && alt) {
// No other modifiers can be down.
// Especially CTRL. CTRL+ALT == AltGR, and
// we'll fuck up on non-US enhanced 102-key
// keyboards if we don't check this.
PRBool ctrl,shift,meta;
keyEvent->GetCtrlKey(&ctrl);
keyEvent->GetShiftKey(&shift);
keyEvent->GetMetaKey(&meta);
if (!(ctrl || shift || meta)) {
// The ALT key just went down by itself. Track this.
mAltKeyDown = PR_TRUE;
if (mAccessKey)
{
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
PRUint32 theChar;
keyEvent->GetKeyCode(&theChar);
PRBool access;
switch (mAccessKey)
{
case nsIDOMKeyEvent::DOM_VK_CONTROL:
keyEvent->GetCtrlKey(&access);
break;
case nsIDOMKeyEvent::DOM_VK_ALT:
keyEvent->GetAltKey(&access);
break;
case nsIDOMKeyEvent::DOM_VK_META:
keyEvent->GetMetaKey(&access);
break;
default:
access = 0;
}
if (theChar == nsIDOMKeyEvent::DOM_VK_TAB && mAccessKeyDown) {
mAccessKeyDown = PR_FALSE;
}
if (theChar == mAccessKey || access) {
// No other modifiers can be down.
// Especially CTRL. CTRL+ALT == AltGR, and
// we'll fuck up on non-US enhanced 102-key
// keyboards if we don't check this.
PRBool ctrl = PR_FALSE;
if (mAccessKey != nsIDOMKeyEvent::DOM_VK_CONTROL)
keyEvent->GetCtrlKey(&ctrl);
PRBool alt=PR_FALSE;
if (mAccessKey != nsIDOMKeyEvent::DOM_VK_ALT)
keyEvent->GetAltKey(&alt);
PRBool shift=PR_FALSE;
if (mAccessKey != nsIDOMKeyEvent::DOM_VK_SHIFT)
keyEvent->GetShiftKey(&shift);
PRBool meta=PR_FALSE;
if (mAccessKey != nsIDOMKeyEvent::DOM_VK_META)
keyEvent->GetMetaKey(&meta);
if (!(ctrl || alt || shift || meta)) {
// The access key just went down by itself. Track this.
mAccessKeyDown = PR_TRUE;
}
}
}
#endif
return NS_OK; // means I am NOT consuming event
}
@ -187,7 +249,7 @@ nsMenuBarListener::Blur(nsIDOMEvent* aEvent)
mMenuBarFrame->ToggleMenuActiveState();
PRBool handled;
mMenuBarFrame->Escape(handled);
mAltKeyDown = PR_FALSE;
mAccessKeyDown = PR_FALSE;
}
return NS_OK; // means I am NOT consuming event
}
@ -200,7 +262,7 @@ nsMenuBarListener::MouseDown(nsIDOMEvent* aMouseEvent)
mMenuBarFrame->ToggleMenuActiveState();
PRBool handled;
mMenuBarFrame->Escape(handled);
mAltKeyDown = PR_FALSE;
mAccessKeyDown = PR_FALSE;
}
return NS_OK; // means I am NOT consuming event
}

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

@ -64,8 +64,11 @@ public:
NS_DECL_ISUPPORTS
protected:
void InitAccessKey();
nsMenuBarFrame* mMenuBarFrame; // The menu bar object.
PRBool mAltKeyDown; // Whether or not the ALT key is currently down.
PRBool mAccessKeyDown; // Whether or not the ALT key is currently down.
PRInt32 mAccessKey; // See nsIDOMKeyEvent.h for sample values
};

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

@ -63,7 +63,9 @@
#include "nsIServiceManager.h"
#include "nsIXBLService.h"
#include "nsCSSFrameConstructor.h"
#include "nsIDOMKeyEvent.h"
#include "nsIPref.h"
#define NS_MENU_POPUP_LIST_INDEX 0
static PRInt32 gEatMouseMove = PR_FALSE;
@ -72,7 +74,7 @@ nsMenuDismissalListener* nsMenuFrame::mDismissalListener = nsnull;
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
//
// NS_NewMenuFrame
@ -135,7 +137,7 @@ nsMenuFrame::nsMenuFrame(nsIPresShell* aShell):nsBoxFrame(aShell),
NS_IMETHODIMP
nsMenuFrame::SetParent(const nsIFrame* aParent)
{
nsresult rv = nsBoxFrame::SetParent(aParent);
nsBoxFrame::SetParent(aParent);
nsIFrame* currFrame = (nsIFrame*)aParent;
while (!mMenuParent && currFrame) {
// Set our menu parent.
@ -1363,61 +1365,79 @@ nsMenuFrame::BuildAcceleratorText(nsString& aAccelString)
nsAutoString keyAtom; keyAtom.AssignWithConversion("key");
nsAutoString shiftAtom; shiftAtom.AssignWithConversion("shift");
nsAutoString altAtom; altAtom.AssignWithConversion("alt");
nsAutoString commandAtom; commandAtom.AssignWithConversion("command");
nsAutoString altAtom; altAtom.AssignWithConversion("alt");
nsAutoString commandAtom; commandAtom.AssignWithConversion("command");
nsAutoString controlAtom; controlAtom.AssignWithConversion("control");
nsAutoString shiftValue;
nsAutoString altValue;
nsAutoString commandValue;
nsAutoString shiftValue;
nsAutoString altValue;
nsAutoString commandValue;
nsAutoString controlValue;
nsAutoString keyChar; keyChar.AssignWithConversion(" ");
nsAutoString keyChar; keyChar.AssignWithConversion(" ");
keyElement->GetAttribute(keyAtom, keyChar);
keyElement->GetAttribute(shiftAtom, shiftValue);
keyElement->GetAttribute(altAtom, altValue);
keyElement->GetAttribute(commandAtom, commandValue);
keyElement->GetAttribute(keyAtom, keyChar);
keyElement->GetAttribute(shiftAtom, shiftValue);
keyElement->GetAttribute(altAtom, altValue);
keyElement->GetAttribute(commandAtom, commandValue);
keyElement->GetAttribute(controlAtom, controlValue);
nsAutoString xulkey;
keyElement->GetAttribute(NS_ConvertASCIItoUCS2("xulkey"), xulkey);
if (xulkey.EqualsWithConversion("true")) {
// Set the default for the xul key modifier
#ifdef XP_MAC
commandValue.AssignWithConversion("true");
#elif defined(XP_PC) || defined(NTO)
controlValue.AssignWithConversion("true");
#else
altValue.AssignWithConversion("true");
#endif
}
PRInt32 accelKey = 0;
PRBool prependPlus = PR_FALSE;
if(!commandValue.IsEmpty() && !commandValue.EqualsWithConversion("false")) {
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Ctrl"); // Hmmm. Kinda defeats the point of having an abstraction.
nsAutoString xulkey;
keyElement->GetAttribute(NS_ConvertASCIItoUCS2("xulkey"), xulkey);
if (xulkey.EqualsWithConversion("true"))
{
// Compiled-in defaults, in case we can't get LookAndFeel --
// command for mac, control for all other platforms.
#ifdef XP_MAC
accelKey = nsIDOMKeyEvent::DOM_VK_META;
#else
accelKey = nsIDOMKeyEvent::DOM_VK_CONTROL;
#endif
// Get the accelerator key value from prefs, overriding the default:
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
rv = prefs->GetIntPref("ui.key.acceleratorKey", &accelKey);
}
#ifdef DEBUG_akkana
else
{
NS_ASSERTION(PR_FALSE,"Menu couldn't get accel key from prefs!\n");
}
#endif
switch (accelKey)
{
case nsIDOMKeyEvent::DOM_VK_META:
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Ctrl"); // Hmmm. Kinda defeats the point of having an abstraction.
break;
case nsIDOMKeyEvent::DOM_VK_ALT:
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Alt");
break;
case nsIDOMKeyEvent::DOM_VK_CONTROL:
default:
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Ctrl");
break;
}
}
if(!controlValue.IsEmpty() && !controlValue.EqualsWithConversion("false")) {
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Ctrl");
}
if(!shiftValue.IsEmpty() && !shiftValue.EqualsWithConversion("false")) {
if (!shiftValue.IsEmpty() && !shiftValue.EqualsWithConversion("false")) {
if (prependPlus)
aAccelString.AppendWithConversion("+");
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Shift");
}
if (!altValue.IsEmpty() && !altValue.EqualsWithConversion("false")) {
if (prependPlus)
aAccelString.AppendWithConversion("+");
prependPlus = PR_TRUE;
aAccelString.AppendWithConversion("Alt");
}
keyChar.ToUpperCase();
if (!keyChar.IsEmpty()) {
if (prependPlus)

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

@ -133,10 +133,9 @@ nsTextBoxFrame::Init(nsIPresContext* aPresContext,
UpdateAttributes(aPresContext, nsnull, a, b, c /* all */);
// the following block is to append the accesskey to to mTitle if there is an accesskey
// but the mTitle doesn't have the character
// but the mTitle doesn't have the character
// XXX Should this code first check to see if there's a menuAccessKey?
#ifndef XP_UNIX
nsAutoString accesskey;
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey,
accesskey);
@ -163,7 +162,6 @@ nsTextBoxFrame::Init(nsIPresContext* aPresContext,
mAccessKeyInfo = nsnull;
}
}
#endif
return rv;
}

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

@ -305,9 +305,9 @@ nsTitledButtonFrame::Init(nsIPresContext* aPresContext,
// the following block is to append the accesskey to to mTitle if there is an accesskey
// but the mTitle doesn't have the character
// XXX Should this code first check to see if there's a menuAccessKey?
mAccesskeyIndex = -1;
#ifndef XP_UNIX
nsAutoString accesskey;
mContent->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey,
accesskey);
@ -325,7 +325,6 @@ nsTitledButtonFrame::Init(nsIPresContext* aPresContext,
mTitle += tmpstring;
}
}
#endif
return rv;
}

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

@ -414,6 +414,11 @@ pref("signed.applets.codebase_principal_support", false);
pref("security.checkloaduri", true);
pref("security.xpconnect.plugin.unrestricted", true);
// Modifier key prefs: default to Windows settings,
// menu access key = alt, accelerator key = control.
pref("ui.key.acceleratorKey", 17);
pref("ui.key.menuAccessKey", 18);
// Middle-mouse handling
pref("middlemouse.paste", false);
pref("middlemouse.openNewWindow", false);

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

@ -138,6 +138,9 @@ pref("font.name.monospace.zh-TW", "Apple LiGothic Medium");
pref("font.name.cursive.zh-TW", "XXX.cursive");
pref("font.name.fantasy.zh-TW", "XXX.fantasy");
// Override the Windows settings: no menu key, meta accelerator key.
pref("ui.key.menuAccessKey", 0);
pref("ui.key.acceleratorKey", 224);
// This overrides the setting in config.js (which points to the Windows page)
config("menu.help.item_0.label","Help Contents");

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
@ -63,6 +63,8 @@
#include "nsIDocumentViewer.h"
#include "nsIPresContext.h"
#include "nsIDOMEventTarget.h"
#include "nsIPref.h"
#include "nsIServiceManager.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
@ -196,6 +198,8 @@ static NS_DEFINE_IID(kIDomNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDomElementIID, NS_IDOMELEMENT_IID);
static NS_DEFINE_IID(kIDomEventListenerIID, NS_IDOMEVENTLISTENER_IID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
enum eEventType {
eKeyPress,
eKeyDown,
@ -308,10 +312,9 @@ private:
static nsSupportsHashtable* mKeyBindingTable;
// The "xul key" modifier can be any of the known modifiers:
enum {
xulKeyNone, xulKeyShift, xulKeyControl, xulKeyAlt, xulKeyMeta
} mXULKeyModifier;
// The "xul key" modifier is a key code from nsIDOMKeyEvent,
// e.g. nsIDOMKeyEvent::DOM_VK_CONTROL
PRUint32 mXULKeyModifier;
};
nsSupportsHashtable* nsXULKeyListenerImpl::mKeyBindingTable = nsnull;
@ -461,14 +464,29 @@ nsXULKeyListenerImpl::Init(
mDOMDocument = xulDoc; // Weak reference.
// Set the default for the xul key modifier
// Compiled-in defaults, in case we can't get LookAndFeel --
// command for mac, control for all other platforms.
#ifdef XP_MAC
mXULKeyModifier = xulKeyMeta;
#elif XP_UNIX
mXULKeyModifier = xulKeyAlt;
mXULKeyModifier = nsIDOMKeyEvent::DOM_VK_META;
#else
mXULKeyModifier = xulKeyControl;
mXULKeyModifier = nsIDOMKeyEvent::DOM_VK_CONTROL;
#endif
// Get the accelerator key value from prefs, overriding the default:
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_PROGID, &rv);
if (NS_SUCCEEDED(rv) && prefs)
{
rv = prefs->GetIntPref("ui.key.acceleratorKey",
(PRInt32*)&mXULKeyModifier);
}
#ifdef DEBUG_akkana
else
{
NS_ASSERTION(PR_FALSE, "XULKeyListener couldn't get accel key from prefs!\n");
}
#endif
return NS_OK;
}
@ -1478,7 +1496,7 @@ nsXULKeyListenerImpl::HandleEventUsingKeyset(nsIDOMElement* aKeysetElement, nsID
|| (property == falseString && isModKey))
break;
// and also the xul key, if it's specified to be shift:
if (xulKeyShift == mXULKeyModifier &&
if (nsIDOMKeyEvent::DOM_VK_SHIFT == mXULKeyModifier &&
((xproperty == trueString && !isModKey)
|| (xproperty == falseString && isModKey)))
break;
@ -1491,7 +1509,7 @@ nsXULKeyListenerImpl::HandleEventUsingKeyset(nsIDOMElement* aKeysetElement, nsID
|| (property == falseString && isModKey))
break;
// and if xul is control:
if (xulKeyControl == mXULKeyModifier &&
if (nsIDOMKeyEvent::DOM_VK_CONTROL == mXULKeyModifier &&
((xproperty == trueString && !isModKey)
|| (xproperty == falseString && isModKey)))
break;
@ -1504,7 +1522,7 @@ nsXULKeyListenerImpl::HandleEventUsingKeyset(nsIDOMElement* aKeysetElement, nsID
|| (property == falseString && isModKey))
break;
// and if xul is alt:
if (xulKeyAlt == mXULKeyModifier &&
if (nsIDOMKeyEvent::DOM_VK_ALT == mXULKeyModifier &&
((xproperty == trueString && !isModKey)
|| (xproperty == falseString && isModKey)))
break;
@ -1517,7 +1535,7 @@ nsXULKeyListenerImpl::HandleEventUsingKeyset(nsIDOMElement* aKeysetElement, nsID
|| (property == falseString && isModKey))
break;
// and if xul is meta:
if (xulKeyMeta == mXULKeyModifier &&
if (nsIDOMKeyEvent::DOM_VK_META == mXULKeyModifier &&
((xproperty == trueString && !isModKey)
|| (xproperty == falseString && isModKey)))
break;

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

@ -601,6 +601,8 @@ enum nsDragDropEventStatus {
#define NS_VK_CLOSE_BRACKET 0xDD
#define NS_VK_QUOTE 0xDE
#define NS_VK_META 0xE0
#define NS_EVENT_FLAG_NONE 0x0000
#define NS_EVENT_FLAG_INIT 0x0001
#define NS_EVENT_FLAG_BUBBLE 0x0002