mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1009388 part.4 nsMenuFrame should use WidgetEvent::AccelModifier() for consistency with other modules r=smaug+enndeakin
This commit is contained in:
parent
b2db399fcc
commit
ad939f2f11
@ -18,6 +18,7 @@
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/BasicEvents.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/TextEvents.h"
|
||||
|
||||
@ -29,16 +30,10 @@ using namespace mozilla;
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMenuBarListener, nsIDOMEventListener)
|
||||
|
||||
#define MODIFIER_SHIFT 1
|
||||
#define MODIFIER_CONTROL 2
|
||||
#define MODIFIER_ALT 4
|
||||
#define MODIFIER_META 8
|
||||
#define MODIFIER_OS 16
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int32_t nsMenuBarListener::mAccessKey = -1;
|
||||
uint32_t nsMenuBarListener::mAccessKeyMask = 0;
|
||||
Modifiers nsMenuBarListener::mAccessKeyMask = 0;
|
||||
bool nsMenuBarListener::mAccessKeyFocuses = false;
|
||||
|
||||
nsMenuBarListener::nsMenuBarListener(nsMenuBarFrame* aMenuBar)
|
||||
@ -238,7 +233,7 @@ nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
||||
#ifndef XP_MACOSX
|
||||
// Also need to handle F10 specially on Non-Mac platform.
|
||||
else if (keyCode == NS_VK_F10) {
|
||||
if ((GetModifiers(keyEvent) & ~MODIFIER_CONTROL) == 0) {
|
||||
if ((GetModifiersForAccessKey(keyEvent) & ~MODIFIER_CONTROL) == 0) {
|
||||
// The F10 key just went down by itself or with ctrl pressed.
|
||||
// In Windows, both of these activate the menu bar.
|
||||
mMenuBarFrame->SetActiveByKeyboard();
|
||||
@ -267,42 +262,24 @@ nsMenuBarListener::IsAccessKeyPressed(nsIDOMKeyEvent* aKeyEvent)
|
||||
{
|
||||
InitAccessKey();
|
||||
// No other modifiers are allowed to be down except for Shift.
|
||||
uint32_t modifiers = GetModifiers(aKeyEvent);
|
||||
uint32_t modifiers = GetModifiersForAccessKey(aKeyEvent);
|
||||
|
||||
return (mAccessKeyMask != MODIFIER_SHIFT &&
|
||||
(modifiers & mAccessKeyMask) &&
|
||||
(modifiers & ~(mAccessKeyMask | MODIFIER_SHIFT)) == 0);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
nsMenuBarListener::GetModifiers(nsIDOMKeyEvent* aKeyEvent)
|
||||
Modifiers
|
||||
nsMenuBarListener::GetModifiersForAccessKey(nsIDOMKeyEvent* aKeyEvent)
|
||||
{
|
||||
uint32_t modifiers = 0;
|
||||
WidgetInputEvent* inputEvent =
|
||||
aKeyEvent->GetInternalNSEvent()->AsInputEvent();
|
||||
MOZ_ASSERT(inputEvent);
|
||||
|
||||
if (inputEvent->IsShift()) {
|
||||
modifiers |= MODIFIER_SHIFT;
|
||||
}
|
||||
|
||||
if (inputEvent->IsControl()) {
|
||||
modifiers |= MODIFIER_CONTROL;
|
||||
}
|
||||
|
||||
if (inputEvent->IsAlt()) {
|
||||
modifiers |= MODIFIER_ALT;
|
||||
}
|
||||
|
||||
if (inputEvent->IsMeta()) {
|
||||
modifiers |= MODIFIER_META;
|
||||
}
|
||||
|
||||
if (inputEvent->IsOS()) {
|
||||
modifiers |= MODIFIER_OS;
|
||||
}
|
||||
|
||||
return modifiers;
|
||||
static const Modifiers kPossibleModifiersForAccessKey =
|
||||
(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META |
|
||||
MODIFIER_OS);
|
||||
return (inputEvent->modifiers & kPossibleModifiersForAccessKey);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@ -334,7 +311,7 @@ nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
||||
// enhanced 102-key keyboards if we don't check this.
|
||||
bool isAccessKeyDownEvent =
|
||||
((theChar == (uint32_t)mAccessKey) &&
|
||||
(GetModifiers(keyEvent) & ~mAccessKeyMask) == 0);
|
||||
(GetModifiersForAccessKey(keyEvent) & ~mAccessKeyMask) == 0);
|
||||
|
||||
if (!mAccessKeyDown) {
|
||||
// If accesskey isn't being pressed and the key isn't the accesskey,
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define nsMenuBarListener_h__
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
// X.h defines KeyPress
|
||||
@ -47,7 +48,7 @@ public:
|
||||
protected:
|
||||
static void InitAccessKey();
|
||||
|
||||
static uint32_t GetModifiers(nsIDOMKeyEvent* event);
|
||||
static mozilla::Modifiers GetModifiersForAccessKey(nsIDOMKeyEvent* event);
|
||||
|
||||
// This should only be called by the nsMenuBarListener during event dispatch,
|
||||
// thus ensuring that this doesn't get destroyed during the process.
|
||||
@ -60,7 +61,7 @@ protected:
|
||||
bool mAccessKeyDownCanceled;
|
||||
static bool mAccessKeyFocuses; // Does the access key by itself focus the menubar?
|
||||
static int32_t mAccessKey; // See nsIDOMKeyEvent.h for sample values
|
||||
static uint32_t mAccessKeyMask;// Modifier mask for the access key
|
||||
static mozilla::Modifiers mAccessKeyMask;// Modifier mask for the access key
|
||||
};
|
||||
|
||||
|
||||
|
@ -1088,22 +1088,6 @@ nsMenuFrame::BuildAcceleratorText(bool aNotify)
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t accelKey = 0;
|
||||
|
||||
if (!accelKey)
|
||||
{
|
||||
// Compiled-in defaults, in case we can't get LookAndFeel --
|
||||
// command for mac, control for all other platforms.
|
||||
#ifdef XP_MACOSX
|
||||
accelKey = nsIDOMKeyEvent::DOM_VK_META;
|
||||
#else
|
||||
accelKey = nsIDOMKeyEvent::DOM_VK_CONTROL;
|
||||
#endif
|
||||
|
||||
// Get the accelerator key value from prefs, overriding the default:
|
||||
accelKey = Preferences::GetInt("ui.key.accelKey", accelKey);
|
||||
}
|
||||
|
||||
nsAutoString modifiers;
|
||||
keyElement->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiers);
|
||||
|
||||
@ -1138,24 +1122,23 @@ nsMenuFrame::BuildAcceleratorText(bool aNotify)
|
||||
else if (PL_strcmp(token, "control") == 0)
|
||||
accelText += controlText;
|
||||
else if (PL_strcmp(token, "accel") == 0) {
|
||||
switch (accelKey)
|
||||
{
|
||||
case nsIDOMKeyEvent::DOM_VK_META:
|
||||
switch (WidgetInputEvent::AccelModifier()) {
|
||||
case MODIFIER_META:
|
||||
accelText += metaText;
|
||||
break;
|
||||
|
||||
case nsIDOMKeyEvent::DOM_VK_WIN:
|
||||
case MODIFIER_OS:
|
||||
accelText += osText;
|
||||
break;
|
||||
|
||||
case nsIDOMKeyEvent::DOM_VK_ALT:
|
||||
case MODIFIER_ALT:
|
||||
accelText += altText;
|
||||
break;
|
||||
|
||||
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
||||
default:
|
||||
case MODIFIER_CONTROL:
|
||||
accelText += controlText;
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH(
|
||||
"Handle the new result of WidgetInputEvent::AccelModifier()");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user