зеркало из https://github.com/mozilla/gecko-dev.git
Bug 602787 part.9 Don't implement methods which need BasicEvents.h or TextEvents.h in windows/KeyboardLayout.h r=jimm
This commit is contained in:
Родитель
8086dafaf2
Коммит
1aaa1d8c9f
|
@ -95,6 +95,38 @@ public:
|
||||||
* mozilla::widget::ModifierKeyState
|
* mozilla::widget::ModifierKeyState
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
ModifierKeyState::ModifierKeyState()
|
||||||
|
{
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
ModifierKeyState::ModifierKeyState(bool aIsShiftDown,
|
||||||
|
bool aIsControlDown,
|
||||||
|
bool aIsAltDown)
|
||||||
|
{
|
||||||
|
Update();
|
||||||
|
Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_ALTGRAPH);
|
||||||
|
Modifiers modifiers = 0;
|
||||||
|
if (aIsShiftDown) {
|
||||||
|
modifiers |= MODIFIER_SHIFT;
|
||||||
|
}
|
||||||
|
if (aIsControlDown) {
|
||||||
|
modifiers |= MODIFIER_CONTROL;
|
||||||
|
}
|
||||||
|
if (aIsAltDown) {
|
||||||
|
modifiers |= MODIFIER_ALT;
|
||||||
|
}
|
||||||
|
if (modifiers) {
|
||||||
|
Set(modifiers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ModifierKeyState::ModifierKeyState(Modifiers aModifiers) :
|
||||||
|
mModifiers(aModifiers)
|
||||||
|
{
|
||||||
|
EnsureAltGr();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModifierKeyState::Update()
|
ModifierKeyState::Update()
|
||||||
{
|
{
|
||||||
|
@ -124,6 +156,22 @@ ModifierKeyState::Update()
|
||||||
EnsureAltGr();
|
EnsureAltGr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModifierKeyState::Unset(Modifiers aRemovingModifiers)
|
||||||
|
{
|
||||||
|
mModifiers &= ~aRemovingModifiers;
|
||||||
|
// Note that we don't need to unset AltGr flag here automatically.
|
||||||
|
// For nsEditor, we need to remove Alt and Control flags but AltGr isn't
|
||||||
|
// checked in nsEditor, so, it can be kept.
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModifierKeyState::Set(Modifiers aAddingModifiers)
|
||||||
|
{
|
||||||
|
mModifiers |= aAddingModifiers;
|
||||||
|
EnsureAltGr();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModifierKeyState::InitInputEvent(WidgetInputEvent& aInputEvent) const
|
ModifierKeyState::InitInputEvent(WidgetInputEvent& aInputEvent) const
|
||||||
{
|
{
|
||||||
|
@ -170,6 +218,72 @@ ModifierKeyState::InitMouseEvent(WidgetInputEvent& aMouseEvent) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsShift() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_SHIFT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsControl() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_CONTROL) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsAlt() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_ALT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsAltGr() const
|
||||||
|
{
|
||||||
|
return IsControl() && IsAlt();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsWin() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_OS) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsCapsLocked() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_CAPSLOCK) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsNumLocked() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_NUMLOCK) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ModifierKeyState::IsScrollLocked() const
|
||||||
|
{
|
||||||
|
return (mModifiers & MODIFIER_SCROLLLOCK) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Modifiers
|
||||||
|
ModifierKeyState::GetModifiers() const
|
||||||
|
{
|
||||||
|
return mModifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ModifierKeyState::EnsureAltGr()
|
||||||
|
{
|
||||||
|
// If both Control key and Alt key are pressed, it means AltGr is pressed.
|
||||||
|
// Ideally, we should check whether the current keyboard layout has AltGr
|
||||||
|
// or not. However, setting AltGr flags for keyboard which doesn't have
|
||||||
|
// AltGr must not be serious bug. So, it should be OK for now.
|
||||||
|
if (IsAltGr()) {
|
||||||
|
mModifiers |= MODIFIER_ALTGRAPH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* mozilla::widget::UniCharsAndModifiers
|
* mozilla::widget::UniCharsAndModifiers
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
@ -236,6 +350,50 @@ UniCharsAndModifiers::operator+(const UniCharsAndModifiers& aOther) const
|
||||||
* mozilla::widget::VirtualKey
|
* mozilla::widget::VirtualKey
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
|
// static
|
||||||
|
VirtualKey::ShiftState
|
||||||
|
VirtualKey::ModifiersToShiftState(Modifiers aModifiers)
|
||||||
|
{
|
||||||
|
ShiftState state = 0;
|
||||||
|
if (aModifiers & MODIFIER_SHIFT) {
|
||||||
|
state |= STATE_SHIFT;
|
||||||
|
}
|
||||||
|
if (aModifiers & MODIFIER_CONTROL) {
|
||||||
|
state |= STATE_CONTROL;
|
||||||
|
}
|
||||||
|
if (aModifiers & MODIFIER_ALT) {
|
||||||
|
state |= STATE_ALT;
|
||||||
|
}
|
||||||
|
if (aModifiers & MODIFIER_CAPSLOCK) {
|
||||||
|
state |= STATE_CAPSLOCK;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
Modifiers
|
||||||
|
VirtualKey::ShiftStateToModifiers(ShiftState aShiftState)
|
||||||
|
{
|
||||||
|
Modifiers modifiers = 0;
|
||||||
|
if (aShiftState & STATE_SHIFT) {
|
||||||
|
modifiers |= MODIFIER_SHIFT;
|
||||||
|
}
|
||||||
|
if (aShiftState & STATE_CONTROL) {
|
||||||
|
modifiers |= MODIFIER_CONTROL;
|
||||||
|
}
|
||||||
|
if (aShiftState & STATE_ALT) {
|
||||||
|
modifiers |= MODIFIER_ALT;
|
||||||
|
}
|
||||||
|
if (aShiftState & STATE_CAPSLOCK) {
|
||||||
|
modifiers |= MODIFIER_CAPSLOCK;
|
||||||
|
}
|
||||||
|
if ((modifiers & (MODIFIER_ALT | MODIFIER_CONTROL)) ==
|
||||||
|
(MODIFIER_ALT | MODIFIER_CONTROL)) {
|
||||||
|
modifiers |= MODIFIER_ALTGRAPH;
|
||||||
|
}
|
||||||
|
return modifiers;
|
||||||
|
}
|
||||||
|
|
||||||
inline PRUnichar
|
inline PRUnichar
|
||||||
VirtualKey::GetCompositeChar(ShiftState aShiftState, PRUnichar aBaseChar) const
|
VirtualKey::GetCompositeChar(ShiftState aShiftState, PRUnichar aBaseChar) const
|
||||||
{
|
{
|
||||||
|
@ -752,6 +910,12 @@ NativeKey::ComputeUnicharFromScanCode() const
|
||||||
MAPVK_VK_TO_CHAR, mKeyboardLayout));
|
MAPVK_VK_TO_CHAR, mKeyboardLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const
|
||||||
|
{
|
||||||
|
InitKeyEvent(aKeyEvent, mModKeyState);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
||||||
const ModifierKeyState& aModKeyState) const
|
const ModifierKeyState& aModKeyState) const
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsWindowBase.h"
|
#include "nsWindowBase.h"
|
||||||
#include "nsWindowDefs.h"
|
#include "nsWindowDefs.h"
|
||||||
#include "mozilla/BasicEvents.h"
|
#include "mozilla/Attributes.h"
|
||||||
|
#include "mozilla/EventForwards.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#define NS_NUM_OF_KEYS 70
|
#define NS_NUM_OF_KEYS 70
|
||||||
|
@ -54,84 +55,36 @@ static const uint32_t sModifierKeyMap[][3] = {
|
||||||
|
|
||||||
class KeyboardLayout;
|
class KeyboardLayout;
|
||||||
|
|
||||||
class ModifierKeyState {
|
class ModifierKeyState
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ModifierKeyState()
|
ModifierKeyState();
|
||||||
{
|
ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown);
|
||||||
Update();
|
ModifierKeyState(Modifiers aModifiers);
|
||||||
}
|
|
||||||
|
|
||||||
ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown)
|
MOZ_ALWAYS_INLINE void Update();
|
||||||
{
|
|
||||||
Update();
|
|
||||||
Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_ALTGRAPH);
|
|
||||||
Modifiers modifiers = 0;
|
|
||||||
if (aIsShiftDown) {
|
|
||||||
modifiers |= MODIFIER_SHIFT;
|
|
||||||
}
|
|
||||||
if (aIsControlDown) {
|
|
||||||
modifiers |= MODIFIER_CONTROL;
|
|
||||||
}
|
|
||||||
if (aIsAltDown) {
|
|
||||||
modifiers |= MODIFIER_ALT;
|
|
||||||
}
|
|
||||||
if (modifiers) {
|
|
||||||
Set(modifiers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ModifierKeyState(Modifiers aModifiers) :
|
MOZ_ALWAYS_INLINE void Unset(Modifiers aRemovingModifiers);
|
||||||
mModifiers(aModifiers)
|
MOZ_ALWAYS_INLINE void Set(Modifiers aAddingModifiers);
|
||||||
{
|
|
||||||
EnsureAltGr();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Update();
|
|
||||||
|
|
||||||
void Unset(Modifiers aRemovingModifiers)
|
|
||||||
{
|
|
||||||
mModifiers &= ~aRemovingModifiers;
|
|
||||||
// Note that we don't need to unset AltGr flag here automatically.
|
|
||||||
// For nsEditor, we need to remove Alt and Control flags but AltGr isn't
|
|
||||||
// checked in nsEditor, so, it can be kept.
|
|
||||||
}
|
|
||||||
|
|
||||||
void Set(Modifiers aAddingModifiers)
|
|
||||||
{
|
|
||||||
mModifiers |= aAddingModifiers;
|
|
||||||
EnsureAltGr();
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitInputEvent(WidgetInputEvent& aInputEvent) const;
|
void InitInputEvent(WidgetInputEvent& aInputEvent) const;
|
||||||
|
|
||||||
bool IsShift() const { return (mModifiers & MODIFIER_SHIFT) != 0; }
|
MOZ_ALWAYS_INLINE bool IsShift() const;
|
||||||
bool IsControl() const { return (mModifiers & MODIFIER_CONTROL) != 0; }
|
MOZ_ALWAYS_INLINE bool IsControl() const;
|
||||||
bool IsAlt() const { return (mModifiers & MODIFIER_ALT) != 0; }
|
MOZ_ALWAYS_INLINE bool IsAlt() const;
|
||||||
bool IsAltGr() const { return IsControl() && IsAlt(); }
|
MOZ_ALWAYS_INLINE bool IsAltGr() const;
|
||||||
bool IsWin() const { return (mModifiers & MODIFIER_OS) != 0; }
|
MOZ_ALWAYS_INLINE bool IsWin() const;
|
||||||
|
|
||||||
bool IsCapsLocked() const { return (mModifiers & MODIFIER_CAPSLOCK) != 0; }
|
MOZ_ALWAYS_INLINE bool IsCapsLocked() const;
|
||||||
bool IsNumLocked() const { return (mModifiers & MODIFIER_NUMLOCK) != 0; }
|
MOZ_ALWAYS_INLINE bool IsNumLocked() const;
|
||||||
bool IsScrollLocked() const
|
MOZ_ALWAYS_INLINE bool IsScrollLocked() const;
|
||||||
{
|
|
||||||
return (mModifiers & MODIFIER_SCROLLLOCK) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Modifiers GetModifiers() const { return mModifiers; }
|
MOZ_ALWAYS_INLINE Modifiers GetModifiers() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Modifiers mModifiers;
|
Modifiers mModifiers;
|
||||||
|
|
||||||
void EnsureAltGr()
|
MOZ_ALWAYS_INLINE void EnsureAltGr();
|
||||||
{
|
|
||||||
// If both Control key and Alt key are pressed, it means AltGr is pressed.
|
|
||||||
// Ideally, we should check whether the current keyboard layout has AltGr
|
|
||||||
// or not. However, setting AltGr flags for keyboard which doesn't have
|
|
||||||
// AltGr must not be serious bug. So, it should be OK for now.
|
|
||||||
if (IsAltGr()) {
|
|
||||||
mModifiers |= MODIFIER_ALTGRAPH;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitMouseEvent(WidgetInputEvent& aMouseEvent) const;
|
void InitMouseEvent(WidgetInputEvent& aMouseEvent) const;
|
||||||
};
|
};
|
||||||
|
@ -196,45 +149,8 @@ public:
|
||||||
|
|
||||||
typedef uint8_t ShiftState;
|
typedef uint8_t ShiftState;
|
||||||
|
|
||||||
static ShiftState ModifiersToShiftState(Modifiers aModifiers)
|
static ShiftState ModifiersToShiftState(Modifiers aModifiers);
|
||||||
{
|
static Modifiers ShiftStateToModifiers(ShiftState aShiftState);
|
||||||
ShiftState state = 0;
|
|
||||||
if (aModifiers & MODIFIER_SHIFT) {
|
|
||||||
state |= STATE_SHIFT;
|
|
||||||
}
|
|
||||||
if (aModifiers & MODIFIER_CONTROL) {
|
|
||||||
state |= STATE_CONTROL;
|
|
||||||
}
|
|
||||||
if (aModifiers & MODIFIER_ALT) {
|
|
||||||
state |= STATE_ALT;
|
|
||||||
}
|
|
||||||
if (aModifiers & MODIFIER_CAPSLOCK) {
|
|
||||||
state |= STATE_CAPSLOCK;
|
|
||||||
}
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Modifiers ShiftStateToModifiers(ShiftState aShiftState)
|
|
||||||
{
|
|
||||||
Modifiers modifiers = 0;
|
|
||||||
if (aShiftState & STATE_SHIFT) {
|
|
||||||
modifiers |= MODIFIER_SHIFT;
|
|
||||||
}
|
|
||||||
if (aShiftState & STATE_CONTROL) {
|
|
||||||
modifiers |= MODIFIER_CONTROL;
|
|
||||||
}
|
|
||||||
if (aShiftState & STATE_ALT) {
|
|
||||||
modifiers |= MODIFIER_ALT;
|
|
||||||
}
|
|
||||||
if (aShiftState & STATE_CAPSLOCK) {
|
|
||||||
modifiers |= MODIFIER_CAPSLOCK;
|
|
||||||
}
|
|
||||||
if ((modifiers & (MODIFIER_ALT | MODIFIER_CONTROL)) ==
|
|
||||||
(MODIFIER_ALT | MODIFIER_CONTROL)) {
|
|
||||||
modifiers |= MODIFIER_ALTGRAPH;
|
|
||||||
}
|
|
||||||
return modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
union KeyShiftState
|
union KeyShiftState
|
||||||
|
@ -428,10 +344,7 @@ private:
|
||||||
*/
|
*/
|
||||||
void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
|
||||||
const ModifierKeyState& aModKeyState) const;
|
const ModifierKeyState& aModKeyState) const;
|
||||||
void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const
|
void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const;
|
||||||
{
|
|
||||||
InitKeyEvent(aKeyEvent, mModKeyState);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatches the key event. Returns true if the event is consumed.
|
* Dispatches the key event. Returns true if the event is consumed.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче