2009-10-01 06:52:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
#include "TextInputHandler.h"
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
#include "mozilla/AutoRestore.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2016-12-16 06:16:31 +03:00
|
|
|
#include "mozilla/SizePrintfMacros.h"
|
2016-03-16 07:47:49 +03:00
|
|
|
#include "mozilla/TextEventDispatcher.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
#include "nsChildView.h"
|
|
|
|
#include "nsObjCExceptions.h"
|
2009-10-16 13:12:09 +04:00
|
|
|
#include "nsBidiUtils.h"
|
2011-02-24 07:48:12 +03:00
|
|
|
#include "nsToolkit.h"
|
2011-07-21 04:33:16 +04:00
|
|
|
#include "nsCocoaUtils.h"
|
2012-05-17 11:04:16 +04:00
|
|
|
#include "WidgetUtils.h"
|
2011-08-25 12:46:01 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2015-03-03 08:31:10 +03:00
|
|
|
#include "ComplexTextInputPanel.h"
|
2011-02-24 07:48:12 +03:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2011-05-08 14:19:15 +04:00
|
|
|
using namespace mozilla::widget;
|
|
|
|
|
2016-06-16 11:14:34 +03:00
|
|
|
LazyLogModule gLog("TextInputHandlerWidgets");
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
static const char*
|
2011-09-29 10:19:26 +04:00
|
|
|
OnOrOff(bool aBool)
|
2011-07-21 04:33:16 +04:00
|
|
|
{
|
|
|
|
return aBool ? "ON" : "off";
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
static const char*
|
2011-09-29 10:19:26 +04:00
|
|
|
TrueOrFalse(bool aBool)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
return aBool ? "TRUE" : "FALSE";
|
|
|
|
}
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
static const char*
|
|
|
|
GetKeyNameForNativeKeyCode(unsigned short aNativeKeyCode)
|
|
|
|
{
|
|
|
|
switch (aNativeKeyCode) {
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Escape: return "Escape";
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_RightCommand: return "Right-Command";
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Command: return "Command";
|
|
|
|
case kVK_Shift: return "Shift";
|
|
|
|
case kVK_CapsLock: return "CapsLock";
|
|
|
|
case kVK_Option: return "Option";
|
|
|
|
case kVK_Control: return "Control";
|
|
|
|
case kVK_RightShift: return "Right-Shift";
|
|
|
|
case kVK_RightOption: return "Right-Option";
|
|
|
|
case kVK_RightControl: return "Right-Control";
|
|
|
|
case kVK_ANSI_KeypadClear: return "Clear";
|
|
|
|
|
|
|
|
case kVK_F1: return "F1";
|
|
|
|
case kVK_F2: return "F2";
|
|
|
|
case kVK_F3: return "F3";
|
|
|
|
case kVK_F4: return "F4";
|
|
|
|
case kVK_F5: return "F5";
|
|
|
|
case kVK_F6: return "F6";
|
|
|
|
case kVK_F7: return "F7";
|
|
|
|
case kVK_F8: return "F8";
|
|
|
|
case kVK_F9: return "F9";
|
|
|
|
case kVK_F10: return "F10";
|
|
|
|
case kVK_F11: return "F11";
|
|
|
|
case kVK_F12: return "F12";
|
|
|
|
case kVK_F13: return "F13/PrintScreen";
|
|
|
|
case kVK_F14: return "F14/ScrollLock";
|
|
|
|
case kVK_F15: return "F15/Pause";
|
|
|
|
|
|
|
|
case kVK_ANSI_Keypad0: return "NumPad-0";
|
|
|
|
case kVK_ANSI_Keypad1: return "NumPad-1";
|
|
|
|
case kVK_ANSI_Keypad2: return "NumPad-2";
|
|
|
|
case kVK_ANSI_Keypad3: return "NumPad-3";
|
|
|
|
case kVK_ANSI_Keypad4: return "NumPad-4";
|
|
|
|
case kVK_ANSI_Keypad5: return "NumPad-5";
|
|
|
|
case kVK_ANSI_Keypad6: return "NumPad-6";
|
|
|
|
case kVK_ANSI_Keypad7: return "NumPad-7";
|
|
|
|
case kVK_ANSI_Keypad8: return "NumPad-8";
|
|
|
|
case kVK_ANSI_Keypad9: return "NumPad-9";
|
|
|
|
|
|
|
|
case kVK_ANSI_KeypadMultiply: return "NumPad-*";
|
|
|
|
case kVK_ANSI_KeypadPlus: return "NumPad-+";
|
|
|
|
case kVK_ANSI_KeypadMinus: return "NumPad--";
|
|
|
|
case kVK_ANSI_KeypadDecimal: return "NumPad-.";
|
|
|
|
case kVK_ANSI_KeypadDivide: return "NumPad-/";
|
|
|
|
case kVK_ANSI_KeypadEquals: return "NumPad-=";
|
|
|
|
case kVK_ANSI_KeypadEnter: return "NumPad-Enter";
|
|
|
|
case kVK_Return: return "Return";
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Powerbook_KeypadEnter: return "NumPad-EnterOnPowerBook";
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Insert: return "Insert/Help";
|
|
|
|
case kVK_PC_Delete: return "Delete";
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Tab: return "Tab";
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Backspace: return "Backspace";
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Home: return "Home";
|
|
|
|
case kVK_End: return "End";
|
|
|
|
case kVK_PageUp: return "PageUp";
|
|
|
|
case kVK_PageDown: return "PageDown";
|
|
|
|
case kVK_LeftArrow: return "LeftArrow";
|
|
|
|
case kVK_RightArrow: return "RightArrow";
|
|
|
|
case kVK_UpArrow: return "UpArrow";
|
|
|
|
case kVK_DownArrow: return "DownArrow";
|
2013-12-06 07:16:55 +04:00
|
|
|
case kVK_PC_ContextMenu: return "ContextMenu";
|
2012-07-04 09:59:50 +04:00
|
|
|
|
|
|
|
case kVK_Function: return "Function";
|
|
|
|
case kVK_VolumeUp: return "VolumeUp";
|
|
|
|
case kVK_VolumeDown: return "VolumeDown";
|
|
|
|
case kVK_Mute: return "Mute";
|
|
|
|
|
|
|
|
case kVK_ISO_Section: return "ISO_Section";
|
|
|
|
|
|
|
|
case kVK_JIS_Yen: return "JIS_Yen";
|
|
|
|
case kVK_JIS_Underscore: return "JIS_Underscore";
|
|
|
|
case kVK_JIS_KeypadComma: return "JIS_KeypadComma";
|
|
|
|
case kVK_JIS_Eisu: return "JIS_Eisu";
|
|
|
|
case kVK_JIS_Kana: return "JIS_Kana";
|
|
|
|
|
|
|
|
case kVK_ANSI_A: return "A";
|
|
|
|
case kVK_ANSI_B: return "B";
|
|
|
|
case kVK_ANSI_C: return "C";
|
|
|
|
case kVK_ANSI_D: return "D";
|
|
|
|
case kVK_ANSI_E: return "E";
|
|
|
|
case kVK_ANSI_F: return "F";
|
|
|
|
case kVK_ANSI_G: return "G";
|
|
|
|
case kVK_ANSI_H: return "H";
|
|
|
|
case kVK_ANSI_I: return "I";
|
|
|
|
case kVK_ANSI_J: return "J";
|
|
|
|
case kVK_ANSI_K: return "K";
|
|
|
|
case kVK_ANSI_L: return "L";
|
|
|
|
case kVK_ANSI_M: return "M";
|
|
|
|
case kVK_ANSI_N: return "N";
|
|
|
|
case kVK_ANSI_O: return "O";
|
|
|
|
case kVK_ANSI_P: return "P";
|
|
|
|
case kVK_ANSI_Q: return "Q";
|
|
|
|
case kVK_ANSI_R: return "R";
|
|
|
|
case kVK_ANSI_S: return "S";
|
|
|
|
case kVK_ANSI_T: return "T";
|
|
|
|
case kVK_ANSI_U: return "U";
|
|
|
|
case kVK_ANSI_V: return "V";
|
|
|
|
case kVK_ANSI_W: return "W";
|
|
|
|
case kVK_ANSI_X: return "X";
|
|
|
|
case kVK_ANSI_Y: return "Y";
|
|
|
|
case kVK_ANSI_Z: return "Z";
|
|
|
|
|
|
|
|
case kVK_ANSI_1: return "1";
|
|
|
|
case kVK_ANSI_2: return "2";
|
|
|
|
case kVK_ANSI_3: return "3";
|
|
|
|
case kVK_ANSI_4: return "4";
|
|
|
|
case kVK_ANSI_5: return "5";
|
|
|
|
case kVK_ANSI_6: return "6";
|
|
|
|
case kVK_ANSI_7: return "7";
|
|
|
|
case kVK_ANSI_8: return "8";
|
|
|
|
case kVK_ANSI_9: return "9";
|
|
|
|
case kVK_ANSI_0: return "0";
|
|
|
|
case kVK_ANSI_Equal: return "Equal";
|
|
|
|
case kVK_ANSI_Minus: return "Minus";
|
|
|
|
case kVK_ANSI_RightBracket: return "RightBracket";
|
|
|
|
case kVK_ANSI_LeftBracket: return "LeftBracket";
|
|
|
|
case kVK_ANSI_Quote: return "Quote";
|
|
|
|
case kVK_ANSI_Semicolon: return "Semicolon";
|
|
|
|
case kVK_ANSI_Backslash: return "Backslash";
|
|
|
|
case kVK_ANSI_Comma: return "Comma";
|
|
|
|
case kVK_ANSI_Slash: return "Slash";
|
|
|
|
case kVK_ANSI_Period: return "Period";
|
|
|
|
case kVK_ANSI_Grave: return "Grave";
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
default: return "undefined";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetCharacters(const NSString* aString)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-07-21 04:33:16 +04:00
|
|
|
nsAutoString str;
|
|
|
|
nsCocoaUtils::GetStringForNSString(aString, str);
|
|
|
|
if (str.IsEmpty()) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString escapedStr;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < str.Length(); i++) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = str[i];
|
2011-07-21 04:33:16 +04:00
|
|
|
if (ch < 0x20) {
|
|
|
|
nsPrintfCString utf8str("(U+%04X)", ch);
|
|
|
|
escapedStr += NS_ConvertUTF8toUTF16(utf8str);
|
|
|
|
} else if (ch <= 0x7E) {
|
|
|
|
escapedStr += ch;
|
|
|
|
} else {
|
|
|
|
nsPrintfCString utf8str("(U+%04X)", ch);
|
|
|
|
escapedStr += ch;
|
|
|
|
escapedStr += NS_ConvertUTF8toUTF16(utf8str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the result will be freed automatically by cocoa.
|
|
|
|
NSString* result = nsCocoaUtils::ToNSString(escapedStr);
|
|
|
|
return [result UTF8String];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetCharacters(const CFStringRef aString)
|
|
|
|
{
|
2011-07-22 01:05:58 +04:00
|
|
|
const NSString* str = reinterpret_cast<const NSString*>(aString);
|
2011-07-21 04:33:16 +04:00
|
|
|
return GetCharacters(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetNativeKeyEventType(NSEvent* aNativeEvent)
|
|
|
|
{
|
|
|
|
switch ([aNativeEvent type]) {
|
|
|
|
case NSKeyDown: return "NSKeyDown";
|
|
|
|
case NSKeyUp: return "NSKeyUp";
|
|
|
|
case NSFlagsChanged: return "NSFlagsChanged";
|
|
|
|
default: return "not key event";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
2013-10-02 07:46:04 +04:00
|
|
|
GetGeckoKeyEventType(const WidgetEvent& aEvent)
|
2011-07-21 04:33:16 +04:00
|
|
|
{
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aEvent.mMessage) {
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyDown: return "eKeyDown";
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyUp: return "eKeyUp";
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyPress: return "eKeyPress";
|
2011-07-21 04:33:16 +04:00
|
|
|
default: return "not key event";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
static const char*
|
|
|
|
GetWindowLevelName(NSInteger aWindowLevel)
|
|
|
|
{
|
|
|
|
switch (aWindowLevel) {
|
|
|
|
case kCGBaseWindowLevelKey:
|
|
|
|
return "kCGBaseWindowLevelKey (NSNormalWindowLevel)";
|
|
|
|
case kCGMinimumWindowLevelKey:
|
|
|
|
return "kCGMinimumWindowLevelKey";
|
|
|
|
case kCGDesktopWindowLevelKey:
|
|
|
|
return "kCGDesktopWindowLevelKey";
|
|
|
|
case kCGBackstopMenuLevelKey:
|
|
|
|
return "kCGBackstopMenuLevelKey";
|
|
|
|
case kCGNormalWindowLevelKey:
|
|
|
|
return "kCGNormalWindowLevelKey";
|
|
|
|
case kCGFloatingWindowLevelKey:
|
|
|
|
return "kCGFloatingWindowLevelKey (NSFloatingWindowLevel)";
|
|
|
|
case kCGTornOffMenuWindowLevelKey:
|
|
|
|
return "kCGTornOffMenuWindowLevelKey (NSSubmenuWindowLevel, NSTornOffMenuWindowLevel)";
|
|
|
|
case kCGDockWindowLevelKey:
|
|
|
|
return "kCGDockWindowLevelKey (NSDockWindowLevel)";
|
|
|
|
case kCGMainMenuWindowLevelKey:
|
|
|
|
return "kCGMainMenuWindowLevelKey (NSMainMenuWindowLevel)";
|
|
|
|
case kCGStatusWindowLevelKey:
|
|
|
|
return "kCGStatusWindowLevelKey (NSStatusWindowLevel)";
|
|
|
|
case kCGModalPanelWindowLevelKey:
|
|
|
|
return "kCGModalPanelWindowLevelKey (NSModalPanelWindowLevel)";
|
|
|
|
case kCGPopUpMenuWindowLevelKey:
|
|
|
|
return "kCGPopUpMenuWindowLevelKey (NSPopUpMenuWindowLevel)";
|
|
|
|
case kCGDraggingWindowLevelKey:
|
|
|
|
return "kCGDraggingWindowLevelKey";
|
|
|
|
case kCGScreenSaverWindowLevelKey:
|
|
|
|
return "kCGScreenSaverWindowLevelKey (NSScreenSaverWindowLevel)";
|
|
|
|
case kCGMaximumWindowLevelKey:
|
|
|
|
return "kCGMaximumWindowLevelKey";
|
|
|
|
case kCGOverlayWindowLevelKey:
|
|
|
|
return "kCGOverlayWindowLevelKey";
|
|
|
|
case kCGHelpWindowLevelKey:
|
|
|
|
return "kCGHelpWindowLevelKey";
|
|
|
|
case kCGUtilityWindowLevelKey:
|
|
|
|
return "kCGUtilityWindowLevelKey";
|
|
|
|
case kCGDesktopIconWindowLevelKey:
|
|
|
|
return "kCGDesktopIconWindowLevelKey";
|
|
|
|
case kCGCursorWindowLevelKey:
|
|
|
|
return "kCGCursorWindowLevelKey";
|
|
|
|
case kCGNumberOfWindowLevelKeys:
|
|
|
|
return "kCGNumberOfWindowLevelKeys";
|
|
|
|
default:
|
|
|
|
return "unknown window level";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 07:16:55 +04:00
|
|
|
static bool
|
|
|
|
IsControlChar(uint32_t aCharCode)
|
|
|
|
{
|
|
|
|
return aCharCode < ' ' || aCharCode == 0x7F;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t gHandlerInstanceCount = 0;
|
2009-10-16 13:12:09 +04:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
static void
|
2016-06-16 11:14:34 +03:00
|
|
|
EnsureToLogAllKeyboardLayoutsAndIMEs()
|
2011-07-21 04:33:16 +04:00
|
|
|
{
|
2016-06-16 11:14:34 +03:00
|
|
|
static bool sDone = false;
|
|
|
|
if (!sDone) {
|
|
|
|
sDone = true;
|
2011-07-21 04:33:16 +04:00
|
|
|
TextInputHandler::DebugPrintAllKeyboardLayouts();
|
|
|
|
IMEInputHandler::DebugPrintAllIMEModes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* TISInputSourceWrapper implementation
|
2009-10-01 06:52:50 +04:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2016-06-16 11:00:38 +03:00
|
|
|
TISInputSourceWrapper* TISInputSourceWrapper::sCurrentInputSource = nullptr;
|
|
|
|
|
2009-10-16 13:12:09 +04:00
|
|
|
// static
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper&
|
2012-10-16 05:43:50 +04:00
|
|
|
TISInputSourceWrapper::CurrentInputSource()
|
2009-10-16 13:12:09 +04:00
|
|
|
{
|
2016-06-16 11:00:38 +03:00
|
|
|
if (!sCurrentInputSource) {
|
|
|
|
sCurrentInputSource = new TISInputSourceWrapper();
|
|
|
|
}
|
|
|
|
if (!sCurrentInputSource->IsInitializedByCurrentInputSource()) {
|
|
|
|
sCurrentInputSource->InitByCurrentInputSource();
|
|
|
|
}
|
|
|
|
return *sCurrentInputSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
TISInputSourceWrapper::Shutdown()
|
|
|
|
{
|
|
|
|
if (!sCurrentInputSource) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sCurrentInputSource->Clear();
|
|
|
|
delete sCurrentInputSource;
|
|
|
|
sCurrentInputSource = nullptr;
|
2009-10-16 13:12:09 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-02-23 20:25:11 +03:00
|
|
|
TISInputSourceWrapper::TranslateToString(UInt32 aKeyCode, UInt32 aModifiers,
|
|
|
|
UInt32 aKbType, nsAString &aStr)
|
2009-10-16 13:12:09 +04:00
|
|
|
{
|
2011-02-23 20:25:11 +03:00
|
|
|
aStr.Truncate();
|
|
|
|
|
|
|
|
const UCKeyboardLayout* UCKey = GetUCKeyboardLayout();
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TISInputSourceWrapper::TranslateToString, aKeyCode=0x%X, "
|
|
|
|
"aModifiers=0x%X, aKbType=0x%X UCKey=%p\n "
|
|
|
|
"Shift: %s, Ctrl: %s, Opt: %s, Cmd: %s, CapsLock: %s, NumLock: %s",
|
2016-12-16 06:16:31 +03:00
|
|
|
this, static_cast<unsigned int>(aKeyCode), static_cast<unsigned int>(aModifiers),
|
|
|
|
static_cast<unsigned int>(aKbType), UCKey,
|
2011-07-21 04:33:16 +04:00
|
|
|
OnOrOff(aModifiers & shiftKey), OnOrOff(aModifiers & controlKey),
|
|
|
|
OnOrOff(aModifiers & optionKey), OnOrOff(aModifiers & cmdKey),
|
|
|
|
OnOrOff(aModifiers & alphaLock),
|
|
|
|
OnOrOff(aModifiers & kEventKeyModifierNumLockMask)));
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(UCKey, false);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2009-10-16 13:12:09 +04:00
|
|
|
UInt32 deadKeyState = 0;
|
|
|
|
UniCharCount len;
|
|
|
|
UniChar chars[5];
|
2011-02-23 20:25:11 +03:00
|
|
|
OSStatus err = ::UCKeyTranslate(UCKey, aKeyCode,
|
2009-10-16 13:12:09 +04:00
|
|
|
kUCKeyActionDown, aModifiers >> 8,
|
|
|
|
aKbType, kUCKeyTranslateNoDeadKeysMask,
|
|
|
|
&deadKeyState, 5, &len, chars);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-12-16 06:16:31 +03:00
|
|
|
("%p TISInputSourceWrapper::TranslateToString, err=0x%X, len=%" PRIuSIZE,
|
|
|
|
this, static_cast<int>(err), len));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(err == noErr, false);
|
2009-10-16 13:12:09 +04:00
|
|
|
if (len == 0) {
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2009-10-16 13:12:09 +04:00
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(EnsureStringLength(aStr, len), false);
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_ASSERTION(sizeof(char16_t) == sizeof(UniChar),
|
|
|
|
"size of char16_t and size of UniChar are different");
|
|
|
|
memcpy(aStr.BeginWriting(), chars, len * sizeof(char16_t));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TISInputSourceWrapper::TranslateToString, aStr=\"%s\"",
|
|
|
|
this, NS_ConvertUTF16toUTF8(aStr).get()));
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2009-10-16 13:12:09 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2011-02-23 20:25:11 +03:00
|
|
|
TISInputSourceWrapper::TranslateToChar(UInt32 aKeyCode, UInt32 aModifiers,
|
|
|
|
UInt32 aKbType)
|
|
|
|
{
|
|
|
|
nsAutoString str;
|
|
|
|
if (!TranslateToString(aKeyCode, aModifiers, aKbType, str) ||
|
|
|
|
str.Length() != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
return static_cast<uint32_t>(str.CharAt(0));
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
|
|
|
|
2017-03-01 04:58:55 +03:00
|
|
|
bool
|
|
|
|
TISInputSourceWrapper::IsDeadKey(UInt32 aKeyCode,
|
|
|
|
UInt32 aModifiers,
|
|
|
|
UInt32 aKbType)
|
|
|
|
{
|
|
|
|
const UCKeyboardLayout* UCKey = GetUCKeyboardLayout();
|
|
|
|
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TISInputSourceWrapper::IsDeadKey, aKeyCode=0x%X, "
|
|
|
|
"aModifiers=0x%X, aKbType=0x%X UCKey=%p\n "
|
|
|
|
"Shift: %s, Ctrl: %s, Opt: %s, Cmd: %s, CapsLock: %s, NumLock: %s",
|
|
|
|
this, static_cast<unsigned int>(aKeyCode), static_cast<unsigned int>(aModifiers),
|
|
|
|
static_cast<unsigned int>(aKbType), UCKey,
|
|
|
|
OnOrOff(aModifiers & shiftKey), OnOrOff(aModifiers & controlKey),
|
|
|
|
OnOrOff(aModifiers & optionKey), OnOrOff(aModifiers & cmdKey),
|
|
|
|
OnOrOff(aModifiers & alphaLock),
|
|
|
|
OnOrOff(aModifiers & kEventKeyModifierNumLockMask)));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!UCKey)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
UInt32 deadKeyState = 0;
|
|
|
|
UniCharCount len;
|
|
|
|
UniChar chars[5];
|
|
|
|
OSStatus err = ::UCKeyTranslate(UCKey, aKeyCode,
|
|
|
|
kUCKeyActionDown, aModifiers >> 8,
|
|
|
|
aKbType, 0,
|
|
|
|
&deadKeyState, 5, &len, chars);
|
|
|
|
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TISInputSourceWrapper::IsDeadKey, err=0x%X, "
|
|
|
|
"len=%" PRIuSIZE ", deadKeyState=%u",
|
|
|
|
this, static_cast<int>(err), len, deadKeyState));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(err != noErr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return deadKeyState != 0;
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByInputSourceID(const char* aID)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
if (!aID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CFStringRef idstr = ::CFStringCreateWithCString(kCFAllocatorDefault, aID,
|
|
|
|
kCFStringEncodingASCII);
|
|
|
|
InitByInputSourceID(idstr);
|
|
|
|
::CFRelease(idstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-20 12:19:05 +03:00
|
|
|
TISInputSourceWrapper::InitByInputSourceID(const nsString& aID)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
if (aID.IsEmpty())
|
|
|
|
return;
|
|
|
|
CFStringRef idstr = ::CFStringCreateWithCharacters(kCFAllocatorDefault,
|
2013-10-10 20:59:40 +04:00
|
|
|
reinterpret_cast<const UniChar*>(aID.get()),
|
|
|
|
aID.Length());
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByInputSourceID(idstr);
|
|
|
|
::CFRelease(idstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByInputSourceID(const CFStringRef aID)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
if (!aID)
|
|
|
|
return;
|
|
|
|
const void* keys[] = { kTISPropertyInputSourceID };
|
|
|
|
const void* values[] = { aID };
|
|
|
|
CFDictionaryRef filter =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1, NULL, NULL);
|
|
|
|
NS_ASSERTION(filter, "failed to create the filter");
|
|
|
|
mInputSourceList = ::TISCreateInputSourceList(filter, true);
|
|
|
|
::CFRelease(filter);
|
|
|
|
if (::CFArrayGetCount(mInputSourceList) > 0) {
|
|
|
|
mInputSource = static_cast<TISInputSourceRef>(
|
|
|
|
const_cast<void *>(::CFArrayGetValueAtIndex(mInputSourceList, 0)));
|
2012-10-16 05:43:50 +04:00
|
|
|
if (IsKeyboardLayout()) {
|
|
|
|
mKeyboardLayout = mInputSource;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-23 20:25:11 +03:00
|
|
|
TISInputSourceWrapper::InitByLayoutID(SInt32 aLayoutID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aOverrideKeyboard)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-02-23 20:25:11 +03:00
|
|
|
// NOTE: Doument new layout IDs in TextInputHandler.h when you add ones.
|
2009-10-01 06:52:50 +04:00
|
|
|
switch (aLayoutID) {
|
|
|
|
case 0:
|
|
|
|
InitByInputSourceID("com.apple.keylayout.US");
|
|
|
|
break;
|
2012-03-30 07:37:40 +04:00
|
|
|
case 1:
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByInputSourceID("com.apple.keylayout.Greek");
|
|
|
|
break;
|
2012-03-30 07:37:40 +04:00
|
|
|
case 2:
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByInputSourceID("com.apple.keylayout.German");
|
|
|
|
break;
|
2012-03-30 07:37:40 +04:00
|
|
|
case 3:
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByInputSourceID("com.apple.keylayout.Swedish-Pro");
|
|
|
|
break;
|
2012-03-30 07:37:40 +04:00
|
|
|
case 4:
|
|
|
|
InitByInputSourceID("com.apple.keylayout.DVORAK-QWERTYCMD");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
InitByInputSourceID("com.apple.keylayout.Thai");
|
|
|
|
break;
|
2013-12-18 11:02:46 +04:00
|
|
|
case 6:
|
|
|
|
InitByInputSourceID("com.apple.keylayout.Arabic");
|
|
|
|
break;
|
|
|
|
case 7:
|
2016-10-14 06:06:30 +03:00
|
|
|
InitByInputSourceID("com.apple.keylayout.ArabicPC");
|
2013-12-18 11:02:46 +04:00
|
|
|
break;
|
|
|
|
case 8:
|
2016-10-14 06:06:30 +03:00
|
|
|
InitByInputSourceID("com.apple.keylayout.French");
|
2013-12-18 11:02:46 +04:00
|
|
|
break;
|
|
|
|
case 9:
|
2016-10-14 06:06:30 +03:00
|
|
|
InitByInputSourceID("com.apple.keylayout.Hebrew");
|
2013-12-18 11:02:46 +04:00
|
|
|
break;
|
|
|
|
case 10:
|
2016-10-14 06:06:30 +03:00
|
|
|
InitByInputSourceID("com.apple.keylayout.Lithuanian");
|
2013-12-18 11:02:46 +04:00
|
|
|
break;
|
|
|
|
case 11:
|
2016-10-14 06:06:30 +03:00
|
|
|
InitByInputSourceID("com.apple.keylayout.Norwegian");
|
|
|
|
break;
|
|
|
|
case 12:
|
2013-12-18 11:02:46 +04:00
|
|
|
InitByInputSourceID("com.apple.keylayout.Spanish");
|
|
|
|
break;
|
2011-02-23 20:25:11 +03:00
|
|
|
default:
|
|
|
|
Clear();
|
|
|
|
break;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
2011-02-23 20:25:11 +03:00
|
|
|
mOverrideKeyboard = aOverrideKeyboard;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByCurrentInputSource()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = ::TISCopyCurrentKeyboardInputSource();
|
2012-10-16 05:43:50 +04:00
|
|
|
mKeyboardLayout = ::TISCopyInputMethodKeyboardLayoutOverride();
|
|
|
|
if (!mKeyboardLayout) {
|
|
|
|
mKeyboardLayout = ::TISCopyCurrentKeyboardLayoutInputSource();
|
|
|
|
}
|
|
|
|
// If this causes composition, the current keyboard layout may input non-ASCII
|
|
|
|
// characters such as Japanese Kana characters or Hangul characters.
|
|
|
|
// However, we need to set ASCII characters to DOM key events for consistency
|
|
|
|
// with other platforms.
|
|
|
|
if (IsOpenedIMEMode()) {
|
|
|
|
TISInputSourceWrapper tis(mKeyboardLayout);
|
|
|
|
if (!tis.IsASCIICapable()) {
|
|
|
|
mKeyboardLayout =
|
|
|
|
::TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
|
|
|
}
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByCurrentKeyboardLayout()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = ::TISCopyCurrentKeyboardLayoutInputSource();
|
2012-10-16 05:43:50 +04:00
|
|
|
mKeyboardLayout = mInputSource;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByCurrentASCIICapableInputSource()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = ::TISCopyCurrentASCIICapableKeyboardInputSource();
|
2012-10-16 05:43:50 +04:00
|
|
|
mKeyboardLayout = ::TISCopyInputMethodKeyboardLayoutOverride();
|
|
|
|
if (mKeyboardLayout) {
|
|
|
|
TISInputSourceWrapper tis(mKeyboardLayout);
|
|
|
|
if (!tis.IsASCIICapable()) {
|
|
|
|
mKeyboardLayout = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mKeyboardLayout) {
|
|
|
|
mKeyboardLayout =
|
|
|
|
::TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByCurrentASCIICapableKeyboardLayout()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = ::TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
2012-10-16 05:43:50 +04:00
|
|
|
mKeyboardLayout = mInputSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TISInputSourceWrapper::InitByCurrentInputMethodKeyboardLayoutOverride()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = ::TISCopyInputMethodKeyboardLayoutOverride();
|
|
|
|
mKeyboardLayout = mInputSource;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByTISInputSourceRef(TISInputSourceRef aInputSource)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = aInputSource;
|
2012-10-16 05:43:50 +04:00
|
|
|
if (IsKeyboardLayout()) {
|
|
|
|
mKeyboardLayout = mInputSource;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::InitByLanguage(CFStringRef aLanguage)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mInputSource = ::TISCopyInputSourceForLanguage(aLanguage);
|
2012-10-16 05:43:50 +04:00
|
|
|
if (IsKeyboardLayout()) {
|
|
|
|
mKeyboardLayout = mInputSource;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const UCKeyboardLayout*
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetUCKeyboardLayout()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2012-10-16 05:43:50 +04:00
|
|
|
NS_ENSURE_TRUE(mKeyboardLayout, nullptr);
|
2009-10-16 13:12:09 +04:00
|
|
|
if (mUCKeyboardLayout) {
|
|
|
|
return mUCKeyboardLayout;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
CFDataRef uchr = static_cast<CFDataRef>(
|
2012-10-16 05:43:50 +04:00
|
|
|
::TISGetInputSourceProperty(mKeyboardLayout,
|
2009-10-01 06:52:50 +04:00
|
|
|
kTISPropertyUnicodeKeyLayoutData));
|
|
|
|
|
|
|
|
// We should be always able to get the layout here.
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(uchr, nullptr);
|
2009-10-16 13:12:09 +04:00
|
|
|
mUCKeyboardLayout =
|
|
|
|
reinterpret_cast<const UCKeyboardLayout*>(CFDataGetBytePtr(uchr));
|
|
|
|
return mUCKeyboardLayout;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetBoolProperty(const CFStringRef aKey)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
CFBooleanRef ret = static_cast<CFBooleanRef>(
|
|
|
|
::TISGetInputSourceProperty(mInputSource, aKey));
|
|
|
|
return ::CFBooleanGetValue(ret);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetStringProperty(const CFStringRef aKey,
|
|
|
|
CFStringRef &aStr)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
aStr = static_cast<CFStringRef>(
|
|
|
|
::TISGetInputSourceProperty(mInputSource, aKey));
|
2012-07-30 18:20:58 +04:00
|
|
|
return aStr != nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetStringProperty(const CFStringRef aKey,
|
|
|
|
nsAString &aStr)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
CFStringRef str;
|
|
|
|
GetStringProperty(aKey, str);
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GetStringForNSString((const NSString*)str, aStr);
|
2009-10-01 06:52:50 +04:00
|
|
|
return !aStr.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::IsOpenedIMEMode()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(mInputSource, false);
|
2009-10-01 06:52:50 +04:00
|
|
|
if (!IsIMEMode())
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2009-10-01 06:52:50 +04:00
|
|
|
return !IsASCIICapable();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::IsIMEMode()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(mInputSource, false);
|
2009-10-01 06:52:50 +04:00
|
|
|
CFStringRef str;
|
|
|
|
GetInputSourceType(str);
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(str, false);
|
2009-10-01 06:52:50 +04:00
|
|
|
return ::CFStringCompare(kTISTypeKeyboardInputMode,
|
|
|
|
str, 0) == kCFCompareEqualTo;
|
|
|
|
}
|
|
|
|
|
2012-10-16 05:43:50 +04:00
|
|
|
bool
|
|
|
|
TISInputSourceWrapper::IsKeyboardLayout()
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mInputSource, false);
|
|
|
|
CFStringRef str;
|
|
|
|
GetInputSourceType(str);
|
|
|
|
NS_ENSURE_TRUE(str, false);
|
|
|
|
return ::CFStringCompare(kTISTypeKeyboardLayout,
|
|
|
|
str, 0) == kCFCompareEqualTo;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetLanguageList(CFArrayRef &aLanguageList)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(mInputSource, false);
|
2009-10-01 06:52:50 +04:00
|
|
|
aLanguageList = static_cast<CFArrayRef>(
|
|
|
|
::TISGetInputSourceProperty(mInputSource,
|
|
|
|
kTISPropertyInputSourceLanguages));
|
2012-07-30 18:20:58 +04:00
|
|
|
return aLanguageList != nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetPrimaryLanguage(CFStringRef &aPrimaryLanguage)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(mInputSource, false);
|
2009-10-01 06:52:50 +04:00
|
|
|
CFArrayRef langList;
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(GetLanguageList(langList), false);
|
2009-10-01 06:52:50 +04:00
|
|
|
if (::CFArrayGetCount(langList) == 0)
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2009-10-01 06:52:50 +04:00
|
|
|
aPrimaryLanguage =
|
|
|
|
static_cast<CFStringRef>(::CFArrayGetValueAtIndex(langList, 0));
|
2012-07-30 18:20:58 +04:00
|
|
|
return aPrimaryLanguage != nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::GetPrimaryLanguage(nsAString &aPrimaryLanguage)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(mInputSource, false);
|
2009-10-01 06:52:50 +04:00
|
|
|
CFStringRef primaryLanguage;
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(GetPrimaryLanguage(primaryLanguage), false);
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GetStringForNSString((const NSString*)primaryLanguage,
|
|
|
|
aPrimaryLanguage);
|
2009-10-01 06:52:50 +04:00
|
|
|
return !aPrimaryLanguage.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::IsForRTLLanguage()
|
2009-10-16 13:12:09 +04:00
|
|
|
{
|
|
|
|
if (mIsRTL < 0) {
|
|
|
|
// Get the input character of the 'A' key of ANSI keyboard layout.
|
|
|
|
nsAutoString str;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ret = TranslateToString(kVK_ANSI_A, 0, eKbdType_ANSI, str);
|
2009-10-16 13:12:09 +04:00
|
|
|
NS_ENSURE_TRUE(ret, ret);
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = str.IsEmpty() ? char16_t(0) : str.CharAt(0);
|
2013-08-10 22:41:00 +04:00
|
|
|
mIsRTL = UCS2_CHAR_IS_BIDI(ch);
|
2009-10-16 13:12:09 +04:00
|
|
|
}
|
|
|
|
return mIsRTL != 0;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-10-16 05:43:50 +04:00
|
|
|
TISInputSourceWrapper::IsInitializedByCurrentInputSource()
|
2009-10-16 13:12:09 +04:00
|
|
|
{
|
2012-10-16 05:43:50 +04:00
|
|
|
return mInputSource == ::TISCopyCurrentKeyboardInputSource();
|
2009-10-16 13:12:09 +04:00
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::Select()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
if (!mInputSource)
|
|
|
|
return;
|
|
|
|
::TISSelectInputSource(mInputSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper::Clear()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-07-21 04:33:16 +04:00
|
|
|
// Clear() is always called when TISInputSourceWrappper is created.
|
2016-06-16 11:14:34 +03:00
|
|
|
EnsureToLogAllKeyboardLayoutsAndIMEs();
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
if (mInputSourceList) {
|
|
|
|
::CFRelease(mInputSourceList);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mInputSourceList = nullptr;
|
|
|
|
mInputSource = nullptr;
|
2012-10-16 05:43:50 +04:00
|
|
|
mKeyboardLayout = nullptr;
|
2009-10-16 13:12:09 +04:00
|
|
|
mIsRTL = -1;
|
2012-07-30 18:20:58 +04:00
|
|
|
mUCKeyboardLayout = nullptr;
|
2011-10-01 04:20:33 +04:00
|
|
|
mOverrideKeyboard = false;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
bool
|
|
|
|
TISInputSourceWrapper::IsPrintableKeyEvent(NSEvent* aNativeKeyEvent) const
|
2011-02-23 20:25:11 +03:00
|
|
|
{
|
2012-07-21 03:24:48 +04:00
|
|
|
UInt32 nativeKeyCode = [aNativeKeyEvent keyCode];
|
|
|
|
|
|
|
|
bool isPrintableKey = !TextInputHandler::IsSpecialGeckoKey(nativeKeyCode);
|
2012-08-31 07:55:23 +04:00
|
|
|
if (isPrintableKey &&
|
|
|
|
[aNativeKeyEvent type] != NSKeyDown &&
|
2012-08-31 08:22:26 +04:00
|
|
|
[aNativeKeyEvent type] != NSKeyUp) {
|
2012-08-31 07:55:23 +04:00
|
|
|
NS_WARNING("Why the printable key doesn't cause NSKeyDown or NSKeyUp?");
|
|
|
|
isPrintableKey = false;
|
|
|
|
}
|
2016-03-16 07:47:50 +03:00
|
|
|
return isPrintableKey;
|
|
|
|
}
|
2012-07-21 03:24:48 +04:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
UInt32
|
|
|
|
TISInputSourceWrapper::GetKbdType() const
|
|
|
|
{
|
|
|
|
// If a keyboard layout override is set, we also need to force the keyboard
|
|
|
|
// type to something ANSI to avoid test failures on machines with JIS
|
|
|
|
// keyboards (since the pair of keyboard layout and physical keyboard type
|
|
|
|
// form the actual key layout). This assumes that the test setting the
|
|
|
|
// override was written assuming an ANSI keyboard.
|
|
|
|
return mOverrideKeyboard ? eKbdType_ANSI : ::LMGetKbdType();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TISInputSourceWrapper::ComputeInsertStringForCharCode(
|
|
|
|
NSEvent* aNativeKeyEvent,
|
|
|
|
const WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
const nsAString* aInsertString,
|
|
|
|
nsAString& aResult)
|
|
|
|
{
|
2012-07-21 03:24:48 +04:00
|
|
|
if (aInsertString) {
|
|
|
|
// If the caller expects that the aInsertString will be input, we shouldn't
|
|
|
|
// change it.
|
2016-03-16 07:47:50 +03:00
|
|
|
aResult = *aInsertString;
|
|
|
|
} else if (IsPrintableKeyEvent(aNativeKeyEvent)) {
|
2012-10-16 05:43:50 +04:00
|
|
|
// If IME is open, [aNativeKeyEvent characters] may be a character
|
|
|
|
// which will be appended to the composition string. However, especially,
|
|
|
|
// while IME is disabled, most users and developers expect the key event
|
2016-03-16 07:47:50 +03:00
|
|
|
// works as IME closed. So, we should compute the aResult with
|
2012-10-16 05:43:50 +04:00
|
|
|
// the ASCII capable keyboard layout.
|
|
|
|
// NOTE: Such keyboard layouts typically change the layout to its ASCII
|
|
|
|
// capable layout when Command key is pressed. And we don't worry
|
|
|
|
// when Control key is pressed too because it causes inputting
|
|
|
|
// control characters.
|
2016-03-16 07:47:50 +03:00
|
|
|
// Additionally, if the key event doesn't input any text, the event may be
|
|
|
|
// dead key event. In this case, the charCode value should be the dead
|
|
|
|
// character.
|
2016-03-16 07:47:50 +03:00
|
|
|
UInt32 nativeKeyCode = [aNativeKeyEvent keyCode];
|
2016-03-16 07:47:50 +03:00
|
|
|
if ((!aKeyEvent.IsMeta() && !aKeyEvent.IsControl() && IsOpenedIMEMode()) ||
|
|
|
|
![[aNativeKeyEvent characters] length]) {
|
2012-10-16 05:43:50 +04:00
|
|
|
UInt32 state =
|
|
|
|
nsCocoaUtils::ConvertToCarbonModifier([aNativeKeyEvent modifierFlags]);
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t ch = TranslateToChar(nativeKeyCode, state, GetKbdType());
|
2012-10-16 05:43:50 +04:00
|
|
|
if (ch) {
|
2016-03-16 07:47:50 +03:00
|
|
|
aResult = ch;
|
2012-10-16 05:43:50 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the caller isn't sure what string will be input, let's use
|
|
|
|
// characters of NSEvent.
|
2016-03-16 07:47:50 +03:00
|
|
|
nsCocoaUtils::GetStringForNSString([aNativeKeyEvent characters], aResult);
|
2012-10-16 05:43:50 +04:00
|
|
|
}
|
|
|
|
|
2012-07-21 03:24:48 +04:00
|
|
|
// If control key is pressed and the eventChars is a non-printable control
|
|
|
|
// character, we should convert it to ASCII alphabet.
|
|
|
|
if (aKeyEvent.IsControl() &&
|
2016-03-16 07:47:50 +03:00
|
|
|
!aResult.IsEmpty() && aResult[0] <= char16_t(26)) {
|
|
|
|
aResult = (aKeyEvent.IsShift() ^ aKeyEvent.IsCapsLocked()) ?
|
|
|
|
static_cast<char16_t>(aResult[0] + ('A' - 1)) :
|
|
|
|
static_cast<char16_t>(aResult[0] + ('a' - 1));
|
2012-07-21 03:24:48 +04:00
|
|
|
}
|
|
|
|
// If Meta key is pressed, it may cause to switch the keyboard layout like
|
|
|
|
// Arabic, Russian, Hebrew, Greek and Dvorak-QWERTY.
|
|
|
|
else if (aKeyEvent.IsMeta() &&
|
|
|
|
!(aKeyEvent.IsControl() || aKeyEvent.IsAlt())) {
|
2016-03-16 07:47:50 +03:00
|
|
|
UInt32 kbType = GetKbdType();
|
2012-07-21 03:24:48 +04:00
|
|
|
UInt32 numLockState =
|
|
|
|
aKeyEvent.IsNumLocked() ? kEventKeyModifierNumLockMask : 0;
|
|
|
|
UInt32 capsLockState = aKeyEvent.IsCapsLocked() ? alphaLock : 0;
|
|
|
|
UInt32 shiftState = aKeyEvent.IsShift() ? shiftKey : 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t uncmdedChar =
|
2012-07-21 03:24:48 +04:00
|
|
|
TranslateToChar(nativeKeyCode, numLockState, kbType);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t cmdedChar =
|
2012-07-21 03:24:48 +04:00
|
|
|
TranslateToChar(nativeKeyCode, cmdKey | numLockState, kbType);
|
|
|
|
// If we can make a good guess at the characters that the user would
|
|
|
|
// expect this key combination to produce (with and without Shift) then
|
|
|
|
// use those characters. This also corrects for CapsLock.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t ch = 0;
|
2012-07-21 03:24:48 +04:00
|
|
|
if (uncmdedChar == cmdedChar) {
|
|
|
|
// The characters produced with Command seem similar to those without
|
|
|
|
// Command.
|
|
|
|
ch = TranslateToChar(nativeKeyCode,
|
|
|
|
shiftState | capsLockState | numLockState, kbType);
|
|
|
|
} else {
|
|
|
|
TISInputSourceWrapper USLayout("com.apple.keylayout.US");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t uncmdedUSChar =
|
2012-07-21 03:24:48 +04:00
|
|
|
USLayout.TranslateToChar(nativeKeyCode, numLockState, kbType);
|
|
|
|
// If it looks like characters from US keyboard layout when Command key
|
|
|
|
// is pressed, we should compute a character in the layout.
|
|
|
|
if (uncmdedUSChar == cmdedChar) {
|
|
|
|
ch = USLayout.TranslateToChar(nativeKeyCode,
|
|
|
|
shiftState | capsLockState | numLockState, kbType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a more preferred character for the commanded key event,
|
|
|
|
// we should use it.
|
|
|
|
if (ch) {
|
2016-03-16 07:47:50 +03:00
|
|
|
aResult = ch;
|
2012-07-21 03:24:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-06 07:16:55 +04:00
|
|
|
// Remove control characters which shouldn't be inputted on editor.
|
|
|
|
// XXX Currently, we don't find any cases inserting control characters with
|
|
|
|
// printable character. So, just checking first character is enough.
|
2016-03-16 07:47:50 +03:00
|
|
|
if (!aResult.IsEmpty() && IsControlChar(aResult[0])) {
|
|
|
|
aResult.Truncate();
|
2013-12-06 07:16:55 +04:00
|
|
|
}
|
2016-03-16 07:47:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TISInputSourceWrapper::InitKeyEvent(NSEvent *aNativeKeyEvent,
|
|
|
|
WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
const nsAString *aInsertString)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TISInputSourceWrapper::InitKeyEvent, aNativeKeyEvent=%p, "
|
|
|
|
"aKeyEvent.mMessage=%s, aInsertString=%p, IsOpenedIMEMode()=%s",
|
|
|
|
this, aNativeKeyEvent, GetGeckoKeyEventType(aKeyEvent), aInsertString,
|
|
|
|
TrueOrFalse(IsOpenedIMEMode())));
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aNativeKeyEvent, );
|
|
|
|
|
|
|
|
nsCocoaUtils::InitInputEvent(aKeyEvent, aNativeKeyEvent);
|
|
|
|
|
|
|
|
// This is used only while dispatching the event (which is a synchronous
|
|
|
|
// call), so there is no need to retain and release this data.
|
|
|
|
aKeyEvent.mNativeKeyEvent = aNativeKeyEvent;
|
|
|
|
|
|
|
|
// Fill in fields used for Cocoa NPAPI plugins
|
|
|
|
if ([aNativeKeyEvent type] == NSKeyDown ||
|
|
|
|
[aNativeKeyEvent type] == NSKeyUp) {
|
|
|
|
aKeyEvent.mNativeKeyCode = [aNativeKeyEvent keyCode];
|
|
|
|
aKeyEvent.mNativeModifierFlags = [aNativeKeyEvent modifierFlags];
|
|
|
|
nsAutoString nativeChars;
|
|
|
|
nsCocoaUtils::GetStringForNSString([aNativeKeyEvent characters], nativeChars);
|
|
|
|
aKeyEvent.mNativeCharacters.Assign(nativeChars);
|
|
|
|
nsAutoString nativeCharsIgnoringModifiers;
|
|
|
|
nsCocoaUtils::GetStringForNSString([aNativeKeyEvent charactersIgnoringModifiers], nativeCharsIgnoringModifiers);
|
|
|
|
aKeyEvent.mNativeCharactersIgnoringModifiers.Assign(nativeCharsIgnoringModifiers);
|
|
|
|
} else if ([aNativeKeyEvent type] == NSFlagsChanged) {
|
|
|
|
aKeyEvent.mNativeKeyCode = [aNativeKeyEvent keyCode];
|
|
|
|
aKeyEvent.mNativeModifierFlags = [aNativeKeyEvent modifierFlags];
|
|
|
|
}
|
|
|
|
|
2016-04-18 17:09:02 +03:00
|
|
|
aKeyEvent.mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2016-03-16 07:47:50 +03:00
|
|
|
|
|
|
|
UInt32 kbType = GetKbdType();
|
|
|
|
UInt32 nativeKeyCode = [aNativeKeyEvent keyCode];
|
2013-12-06 07:16:55 +04:00
|
|
|
|
2016-05-12 11:13:49 +03:00
|
|
|
aKeyEvent.mKeyCode =
|
2012-07-21 03:24:48 +04:00
|
|
|
ComputeGeckoKeyCode(nativeKeyCode, kbType, aKeyEvent.IsMeta());
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2012-07-21 03:24:48 +04:00
|
|
|
switch (nativeKeyCode) {
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Command:
|
|
|
|
case kVK_Shift:
|
|
|
|
case kVK_Option:
|
|
|
|
case kVK_Control:
|
2017-02-08 15:04:22 +03:00
|
|
|
aKeyEvent.mLocation = eKeyLocationLeft;
|
2012-05-03 12:35:02 +04:00
|
|
|
break;
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_RightCommand:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_RightShift:
|
|
|
|
case kVK_RightOption:
|
|
|
|
case kVK_RightControl:
|
2017-02-08 15:04:22 +03:00
|
|
|
aKeyEvent.mLocation = eKeyLocationRight;
|
2012-05-03 12:35:02 +04:00
|
|
|
break;
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_ANSI_Keypad0:
|
|
|
|
case kVK_ANSI_Keypad1:
|
|
|
|
case kVK_ANSI_Keypad2:
|
|
|
|
case kVK_ANSI_Keypad3:
|
|
|
|
case kVK_ANSI_Keypad4:
|
|
|
|
case kVK_ANSI_Keypad5:
|
|
|
|
case kVK_ANSI_Keypad6:
|
|
|
|
case kVK_ANSI_Keypad7:
|
|
|
|
case kVK_ANSI_Keypad8:
|
|
|
|
case kVK_ANSI_Keypad9:
|
|
|
|
case kVK_ANSI_KeypadMultiply:
|
|
|
|
case kVK_ANSI_KeypadPlus:
|
|
|
|
case kVK_ANSI_KeypadMinus:
|
|
|
|
case kVK_ANSI_KeypadDecimal:
|
|
|
|
case kVK_ANSI_KeypadDivide:
|
|
|
|
case kVK_ANSI_KeypadEquals:
|
|
|
|
case kVK_ANSI_KeypadEnter:
|
2013-08-24 08:53:01 +04:00
|
|
|
case kVK_JIS_KeypadComma:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Powerbook_KeypadEnter:
|
2017-02-08 15:04:22 +03:00
|
|
|
aKeyEvent.mLocation = eKeyLocationNumpad;
|
2012-05-03 12:35:02 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-02-08 15:04:22 +03:00
|
|
|
aKeyEvent.mLocation = eKeyLocationStandard;
|
2012-05-03 12:35:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:17:33 +04:00
|
|
|
aKeyEvent.mIsRepeat =
|
|
|
|
([aNativeKeyEvent type] == NSKeyDown) ? [aNativeKeyEvent isARepeat] : false;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TISInputSourceWrapper::InitKeyEvent, "
|
|
|
|
"shift=%s, ctrl=%s, alt=%s, meta=%s",
|
2012-04-25 07:00:02 +04:00
|
|
|
this, OnOrOff(aKeyEvent.IsShift()), OnOrOff(aKeyEvent.IsControl()),
|
|
|
|
OnOrOff(aKeyEvent.IsAlt()), OnOrOff(aKeyEvent.IsMeta())));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
if (IsPrintableKeyEvent(aNativeKeyEvent)) {
|
2013-12-10 20:14:54 +04:00
|
|
|
aKeyEvent.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
|
|
|
|
// If insertText calls this method, let's use the string.
|
|
|
|
if (aInsertString && !aInsertString->IsEmpty() &&
|
|
|
|
!IsControlChar((*aInsertString)[0])) {
|
|
|
|
aKeyEvent.mKeyValue = *aInsertString;
|
|
|
|
}
|
|
|
|
// If meta key is pressed, the printable key layout may be switched from
|
|
|
|
// non-ASCII capable layout to ASCII capable, or from Dvorak to QWERTY.
|
|
|
|
// KeyboardEvent.key value should be the switched layout's character.
|
|
|
|
else if (aKeyEvent.IsMeta()) {
|
|
|
|
nsCocoaUtils::GetStringForNSString([aNativeKeyEvent characters],
|
|
|
|
aKeyEvent.mKeyValue);
|
|
|
|
}
|
|
|
|
// If control key is pressed, some keys may produce printable character via
|
|
|
|
// [aNativeKeyEvent characters]. Otherwise, translate input character of
|
|
|
|
// the key without control key.
|
|
|
|
else if (aKeyEvent.IsControl()) {
|
2017-03-01 04:58:55 +03:00
|
|
|
NSUInteger cocoaState =
|
|
|
|
[aNativeKeyEvent modifierFlags] & ~NSControlKeyMask;
|
|
|
|
UInt32 carbonState = nsCocoaUtils::ConvertToCarbonModifier(cocoaState);
|
|
|
|
if (IsDeadKey(nativeKeyCode, carbonState, kbType)) {
|
|
|
|
aKeyEvent.mKeyNameIndex = KEY_NAME_INDEX_Dead;
|
|
|
|
} else {
|
|
|
|
aKeyEvent.mKeyValue = TranslateToChar(nativeKeyCode, carbonState, kbType);
|
|
|
|
if (!aKeyEvent.mKeyValue.IsEmpty() &&
|
|
|
|
IsControlChar(aKeyEvent.mKeyValue[0])) {
|
|
|
|
// Don't expose control character to the web.
|
|
|
|
aKeyEvent.mKeyValue.Truncate();
|
|
|
|
}
|
2013-12-10 20:14:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, KeyboardEvent.key expose
|
|
|
|
// [aNativeKeyEvent characters] value. However, if IME is open and the
|
|
|
|
// keyboard layout isn't ASCII capable, exposing the non-ASCII character
|
|
|
|
// doesn't match with other platform's behavior. For the compatibility
|
|
|
|
// with other platform's Gecko, we need to set a translated character.
|
|
|
|
else if (IsOpenedIMEMode()) {
|
2013-04-24 07:49:47 +04:00
|
|
|
UInt32 state =
|
|
|
|
nsCocoaUtils::ConvertToCarbonModifier([aNativeKeyEvent modifierFlags]);
|
2013-12-10 20:14:54 +04:00
|
|
|
aKeyEvent.mKeyValue = TranslateToChar(nativeKeyCode, state, kbType);
|
|
|
|
} else {
|
|
|
|
nsCocoaUtils::GetStringForNSString([aNativeKeyEvent characters],
|
|
|
|
aKeyEvent.mKeyValue);
|
2016-03-16 07:50:01 +03:00
|
|
|
// If the key value is empty, the event may be a dead key event.
|
|
|
|
// If TranslateToChar() returns non-zero value, that means that
|
|
|
|
// the key may input a character with different dead key state.
|
|
|
|
if (aKeyEvent.mKeyValue.IsEmpty()) {
|
|
|
|
NSUInteger cocoaState = [aNativeKeyEvent modifierFlags];
|
|
|
|
UInt32 carbonState = nsCocoaUtils::ConvertToCarbonModifier(cocoaState);
|
|
|
|
if (TranslateToChar(nativeKeyCode, carbonState, kbType)) {
|
|
|
|
aKeyEvent.mKeyNameIndex = KEY_NAME_INDEX_Dead;
|
|
|
|
}
|
|
|
|
}
|
2013-04-24 07:49:47 +04:00
|
|
|
}
|
2013-12-10 20:14:54 +04:00
|
|
|
|
|
|
|
// Last resort. If .key value becomes empty string, we should use
|
|
|
|
// charactersIgnoringModifiers, if it's available.
|
2016-03-16 07:50:01 +03:00
|
|
|
if (aKeyEvent.mKeyNameIndex == KEY_NAME_INDEX_USE_STRING &&
|
|
|
|
(aKeyEvent.mKeyValue.IsEmpty() ||
|
|
|
|
IsControlChar(aKeyEvent.mKeyValue[0]))) {
|
2013-12-10 20:14:54 +04:00
|
|
|
nsCocoaUtils::GetStringForNSString(
|
|
|
|
[aNativeKeyEvent charactersIgnoringModifiers], aKeyEvent.mKeyValue);
|
|
|
|
// But don't expose it if it's a control character.
|
|
|
|
if (!aKeyEvent.mKeyValue.IsEmpty() &&
|
|
|
|
IsControlChar(aKeyEvent.mKeyValue[0])) {
|
|
|
|
aKeyEvent.mKeyValue.Truncate();
|
|
|
|
}
|
2013-04-24 07:49:47 +04:00
|
|
|
}
|
2013-12-10 20:14:54 +04:00
|
|
|
} else {
|
|
|
|
// Compute the key for non-printable keys and some special printable keys.
|
|
|
|
aKeyEvent.mKeyNameIndex = ComputeGeckoKeyNameIndex(nativeKeyCode);
|
2013-04-24 07:49:47 +04:00
|
|
|
}
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2017-02-27 12:04:30 +03:00
|
|
|
aKeyEvent.mCodeNameIndex = ComputeGeckoCodeNameIndex(nativeKeyCode, kbType);
|
2014-05-25 06:08:59 +04:00
|
|
|
MOZ_ASSERT(aKeyEvent.mCodeNameIndex != CODE_NAME_INDEX_USE_STRING);
|
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-16 07:47:50 +03:00
|
|
|
TISInputSourceWrapper::WillDispatchKeyboardEvent(
|
|
|
|
NSEvent* aNativeKeyEvent,
|
|
|
|
const nsAString* aInsertString,
|
|
|
|
WidgetKeyboardEvent& aKeyEvent)
|
2011-02-23 20:25:11 +03:00
|
|
|
{
|
2012-05-26 06:35:58 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
2012-10-16 05:43:50 +04:00
|
|
|
|
2016-03-19 14:57:11 +03:00
|
|
|
// Nothing to do here if the native key event is neither NSKeyDown nor
|
|
|
|
// NSKeyUp because accessing [aNativeKeyEvent characters] causes throwing
|
|
|
|
// an exception.
|
|
|
|
if ([aNativeKeyEvent type] != NSKeyDown &&
|
|
|
|
[aNativeKeyEvent type] != NSKeyUp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
UInt32 kbType = GetKbdType();
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Info)) {
|
2012-05-26 06:35:58 +04:00
|
|
|
nsAutoString chars;
|
|
|
|
nsCocoaUtils::GetStringForNSString([aNativeKeyEvent characters], chars);
|
|
|
|
NS_ConvertUTF16toUTF8 utf8Chars(chars);
|
2016-05-13 10:06:18 +03:00
|
|
|
char16_t uniChar = static_cast<char16_t>(aKeyEvent.mCharCode);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-03-16 07:47:50 +03:00
|
|
|
("%p TISInputSourceWrapper::WillDispatchKeyboardEvent, "
|
|
|
|
"aNativeKeyEvent=%p, [aNativeKeyEvent characters]=\"%s\", "
|
2016-05-13 10:06:18 +03:00
|
|
|
"aKeyEvent={ mMessage=%s, mCharCode=0x%X(%s) }, kbType=0x%X, "
|
2016-03-16 07:47:50 +03:00
|
|
|
"IsOpenedIMEMode()=%s",
|
|
|
|
this, aNativeKeyEvent, utf8Chars.get(),
|
2016-05-13 10:06:18 +03:00
|
|
|
GetGeckoKeyEventType(aKeyEvent), aKeyEvent.mCharCode,
|
2016-03-16 07:47:50 +03:00
|
|
|
uniChar ? NS_ConvertUTF16toUTF8(&uniChar, 1).get() : "",
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned int>(kbType), TrueOrFalse(IsOpenedIMEMode())));
|
2016-03-16 07:47:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString insertStringForCharCode;
|
|
|
|
ComputeInsertStringForCharCode(aNativeKeyEvent, aKeyEvent, aInsertString,
|
|
|
|
insertStringForCharCode);
|
2016-03-19 14:57:11 +03:00
|
|
|
|
2016-05-13 10:06:18 +03:00
|
|
|
// The mCharCode was set from mKeyValue. However, for example, when Ctrl key
|
2016-03-19 14:57:11 +03:00
|
|
|
// is pressed, its value should indicate an ASCII character for backward
|
|
|
|
// compatibility rather than inputting character without the modifiers.
|
2016-05-13 10:06:18 +03:00
|
|
|
// Therefore, we need to modify mCharCode value here.
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t charCode =
|
|
|
|
insertStringForCharCode.IsEmpty() ? 0 : insertStringForCharCode[0];
|
2016-03-19 14:57:11 +03:00
|
|
|
aKeyEvent.SetCharCode(charCode);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-03-16 07:47:50 +03:00
|
|
|
("%p TISInputSourceWrapper::WillDispatchKeyboardEvent, "
|
2016-05-13 10:06:18 +03:00
|
|
|
"aKeyEvent.mKeyCode=0x%X, aKeyEvent.mCharCode=0x%X",
|
|
|
|
this, aKeyEvent.mKeyCode, aKeyEvent.mCharCode));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
TISInputSourceWrapper USLayout("com.apple.keylayout.US");
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isRomanKeyboardLayout = IsASCIICapable();
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
UInt32 key = [aNativeKeyEvent keyCode];
|
|
|
|
|
|
|
|
// Caps lock and num lock modifier state:
|
|
|
|
UInt32 lockState = 0;
|
|
|
|
if ([aNativeKeyEvent modifierFlags] & NSAlphaShiftKeyMask) {
|
|
|
|
lockState |= alphaLock;
|
|
|
|
}
|
|
|
|
if ([aNativeKeyEvent modifierFlags] & NSNumericPadKeyMask) {
|
|
|
|
lockState |= kEventKeyModifierNumLockMask;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-03-16 07:47:50 +03:00
|
|
|
("%p TISInputSourceWrapper::WillDispatchKeyboardEvent, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"isRomanKeyboardLayout=%s, kbType=0x%X, key=0x%X",
|
|
|
|
this, TrueOrFalse(isRomanKeyboardLayout), static_cast<unsigned int>(kbType),
|
|
|
|
static_cast<unsigned int>(key)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
nsString str;
|
|
|
|
|
|
|
|
// normal chars
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t unshiftedChar = TranslateToChar(key, lockState, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
UInt32 shiftLockMod = shiftKey | lockState;
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t shiftedChar = TranslateToChar(key, shiftLockMod, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
// characters generated with Cmd key
|
|
|
|
// XXX we should remove CapsLock state, which changes characters from
|
|
|
|
// Latin to Cyrillic with Russian layout on 10.4 only when Cmd key
|
|
|
|
// is pressed.
|
|
|
|
UInt32 numState = (lockState & ~alphaLock); // only num lock state
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t uncmdedChar = TranslateToChar(key, numState, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
UInt32 shiftNumMod = numState | shiftKey;
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t uncmdedShiftChar = TranslateToChar(key, shiftNumMod, kbType);
|
|
|
|
uint32_t uncmdedUSChar = USLayout.TranslateToChar(key, numState, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
UInt32 cmdNumMod = cmdKey | numState;
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t cmdedChar = TranslateToChar(key, cmdNumMod, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
UInt32 cmdShiftNumMod = shiftKey | cmdNumMod;
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t cmdedShiftChar = TranslateToChar(key, cmdShiftNumMod, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
// Is the keyboard layout changed by Cmd key?
|
|
|
|
// E.g., Arabic, Russian, Hebrew, Greek and Dvorak-QWERTY.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isCmdSwitchLayout = uncmdedChar != cmdedChar;
|
2011-02-23 20:25:11 +03:00
|
|
|
// Is the keyboard layout for Latin, but Cmd key switches the layout?
|
|
|
|
// I.e., Dvorak-QWERTY
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDvorakQWERTY = isCmdSwitchLayout && isRomanKeyboardLayout;
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
// If the current keyboard is not Dvorak-QWERTY or Cmd is not pressed,
|
|
|
|
// we should append unshiftedChar and shiftedChar for handling the
|
|
|
|
// normal characters. These are the characters that the user is most
|
|
|
|
// likely to associate with this key.
|
|
|
|
if ((unshiftedChar || shiftedChar) &&
|
2012-04-25 07:00:02 +04:00
|
|
|
(!aKeyEvent.IsMeta() || !isDvorakQWERTY)) {
|
2013-10-01 11:22:57 +04:00
|
|
|
AlternativeCharCode altCharCodes(unshiftedChar, shiftedChar);
|
2016-05-12 11:57:21 +03:00
|
|
|
aKeyEvent.mAlternativeCharCodes.AppendElement(altCharCodes);
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-03-16 07:47:50 +03:00
|
|
|
("%p TISInputSourceWrapper::WillDispatchKeyboardEvent, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"aKeyEvent.isMeta=%s, isDvorakQWERTY=%s, "
|
|
|
|
"unshiftedChar=U+%X, shiftedChar=U+%X",
|
2012-04-25 07:00:02 +04:00
|
|
|
this, OnOrOff(aKeyEvent.IsMeta()), TrueOrFalse(isDvorakQWERTY),
|
2011-07-21 04:33:16 +04:00
|
|
|
unshiftedChar, shiftedChar));
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
// Most keyboard layouts provide the same characters in the NSEvents
|
|
|
|
// with Command+Shift as with Command. However, with Command+Shift we
|
|
|
|
// want the character on the second level. e.g. With a US QWERTY
|
|
|
|
// layout, we want "?" when the "/","?" key is pressed with
|
|
|
|
// Command+Shift.
|
|
|
|
|
|
|
|
// On a German layout, the OS gives us '/' with Cmd+Shift+SS(eszett)
|
|
|
|
// even though Cmd+SS is 'SS' and Shift+'SS' is '?'. This '/' seems
|
|
|
|
// like a hack to make the Cmd+"?" event look the same as the Cmd+"?"
|
|
|
|
// event on a US keyboard. The user thinks they are typing Cmd+"?", so
|
2016-05-13 10:06:18 +03:00
|
|
|
// we'll prefer the "?" character, replacing mCharCode with shiftedChar
|
2011-02-23 20:25:11 +03:00
|
|
|
// when Shift is pressed. However, in case there is a layout where the
|
|
|
|
// character unique to Cmd+Shift is the character that the user expects,
|
|
|
|
// we'll send it as an alternative char.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasCmdShiftOnlyChar =
|
2011-02-23 20:25:11 +03:00
|
|
|
cmdedChar != cmdedShiftChar && uncmdedShiftChar != cmdedShiftChar;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t originalCmdedShiftChar = cmdedShiftChar;
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
// If we can make a good guess at the characters that the user would
|
|
|
|
// expect this key combination to produce (with and without Shift) then
|
|
|
|
// use those characters. This also corrects for CapsLock, which was
|
|
|
|
// ignored above.
|
|
|
|
if (!isCmdSwitchLayout) {
|
|
|
|
// The characters produced with Command seem similar to those without
|
|
|
|
// Command.
|
|
|
|
if (unshiftedChar) {
|
|
|
|
cmdedChar = unshiftedChar;
|
|
|
|
}
|
|
|
|
if (shiftedChar) {
|
|
|
|
cmdedShiftChar = shiftedChar;
|
|
|
|
}
|
|
|
|
} else if (uncmdedUSChar == cmdedChar) {
|
|
|
|
// It looks like characters from a US layout are provided when Command
|
|
|
|
// is down.
|
2016-03-16 07:47:50 +03:00
|
|
|
uint32_t ch = USLayout.TranslateToChar(key, lockState, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
if (ch) {
|
|
|
|
cmdedChar = ch;
|
|
|
|
}
|
2016-03-16 07:47:50 +03:00
|
|
|
ch = USLayout.TranslateToChar(key, shiftLockMod, kbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
if (ch) {
|
|
|
|
cmdedShiftChar = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the current keyboard layout is switched by the Cmd key,
|
|
|
|
// we should append cmdedChar and shiftedCmdChar that are
|
2012-03-30 07:37:40 +04:00
|
|
|
// Latin char for the key.
|
|
|
|
// If the keyboard layout is Dvorak-QWERTY, we should append them only when
|
|
|
|
// command key is pressed because when command key isn't pressed, uncmded
|
|
|
|
// chars have been appended already.
|
|
|
|
if ((cmdedChar || cmdedShiftChar) && isCmdSwitchLayout &&
|
2012-04-25 07:00:02 +04:00
|
|
|
(aKeyEvent.IsMeta() || !isDvorakQWERTY)) {
|
2013-10-01 11:22:57 +04:00
|
|
|
AlternativeCharCode altCharCodes(cmdedChar, cmdedShiftChar);
|
2016-05-12 11:57:21 +03:00
|
|
|
aKeyEvent.mAlternativeCharCodes.AppendElement(altCharCodes);
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-03-16 07:47:50 +03:00
|
|
|
("%p TISInputSourceWrapper::WillDispatchKeyboardEvent, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"hasCmdShiftOnlyChar=%s, isCmdSwitchLayout=%s, isDvorakQWERTY=%s, "
|
|
|
|
"cmdedChar=U+%X, cmdedShiftChar=U+%X",
|
|
|
|
this, TrueOrFalse(hasCmdShiftOnlyChar), TrueOrFalse(isDvorakQWERTY),
|
|
|
|
TrueOrFalse(isDvorakQWERTY), cmdedChar, cmdedShiftChar));
|
2011-02-23 20:25:11 +03:00
|
|
|
// Special case for 'SS' key of German layout. See the comment of
|
|
|
|
// hasCmdShiftOnlyChar definition for the detail.
|
|
|
|
if (hasCmdShiftOnlyChar && originalCmdedShiftChar) {
|
2013-10-01 11:22:57 +04:00
|
|
|
AlternativeCharCode altCharCodes(0, originalCmdedShiftChar);
|
2016-05-12 11:57:21 +03:00
|
|
|
aKeyEvent.mAlternativeCharCodes.AppendElement(altCharCodes);
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-03-16 07:47:50 +03:00
|
|
|
("%p TISInputSourceWrapper::WillDispatchKeyboardEvent, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"hasCmdShiftOnlyChar=%s, originalCmdedShiftChar=U+%X",
|
|
|
|
this, TrueOrFalse(hasCmdShiftOnlyChar), originalCmdedShiftChar));
|
2012-05-26 06:35:58 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-05-17 11:04:16 +04:00
|
|
|
TISInputSourceWrapper::ComputeGeckoKeyCode(UInt32 aNativeKeyCode,
|
|
|
|
UInt32 aKbType,
|
|
|
|
bool aCmdIsPressed)
|
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2012-05-17 11:04:16 +04:00
|
|
|
("%p TISInputSourceWrapper::ComputeGeckoKeyCode, aNativeKeyCode=0x%X, "
|
|
|
|
"aKbType=0x%X, aCmdIsPressed=%s, IsOpenedIMEMode()=%s, "
|
|
|
|
"IsASCIICapable()=%s",
|
2016-12-16 06:16:31 +03:00
|
|
|
this, static_cast<unsigned int>(aNativeKeyCode),
|
|
|
|
static_cast<unsigned int>(aKbType), TrueOrFalse(aCmdIsPressed),
|
2012-05-17 11:04:16 +04:00
|
|
|
TrueOrFalse(IsOpenedIMEMode()), TrueOrFalse(IsASCIICapable())));
|
|
|
|
|
|
|
|
switch (aNativeKeyCode) {
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Space: return NS_VK_SPACE;
|
|
|
|
case kVK_Escape: return NS_VK_ESCAPE;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
|
|
|
// modifiers
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_RightCommand:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Command: return NS_VK_META;
|
|
|
|
case kVK_RightShift:
|
|
|
|
case kVK_Shift: return NS_VK_SHIFT;
|
|
|
|
case kVK_CapsLock: return NS_VK_CAPS_LOCK;
|
|
|
|
case kVK_RightControl:
|
|
|
|
case kVK_Control: return NS_VK_CONTROL;
|
|
|
|
case kVK_RightOption:
|
|
|
|
case kVK_Option: return NS_VK_ALT;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_ANSI_KeypadClear: return NS_VK_CLEAR;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
|
|
|
// function keys
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_F1: return NS_VK_F1;
|
|
|
|
case kVK_F2: return NS_VK_F2;
|
|
|
|
case kVK_F3: return NS_VK_F3;
|
|
|
|
case kVK_F4: return NS_VK_F4;
|
|
|
|
case kVK_F5: return NS_VK_F5;
|
|
|
|
case kVK_F6: return NS_VK_F6;
|
|
|
|
case kVK_F7: return NS_VK_F7;
|
|
|
|
case kVK_F8: return NS_VK_F8;
|
|
|
|
case kVK_F9: return NS_VK_F9;
|
|
|
|
case kVK_F10: return NS_VK_F10;
|
|
|
|
case kVK_F11: return NS_VK_F11;
|
|
|
|
case kVK_F12: return NS_VK_F12;
|
|
|
|
// case kVK_F13: return NS_VK_F13; // clash with the 3 below
|
|
|
|
// case kVK_F14: return NS_VK_F14;
|
|
|
|
// case kVK_F15: return NS_VK_F15;
|
|
|
|
case kVK_F16: return NS_VK_F16;
|
|
|
|
case kVK_F17: return NS_VK_F17;
|
|
|
|
case kVK_F18: return NS_VK_F18;
|
|
|
|
case kVK_F19: return NS_VK_F19;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Pause: return NS_VK_PAUSE;
|
|
|
|
case kVK_PC_ScrollLock: return NS_VK_SCROLL_LOCK;
|
|
|
|
case kVK_PC_PrintScreen: return NS_VK_PRINTSCREEN;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
|
|
|
// keypad
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_ANSI_Keypad0: return NS_VK_NUMPAD0;
|
|
|
|
case kVK_ANSI_Keypad1: return NS_VK_NUMPAD1;
|
|
|
|
case kVK_ANSI_Keypad2: return NS_VK_NUMPAD2;
|
|
|
|
case kVK_ANSI_Keypad3: return NS_VK_NUMPAD3;
|
|
|
|
case kVK_ANSI_Keypad4: return NS_VK_NUMPAD4;
|
|
|
|
case kVK_ANSI_Keypad5: return NS_VK_NUMPAD5;
|
|
|
|
case kVK_ANSI_Keypad6: return NS_VK_NUMPAD6;
|
|
|
|
case kVK_ANSI_Keypad7: return NS_VK_NUMPAD7;
|
|
|
|
case kVK_ANSI_Keypad8: return NS_VK_NUMPAD8;
|
|
|
|
case kVK_ANSI_Keypad9: return NS_VK_NUMPAD9;
|
|
|
|
|
|
|
|
case kVK_ANSI_KeypadMultiply: return NS_VK_MULTIPLY;
|
|
|
|
case kVK_ANSI_KeypadPlus: return NS_VK_ADD;
|
|
|
|
case kVK_ANSI_KeypadMinus: return NS_VK_SUBTRACT;
|
|
|
|
case kVK_ANSI_KeypadDecimal: return NS_VK_DECIMAL;
|
|
|
|
case kVK_ANSI_KeypadDivide: return NS_VK_DIVIDE;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2013-08-24 08:53:01 +04:00
|
|
|
case kVK_JIS_KeypadComma: return NS_VK_SEPARATOR;
|
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
// IME keys
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_JIS_Eisu: return NS_VK_EISU;
|
|
|
|
case kVK_JIS_Kana: return NS_VK_KANA;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
|
|
|
// these may clash with forward delete and help
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Insert: return NS_VK_INSERT;
|
|
|
|
case kVK_PC_Delete: return NS_VK_DELETE;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Backspace: return NS_VK_BACK;
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Tab: return NS_VK_TAB;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Home: return NS_VK_HOME;
|
|
|
|
case kVK_End: return NS_VK_END;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PageUp: return NS_VK_PAGE_UP;
|
|
|
|
case kVK_PageDown: return NS_VK_PAGE_DOWN;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_LeftArrow: return NS_VK_LEFT;
|
|
|
|
case kVK_RightArrow: return NS_VK_RIGHT;
|
|
|
|
case kVK_UpArrow: return NS_VK_UP;
|
|
|
|
case kVK_DownArrow: return NS_VK_DOWN;
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2013-12-06 07:16:55 +04:00
|
|
|
case kVK_PC_ContextMenu: return NS_VK_CONTEXT_MENU;
|
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
case kVK_ANSI_1: return NS_VK_1;
|
|
|
|
case kVK_ANSI_2: return NS_VK_2;
|
|
|
|
case kVK_ANSI_3: return NS_VK_3;
|
|
|
|
case kVK_ANSI_4: return NS_VK_4;
|
|
|
|
case kVK_ANSI_5: return NS_VK_5;
|
|
|
|
case kVK_ANSI_6: return NS_VK_6;
|
|
|
|
case kVK_ANSI_7: return NS_VK_7;
|
|
|
|
case kVK_ANSI_8: return NS_VK_8;
|
|
|
|
case kVK_ANSI_9: return NS_VK_9;
|
|
|
|
case kVK_ANSI_0: return NS_VK_0;
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_ANSI_KeypadEnter:
|
|
|
|
case kVK_Return:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Powerbook_KeypadEnter: return NS_VK_RETURN;
|
2012-05-17 11:04:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If Cmd key is pressed, that causes switching keyboard layout temporarily.
|
|
|
|
// E.g., Dvorak-QWERTY. Therefore, if Cmd key is pressed, we should honor it.
|
|
|
|
UInt32 modifiers = aCmdIsPressed ? cmdKey : 0;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t charCode = TranslateToChar(aNativeKeyCode, modifiers, aKbType);
|
2012-05-17 11:04:16 +04:00
|
|
|
|
|
|
|
// Special case for Mac. Mac inputs Yen sign (U+00A5) directly instead of
|
|
|
|
// Back slash (U+005C). We should return NS_VK_BACK_SLASH for compatibility
|
|
|
|
// with other platforms.
|
|
|
|
// XXX How about Won sign (U+20A9) which has same problem as Yen sign?
|
|
|
|
if (charCode == 0x00A5) {
|
|
|
|
return NS_VK_BACK_SLASH;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t keyCode = WidgetUtils::ComputeKeyCodeFromChar(charCode);
|
2012-05-17 11:04:16 +04:00
|
|
|
if (keyCode) {
|
|
|
|
return keyCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the unshifed char isn't an ASCII character, use shifted char.
|
|
|
|
charCode = TranslateToChar(aNativeKeyCode, modifiers | shiftKey, aKbType);
|
|
|
|
keyCode = WidgetUtils::ComputeKeyCodeFromChar(charCode);
|
|
|
|
if (keyCode) {
|
|
|
|
return keyCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is ASCII capable, give up to compute it.
|
|
|
|
if (IsASCIICapable()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retry with ASCII capable keyboard layout.
|
|
|
|
TISInputSourceWrapper currentKeyboardLayout;
|
|
|
|
currentKeyboardLayout.InitByCurrentASCIICapableKeyboardLayout();
|
|
|
|
NS_ENSURE_TRUE(mInputSource != currentKeyboardLayout.mInputSource, 0);
|
|
|
|
keyCode = currentKeyboardLayout.ComputeGeckoKeyCode(aNativeKeyCode, aKbType,
|
|
|
|
aCmdIsPressed);
|
|
|
|
|
|
|
|
// However, if keyCode isn't for an alphabet keys or a numeric key, we should
|
|
|
|
// ignore it. For example, comma key of Thai layout is same as close-square-
|
|
|
|
// bracket key of US layout and an unicode character key of Thai layout is
|
|
|
|
// same as comma key of US layout. If we return NS_VK_COMMA for latter key,
|
|
|
|
// web application developers cannot distinguish with the former key.
|
|
|
|
return ((keyCode >= NS_VK_A && keyCode <= NS_VK_Z) ||
|
|
|
|
(keyCode >= NS_VK_0 && keyCode <= NS_VK_9)) ? keyCode : 0;
|
|
|
|
}
|
|
|
|
|
2013-04-24 07:49:47 +04:00
|
|
|
// static
|
|
|
|
KeyNameIndex
|
|
|
|
TISInputSourceWrapper::ComputeGeckoKeyNameIndex(UInt32 aNativeKeyCode)
|
|
|
|
{
|
2014-05-25 06:08:59 +04:00
|
|
|
// NOTE:
|
|
|
|
// When unsupported keys like Convert, Nonconvert of Japanese keyboard is
|
|
|
|
// pressed:
|
|
|
|
// on 10.6.x, 'A' key event is fired (and also actually 'a' is inserted).
|
|
|
|
// on 10.7.x, Nothing happens.
|
|
|
|
// on 10.8.x, Nothing happens.
|
|
|
|
// on 10.9.x, FlagsChanged event is fired with keyCode 0xFF.
|
2013-04-24 07:49:47 +04:00
|
|
|
switch (aNativeKeyCode) {
|
|
|
|
|
|
|
|
#define NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX(aNativeKey, aKeyNameIndex) \
|
|
|
|
case aNativeKey: return aKeyNameIndex;
|
|
|
|
|
|
|
|
#include "NativeKeyToDOMKeyName.h"
|
|
|
|
|
|
|
|
#undef NS_NATIVE_KEY_TO_DOM_KEY_NAME_INDEX
|
|
|
|
|
|
|
|
default:
|
|
|
|
return KEY_NAME_INDEX_Unidentified;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-25 06:08:59 +04:00
|
|
|
// static
|
|
|
|
CodeNameIndex
|
2017-02-27 12:04:30 +03:00
|
|
|
TISInputSourceWrapper::ComputeGeckoCodeNameIndex(UInt32 aNativeKeyCode,
|
|
|
|
UInt32 aKbType)
|
2014-05-25 06:08:59 +04:00
|
|
|
{
|
2017-02-27 12:04:30 +03:00
|
|
|
// macOS swaps native key code between Backquote key and IntlBackslash key
|
|
|
|
// only when the keyboard type is ISO. Let's treat the key code after
|
|
|
|
// swapping them here because Chromium does so only when computing .code
|
|
|
|
// value.
|
|
|
|
if (::KBGetLayoutType(aKbType) == kKeyboardISO) {
|
|
|
|
if (aNativeKeyCode == kVK_ISO_Section) {
|
|
|
|
aNativeKeyCode = kVK_ANSI_Grave;
|
|
|
|
} else if (aNativeKeyCode == kVK_ANSI_Grave) {
|
|
|
|
aNativeKeyCode = kVK_ISO_Section;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-25 06:08:59 +04:00
|
|
|
switch (aNativeKeyCode) {
|
|
|
|
|
|
|
|
#define NS_NATIVE_KEY_TO_DOM_CODE_NAME_INDEX(aNativeKey, aCodeNameIndex) \
|
|
|
|
case aNativeKey: return aCodeNameIndex;
|
|
|
|
|
|
|
|
#include "NativeKeyToDOMCodeName.h"
|
|
|
|
|
|
|
|
#undef NS_NATIVE_KEY_TO_DOM_CODE_NAME_INDEX
|
|
|
|
|
|
|
|
default:
|
|
|
|
return CODE_NAME_INDEX_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* TextInputHandler implementation (static methods)
|
2009-10-01 06:52:50 +04:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2011-08-02 05:20:52 +04:00
|
|
|
NSUInteger TextInputHandler::sLastModifierState = 0;
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
// static
|
|
|
|
CFArrayRef
|
2011-05-08 14:19:15 +04:00
|
|
|
TextInputHandler::CreateAllKeyboardLayoutList()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
const void* keys[] = { kTISPropertyInputSourceType };
|
|
|
|
const void* values[] = { kTISTypeKeyboardLayout };
|
|
|
|
CFDictionaryRef filter =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1, NULL, NULL);
|
|
|
|
NS_ASSERTION(filter, "failed to create the filter");
|
|
|
|
CFArrayRef list = ::TISCreateInputSourceList(filter, true);
|
|
|
|
::CFRelease(filter);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2011-07-21 04:33:16 +04:00
|
|
|
TextInputHandler::DebugPrintAllKeyboardLayouts()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Info)) {
|
2011-07-21 04:33:16 +04:00
|
|
|
CFArrayRef list = CreateAllKeyboardLayoutList();
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info, ("Keyboard layout configuration:"));
|
2011-07-21 04:33:16 +04:00
|
|
|
CFIndex idx = ::CFArrayGetCount(list);
|
|
|
|
TISInputSourceWrapper tis;
|
|
|
|
for (CFIndex i = 0; i < idx; ++i) {
|
|
|
|
TISInputSourceRef inputSource = static_cast<TISInputSourceRef>(
|
|
|
|
const_cast<void *>(::CFArrayGetValueAtIndex(list, i)));
|
|
|
|
tis.InitByTISInputSourceRef(inputSource);
|
|
|
|
nsAutoString name, isid;
|
|
|
|
tis.GetLocalizedName(name);
|
|
|
|
tis.GetInputSourceID(isid);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-07-05 12:38:53 +03:00
|
|
|
(" %s\t<%s>%s%s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(name).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(isid).get(),
|
|
|
|
tis.IsASCIICapable() ? "" : "\t(Isn't ASCII capable)",
|
|
|
|
tis.IsKeyboardLayout() && tis.GetUCKeyboardLayout() ?
|
|
|
|
"" : "\t(uchr is NOT AVAILABLE)"));
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
|
|
|
::CFRelease(list);
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* TextInputHandler implementation
|
2009-10-01 06:52:50 +04:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
TextInputHandler::TextInputHandler(nsChildView* aWidget,
|
|
|
|
NSView<mozView> *aNativeView) :
|
|
|
|
IMEInputHandler(aWidget, aNativeView)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2016-06-16 11:14:34 +03:00
|
|
|
EnsureToLogAllKeyboardLayoutsAndIMEs();
|
2011-05-08 14:19:23 +04:00
|
|
|
[mView installTextInputHandler:this];
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
TextInputHandler::~TextInputHandler()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
[mView uninstallTextInputHandler];
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-05-16 05:59:35 +03:00
|
|
|
TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent,
|
|
|
|
uint32_t aUniqueId)
|
2011-02-23 21:06:26 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, "
|
|
|
|
"widget has been already destroyed", this));
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
// Insert empty line to the log for easier to read.
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info, (""));
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, aNativeEvent=%p, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"type=%s, keyCode=%u (0x%X), modifierFlags=0x%lX, characters=\"%s\", "
|
2011-07-21 04:33:16 +04:00
|
|
|
"charactersIgnoringModifiers=\"%s\"",
|
|
|
|
this, aNativeEvent, GetNativeKeyEventType(aNativeEvent),
|
|
|
|
[aNativeEvent keyCode], [aNativeEvent keyCode],
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>([aNativeEvent modifierFlags]),
|
|
|
|
GetCharacters([aNativeEvent characters]),
|
2011-07-21 04:33:16 +04:00
|
|
|
GetCharacters([aNativeEvent charactersIgnoringModifiers])));
|
|
|
|
|
2016-06-08 08:37:51 +03:00
|
|
|
// Except when Command key is pressed, we should hide mouse cursor until
|
|
|
|
// next mousemove. Handling here means that:
|
|
|
|
// - Don't hide mouse cursor at pressing modifier key
|
|
|
|
// - Hide mouse cursor even if the key event will be handled by IME (i.e.,
|
|
|
|
// even without dispatching eKeyPress events)
|
|
|
|
// - Hide mouse cursor even when a plugin has focus
|
|
|
|
if (!([aNativeEvent modifierFlags] & NSCommandKeyMask)) {
|
|
|
|
[NSCursor setHiddenUntilMouseMoves:YES];
|
|
|
|
}
|
|
|
|
|
2016-07-18 19:36:38 +03:00
|
|
|
RefPtr<nsChildView> widget(mWidget);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2017-05-16 05:59:35 +03:00
|
|
|
KeyEventState* currentKeyEvent = PushKeyEvent(aNativeEvent, aUniqueId);
|
2011-02-23 21:06:26 +03:00
|
|
|
AutoKeyEventStateCleaner remover(this);
|
|
|
|
|
2015-02-20 19:37:02 +03:00
|
|
|
ComplexTextInputPanel* ctiPanel = ComplexTextInputPanel::GetSharedComplexTextInputPanel();
|
|
|
|
if (ctiPanel && ctiPanel->IsInComposition()) {
|
|
|
|
nsAutoString committed;
|
|
|
|
ctiPanel->InterpretKeyEvent(aNativeEvent, committed);
|
|
|
|
if (!committed.IsEmpty()) {
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::HandleKeyDownEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure "
|
|
|
|
"at dispatching keydown for ComplexTextInputPanel", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-18 19:36:38 +03:00
|
|
|
WidgetKeyboardEvent imeEvent(true, eKeyDown, widget);
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
currentKeyEvent->InitKeyEvent(this, imeEvent);
|
2015-02-20 19:37:02 +03:00
|
|
|
imeEvent.mPluginTextEventString.Assign(committed);
|
2016-03-16 07:47:50 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mDispatcher->DispatchKeyboardEvent(eKeyDown, imeEvent, status,
|
|
|
|
currentKeyEvent);
|
2015-02-20 19:37:02 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
NSResponder* firstResponder = [[mView window] firstResponder];
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::HandleKeyDownEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure "
|
|
|
|
"at dispatching keydown for ordinal cases", this));
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2016-07-18 19:36:38 +03:00
|
|
|
WidgetKeyboardEvent keydownEvent(true, eKeyDown, widget);
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
currentKeyEvent->InitKeyEvent(this, keydownEvent);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mDispatcher->DispatchKeyboardEvent(eKeyDown, keydownEvent, status,
|
|
|
|
currentKeyEvent);
|
|
|
|
currentKeyEvent->mKeyDownHandled =
|
|
|
|
(status == nsEventStatus_eConsumeNoDefault);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
if (Destroyed()) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, "
|
|
|
|
"widget was destroyed by keydown event", this));
|
|
|
|
return currentKeyEvent->IsDefaultPrevented();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The key down event may have shifted the focus, in which
|
|
|
|
// case we should not fire the key press.
|
|
|
|
// XXX This is a special code only on Cocoa widget, why is this needed?
|
|
|
|
if (firstResponder != [[mView window] firstResponder]) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, "
|
|
|
|
"view lost focus by keydown event", this));
|
|
|
|
return currentKeyEvent->IsDefaultPrevented();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentKeyEvent->IsDefaultPrevented()) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, "
|
|
|
|
"keydown event's default is prevented", this));
|
|
|
|
return true;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Let Cocoa interpret the key events, caching IsIMEComposing first.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool wasComposing = IsIMEComposing();
|
|
|
|
bool interpretKeyEventsCalled = false;
|
2016-03-23 09:31:54 +03:00
|
|
|
// Don't call interpretKeyEvents when a plugin has focus. If we call it,
|
|
|
|
// for example, a character is inputted twice during a composition in e10s
|
|
|
|
// mode.
|
2016-07-18 19:36:38 +03:00
|
|
|
if (!widget->IsPluginFocused() && (IsIMEEnabled() || IsASCIICapableOnly())) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, calling interpretKeyEvents",
|
|
|
|
this));
|
2011-02-23 21:06:26 +03:00
|
|
|
[mView interpretKeyEvents:[NSArray arrayWithObject:aNativeEvent]];
|
2011-10-01 04:20:33 +04:00
|
|
|
interpretKeyEventsCalled = true;
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, called interpretKeyEvents",
|
|
|
|
this));
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, widget was destroyed",
|
|
|
|
this));
|
2013-07-25 10:09:28 +04:00
|
|
|
return currentKeyEvent->IsDefaultPrevented();
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, wasComposing=%s, "
|
|
|
|
"IsIMEComposing()=%s",
|
|
|
|
this, TrueOrFalse(wasComposing), TrueOrFalse(IsIMEComposing())));
|
|
|
|
|
2013-07-25 10:09:28 +04:00
|
|
|
if (currentKeyEvent->CanDispatchKeyPressEvent() &&
|
2011-02-23 21:06:26 +03:00
|
|
|
!wasComposing && !IsIMEComposing()) {
|
2016-03-16 07:47:50 +03:00
|
|
|
rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::HandleKeyDownEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure "
|
|
|
|
"at dispatching keypress", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-18 19:36:38 +03:00
|
|
|
WidgetKeyboardEvent keypressEvent(true, eKeyPress, widget);
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
currentKeyEvent->InitKeyEvent(this, keypressEvent);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
// If we called interpretKeyEvents and this isn't normal character input
|
|
|
|
// then IME probably ate the event for some reason. We do not want to
|
|
|
|
// send a key press event in that case.
|
|
|
|
// TODO:
|
|
|
|
// There are some other cases which IME eats the current event.
|
|
|
|
// 1. If key events were nested during calling interpretKeyEvents, it means
|
|
|
|
// that IME did something. Then, we should do nothing.
|
|
|
|
// 2. If one or more commands are called like "deleteBackward", we should
|
|
|
|
// dispatch keypress event at that time. Note that the command may have
|
|
|
|
// been a converted or generated action by IME. Then, we shouldn't do
|
|
|
|
// our default action for this key.
|
|
|
|
if (!(interpretKeyEventsCalled &&
|
|
|
|
IsNormalCharInputtingEvent(keypressEvent))) {
|
2016-03-16 07:47:50 +03:00
|
|
|
currentKeyEvent->mKeyPressDispatched =
|
|
|
|
mDispatcher->MaybeDispatchKeypressEvents(keypressEvent, status,
|
|
|
|
currentKeyEvent);
|
|
|
|
currentKeyEvent->mKeyPressHandled =
|
|
|
|
(status == nsEventStatus_eConsumeNoDefault);
|
2013-07-25 10:09:28 +04:00
|
|
|
currentKeyEvent->mKeyPressDispatched = true;
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, keypress event dispatched",
|
|
|
|
this));
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: mWidget might have become null here. Don't count on it from here on.
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyDownEvent, "
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
"keydown handled=%s, keypress handled=%s, causedOtherKeyEvents=%s, "
|
|
|
|
"compositionDispatched=%s",
|
2011-10-05 06:19:24 +04:00
|
|
|
this, TrueOrFalse(currentKeyEvent->mKeyDownHandled),
|
2013-07-25 10:09:28 +04:00
|
|
|
TrueOrFalse(currentKeyEvent->mKeyPressHandled),
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents),
|
|
|
|
TrueOrFalse(currentKeyEvent->mCompositionDispatched)));
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
// Insert empty line to the log for easier to read.
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info, (""));
|
2013-07-25 10:09:28 +04:00
|
|
|
return currentKeyEvent->IsDefaultPrevented();
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
void
|
|
|
|
TextInputHandler::HandleKeyUpEvent(NSEvent* aNativeEvent)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyUpEvent, aNativeEvent=%p, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"type=%s, keyCode=%u (0x%X), modifierFlags=0x%lX, characters=\"%s\", "
|
2011-07-21 04:33:16 +04:00
|
|
|
"charactersIgnoringModifiers=\"%s\", "
|
2014-12-11 17:44:07 +03:00
|
|
|
"IsIMEComposing()=%s",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, aNativeEvent, GetNativeKeyEventType(aNativeEvent),
|
|
|
|
[aNativeEvent keyCode], [aNativeEvent keyCode],
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>([aNativeEvent modifierFlags]),
|
|
|
|
GetCharacters([aNativeEvent characters]),
|
2011-07-21 04:33:16 +04:00
|
|
|
GetCharacters([aNativeEvent charactersIgnoringModifiers]),
|
2014-12-11 17:44:07 +03:00
|
|
|
TrueOrFalse(IsIMEComposing())));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
if (Destroyed()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleKeyUpEvent, "
|
|
|
|
"widget has been already destroyed", this));
|
2011-07-21 04:33:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::HandleKeyUpEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
2011-07-21 04:33:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-29 02:58:27 +03:00
|
|
|
WidgetKeyboardEvent keyupEvent(true, eKeyUp, mWidget);
|
2011-07-21 04:33:16 +04:00
|
|
|
InitKeyEvent(aNativeEvent, keyupEvent);
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
KeyEventState currentKeyEvent(aNativeEvent);
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mDispatcher->DispatchKeyboardEvent(eKeyUp, keyupEvent, status,
|
|
|
|
¤tKeyEvent);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextInputHandler::HandleFlagsChanged(NSEvent* aNativeEvent)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleFlagsChanged, "
|
|
|
|
"widget has been already destroyed", this));
|
2011-07-21 04:33:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsChildView> kungFuDeathGrip(mWidget);
|
2016-07-18 19:36:38 +03:00
|
|
|
mozilla::Unused << kungFuDeathGrip; // Not referenced within this function
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::HandleFlagsChanged, aNativeEvent=%p, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"type=%s, keyCode=%s (0x%X), modifierFlags=0x%08lX, "
|
|
|
|
"sLastModifierState=0x%08lX, IsIMEComposing()=%s",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, aNativeEvent, GetNativeKeyEventType(aNativeEvent),
|
|
|
|
GetKeyNameForNativeKeyCode([aNativeEvent keyCode]), [aNativeEvent keyCode],
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>([aNativeEvent modifierFlags]),
|
|
|
|
static_cast<unsigned long>(sLastModifierState),
|
2012-10-19 05:17:07 +04:00
|
|
|
TrueOrFalse(IsIMEComposing())));
|
|
|
|
|
|
|
|
MOZ_ASSERT([aNativeEvent type] == NSFlagsChanged);
|
|
|
|
|
|
|
|
NSUInteger diff = [aNativeEvent modifierFlags] ^ sLastModifierState;
|
|
|
|
// Device dependent flags for left-control key, both shift keys, both command
|
|
|
|
// keys and both option keys have been defined in Next's SDK. But we
|
|
|
|
// shouldn't use it directly as far as possible since Cocoa SDK doesn't
|
|
|
|
// define them. Fortunately, we need them only when we dispatch keyup
|
|
|
|
// events. So, we can usually know the actual relation between keyCode and
|
|
|
|
// device dependent flags. However, we need to remove following flags first
|
|
|
|
// since the differences don't indicate modifier key state.
|
|
|
|
// NX_STYLUSPROXIMITYMASK: Probably used for pen like device.
|
|
|
|
// kCGEventFlagMaskNonCoalesced (= NX_NONCOALSESCEDMASK): See the document for
|
|
|
|
// Quartz Event Services.
|
|
|
|
diff &= ~(NX_STYLUSPROXIMITYMASK | kCGEventFlagMaskNonCoalesced);
|
|
|
|
|
|
|
|
switch ([aNativeEvent keyCode]) {
|
|
|
|
// CapsLock state and other modifier states are different:
|
|
|
|
// CapsLock state does not revert when the CapsLock key goes up, as the
|
|
|
|
// modifier state does for other modifier keys on key up.
|
|
|
|
case kVK_CapsLock: {
|
|
|
|
// Fire key down event for caps lock.
|
|
|
|
DispatchKeyEventForFlagsChanged(aNativeEvent, true);
|
|
|
|
// XXX should we fire keyup event too? The keyup event for CapsLock key
|
|
|
|
// is never dispatched on Gecko.
|
|
|
|
// XXX WebKit dispatches keydown event when CapsLock is locked, otherwise,
|
|
|
|
// keyup event. If we do so, we cannot keep the consistency with other
|
|
|
|
// platform's behavior...
|
|
|
|
break;
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
2012-10-19 05:17:07 +04:00
|
|
|
|
|
|
|
// If the event is caused by pressing or releasing a modifier key, just
|
|
|
|
// dispatch the key's event.
|
|
|
|
case kVK_Shift:
|
|
|
|
case kVK_RightShift:
|
|
|
|
case kVK_Command:
|
|
|
|
case kVK_RightCommand:
|
|
|
|
case kVK_Control:
|
|
|
|
case kVK_RightControl:
|
|
|
|
case kVK_Option:
|
|
|
|
case kVK_RightOption:
|
|
|
|
case kVK_Help: {
|
|
|
|
// We assume that at most one modifier is changed per event if the event
|
|
|
|
// is caused by pressing or releasing a modifier key.
|
|
|
|
bool isKeyDown = ([aNativeEvent modifierFlags] & diff) != 0;
|
|
|
|
DispatchKeyEventForFlagsChanged(aNativeEvent, isKeyDown);
|
2012-12-21 12:31:24 +04:00
|
|
|
// XXX Some applications might send the event with incorrect device-
|
|
|
|
// dependent flags.
|
2012-10-19 05:17:07 +04:00
|
|
|
if (isKeyDown && ((diff & ~NSDeviceIndependentModifierFlagsMask) != 0)) {
|
|
|
|
unsigned short keyCode = [aNativeEvent keyCode];
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
|
|
|
GetModifierKeyForDeviceDependentFlags(diff);
|
|
|
|
if (modifierKey && modifierKey->keyCode != keyCode) {
|
|
|
|
// Although, we're not sure the actual cause of this case, the stored
|
|
|
|
// modifier information and the latest key event information may be
|
|
|
|
// mismatched. Then, let's reset the stored information.
|
|
|
|
// NOTE: If this happens, it may fail to handle NSFlagsChanged event
|
|
|
|
// in the default case (below). However, it's the rare case handler
|
|
|
|
// and this case occurs rarely. So, we can ignore the edge case bug.
|
|
|
|
NS_WARNING("Resetting stored modifier key information");
|
|
|
|
mModifierKeys.Clear();
|
|
|
|
modifierKey = nullptr;
|
|
|
|
}
|
|
|
|
if (!modifierKey) {
|
2012-10-19 05:17:07 +04:00
|
|
|
mModifierKeys.AppendElement(ModifierKey(diff, keyCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Currently we don't support Fn key since other browsers don't dispatch
|
|
|
|
// events for it and we don't have keyCode for this key.
|
|
|
|
// It should be supported when we implement .key and .char.
|
|
|
|
case kVK_Function:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If the event is caused by something else than pressing or releasing a
|
|
|
|
// single modifier key (for example by the app having been deactivated
|
|
|
|
// using command-tab), use the modifiers themselves to determine which
|
|
|
|
// key's event to dispatch, and whether it's a keyup or keydown event.
|
|
|
|
// In all cases we assume one or more modifiers are being deactivated
|
|
|
|
// (never activated) -- otherwise we'd have received one or more events
|
|
|
|
// corresponding to a single modifier key being pressed.
|
|
|
|
default: {
|
|
|
|
NSUInteger modifiers = sLastModifierState;
|
|
|
|
for (int32_t bit = 0; bit < 32; ++bit) {
|
|
|
|
NSUInteger flag = 1 << bit;
|
|
|
|
if (!(diff & flag)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-12-21 12:31:24 +04:00
|
|
|
// Given correct information from the application, a flag change here
|
|
|
|
// will normally be a deactivation (except for some lockable modifiers
|
|
|
|
// such as CapsLock). But some applications (like VNC) can send an
|
|
|
|
// activating event with a zero keyCode. So we need to check for that
|
|
|
|
// here.
|
|
|
|
bool dispatchKeyDown = ((flag & [aNativeEvent modifierFlags]) != 0);
|
|
|
|
|
2012-10-19 05:17:07 +04:00
|
|
|
unsigned short keyCode = 0;
|
|
|
|
if (flag & NSDeviceIndependentModifierFlagsMask) {
|
|
|
|
switch (flag) {
|
|
|
|
case NSAlphaShiftKeyMask:
|
|
|
|
keyCode = kVK_CapsLock;
|
|
|
|
dispatchKeyDown = true;
|
|
|
|
break;
|
2012-12-21 12:31:24 +04:00
|
|
|
|
2012-10-19 05:17:07 +04:00
|
|
|
case NSNumericPadKeyMask:
|
2012-12-21 12:31:24 +04:00
|
|
|
// NSNumericPadKeyMask is fired by VNC a lot. But not all of
|
|
|
|
// these events can really be Clear key events, so we just ignore
|
|
|
|
// them.
|
|
|
|
continue;
|
|
|
|
|
2012-10-19 05:17:07 +04:00
|
|
|
case NSHelpKeyMask:
|
|
|
|
keyCode = kVK_Help;
|
|
|
|
break;
|
2012-12-21 12:31:24 +04:00
|
|
|
|
2012-10-19 05:17:07 +04:00
|
|
|
case NSFunctionKeyMask:
|
2012-12-21 12:31:24 +04:00
|
|
|
// An NSFunctionKeyMask change here will normally be a
|
|
|
|
// deactivation. But sometimes it will be an activation send (by
|
|
|
|
// VNC for example) with a zero keyCode.
|
2012-10-19 05:17:07 +04:00
|
|
|
continue;
|
2012-12-21 12:31:24 +04:00
|
|
|
|
|
|
|
// These cases (NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask
|
|
|
|
// and NSCommandKeyMask) should be handled by the other branch of
|
|
|
|
// the if statement, below (which handles device dependent flags).
|
|
|
|
// However, some applications (like VNC) can send key events without
|
|
|
|
// any device dependent flags, so we handle them here instead.
|
|
|
|
case NSShiftKeyMask:
|
|
|
|
keyCode = (modifiers & 0x0004) ? kVK_RightShift : kVK_Shift;
|
|
|
|
break;
|
|
|
|
case NSControlKeyMask:
|
|
|
|
keyCode = (modifiers & 0x2000) ? kVK_RightControl : kVK_Control;
|
|
|
|
break;
|
|
|
|
case NSAlternateKeyMask:
|
|
|
|
keyCode = (modifiers & 0x0040) ? kVK_RightOption : kVK_Option;
|
|
|
|
break;
|
|
|
|
case NSCommandKeyMask:
|
|
|
|
keyCode = (modifiers & 0x0010) ? kVK_RightCommand : kVK_Command;
|
|
|
|
break;
|
|
|
|
|
2012-10-19 05:17:07 +04:00
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForDeviceDependentFlags(flag);
|
|
|
|
if (!modifierKey) {
|
2012-12-21 12:31:24 +04:00
|
|
|
// See the note above (in the other branch of the if statement)
|
|
|
|
// about the NSShiftKeyMask, NSControlKeyMask, NSAlternateKeyMask
|
|
|
|
// and NSCommandKeyMask cases.
|
2012-10-19 05:17:07 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
keyCode = modifierKey->keyCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove flags
|
|
|
|
modifiers &= ~flag;
|
|
|
|
switch (keyCode) {
|
|
|
|
case kVK_Shift: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_RightShift);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSShiftKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_RightShift: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_Shift);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSShiftKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_Command: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_RightCommand);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSCommandKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_RightCommand: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_Command);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSCommandKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_Control: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_RightControl);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSControlKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_RightControl: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_Control);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSControlKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_Option: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_RightOption);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSAlternateKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_RightOption: {
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey* modifierKey =
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(kVK_Option);
|
|
|
|
if (!modifierKey ||
|
|
|
|
!(modifiers & modifierKey->GetDeviceDependentFlags())) {
|
|
|
|
modifiers &= ~NSAlternateKeyMask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kVK_Help:
|
|
|
|
modifiers &= ~NSHelpKeyMask;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSEvent* event =
|
|
|
|
[NSEvent keyEventWithType:NSFlagsChanged
|
|
|
|
location:[aNativeEvent locationInWindow]
|
|
|
|
modifierFlags:modifiers
|
|
|
|
timestamp:[aNativeEvent timestamp]
|
|
|
|
windowNumber:[aNativeEvent windowNumber]
|
|
|
|
context:[aNativeEvent context]
|
2015-11-06 04:24:19 +03:00
|
|
|
characters:@""
|
|
|
|
charactersIgnoringModifiers:@""
|
2012-10-19 05:17:07 +04:00
|
|
|
isARepeat:NO
|
|
|
|
keyCode:keyCode];
|
|
|
|
DispatchKeyEventForFlagsChanged(event, dispatchKeyDown);
|
2011-07-21 04:33:16 +04:00
|
|
|
if (Destroyed()) {
|
2012-10-19 05:17:07 +04:00
|
|
|
break;
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop if focus has changed.
|
|
|
|
// Check to see if mView is still the first responder.
|
|
|
|
if (![mView isFirstResponder]) {
|
|
|
|
break;
|
|
|
|
}
|
2012-10-19 05:17:07 +04:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
2012-10-19 05:17:07 +04:00
|
|
|
break;
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-19 05:17:07 +04:00
|
|
|
// Be aware, the widget may have been destroyed.
|
|
|
|
sLastModifierState = [aNativeEvent modifierFlags];
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:26:43 +04:00
|
|
|
const TextInputHandler::ModifierKey*
|
2012-10-19 05:17:07 +04:00
|
|
|
TextInputHandler::GetModifierKeyForNativeKeyCode(unsigned short aKeyCode) const
|
|
|
|
{
|
|
|
|
for (ModifierKeyArray::index_type i = 0; i < mModifierKeys.Length(); ++i) {
|
|
|
|
if (mModifierKeys[i].keyCode == aKeyCode) {
|
|
|
|
return &((ModifierKey&)mModifierKeys[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:26:43 +04:00
|
|
|
const TextInputHandler::ModifierKey*
|
2012-10-19 05:17:07 +04:00
|
|
|
TextInputHandler::GetModifierKeyForDeviceDependentFlags(NSUInteger aFlags) const
|
|
|
|
{
|
|
|
|
for (ModifierKeyArray::index_type i = 0; i < mModifierKeys.Length(); ++i) {
|
|
|
|
if (mModifierKeys[i].GetDeviceDependentFlags() ==
|
|
|
|
(aFlags & ~NSDeviceIndependentModifierFlagsMask)) {
|
|
|
|
return &((ModifierKey&)mModifierKeys[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
void
|
|
|
|
TextInputHandler::DispatchKeyEventForFlagsChanged(NSEvent* aNativeEvent,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDispatchKeyDown)
|
2011-07-21 04:33:16 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::DispatchKeyEventForFlagsChanged, aNativeEvent=%p, "
|
|
|
|
"type=%s, keyCode=%s (0x%X), aDispatchKeyDown=%s, IsIMEComposing()=%s",
|
|
|
|
this, aNativeEvent, GetNativeKeyEventType(aNativeEvent),
|
|
|
|
GetKeyNameForNativeKeyCode([aNativeEvent keyCode]), [aNativeEvent keyCode],
|
|
|
|
TrueOrFalse(aDispatchKeyDown), TrueOrFalse(IsIMEComposing())));
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
if ([aNativeEvent type] != NSFlagsChanged || IsIMEComposing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchKeyEventForFlagsChanged, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-29 02:58:27 +03:00
|
|
|
EventMessage message = aDispatchKeyDown ? eKeyDown : eKeyUp;
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
// Fire a key event.
|
2013-10-01 11:22:58 +04:00
|
|
|
WidgetKeyboardEvent keyEvent(true, message, mWidget);
|
2011-07-21 04:33:16 +04:00
|
|
|
InitKeyEvent(aNativeEvent, keyEvent);
|
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
// Attach a plugin event, in case keyEvent gets dispatched to a plugin. Only
|
|
|
|
// one field is needed -- the type. The other fields can be constructed as
|
|
|
|
// the need arises. But Gecko doesn't have anything equivalent to the
|
|
|
|
// NPCocoaEventFlagsChanged type, and this needs to be passed accurately to
|
|
|
|
// any plugin to which this event is sent.
|
|
|
|
NPCocoaEvent cocoaEvent;
|
|
|
|
nsCocoaUtils::InitNPCocoaEvent(&cocoaEvent);
|
|
|
|
cocoaEvent.type = NPCocoaEventFlagsChanged;
|
|
|
|
keyEvent.mPluginEvent.Copy(cocoaEvent);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
KeyEventState currentKeyEvent(aNativeEvent);
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
mDispatcher->DispatchKeyboardEvent(message, keyEvent, status,
|
|
|
|
¤tKeyEvent);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
void
|
2013-07-11 11:46:35 +04:00
|
|
|
TextInputHandler::InsertText(NSAttributedString* aAttrString,
|
|
|
|
NSRange* aReplacementRange)
|
2011-02-23 21:06:26 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-05 06:19:24 +04:00
|
|
|
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::InsertText, aAttrString=\"%s\", "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aReplacementRange=%p { location=%lu, length=%lu }, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"IsIMEComposing()=%s, IgnoreIMEComposition()=%s, "
|
2013-07-25 10:09:28 +04:00
|
|
|
"keyevent=%p, keydownHandled=%s, keypressDispatched=%s, "
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
"causedOtherKeyEvents=%s, compositionDispatched=%s",
|
2013-07-11 11:46:35 +04:00
|
|
|
this, GetCharacters([aAttrString string]), aReplacementRange,
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>(aReplacementRange ? aReplacementRange->location : 0),
|
|
|
|
static_cast<unsigned long>(aReplacementRange ? aReplacementRange->length : 0),
|
2013-07-11 11:46:35 +04:00
|
|
|
TrueOrFalse(IsIMEComposing()), TrueOrFalse(IgnoreIMEComposition()),
|
2012-07-30 18:20:58 +04:00
|
|
|
currentKeyEvent ? currentKeyEvent->mKeyEvent : nullptr,
|
2011-10-05 06:19:24 +04:00
|
|
|
currentKeyEvent ?
|
2013-07-25 10:09:28 +04:00
|
|
|
TrueOrFalse(currentKeyEvent->mKeyDownHandled) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyPressDispatched) : "N/A",
|
|
|
|
currentKeyEvent ?
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mCompositionDispatched) : "N/A"));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
if (IgnoreIMEComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
InputContext context = mWidget->GetInputContext();
|
|
|
|
bool isEditable = (context.mIMEState.mEnabled == IMEState::ENABLED ||
|
|
|
|
context.mIMEState.mEnabled == IMEState::PASSWORD);
|
|
|
|
NSRange selectedRange = SelectedRange();
|
|
|
|
|
2012-07-21 03:24:48 +04:00
|
|
|
nsAutoString str;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GetStringForNSString([aAttrString string], str);
|
2016-03-16 07:47:50 +03:00
|
|
|
|
|
|
|
AutoInsertStringClearer clearer(currentKeyEvent);
|
|
|
|
if (currentKeyEvent) {
|
|
|
|
currentKeyEvent->mInsertString = &str;
|
|
|
|
}
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
if (!IsIMEComposing() && str.IsEmpty()) {
|
2013-07-11 11:46:35 +04:00
|
|
|
// nothing to do if there is no content which can be removed.
|
|
|
|
if (!isEditable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If replacement range is specified, we need to remove the range.
|
|
|
|
// Otherwise, we need to remove the selected range if it's not collapsed.
|
|
|
|
if (aReplacementRange && aReplacementRange->location != NSNotFound) {
|
|
|
|
// nothing to do since the range is collapsed.
|
|
|
|
if (aReplacementRange->length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If the replacement range is different from current selected range,
|
|
|
|
// select the range.
|
|
|
|
if (!NSEqualRanges(selectedRange, *aReplacementRange)) {
|
|
|
|
NS_ENSURE_TRUE_VOID(SetSelection(*aReplacementRange));
|
|
|
|
}
|
|
|
|
selectedRange = SelectedRange();
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(selectedRange.location != NSNotFound);
|
|
|
|
if (selectedRange.length == 0) {
|
|
|
|
return; // nothing to do
|
|
|
|
}
|
|
|
|
// If this is caused by a key input, the keypress event which will be
|
|
|
|
// dispatched later should cause the delete. Therefore, nothing to do here.
|
|
|
|
// Although, we're not sure if such case is actually possible.
|
|
|
|
if (!currentKeyEvent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Delete the selected range.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextInputHandler> kungFuDeathGrip(this);
|
2015-09-10 19:59:52 +03:00
|
|
|
WidgetContentCommandEvent deleteCommandEvent(true, eContentCommandDelete,
|
2013-09-27 10:20:54 +04:00
|
|
|
mWidget);
|
2013-07-11 11:46:35 +04:00
|
|
|
DispatchEvent(deleteCommandEvent);
|
|
|
|
NS_ENSURE_TRUE_VOID(deleteCommandEvent.mSucceeded);
|
|
|
|
// Be aware! The widget might be destroyed here.
|
|
|
|
return;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
bool isReplacingSpecifiedRange =
|
|
|
|
isEditable && aReplacementRange &&
|
|
|
|
aReplacementRange->location != NSNotFound &&
|
|
|
|
!NSEqualRanges(selectedRange, *aReplacementRange);
|
|
|
|
|
|
|
|
// If this is not caused by pressing a key, there is a composition or
|
|
|
|
// replacing a range which is different from current selection, let's
|
2016-10-18 09:26:54 +03:00
|
|
|
// insert the text as committing a composition.
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
// If InsertText() is called two or more times, we should insert all
|
|
|
|
// text with composition events.
|
|
|
|
// XXX When InsertText() is called multiple times, Chromium dispatches
|
|
|
|
// only one composition event. So, we need to store InsertText()
|
|
|
|
// calls and flush later.
|
|
|
|
if (!currentKeyEvent || currentKeyEvent->mCompositionDispatched ||
|
|
|
|
IsIMEComposing() || isReplacingSpecifiedRange) {
|
2013-07-11 11:46:35 +04:00
|
|
|
InsertTextAsCommittingComposition(aAttrString, aReplacementRange);
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
if (currentKeyEvent) {
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
currentKeyEvent->mCompositionDispatched = true;
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
}
|
2011-02-23 21:06:26 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't let the same event be fired twice when hitting
|
2017-02-23 05:45:13 +03:00
|
|
|
// enter/return for Bug 420502. However, Korean IME (or some other
|
|
|
|
// simple IME) may work without marked text. For example, composing
|
|
|
|
// character may be inserted as committed text and it's modified with
|
|
|
|
// aReplacementRange. When a keydown starts new composition with
|
|
|
|
// committing previous character, InsertText() may be called twice,
|
|
|
|
// one is for committing previous character and then, inserting new
|
|
|
|
// composing character as committed character. In the latter case,
|
|
|
|
// |CanDispatchKeyPressEvent()| returns true but we need to dispatch
|
|
|
|
// keypress event for the new character. So, when IME tries to insert
|
|
|
|
// printable characters, we should ignore current key event state even
|
|
|
|
// after the keydown has already caused dispatching composition event.
|
|
|
|
// XXX Anyway, we should sort out around this at fixing bug 1338460.
|
|
|
|
if (currentKeyEvent && !currentKeyEvent->CanDispatchKeyPressEvent() &&
|
|
|
|
(str.IsEmpty() || (str.Length() == 1 && !IsPrintableChar(str[0])))) {
|
2011-02-23 21:06:26 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
// XXX Shouldn't we hold mDispatcher instead of mWidget?
|
2016-07-18 19:36:38 +03:00
|
|
|
RefPtr<nsChildView> widget(mWidget);
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::HandleKeyUpEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-07 14:01:49 +04:00
|
|
|
// Dispatch keypress event with char instead of compositionchange event
|
2016-07-18 19:36:38 +03:00
|
|
|
WidgetKeyboardEvent keypressEvent(true, eKeyPress, widget);
|
2016-06-16 06:11:01 +03:00
|
|
|
// XXX Why do we need to dispatch keypress event for not inputting any
|
|
|
|
// string? If it wants to delete the specified range, should we
|
|
|
|
// dispatch an eContentCommandDelete event instead? Because this
|
|
|
|
// must not be caused by a key operation, a part of IME's processing.
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
// Don't set other modifiers from the current event, because here in
|
|
|
|
// -insertText: they've already been taken into account in creating
|
|
|
|
// the input string.
|
|
|
|
|
2011-10-05 06:19:24 +04:00
|
|
|
if (currentKeyEvent) {
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
currentKeyEvent->InitKeyEvent(this, keypressEvent);
|
2011-02-23 21:06:26 +03:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsCocoaUtils::InitInputEvent(keypressEvent, static_cast<NSEvent*>(nullptr));
|
2016-06-16 06:11:01 +03:00
|
|
|
keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
|
|
|
|
keypressEvent.mKeyValue = str;
|
|
|
|
// FYI: TextEventDispatcher will set mKeyCode to 0 for printable key's
|
|
|
|
// keypress events even if they don't cause inputting non-empty string.
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
// Remove basic modifiers from keypress event because if they are included,
|
|
|
|
// nsPlaintextEditor ignores the event.
|
2016-03-31 11:03:00 +03:00
|
|
|
keypressEvent.mModifiers &= ~(MODIFIER_CONTROL |
|
|
|
|
MODIFIER_ALT |
|
|
|
|
MODIFIER_META);
|
2012-04-25 07:00:02 +04:00
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
// TODO:
|
2016-03-16 07:47:50 +03:00
|
|
|
// If mCurrentKeyEvent.mKeyEvent is null, the text should be inputted as
|
|
|
|
// composition events.
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
bool keyPressDispatched =
|
|
|
|
mDispatcher->MaybeDispatchKeypressEvents(keypressEvent, status,
|
|
|
|
currentKeyEvent);
|
|
|
|
bool keyPressHandled = (status == nsEventStatus_eConsumeNoDefault);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
// Note: mWidget might have become null here. Don't count on it from here on.
|
|
|
|
|
2011-10-05 06:19:24 +04:00
|
|
|
if (currentKeyEvent) {
|
|
|
|
currentKeyEvent->mKeyPressHandled = keyPressHandled;
|
2016-03-16 07:47:50 +03:00
|
|
|
currentKeyEvent->mKeyPressDispatched = keyPressDispatched;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2017-04-27 15:44:58 +03:00
|
|
|
void
|
|
|
|
TextInputHandler::InsertNewline()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
|
|
|
|
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p TextInputHandler::InsertNewline, "
|
|
|
|
"IsIMEComposing()=%s, IgnoreIMEComposition()=%s, "
|
|
|
|
"keyevent=%p, keydownHandled=%s, keypressDispatched=%s, "
|
|
|
|
"causedOtherKeyEvents=%s, compositionDispatched=%s",
|
|
|
|
this, TrueOrFalse(IsIMEComposing()), TrueOrFalse(IgnoreIMEComposition()),
|
|
|
|
currentKeyEvent ? currentKeyEvent->mKeyEvent : nullptr,
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyDownHandled) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyPressDispatched) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mCompositionDispatched) : "N/A"));
|
|
|
|
|
|
|
|
if (IgnoreIMEComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If "insertNewline:" command shouldn't be handled, let's ignore it.
|
|
|
|
if (currentKeyEvent && !currentKeyEvent->CanHandleCommand()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's in composition, we cannot dispatch keypress event.
|
|
|
|
// Therefore, we should insert '\n' as committing composition.
|
|
|
|
if (IsIMEComposing()) {
|
|
|
|
NSAttributedString* lineBreaker =
|
|
|
|
[[NSAttributedString alloc] initWithString:@"\n"];
|
|
|
|
InsertTextAsCommittingComposition(lineBreaker, nullptr);
|
|
|
|
if (currentKeyEvent) {
|
|
|
|
currentKeyEvent->mCompositionDispatched = true;
|
|
|
|
}
|
|
|
|
[lineBreaker release];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we need to dispatch keypress event because HTMLEditor doesn't
|
|
|
|
// treat "\n" in composition string as a line break unless the whitespace is
|
|
|
|
// treated as pre (see bug 1350541). In strictly speaking, we should
|
|
|
|
// dispatch keypress event as-is if it's handling NSKeyDown event or
|
|
|
|
// should insert it with committing composition.
|
|
|
|
|
|
|
|
RefPtr<nsChildView> widget(mWidget);
|
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p, IMEInputHandler::InsertNewline, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: If it's not Enter keypress but user customized the OS settings
|
|
|
|
// to insert a line breaker with other key, we should just set
|
|
|
|
// command to the keypress event and it should be handled as
|
|
|
|
// Enter key press in editor.
|
|
|
|
|
|
|
|
// If it's handling actual Enter key event and hasn't cause any composition
|
|
|
|
// events nor other key events, we should expose actual modifier state.
|
|
|
|
// Otherwise, we should remove Control, Option and Command state since
|
|
|
|
// editor may behave differently if some of them are active. Although,
|
|
|
|
// Shift+Enter and Enter are work differently in HTML editor, we should
|
|
|
|
// expose actual Shift state if it's caused by Enter key for compatibility
|
|
|
|
// with Chromium. Chromium breaks line in HTML editor with default pargraph
|
|
|
|
// separator when Enter is pressed, with <br> element when Shift+Enter.
|
|
|
|
// Safari breaks line in HTML editor with default paragraph separator when
|
|
|
|
// Enter, Shift+Enter or Option+Enter. So, we should not change Shift+Enter
|
|
|
|
// meaning when there was composition string or not.
|
|
|
|
bool dispatchFakeKeyPress =
|
|
|
|
!(currentKeyEvent && currentKeyEvent->IsEnterKeyEvent() &&
|
|
|
|
currentKeyEvent->CanDispatchKeyPressEvent());
|
|
|
|
|
|
|
|
WidgetKeyboardEvent keypressEvent(true, eKeyPress, widget);
|
|
|
|
if (!dispatchFakeKeyPress) {
|
|
|
|
// If we're acutally handling an Enter key press, we should dispatch
|
|
|
|
// Enter keypress event as-is.
|
|
|
|
currentKeyEvent->InitKeyEvent(this, keypressEvent);
|
|
|
|
} else {
|
|
|
|
// Otherwise, we should dispatch "fake" Enter keypress event.
|
|
|
|
// In this case, we shouldn't set code value to "Enter".
|
|
|
|
NSEvent* keyEvent = currentKeyEvent ? currentKeyEvent->mKeyEvent : nullptr;
|
|
|
|
nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
|
|
|
|
keypressEvent.mKeyCode = NS_VK_RETURN;
|
|
|
|
keypressEvent.mKeyNameIndex = KEY_NAME_INDEX_Enter;
|
|
|
|
keypressEvent.mModifiers &= ~(MODIFIER_CONTROL |
|
|
|
|
MODIFIER_ALT |
|
|
|
|
MODIFIER_META);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
bool keyPressDispatched =
|
|
|
|
mDispatcher->MaybeDispatchKeypressEvents(keypressEvent, status,
|
|
|
|
currentKeyEvent);
|
|
|
|
bool keyPressHandled = (status == nsEventStatus_eConsumeNoDefault);
|
|
|
|
|
|
|
|
// NOTE: mWidget might have become null here.
|
|
|
|
|
|
|
|
if (keyPressDispatched) {
|
|
|
|
// Record the keypress event state only when it dispatched actual Enter
|
|
|
|
// keypress event because in other cases, the keypress event just a
|
|
|
|
// messenger. E.g., if it's caused by different key, keypress event for
|
|
|
|
// the actual key should be dispatched.
|
|
|
|
if (!dispatchFakeKeyPress && currentKeyEvent) {
|
|
|
|
currentKeyEvent->mKeyPressHandled = keyPressHandled;
|
|
|
|
currentKeyEvent->mKeyPressDispatched = keyPressDispatched;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If keypress event isn't dispatched as expected, we should fallback to
|
|
|
|
// using composition events.
|
|
|
|
NSAttributedString* lineBreaker =
|
|
|
|
[[NSAttributedString alloc] initWithString:@"\n"];
|
|
|
|
InsertTextAsCommittingComposition(lineBreaker, nullptr);
|
|
|
|
if (currentKeyEvent) {
|
|
|
|
currentKeyEvent->mCompositionDispatched = true;
|
|
|
|
}
|
|
|
|
[lineBreaker release];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-07-21 04:33:16 +04:00
|
|
|
TextInputHandler::DoCommandBySelector(const char* aSelector)
|
|
|
|
{
|
2016-07-18 19:36:38 +03:00
|
|
|
RefPtr<nsChildView> widget(mWidget);
|
2011-10-05 06:19:25 +04:00
|
|
|
|
2011-10-05 06:19:24 +04:00
|
|
|
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandler::DoCommandBySelector, aSelector=\"%s\", "
|
2013-07-25 10:09:28 +04:00
|
|
|
"Destroyed()=%s, keydownHandled=%s, keypressHandled=%s, "
|
|
|
|
"causedOtherKeyEvents=%s",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, aSelector ? aSelector : "", TrueOrFalse(Destroyed()),
|
2013-07-25 10:09:28 +04:00
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyDownHandled) : "N/A",
|
2011-10-05 06:19:24 +04:00
|
|
|
currentKeyEvent ?
|
2011-10-05 06:19:24 +04:00
|
|
|
TrueOrFalse(currentKeyEvent->mKeyPressHandled) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A"));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2017-04-26 14:39:13 +03:00
|
|
|
// If the command isn't caused by key operation, the command should
|
|
|
|
// be handled in the super class of the caller.
|
|
|
|
if (!currentKeyEvent) {
|
|
|
|
return Destroyed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the key operation causes this command, should dispatch a keypress
|
|
|
|
// event.
|
|
|
|
// XXX This must be worng. Even if this command is caused by the key
|
|
|
|
// operation, its our default action can be different from the
|
|
|
|
// command. So, in this case, we should dispatch a keypress event
|
|
|
|
// which have the command and editor should handle it.
|
|
|
|
if (currentKeyEvent->CanDispatchKeyPressEvent()) {
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DoCommandBySelector, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure "
|
|
|
|
"at dispatching keypress", this));
|
2017-04-26 14:39:13 +03:00
|
|
|
return Destroyed();
|
2016-03-16 07:47:50 +03:00
|
|
|
}
|
|
|
|
|
2016-07-18 19:36:38 +03:00
|
|
|
WidgetKeyboardEvent keypressEvent(true, eKeyPress, widget);
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
currentKeyEvent->InitKeyEvent(this, keypressEvent);
|
2016-03-16 07:47:50 +03:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
currentKeyEvent->mKeyPressDispatched =
|
|
|
|
mDispatcher->MaybeDispatchKeypressEvents(keypressEvent, status,
|
|
|
|
currentKeyEvent);
|
|
|
|
currentKeyEvent->mKeyPressHandled =
|
|
|
|
(status == nsEventStatus_eConsumeNoDefault);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-10-05 06:19:25 +04:00
|
|
|
("%p TextInputHandler::DoCommandBySelector, keypress event "
|
|
|
|
"dispatched, Destroyed()=%s, keypressHandled=%s",
|
|
|
|
this, TrueOrFalse(Destroyed()),
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyPressHandled)));
|
2017-04-26 14:39:13 +03:00
|
|
|
// This command is now dispatched with keypress event.
|
|
|
|
// So, this shouldn't be handled by nobody anymore.
|
|
|
|
return true;
|
2011-10-05 06:19:25 +04:00
|
|
|
}
|
|
|
|
|
2017-04-26 14:39:13 +03:00
|
|
|
// If the key operation didn't cause keypress event or caused keypress event
|
|
|
|
// but not prevented its default, we need to honor the command. For example,
|
|
|
|
// Korean IME sends "insertNewline:" when committing existing composition
|
|
|
|
// with Enter key press. In such case, the key operation has been consumed
|
|
|
|
// by the committing composition but we still need to handle the command.
|
|
|
|
return Destroyed() || !currentKeyEvent->CanHandleCommand();
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* IMEInputHandler implementation (static methods)
|
2009-10-01 06:52:50 +04:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IMEInputHandler::sStaticMembersInitialized = false;
|
2015-04-11 01:18:05 +03:00
|
|
|
bool IMEInputHandler::sCachedIsForRTLLangage = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
CFStringRef IMEInputHandler::sLatestIMEOpenedModeInputSourceID = nullptr;
|
|
|
|
IMEInputHandler* IMEInputHandler::sFocusedIMEHandler = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::InitStaticMembers()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
if (sStaticMembersInitialized)
|
|
|
|
return;
|
2011-10-01 04:20:33 +04:00
|
|
|
sStaticMembersInitialized = true;
|
2009-10-01 06:52:50 +04:00
|
|
|
// We need to check the keyboard layout changes on all applications.
|
|
|
|
CFNotificationCenterRef center = ::CFNotificationCenterGetDistributedCenter();
|
|
|
|
// XXX Don't we need to remove the observer at shut down?
|
|
|
|
// Mac Dev Center's document doesn't say how to remove the observer if
|
|
|
|
// the second parameter is NULL.
|
|
|
|
::CFNotificationCenterAddObserver(center, NULL,
|
|
|
|
OnCurrentTextInputSourceChange,
|
|
|
|
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
|
|
|
|
CFNotificationSuspensionBehaviorDeliverImmediately);
|
|
|
|
// Initiailize with the current keyboard layout
|
|
|
|
OnCurrentTextInputSourceChange(NULL, NULL,
|
|
|
|
kTISNotifySelectedKeyboardInputSourceChanged,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::OnCurrentTextInputSourceChange(CFNotificationCenterRef aCenter,
|
|
|
|
void* aObserver,
|
|
|
|
CFStringRef aName,
|
|
|
|
const void* aObject,
|
|
|
|
CFDictionaryRef aUserInfo)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
// Cache the latest IME opened mode to sLatestIMEOpenedModeInputSourceID.
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper tis;
|
2009-10-01 06:52:50 +04:00
|
|
|
tis.InitByCurrentInputSource();
|
|
|
|
if (tis.IsOpenedIMEMode()) {
|
|
|
|
tis.GetInputSourceID(sLatestIMEOpenedModeInputSourceID);
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Info)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
static CFStringRef sLastTIS = nullptr;
|
2011-07-21 04:33:16 +04:00
|
|
|
CFStringRef newTIS;
|
|
|
|
tis.GetInputSourceID(newTIS);
|
|
|
|
if (!sLastTIS ||
|
|
|
|
::CFStringCompare(sLastTIS, newTIS, 0) != kCFCompareEqualTo) {
|
2012-10-16 05:43:50 +04:00
|
|
|
TISInputSourceWrapper tis1, tis2, tis3, tis4, tis5;
|
2011-07-21 04:33:16 +04:00
|
|
|
tis1.InitByCurrentKeyboardLayout();
|
|
|
|
tis2.InitByCurrentASCIICapableInputSource();
|
|
|
|
tis3.InitByCurrentASCIICapableKeyboardLayout();
|
2012-10-16 05:43:50 +04:00
|
|
|
tis4.InitByCurrentInputMethodKeyboardLayoutOverride();
|
|
|
|
tis5.InitByTISInputSourceRef(tis.GetKeyboardLayoutInputSource());
|
|
|
|
CFStringRef is0 = nullptr, is1 = nullptr, is2 = nullptr, is3 = nullptr,
|
|
|
|
is4 = nullptr, is5 = nullptr, type0 = nullptr,
|
|
|
|
lang0 = nullptr, bundleID0 = nullptr;
|
2011-07-21 04:33:16 +04:00
|
|
|
tis.GetInputSourceID(is0);
|
|
|
|
tis1.GetInputSourceID(is1);
|
|
|
|
tis2.GetInputSourceID(is2);
|
|
|
|
tis3.GetInputSourceID(is3);
|
2012-10-16 05:43:50 +04:00
|
|
|
tis4.GetInputSourceID(is4);
|
|
|
|
tis5.GetInputSourceID(is5);
|
2011-07-21 04:33:16 +04:00
|
|
|
tis.GetInputSourceType(type0);
|
|
|
|
tis.GetPrimaryLanguage(lang0);
|
|
|
|
tis.GetBundleID(bundleID0);
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("IMEInputHandler::OnCurrentTextInputSourceChange,\n"
|
|
|
|
" Current Input Source is changed to:\n"
|
2013-07-13 06:53:23 +04:00
|
|
|
" currentInputContext=%p\n"
|
2011-07-21 04:33:16 +04:00
|
|
|
" %s\n"
|
|
|
|
" type=%s %s\n"
|
2012-10-16 05:43:50 +04:00
|
|
|
" overridden keyboard layout=%s\n"
|
|
|
|
" used keyboard layout for translation=%s\n"
|
2011-07-21 04:33:16 +04:00
|
|
|
" primary language=%s\n"
|
|
|
|
" bundle ID=%s\n"
|
|
|
|
" current ASCII capable Input Source=%s\n"
|
|
|
|
" current Keyboard Layout=%s\n"
|
|
|
|
" current ASCII capable Keyboard Layout=%s",
|
2013-07-13 06:53:23 +04:00
|
|
|
[NSTextInputContext currentInputContext], GetCharacters(is0),
|
2011-07-21 04:33:16 +04:00
|
|
|
GetCharacters(type0), tis.IsASCIICapable() ? "- ASCII capable " : "",
|
2012-10-16 05:43:50 +04:00
|
|
|
GetCharacters(is4), GetCharacters(is5),
|
2011-07-21 04:33:16 +04:00
|
|
|
GetCharacters(lang0), GetCharacters(bundleID0),
|
|
|
|
GetCharacters(is2), GetCharacters(is1), GetCharacters(is3)));
|
|
|
|
}
|
|
|
|
sLastTIS = newTIS;
|
|
|
|
}
|
2015-04-11 01:18:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When the direction is changed, all the children are notified.
|
|
|
|
* No need to treat the initial case separately because it is covered
|
|
|
|
* by the general case (sCachedIsForRTLLangage is initially false)
|
|
|
|
*/
|
|
|
|
if (sCachedIsForRTLLangage != tis.IsForRTLLanguage()) {
|
2016-05-19 11:47:49 +03:00
|
|
|
WidgetUtils::SendBidiKeyboardInfoToContent();
|
2015-04-11 01:18:05 +03:00
|
|
|
sCachedIsForRTLLangage = tis.IsForRTLLanguage();
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::FlushPendingMethods(nsITimer* aTimer, void* aClosure)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aClosure, "aClosure is null");
|
2011-05-08 14:19:15 +04:00
|
|
|
static_cast<IMEInputHandler*>(aClosure)->ExecutePendingMethods();
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CFArrayRef
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::CreateAllIMEModeList()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
const void* keys[] = { kTISPropertyInputSourceType };
|
|
|
|
const void* values[] = { kTISTypeKeyboardInputMode };
|
|
|
|
CFDictionaryRef filter =
|
|
|
|
::CFDictionaryCreate(kCFAllocatorDefault, keys, values, 1, NULL, NULL);
|
|
|
|
NS_ASSERTION(filter, "failed to create the filter");
|
|
|
|
CFArrayRef list = ::TISCreateInputSourceList(filter, true);
|
|
|
|
::CFRelease(filter);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2011-07-21 04:33:16 +04:00
|
|
|
IMEInputHandler::DebugPrintAllIMEModes()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Info)) {
|
2011-07-21 04:33:16 +04:00
|
|
|
CFArrayRef list = CreateAllIMEModeList();
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info, ("IME mode configuration:"));
|
2011-07-21 04:33:16 +04:00
|
|
|
CFIndex idx = ::CFArrayGetCount(list);
|
|
|
|
TISInputSourceWrapper tis;
|
|
|
|
for (CFIndex i = 0; i < idx; ++i) {
|
|
|
|
TISInputSourceRef inputSource = static_cast<TISInputSourceRef>(
|
|
|
|
const_cast<void *>(::CFArrayGetValueAtIndex(list, i)));
|
|
|
|
tis.InitByTISInputSourceRef(inputSource);
|
|
|
|
nsAutoString name, isid;
|
|
|
|
tis.GetLocalizedName(name);
|
|
|
|
tis.GetInputSourceID(isid);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-07-05 12:38:53 +03:00
|
|
|
(" %s\t<%s>%s%s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(name).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(isid).get(),
|
|
|
|
tis.IsASCIICapable() ? "" : "\t(Isn't ASCII capable)",
|
|
|
|
tis.IsEnabled() ? "" : "\t(Isn't Enabled)"));
|
2011-07-21 04:33:16 +04:00
|
|
|
}
|
|
|
|
::CFRelease(list);
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2010-08-16 12:20:27 +04:00
|
|
|
//static
|
|
|
|
TSMDocumentID
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::GetCurrentTSMDocumentID()
|
2010-08-16 12:20:27 +04:00
|
|
|
{
|
2013-07-13 06:53:24 +04:00
|
|
|
// At least on Mac OS X 10.6.x and 10.7.x, ::TSMGetActiveDocument() has a bug.
|
|
|
|
// The result of ::TSMGetActiveDocument() isn't modified for new active text
|
|
|
|
// input context until [NSTextInputContext currentInputContext] is called.
|
|
|
|
// Therefore, we need to call it here.
|
|
|
|
[NSTextInputContext currentInputContext];
|
2010-08-16 12:20:27 +04:00
|
|
|
return ::TSMGetActiveDocument();
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* IMEInputHandler implementation #1
|
2009-10-01 06:52:50 +04:00
|
|
|
* The methods are releated to the pending methods. Some jobs should be
|
|
|
|
* run after the stack is finished, e.g, some methods cannot run the jobs
|
|
|
|
* during processing the focus event. And also some other jobs should be
|
|
|
|
* run at the next focus event is processed.
|
|
|
|
* The pending methods are recorded in mPendingMethods. They are executed
|
|
|
|
* by ExecutePendingMethods via FlushPendingMethods.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2016-12-20 01:55:30 +03:00
|
|
|
nsresult
|
2016-03-16 07:47:49 +03:00
|
|
|
IMEInputHandler::NotifyIME(TextEventDispatcher* aTextEventDispatcher,
|
|
|
|
const IMENotification& aNotification)
|
|
|
|
{
|
|
|
|
switch (aNotification.mMessage) {
|
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
CommitIMEComposition();
|
|
|
|
return NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
CancelIMEComposition();
|
|
|
|
return NS_OK;
|
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
|
|
|
if (IsFocused()) {
|
|
|
|
nsIWidget* widget = aTextEventDispatcher->GetWidget();
|
|
|
|
if (widget && widget->GetInputContext().IsPasswordEditor()) {
|
|
|
|
EnableSecureEventInput();
|
|
|
|
} else {
|
|
|
|
EnsureSecureEventInputDisabled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OnFocusChangeInGecko(true);
|
|
|
|
return NS_OK;
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
OnFocusChangeInGecko(false);
|
|
|
|
return NS_OK;
|
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
OnSelectionChange(aNotification);
|
|
|
|
return NS_OK;
|
2017-06-29 10:03:57 +03:00
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
|
|
|
OnLayoutChange();
|
|
|
|
return NS_OK;
|
2016-03-16 07:47:49 +03:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-11 15:24:55 +03:00
|
|
|
NS_IMETHODIMP_(IMENotificationRequests)
|
|
|
|
IMEInputHandler::GetIMENotificationRequests()
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
{
|
|
|
|
// XXX Shouldn't we move floating window which shows composition string
|
|
|
|
// when plugin has focus and its parent is scrolled or the window is
|
|
|
|
// moved?
|
2017-04-11 15:24:55 +03:00
|
|
|
return IMENotificationRequests();
|
Bug 1343075 - Use GeckoEditableSupport from PuppetWidget; r=masayuki r=rbarker r=snorp r=esawin
Bug 1343075 - 1a. Add TextEventDispatcherListener::GetIMEUpdatePreference; r=masayuki
Add a GetIMEUpdatePreference method to TextEventDispatcherListener to
optionally control which IME notifications are received by NotifyIME.
This patch also makes nsBaseWidget forward its GetIMEUpdatePreference
call to the widget's native TextEventDispatcherListener.
Bug 1343075 - 1b. Implement GetIMEUpdatePreference for all TextEventDispatcherListener; r=masayuki
This patch implements GetIMEUpdatePreference for all
TextEventDispatcherListener implementations, by moving previous
implementations of nsIWidget::GetIMEUpdatePreference.
Bug 1343075 - 2. Allow setting a PuppetWidget's native TextEventDispatcherListener; r=masayuki
In PuppetWidget, add getter and setter for the widget's native
TextEventDispatcherListener. This allows overriding of PuppetWidget's
default IME handling. For example, on Android, the PuppetWidget's native
TextEventDispatcherListener will communicate directly with Java IME code
in the main process.
Bug 1343075 - 3. Add AIDL interface for main process; r=rbarker
Add AIDL definition and implementation for an interface for the main
process that child processes can access.
Bug 1343075 - 4. Set Gecko thread JNIEnv for child process; r=snorp
Add a JNIEnv* parameter to XRE_SetAndroidChildFds, which is used to set
the Gecko thread JNIEnv for child processes. XRE_SetAndroidChildFds is
the only Android-specific entry point for child processes, so I think
it's the most logical place to initialize JNI.
Bug 1343075 - 5. Support multiple remote GeckoEditableChild; r=esawin
Support remote GeckoEditableChild instances that are created in the
content processes and connect to the parent process GeckoEditableParent
through binders.
Support having multiple GeckoEditableChild instances in GeckoEditable by
keeping track of which child is currently focused, and only allow
calls to/from the focused child by using access tokens.
Bug 1343075 - 6. Add method to get GeckoEditableParent instance; r=esawin
Add IProcessManager.getEditableParent, which a content process can call
to get the GeckoEditableParent instance that corresponds to a given
content process tab, from the main process.
Bug 1343075 - 7. Support GeckoEditableSupport in content processes; r=esawin
Support creating and running GeckoEditableSupport attached to a
PuppetWidget in content processes.
Because we don't know PuppetWidget's lifetime as well as nsWindow's,
when attached to PuppetWidget, we need to attach/detach our native
object on focus/blur, respectively.
Bug 1343075 - 8. Connect GeckoEditableSupport on PuppetWidget creation; r=esawin
Listen to the "tab-child-created" notification and attach our content
process GeckoEditableSupport to the new PuppetWidget.
Bug 1343075 - 9. Update auto-generated bindings; r=me
2017-03-08 06:34:39 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:49 +03:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
IMEInputHandler::OnRemovedFrom(TextEventDispatcher* aTextEventDispatcher)
|
|
|
|
{
|
|
|
|
// XXX When input transaction is being stolen by add-on, what should we do?
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
IMEInputHandler::WillDispatchKeyboardEvent(
|
|
|
|
TextEventDispatcher* aTextEventDispatcher,
|
|
|
|
WidgetKeyboardEvent& aKeyboardEvent,
|
|
|
|
uint32_t aIndexOfKeypress,
|
|
|
|
void* aData)
|
|
|
|
{
|
2016-03-16 07:47:50 +03:00
|
|
|
// If the keyboard event is not caused by a native key event, we can do
|
|
|
|
// nothing here.
|
|
|
|
if (!aData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyEventState* currentKeyEvent = static_cast<KeyEventState*>(aData);
|
|
|
|
NSEvent* nativeEvent = currentKeyEvent->mKeyEvent;
|
|
|
|
nsAString* insertString = currentKeyEvent->mInsertString;
|
2017-05-16 05:59:35 +03:00
|
|
|
if (aKeyboardEvent.mMessage == eKeyPress && aIndexOfKeypress == 0 &&
|
|
|
|
(!insertString || insertString->IsEmpty())) {
|
|
|
|
// Inform the child process that this is an event that we want a reply
|
|
|
|
// from.
|
2017-07-21 11:22:08 +03:00
|
|
|
// XXX This should be called only when the target is a remote process.
|
|
|
|
// However, it's difficult to check it under widget/.
|
|
|
|
// So, let's do this here for now, then,
|
|
|
|
// EventStateManager::PreHandleEvent() will reset the flags if
|
|
|
|
// the event target isn't in remote process.
|
|
|
|
aKeyboardEvent.MarkAsWaitingReplyFromRemoteProcess();
|
2017-05-16 05:59:35 +03:00
|
|
|
}
|
2016-03-16 07:47:50 +03:00
|
|
|
if (KeyboardLayoutOverrideRef().mOverrideEnabled) {
|
|
|
|
TISInputSourceWrapper tis;
|
|
|
|
tis.InitByLayoutID(KeyboardLayoutOverrideRef().mKeyboardLayout, true);
|
|
|
|
tis.WillDispatchKeyboardEvent(nativeEvent, insertString, aKeyboardEvent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TISInputSourceWrapper::CurrentInputSource().
|
|
|
|
WillDispatchKeyboardEvent(nativeEvent, insertString, aKeyboardEvent);
|
2016-03-16 07:47:49 +03:00
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
void
|
2013-07-11 11:46:36 +04:00
|
|
|
IMEInputHandler::NotifyIMEOfFocusChangeInGecko()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-11 11:46:36 +04:00
|
|
|
("%p IMEInputHandler::NotifyIMEOfFocusChangeInGecko, "
|
|
|
|
"Destroyed()=%s, IsFocused()=%s, inputContext=%p",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, TrueOrFalse(Destroyed()), TrueOrFalse(IsFocused()),
|
2013-07-11 11:46:36 +04:00
|
|
|
mView ? [mView inputContext] : nullptr));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed()) {
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
if (!IsFocused()) {
|
|
|
|
// retry at next focus event
|
2013-07-11 11:46:36 +04:00
|
|
|
mPendingMethods |= kNotifyIMEOfFocusChangeInGecko;
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:46:36 +04:00
|
|
|
MOZ_ASSERT(mView);
|
|
|
|
NSTextInputContext* inputContext = [mView inputContext];
|
|
|
|
NS_ENSURE_TRUE_VOID(inputContext);
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2013-07-11 11:46:36 +04:00
|
|
|
// When an <input> element on a XUL <panel> element gets focus from an <input>
|
|
|
|
// element on the opener window of the <panel> element, the owner window
|
|
|
|
// still has native focus. Therefore, IMEs may store the opener window's
|
|
|
|
// level at this time because they don't know the actual focus is moved to
|
|
|
|
// different window. If IMEs try to get the newest window level after the
|
|
|
|
// focus change, we return the window level of the XUL <panel>'s widget.
|
|
|
|
// Therefore, let's emulate the native focus change. Then, IMEs can refresh
|
|
|
|
// the stored window level.
|
|
|
|
[inputContext deactivate];
|
|
|
|
[inputContext activate];
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::DiscardIMEComposition()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::DiscardIMEComposition, "
|
2013-07-13 06:53:23 +04:00
|
|
|
"Destroyed()=%s, IsFocused()=%s, mView=%p, inputContext=%p",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, TrueOrFalse(Destroyed()), TrueOrFalse(IsFocused()),
|
2013-07-13 06:53:23 +04:00
|
|
|
mView, mView ? [mView inputContext] : nullptr));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed()) {
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
if (!IsFocused()) {
|
|
|
|
// retry at next focus event
|
|
|
|
mPendingMethods |= kDiscardIMEComposition;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-13 06:53:24 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(mView);
|
|
|
|
NSTextInputContext* inputContext = [mView inputContext];
|
|
|
|
NS_ENSURE_TRUE_VOID(inputContext);
|
2011-10-01 04:20:33 +04:00
|
|
|
mIgnoreIMECommit = true;
|
2013-07-13 06:53:24 +04:00
|
|
|
[inputContext discardMarkedText];
|
2011-10-01 04:20:33 +04:00
|
|
|
mIgnoreIMECommit = false;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::SyncASCIICapableOnly()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::SyncASCIICapableOnly, "
|
|
|
|
"Destroyed()=%s, IsFocused()=%s, mIsASCIICapableOnly=%s, "
|
|
|
|
"GetCurrentTSMDocumentID()=%p",
|
|
|
|
this, TrueOrFalse(Destroyed()), TrueOrFalse(IsFocused()),
|
|
|
|
TrueOrFalse(mIsASCIICapableOnly), GetCurrentTSMDocumentID()));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed()) {
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
if (!IsFocused()) {
|
|
|
|
// retry at next focus event
|
|
|
|
mPendingMethods |= kSyncASCIICapableOnly;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-08-16 12:20:27 +04:00
|
|
|
TSMDocumentID doc = GetCurrentTSMDocumentID();
|
2009-10-01 06:52:50 +04:00
|
|
|
if (!doc) {
|
|
|
|
// retry
|
|
|
|
mPendingMethods |= kSyncASCIICapableOnly;
|
|
|
|
NS_WARNING("Application is active but there is no active document");
|
|
|
|
ResetTimer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsASCIICapableOnly) {
|
|
|
|
CFArrayRef ASCIICapableTISList = ::TISCreateASCIICapableInputSourceList();
|
|
|
|
::TSMSetDocumentProperty(doc,
|
|
|
|
kTSMDocumentEnabledInputSourcesPropertyTag,
|
|
|
|
sizeof(CFArrayRef),
|
|
|
|
&ASCIICapableTISList);
|
|
|
|
::CFRelease(ASCIICapableTISList);
|
|
|
|
} else {
|
|
|
|
::TSMRemoveDocumentProperty(doc,
|
|
|
|
kTSMDocumentEnabledInputSourcesPropertyTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::ResetTimer()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mPendingMethods != 0,
|
|
|
|
"There are not pending methods, why this is called?");
|
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
2010-08-16 12:20:27 +04:00
|
|
|
} else {
|
|
|
|
mTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(mTimer, );
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
2017-06-29 22:13:25 +03:00
|
|
|
mTimer->InitWithNamedFuncCallback(FlushPendingMethods, this, 0,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"IMEInputHandler::FlushPendingMethods");
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::ExecutePendingMethods()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2010-08-16 12:20:27 +04:00
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mTimer = nullptr;
|
2010-08-16 12:20:27 +04:00
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
if (![[NSApplication sharedApplication] isActive]) {
|
2011-10-01 04:20:33 +04:00
|
|
|
mIsInFocusProcessing = false;
|
2009-10-01 06:52:50 +04:00
|
|
|
// If we're not active, we should retry at focus event
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t pendingMethods = mPendingMethods;
|
2009-10-01 06:52:50 +04:00
|
|
|
// First, reset the pending method flags because if each methods cannot
|
|
|
|
// run now, they can reentry to the pending flags by theirselves.
|
|
|
|
mPendingMethods = 0;
|
|
|
|
|
|
|
|
if (pendingMethods & kDiscardIMEComposition)
|
|
|
|
DiscardIMEComposition();
|
|
|
|
if (pendingMethods & kSyncASCIICapableOnly)
|
|
|
|
SyncASCIICapableOnly();
|
2013-07-11 11:46:36 +04:00
|
|
|
if (pendingMethods & kNotifyIMEOfFocusChangeInGecko) {
|
|
|
|
NotifyIMEOfFocusChangeInGecko();
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mIsInFocusProcessing = false;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2011-02-17 10:41:36 +03:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* IMEInputHandler implementation (native event handlers)
|
2011-02-17 10:41:36 +03:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2016-06-04 03:49:21 +03:00
|
|
|
TextRangeType
|
2012-08-22 19:56:38 +04:00
|
|
|
IMEInputHandler::ConvertToTextRangeType(uint32_t aUnderlineStyle,
|
2011-05-08 14:19:15 +04:00
|
|
|
NSRange& aSelectedRange)
|
2011-02-17 10:41:36 +03:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::ConvertToTextRangeType, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aUnderlineStyle=%u, aSelectedRange.length=%lu,",
|
|
|
|
this, aUnderlineStyle, static_cast<unsigned long>(aSelectedRange.length)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-17 10:41:36 +03:00
|
|
|
// We assume that aUnderlineStyle is NSUnderlineStyleSingle or
|
|
|
|
// NSUnderlineStyleThick. NSUnderlineStyleThick should indicate a selected
|
|
|
|
// clause. Otherwise, should indicate non-selected clause.
|
|
|
|
|
|
|
|
if (aSelectedRange.length == 0) {
|
|
|
|
switch (aUnderlineStyle) {
|
|
|
|
case NSUnderlineStyleSingle:
|
2016-06-03 12:48:37 +03:00
|
|
|
return TextRangeType::eRawClause;
|
2011-02-17 10:41:36 +03:00
|
|
|
case NSUnderlineStyleThick:
|
2016-06-03 12:57:21 +03:00
|
|
|
return TextRangeType::eSelectedRawClause;
|
2011-02-17 10:41:36 +03:00
|
|
|
default:
|
|
|
|
NS_WARNING("Unexpected line style");
|
2016-06-03 12:57:21 +03:00
|
|
|
return TextRangeType::eSelectedRawClause;
|
2011-02-17 10:41:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aUnderlineStyle) {
|
|
|
|
case NSUnderlineStyleSingle:
|
2016-06-03 13:05:32 +03:00
|
|
|
return TextRangeType::eConvertedClause;
|
2011-02-17 10:41:36 +03:00
|
|
|
case NSUnderlineStyleThick:
|
2016-06-03 13:15:21 +03:00
|
|
|
return TextRangeType::eSelectedClause;
|
2011-02-17 10:41:36 +03:00
|
|
|
default:
|
|
|
|
NS_WARNING("Unexpected line style");
|
2016-06-03 13:15:21 +03:00
|
|
|
return TextRangeType::eSelectedClause;
|
2011-02-17 10:41:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::GetRangeCount(NSAttributedString *aAttrString)
|
2011-02-17 10:41:36 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
|
|
|
// Iterate through aAttrString for the NSUnderlineStyleAttributeName and
|
|
|
|
// count the different segments adjusting limitRange as we go.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
2011-02-17 10:41:36 +03:00
|
|
|
NSRange effectiveRange;
|
|
|
|
NSRange limitRange = NSMakeRange(0, [aAttrString length]);
|
|
|
|
while (limitRange.length > 0) {
|
|
|
|
[aAttrString attribute:NSUnderlineStyleAttributeName
|
|
|
|
atIndex:limitRange.location
|
|
|
|
longestEffectiveRange:&effectiveRange
|
|
|
|
inRange:limitRange];
|
|
|
|
limitRange =
|
|
|
|
NSMakeRange(NSMaxRange(effectiveRange),
|
|
|
|
NSMaxRange(limitRange) - NSMaxRange(effectiveRange));
|
|
|
|
count++;
|
|
|
|
}
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-12-16 06:16:31 +03:00
|
|
|
("%p IMEInputHandler::GetRangeCount, aAttrString=\"%s\", count=%u",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, GetCharacters([aAttrString string]), count));
|
|
|
|
|
2011-02-17 10:41:36 +03:00
|
|
|
return count;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(0);
|
|
|
|
}
|
|
|
|
|
2014-03-04 17:48:27 +04:00
|
|
|
already_AddRefed<mozilla::TextRangeArray>
|
|
|
|
IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
|
|
|
|
NSRange& aSelectedRange)
|
2011-02-17 10:41:36 +03:00
|
|
|
{
|
2014-03-04 17:48:27 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
2011-02-17 10:41:36 +03:00
|
|
|
|
2016-09-26 11:19:30 +03:00
|
|
|
RefPtr<mozilla::TextRangeArray> textRangeArray =
|
|
|
|
new mozilla::TextRangeArray();
|
|
|
|
|
|
|
|
// Note that we shouldn't append ranges when composition string
|
|
|
|
// is empty because it may cause TextComposition confused.
|
|
|
|
if (![aAttrString length]) {
|
|
|
|
return textRangeArray.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-01 11:22:59 +04:00
|
|
|
// Convert the Cocoa range into the TextRange Array used in Gecko.
|
2011-02-17 10:41:36 +03:00
|
|
|
// Iterate through the attributed string and map the underline attribute to
|
|
|
|
// Gecko IME textrange attributes. We may need to change the code here if
|
|
|
|
// we change the implementation of validAttributesForMarkedText.
|
|
|
|
NSRange limitRange = NSMakeRange(0, [aAttrString length]);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rangeCount = GetRangeCount(aAttrString);
|
|
|
|
for (uint32_t i = 0; i < rangeCount && limitRange.length > 0; i++) {
|
2011-02-17 10:41:36 +03:00
|
|
|
NSRange effectiveRange;
|
|
|
|
id attributeValue = [aAttrString attribute:NSUnderlineStyleAttributeName
|
|
|
|
atIndex:limitRange.location
|
|
|
|
longestEffectiveRange:&effectiveRange
|
|
|
|
inRange:limitRange];
|
|
|
|
|
2013-10-01 11:22:59 +04:00
|
|
|
TextRange range;
|
2011-02-17 10:41:36 +03:00
|
|
|
range.mStartOffset = effectiveRange.location;
|
|
|
|
range.mEndOffset = NSMaxRange(effectiveRange);
|
|
|
|
range.mRangeType =
|
|
|
|
ConvertToTextRangeType([attributeValue intValue], aSelectedRange);
|
2014-03-04 17:48:27 +04:00
|
|
|
textRangeArray->AppendElement(range);
|
2011-02-17 10:41:36 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2014-03-04 17:48:27 +04:00
|
|
|
("%p IMEInputHandler::CreateTextRangeArray, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"range={ mStartOffset=%u, mEndOffset=%u, mRangeType=%s }",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, range.mStartOffset, range.mEndOffset,
|
2016-06-04 03:49:21 +03:00
|
|
|
ToChar(range.mRangeType)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-17 10:41:36 +03:00
|
|
|
limitRange =
|
|
|
|
NSMakeRange(NSMaxRange(effectiveRange),
|
|
|
|
NSMaxRange(limitRange) - NSMaxRange(effectiveRange));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get current caret position.
|
2013-10-01 11:22:59 +04:00
|
|
|
TextRange range;
|
2011-02-17 10:41:36 +03:00
|
|
|
range.mStartOffset = aSelectedRange.location + aSelectedRange.length;
|
|
|
|
range.mEndOffset = range.mStartOffset;
|
2016-06-03 12:40:06 +03:00
|
|
|
range.mRangeType = TextRangeType::eCaret;
|
2014-03-04 17:48:27 +04:00
|
|
|
textRangeArray->AppendElement(range);
|
2011-02-17 10:41:36 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2014-03-04 17:48:27 +04:00
|
|
|
("%p IMEInputHandler::CreateTextRangeArray, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"range={ mStartOffset=%u, mEndOffset=%u, mRangeType=%s }",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, range.mStartOffset, range.mEndOffset,
|
2016-06-04 03:49:21 +03:00
|
|
|
ToChar(range.mRangeType)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2014-03-04 17:48:27 +04:00
|
|
|
return textRangeArray.forget();
|
|
|
|
|
2014-05-26 05:16:01 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSNULL;
|
2011-02-17 10:41:36 +03:00
|
|
|
}
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
bool
|
|
|
|
IMEInputHandler::DispatchCompositionStartEvent()
|
|
|
|
{
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionStartEvent, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"mSelectedRange={ location=%lu, length=%lu }, Destroyed()=%s, "
|
2015-09-19 05:01:57 +03:00
|
|
|
"mView=%p, mWidget=%p, inputContext=%p, mIsIMEComposing=%s",
|
2016-12-16 06:16:31 +03:00
|
|
|
this, static_cast<unsigned long>(SelectedRange().location),
|
|
|
|
static_cast<unsigned long>(mSelectedRange.length),
|
2015-09-19 05:01:57 +03:00
|
|
|
TrueOrFalse(Destroyed()), mView, mWidget,
|
|
|
|
mView ? [mView inputContext] : nullptr, TrueOrFalse(mIsIMEComposing)));
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionStartEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-19 05:01:57 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(!mIsIMEComposing, "There is a composition already");
|
|
|
|
mIsIMEComposing = true;
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsEventStatus status;
|
|
|
|
rv = mDispatcher->StartComposition(status);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionStartEvent, "
|
|
|
|
"FAILED, due to StartComposition() failure", this));
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-19 05:01:57 +03:00
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionStartEvent, "
|
|
|
|
"destroyed by compositionstart event", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FYI: compositionstart may cause committing composition by the webapp.
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!mIsIMEComposing) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FYI: The selection range might have been modified by a compositionstart
|
|
|
|
// event handler.
|
|
|
|
mIMECompositionStart = SelectedRange().location;
|
|
|
|
return true;
|
2015-09-19 05:01:57 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-10-07 14:01:49 +04:00
|
|
|
IMEInputHandler::DispatchCompositionChangeEvent(const nsString& aText,
|
|
|
|
NSAttributedString* aAttrString,
|
2014-11-25 08:02:34 +03:00
|
|
|
NSRange& aSelectedRange)
|
2011-02-17 10:41:36 +03:00
|
|
|
{
|
2015-09-19 05:01:57 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2014-10-07 14:01:49 +04:00
|
|
|
("%p IMEInputHandler::DispatchCompositionChangeEvent, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"aText=\"%s\", aAttrString=\"%s\", "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aSelectedRange={ location=%lu, length=%lu }, Destroyed()=%s, mView=%p, "
|
2015-09-19 05:01:57 +03:00
|
|
|
"mWidget=%p, inputContext=%p, mIsIMEComposing=%s",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, NS_ConvertUTF16toUTF8(aText).get(),
|
|
|
|
GetCharacters([aAttrString string]),
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>(aSelectedRange.location),
|
|
|
|
static_cast<unsigned long>(aSelectedRange.length),
|
2015-09-19 05:01:57 +03:00
|
|
|
TrueOrFalse(Destroyed()), mView, mWidget,
|
|
|
|
mView ? [mView inputContext] : nullptr, TrueOrFalse(mIsIMEComposing)));
|
2011-02-17 10:41:36 +03:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(!Destroyed(), false);
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
NS_ASSERTION(mIsIMEComposing, "We're not in composition");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionChangeEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<TextRangeArray> rangeArray =
|
2014-11-25 08:02:34 +03:00
|
|
|
CreateTextRangeArray(aAttrString, aSelectedRange);
|
2015-09-19 05:01:57 +03:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
rv = mDispatcher->SetPendingComposition(aText, rangeArray);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionChangeEvent, "
|
|
|
|
"FAILED, due to SetPendingComposition() failure", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
mSelectedRange.location = mIMECompositionStart + aSelectedRange.location;
|
|
|
|
mSelectedRange.length = aSelectedRange.length;
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
if (mIMECompositionString) {
|
|
|
|
[mIMECompositionString release];
|
|
|
|
}
|
|
|
|
mIMECompositionString = [[aAttrString string] retain];
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsEventStatus status;
|
|
|
|
rv = mDispatcher->FlushPendingComposition(status);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionChangeEvent, "
|
|
|
|
"FAILED, due to FlushPendingComposition() failure", this));
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-19 05:01:57 +03:00
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionChangeEvent, "
|
|
|
|
"destroyed by compositionchange event", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FYI: compositionstart may cause committing composition by the webapp.
|
|
|
|
return mIsIMEComposing;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2011-02-17 10:41:36 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 08:02:34 +03:00
|
|
|
bool
|
|
|
|
IMEInputHandler::DispatchCompositionCommitEvent(const nsAString* aCommitString)
|
|
|
|
{
|
2015-09-19 05:01:57 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2014-11-25 08:02:34 +03:00
|
|
|
("%p IMEInputHandler::DispatchCompositionCommitEvent, "
|
2015-09-19 05:01:57 +03:00
|
|
|
"aCommitString=0x%p (\"%s\"), Destroyed()=%s, mView=%p, mWidget=%p, "
|
|
|
|
"inputContext=%p, mIsIMEComposing=%s",
|
2014-11-25 08:02:34 +03:00
|
|
|
this, aCommitString,
|
|
|
|
aCommitString ? NS_ConvertUTF16toUTF8(*aCommitString).get() : "",
|
2015-09-19 05:01:57 +03:00
|
|
|
TrueOrFalse(Destroyed()), mView, mWidget,
|
|
|
|
mView ? [mView inputContext] : nullptr, TrueOrFalse(mIsIMEComposing)));
|
2014-11-25 08:02:34 +03:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
NS_ASSERTION(mIsIMEComposing, "We're not in composition");
|
2014-11-25 08:02:34 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2014-11-25 08:02:34 +03:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!Destroyed()) {
|
2015-09-19 05:01:57 +03:00
|
|
|
// IME may query selection immediately after this, however, in e10s mode,
|
|
|
|
// OnSelectionChange() will be called asynchronously. Until then, we
|
|
|
|
// should emulate expected selection range if the webapp does nothing.
|
|
|
|
mSelectedRange.location = mIMECompositionStart;
|
2016-03-16 07:47:50 +03:00
|
|
|
if (aCommitString) {
|
|
|
|
mSelectedRange.location += aCommitString->Length();
|
2015-09-19 05:01:57 +03:00
|
|
|
} else if (mIMECompositionString) {
|
|
|
|
nsAutoString commitString;
|
|
|
|
nsCocoaUtils::GetStringForNSString(mIMECompositionString, commitString);
|
|
|
|
mSelectedRange.location += commitString.Length();
|
|
|
|
}
|
|
|
|
mSelectedRange.length = 0;
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
nsresult rv = mDispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionCommitEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
} else {
|
|
|
|
nsEventStatus status;
|
|
|
|
rv = mDispatcher->CommitComposition(status, aCommitString);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionCommitEvent, "
|
|
|
|
"FAILED, due to BeginNativeInputTransaction() failure", this));
|
|
|
|
}
|
|
|
|
}
|
2015-09-19 05:01:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mIsIMEComposing = false;
|
2015-09-19 05:01:57 +03:00
|
|
|
mIMECompositionStart = UINT32_MAX;
|
2015-09-19 05:01:57 +03:00
|
|
|
if (mIMECompositionString) {
|
|
|
|
[mIMECompositionString release];
|
|
|
|
mIMECompositionString = nullptr;
|
2014-11-25 08:02:34 +03:00
|
|
|
}
|
2015-09-19 05:01:57 +03:00
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::DispatchCompositionCommitEvent, "
|
|
|
|
"destroyed by compositioncommit event", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2014-11-25 08:02:34 +03:00
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:34 +03:00
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::InsertTextAsCommittingComposition(
|
2013-07-11 11:46:35 +04:00
|
|
|
NSAttributedString* aAttrString,
|
|
|
|
NSRange* aReplacementRange)
|
2011-02-19 07:55:34 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aAttrString=\"%s\", aReplacementRange=%p { location=%lu, length=%lu }, "
|
2013-07-11 11:46:35 +04:00
|
|
|
"Destroyed()=%s, IsIMEComposing()=%s, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"mMarkedRange={ location=%lu, length=%lu }",
|
2013-07-11 11:46:35 +04:00
|
|
|
this, GetCharacters([aAttrString string]), aReplacementRange,
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>(aReplacementRange ? aReplacementRange->location : 0),
|
|
|
|
static_cast<unsigned long>(aReplacementRange ? aReplacementRange->length : 0),
|
2013-07-11 11:46:35 +04:00
|
|
|
TrueOrFalse(Destroyed()), TrueOrFalse(IsIMEComposing()),
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>(mMarkedRange.location),
|
|
|
|
static_cast<unsigned long>(mMarkedRange.length)));
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
if (IgnoreIMECommit()) {
|
|
|
|
MOZ_CRASH("IMEInputHandler::InsertTextAsCommittingComposition() must not"
|
|
|
|
"be called while canceling the composition");
|
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
// First, commit current composition with the latest composition string if the
|
|
|
|
// replacement range is different from marked range.
|
|
|
|
if (IsIMEComposing() && aReplacementRange &&
|
|
|
|
aReplacementRange->location != NSNotFound &&
|
|
|
|
!NSEqualRanges(MarkedRange(), *aReplacementRange)) {
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionCommitEvent()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-11 11:46:35 +04:00
|
|
|
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
|
|
|
"destroyed by commiting composition for setting replacement range",
|
|
|
|
this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2011-02-19 07:55:34 +03:00
|
|
|
|
|
|
|
nsString str;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GetStringForNSString([aAttrString string], str);
|
2011-02-19 07:55:34 +03:00
|
|
|
|
|
|
|
if (!IsIMEComposing()) {
|
2013-07-11 11:46:35 +04:00
|
|
|
// If there is no selection and replacement range is specified, set the
|
|
|
|
// range as selection.
|
|
|
|
if (aReplacementRange && aReplacementRange->location != NSNotFound &&
|
|
|
|
!NSEqualRanges(SelectedRange(), *aReplacementRange)) {
|
|
|
|
NS_ENSURE_TRUE_VOID(SetSelection(*aReplacementRange));
|
|
|
|
}
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionStartEvent()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
2015-09-19 05:01:57 +03:00
|
|
|
"cannot continue handling composition after compositionstart", this));
|
2011-05-08 14:19:23 +04:00
|
|
|
return;
|
2011-02-19 07:55:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionCommitEvent(&str)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::InsertTextAsCommittingComposition, "
|
2014-11-25 08:02:34 +03:00
|
|
|
"destroyed by compositioncommit event", this));
|
2011-05-08 14:19:23 +04:00
|
|
|
return;
|
2011-02-19 07:55:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mMarkedRange = NSMakeRange(NSNotFound, 0);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::SetMarkedText(NSAttributedString* aAttrString,
|
2013-07-11 11:46:36 +04:00
|
|
|
NSRange& aSelectedRange,
|
|
|
|
NSRange* aReplacementRange)
|
2011-02-19 07:55:34 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::SetMarkedText, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aAttrString=\"%s\", aSelectedRange={ location=%lu, length=%lu }, "
|
|
|
|
"aReplacementRange=%p { location=%lu, length=%lu }, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"Destroyed()=%s, IgnoreIMEComposition()=%s, IsIMEComposing()=%s, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"mMarkedRange={ location=%lu, length=%lu }, keyevent=%p, "
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
"keydownHandled=%s, keypressDispatched=%s, causedOtherKeyEvents=%s, "
|
|
|
|
"compositionDispatched=%s",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, GetCharacters([aAttrString string]),
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>(aSelectedRange.location),
|
|
|
|
static_cast<unsigned long>(aSelectedRange.length), aReplacementRange,
|
|
|
|
static_cast<unsigned long>(aReplacementRange ? aReplacementRange->location : 0),
|
|
|
|
static_cast<unsigned long>(aReplacementRange ? aReplacementRange->length : 0),
|
2013-07-11 11:46:36 +04:00
|
|
|
TrueOrFalse(Destroyed()), TrueOrFalse(IgnoreIMEComposition()),
|
|
|
|
TrueOrFalse(IsIMEComposing()),
|
2016-12-16 06:16:31 +03:00
|
|
|
static_cast<unsigned long>(mMarkedRange.location),
|
|
|
|
static_cast<unsigned long>(mMarkedRange.length),
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
currentKeyEvent ? currentKeyEvent->mKeyEvent : nullptr,
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyDownHandled) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mKeyPressDispatched) : "N/A",
|
|
|
|
currentKeyEvent ?
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
TrueOrFalse(currentKeyEvent->mCausedOtherKeyEvents) : "N/A",
|
|
|
|
currentKeyEvent ?
|
|
|
|
TrueOrFalse(currentKeyEvent->mCompositionDispatched) : "N/A"));
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
// If SetMarkedText() is called during handling a key press, that means that
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
// the key event caused this composition. So, keypress event shouldn't
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
// be dispatched later, let's mark the key event causing composition event.
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
if (currentKeyEvent) {
|
Bug 1317906 When a key press causes a call of InsertText(), it shouldn't mark keypress as consumed but instead, should mark InsertText() caused composition r=m_kato
Currently, when InsertText() which is caused by a key press causes committing composition, it consumes keypress event. However, Korean 2-set IME calls InsertText() two times when there is composition and key press causes inserting another character next to the composition. In this case, current design ignores second InsertText() becuase keypress event is already consumed by the first InsertText() call.
For solving this issue safely, InsertText() should mark current key event as "dispatched composition event". Then, following InsertText() calls should cause composition events instead of keypress events since following event order is too odd:
1. keydown (currently not dispatched by TextEventDisaptcher)
2. compositionupdate
3. compositionend
4. keypress
5. keyup
with the new design this becomes:
1. keydown (currently not dispatched by TextEventDispatcher)
2. compositionupdate
3. compositionend
4. compositionstart
5. compositionupdate
6. compositionend
7. keyup
This is similar to Chromium, although, Chromium includes the second InsertText() call into the first composition, we need to fix it later due to risky.
MozReview-Commit-ID: GL42cU2WIL0
--HG--
extra : rebase_source : 2063c56166f6c9ccee25a74e1d29f94daa6b159c
2016-11-17 07:35:21 +03:00
|
|
|
currentKeyEvent->mCompositionDispatched = true;
|
Bug 1312649 part.1 TextInputHandler::InsertText() should dispatch composition events instead of keypress events when it replaces a range which is different from current selection r=m_kato
Vietnamese Telex IME handles Backspace key immediately after inputting a word even when there is no marked text. At this time, it tries to replace the word with specific string. In such case, our editor shouldn't remove anything at handling the Backspace keypress event.
For avoiding this issue, InserText() should dispatch a set of composition for inserting the specified text into the range. Then, editor won't perform any action of the key.
Additionally, when a Backspace keydown tries to remove the last character of the word, Telex removes it with a composition. At this time, it creates dummy marked text "a" and make it empty later. So, in this case, InsertText() won't be called, therefore, we need to consume the Backspace keypress when SetMarkedText() is called for preventing removing the previous character of the word.
MozReview-Commit-ID: LfeEHDWn0cZ
--HG--
extra : rebase_source : 4753262ef16bc3875754ae38e966d8512947ad89
2016-11-07 04:30:05 +03:00
|
|
|
}
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed() || IgnoreIMEComposition()) {
|
2011-02-19 07:55:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2013-07-11 11:46:36 +04:00
|
|
|
// First, commit current composition with the latest composition string if the
|
|
|
|
// replacement range is different from marked range.
|
|
|
|
if (IsIMEComposing() && aReplacementRange &&
|
|
|
|
aReplacementRange->location != NSNotFound &&
|
|
|
|
!NSEqualRanges(MarkedRange(), *aReplacementRange)) {
|
2015-09-19 05:01:57 +03:00
|
|
|
AutoRestore<bool> ignoreIMECommit(mIgnoreIMECommit);
|
2013-07-11 11:46:36 +04:00
|
|
|
mIgnoreIMECommit = false;
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionCommitEvent()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-11 11:46:36 +04:00
|
|
|
("%p IMEInputHandler::SetMarkedText, "
|
|
|
|
"destroyed by commiting composition for setting replacement range",
|
|
|
|
this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:34 +03:00
|
|
|
nsString str;
|
2011-07-21 04:33:16 +04:00
|
|
|
nsCocoaUtils::GetStringForNSString([aAttrString string], str);
|
2011-02-19 07:55:34 +03:00
|
|
|
|
|
|
|
mMarkedRange.length = str.Length();
|
|
|
|
|
|
|
|
if (!IsIMEComposing() && !str.IsEmpty()) {
|
2013-07-11 11:46:36 +04:00
|
|
|
// If there is no selection and replacement range is specified, set the
|
|
|
|
// range as selection.
|
|
|
|
if (aReplacementRange && aReplacementRange->location != NSNotFound &&
|
|
|
|
!NSEqualRanges(SelectedRange(), *aReplacementRange)) {
|
|
|
|
NS_ENSURE_TRUE_VOID(SetSelection(*aReplacementRange));
|
|
|
|
}
|
|
|
|
|
|
|
|
mMarkedRange.location = SelectedRange().location;
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionStartEvent()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2015-09-19 05:01:57 +03:00
|
|
|
("%p IMEInputHandler::SetMarkedText, cannot continue handling "
|
|
|
|
"composition after dispatching compositionstart", this));
|
2011-05-08 14:19:23 +04:00
|
|
|
return;
|
2011-02-19 07:55:34 +03:00
|
|
|
}
|
2014-11-25 08:02:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!str.IsEmpty()) {
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionChangeEvent(str, aAttrString, aSelectedRange)) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2015-09-19 05:01:57 +03:00
|
|
|
("%p IMEInputHandler::SetMarkedText, cannot continue handling "
|
|
|
|
"composition after dispatching compositionchange", this));
|
2011-02-19 07:55:34 +03:00
|
|
|
}
|
2014-11-25 08:02:34 +03:00
|
|
|
return;
|
|
|
|
}
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2014-11-25 08:02:34 +03:00
|
|
|
// If the composition string becomes empty string, we should commit
|
|
|
|
// current composition.
|
2015-09-19 05:01:57 +03:00
|
|
|
if (!DispatchCompositionCommitEvent(&EmptyString())) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2014-11-25 08:02:34 +03:00
|
|
|
("%p IMEInputHandler::SetMarkedText, "
|
|
|
|
"destroyed by compositioncommit event", this));
|
2011-02-19 07:55:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
NSAttributedString*
|
2013-07-11 11:46:35 +04:00
|
|
|
IMEInputHandler::GetAttributedSubstringFromRange(NSRange& aRange,
|
|
|
|
NSRange* aActualRange)
|
2011-02-19 07:55:49 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::GetAttributedSubstringFromRange, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aRange={ location=%lu, length=%lu }, aActualRange=%p, Destroyed()=%s",
|
|
|
|
this, static_cast<unsigned long>(aRange.location),
|
|
|
|
static_cast<unsigned long>(aRange.length), aActualRange,
|
2013-07-11 11:46:35 +04:00
|
|
|
TrueOrFalse(Destroyed())));
|
|
|
|
|
|
|
|
if (aActualRange) {
|
|
|
|
*aActualRange = NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
2011-02-19 07:55:49 +03:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed() || aRange.location == NSNotFound || aRange.length == 0) {
|
2011-02-19 07:55:49 +03:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
// If we're in composing, the queried range may be in the composition string.
|
|
|
|
// In such case, we should use mIMECompositionString since if the composition
|
|
|
|
// string is handled by a remote process, the content cache may be out of
|
|
|
|
// date.
|
2016-11-07 10:19:41 +03:00
|
|
|
// XXX Should we set composition string attributes? Although, Blink claims
|
|
|
|
// that some attributes of marked text are supported, but they return
|
|
|
|
// just marked string without any style. So, let's keep current behavior
|
|
|
|
// at least for now.
|
2015-09-19 05:01:57 +03:00
|
|
|
NSUInteger compositionLength =
|
|
|
|
mIMECompositionString ? [mIMECompositionString length] : 0;
|
|
|
|
if (mIMECompositionStart != UINT32_MAX &&
|
|
|
|
mIMECompositionStart >= aRange.location &&
|
|
|
|
mIMECompositionStart + compositionLength <=
|
|
|
|
aRange.location + aRange.length) {
|
|
|
|
NSRange range =
|
|
|
|
NSMakeRange(aRange.location - mIMECompositionStart, aRange.length);
|
|
|
|
NSString* nsstr = [mIMECompositionString substringWithRange:range];
|
|
|
|
NSMutableAttributedString* result =
|
|
|
|
[[[NSMutableAttributedString alloc] initWithString:nsstr
|
|
|
|
attributes:nil] autorelease];
|
|
|
|
// XXX We cannot return font information in this case. However, this
|
|
|
|
// case must occur only when IME tries to confirm if composing string
|
|
|
|
// is handled as expected.
|
|
|
|
if (aActualRange) {
|
|
|
|
*aActualRange = aRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Info)) {
|
|
|
|
nsAutoString str;
|
|
|
|
nsCocoaUtils::GetStringForNSString(nsstr, str);
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::GetAttributedSubstringFromRange, "
|
|
|
|
"computed with mIMECompositionString (result string=\"%s\")",
|
|
|
|
this, NS_ConvertUTF16toUTF8(str).get()));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
nsAutoString str;
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent textContent(true, eQueryTextContent, mWidget);
|
2016-08-19 15:51:54 +03:00
|
|
|
WidgetQueryContentEvent::Options options;
|
|
|
|
int64_t startOffset = aRange.location;
|
|
|
|
if (IsIMEComposing()) {
|
|
|
|
// The composition may be at different offset from the selection start
|
|
|
|
// offset at dispatching compositionstart because start of composition
|
|
|
|
// is fixed when composition string becomes non-empty in the editor.
|
|
|
|
// Therefore, we need to use query event which is relative to insertion
|
|
|
|
// point.
|
|
|
|
options.mRelativeToInsertionPoint = true;
|
|
|
|
startOffset -= mIMECompositionStart;
|
|
|
|
}
|
|
|
|
textContent.InitForQueryTextContent(startOffset, aRange.length, options);
|
2015-01-31 10:17:18 +03:00
|
|
|
textContent.RequestFontRanges();
|
2011-02-23 20:25:11 +03:00
|
|
|
DispatchEvent(textContent);
|
2011-02-19 07:55:49 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::GetAttributedSubstringFromRange, "
|
2016-08-27 10:09:29 +03:00
|
|
|
"textContent={ mSucceeded=%s, mReply={ mString=\"%s\", mOffset=%u } }",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, TrueOrFalse(textContent.mSucceeded),
|
2013-07-11 11:46:35 +04:00
|
|
|
NS_ConvertUTF16toUTF8(textContent.mReply.mString).get(),
|
|
|
|
textContent.mReply.mOffset));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
if (!textContent.mSucceeded) {
|
2011-02-19 07:55:49 +03:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2016-04-04 11:14:36 +03:00
|
|
|
// We don't set vertical information at this point. If required,
|
|
|
|
// OS will calls drawsVerticallyForCharacterAtIndex.
|
2015-01-31 10:17:18 +03:00
|
|
|
NSMutableAttributedString* result =
|
2016-04-04 11:14:36 +03:00
|
|
|
nsCocoaUtils::GetNSMutableAttributedString(textContent.mReply.mString,
|
|
|
|
textContent.mReply.mFontRanges,
|
|
|
|
false,
|
|
|
|
mWidget->BackingScaleFactor());
|
2013-07-11 11:46:35 +04:00
|
|
|
if (aActualRange) {
|
|
|
|
aActualRange->location = textContent.mReply.mOffset;
|
|
|
|
aActualRange->length = textContent.mReply.mString.Length();
|
|
|
|
}
|
2011-02-19 07:55:49 +03:00
|
|
|
return result;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-07-21 04:33:16 +04:00
|
|
|
IMEInputHandler::HasMarkedText()
|
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::HasMarkedText, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"mMarkedRange={ location=%lu, length=%lu }",
|
|
|
|
this, static_cast<unsigned long>(mMarkedRange.location),
|
|
|
|
static_cast<unsigned long>(mMarkedRange.length)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
return (mMarkedRange.location != NSNotFound) && (mMarkedRange.length != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRange
|
|
|
|
IMEInputHandler::MarkedRange()
|
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::MarkedRange, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"mMarkedRange={ location=%lu, length=%lu }",
|
|
|
|
this, static_cast<unsigned long>(mMarkedRange.location),
|
|
|
|
static_cast<unsigned long>(mMarkedRange.length)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
if (!HasMarkedText()) {
|
|
|
|
return NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
|
|
|
return mMarkedRange;
|
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
NSRange
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::SelectedRange()
|
2011-02-19 07:55:49 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-11 11:46:35 +04:00
|
|
|
("%p IMEInputHandler::SelectedRange, Destroyed()=%s, mSelectedRange={ "
|
2016-12-16 06:16:31 +03:00
|
|
|
"location=%lu, length=%lu }",
|
|
|
|
this, TrueOrFalse(Destroyed()), static_cast<unsigned long>(mSelectedRange.location),
|
|
|
|
static_cast<unsigned long>(mSelectedRange.length)));
|
2011-05-08 14:19:23 +04:00
|
|
|
|
|
|
|
if (Destroyed()) {
|
2013-07-11 11:46:35 +04:00
|
|
|
return mSelectedRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelectedRange.location != NSNotFound) {
|
|
|
|
MOZ_ASSERT(mIMEHasFocus);
|
|
|
|
return mSelectedRange;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent selection(true, eQuerySelectedText, mWidget);
|
2011-02-23 20:25:11 +03:00
|
|
|
DispatchEvent(selection);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::SelectedRange, selection={ mSucceeded=%s, "
|
2016-08-27 10:09:29 +03:00
|
|
|
"mReply={ mOffset=%u, mString.Length()=%u } }",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, TrueOrFalse(selection.mSucceeded), selection.mReply.mOffset,
|
|
|
|
selection.mReply.mString.Length()));
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
if (!selection.mSucceeded) {
|
2013-07-11 11:46:35 +04:00
|
|
|
return mSelectedRange;
|
|
|
|
}
|
|
|
|
|
2015-02-10 18:28:05 +03:00
|
|
|
mWritingMode = selection.GetWritingMode();
|
|
|
|
mRangeForWritingMode = NSMakeRange(selection.mReply.mOffset,
|
|
|
|
selection.mReply.mString.Length());
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
if (mIMEHasFocus) {
|
2015-02-10 18:28:05 +03:00
|
|
|
mSelectedRange = mRangeForWritingMode;
|
2011-02-19 07:55:49 +03:00
|
|
|
}
|
|
|
|
|
2015-02-10 18:28:05 +03:00
|
|
|
return mRangeForWritingMode;
|
2011-02-19 07:55:49 +03:00
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(mSelectedRange);
|
2011-02-19 07:55:49 +03:00
|
|
|
}
|
|
|
|
|
2015-02-10 18:28:05 +03:00
|
|
|
bool
|
|
|
|
IMEInputHandler::DrawsVerticallyForCharacterAtIndex(uint32_t aCharIndex)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mRangeForWritingMode.location == NSNotFound) {
|
|
|
|
// Update cached writing-mode value for the current selection.
|
|
|
|
SelectedRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCharIndex < mRangeForWritingMode.location ||
|
|
|
|
aCharIndex > mRangeForWritingMode.location + mRangeForWritingMode.length) {
|
|
|
|
// It's not clear to me whether this ever happens in practice, but if an
|
|
|
|
// IME ever wants to query writing mode at an offset outside the current
|
|
|
|
// selection, the writing-mode value may not be correct for the index.
|
|
|
|
// In that case, use FirstRectForCharacterRange to get a fresh value.
|
|
|
|
// This does more work than strictly necessary (we don't need the rect here),
|
|
|
|
// but should be a rare case.
|
|
|
|
NS_WARNING("DrawsVerticallyForCharacterAtIndex not using cached writing mode");
|
|
|
|
NSRange range = NSMakeRange(aCharIndex, 1);
|
|
|
|
NSRange actualRange;
|
|
|
|
FirstRectForCharacterRange(range, &actualRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mWritingMode.IsVertical();
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
NSRect
|
2013-07-11 11:46:35 +04:00
|
|
|
IMEInputHandler::FirstRectForCharacterRange(NSRange& aRange,
|
|
|
|
NSRange* aActualRange)
|
2011-02-19 07:55:49 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-11 11:46:35 +04:00
|
|
|
("%p IMEInputHandler::FirstRectForCharacterRange, Destroyed()=%s, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"aRange={ location=%lu, length=%lu }, aActualRange=%p }",
|
|
|
|
this, TrueOrFalse(Destroyed()), static_cast<unsigned long>(aRange.location),
|
|
|
|
static_cast<unsigned long>(aRange.length), aActualRange));
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
// XXX this returns first character rect or caret rect, it is limitation of
|
|
|
|
// now. We need more work for returns first line rect. But current
|
|
|
|
// implementation is enough for IMEs.
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
NSRect rect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
|
|
|
|
NSRange actualRange = NSMakeRange(NSNotFound, 0);
|
|
|
|
if (aActualRange) {
|
|
|
|
*aActualRange = actualRange;
|
|
|
|
}
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed() || aRange.location == NSNotFound) {
|
2011-02-19 07:55:49 +03:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMEInputHandler> kungFuDeathGrip(this);
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntRect r;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useCaretRect = (aRange.length == 0);
|
2011-02-19 07:55:49 +03:00
|
|
|
if (!useCaretRect) {
|
2015-09-11 15:21:26 +03:00
|
|
|
WidgetQueryContentEvent charRect(true, eQueryTextRect, mWidget);
|
2016-08-19 15:51:54 +03:00
|
|
|
WidgetQueryContentEvent::Options options;
|
|
|
|
int64_t startOffset = aRange.location;
|
|
|
|
if (IsIMEComposing()) {
|
|
|
|
// The composition may be at different offset from the selection start
|
|
|
|
// offset at dispatching compositionstart because start of composition
|
|
|
|
// is fixed when composition string becomes non-empty in the editor.
|
|
|
|
// Therefore, we need to use query event which is relative to insertion
|
|
|
|
// point.
|
|
|
|
options.mRelativeToInsertionPoint = true;
|
|
|
|
startOffset -= mIMECompositionStart;
|
|
|
|
}
|
|
|
|
charRect.InitForQueryTextRect(startOffset, 1, options);
|
2011-02-23 20:25:11 +03:00
|
|
|
DispatchEvent(charRect);
|
2011-02-19 07:55:49 +03:00
|
|
|
if (charRect.mSucceeded) {
|
|
|
|
r = charRect.mReply.mRect;
|
2013-07-11 11:46:35 +04:00
|
|
|
actualRange.location = charRect.mReply.mOffset;
|
|
|
|
actualRange.length = charRect.mReply.mString.Length();
|
2015-02-10 18:28:05 +03:00
|
|
|
mWritingMode = charRect.GetWritingMode();
|
|
|
|
mRangeForWritingMode = actualRange;
|
2011-02-19 07:55:49 +03:00
|
|
|
} else {
|
2011-10-01 04:20:33 +04:00
|
|
|
useCaretRect = true;
|
2011-02-19 07:55:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useCaretRect) {
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent caretRect(true, eQueryCaretRect, mWidget);
|
2016-08-19 15:51:54 +03:00
|
|
|
WidgetQueryContentEvent::Options options;
|
|
|
|
int64_t startOffset = aRange.location;
|
|
|
|
if (IsIMEComposing()) {
|
|
|
|
// The composition may be at different offset from the selection start
|
|
|
|
// offset at dispatching compositionstart because start of composition
|
|
|
|
// is fixed when composition string becomes non-empty in the editor.
|
|
|
|
// Therefore, we need to use query event which is relative to insertion
|
|
|
|
// point.
|
|
|
|
options.mRelativeToInsertionPoint = true;
|
|
|
|
startOffset -= mIMECompositionStart;
|
|
|
|
}
|
|
|
|
caretRect.InitForQueryCaretRect(startOffset, options);
|
2011-02-23 20:25:11 +03:00
|
|
|
DispatchEvent(caretRect);
|
2011-02-19 07:55:49 +03:00
|
|
|
if (!caretRect.mSucceeded) {
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
r = caretRect.mReply.mRect;
|
|
|
|
r.width = 0;
|
2013-07-11 11:46:35 +04:00
|
|
|
actualRange.location = caretRect.mReply.mOffset;
|
|
|
|
actualRange.length = 0;
|
2011-02-19 07:55:49 +03:00
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
nsIWidget* rootWidget = mWidget->GetTopLevelWidget();
|
2011-02-19 07:55:49 +03:00
|
|
|
NSWindow* rootWindow =
|
|
|
|
static_cast<NSWindow*>(rootWidget->GetNativeData(NS_NATIVE_WINDOW));
|
|
|
|
NSView* rootView =
|
|
|
|
static_cast<NSView*>(rootWidget->GetNativeData(NS_NATIVE_WIDGET));
|
|
|
|
if (!rootWindow || !rootView) {
|
|
|
|
return rect;
|
|
|
|
}
|
2015-11-19 06:10:38 +03:00
|
|
|
rect = nsCocoaUtils::DevPixelsToCocoaPoints(r, mWidget->BackingScaleFactor());
|
2011-02-19 07:55:49 +03:00
|
|
|
rect = [rootView convertRect:rect toView:nil];
|
2016-05-05 14:27:13 +03:00
|
|
|
rect.origin = nsCocoaUtils::ConvertPointToScreen(rootWindow, rect.origin);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
if (aActualRange) {
|
|
|
|
*aActualRange = actualRange;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::FirstRectForCharacterRange, "
|
2013-07-11 11:46:35 +04:00
|
|
|
"useCaretRect=%s rect={ x=%f, y=%f, width=%f, height=%f }, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"actualRange={ location=%lu, length=%lu }",
|
2011-07-21 04:33:16 +04:00
|
|
|
this, TrueOrFalse(useCaretRect), rect.origin.x, rect.origin.y,
|
2016-12-16 06:16:31 +03:00
|
|
|
rect.size.width, rect.size.height, static_cast<unsigned long>(actualRange.location),
|
|
|
|
static_cast<unsigned long>(actualRange.length)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
return rect;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSMakeRect(0.0, 0.0, 0.0, 0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
NSUInteger
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::CharacterIndexForPoint(NSPoint& aPoint)
|
2011-02-19 07:55:49 +03:00
|
|
|
{
|
2014-07-29 18:32:40 +04:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::CharacterIndexForPoint, aPoint={ x=%f, y=%f }",
|
|
|
|
this, aPoint.x, aPoint.y));
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2014-07-29 18:32:40 +04:00
|
|
|
NSWindow* mainWindow = [NSApp mainWindow];
|
|
|
|
if (!mWidget || !mainWindow) {
|
|
|
|
return NSNotFound;
|
|
|
|
}
|
|
|
|
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent charAt(true, eQueryCharacterAtPoint, mWidget);
|
2016-05-05 14:27:13 +03:00
|
|
|
NSPoint ptInWindow = nsCocoaUtils::ConvertPointFromScreen(mainWindow, aPoint);
|
2014-07-29 18:32:40 +04:00
|
|
|
NSPoint ptInView = [mView convertPoint:ptInWindow fromView:nil];
|
2016-04-18 17:09:02 +03:00
|
|
|
charAt.mRefPoint.x =
|
2014-07-29 18:32:40 +04:00
|
|
|
static_cast<int32_t>(ptInView.x) * mWidget->BackingScaleFactor();
|
2016-04-18 17:09:02 +03:00
|
|
|
charAt.mRefPoint.y =
|
2014-07-29 18:32:40 +04:00
|
|
|
static_cast<int32_t>(ptInView.y) * mWidget->BackingScaleFactor();
|
|
|
|
mWidget->DispatchWindowEvent(charAt);
|
|
|
|
if (!charAt.mSucceeded ||
|
|
|
|
charAt.mReply.mOffset == WidgetQueryContentEvent::NOT_FOUND ||
|
|
|
|
charAt.mReply.mOffset >= static_cast<uint32_t>(NSNotFound)) {
|
|
|
|
return NSNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
return charAt.mReply.mOffset;
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2014-07-29 18:32:40 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSNotFound);
|
2011-02-19 07:55:49 +03:00
|
|
|
}
|
|
|
|
|
2016-11-07 10:19:41 +03:00
|
|
|
extern "C" {
|
|
|
|
extern NSString *NSTextInputReplacementRangeAttributeName;
|
|
|
|
}
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
NSArray*
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::GetValidAttributesForMarkedText()
|
2011-02-19 07:55:49 +03:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::GetValidAttributesForMarkedText", this));
|
2011-02-19 07:55:49 +03:00
|
|
|
|
2016-11-07 10:19:41 +03:00
|
|
|
// Return same attributes as Chromium (see render_widget_host_view_mac.mm)
|
|
|
|
// because most IMEs must be tested with Safari (OS default) and Chrome
|
|
|
|
// (having most market share). Therefore, we need to follow their behavior.
|
|
|
|
// XXX It might be better to reuse an array instance for this result because
|
|
|
|
// this may be called a lot. Note that Chromium does so.
|
|
|
|
return [NSArray arrayWithObjects:NSUnderlineStyleAttributeName,
|
|
|
|
NSUnderlineColorAttributeName,
|
|
|
|
NSMarkedClauseSegmentAttributeName,
|
|
|
|
NSTextInputReplacementRangeAttributeName,
|
|
|
|
nil];
|
2011-02-19 07:55:49 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
2011-05-08 14:19:15 +04:00
|
|
|
* IMEInputHandler implementation #2
|
2009-10-01 06:52:50 +04:00
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
IMEInputHandler::IMEInputHandler(nsChildView* aWidget,
|
2015-09-19 05:01:57 +03:00
|
|
|
NSView<mozView> *aNativeView)
|
|
|
|
: TextInputHandlerBase(aWidget, aNativeView)
|
|
|
|
, mPendingMethods(0)
|
|
|
|
, mIMECompositionString(nullptr)
|
|
|
|
, mIMECompositionStart(UINT32_MAX)
|
|
|
|
, mIsIMEComposing(false)
|
|
|
|
, mIsIMEEnabled(true)
|
|
|
|
, mIsASCIICapableOnly(false)
|
|
|
|
, mIgnoreIMECommit(false)
|
|
|
|
, mIsInFocusProcessing(false)
|
|
|
|
, mIMEHasFocus(false)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
InitStaticMembers();
|
2011-02-19 07:55:34 +03:00
|
|
|
|
|
|
|
mMarkedRange.location = NSNotFound;
|
|
|
|
mMarkedRange.length = 0;
|
2013-07-11 11:46:35 +04:00
|
|
|
mSelectedRange.location = NSNotFound;
|
|
|
|
mSelectedRange.length = 0;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::~IMEInputHandler()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
2012-07-30 18:20:58 +04:00
|
|
|
mTimer = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
if (sFocusedIMEHandler == this) {
|
2012-07-30 18:20:58 +04:00
|
|
|
sFocusedIMEHandler = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
2015-09-19 05:01:57 +03:00
|
|
|
if (mIMECompositionString) {
|
|
|
|
[mIMECompositionString release];
|
|
|
|
mIMECompositionString = nullptr;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
IMEInputHandler::OnFocusChangeInGecko(bool aFocus)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::OnFocusChangeInGecko, aFocus=%s, Destroyed()=%s, "
|
|
|
|
"sFocusedIMEHandler=%p",
|
|
|
|
this, TrueOrFalse(aFocus), TrueOrFalse(Destroyed()), sFocusedIMEHandler));
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
mSelectedRange.location = NSNotFound; // Marking dirty
|
|
|
|
mIMEHasFocus = aFocus;
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
// This is called when the native focus is changed and when the native focus
|
|
|
|
// isn't changed but the focus is changed in Gecko.
|
|
|
|
if (!aFocus) {
|
|
|
|
if (sFocusedIMEHandler == this)
|
2012-07-30 18:20:58 +04:00
|
|
|
sFocusedIMEHandler = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sFocusedIMEHandler = this;
|
2011-10-01 04:20:33 +04:00
|
|
|
mIsInFocusProcessing = true;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2013-07-11 11:46:36 +04:00
|
|
|
// We need to notify IME of focus change in Gecko as native focus change
|
|
|
|
// because the window level of the focused element in Gecko may be changed.
|
|
|
|
mPendingMethods |= kNotifyIMEOfFocusChangeInGecko;
|
2009-10-01 06:52:50 +04:00
|
|
|
ResetTimer();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:23 +04:00
|
|
|
IMEInputHandler::OnDestroyWidget(nsChildView* aDestroyingWidget)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::OnDestroyWidget, aDestroyingWidget=%p, "
|
|
|
|
"sFocusedIMEHandler=%p, IsIMEComposing()=%s",
|
|
|
|
this, aDestroyingWidget, sFocusedIMEHandler,
|
|
|
|
TrueOrFalse(IsIMEComposing())));
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
// If we're not focused, the focused IMEInputHandler may have been
|
|
|
|
// created by another widget/nsChildView.
|
2009-10-01 06:52:50 +04:00
|
|
|
if (sFocusedIMEHandler && sFocusedIMEHandler != this) {
|
2011-05-08 14:19:23 +04:00
|
|
|
sFocusedIMEHandler->OnDestroyWidget(aDestroyingWidget);
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2015-03-11 04:25:38 +03:00
|
|
|
if (!TextInputHandlerBase::OnDestroyWidget(aDestroyingWidget)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
if (IsIMEComposing()) {
|
|
|
|
// If our view is in the composition, we should clean up it.
|
|
|
|
CancelIMEComposition();
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
mSelectedRange.location = NSNotFound; // Marking dirty
|
|
|
|
mIMEHasFocus = false;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::SendCommittedText(NSString *aString)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::SendCommittedText, mView=%p, mWidget=%p, "
|
2013-07-13 06:53:23 +04:00
|
|
|
"inputContext=%p, mIsIMEComposing=%s",
|
|
|
|
this, mView, mWidget, mView ? [mView inputContext] : nullptr,
|
2016-12-16 06:16:31 +03:00
|
|
|
TrueOrFalse(mIsIMEComposing)));
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
NS_ENSURE_TRUE(mWidget, );
|
|
|
|
// XXX We should send the string without mView.
|
|
|
|
if (!mView) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
NSAttributedString* attrStr =
|
|
|
|
[[NSAttributedString alloc] initWithString:aString];
|
2017-02-07 13:03:14 +03:00
|
|
|
if ([mView conformsToProtocol:@protocol(NSTextInputClient)]) {
|
|
|
|
NSObject<NSTextInputClient>* textInputClient =
|
|
|
|
static_cast<NSObject<NSTextInputClient>*>(mView);
|
|
|
|
[textInputClient insertText:attrStr
|
|
|
|
replacementRange:NSMakeRange(NSNotFound, 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last resort. If we cannot retrieve NSTextInputProtocol from mView
|
|
|
|
// or blocking to call our InsertText(), we should call InsertText()
|
|
|
|
// directly to commit composition forcibly.
|
|
|
|
if (mIsIMEComposing) {
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::SendCommittedText, trying to insert text directly "
|
|
|
|
"due to IME not calling our InsertText()", this));
|
|
|
|
static_cast<TextInputHandler*>(this)->InsertText(attrStr);
|
|
|
|
MOZ_ASSERT(!mIsIMEComposing);
|
|
|
|
}
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
[attrStr release];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::KillIMEComposition()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::KillIMEComposition, mView=%p, mWidget=%p, "
|
2013-07-13 06:53:23 +04:00
|
|
|
"inputContext=%p, mIsIMEComposing=%s, "
|
2011-07-21 04:33:16 +04:00
|
|
|
"Destroyed()=%s, IsFocused()=%s",
|
2013-07-13 06:53:23 +04:00
|
|
|
this, mView, mWidget, mView ? [mView inputContext] : nullptr,
|
2011-07-21 04:33:16 +04:00
|
|
|
TrueOrFalse(mIsIMEComposing), TrueOrFalse(Destroyed()),
|
|
|
|
TrueOrFalse(IsFocused())));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (Destroyed()) {
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
2011-05-08 14:19:23 +04:00
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
if (IsFocused()) {
|
2013-07-13 06:53:24 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(mView);
|
|
|
|
NSTextInputContext* inputContext = [mView inputContext];
|
|
|
|
NS_ENSURE_TRUE_VOID(inputContext);
|
|
|
|
[inputContext discardMarkedText];
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::KillIMEComposition, Pending...", this));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
// Commit the composition internally.
|
|
|
|
SendCommittedText(mIMECompositionString);
|
|
|
|
NS_ASSERTION(!mIsIMEComposing, "We're still in a composition");
|
|
|
|
// The pending method will be fired by the next focus event.
|
|
|
|
mPendingMethods |= kDiscardIMEComposition;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::CommitIMEComposition()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!IsIMEComposing())
|
|
|
|
return;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::CommitIMEComposition, mIMECompositionString=%s",
|
|
|
|
this, GetCharacters(mIMECompositionString)));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
KillIMEComposition();
|
|
|
|
|
|
|
|
if (!IsIMEComposing())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the composition is still there, KillIMEComposition only kills the
|
|
|
|
// composition in TSM. We also need to finish the our composition too.
|
|
|
|
SendCommittedText(mIMECompositionString);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::CancelIMEComposition()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!IsIMEComposing())
|
|
|
|
return;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::CancelIMEComposition, mIMECompositionString=%s",
|
|
|
|
this, GetCharacters(mIMECompositionString)));
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
// For canceling the current composing, we need to ignore the param of
|
|
|
|
// insertText. But this code is ugly...
|
2011-10-01 04:20:33 +04:00
|
|
|
mIgnoreIMECommit = true;
|
2009-10-01 06:52:50 +04:00
|
|
|
KillIMEComposition();
|
2011-10-01 04:20:33 +04:00
|
|
|
mIgnoreIMECommit = false;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
if (!IsIMEComposing())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If the composition is still there, KillIMEComposition only kills the
|
|
|
|
// composition in TSM. We also need to kill the our composition too.
|
|
|
|
SendCommittedText(@"");
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::IsFocused()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(!Destroyed(), false);
|
2009-10-01 06:52:50 +04:00
|
|
|
NSWindow* window = [mView window];
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_ENSURE_TRUE(window, false);
|
2010-08-16 12:20:27 +04:00
|
|
|
return [window firstResponder] == mView &&
|
2013-08-07 06:49:21 +04:00
|
|
|
[window isKeyWindow] &&
|
2009-10-01 06:52:50 +04:00
|
|
|
[[NSApplication sharedApplication] isActive];
|
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::IsIMEOpened()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper tis;
|
2009-10-01 06:52:50 +04:00
|
|
|
tis.InitByCurrentInputSource();
|
|
|
|
return tis.IsOpenedIMEMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
IMEInputHandler::SetASCIICapableOnly(bool aASCIICapableOnly)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
if (aASCIICapableOnly == mIsASCIICapableOnly)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CommitIMEComposition();
|
|
|
|
mIsASCIICapableOnly = aASCIICapableOnly;
|
|
|
|
SyncASCIICapableOnly();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
IMEInputHandler::EnableIME(bool aEnableIME)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
if (aEnableIME == mIsIMEEnabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CommitIMEComposition();
|
|
|
|
mIsIMEEnabled = aEnableIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
IMEInputHandler::SetIMEOpenState(bool aOpenIME)
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
if (!IsFocused() || IsIMEOpened() == aOpenIME)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!aOpenIME) {
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper tis;
|
2009-10-01 06:52:50 +04:00
|
|
|
tis.InitByCurrentASCIICapableInputSource();
|
|
|
|
tis.Select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we know the latest IME opened mode, we should select it.
|
|
|
|
if (sLatestIMEOpenedModeInputSourceID) {
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper tis;
|
2009-10-01 06:52:50 +04:00
|
|
|
tis.InitByInputSourceID(sLatestIMEOpenedModeInputSourceID);
|
|
|
|
tis.Select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If the current input source is a mode of IME, we should turn on it,
|
|
|
|
// but we haven't found such way...
|
|
|
|
|
|
|
|
// Finally, we should refer the system locale but this is a little expensive,
|
|
|
|
// we shouldn't retry this (if it was succeeded, we already set
|
|
|
|
// sLatestIMEOpenedModeInputSourceID at that time).
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sIsPrefferredIMESearched = false;
|
2009-10-01 06:52:50 +04:00
|
|
|
if (sIsPrefferredIMESearched)
|
|
|
|
return;
|
2011-10-01 04:20:33 +04:00
|
|
|
sIsPrefferredIMESearched = true;
|
2009-10-01 06:52:50 +04:00
|
|
|
OpenSystemPreferredLanguageIME();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-08 14:19:15 +04:00
|
|
|
IMEInputHandler::OpenSystemPreferredLanguageIME()
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::OpenSystemPreferredLanguageIME", this));
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
CFArrayRef langList = ::CFLocaleCopyPreferredLanguages();
|
|
|
|
if (!langList) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::OpenSystemPreferredLanguageIME, langList is NULL",
|
|
|
|
this));
|
2009-10-01 06:52:50 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
CFIndex count = ::CFArrayGetCount(langList);
|
|
|
|
for (CFIndex i = 0; i < count; i++) {
|
|
|
|
CFLocaleRef locale =
|
|
|
|
::CFLocaleCreate(kCFAllocatorDefault,
|
|
|
|
static_cast<CFStringRef>(::CFArrayGetValueAtIndex(langList, i)));
|
|
|
|
if (!locale) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed = false;
|
2009-10-01 06:52:50 +04:00
|
|
|
CFStringRef lang = static_cast<CFStringRef>(
|
|
|
|
::CFLocaleGetValue(locale, kCFLocaleLanguageCode));
|
|
|
|
NS_ASSERTION(lang, "lang is null");
|
|
|
|
if (lang) {
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper tis;
|
2009-10-01 06:52:50 +04:00
|
|
|
tis.InitByLanguage(lang);
|
|
|
|
if (tis.IsOpenedIMEMode()) {
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Info)) {
|
2011-07-21 04:33:16 +04:00
|
|
|
CFStringRef foundTIS;
|
|
|
|
tis.GetInputSourceID(foundTIS);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p IMEInputHandler::OpenSystemPreferredLanguageIME, "
|
|
|
|
"foundTIS=%s, lang=%s",
|
|
|
|
this, GetCharacters(foundTIS), GetCharacters(lang)));
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
tis.Select();
|
2011-10-01 04:20:33 +04:00
|
|
|
changed = true;
|
2009-10-01 06:52:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
::CFRelease(locale);
|
|
|
|
if (changed) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
::CFRelease(langList);
|
|
|
|
}
|
2011-05-08 14:19:15 +04:00
|
|
|
|
2015-07-21 15:47:54 +03:00
|
|
|
void
|
|
|
|
IMEInputHandler::OnSelectionChange(const IMENotification& aIMENotification)
|
|
|
|
{
|
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
|
|
|
("%p IMEInputHandler::OnSelectionChange", this));
|
|
|
|
|
|
|
|
if (aIMENotification.mSelectionChangeData.mOffset == UINT32_MAX) {
|
|
|
|
mSelectedRange.location = NSNotFound;
|
|
|
|
mSelectedRange.length = 0;
|
|
|
|
mRangeForWritingMode.location = NSNotFound;
|
|
|
|
mRangeForWritingMode.length = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWritingMode = aIMENotification.mSelectionChangeData.GetWritingMode();
|
|
|
|
mRangeForWritingMode =
|
|
|
|
NSMakeRange(aIMENotification.mSelectionChangeData.mOffset,
|
2015-07-22 07:28:23 +03:00
|
|
|
aIMENotification.mSelectionChangeData.Length());
|
2015-07-21 15:47:54 +03:00
|
|
|
if (mIMEHasFocus) {
|
|
|
|
mSelectedRange = mRangeForWritingMode;
|
|
|
|
}
|
|
|
|
}
|
2011-05-08 14:19:15 +04:00
|
|
|
|
2017-06-29 10:03:57 +03:00
|
|
|
void
|
|
|
|
IMEInputHandler::OnLayoutChange()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
if (!IsFocused()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSTextInputContext* inputContext = [mView inputContext];
|
|
|
|
[inputContext invalidateCharacterCoordinates];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
2016-04-27 15:14:43 +03:00
|
|
|
bool
|
|
|
|
IMEInputHandler::OnHandleEvent(NSEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!IsFocused()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NSTextInputContext* inputContext = [mView inputContext];
|
|
|
|
return [inputContext handleEvent:aEvent];
|
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* TextInputHandlerBase implementation
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-05-24 20:27:52 +04:00
|
|
|
int32_t TextInputHandlerBase::sSecureEventInputCount = 0;
|
|
|
|
|
2016-03-16 07:47:49 +03:00
|
|
|
NS_IMPL_ISUPPORTS(TextInputHandlerBase,
|
|
|
|
TextEventDispatcherListener,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
TextInputHandlerBase::TextInputHandlerBase(nsChildView* aWidget,
|
2016-03-16 07:47:50 +03:00
|
|
|
NSView<mozView> *aNativeView)
|
|
|
|
: mWidget(aWidget)
|
|
|
|
, mDispatcher(aWidget->GetTextEventDispatcher())
|
2011-05-08 14:19:15 +04:00
|
|
|
{
|
|
|
|
gHandlerInstanceCount++;
|
2011-05-08 14:19:23 +04:00
|
|
|
mView = [aNativeView retain];
|
2011-05-08 14:19:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TextInputHandlerBase::~TextInputHandlerBase()
|
|
|
|
{
|
2011-05-08 14:19:23 +04:00
|
|
|
[mView release];
|
2011-05-08 14:19:15 +04:00
|
|
|
if (--gHandlerInstanceCount == 0) {
|
2016-06-16 11:00:38 +03:00
|
|
|
TISInputSourceWrapper::Shutdown();
|
2011-05-08 14:19:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-08 14:19:23 +04:00
|
|
|
TextInputHandlerBase::OnDestroyWidget(nsChildView* aDestroyingWidget)
|
2011-05-08 14:19:15 +04:00
|
|
|
{
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2011-07-21 04:33:16 +04:00
|
|
|
("%p TextInputHandlerBase::OnDestroyWidget, "
|
|
|
|
"aDestroyingWidget=%p, mWidget=%p",
|
|
|
|
this, aDestroyingWidget, mWidget));
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
if (aDestroyingWidget != mWidget) {
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2011-05-08 14:19:15 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mWidget = nullptr;
|
2016-03-16 07:47:50 +03:00
|
|
|
mDispatcher = nullptr;
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2011-05-08 14:19:15 +04:00
|
|
|
}
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-10-02 07:46:03 +04:00
|
|
|
TextInputHandlerBase::DispatchEvent(WidgetGUIEvent& aEvent)
|
2011-02-23 20:25:11 +03:00
|
|
|
{
|
|
|
|
return mWidget->DispatchWindowEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextInputHandlerBase::InitKeyEvent(NSEvent *aNativeKeyEvent,
|
2013-10-01 11:22:58 +04:00
|
|
|
WidgetKeyboardEvent& aKeyEvent,
|
2012-07-21 03:24:48 +04:00
|
|
|
const nsAString* aInsertString)
|
2011-02-23 20:25:11 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNativeKeyEvent, "aNativeKeyEvent must not be NULL");
|
|
|
|
|
|
|
|
if (mKeyboardOverride.mOverrideEnabled) {
|
2012-10-16 05:43:50 +04:00
|
|
|
TISInputSourceWrapper tis;
|
2011-10-01 04:20:33 +04:00
|
|
|
tis.InitByLayoutID(mKeyboardOverride.mKeyboardLayout, true);
|
2012-10-16 05:43:50 +04:00
|
|
|
tis.InitKeyEvent(aNativeKeyEvent, aKeyEvent, aInsertString);
|
|
|
|
return;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2012-10-16 05:43:50 +04:00
|
|
|
TISInputSourceWrapper::CurrentInputSource().
|
|
|
|
InitKeyEvent(aNativeKeyEvent, aKeyEvent, aInsertString);
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TextInputHandlerBase::SynthesizeNativeKeyEvent(
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aNativeKeyboardLayout,
|
|
|
|
int32_t aNativeKeyCode,
|
|
|
|
uint32_t aModifierFlags,
|
2011-02-23 20:25:11 +03:00
|
|
|
const nsAString& aCharacters,
|
|
|
|
const nsAString& aUnmodifiedCharacters)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint32_t sModifierFlagMap[][2] = {
|
2011-02-23 20:25:11 +03:00
|
|
|
{ nsIWidget::CAPS_LOCK, NSAlphaShiftKeyMask },
|
2012-10-19 05:17:07 +04:00
|
|
|
{ nsIWidget::SHIFT_L, NSShiftKeyMask | 0x0002 },
|
|
|
|
{ nsIWidget::SHIFT_R, NSShiftKeyMask | 0x0004 },
|
|
|
|
{ nsIWidget::CTRL_L, NSControlKeyMask | 0x0001 },
|
|
|
|
{ nsIWidget::CTRL_R, NSControlKeyMask | 0x2000 },
|
|
|
|
{ nsIWidget::ALT_L, NSAlternateKeyMask | 0x0020 },
|
|
|
|
{ nsIWidget::ALT_R, NSAlternateKeyMask | 0x0040 },
|
|
|
|
{ nsIWidget::COMMAND_L, NSCommandKeyMask | 0x0008 },
|
|
|
|
{ nsIWidget::COMMAND_R, NSCommandKeyMask | 0x0010 },
|
2011-02-23 20:25:11 +03:00
|
|
|
{ nsIWidget::NUMERIC_KEY_PAD, NSNumericPadKeyMask },
|
|
|
|
{ nsIWidget::HELP, NSHelpKeyMask },
|
|
|
|
{ nsIWidget::FUNCTION, NSFunctionKeyMask }
|
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t modifierFlags = 0;
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(sModifierFlagMap); ++i) {
|
2011-02-23 20:25:11 +03:00
|
|
|
if (aModifierFlags & sModifierFlagMap[i][0]) {
|
|
|
|
modifierFlags |= sModifierFlagMap[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSInteger windowNumber = [[mView window] windowNumber];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool sendFlagsChangedEvent = IsModifierKey(aNativeKeyCode);
|
2011-02-23 20:25:11 +03:00
|
|
|
NSEventType eventType = sendFlagsChangedEvent ? NSFlagsChanged : NSKeyDown;
|
|
|
|
NSEvent* downEvent =
|
|
|
|
[NSEvent keyEventWithType:eventType
|
|
|
|
location:NSMakePoint(0,0)
|
|
|
|
modifierFlags:modifierFlags
|
|
|
|
timestamp:0
|
|
|
|
windowNumber:windowNumber
|
|
|
|
context:[NSGraphicsContext currentContext]
|
2011-07-21 04:33:16 +04:00
|
|
|
characters:nsCocoaUtils::ToNSString(aCharacters)
|
|
|
|
charactersIgnoringModifiers:nsCocoaUtils::ToNSString(aUnmodifiedCharacters)
|
2011-02-23 20:25:11 +03:00
|
|
|
isARepeat:NO
|
|
|
|
keyCode:aNativeKeyCode];
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
NSEvent* upEvent = sendFlagsChangedEvent ?
|
|
|
|
nil : nsCocoaUtils::MakeNewCocoaEventWithType(NSKeyUp, downEvent);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
if (downEvent && (sendFlagsChangedEvent || upEvent)) {
|
|
|
|
KeyboardLayoutOverride currentLayout = mKeyboardOverride;
|
|
|
|
mKeyboardOverride.mKeyboardLayout = aNativeKeyboardLayout;
|
2011-10-01 04:20:33 +04:00
|
|
|
mKeyboardOverride.mOverrideEnabled = true;
|
2011-02-23 20:25:11 +03:00
|
|
|
[NSApp sendEvent:downEvent];
|
|
|
|
if (upEvent) {
|
|
|
|
[NSApp sendEvent:upEvent];
|
|
|
|
}
|
|
|
|
// processKeyDownEvent and keyUp block exceptions so we're sure to
|
|
|
|
// reach here to restore mKeyboardOverride
|
|
|
|
mKeyboardOverride = currentLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
NSInteger
|
|
|
|
TextInputHandlerBase::GetWindowLevel()
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-11 11:46:35 +04:00
|
|
|
("%p TextInputHandlerBase::GetWindowLevel, Destryoed()=%s",
|
|
|
|
this, TrueOrFalse(Destroyed())));
|
|
|
|
|
|
|
|
if (Destroyed()) {
|
|
|
|
return NSNormalWindowLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When an <input> element on a XUL <panel> is focused, the actual focused view
|
|
|
|
// is the panel's parent view (mView). But the editor is displayed on the
|
|
|
|
// popped-up widget's view (editorView). We want the latter's window level.
|
|
|
|
NSView<mozView>* editorView = mWidget->GetEditorView();
|
|
|
|
NS_ENSURE_TRUE(editorView, NSNormalWindowLevel);
|
|
|
|
NSInteger windowLevel = [[editorView window] level];
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2016-12-16 06:16:31 +03:00
|
|
|
("%p TextInputHandlerBase::GetWindowLevel, windowLevel=%s (%lX)",
|
|
|
|
this, GetWindowLevelName(windowLevel), static_cast<unsigned long>(windowLevel)));
|
2013-07-11 11:46:35 +04:00
|
|
|
|
|
|
|
return windowLevel;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NSNormalWindowLevel);
|
|
|
|
}
|
|
|
|
|
2013-07-10 18:12:40 +04:00
|
|
|
NS_IMETHODIMP
|
2013-10-01 11:22:58 +04:00
|
|
|
TextInputHandlerBase::AttachNativeKeyEvent(WidgetKeyboardEvent& aKeyEvent)
|
2013-07-10 18:12:40 +04:00
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
|
|
|
// Don't try to replace a native event if one already exists.
|
|
|
|
// OS X doesn't have an OS modifier, can't make a native event.
|
2016-03-31 11:03:00 +03:00
|
|
|
if (aKeyEvent.mNativeKeyEvent || aKeyEvent.mModifiers & MODIFIER_OS) {
|
2013-07-10 18:12:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Info,
|
2013-07-10 18:12:40 +04:00
|
|
|
("%p TextInputHandlerBase::AttachNativeKeyEvent, key=0x%X, char=0x%X, "
|
2016-05-13 10:06:18 +03:00
|
|
|
"mod=0x%X", this, aKeyEvent.mKeyCode, aKeyEvent.mCharCode,
|
2016-03-31 11:03:00 +03:00
|
|
|
aKeyEvent.mModifiers));
|
2013-07-10 18:12:40 +04:00
|
|
|
|
|
|
|
NSEventType eventType;
|
2015-08-29 02:58:27 +03:00
|
|
|
if (aKeyEvent.mMessage == eKeyUp) {
|
2013-07-10 18:12:40 +04:00
|
|
|
eventType = NSKeyUp;
|
|
|
|
} else {
|
|
|
|
eventType = NSKeyDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t sModifierFlagMap[][2] = {
|
|
|
|
{ MODIFIER_SHIFT, NSShiftKeyMask },
|
|
|
|
{ MODIFIER_CONTROL, NSControlKeyMask },
|
|
|
|
{ MODIFIER_ALT, NSAlternateKeyMask },
|
|
|
|
{ MODIFIER_ALTGRAPH, NSAlternateKeyMask },
|
|
|
|
{ MODIFIER_META, NSCommandKeyMask },
|
|
|
|
{ MODIFIER_CAPSLOCK, NSAlphaShiftKeyMask },
|
|
|
|
{ MODIFIER_NUMLOCK, NSNumericPadKeyMask }
|
|
|
|
};
|
|
|
|
|
|
|
|
NSUInteger modifierFlags = 0;
|
|
|
|
for (uint32_t i = 0; i < ArrayLength(sModifierFlagMap); ++i) {
|
2016-03-31 11:03:00 +03:00
|
|
|
if (aKeyEvent.mModifiers & sModifierFlagMap[i][0]) {
|
2013-07-10 18:12:40 +04:00
|
|
|
modifierFlags |= sModifierFlagMap[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSInteger windowNumber = [[mView window] windowNumber];
|
|
|
|
|
|
|
|
NSString* characters;
|
2016-05-13 10:06:18 +03:00
|
|
|
if (aKeyEvent.mCharCode) {
|
2013-07-10 18:12:40 +04:00
|
|
|
characters = [NSString stringWithCharacters:
|
2016-05-13 10:06:18 +03:00
|
|
|
reinterpret_cast<const unichar*>(&(aKeyEvent.mCharCode)) length:1];
|
2013-07-10 18:12:40 +04:00
|
|
|
} else {
|
|
|
|
uint32_t cocoaCharCode =
|
2016-05-12 11:13:49 +03:00
|
|
|
nsCocoaUtils::ConvertGeckoKeyCodeToMacCharCode(aKeyEvent.mKeyCode);
|
2013-07-10 18:12:40 +04:00
|
|
|
characters = [NSString stringWithCharacters:
|
|
|
|
reinterpret_cast<const unichar*>(&cocoaCharCode) length:1];
|
|
|
|
}
|
|
|
|
|
|
|
|
aKeyEvent.mNativeKeyEvent =
|
|
|
|
[NSEvent keyEventWithType:eventType
|
|
|
|
location:NSMakePoint(0,0)
|
|
|
|
modifierFlags:modifierFlags
|
|
|
|
timestamp:0
|
|
|
|
windowNumber:windowNumber
|
|
|
|
context:[NSGraphicsContext currentContext]
|
|
|
|
characters:characters
|
|
|
|
charactersIgnoringModifiers:characters
|
|
|
|
isARepeat:NO
|
|
|
|
keyCode:0]; // Native key code not currently needed
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
}
|
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
bool
|
|
|
|
TextInputHandlerBase::SetSelection(NSRange& aRange)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!Destroyed());
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextInputHandlerBase> kungFuDeathGrip(this);
|
2015-09-08 17:33:38 +03:00
|
|
|
WidgetSelectionEvent selectionEvent(true, eSetSelection, mWidget);
|
2013-07-11 11:46:35 +04:00
|
|
|
selectionEvent.mOffset = aRange.location;
|
|
|
|
selectionEvent.mLength = aRange.length;
|
|
|
|
selectionEvent.mReversed = false;
|
|
|
|
selectionEvent.mExpandToClusterBoundary = false;
|
|
|
|
DispatchEvent(selectionEvent);
|
|
|
|
NS_ENSURE_TRUE(selectionEvent.mSucceeded, false);
|
|
|
|
return !Destroyed();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2014-01-04 19:02:17 +04:00
|
|
|
TextInputHandlerBase::IsPrintableChar(char16_t aChar)
|
2011-02-23 20:25:11 +03:00
|
|
|
{
|
|
|
|
return (aChar >= 0x20 && aChar <= 0x7E) || aChar >= 0xA0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2011-02-23 20:25:11 +03:00
|
|
|
TextInputHandlerBase::IsSpecialGeckoKey(UInt32 aNativeKeyCode)
|
|
|
|
{
|
|
|
|
// this table is used to determine which keys are special and should not
|
|
|
|
// generate a charCode
|
|
|
|
switch (aNativeKeyCode) {
|
|
|
|
// modifiers - we don't get separate events for these yet
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Escape:
|
|
|
|
case kVK_Shift:
|
|
|
|
case kVK_RightShift:
|
|
|
|
case kVK_Command:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_RightCommand:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_CapsLock:
|
|
|
|
case kVK_Control:
|
|
|
|
case kVK_RightControl:
|
|
|
|
case kVK_Option:
|
|
|
|
case kVK_RightOption:
|
|
|
|
case kVK_ANSI_KeypadClear:
|
2012-10-19 05:17:07 +04:00
|
|
|
case kVK_Function:
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
// function keys
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_F1:
|
|
|
|
case kVK_F2:
|
|
|
|
case kVK_F3:
|
|
|
|
case kVK_F4:
|
|
|
|
case kVK_F5:
|
|
|
|
case kVK_F6:
|
|
|
|
case kVK_F7:
|
|
|
|
case kVK_F8:
|
|
|
|
case kVK_F9:
|
|
|
|
case kVK_F10:
|
|
|
|
case kVK_F11:
|
|
|
|
case kVK_F12:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Pause:
|
|
|
|
case kVK_PC_ScrollLock:
|
|
|
|
case kVK_PC_PrintScreen:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_F16:
|
|
|
|
case kVK_F17:
|
|
|
|
case kVK_F18:
|
|
|
|
case kVK_F19:
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Insert:
|
|
|
|
case kVK_PC_Delete:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Tab:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_PC_Backspace:
|
2013-12-06 07:16:55 +04:00
|
|
|
case kVK_PC_ContextMenu:
|
2012-07-04 09:59:50 +04:00
|
|
|
|
|
|
|
case kVK_JIS_Eisu:
|
|
|
|
case kVK_JIS_Kana:
|
|
|
|
|
|
|
|
case kVK_Home:
|
|
|
|
case kVK_End:
|
|
|
|
case kVK_PageUp:
|
|
|
|
case kVK_PageDown:
|
|
|
|
case kVK_LeftArrow:
|
|
|
|
case kVK_RightArrow:
|
|
|
|
case kVK_UpArrow:
|
|
|
|
case kVK_DownArrow:
|
|
|
|
case kVK_Return:
|
|
|
|
case kVK_ANSI_KeypadEnter:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Powerbook_KeypadEnter:
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2013-10-01 11:22:58 +04:00
|
|
|
TextInputHandlerBase::IsNormalCharInputtingEvent(
|
|
|
|
const WidgetKeyboardEvent& aKeyEvent)
|
2011-02-23 20:25:11 +03:00
|
|
|
{
|
|
|
|
// this is not character inputting event, simply.
|
2016-03-16 07:47:50 +03:00
|
|
|
if (aKeyEvent.mNativeCharacters.IsEmpty() ||
|
|
|
|
aKeyEvent.IsMeta()) {
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2016-03-16 07:47:50 +03:00
|
|
|
return !IsControlChar(aKeyEvent.mNativeCharacters[0]);
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* static */ bool
|
2011-02-23 20:25:11 +03:00
|
|
|
TextInputHandlerBase::IsModifierKey(UInt32 aNativeKeyCode)
|
|
|
|
{
|
|
|
|
switch (aNativeKeyCode) {
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_CapsLock:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_RightCommand:
|
2012-07-04 09:59:50 +04:00
|
|
|
case kVK_Command:
|
|
|
|
case kVK_Shift:
|
|
|
|
case kVK_Option:
|
|
|
|
case kVK_Control:
|
|
|
|
case kVK_RightShift:
|
|
|
|
case kVK_RightOption:
|
|
|
|
case kVK_RightControl:
|
2012-10-19 05:17:07 +04:00
|
|
|
case kVK_Function:
|
2011-10-01 04:20:33 +04:00
|
|
|
return true;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
return false;
|
2011-02-23 20:25:11 +03:00
|
|
|
}
|
2013-05-24 20:27:52 +04:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
TextInputHandlerBase::EnableSecureEventInput()
|
|
|
|
{
|
|
|
|
sSecureEventInputCount++;
|
|
|
|
::EnableSecureEventInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
TextInputHandlerBase::DisableSecureEventInput()
|
|
|
|
{
|
|
|
|
if (!sSecureEventInputCount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sSecureEventInputCount--;
|
|
|
|
::DisableSecureEventInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
TextInputHandlerBase::IsSecureEventInputEnabled()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!!sSecureEventInputCount == !!::IsSecureEventInputEnabled(),
|
|
|
|
"Some other process has enabled secure event input");
|
|
|
|
return !!sSecureEventInputCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
TextInputHandlerBase::EnsureSecureEventInputDisabled()
|
|
|
|
{
|
|
|
|
while (sSecureEventInputCount) {
|
|
|
|
TextInputHandlerBase::DisableSecureEventInput();
|
|
|
|
}
|
|
|
|
}
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* TextInputHandlerBase::KeyEventState implementation
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
TextInputHandlerBase::KeyEventState::InitKeyEvent(
|
|
|
|
TextInputHandlerBase* aHandler,
|
|
|
|
WidgetKeyboardEvent& aKeyEvent)
|
|
|
|
{
|
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
|
|
|
MOZ_ASSERT(aHandler);
|
|
|
|
MOZ_RELEASE_ASSERT(mKeyEvent);
|
|
|
|
|
|
|
|
NSEvent* nativeEvent = mKeyEvent;
|
|
|
|
if (!mInsertedString.IsEmpty()) {
|
|
|
|
nsAutoString unhandledString;
|
|
|
|
GetUnhandledString(unhandledString);
|
|
|
|
NSString* unhandledNSString =
|
|
|
|
nsCocoaUtils::ToNSString(unhandledString);
|
|
|
|
// If the key event's some characters were already handled by
|
|
|
|
// InsertString() calls, we need to create a dummy event which doesn't
|
|
|
|
// include the handled characters.
|
|
|
|
nativeEvent =
|
|
|
|
[NSEvent keyEventWithType:[mKeyEvent type]
|
|
|
|
location:[mKeyEvent locationInWindow]
|
|
|
|
modifierFlags:[mKeyEvent modifierFlags]
|
|
|
|
timestamp:[mKeyEvent timestamp]
|
|
|
|
windowNumber:[mKeyEvent windowNumber]
|
|
|
|
context:[mKeyEvent context]
|
|
|
|
characters:unhandledNSString
|
|
|
|
charactersIgnoringModifiers:[mKeyEvent charactersIgnoringModifiers]
|
|
|
|
isARepeat:[mKeyEvent isARepeat]
|
|
|
|
keyCode:[mKeyEvent keyCode]];
|
|
|
|
}
|
|
|
|
|
2017-05-16 05:59:35 +03:00
|
|
|
aKeyEvent.mUniqueId = mUniqueId;
|
Bug 1280053 TextInputHandler should initialize WidgetKeyboardEvent without already handled characters r=m_kato
TextInputHandler may dispatch keypress events after InsertText() is called if there was composition and it's committed by "current" keydown event. In that case, [NSEvent characters] may have the committing string. For example, when Opt+e of US keyboard layout started composition, Cmd+v causes committing the "`" character and pasting the clipboard text. Then, the "v" key's keydown event's |characters| is "`v". So, after InsertText() is called with "`", TextInputHandler shouldn't dispatch keypress event for "`" again. I.e., the KeyboardEvent.key value should be "v" rather than "`v".
For solving this issue, TextInputHandlerBase::AutoInsertStringClearer which is created at every InsertText() call should store the inserted string to TextInputHandlerBase::KeyEventState. However, for making the implemntation simpler, it should recode only when the inserting string is actually a part of [mKeyEvent characters]. Then, TextInputHandlerBase::KeyEventState can compute unhandled insert string at initializing WidgetKeyboardEvent.
So, finally, TextInputHandlerBase::InitKeyEvent() should be called via TextInputHandlerBase::KeyEventState::InitKeyEvent(). This ensures that all key events which may cause InsertText() calls are always initialized with unhandled string.
MozReview-Commit-ID: A9o8o9pV2XV
--HG--
extra : rebase_source : d99e9ab7633f45069d0a3940cc2b2b5ad859ea05
2016-06-18 19:13:16 +03:00
|
|
|
aHandler->InitKeyEvent(nativeEvent, aKeyEvent, mInsertString);
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextInputHandlerBase::KeyEventState::GetUnhandledString(
|
|
|
|
nsAString& aUnhandledString) const
|
|
|
|
{
|
|
|
|
aUnhandledString.Truncate();
|
|
|
|
if (NS_WARN_IF(!mKeyEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsAutoString characters;
|
|
|
|
nsCocoaUtils::GetStringForNSString([mKeyEvent characters],
|
|
|
|
characters);
|
|
|
|
if (characters.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mInsertedString.IsEmpty()) {
|
|
|
|
aUnhandledString = characters;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The insertes string must match with the start of characters.
|
|
|
|
MOZ_ASSERT(StringBeginsWith(characters, mInsertedString));
|
|
|
|
|
|
|
|
aUnhandledString = nsDependentSubstring(characters, mInsertedString.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* TextInputHandlerBase::AutoInsertStringClearer implementation
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
TextInputHandlerBase::AutoInsertStringClearer::~AutoInsertStringClearer()
|
|
|
|
{
|
|
|
|
if (mState && mState->mInsertString) {
|
|
|
|
// If inserting string is a part of characters of the event,
|
|
|
|
// we should record it as inserted string.
|
|
|
|
nsAutoString characters;
|
|
|
|
nsCocoaUtils::GetStringForNSString([mState->mKeyEvent characters],
|
|
|
|
characters);
|
|
|
|
nsAutoString insertedString(mState->mInsertedString);
|
|
|
|
insertedString += *mState->mInsertString;
|
|
|
|
if (StringBeginsWith(characters, insertedString)) {
|
|
|
|
mState->mInsertedString = insertedString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mState) {
|
|
|
|
mState->mInsertString = nullptr;
|
|
|
|
}
|
|
|
|
}
|