2013-09-24 10:04:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-09-20 02:22:26 +00:00
|
|
|
#include "gfxPrefs.h"
|
2013-09-24 10:04:16 +00:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2013-10-18 06:10:20 +00:00
|
|
|
#include "mozilla/ContentEvents.h"
|
2014-02-27 10:51:15 +00:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2013-09-24 10:04:16 +00:00
|
|
|
#include "mozilla/MiscEvents.h"
|
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-05-22 04:06:05 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-10-18 06:10:20 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
#include "mozilla/TouchEvents.h"
|
Bug 1297013 part.2 Implement some helper methods to log constants related to event handling r=smaug
This patch implements some helper methods to log constants related to event handling.
ToString(KeyNameIndex) and ToString(CodeNameIndex) converts the enum itmes to human readable string. They use WidgetKeyboardEvent's helper class which returns Unicode text. Therefore, this need to convert from UTF16 to UTF8. That's the reason why these methods don't return |const char*|.
GetDOMKeyCodeName(uint32_t) returns DOM keycode name if it's defined. Otherwise, returns hexadecimal value. For generating switch-case statement, VirtualKeyCodeList.h shouldn't include ",". Therefore, this patch removes "," from VirtualKeyCodeList.h and append it at defining NS_DEFINE_VK. Additionally, the last item of enum and array should not end with ",". Therefore, this adds dummy last item at each of them. Finally, some of the keyCode values are shared between 2 keys. Therefore, it needs to support NS_DISALLOW_SAME_KEYCODE for switch-case generator. See the comment in the file for more detail.
GetModifiersName(Modifiers) returns all modifier names included in the given value.
MozReview-Commit-ID: 9i2ftFOTpDn
--HG--
extra : rebase_source : 458a4d28624dc10dd4454f2e7708d746d1fcb045
2016-09-14 15:48:47 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2013-09-24 10:04:16 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-09-17 03:05:44 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* Global helper methods
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ToChar(EventMessage aEventMessage)
|
|
|
|
{
|
|
|
|
switch (aEventMessage) {
|
|
|
|
|
|
|
|
#define NS_EVENT_MESSAGE(aMessage) \
|
|
|
|
case aMessage: \
|
|
|
|
return #aMessage;
|
|
|
|
|
|
|
|
#include "mozilla/EventMessageList.h"
|
|
|
|
|
|
|
|
#undef NS_EVENT_MESSAGE
|
|
|
|
default:
|
|
|
|
return "illegal event message";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ToChar(EventClassID aEventClassID)
|
|
|
|
{
|
|
|
|
switch (aEventClassID) {
|
|
|
|
|
|
|
|
#define NS_ROOT_EVENT_CLASS(aPrefix, aName) \
|
|
|
|
case eBasic##aName##Class: \
|
|
|
|
return "eBasic" #aName "Class";
|
|
|
|
|
|
|
|
#define NS_EVENT_CLASS(aPrefix, aName) \
|
|
|
|
case e##aName##Class: \
|
|
|
|
return "e" #aName "Class";
|
|
|
|
|
|
|
|
#include "mozilla/EventClassList.h"
|
|
|
|
|
|
|
|
#undef NS_EVENT_CLASS
|
|
|
|
#undef NS_ROOT_EVENT_CLASS
|
|
|
|
default:
|
|
|
|
return "illegal event class ID";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1297013 part.2 Implement some helper methods to log constants related to event handling r=smaug
This patch implements some helper methods to log constants related to event handling.
ToString(KeyNameIndex) and ToString(CodeNameIndex) converts the enum itmes to human readable string. They use WidgetKeyboardEvent's helper class which returns Unicode text. Therefore, this need to convert from UTF16 to UTF8. That's the reason why these methods don't return |const char*|.
GetDOMKeyCodeName(uint32_t) returns DOM keycode name if it's defined. Otherwise, returns hexadecimal value. For generating switch-case statement, VirtualKeyCodeList.h shouldn't include ",". Therefore, this patch removes "," from VirtualKeyCodeList.h and append it at defining NS_DEFINE_VK. Additionally, the last item of enum and array should not end with ",". Therefore, this adds dummy last item at each of them. Finally, some of the keyCode values are shared between 2 keys. Therefore, it needs to support NS_DISALLOW_SAME_KEYCODE for switch-case generator. See the comment in the file for more detail.
GetModifiersName(Modifiers) returns all modifier names included in the given value.
MozReview-Commit-ID: 9i2ftFOTpDn
--HG--
extra : rebase_source : 458a4d28624dc10dd4454f2e7708d746d1fcb045
2016-09-14 15:48:47 +00:00
|
|
|
const nsCString
|
|
|
|
ToString(KeyNameIndex aKeyNameIndex)
|
|
|
|
{
|
|
|
|
if (aKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
|
|
|
|
return NS_LITERAL_CSTRING("USE_STRING");
|
|
|
|
}
|
|
|
|
nsAutoString keyName;
|
|
|
|
WidgetKeyboardEvent::GetDOMKeyName(aKeyNameIndex, keyName);
|
|
|
|
return NS_ConvertUTF16toUTF8(keyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString
|
|
|
|
ToString(CodeNameIndex aCodeNameIndex)
|
|
|
|
{
|
|
|
|
if (aCodeNameIndex == CODE_NAME_INDEX_USE_STRING) {
|
|
|
|
return NS_LITERAL_CSTRING("USE_STRING");
|
|
|
|
}
|
|
|
|
nsAutoString codeName;
|
|
|
|
WidgetKeyboardEvent::GetDOMCodeName(aCodeNameIndex, codeName);
|
|
|
|
return NS_ConvertUTF16toUTF8(codeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString
|
|
|
|
GetDOMKeyCodeName(uint32_t aKeyCode)
|
|
|
|
{
|
|
|
|
switch (aKeyCode) {
|
|
|
|
#define NS_DISALLOW_SAME_KEYCODE
|
|
|
|
#define NS_DEFINE_VK(aDOMKeyName, aDOMKeyCode) \
|
|
|
|
case aDOMKeyCode: \
|
|
|
|
return NS_LITERAL_CSTRING(#aDOMKeyName);
|
|
|
|
|
|
|
|
#include "mozilla/VirtualKeyCodeList.h"
|
|
|
|
|
|
|
|
#undef NS_DEFINE_VK
|
|
|
|
#undef NS_DISALLOW_SAME_KEYCODE
|
|
|
|
|
|
|
|
default:
|
|
|
|
return nsPrintfCString("Invalid DOM keyCode (0x%08X)", aKeyCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-04 00:49:21 +00:00
|
|
|
bool
|
|
|
|
IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeType)
|
|
|
|
{
|
|
|
|
switch (static_cast<TextRangeType>(aRawTextRangeType)) {
|
2016-06-03 09:32:22 +00:00
|
|
|
case TextRangeType::eUninitialized:
|
2016-06-03 09:40:06 +00:00
|
|
|
case TextRangeType::eCaret:
|
2016-06-03 09:48:37 +00:00
|
|
|
case TextRangeType::eRawClause:
|
2016-06-03 09:57:21 +00:00
|
|
|
case TextRangeType::eSelectedRawClause:
|
2016-06-03 10:05:32 +00:00
|
|
|
case TextRangeType::eConvertedClause:
|
2016-06-03 10:15:21 +00:00
|
|
|
case TextRangeType::eSelectedClause:
|
2016-06-04 00:49:21 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RawTextRangeType
|
|
|
|
ToRawTextRangeType(TextRangeType aTextRangeType)
|
|
|
|
{
|
|
|
|
return static_cast<RawTextRangeType>(aTextRangeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextRangeType
|
|
|
|
ToTextRangeType(RawTextRangeType aRawTextRangeType)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsValidRawTextRangeValue(aRawTextRangeType));
|
|
|
|
return static_cast<TextRangeType>(aRawTextRangeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
ToChar(TextRangeType aTextRangeType)
|
|
|
|
{
|
|
|
|
switch (aTextRangeType) {
|
2016-06-03 09:32:22 +00:00
|
|
|
case TextRangeType::eUninitialized:
|
|
|
|
return "TextRangeType::eUninitialized";
|
2016-06-03 09:40:06 +00:00
|
|
|
case TextRangeType::eCaret:
|
|
|
|
return "TextRangeType::eCaret";
|
2016-06-03 09:48:37 +00:00
|
|
|
case TextRangeType::eRawClause:
|
|
|
|
return "TextRangeType::eRawClause";
|
2016-06-03 09:57:21 +00:00
|
|
|
case TextRangeType::eSelectedRawClause:
|
|
|
|
return "TextRangeType::eSelectedRawClause";
|
2016-06-03 10:05:32 +00:00
|
|
|
case TextRangeType::eConvertedClause:
|
|
|
|
return "TextRangeType::eConvertedClause";
|
2016-06-03 10:15:21 +00:00
|
|
|
case TextRangeType::eSelectedClause:
|
|
|
|
return "TextRangeType::eSelectedClause";
|
2016-06-04 00:49:21 +00:00
|
|
|
default:
|
|
|
|
return "Invalid TextRangeType";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-11 02:06:37 +00:00
|
|
|
SelectionType
|
|
|
|
ToSelectionType(TextRangeType aTextRangeType)
|
|
|
|
{
|
|
|
|
switch (aTextRangeType) {
|
|
|
|
case TextRangeType::eRawClause:
|
2016-06-09 09:51:49 +00:00
|
|
|
return SelectionType::eIMERawClause;
|
2016-06-11 02:06:37 +00:00
|
|
|
case TextRangeType::eSelectedRawClause:
|
2016-06-09 10:03:40 +00:00
|
|
|
return SelectionType::eIMESelectedRawClause;
|
2016-06-11 02:06:37 +00:00
|
|
|
case TextRangeType::eConvertedClause:
|
2016-06-09 10:14:17 +00:00
|
|
|
return SelectionType::eIMEConvertedClause;
|
2016-06-11 02:06:37 +00:00
|
|
|
case TextRangeType::eSelectedClause:
|
2016-06-09 10:29:29 +00:00
|
|
|
return SelectionType::eIMESelectedClause;
|
2016-06-11 02:06:37 +00:00
|
|
|
default:
|
|
|
|
MOZ_CRASH("TextRangeType is invalid");
|
2016-06-09 09:35:22 +00:00
|
|
|
return SelectionType::eNormal;
|
2016-06-11 02:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 06:10:20 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* As*Event() implementation
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#define NS_ROOT_EVENT_CLASS(aPrefix, aName)
|
|
|
|
#define NS_EVENT_CLASS(aPrefix, aName) \
|
|
|
|
aPrefix##aName* \
|
|
|
|
WidgetEvent::As##aName() \
|
|
|
|
{ \
|
|
|
|
return nullptr; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
const aPrefix##aName* \
|
|
|
|
WidgetEvent::As##aName() const \
|
|
|
|
{ \
|
|
|
|
return const_cast<WidgetEvent*>(this)->As##aName(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "mozilla/EventClassList.h"
|
|
|
|
|
|
|
|
#undef NS_EVENT_CLASS
|
|
|
|
#undef NS_ROOT_EVENT_CLASS
|
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetEvent
|
|
|
|
*
|
|
|
|
* Event struct type checking methods.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsQueryContentEvent() const
|
|
|
|
{
|
2014-08-04 05:28:49 +00:00
|
|
|
return mClass == eQueryContentEventClass;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsSelectionEvent() const
|
|
|
|
{
|
2014-08-04 05:28:49 +00:00
|
|
|
return mClass == eSelectionEventClass;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsContentCommandEvent() const
|
|
|
|
{
|
2014-08-04 05:28:56 +00:00
|
|
|
return mClass == eContentCommandEventClass;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsNativeEventDelivererForPlugin() const
|
|
|
|
{
|
2014-08-04 05:28:57 +00:00
|
|
|
return mClass == ePluginEventClass;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetEvent
|
|
|
|
*
|
|
|
|
* Event message checking methods.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::HasMouseEventMessage() const
|
|
|
|
{
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (mMessage) {
|
2015-08-28 23:58:30 +00:00
|
|
|
case eMouseDown:
|
2015-08-28 23:58:30 +00:00
|
|
|
case eMouseUp:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseClick:
|
2015-08-28 23:58:31 +00:00
|
|
|
case eMouseDoubleClick:
|
2015-08-28 23:58:31 +00:00
|
|
|
case eMouseEnterIntoWidget:
|
2015-08-28 23:58:31 +00:00
|
|
|
case eMouseExitFromWidget:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseActivate:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseOver:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseOut:
|
2015-08-28 23:58:32 +00:00
|
|
|
case eMouseHitTest:
|
2015-08-28 23:58:29 +00:00
|
|
|
case eMouseMove:
|
2013-09-24 10:04:16 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::HasDragEventMessage() const
|
|
|
|
{
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (mMessage) {
|
2015-09-02 06:08:02 +00:00
|
|
|
case eDragEnter:
|
2015-09-02 06:08:02 +00:00
|
|
|
case eDragOver:
|
2015-09-02 06:08:02 +00:00
|
|
|
case eDragExit:
|
2015-09-02 06:08:02 +00:00
|
|
|
case eDrag:
|
2015-09-02 06:08:02 +00:00
|
|
|
case eDragEnd:
|
2015-09-02 06:08:01 +00:00
|
|
|
case eDragStart:
|
2015-09-02 06:08:01 +00:00
|
|
|
case eDrop:
|
2015-09-02 06:08:01 +00:00
|
|
|
case eDragLeave:
|
2013-09-24 10:04:16 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::HasKeyEventMessage() const
|
|
|
|
{
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (mMessage) {
|
2015-08-28 23:58:27 +00:00
|
|
|
case eKeyDown:
|
2015-08-28 23:58:27 +00:00
|
|
|
case eKeyPress:
|
2015-08-28 23:58:27 +00:00
|
|
|
case eKeyUp:
|
2016-04-22 16:22:49 +00:00
|
|
|
case eKeyDownOnPlugin:
|
|
|
|
case eKeyUpOnPlugin:
|
2015-08-28 23:58:27 +00:00
|
|
|
case eBeforeKeyDown:
|
2015-08-28 23:58:28 +00:00
|
|
|
case eBeforeKeyUp:
|
2015-08-28 23:58:28 +00:00
|
|
|
case eAfterKeyDown:
|
2015-08-28 23:58:28 +00:00
|
|
|
case eAfterKeyUp:
|
2016-05-11 12:56:42 +00:00
|
|
|
case eAccessKeyNotFound:
|
2013-09-24 10:04:16 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::HasIMEEventMessage() const
|
|
|
|
{
|
2015-08-22 01:34:51 +00:00
|
|
|
switch (mMessage) {
|
2015-09-11 12:21:27 +00:00
|
|
|
case eCompositionStart:
|
2015-09-11 12:21:27 +00:00
|
|
|
case eCompositionEnd:
|
2015-09-11 12:21:27 +00:00
|
|
|
case eCompositionUpdate:
|
2015-09-11 12:21:27 +00:00
|
|
|
case eCompositionChange:
|
2015-09-11 12:21:26 +00:00
|
|
|
case eCompositionCommitAsIs:
|
2015-09-11 12:21:27 +00:00
|
|
|
case eCompositionCommit:
|
2013-09-24 10:04:16 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::HasPluginActivationEventMessage() const
|
|
|
|
{
|
2015-08-28 23:58:28 +00:00
|
|
|
return mMessage == ePluginActivate ||
|
2015-08-28 23:58:28 +00:00
|
|
|
mMessage == ePluginFocus;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetEvent
|
|
|
|
*
|
|
|
|
* Specific event checking methods.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsRetargetedNativeEventDelivererForPlugin() const
|
|
|
|
{
|
2013-10-18 06:10:20 +00:00
|
|
|
const WidgetPluginEvent* pluginEvent = AsPluginEvent();
|
2016-03-30 09:07:50 +00:00
|
|
|
return pluginEvent && pluginEvent->mRetargetToFocusedDocument;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsNonRetargetedNativeEventDelivererForPlugin() const
|
|
|
|
{
|
2013-10-18 06:10:20 +00:00
|
|
|
const WidgetPluginEvent* pluginEvent = AsPluginEvent();
|
2016-03-30 09:07:50 +00:00
|
|
|
return pluginEvent && !pluginEvent->mRetargetToFocusedDocument;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsIMERelatedEvent() const
|
|
|
|
{
|
|
|
|
return HasIMEEventMessage() || IsQueryContentEvent() || IsSelectionEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsUsingCoordinates() const
|
|
|
|
{
|
2013-10-28 09:03:19 +00:00
|
|
|
const WidgetMouseEvent* mouseEvent = AsMouseEvent();
|
|
|
|
if (mouseEvent) {
|
|
|
|
return !mouseEvent->IsContextMenuKeyEvent();
|
|
|
|
}
|
2013-09-24 10:04:16 +00:00
|
|
|
return !HasKeyEventMessage() && !IsIMERelatedEvent() &&
|
|
|
|
!HasPluginActivationEventMessage() &&
|
|
|
|
!IsNativeEventDelivererForPlugin() &&
|
2014-12-11 14:44:07 +00:00
|
|
|
!IsContentCommandEvent();
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsTargetedAtFocusedWindow() const
|
|
|
|
{
|
2013-10-28 09:03:19 +00:00
|
|
|
const WidgetMouseEvent* mouseEvent = AsMouseEvent();
|
|
|
|
if (mouseEvent) {
|
|
|
|
return mouseEvent->IsContextMenuKeyEvent();
|
|
|
|
}
|
2013-09-24 10:04:16 +00:00
|
|
|
return HasKeyEventMessage() || IsIMERelatedEvent() ||
|
|
|
|
IsContentCommandEvent() ||
|
|
|
|
IsRetargetedNativeEventDelivererForPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsTargetedAtFocusedContent() const
|
|
|
|
{
|
2013-10-28 09:03:19 +00:00
|
|
|
const WidgetMouseEvent* mouseEvent = AsMouseEvent();
|
|
|
|
if (mouseEvent) {
|
|
|
|
return mouseEvent->IsContextMenuKeyEvent();
|
|
|
|
}
|
2013-09-24 10:04:16 +00:00
|
|
|
return HasKeyEventMessage() || IsIMERelatedEvent() ||
|
|
|
|
IsRetargetedNativeEventDelivererForPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WidgetEvent::IsAllowedToDispatchDOMEvent() const
|
|
|
|
{
|
2014-08-04 05:28:46 +00:00
|
|
|
switch (mClass) {
|
2014-08-04 05:28:50 +00:00
|
|
|
case eMouseEventClass:
|
2014-08-04 05:28:52 +00:00
|
|
|
case ePointerEventClass:
|
2013-09-24 10:04:16 +00:00
|
|
|
// We want synthesized mouse moves to cause mouseover and mouseout
|
2014-04-01 04:09:23 +00:00
|
|
|
// DOM events (EventStateManager::PreHandleEvent), but not mousemove
|
2013-09-24 10:04:16 +00:00
|
|
|
// DOM events.
|
|
|
|
// Synthesized button up events also do not cause DOM events because they
|
2016-04-18 14:09:02 +00:00
|
|
|
// do not have a reliable mRefPoint.
|
2016-05-12 02:36:41 +00:00
|
|
|
return AsMouseEvent()->mReason == WidgetMouseEvent::eReal;
|
2013-09-24 10:04:16 +00:00
|
|
|
|
2014-08-04 05:28:51 +00:00
|
|
|
case eWheelEventClass: {
|
2013-09-24 10:04:16 +00:00
|
|
|
// wheel event whose all delta values are zero by user pref applied, it
|
|
|
|
// shouldn't cause a DOM event.
|
2013-10-18 06:10:20 +00:00
|
|
|
const WidgetWheelEvent* wheelEvent = AsWheelEvent();
|
2016-03-31 09:09:47 +00:00
|
|
|
return wheelEvent->mDeltaX != 0.0 || wheelEvent->mDeltaY != 0.0 ||
|
2016-03-31 09:18:34 +00:00
|
|
|
wheelEvent->mDeltaZ != 0.0;
|
2013-09-24 10:04:16 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 13:53:19 +00:00
|
|
|
// Following events are handled in EventStateManager, so, we don't need to
|
|
|
|
// dispatch DOM event for them into the DOM tree.
|
2014-08-04 05:28:49 +00:00
|
|
|
case eQueryContentEventClass:
|
2014-08-04 05:28:49 +00:00
|
|
|
case eSelectionEventClass:
|
2014-08-04 05:28:56 +00:00
|
|
|
case eContentCommandEventClass:
|
2014-03-27 13:53:19 +00:00
|
|
|
return false;
|
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 04:06:05 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetInputEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/* static */
|
|
|
|
Modifier
|
|
|
|
WidgetInputEvent::GetModifier(const nsAString& aDOMKeyName)
|
|
|
|
{
|
|
|
|
if (aDOMKeyName.EqualsLiteral("Accel")) {
|
|
|
|
return AccelModifier();
|
|
|
|
}
|
|
|
|
KeyNameIndex keyNameIndex = WidgetKeyboardEvent::GetKeyNameIndex(aDOMKeyName);
|
|
|
|
return WidgetKeyboardEvent::GetModifierForKeyName(keyNameIndex);
|
|
|
|
}
|
|
|
|
|
2014-05-22 04:06:05 +00:00
|
|
|
/* static */
|
|
|
|
Modifier
|
|
|
|
WidgetInputEvent::AccelModifier()
|
|
|
|
{
|
|
|
|
static Modifier sAccelModifier = MODIFIER_NONE;
|
|
|
|
if (sAccelModifier == MODIFIER_NONE) {
|
|
|
|
switch (Preferences::GetInt("ui.key.accelKey", 0)) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META:
|
|
|
|
sAccelModifier = MODIFIER_META;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_WIN:
|
|
|
|
sAccelModifier = MODIFIER_OS;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT:
|
|
|
|
sAccelModifier = MODIFIER_ALT;
|
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
|
|
|
sAccelModifier = MODIFIER_CONTROL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
sAccelModifier = MODIFIER_META;
|
|
|
|
#else
|
|
|
|
sAccelModifier = MODIFIER_CONTROL;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sAccelModifier;
|
|
|
|
}
|
|
|
|
|
2016-01-27 06:09:13 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetWheelEvent (MouseEvents.h)
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/* static */ double
|
|
|
|
WidgetWheelEvent::ComputeOverriddenDelta(double aDelta, bool aIsForVertical)
|
|
|
|
{
|
2016-09-20 02:22:26 +00:00
|
|
|
if (!gfxPrefs::MouseWheelHasRootScrollDeltaOverride()) {
|
2016-01-27 06:09:13 +00:00
|
|
|
return aDelta;
|
|
|
|
}
|
2016-09-20 02:22:26 +00:00
|
|
|
int32_t intFactor = aIsForVertical
|
|
|
|
? gfxPrefs::MouseWheelRootScrollVerticalFactor()
|
|
|
|
: gfxPrefs::MouseWheelRootScrollHorizontalFactor();
|
2016-01-27 06:09:13 +00:00
|
|
|
// Making the scroll speed slower doesn't make sense. So, ignore odd factor
|
|
|
|
// which is less than 1.0.
|
|
|
|
if (intFactor <= 100) {
|
|
|
|
return aDelta;
|
|
|
|
}
|
|
|
|
double factor = static_cast<double>(intFactor) / 100;
|
|
|
|
return aDelta * factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
WidgetWheelEvent::OverriddenDeltaX() const
|
|
|
|
{
|
2016-01-27 06:09:13 +00:00
|
|
|
if (!mAllowToOverrideSystemScrollSpeed) {
|
2016-03-31 09:55:59 +00:00
|
|
|
return mDeltaX;
|
2016-01-27 06:09:13 +00:00
|
|
|
}
|
2016-03-31 09:55:59 +00:00
|
|
|
return ComputeOverriddenDelta(mDeltaX, false);
|
2016-01-27 06:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
WidgetWheelEvent::OverriddenDeltaY() const
|
|
|
|
{
|
2016-01-27 06:09:13 +00:00
|
|
|
if (!mAllowToOverrideSystemScrollSpeed) {
|
2016-03-31 09:09:47 +00:00
|
|
|
return mDeltaY;
|
2016-01-27 06:09:13 +00:00
|
|
|
}
|
2016-03-31 09:09:47 +00:00
|
|
|
return ComputeOverriddenDelta(mDeltaY, true);
|
2016-01-27 06:09:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-08 16:45:30 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::WidgetKeyboardEvent (TextEvents.h)
|
|
|
|
******************************************************************************/
|
|
|
|
|
2016-07-20 04:07:53 +00:00
|
|
|
#define NS_DEFINE_KEYNAME(aCPPName, aDOMKeyName) (u"" aDOMKeyName),
|
2016-03-11 02:18:39 +00:00
|
|
|
const char16_t* const WidgetKeyboardEvent::kKeyNames[] = {
|
2015-02-19 06:50:19 +00:00
|
|
|
#include "mozilla/KeyNameList.h"
|
|
|
|
};
|
|
|
|
#undef NS_DEFINE_KEYNAME
|
|
|
|
|
|
|
|
#define NS_DEFINE_PHYSICAL_KEY_CODE_NAME(aCPPName, aDOMCodeName) \
|
2016-07-20 04:07:53 +00:00
|
|
|
(u"" aDOMCodeName),
|
2016-03-11 02:18:39 +00:00
|
|
|
const char16_t* const WidgetKeyboardEvent::kCodeNames[] = {
|
2015-02-19 06:50:19 +00:00
|
|
|
#include "mozilla/PhysicalKeyCodeNameList.h"
|
|
|
|
};
|
|
|
|
#undef NS_DEFINE_PHYSICAL_KEY_CODE_NAME
|
|
|
|
|
|
|
|
WidgetKeyboardEvent::KeyNameIndexHashtable*
|
|
|
|
WidgetKeyboardEvent::sKeyNameIndexHashtable = nullptr;
|
|
|
|
WidgetKeyboardEvent::CodeNameIndexHashtable*
|
|
|
|
WidgetKeyboardEvent::sCodeNameIndexHashtable = nullptr;
|
|
|
|
|
2015-02-19 06:50:18 +00:00
|
|
|
bool
|
|
|
|
WidgetKeyboardEvent::ShouldCauseKeypressEvents() const
|
|
|
|
{
|
2016-03-16 04:50:01 +00:00
|
|
|
// Currently, we don't dispatch keypress events of modifier keys and
|
|
|
|
// dead keys.
|
2015-02-19 06:50:18 +00:00
|
|
|
switch (mKeyNameIndex) {
|
|
|
|
case KEY_NAME_INDEX_Alt:
|
|
|
|
case KEY_NAME_INDEX_AltGraph:
|
|
|
|
case KEY_NAME_INDEX_CapsLock:
|
|
|
|
case KEY_NAME_INDEX_Control:
|
|
|
|
case KEY_NAME_INDEX_Fn:
|
2015-02-19 06:50:19 +00:00
|
|
|
case KEY_NAME_INDEX_FnLock:
|
2015-02-19 06:50:18 +00:00
|
|
|
// case KEY_NAME_INDEX_Hyper:
|
|
|
|
case KEY_NAME_INDEX_Meta:
|
|
|
|
case KEY_NAME_INDEX_NumLock:
|
|
|
|
case KEY_NAME_INDEX_OS:
|
|
|
|
case KEY_NAME_INDEX_ScrollLock:
|
|
|
|
case KEY_NAME_INDEX_Shift:
|
|
|
|
// case KEY_NAME_INDEX_Super:
|
|
|
|
case KEY_NAME_INDEX_Symbol:
|
2015-02-19 06:50:19 +00:00
|
|
|
case KEY_NAME_INDEX_SymbolLock:
|
2016-03-16 04:50:01 +00:00
|
|
|
case KEY_NAME_INDEX_Dead:
|
2015-02-19 06:50:18 +00:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-18 02:22:37 +00:00
|
|
|
static bool
|
|
|
|
HasASCIIDigit(const ShortcutKeyCandidateArray& aCandidates)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < aCandidates.Length(); ++i) {
|
|
|
|
uint32_t ch = aCandidates[i].mCharCode;
|
|
|
|
if (ch >= '0' && ch <= '9')
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
CharsCaseInsensitiveEqual(uint32_t aChar1, uint32_t aChar2)
|
|
|
|
{
|
|
|
|
return aChar1 == aChar2 ||
|
|
|
|
(IS_IN_BMP(aChar1) && IS_IN_BMP(aChar2) &&
|
|
|
|
ToLowerCase(static_cast<char16_t>(aChar1)) ==
|
|
|
|
ToLowerCase(static_cast<char16_t>(aChar2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsCaseChangeableChar(uint32_t aChar)
|
|
|
|
{
|
|
|
|
return IS_IN_BMP(aChar) &&
|
|
|
|
ToLowerCase(static_cast<char16_t>(aChar)) !=
|
|
|
|
ToUpperCase(static_cast<char16_t>(aChar));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WidgetKeyboardEvent::GetShortcutKeyCandidates(
|
|
|
|
ShortcutKeyCandidateArray& aCandidates)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCandidates.IsEmpty(), "aCandidates must be empty");
|
|
|
|
|
|
|
|
// ShortcutKeyCandidate::mCharCode is a candidate charCode.
|
|
|
|
// ShortcutKeyCandidate::mIgnoreShift means the mCharCode should be tried to
|
|
|
|
// execute a command with/without shift key state. If this is TRUE, the
|
|
|
|
// shifted key state should be ignored. Otherwise, don't ignore the state.
|
|
|
|
// the priority of the charCodes are (shift key is not pressed):
|
2016-03-19 11:57:11 +00:00
|
|
|
// 0: PseudoCharCode()/false,
|
2016-03-18 02:22:37 +00:00
|
|
|
// 1: unshiftedCharCodes[0]/false, 2: unshiftedCharCodes[1]/false...
|
|
|
|
// the priority of the charCodes are (shift key is pressed):
|
2016-03-19 11:57:11 +00:00
|
|
|
// 0: PseudoCharCode()/false,
|
2016-03-18 02:22:37 +00:00
|
|
|
// 1: shiftedCharCodes[0]/false, 2: shiftedCharCodes[0]/true,
|
|
|
|
// 3: shiftedCharCodes[1]/false, 4: shiftedCharCodes[1]/true...
|
2016-03-19 11:57:11 +00:00
|
|
|
uint32_t pseudoCharCode = PseudoCharCode();
|
|
|
|
if (pseudoCharCode) {
|
|
|
|
ShortcutKeyCandidate key(pseudoCharCode, false);
|
2016-03-18 02:22:37 +00:00
|
|
|
aCandidates.AppendElement(key);
|
|
|
|
}
|
|
|
|
|
2016-05-12 08:57:21 +00:00
|
|
|
uint32_t len = mAlternativeCharCodes.Length();
|
2016-03-18 02:22:37 +00:00
|
|
|
if (!IsShift()) {
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2016-05-12 08:57:21 +00:00
|
|
|
uint32_t ch = mAlternativeCharCodes[i].mUnshiftedCharCode;
|
2016-03-19 11:57:11 +00:00
|
|
|
if (!ch || ch == pseudoCharCode) {
|
2016-03-18 02:22:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ShortcutKeyCandidate key(ch, false);
|
|
|
|
aCandidates.AppendElement(key);
|
|
|
|
}
|
|
|
|
// If unshiftedCharCodes doesn't have numeric but shiftedCharCode has it,
|
|
|
|
// this keyboard layout is AZERTY or similar layout, probably.
|
|
|
|
// In this case, Accel+[0-9] should be accessible without shift key.
|
|
|
|
// However, the priority should be lowest.
|
|
|
|
if (!HasASCIIDigit(aCandidates)) {
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2016-05-12 08:57:21 +00:00
|
|
|
uint32_t ch = mAlternativeCharCodes[i].mShiftedCharCode;
|
2016-03-18 02:22:37 +00:00
|
|
|
if (ch >= '0' && ch <= '9') {
|
|
|
|
ShortcutKeyCandidate key(ch, false);
|
|
|
|
aCandidates.AppendElement(key);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2016-05-12 08:57:21 +00:00
|
|
|
uint32_t ch = mAlternativeCharCodes[i].mShiftedCharCode;
|
2016-03-18 02:22:37 +00:00
|
|
|
if (!ch) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-19 11:57:11 +00:00
|
|
|
if (ch != pseudoCharCode) {
|
2016-03-18 02:22:37 +00:00
|
|
|
ShortcutKeyCandidate key(ch, false);
|
|
|
|
aCandidates.AppendElement(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the char is an alphabet, the shift key state should not be
|
|
|
|
// ignored. E.g., Ctrl+Shift+C should not execute Ctrl+C.
|
|
|
|
|
|
|
|
// And checking the charCode is same as unshiftedCharCode too.
|
|
|
|
// E.g., for Ctrl+Shift+(Plus of Numpad) should not run Ctrl+Plus.
|
2016-05-12 08:57:21 +00:00
|
|
|
uint32_t unshiftCh = mAlternativeCharCodes[i].mUnshiftedCharCode;
|
2016-03-18 02:22:37 +00:00
|
|
|
if (CharsCaseInsensitiveEqual(ch, unshiftCh)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// On the Hebrew keyboard layout on Windows, the unshifted char is a
|
|
|
|
// localized character but the shifted char is a Latin alphabet,
|
|
|
|
// then, we should not execute without the shift state. See bug 433192.
|
|
|
|
if (IsCaseChangeableChar(ch)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setting the alternative charCode candidates for retry without shift
|
|
|
|
// key state only when the shift key is pressed.
|
|
|
|
ShortcutKeyCandidate key(ch, true);
|
|
|
|
aCandidates.AppendElement(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Special case for "Space" key. With some keyboard layouts, "Space" with
|
|
|
|
// or without Shift key causes non-ASCII space. For such keyboard layouts,
|
|
|
|
// we should guarantee that the key press works as an ASCII white space key
|
2016-03-26 05:06:16 +00:00
|
|
|
// press. However, if the space key is assigned to a function key, it
|
|
|
|
// shouldn't work as a space key.
|
|
|
|
if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING &&
|
2016-05-13 07:06:18 +00:00
|
|
|
mCodeNameIndex == CODE_NAME_INDEX_Space && pseudoCharCode != ' ') {
|
|
|
|
ShortcutKeyCandidate spaceKey(' ', false);
|
2016-03-18 02:22:37 +00:00
|
|
|
aCandidates.AppendElement(spaceKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WidgetKeyboardEvent::GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCandidates.IsEmpty(), "aCandidates must be empty");
|
|
|
|
|
|
|
|
// return the lower cased charCode candidates for access keys.
|
|
|
|
// the priority of the charCodes are:
|
|
|
|
// 0: charCode, 1: unshiftedCharCodes[0], 2: shiftedCharCodes[0]
|
|
|
|
// 3: unshiftedCharCodes[1], 4: shiftedCharCodes[1],...
|
2016-05-13 07:06:18 +00:00
|
|
|
if (mCharCode) {
|
|
|
|
uint32_t ch = mCharCode;
|
2016-03-18 02:22:37 +00:00
|
|
|
if (IS_IN_BMP(ch)) {
|
|
|
|
ch = ToLowerCase(static_cast<char16_t>(ch));
|
|
|
|
}
|
|
|
|
aCandidates.AppendElement(ch);
|
|
|
|
}
|
2016-05-12 08:57:21 +00:00
|
|
|
for (uint32_t i = 0; i < mAlternativeCharCodes.Length(); ++i) {
|
2016-03-18 02:22:37 +00:00
|
|
|
uint32_t ch[2] =
|
2016-05-12 08:57:21 +00:00
|
|
|
{ mAlternativeCharCodes[i].mUnshiftedCharCode,
|
|
|
|
mAlternativeCharCodes[i].mShiftedCharCode };
|
2016-03-18 02:22:37 +00:00
|
|
|
for (uint32_t j = 0; j < 2; ++j) {
|
|
|
|
if (!ch[j]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (IS_IN_BMP(ch[j])) {
|
|
|
|
ch[j] = ToLowerCase(static_cast<char16_t>(ch[j]));
|
|
|
|
}
|
2016-05-13 07:06:18 +00:00
|
|
|
// Don't append the mCharCode that was already appended.
|
2016-03-18 02:22:37 +00:00
|
|
|
if (aCandidates.IndexOf(ch[j]) == aCandidates.NoIndex) {
|
|
|
|
aCandidates.AppendElement(ch[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Special case for "Space" key. With some keyboard layouts, "Space" with
|
|
|
|
// or without Shift key causes non-ASCII space. For such keyboard layouts,
|
|
|
|
// we should guarantee that the key press works as an ASCII white space key
|
2016-03-26 05:06:16 +00:00
|
|
|
// press. However, if the space key is assigned to a function key, it
|
|
|
|
// shouldn't work as a space key.
|
|
|
|
if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING &&
|
2016-05-13 07:06:18 +00:00
|
|
|
mCodeNameIndex == CODE_NAME_INDEX_Space && mCharCode != ' ') {
|
|
|
|
aCandidates.AppendElement(' ');
|
2016-03-18 02:22:37 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/* static */ void
|
|
|
|
WidgetKeyboardEvent::Shutdown()
|
|
|
|
{
|
|
|
|
delete sKeyNameIndexHashtable;
|
|
|
|
sKeyNameIndexHashtable = nullptr;
|
|
|
|
delete sCodeNameIndexHashtable;
|
|
|
|
sCodeNameIndexHashtable = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2014-01-08 16:45:30 +00:00
|
|
|
WidgetKeyboardEvent::GetDOMKeyName(KeyNameIndex aKeyNameIndex,
|
|
|
|
nsAString& aKeyName)
|
|
|
|
{
|
|
|
|
if (aKeyNameIndex >= KEY_NAME_INDEX_USE_STRING) {
|
|
|
|
aKeyName.Truncate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
MOZ_RELEASE_ASSERT(static_cast<size_t>(aKeyNameIndex) <
|
|
|
|
ArrayLength(kKeyNames),
|
|
|
|
"Illegal key enumeration value");
|
|
|
|
aKeyName = kKeyNames[aKeyNameIndex];
|
2014-01-08 16:45:30 +00:00
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/* static */ void
|
2014-05-25 02:08:58 +00:00
|
|
|
WidgetKeyboardEvent::GetDOMCodeName(CodeNameIndex aCodeNameIndex,
|
|
|
|
nsAString& aCodeName)
|
|
|
|
{
|
|
|
|
if (aCodeNameIndex >= CODE_NAME_INDEX_USE_STRING) {
|
|
|
|
aCodeName.Truncate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(static_cast<size_t>(aCodeNameIndex) <
|
|
|
|
ArrayLength(kCodeNames),
|
|
|
|
"Illegal physical code enumeration value");
|
|
|
|
aCodeName = kCodeNames[aCodeNameIndex];
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/* static */ KeyNameIndex
|
|
|
|
WidgetKeyboardEvent::GetKeyNameIndex(const nsAString& aKeyValue)
|
|
|
|
{
|
|
|
|
if (!sKeyNameIndexHashtable) {
|
|
|
|
sKeyNameIndexHashtable =
|
|
|
|
new KeyNameIndexHashtable(ArrayLength(kKeyNames));
|
|
|
|
for (size_t i = 0; i < ArrayLength(kKeyNames); i++) {
|
|
|
|
sKeyNameIndexHashtable->Put(nsDependentString(kKeyNames[i]),
|
|
|
|
static_cast<KeyNameIndex>(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KeyNameIndex result = KEY_NAME_INDEX_USE_STRING;
|
|
|
|
sKeyNameIndexHashtable->Get(aKeyValue, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ CodeNameIndex
|
|
|
|
WidgetKeyboardEvent::GetCodeNameIndex(const nsAString& aCodeValue)
|
|
|
|
{
|
|
|
|
if (!sCodeNameIndexHashtable) {
|
|
|
|
sCodeNameIndexHashtable =
|
|
|
|
new CodeNameIndexHashtable(ArrayLength(kCodeNames));
|
|
|
|
for (size_t i = 0; i < ArrayLength(kCodeNames); i++) {
|
|
|
|
sCodeNameIndexHashtable->Put(nsDependentString(kCodeNames[i]),
|
|
|
|
static_cast<CodeNameIndex>(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CodeNameIndex result = CODE_NAME_INDEX_USE_STRING;
|
|
|
|
sCodeNameIndexHashtable->Get(aCodeValue, &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-03-14 13:13:30 +00:00
|
|
|
/* static */ const char*
|
|
|
|
WidgetKeyboardEvent::GetCommandStr(Command aCommand)
|
|
|
|
{
|
|
|
|
#define NS_DEFINE_COMMAND(aName, aCommandStr) , #aCommandStr
|
2016-03-11 02:57:18 +00:00
|
|
|
static const char* const kCommands[] = {
|
2014-03-14 13:13:30 +00:00
|
|
|
"" // CommandDoNothing
|
|
|
|
#include "mozilla/CommandList.h"
|
|
|
|
};
|
|
|
|
#undef NS_DEFINE_COMMAND
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(static_cast<size_t>(aCommand) < ArrayLength(kCommands),
|
|
|
|
"Illegal command enumeration value");
|
|
|
|
return kCommands[aCommand];
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:36:53 +00:00
|
|
|
/* static */ uint32_t
|
|
|
|
WidgetKeyboardEvent::ComputeLocationFromCodeValue(CodeNameIndex aCodeNameIndex)
|
|
|
|
{
|
|
|
|
// Following commented out cases are not defined in PhysicalKeyCodeNameList.h
|
|
|
|
// but are defined by D3E spec. So, they should be uncommented when the
|
|
|
|
// code values are defined in the header.
|
|
|
|
switch (aCodeNameIndex) {
|
|
|
|
case CODE_NAME_INDEX_AltLeft:
|
|
|
|
case CODE_NAME_INDEX_ControlLeft:
|
|
|
|
case CODE_NAME_INDEX_OSLeft:
|
|
|
|
case CODE_NAME_INDEX_ShiftLeft:
|
|
|
|
return nsIDOMKeyEvent::DOM_KEY_LOCATION_LEFT;
|
|
|
|
case CODE_NAME_INDEX_AltRight:
|
|
|
|
case CODE_NAME_INDEX_ControlRight:
|
|
|
|
case CODE_NAME_INDEX_OSRight:
|
|
|
|
case CODE_NAME_INDEX_ShiftRight:
|
|
|
|
return nsIDOMKeyEvent::DOM_KEY_LOCATION_RIGHT;
|
|
|
|
case CODE_NAME_INDEX_Numpad0:
|
|
|
|
case CODE_NAME_INDEX_Numpad1:
|
|
|
|
case CODE_NAME_INDEX_Numpad2:
|
|
|
|
case CODE_NAME_INDEX_Numpad3:
|
|
|
|
case CODE_NAME_INDEX_Numpad4:
|
|
|
|
case CODE_NAME_INDEX_Numpad5:
|
|
|
|
case CODE_NAME_INDEX_Numpad6:
|
|
|
|
case CODE_NAME_INDEX_Numpad7:
|
|
|
|
case CODE_NAME_INDEX_Numpad8:
|
|
|
|
case CODE_NAME_INDEX_Numpad9:
|
|
|
|
case CODE_NAME_INDEX_NumpadAdd:
|
|
|
|
case CODE_NAME_INDEX_NumpadBackspace:
|
2015-02-19 06:50:20 +00:00
|
|
|
case CODE_NAME_INDEX_NumpadClear:
|
|
|
|
case CODE_NAME_INDEX_NumpadClearEntry:
|
2015-01-28 13:36:53 +00:00
|
|
|
case CODE_NAME_INDEX_NumpadComma:
|
|
|
|
case CODE_NAME_INDEX_NumpadDecimal:
|
|
|
|
case CODE_NAME_INDEX_NumpadDivide:
|
|
|
|
case CODE_NAME_INDEX_NumpadEnter:
|
|
|
|
case CODE_NAME_INDEX_NumpadEqual:
|
2015-02-19 06:50:20 +00:00
|
|
|
case CODE_NAME_INDEX_NumpadMemoryAdd:
|
|
|
|
case CODE_NAME_INDEX_NumpadMemoryClear:
|
|
|
|
case CODE_NAME_INDEX_NumpadMemoryRecall:
|
|
|
|
case CODE_NAME_INDEX_NumpadMemoryStore:
|
2015-01-28 13:36:53 +00:00
|
|
|
case CODE_NAME_INDEX_NumpadMemorySubtract:
|
|
|
|
case CODE_NAME_INDEX_NumpadMultiply:
|
2015-02-19 06:50:20 +00:00
|
|
|
case CODE_NAME_INDEX_NumpadParenLeft:
|
|
|
|
case CODE_NAME_INDEX_NumpadParenRight:
|
2015-01-28 13:36:53 +00:00
|
|
|
case CODE_NAME_INDEX_NumpadSubtract:
|
|
|
|
return nsIDOMKeyEvent::DOM_KEY_LOCATION_NUMPAD;
|
|
|
|
default:
|
|
|
|
return nsIDOMKeyEvent::DOM_KEY_LOCATION_STANDARD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/* static */ uint32_t
|
|
|
|
WidgetKeyboardEvent::ComputeKeyCodeFromKeyNameIndex(KeyNameIndex aKeyNameIndex)
|
|
|
|
{
|
|
|
|
switch (aKeyNameIndex) {
|
|
|
|
case KEY_NAME_INDEX_Cancel:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CANCEL;
|
|
|
|
case KEY_NAME_INDEX_Help:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_HELP;
|
|
|
|
case KEY_NAME_INDEX_Backspace:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_BACK_SPACE;
|
|
|
|
case KEY_NAME_INDEX_Tab:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_TAB;
|
|
|
|
case KEY_NAME_INDEX_Clear:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CLEAR;
|
|
|
|
case KEY_NAME_INDEX_Enter:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_RETURN;
|
|
|
|
case KEY_NAME_INDEX_Shift:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_SHIFT;
|
|
|
|
case KEY_NAME_INDEX_Control:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CONTROL;
|
|
|
|
case KEY_NAME_INDEX_Alt:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_ALT;
|
|
|
|
case KEY_NAME_INDEX_Pause:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_PAUSE;
|
|
|
|
case KEY_NAME_INDEX_CapsLock:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CAPS_LOCK;
|
|
|
|
case KEY_NAME_INDEX_Hiragana:
|
|
|
|
case KEY_NAME_INDEX_Katakana:
|
|
|
|
case KEY_NAME_INDEX_HiraganaKatakana:
|
|
|
|
case KEY_NAME_INDEX_KanaMode:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_KANA;
|
|
|
|
case KEY_NAME_INDEX_HangulMode:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_HANGUL;
|
|
|
|
case KEY_NAME_INDEX_Eisu:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_EISU;
|
|
|
|
case KEY_NAME_INDEX_JunjaMode:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_JUNJA;
|
|
|
|
case KEY_NAME_INDEX_FinalMode:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_FINAL;
|
|
|
|
case KEY_NAME_INDEX_HanjaMode:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_HANJA;
|
|
|
|
case KEY_NAME_INDEX_KanjiMode:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_KANJI;
|
|
|
|
case KEY_NAME_INDEX_Escape:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_ESCAPE;
|
|
|
|
case KEY_NAME_INDEX_Convert:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CONVERT;
|
|
|
|
case KEY_NAME_INDEX_NonConvert:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_NONCONVERT;
|
|
|
|
case KEY_NAME_INDEX_Accept:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_ACCEPT;
|
|
|
|
case KEY_NAME_INDEX_ModeChange:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_MODECHANGE;
|
|
|
|
case KEY_NAME_INDEX_PageUp:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_PAGE_UP;
|
|
|
|
case KEY_NAME_INDEX_PageDown:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_PAGE_DOWN;
|
|
|
|
case KEY_NAME_INDEX_End:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_END;
|
|
|
|
case KEY_NAME_INDEX_Home:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_HOME;
|
|
|
|
case KEY_NAME_INDEX_ArrowLeft:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_LEFT;
|
|
|
|
case KEY_NAME_INDEX_ArrowUp:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_UP;
|
|
|
|
case KEY_NAME_INDEX_ArrowRight:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_RIGHT;
|
|
|
|
case KEY_NAME_INDEX_ArrowDown:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_DOWN;
|
|
|
|
case KEY_NAME_INDEX_Select:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_SELECT;
|
|
|
|
case KEY_NAME_INDEX_Print:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_PRINT;
|
|
|
|
case KEY_NAME_INDEX_Execute:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_EXECUTE;
|
|
|
|
case KEY_NAME_INDEX_PrintScreen:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_PRINTSCREEN;
|
|
|
|
case KEY_NAME_INDEX_Insert:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_INSERT;
|
|
|
|
case KEY_NAME_INDEX_Delete:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_DELETE;
|
|
|
|
case KEY_NAME_INDEX_OS:
|
|
|
|
// case KEY_NAME_INDEX_Super:
|
|
|
|
// case KEY_NAME_INDEX_Hyper:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_WIN;
|
|
|
|
case KEY_NAME_INDEX_ContextMenu:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CONTEXT_MENU;
|
|
|
|
case KEY_NAME_INDEX_Standby:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_SLEEP;
|
|
|
|
case KEY_NAME_INDEX_F1:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F1;
|
|
|
|
case KEY_NAME_INDEX_F2:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F2;
|
|
|
|
case KEY_NAME_INDEX_F3:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F3;
|
|
|
|
case KEY_NAME_INDEX_F4:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F4;
|
|
|
|
case KEY_NAME_INDEX_F5:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F5;
|
|
|
|
case KEY_NAME_INDEX_F6:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F6;
|
|
|
|
case KEY_NAME_INDEX_F7:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F7;
|
|
|
|
case KEY_NAME_INDEX_F8:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F8;
|
|
|
|
case KEY_NAME_INDEX_F9:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F9;
|
|
|
|
case KEY_NAME_INDEX_F10:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F10;
|
|
|
|
case KEY_NAME_INDEX_F11:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F11;
|
|
|
|
case KEY_NAME_INDEX_F12:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F12;
|
|
|
|
case KEY_NAME_INDEX_F13:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F13;
|
|
|
|
case KEY_NAME_INDEX_F14:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F14;
|
|
|
|
case KEY_NAME_INDEX_F15:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F15;
|
|
|
|
case KEY_NAME_INDEX_F16:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F16;
|
|
|
|
case KEY_NAME_INDEX_F17:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F17;
|
|
|
|
case KEY_NAME_INDEX_F18:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F18;
|
|
|
|
case KEY_NAME_INDEX_F19:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F19;
|
|
|
|
case KEY_NAME_INDEX_F20:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F20;
|
|
|
|
case KEY_NAME_INDEX_F21:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F21;
|
|
|
|
case KEY_NAME_INDEX_F22:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F22;
|
|
|
|
case KEY_NAME_INDEX_F23:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F23;
|
|
|
|
case KEY_NAME_INDEX_F24:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_F24;
|
|
|
|
case KEY_NAME_INDEX_NumLock:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_NUM_LOCK;
|
|
|
|
case KEY_NAME_INDEX_ScrollLock:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_SCROLL_LOCK;
|
2016-05-20 15:57:18 +00:00
|
|
|
case KEY_NAME_INDEX_AudioVolumeMute:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_VOLUME_MUTE;
|
2016-05-20 15:52:03 +00:00
|
|
|
case KEY_NAME_INDEX_AudioVolumeDown:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_VOLUME_DOWN;
|
2016-05-20 15:55:48 +00:00
|
|
|
case KEY_NAME_INDEX_AudioVolumeUp:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_VOLUME_UP;
|
2015-02-19 06:50:19 +00:00
|
|
|
case KEY_NAME_INDEX_Meta:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_META;
|
|
|
|
case KEY_NAME_INDEX_AltGraph:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_ALTGR;
|
|
|
|
case KEY_NAME_INDEX_Attn:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_ATTN;
|
|
|
|
case KEY_NAME_INDEX_CrSel:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_CRSEL;
|
|
|
|
case KEY_NAME_INDEX_ExSel:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_EXSEL;
|
|
|
|
case KEY_NAME_INDEX_EraseEof:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_EREOF;
|
|
|
|
case KEY_NAME_INDEX_Play:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_PLAY;
|
|
|
|
case KEY_NAME_INDEX_ZoomToggle:
|
|
|
|
case KEY_NAME_INDEX_ZoomIn:
|
|
|
|
case KEY_NAME_INDEX_ZoomOut:
|
|
|
|
return nsIDOMKeyEvent::DOM_VK_ZOOM;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:50:19 +00:00
|
|
|
/* static */ Modifier
|
|
|
|
WidgetKeyboardEvent::GetModifierForKeyName(KeyNameIndex aKeyNameIndex)
|
|
|
|
{
|
|
|
|
switch (aKeyNameIndex) {
|
|
|
|
case KEY_NAME_INDEX_Alt:
|
|
|
|
return MODIFIER_ALT;
|
|
|
|
case KEY_NAME_INDEX_AltGraph:
|
|
|
|
return MODIFIER_ALTGRAPH;
|
|
|
|
case KEY_NAME_INDEX_CapsLock:
|
|
|
|
return MODIFIER_CAPSLOCK;
|
|
|
|
case KEY_NAME_INDEX_Control:
|
|
|
|
return MODIFIER_CONTROL;
|
|
|
|
case KEY_NAME_INDEX_Fn:
|
|
|
|
return MODIFIER_FN;
|
|
|
|
case KEY_NAME_INDEX_FnLock:
|
|
|
|
return MODIFIER_FNLOCK;
|
|
|
|
// case KEY_NAME_INDEX_Hyper:
|
|
|
|
case KEY_NAME_INDEX_Meta:
|
|
|
|
return MODIFIER_META;
|
|
|
|
case KEY_NAME_INDEX_NumLock:
|
|
|
|
return MODIFIER_NUMLOCK;
|
|
|
|
case KEY_NAME_INDEX_OS:
|
|
|
|
return MODIFIER_OS;
|
|
|
|
case KEY_NAME_INDEX_ScrollLock:
|
|
|
|
return MODIFIER_SCROLLLOCK;
|
|
|
|
case KEY_NAME_INDEX_Shift:
|
|
|
|
return MODIFIER_SHIFT;
|
|
|
|
// case KEY_NAME_INDEX_Super:
|
|
|
|
case KEY_NAME_INDEX_Symbol:
|
|
|
|
return MODIFIER_SYMBOL;
|
|
|
|
case KEY_NAME_INDEX_SymbolLock:
|
|
|
|
return MODIFIER_SYMBOLLOCK;
|
|
|
|
default:
|
|
|
|
return MODIFIER_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
WidgetKeyboardEvent::IsLockableModifier(KeyNameIndex aKeyNameIndex)
|
|
|
|
{
|
|
|
|
switch (aKeyNameIndex) {
|
|
|
|
case KEY_NAME_INDEX_CapsLock:
|
|
|
|
case KEY_NAME_INDEX_FnLock:
|
|
|
|
case KEY_NAME_INDEX_NumLock:
|
|
|
|
case KEY_NAME_INDEX_ScrollLock:
|
|
|
|
case KEY_NAME_INDEX_SymbolLock:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 10:04:16 +00:00
|
|
|
} // namespace mozilla
|