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
|
|
|
#ifndef TextInputHandler_h_
|
|
|
|
#define TextInputHandler_h_
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
#include "nsCocoaUtils.h"
|
|
|
|
|
|
|
|
#import <Carbon/Carbon.h>
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
#include "mozView.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsITimer.h"
|
2011-02-17 10:41:36 +03:00
|
|
|
#include "nsTArray.h"
|
2013-09-24 14:04:14 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2016-03-16 07:47:49 +03:00
|
|
|
#include "mozilla/TextEventDispatcherListener.h"
|
2015-02-10 18:28:05 +03:00
|
|
|
#include "WritingModes.h"
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
class nsChildView;
|
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
// Key code constants
|
|
|
|
enum
|
|
|
|
{
|
2016-07-09 19:57:01 +03:00
|
|
|
#if !defined(MAC_OS_X_VERSION_10_12) || \
|
|
|
|
MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
|
2012-07-04 09:59:50 +04:00
|
|
|
kVK_RightCommand = 0x36, // right command key
|
2016-07-09 19:57:01 +03:00
|
|
|
#endif
|
2012-05-17 11:04:16 +04:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
kVK_PC_PrintScreen = kVK_F13,
|
|
|
|
kVK_PC_ScrollLock = kVK_F14,
|
|
|
|
kVK_PC_Pause = kVK_F15,
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
kVK_PC_Insert = kVK_Help,
|
|
|
|
kVK_PC_Backspace = kVK_Delete,
|
|
|
|
kVK_PC_Delete = kVK_ForwardDelete,
|
|
|
|
|
2013-12-06 07:16:55 +04:00
|
|
|
kVK_PC_ContextMenu = 0x6E,
|
|
|
|
|
2012-07-04 09:59:50 +04:00
|
|
|
kVK_Powerbook_KeypadEnter = 0x34 // Enter on Powerbook's keyboard is different
|
2011-02-23 20:25:11 +03:00
|
|
|
};
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
/**
|
2011-05-08 14:19:15 +04:00
|
|
|
* TISInputSourceWrapper is a wrapper for the TISInputSourceRef. If we get the
|
2009-10-01 06:52:50 +04:00
|
|
|
* TISInputSourceRef from InputSourceID, we need to release the CFArray instance
|
|
|
|
* which is returned by TISCreateInputSourceList. However, when we release the
|
|
|
|
* list, we cannot access the TISInputSourceRef. So, it's not usable, and it
|
|
|
|
* may cause the memory leak bugs. nsTISInputSource automatically releases the
|
|
|
|
* list when the instance is destroyed.
|
|
|
|
*/
|
2011-05-08 14:19:15 +04:00
|
|
|
class TISInputSourceWrapper
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2012-10-16 05:43:50 +04:00
|
|
|
static TISInputSourceWrapper& CurrentInputSource();
|
2016-06-16 11:00:38 +03:00
|
|
|
/**
|
|
|
|
* Shutdown() should be called when nobody doesn't need to use this class.
|
|
|
|
*/
|
|
|
|
static void Shutdown();
|
2009-10-16 13:12:09 +04:00
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
TISInputSourceWrapper()
|
2017-10-31 13:25:04 +03:00
|
|
|
: mInputSource{nullptr}
|
|
|
|
, mKeyboardLayout{nullptr}
|
|
|
|
, mUCKeyboardLayout{nullptr}
|
|
|
|
, mIsRTL{0}
|
|
|
|
, mOverrideKeyboard{false}
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mInputSourceList = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2014-09-01 07:33:13 +04:00
|
|
|
explicit TISInputSourceWrapper(const char* aID)
|
2017-10-31 13:25:04 +03:00
|
|
|
: mInputSource{nullptr}
|
|
|
|
, mKeyboardLayout{nullptr}
|
|
|
|
, mUCKeyboardLayout{nullptr}
|
|
|
|
, mIsRTL{0}
|
|
|
|
, mOverrideKeyboard{false}
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mInputSourceList = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByInputSourceID(aID);
|
|
|
|
}
|
|
|
|
|
2014-09-01 07:33:13 +04:00
|
|
|
explicit TISInputSourceWrapper(SInt32 aLayoutID)
|
2017-10-31 13:25:04 +03:00
|
|
|
: mInputSource{nullptr}
|
|
|
|
, mKeyboardLayout{nullptr}
|
|
|
|
, mUCKeyboardLayout{nullptr}
|
|
|
|
, mIsRTL{0}
|
|
|
|
, mOverrideKeyboard{false}
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mInputSourceList = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByLayoutID(aLayoutID);
|
|
|
|
}
|
|
|
|
|
2014-09-01 07:33:13 +04:00
|
|
|
explicit TISInputSourceWrapper(TISInputSourceRef aInputSource)
|
2017-10-31 13:25:04 +03:00
|
|
|
: mInputSource{nullptr}
|
|
|
|
, mKeyboardLayout{nullptr}
|
|
|
|
, mUCKeyboardLayout{nullptr}
|
|
|
|
, mIsRTL{0}
|
|
|
|
, mOverrideKeyboard{false}
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mInputSourceList = nullptr;
|
2009-10-01 06:52:50 +04:00
|
|
|
InitByTISInputSourceRef(aInputSource);
|
|
|
|
}
|
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
~TISInputSourceWrapper() { Clear(); }
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
void InitByInputSourceID(const char* aID);
|
2017-06-20 12:19:05 +03:00
|
|
|
void InitByInputSourceID(const nsString& aID);
|
2009-10-01 06:52:50 +04:00
|
|
|
void InitByInputSourceID(const CFStringRef aID);
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
|
|
|
* InitByLayoutID() initializes the keyboard layout by the layout ID.
|
|
|
|
*
|
|
|
|
* @param aLayoutID An ID of keyboard layout.
|
2012-03-30 07:37:40 +04:00
|
|
|
* 0: US
|
|
|
|
* 1: Greek
|
|
|
|
* 2: German
|
|
|
|
* 3: Swedish-Pro
|
|
|
|
* 4: Dvorak-Qwerty Cmd
|
|
|
|
* 5: Thai
|
2013-12-18 11:02:46 +04:00
|
|
|
* 6: Arabic
|
|
|
|
* 7: French
|
|
|
|
* 8: Hebrew
|
|
|
|
* 9: Lithuanian
|
|
|
|
* 10: Norwegian
|
|
|
|
* 11: Spanish
|
2011-02-23 20:25:11 +03:00
|
|
|
* @param aOverrideKeyboard When testing set to TRUE, otherwise, set to
|
|
|
|
* FALSE. When TRUE, we use an ANSI keyboard
|
|
|
|
* instead of the actual keyboard.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void InitByLayoutID(SInt32 aLayoutID, bool aOverrideKeyboard = false);
|
2009-10-01 06:52:50 +04:00
|
|
|
void InitByCurrentInputSource();
|
|
|
|
void InitByCurrentKeyboardLayout();
|
|
|
|
void InitByCurrentASCIICapableInputSource();
|
|
|
|
void InitByCurrentASCIICapableKeyboardLayout();
|
2012-10-16 05:43:50 +04:00
|
|
|
void InitByCurrentInputMethodKeyboardLayoutOverride();
|
2009-10-01 06:52:50 +04:00
|
|
|
void InitByTISInputSourceRef(TISInputSourceRef aInputSource);
|
|
|
|
void InitByLanguage(CFStringRef aLanguage);
|
|
|
|
|
2012-10-16 05:43:50 +04:00
|
|
|
/**
|
|
|
|
* If the instance is initialized with a keyboard layout input source,
|
|
|
|
* returns it.
|
|
|
|
* If the instance is initialized with an IME mode input source, the result
|
|
|
|
* references the keyboard layout for the IME mode. However, this can be
|
|
|
|
* initialized only when the IME mode is actually selected. I.e, if IME mode
|
|
|
|
* input source is initialized with LayoutID or SourceID, this returns null.
|
|
|
|
*/
|
|
|
|
TISInputSourceRef GetKeyboardLayoutInputSource() const
|
|
|
|
{
|
|
|
|
return mKeyboardLayout;
|
|
|
|
}
|
2009-10-01 06:52:50 +04:00
|
|
|
const UCKeyboardLayout* GetUCKeyboardLayout();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsOpenedIMEMode();
|
|
|
|
bool IsIMEMode();
|
2012-10-16 05:43:50 +04:00
|
|
|
bool IsKeyboardLayout();
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsASCIICapable()
|
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
|
|
|
return GetBoolProperty(kTISPropertyInputSourceIsASCIICapable);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsEnabled()
|
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
|
|
|
return GetBoolProperty(kTISPropertyInputSourceIsEnabled);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetLanguageList(CFArrayRef &aLanguageList);
|
|
|
|
bool GetPrimaryLanguage(CFStringRef &aPrimaryLanguage);
|
|
|
|
bool GetPrimaryLanguage(nsAString &aPrimaryLanguage);
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetLocalizedName(CFStringRef &aName)
|
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
|
|
|
return GetStringProperty(kTISPropertyLocalizedName, aName);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetLocalizedName(nsAString &aName)
|
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
|
|
|
return GetStringProperty(kTISPropertyLocalizedName, aName);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetInputSourceID(CFStringRef &aID)
|
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
|
|
|
return GetStringProperty(kTISPropertyInputSourceID, aID);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetInputSourceID(nsAString &aID)
|
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
|
|
|
return GetStringProperty(kTISPropertyInputSourceID, aID);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetBundleID(CFStringRef &aBundleID)
|
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
|
|
|
return GetStringProperty(kTISPropertyBundleID, aBundleID);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetBundleID(nsAString &aBundleID)
|
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
|
|
|
return GetStringProperty(kTISPropertyBundleID, aBundleID);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetInputSourceType(CFStringRef &aType)
|
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
|
|
|
return GetStringProperty(kTISPropertyInputSourceType, aType);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetInputSourceType(nsAString &aType)
|
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
|
|
|
return GetStringProperty(kTISPropertyInputSourceType, aType);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsForRTLLanguage();
|
Bug 1215818 - part 2: Add telemetry probe to collect IME usage on macOS r=m_kato
This patch adds a telemetry probe to collect Input Source ID or Bundle ID of
IME when an IME open mode is selected by user. Input Source ID includes
input mode of IME, but Bundle ID does not so. In most languages, we need
to collect the former, but only for Japanese IME, we need to collect the
latter because non-Japanese IME's input mode is "how to input characters".
So, the input mode is important. However, Japanese IME's input mode is
"to input which type of characters". So, Japanese IME user may use multiple
input modes but we need only the IME mode. If we'd collect number of
each input mode users of Japanese language, it'd be difficult to count
how many users actually used typical Japanese IME since somebody may use
only a mode, some others may use only different modes.
So, this patch collects Input Source ID when non-Japanese IME is open and
Bundle ID when Japanese IME is open.
MozReview-Commit-ID: CltLrWVGyRk
--HG--
extra : rebase_source : 752dd00c4e43bda9586ed3ba498636bf5069ead2
2018-06-20 05:33:42 +03:00
|
|
|
bool IsForJapaneseLanguage();
|
2012-10-16 05:43:50 +04:00
|
|
|
bool IsInitializedByCurrentInputSource();
|
2009-10-16 13:12:09 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
// 40 is an actual result of the ::LMGetKbdType() when we connect an
|
|
|
|
// unknown keyboard and set the keyboard type to ANSI manually on the
|
|
|
|
// set up dialog.
|
|
|
|
eKbdType_ANSI = 40
|
|
|
|
};
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
void Select();
|
2009-10-16 13:12:09 +04:00
|
|
|
void Clear();
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
|
|
|
* InitKeyEvent() initializes aKeyEvent for aNativeKeyEvent.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyEvent A native key event for which you want to
|
|
|
|
* dispatch a Gecko key event.
|
|
|
|
* @param aKeyEvent The result -- a Gecko key event initialized
|
|
|
|
* from the native key event.
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
* @param aIsProcessedByIME true if aNativeKeyEvent has been handled
|
|
|
|
* by IME (but except if the composition was
|
|
|
|
* started with dead key).
|
2012-07-21 03:24:48 +04:00
|
|
|
* @param aInsertString If caller expects that the event will cause
|
|
|
|
* a character to be input (say in an editor),
|
|
|
|
* the caller should set this. Otherwise,
|
|
|
|
* if caller sets null to this, this method will
|
|
|
|
* compute the character to be input from
|
|
|
|
* characters of aNativeKeyEvent.
|
2011-02-23 20:25:11 +03:00
|
|
|
*/
|
2013-10-01 11:22:58 +04:00
|
|
|
void InitKeyEvent(NSEvent *aNativeKeyEvent, WidgetKeyboardEvent& aKeyEvent,
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
bool aIsProcessedByIME,
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsAString *aInsertString = nullptr);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
/**
|
2016-05-12 11:57:21 +03:00
|
|
|
* WillDispatchKeyboardEvent() computes aKeyEvent.mAlternativeCharCodes and
|
2016-05-13 10:06:18 +03:00
|
|
|
* recompute aKeyEvent.mCharCode if it's necessary.
|
2016-03-16 07:47:50 +03:00
|
|
|
*
|
|
|
|
* @param aNativeKeyEvent A native key event for which you want to
|
|
|
|
* dispatch a Gecko key event.
|
|
|
|
* @param aInsertString If caller expects that the event will cause
|
|
|
|
* a character to be input (say in an editor),
|
|
|
|
* the caller should set this. Otherwise,
|
|
|
|
* if caller sets null to this, this method will
|
|
|
|
* compute the character to be input from
|
|
|
|
* characters of aNativeKeyEvent.
|
|
|
|
* @param aKeyEvent The result -- a Gecko key event initialized
|
|
|
|
* from the native key event. This must be
|
|
|
|
* eKeyPress event.
|
|
|
|
*/
|
|
|
|
void WillDispatchKeyboardEvent(NSEvent* aNativeKeyEvent,
|
|
|
|
const nsAString* aInsertString,
|
|
|
|
WidgetKeyboardEvent& aKeyEvent);
|
|
|
|
|
2012-05-17 11:04:16 +04:00
|
|
|
/**
|
|
|
|
* ComputeGeckoKeyCode() returns Gecko keycode for aNativeKeyCode on current
|
|
|
|
* keyboard layout.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyCode A native keycode.
|
|
|
|
* @param aKbType A native Keyboard Type value. Typically,
|
|
|
|
* this is a result of ::LMGetKbdType().
|
|
|
|
* @param aCmdIsPressed TRUE if Cmd key is pressed. Otherwise, FALSE.
|
|
|
|
* @return The computed Gecko keycode.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t ComputeGeckoKeyCode(UInt32 aNativeKeyCode, UInt32 aKbType,
|
2012-05-17 11:04:16 +04:00
|
|
|
bool aCmdIsPressed);
|
|
|
|
|
2013-04-24 07:49:47 +04:00
|
|
|
/**
|
|
|
|
* ComputeGeckoKeyNameIndex() returns Gecko key name index for the key.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyCode A native keycode.
|
|
|
|
*/
|
|
|
|
static KeyNameIndex ComputeGeckoKeyNameIndex(UInt32 aNativeKeyCode);
|
|
|
|
|
2014-05-25 06:08:59 +04:00
|
|
|
/**
|
|
|
|
* ComputeGeckoCodeNameIndex() returns Gecko code name index for the key.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyCode A native keycode.
|
2017-02-27 12:04:30 +03:00
|
|
|
* @param aKbType A native Keyboard Type value. Typically,
|
|
|
|
* this is a result of ::LMGetKbdType().
|
2014-05-25 06:08:59 +04:00
|
|
|
*/
|
2017-02-27 12:04:30 +03:00
|
|
|
static CodeNameIndex ComputeGeckoCodeNameIndex(UInt32 aNativeKeyCode,
|
|
|
|
UInt32 aKbType);
|
2014-05-25 06:08:59 +04:00
|
|
|
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
/**
|
|
|
|
* TranslateToChar() checks if aNativeKeyEvent is a dead key.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyEvent A native key event.
|
|
|
|
* @return Returns true if the key event is a dead key
|
|
|
|
* event. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool IsDeadKey(NSEvent* aNativeKeyEvent);
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
protected:
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
|
|
|
* TranslateToString() computes the inputted text from the native keyCode,
|
|
|
|
* modifier flags and keyboard type.
|
|
|
|
*
|
|
|
|
* @param aKeyCode A native keyCode.
|
|
|
|
* @param aModifiers Combination of native modifier flags.
|
|
|
|
* @param aKbType A native Keyboard Type value. Typically,
|
|
|
|
* this is a result of ::LMGetKbdType().
|
|
|
|
* @param aStr Result, i.e., inputted text.
|
|
|
|
* The result can be two or more characters.
|
|
|
|
* @return If succeeded, TRUE. Otherwise, FALSE.
|
|
|
|
* Even if TRUE, aStr can be empty string.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool TranslateToString(UInt32 aKeyCode, UInt32 aModifiers,
|
2011-02-23 20:25:11 +03:00
|
|
|
UInt32 aKbType, nsAString &aStr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TranslateToChar() computes the inputted character from the native keyCode,
|
|
|
|
* modifier flags and keyboard type. If two or more characters would be
|
|
|
|
* input, this returns 0.
|
|
|
|
*
|
|
|
|
* @param aKeyCode A native keyCode.
|
|
|
|
* @param aModifiers Combination of native modifier flags.
|
|
|
|
* @param aKbType A native Keyboard Type value. Typically,
|
|
|
|
* this is a result of ::LMGetKbdType().
|
|
|
|
* @return If succeeded and the result is one character,
|
|
|
|
* returns the charCode of it. Otherwise,
|
|
|
|
* returns 0.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t TranslateToChar(UInt32 aKeyCode, UInt32 aModifiers, UInt32 aKbType);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2017-03-01 04:58:55 +03:00
|
|
|
/**
|
|
|
|
* TranslateToChar() checks if aKeyCode with aModifiers is a dead key.
|
|
|
|
*
|
|
|
|
* @param aKeyCode A native keyCode.
|
|
|
|
* @param aModifiers Combination of native modifier flags.
|
|
|
|
* @param aKbType A native Keyboard Type value. Typically,
|
|
|
|
* this is a result of ::LMGetKbdType().
|
|
|
|
* @return Returns true if the key with specified
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
* modifier state is a dead key. Otherwise,
|
2017-03-01 04:58:55 +03:00
|
|
|
* false.
|
|
|
|
*/
|
|
|
|
bool IsDeadKey(UInt32 aKeyCode, UInt32 aModifiers, UInt32 aKbType);
|
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
2016-03-16 07:47:50 +03:00
|
|
|
* ComputeInsertString() computes string to be inserted with the key event.
|
2011-02-23 20:25:11 +03:00
|
|
|
*
|
2016-03-16 07:47:50 +03:00
|
|
|
* @param aNativeKeyEvent The native key event which causes our keyboard
|
|
|
|
* event(s).
|
|
|
|
* @param aKeyEvent A Gecko key event which was partially
|
|
|
|
* initialized with aNativeKeyEvent.
|
|
|
|
* @param aInsertString The string to be inputting by aNativeKeyEvent.
|
|
|
|
* This should be specified by InsertText().
|
|
|
|
* In other words, if the key event doesn't cause
|
|
|
|
* a call of InsertText(), this can be nullptr.
|
|
|
|
* @param aResult The string which should be set to charCode of
|
|
|
|
* keypress event(s).
|
2011-02-23 20:25:11 +03:00
|
|
|
*/
|
2016-03-16 07:47:50 +03:00
|
|
|
void ComputeInsertStringForCharCode(NSEvent* aNativeKeyEvent,
|
|
|
|
const WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
const nsAString* aInsertString,
|
|
|
|
nsAString& aResult);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsPrintableKeyEvent() returns true if aNativeKeyEvent is caused by
|
|
|
|
* a printable key. Otherwise, returns false.
|
|
|
|
*/
|
|
|
|
bool IsPrintableKeyEvent(NSEvent* aNativeKeyEvent) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetKbdType() returns physical keyboard type.
|
|
|
|
*/
|
|
|
|
UInt32 GetKbdType() const;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetBoolProperty(const CFStringRef aKey);
|
|
|
|
bool GetStringProperty(const CFStringRef aKey, CFStringRef &aStr);
|
|
|
|
bool GetStringProperty(const CFStringRef aKey, nsAString &aStr);
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
TISInputSourceRef mInputSource;
|
2012-10-16 05:43:50 +04:00
|
|
|
TISInputSourceRef mKeyboardLayout;
|
2009-10-01 06:52:50 +04:00
|
|
|
CFArrayRef mInputSourceList;
|
2009-10-16 13:12:09 +04:00
|
|
|
const UCKeyboardLayout* mUCKeyboardLayout;
|
2012-08-22 19:56:38 +04:00
|
|
|
int8_t mIsRTL;
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOverrideKeyboard;
|
2016-06-16 11:00:38 +03:00
|
|
|
|
|
|
|
static TISInputSourceWrapper* sCurrentInputSource;
|
2009-10-01 06:52:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-12-11 17:44:07 +03:00
|
|
|
* TextInputHandlerBase is a base class of IMEInputHandler and TextInputHandler.
|
|
|
|
* Utility methods should be implemented this level.
|
2011-05-08 14:19:15 +04:00
|
|
|
*/
|
|
|
|
|
2016-03-16 07:47:49 +03:00
|
|
|
class TextInputHandlerBase : public TextEventDispatcherListener
|
2011-05-08 14:19:15 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-03-16 07:47:49 +03:00
|
|
|
/**
|
|
|
|
* Other TextEventDispatcherListener methods should be implemented in
|
|
|
|
* IMEInputHandler.
|
|
|
|
*/
|
|
|
|
NS_DECL_ISUPPORTS
|
2011-05-08 14:19:15 +04:00
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
|
|
|
* DispatchEvent() dispatches aEvent on mWidget.
|
|
|
|
*
|
|
|
|
* @param aEvent An event which you want to dispatch.
|
|
|
|
* @return TRUE if the event is consumed by web contents
|
|
|
|
* or chrome contents. Otherwise, FALSE.
|
|
|
|
*/
|
2013-10-02 07:46:03 +04:00
|
|
|
bool DispatchEvent(WidgetGUIEvent& aEvent);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
/**
|
2015-09-08 17:33:38 +03:00
|
|
|
* SetSelection() dispatches eSetSelection event for the aRange.
|
2013-07-11 11:46:35 +04:00
|
|
|
*
|
|
|
|
* @param aRange The range which will be selected.
|
|
|
|
* @return TRUE if setting selection is succeeded and
|
|
|
|
* the widget hasn't been destroyed.
|
|
|
|
* Otherwise, FALSE.
|
|
|
|
*/
|
|
|
|
bool SetSelection(NSRange& aRange);
|
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
|
|
|
* InitKeyEvent() initializes aKeyEvent for aNativeKeyEvent.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyEvent A native key event for which you want to
|
|
|
|
* dispatch a Gecko key event.
|
|
|
|
* @param aKeyEvent The result -- a Gecko key event initialized
|
|
|
|
* from the native key event.
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
* @param aIsProcessedByIME true if aNativeKeyEvent has been handled
|
|
|
|
* by IME (but except if the composition was
|
|
|
|
* started with dead key).
|
2012-07-21 03:24:48 +04:00
|
|
|
* @param aInsertString If caller expects that the event will cause
|
|
|
|
* a character to be input (say in an editor),
|
|
|
|
* the caller should set this. Otherwise,
|
|
|
|
* if caller sets null to this, this method will
|
|
|
|
* compute the character to be input from
|
|
|
|
* characters of aNativeKeyEvent.
|
2011-02-23 20:25:11 +03:00
|
|
|
*/
|
2013-10-01 11:22:58 +04:00
|
|
|
void InitKeyEvent(NSEvent *aNativeKeyEvent, WidgetKeyboardEvent& aKeyEvent,
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
bool aIsProcessedByIME,
|
2012-07-30 18:20:58 +04:00
|
|
|
const nsAString *aInsertString = nullptr);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SynthesizeNativeKeyEvent() is an implementation of
|
|
|
|
* nsIWidget::SynthesizeNativeKeyEvent(). See the document in nsIWidget.h
|
|
|
|
* for the detail.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
|
|
|
|
int32_t aNativeKeyCode,
|
|
|
|
uint32_t aModifierFlags,
|
2011-02-23 20:25:11 +03:00
|
|
|
const nsAString& aCharacters,
|
|
|
|
const nsAString& aUnmodifiedCharacters);
|
|
|
|
|
2013-07-10 18:12:40 +04:00
|
|
|
/**
|
|
|
|
* Utility method intended for testing. Attempts to construct a native key
|
|
|
|
* event that would have been generated during an actual key press. This
|
|
|
|
* *does not dispatch* the native event. Instead, it is attached to the
|
|
|
|
* |mNativeKeyEvent| field of the Gecko event that is passed in.
|
|
|
|
* @param aKeyEvent Gecko key event to attach the native event to
|
|
|
|
*/
|
2013-10-01 11:22:58 +04:00
|
|
|
NS_IMETHOD AttachNativeKeyEvent(WidgetKeyboardEvent& aKeyEvent);
|
2013-07-10 18:12:40 +04:00
|
|
|
|
2013-07-11 11:46:35 +04:00
|
|
|
/**
|
|
|
|
* GetWindowLevel() returns the window level of current focused (in Gecko)
|
|
|
|
* window. E.g., if an <input> element in XUL panel has focus, this returns
|
|
|
|
* the XUL panel's window level.
|
|
|
|
*/
|
|
|
|
NSInteger GetWindowLevel();
|
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
/**
|
|
|
|
* IsSpecialGeckoKey() checks whether aNativeKeyCode is mapped to a special
|
|
|
|
* Gecko keyCode. A key is "special" if it isn't used for text input.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyCode A native keycode.
|
|
|
|
* @return If the keycode is mapped to a special key,
|
|
|
|
* TRUE. Otherwise, FALSE.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsSpecialGeckoKey(UInt32 aNativeKeyCode);
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2013-05-24 20:27:52 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* EnableSecureEventInput() and DisableSecureEventInput() wrap the Carbon
|
|
|
|
* Event Manager APIs with the same names. In addition they keep track of
|
|
|
|
* how many times we've called them (in the same process) -- unlike the
|
|
|
|
* Carbon Event Manager APIs, which only keep track of how many times they've
|
|
|
|
* been called from any and all processes.
|
|
|
|
*
|
|
|
|
* The Carbon Event Manager's IsSecureEventInputEnabled() returns whether
|
|
|
|
* secure event input mode is enabled (in any process). This class's
|
|
|
|
* IsSecureEventInputEnabled() returns whether we've made any calls to
|
|
|
|
* EnableSecureEventInput() that are not (yet) offset by the calls we've
|
|
|
|
* made to DisableSecureEventInput().
|
|
|
|
*/
|
|
|
|
static void EnableSecureEventInput();
|
|
|
|
static void DisableSecureEventInput();
|
|
|
|
static bool IsSecureEventInputEnabled();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* EnsureSecureEventInputDisabled() calls DisableSecureEventInput() until
|
|
|
|
* our call count becomes 0.
|
|
|
|
*/
|
|
|
|
static void EnsureSecureEventInputDisabled();
|
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* mWidget must not be destroyed without OnDestroyWidget being called.
|
2011-05-08 14:19:15 +04:00
|
|
|
*
|
2011-05-08 14:19:23 +04:00
|
|
|
* @param aDestroyingWidget Destroying widget. This might not be mWidget.
|
2011-05-08 14:19:15 +04:00
|
|
|
* @return This result doesn't have any meaning for
|
2011-05-08 14:19:23 +04:00
|
|
|
* callers. When aDstroyingWidget isn't the same
|
|
|
|
* as mWidget, FALSE. Then, inherited methods in
|
2011-05-08 14:19:15 +04:00
|
|
|
* sub classes should return from this method
|
|
|
|
* without cleaning up.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool OnDestroyWidget(nsChildView* aDestroyingWidget);
|
2011-05-08 14:19:15 +04:00
|
|
|
|
|
|
|
protected:
|
2016-03-16 07:47:50 +03:00
|
|
|
// The creator of this instance, client and its text event dispatcher.
|
|
|
|
// These members must not be nullptr after initialized until
|
|
|
|
// OnDestroyWidget() is called.
|
2011-05-08 14:19:23 +04:00
|
|
|
nsChildView* mWidget; // [WEAK]
|
2016-03-16 07:47:50 +03:00
|
|
|
RefPtr<TextEventDispatcher> mDispatcher;
|
2011-05-08 14:19:15 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
// The native view for mWidget.
|
2011-05-08 14:19:15 +04:00
|
|
|
// This view handles the actual text inputting.
|
2011-05-08 14:19:23 +04:00
|
|
|
NSView<mozView>* mView; // [STRONG]
|
2011-05-08 14:19:15 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
TextInputHandlerBase(nsChildView* aWidget, NSView<mozView> *aNativeView);
|
2011-05-08 14:19:15 +04:00
|
|
|
virtual ~TextInputHandlerBase();
|
2011-05-08 14:19:23 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Destroyed() { return !mWidget; }
|
2011-02-23 20:25:11 +03:00
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
/**
|
|
|
|
* mCurrentKeyEvent indicates what key event we are handling. While
|
|
|
|
* handling a native keydown event, we need to store the event for insertText,
|
|
|
|
* doCommandBySelector and various action message handlers of NSResponder
|
|
|
|
* such as [NSResponder insertNewline:sender].
|
|
|
|
*/
|
|
|
|
struct KeyEventState
|
|
|
|
{
|
|
|
|
// Handling native key event
|
|
|
|
NSEvent* mKeyEvent;
|
2016-03-16 07:47:50 +03:00
|
|
|
// String specified by InsertText(). This is not null only during a
|
|
|
|
// call of InsertText().
|
|
|
|
nsAString* mInsertString;
|
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
|
|
|
// String which are included in [mKeyEvent characters] and already handled
|
|
|
|
// by InsertText() call(s).
|
|
|
|
nsString mInsertedString;
|
2017-05-16 05:59:35 +03:00
|
|
|
// Unique id associated with a keydown / keypress event. It's ok if this
|
|
|
|
// wraps over long periods.
|
|
|
|
uint32_t mUniqueId;
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
// Whether keydown event was dispatched for mKeyEvent.
|
|
|
|
bool mKeyDownDispatched;
|
2011-02-23 21:06:26 +03:00
|
|
|
// Whether keydown event was consumed by web contents or chrome contents.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mKeyDownHandled;
|
2011-02-23 21:06:26 +03:00
|
|
|
// Whether keypress event was dispatched for mKeyEvent.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mKeyPressDispatched;
|
2011-02-23 21:06:26 +03:00
|
|
|
// Whether keypress event was consumed by web contents or chrome contents.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mKeyPressHandled;
|
2011-10-05 06:19:24 +04:00
|
|
|
// Whether the key event causes other key events via IME or something.
|
|
|
|
bool mCausedOtherKeyEvents;
|
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
|
|
|
// Whether the key event causes composition change or committing
|
|
|
|
// composition. So, even if InsertText() is called, this may be false
|
|
|
|
// if it dispatches keypress event.
|
|
|
|
bool mCompositionDispatched;
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2017-05-16 05:59:35 +03:00
|
|
|
KeyEventState()
|
|
|
|
: mKeyEvent(nullptr)
|
|
|
|
, mUniqueId(0)
|
2011-02-23 21:06:26 +03:00
|
|
|
{
|
|
|
|
Clear();
|
2017-05-16 05:59:35 +03:00
|
|
|
}
|
2011-10-05 06:19:24 +04:00
|
|
|
|
2017-05-16 05:59:35 +03:00
|
|
|
explicit KeyEventState(NSEvent* aNativeKeyEvent, uint32_t aUniqueId = 0)
|
|
|
|
: mKeyEvent(nullptr)
|
|
|
|
, mUniqueId(0)
|
2011-10-05 06:19:24 +04:00
|
|
|
{
|
|
|
|
Clear();
|
2017-05-16 05:59:35 +03:00
|
|
|
Set(aNativeKeyEvent, aUniqueId);
|
2011-10-05 06:19:24 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
KeyEventState(const KeyEventState &aOther) = delete;
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
~KeyEventState()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2017-05-16 05:59:35 +03:00
|
|
|
void Set(NSEvent* aNativeKeyEvent, uint32_t aUniqueId = 0)
|
2011-02-23 21:06:26 +03:00
|
|
|
{
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aNativeKeyEvent, "aNativeKeyEvent must not be NULL");
|
2011-02-23 21:06:26 +03:00
|
|
|
Clear();
|
|
|
|
mKeyEvent = [aNativeKeyEvent retain];
|
2017-05-16 05:59:35 +03:00
|
|
|
mUniqueId = aUniqueId;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
if (mKeyEvent) {
|
|
|
|
[mKeyEvent release];
|
2012-07-30 18:20:58 +04:00
|
|
|
mKeyEvent = nullptr;
|
2017-05-16 05:59:35 +03:00
|
|
|
mUniqueId = 0;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
2016-03-16 07:47:50 +03:00
|
|
|
mInsertString = nullptr;
|
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
|
|
|
mInsertedString.Truncate();
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
mKeyDownDispatched = false;
|
2011-10-01 04:20:33 +04:00
|
|
|
mKeyDownHandled = false;
|
|
|
|
mKeyPressDispatched = false;
|
|
|
|
mKeyPressHandled = false;
|
2011-10-05 06:19:24 +04:00
|
|
|
mCausedOtherKeyEvents = false;
|
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
|
|
|
mCompositionDispatched = false;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
|
2013-07-25 10:09:28 +04:00
|
|
|
bool IsDefaultPrevented() const
|
2011-02-23 21:06:26 +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
|
|
|
return mKeyDownHandled || mKeyPressHandled || mCausedOtherKeyEvents ||
|
|
|
|
mCompositionDispatched;
|
2013-07-25 10:09:28 +04:00
|
|
|
}
|
|
|
|
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
bool CanDispatchKeyDownEvent() const
|
|
|
|
{
|
|
|
|
return !mKeyDownDispatched;
|
|
|
|
}
|
|
|
|
|
2013-07-25 10:09:28 +04:00
|
|
|
bool CanDispatchKeyPressEvent() const
|
|
|
|
{
|
|
|
|
return !mKeyPressDispatched && !IsDefaultPrevented();
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
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
|
|
|
|
2017-04-26 14:39:13 +03:00
|
|
|
bool CanHandleCommand() const
|
|
|
|
{
|
|
|
|
return !mKeyDownHandled && !mKeyPressHandled;
|
|
|
|
}
|
|
|
|
|
Bug 1403759 - part 2: Handle edit/selection commands like insertNewline: in TextInputHandler::HandleCommand() r=m_kato
Let's make TextInputHandler::HandleCommand() handle other
commands which are caused by Backspace, Delete, Tab, ArrowUp,
ArrowDown, ArrowRight, ArrowLeft, PageUp, PageDown, Home, End
and Escape keys with various modifiers.
This patch makes Korean users can do most key operation in
editor even with composing Hangul character.
Note that this patch has a hack for cancelOperation: command.
The command is typically fired for Escape key press. However,
it's also fired for Command + Period. Unfortunately, this
behavior is really odd if subclass of NSResponder implements
|void cancelOperation:(id)sender|. If it's implemented,
Cocoa doesn't call its |void keyDown:(NSEvent)theEvent|.
Instead, it calls only |void doCommandBySelector:(SEL)aSelector|
and |void cancelOperation:(id)sender| when Command + Period is
pressed. Therefore, we cannot dispatch keydown nor keypress
event for this key combination if we implement it. Therefore,
this patch doesn't implement the method but handle it in
doCommandBySelector even though the super class of ChildView
cannot handle the command with this path.
MozReview-Commit-ID: 4hS23SiwNJv
--HG--
extra : rebase_source : 38ac1ea494b5f786ecd5c9327efbacd460b59faf
2017-12-02 08:53:10 +03:00
|
|
|
bool IsProperKeyEvent(Command aCommand) const
|
2017-04-27 15:44:58 +03:00
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mKeyEvent)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
KeyNameIndex keyNameIndex =
|
|
|
|
TISInputSourceWrapper::ComputeGeckoKeyNameIndex([mKeyEvent keyCode]);
|
Bug 1403759 - part 2: Handle edit/selection commands like insertNewline: in TextInputHandler::HandleCommand() r=m_kato
Let's make TextInputHandler::HandleCommand() handle other
commands which are caused by Backspace, Delete, Tab, ArrowUp,
ArrowDown, ArrowRight, ArrowLeft, PageUp, PageDown, Home, End
and Escape keys with various modifiers.
This patch makes Korean users can do most key operation in
editor even with composing Hangul character.
Note that this patch has a hack for cancelOperation: command.
The command is typically fired for Escape key press. However,
it's also fired for Command + Period. Unfortunately, this
behavior is really odd if subclass of NSResponder implements
|void cancelOperation:(id)sender|. If it's implemented,
Cocoa doesn't call its |void keyDown:(NSEvent)theEvent|.
Instead, it calls only |void doCommandBySelector:(SEL)aSelector|
and |void cancelOperation:(id)sender| when Command + Period is
pressed. Therefore, we cannot dispatch keydown nor keypress
event for this key combination if we implement it. Therefore,
this patch doesn't implement the method but handle it in
doCommandBySelector even though the super class of ChildView
cannot handle the command with this path.
MozReview-Commit-ID: 4hS23SiwNJv
--HG--
extra : rebase_source : 38ac1ea494b5f786ecd5c9327efbacd460b59faf
2017-12-02 08:53:10 +03:00
|
|
|
Modifiers modifiers =
|
|
|
|
nsCocoaUtils::ModifiersForEvent(mKeyEvent) & (MODIFIER_SHIFT |
|
|
|
|
MODIFIER_CONTROL |
|
|
|
|
MODIFIER_ALT |
|
|
|
|
MODIFIER_META);
|
|
|
|
switch (aCommand) {
|
|
|
|
case CommandInsertLineBreak:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Enter &&
|
|
|
|
modifiers == MODIFIER_CONTROL;
|
|
|
|
case CommandInsertParagraph:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Enter &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandDeleteCharBackward:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Backspace &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandDeleteToBeginningOfLine:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Backspace &&
|
|
|
|
modifiers == MODIFIER_META;
|
|
|
|
case CommandDeleteWordBackward:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Backspace &&
|
|
|
|
modifiers == MODIFIER_ALT;
|
|
|
|
case CommandDeleteCharForward:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Delete &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandDeleteWordForward:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Delete &&
|
|
|
|
modifiers == MODIFIER_ALT;
|
|
|
|
case CommandInsertTab:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Tab &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandInsertBacktab:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Tab &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandCharNext:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandSelectCharNext:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandWordNext:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
|
|
|
|
modifiers == MODIFIER_ALT;
|
|
|
|
case CommandSelectWordNext:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
|
|
|
|
modifiers == (MODIFIER_ALT | MODIFIER_SHIFT);
|
|
|
|
case CommandEndLine:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
|
|
|
|
modifiers == MODIFIER_META;
|
|
|
|
case CommandSelectEndLine:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowRight &&
|
|
|
|
modifiers == (MODIFIER_META | MODIFIER_SHIFT);
|
|
|
|
case CommandCharPrevious:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandSelectCharPrevious:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandWordPrevious:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
|
|
|
|
modifiers == MODIFIER_ALT;
|
|
|
|
case CommandSelectWordPrevious:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
|
|
|
|
modifiers == (MODIFIER_ALT | MODIFIER_SHIFT);
|
|
|
|
case CommandBeginLine:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
|
|
|
|
modifiers == MODIFIER_META;
|
|
|
|
case CommandSelectBeginLine:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowLeft &&
|
|
|
|
modifiers == (MODIFIER_META | MODIFIER_SHIFT);
|
|
|
|
case CommandLinePrevious:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowUp &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandSelectLinePrevious:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowUp &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandMoveTop:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowUp &&
|
|
|
|
modifiers == MODIFIER_META;
|
|
|
|
case CommandSelectTop:
|
|
|
|
return (keyNameIndex == KEY_NAME_INDEX_ArrowUp &&
|
|
|
|
modifiers == (MODIFIER_META | MODIFIER_SHIFT)) ||
|
|
|
|
(keyNameIndex == KEY_NAME_INDEX_Home &&
|
|
|
|
modifiers == MODIFIER_SHIFT);
|
|
|
|
case CommandLineNext:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowDown &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandSelectLineNext:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowDown &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandMoveBottom:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_ArrowDown &&
|
|
|
|
modifiers == MODIFIER_META;
|
|
|
|
case CommandSelectBottom:
|
|
|
|
return (keyNameIndex == KEY_NAME_INDEX_ArrowDown &&
|
|
|
|
modifiers == (MODIFIER_META | MODIFIER_SHIFT)) ||
|
|
|
|
(keyNameIndex == KEY_NAME_INDEX_End &&
|
|
|
|
modifiers == MODIFIER_SHIFT);
|
|
|
|
case CommandScrollPageUp:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_PageUp &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandSelectPageUp:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_PageUp &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandScrollPageDown:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_PageDown &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandSelectPageDown:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_PageDown &&
|
|
|
|
modifiers == MODIFIER_SHIFT;
|
|
|
|
case CommandScrollBottom:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_End &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandScrollTop:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Home &&
|
|
|
|
modifiers == MODIFIER_NONE;
|
|
|
|
case CommandCancelOperation:
|
|
|
|
return (keyNameIndex == KEY_NAME_INDEX_Escape &&
|
|
|
|
(modifiers == MODIFIER_NONE ||
|
|
|
|
modifiers == MODIFIER_SHIFT)) ||
|
|
|
|
([mKeyEvent keyCode] == kVK_ANSI_Period &&
|
|
|
|
modifiers == MODIFIER_META);
|
|
|
|
case CommandComplete:
|
|
|
|
return keyNameIndex == KEY_NAME_INDEX_Escape &&
|
|
|
|
(modifiers == MODIFIER_ALT ||
|
|
|
|
modifiers == (MODIFIER_ALT | MODIFIER_SHIFT));
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-27 15:44:58 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
void InitKeyEvent(TextInputHandlerBase* aHandler,
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
WidgetKeyboardEvent& aKeyEvent,
|
|
|
|
bool aIsProcessedByIME);
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* GetUnhandledString() returns characters of the event which have not been
|
|
|
|
* handled with InsertText() yet. For example, if there is a composition
|
|
|
|
* caused by a dead key press like '`' and it's committed by some key
|
|
|
|
* combinations like |Cmd+v|, then, the |v|'s KeyDown event's |characters|
|
|
|
|
* is |`v|. Then, after |`| is committed with a call of InsertString(),
|
|
|
|
* this returns only 'v'.
|
|
|
|
*/
|
|
|
|
void GetUnhandledString(nsAString& aUnhandledString) const;
|
2011-02-23 21:06:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-03-16 07:47:50 +03:00
|
|
|
* Helper classes for guaranteeing cleaning mCurrentKeyEvent
|
2011-02-23 21:06:26 +03:00
|
|
|
*/
|
|
|
|
class AutoKeyEventStateCleaner
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:33:13 +04:00
|
|
|
explicit AutoKeyEventStateCleaner(TextInputHandlerBase* aHandler) :
|
2011-02-23 21:06:26 +03:00
|
|
|
mHandler(aHandler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoKeyEventStateCleaner()
|
|
|
|
{
|
2011-10-05 06:19:24 +04:00
|
|
|
mHandler->RemoveCurrentKeyEvent();
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextInputHandlerBase> mHandler;
|
2011-02-23 21:06:26 +03:00
|
|
|
};
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
class MOZ_STACK_CLASS AutoInsertStringClearer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoInsertStringClearer(KeyEventState* aState)
|
|
|
|
: mState(aState)
|
|
|
|
{
|
|
|
|
}
|
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
|
|
|
~AutoInsertStringClearer();
|
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
private:
|
|
|
|
KeyEventState* mState;
|
|
|
|
};
|
|
|
|
|
2011-10-05 06:19:24 +04:00
|
|
|
/**
|
|
|
|
* mCurrentKeyEvents stores all key events which are being processed.
|
|
|
|
* When we call interpretKeyEvents, IME may generate other key events.
|
|
|
|
* mCurrentKeyEvents[0] is the latest key event.
|
|
|
|
*/
|
|
|
|
nsTArray<KeyEventState*> mCurrentKeyEvents;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mFirstKeyEvent must be used for first key event. This member prevents
|
|
|
|
* memory fragmentation for most key events.
|
|
|
|
*/
|
|
|
|
KeyEventState mFirstKeyEvent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PushKeyEvent() adds the current key event to mCurrentKeyEvents.
|
|
|
|
*/
|
2017-05-16 05:59:35 +03:00
|
|
|
KeyEventState* PushKeyEvent(NSEvent* aNativeKeyEvent, uint32_t aUniqueId = 0)
|
2011-10-05 06:19:24 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nestCount = mCurrentKeyEvents.Length();
|
|
|
|
for (uint32_t i = 0; i < nestCount; i++) {
|
2011-10-05 06:19:24 +04:00
|
|
|
// When the key event is caused by another key event, all key events
|
|
|
|
// which are being handled should be marked as "consumed".
|
|
|
|
mCurrentKeyEvents[i]->mCausedOtherKeyEvents = true;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
KeyEventState* keyEvent = nullptr;
|
2011-10-05 06:19:24 +04:00
|
|
|
if (nestCount == 0) {
|
2017-05-16 05:59:35 +03:00
|
|
|
mFirstKeyEvent.Set(aNativeKeyEvent, aUniqueId);
|
2011-10-05 06:19:24 +04:00
|
|
|
keyEvent = &mFirstKeyEvent;
|
|
|
|
} else {
|
2017-05-16 05:59:35 +03:00
|
|
|
keyEvent = new KeyEventState(aNativeKeyEvent, aUniqueId);
|
2011-10-05 06:19:24 +04:00
|
|
|
}
|
|
|
|
return *mCurrentKeyEvents.AppendElement(keyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RemoveCurrentKeyEvent() removes the current key event from
|
|
|
|
* mCurrentKeyEvents.
|
|
|
|
*/
|
|
|
|
void RemoveCurrentKeyEvent()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentKeyEvents.Length() > 0,
|
|
|
|
"RemoveCurrentKeyEvent() is called unexpectedly");
|
2018-03-13 16:51:33 +03:00
|
|
|
KeyEventState* keyEvent = mCurrentKeyEvents.PopLastElement();
|
2011-10-05 06:19:24 +04:00
|
|
|
if (keyEvent == &mFirstKeyEvent) {
|
|
|
|
keyEvent->Clear();
|
|
|
|
} else {
|
|
|
|
delete keyEvent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetCurrentKeyEvent() returns current processing key event.
|
|
|
|
*/
|
|
|
|
KeyEventState* GetCurrentKeyEvent()
|
|
|
|
{
|
|
|
|
if (mCurrentKeyEvents.Length() == 0) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-10-05 06:19:24 +04:00
|
|
|
}
|
|
|
|
return mCurrentKeyEvents[mCurrentKeyEvents.Length() - 1];
|
|
|
|
}
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2016-03-16 07:47:50 +03:00
|
|
|
struct KeyboardLayoutOverride final
|
|
|
|
{
|
|
|
|
int32_t mKeyboardLayout;
|
|
|
|
bool mOverrideEnabled;
|
|
|
|
|
|
|
|
KeyboardLayoutOverride() :
|
|
|
|
mKeyboardLayout(0), mOverrideEnabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const KeyboardLayoutOverride& KeyboardLayoutOverrideRef() const
|
|
|
|
{
|
|
|
|
return mKeyboardOverride;
|
|
|
|
}
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
/**
|
|
|
|
* IsPrintableChar() checks whether the unicode character is
|
|
|
|
* a non-printable ASCII character or not. Note that this returns
|
|
|
|
* TRUE even if aChar is a non-printable UNICODE character.
|
|
|
|
*
|
|
|
|
* @param aChar A unicode character.
|
|
|
|
* @return TRUE if aChar is a printable ASCII character
|
|
|
|
* or a unicode character. Otherwise, i.e,
|
|
|
|
* if aChar is a non-printable ASCII character,
|
|
|
|
* FALSE.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool IsPrintableChar(char16_t aChar);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsNormalCharInputtingEvent() checks whether aKeyEvent causes text input.
|
|
|
|
*
|
|
|
|
* @param aKeyEvent A key event.
|
|
|
|
* @return TRUE if the key event causes text input.
|
|
|
|
* Otherwise, FALSE.
|
|
|
|
*/
|
2013-10-01 11:22:58 +04:00
|
|
|
static bool IsNormalCharInputtingEvent(const WidgetKeyboardEvent& aKeyEvent);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IsModifierKey() checks whether the native keyCode is for a modifier key.
|
|
|
|
*
|
|
|
|
* @param aNativeKeyCode A native keyCode.
|
|
|
|
* @return TRUE if aNativeKeyCode is for a modifier key.
|
|
|
|
* Otherwise, FALSE.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsModifierKey(UInt32 aNativeKeyCode);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2011-02-23 20:25:11 +03:00
|
|
|
private:
|
|
|
|
KeyboardLayoutOverride mKeyboardOverride;
|
2013-05-24 20:27:52 +04:00
|
|
|
|
|
|
|
static int32_t sSecureEventInputCount;
|
2011-05-08 14:19:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IMEInputHandler manages:
|
2009-10-01 06:52:50 +04:00
|
|
|
* 1. The IME/keyboard layout statement of nsChildView.
|
|
|
|
* 2. The IME composition statement of nsChildView.
|
|
|
|
* And also provides the methods which controls the current IME transaction of
|
|
|
|
* the instance.
|
|
|
|
*
|
|
|
|
* Note that an nsChildView handles one or more NSView's events. E.g., even if
|
|
|
|
* a text editor on XUL panel element, the input events handled on the parent
|
|
|
|
* (or its ancestor) widget handles it (the native focus is set to it). The
|
|
|
|
* actual focused view is notified by OnFocusChangeInGecko.
|
|
|
|
*/
|
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
class IMEInputHandler : public TextInputHandlerBase
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-03-16 07:47:49 +03:00
|
|
|
// TextEventDispatcherListener methods
|
|
|
|
NS_IMETHOD NotifyIME(TextEventDispatcher* aTextEventDispatcher,
|
|
|
|
const IMENotification& aNotification) override;
|
2017-04-11 15:24:55 +03:00
|
|
|
NS_IMETHOD_(IMENotificationRequests) GetIMENotificationRequests() override;
|
2016-03-16 07:47:49 +03:00
|
|
|
NS_IMETHOD_(void) OnRemovedFrom(
|
|
|
|
TextEventDispatcher* aTextEventDispatcher) override;
|
|
|
|
NS_IMETHOD_(void) WillDispatchKeyboardEvent(
|
|
|
|
TextEventDispatcher* aTextEventDispatcher,
|
|
|
|
WidgetKeyboardEvent& aKeyboardEvent,
|
|
|
|
uint32_t aIndexOfKeypress,
|
|
|
|
void* aData) override;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool OnDestroyWidget(nsChildView* aDestroyingWidget) override;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual void OnFocusChangeInGecko(bool aFocus);
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2015-07-21 15:47:54 +03:00
|
|
|
void OnSelectionChange(const IMENotification& aIMENotification);
|
2017-06-29 10:03:57 +03:00
|
|
|
void OnLayoutChange();
|
2013-07-11 11:46:35 +04:00
|
|
|
|
2016-04-27 15:14:43 +03:00
|
|
|
/**
|
|
|
|
* Call [NSTextInputContext handleEvent] for mouse event support of IME
|
|
|
|
*/
|
|
|
|
bool OnHandleEvent(NSEvent* aEvent);
|
|
|
|
|
2011-02-19 07:55:34 +03:00
|
|
|
/**
|
|
|
|
* SetMarkedText() is a handler of setMarkedText of NSTextInput.
|
|
|
|
*
|
|
|
|
* @param aAttrString This mut be an instance of NSAttributedString.
|
|
|
|
* If the aString parameter to
|
|
|
|
* [ChildView setMarkedText:setSelectedRange:]
|
|
|
|
* isn't an instance of NSAttributedString,
|
|
|
|
* create an NSAttributedString from it and pass
|
|
|
|
* that instead.
|
|
|
|
* @param aSelectedRange Current selected range (or caret position).
|
2013-07-11 11:46:36 +04:00
|
|
|
* @param aReplacementRange The range which will be replaced with the
|
|
|
|
* aAttrString instead of current marked range.
|
2011-02-19 07:55:34 +03:00
|
|
|
*/
|
|
|
|
void SetMarkedText(NSAttributedString* aAttrString,
|
2013-07-11 11:46:36 +04:00
|
|
|
NSRange& aSelectedRange,
|
|
|
|
NSRange* aReplacementRange = nullptr);
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
/**
|
|
|
|
* GetAttributedSubstringFromRange() returns an NSAttributedString instance
|
|
|
|
* which is allocated as autorelease for aRange.
|
|
|
|
*
|
|
|
|
* @param aRange The range of string which you want.
|
2013-07-11 11:46:35 +04:00
|
|
|
* @param aActualRange The actual range of the result.
|
2011-02-19 07:55:49 +03:00
|
|
|
* @return The string in aRange. If the string is empty,
|
|
|
|
* this returns nil. If succeeded, this returns
|
|
|
|
* an instance which is allocated as autorelease.
|
|
|
|
* If this has some troubles, returns nil.
|
|
|
|
*/
|
2013-07-11 11:46:35 +04:00
|
|
|
NSAttributedString* GetAttributedSubstringFromRange(
|
|
|
|
NSRange& aRange,
|
|
|
|
NSRange* aActualRange = nullptr);
|
2011-02-19 07:55:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SelectedRange() returns current selected range.
|
|
|
|
*
|
|
|
|
* @return If an editor has focus, this returns selection
|
|
|
|
* range in the editor. Otherwise, this returns
|
|
|
|
* selection range in the focused document.
|
|
|
|
*/
|
|
|
|
NSRange SelectedRange();
|
|
|
|
|
2015-02-10 18:28:05 +03:00
|
|
|
/**
|
|
|
|
* DrawsVerticallyForCharacterAtIndex() returns whether the character at
|
|
|
|
* the given index is being rendered vertically.
|
|
|
|
*
|
|
|
|
* @param aCharIndex The character offset to query.
|
|
|
|
*
|
|
|
|
* @return True if writing-mode is vertical at the given
|
|
|
|
* character offset; otherwise false.
|
|
|
|
*/
|
|
|
|
bool DrawsVerticallyForCharacterAtIndex(uint32_t aCharIndex);
|
|
|
|
|
2011-02-19 07:55:49 +03:00
|
|
|
/**
|
|
|
|
* FirstRectForCharacterRange() returns first *character* rect in the range.
|
|
|
|
* Cocoa needs the first line rect in the range, but we cannot compute it
|
|
|
|
* on current implementation.
|
|
|
|
*
|
|
|
|
* @param aRange A range of text to examine. Its position is
|
|
|
|
* an offset from the beginning of the focused
|
|
|
|
* editor or document.
|
2013-07-11 11:46:35 +04:00
|
|
|
* @param aActualRange If this is not null, this returns the actual
|
|
|
|
* range used for computing the result.
|
2011-02-19 07:55:49 +03:00
|
|
|
* @return An NSRect containing the first character in
|
|
|
|
* aRange, in screen coordinates.
|
|
|
|
* If the length of aRange is 0, the width will
|
|
|
|
* be 0.
|
|
|
|
*/
|
2013-07-11 11:46:35 +04:00
|
|
|
NSRect FirstRectForCharacterRange(NSRange& aRange,
|
|
|
|
NSRange* aActualRange = nullptr);
|
2011-02-19 07:55:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CharacterIndexForPoint() returns an offset of a character at aPoint.
|
|
|
|
* XXX This isn't implemented, always returns 0.
|
|
|
|
*
|
|
|
|
* @param The point in screen coordinates.
|
|
|
|
* @return The offset of the character at aPoint from
|
|
|
|
* the beginning of the focused editor or
|
|
|
|
* document.
|
|
|
|
*/
|
|
|
|
NSUInteger CharacterIndexForPoint(NSPoint& aPoint);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetValidAttributesForMarkedText() returns attributes which we support.
|
|
|
|
*
|
|
|
|
* @return Always empty array for now.
|
|
|
|
*/
|
|
|
|
NSArray* GetValidAttributesForMarkedText();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasMarkedText();
|
2011-07-21 04:33:16 +04:00
|
|
|
NSRange MarkedRange();
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsIMEComposing() { return mIsIMEComposing; }
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
bool IsDeadKeyComposing() { return mIsDeadKeyComposing; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsIMEOpened();
|
|
|
|
bool IsIMEEnabled() { return mIsIMEEnabled; }
|
|
|
|
bool IsASCIICapableOnly() { return mIsASCIICapableOnly; }
|
Bug 1464016 - TextInputHandler should not clear alt/ctrl/meta modifiers of eKeyPress event before sending TextEventDispatcher r=m_kato
If a key combination causes text input, we need to dispatch keypress
events without alt/ctrl/meta modifiers since TextEditor won't handle
keyepress events whose altKey, ctrlKey or metaKey is true as inputting
text.
Currently, TextEventDispatcher sets mCharCode of eKeyPress event from
mKeyValue. Then, when altKey, ctrlKey or metaKey is true, it'll call
WillDispatchKeyboardEvent() and then, TextInputHandler needs to reset
the charCode value from native event information.
However, the problem is, TextInputHandler::InsertText() is called
with control character when control key is pressed and InsertText()
clears the modifier information before sending eKeyPress event to
TextEvenDispatcher so that TextEventDispatcher won't call
WillDispatchKeyboardEvent() even though control key is actually
pressed. Therefore, TextInputHandler cannot adjust charCode value
and modifier flags in some cases such as control + option + 'a'.
This patch makes InsertText() stop clearing the modifiers and
makes WillDispatchKeyboardEvent() do it instead. This procedure
is expected by TextEventDispatcher.
MozReview-Commit-ID: Ig6qgRBeQDh
--HG--
extra : rebase_source : 446e8af0e921946f3409d26ede70446248317673
2018-05-24 14:59:48 +03:00
|
|
|
bool IsEditableContent() const
|
|
|
|
{
|
|
|
|
return mIsIMEEnabled || mIsASCIICapableOnly;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IgnoreIMECommit() { return mIgnoreIMECommit; }
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
void CommitIMEComposition();
|
|
|
|
void CancelIMEComposition();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void EnableIME(bool aEnableIME);
|
|
|
|
void SetIMEOpenState(bool aOpen);
|
|
|
|
void SetASCIICapableOnly(bool aASCIICapableOnly);
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2015-01-12 19:26:05 +03:00
|
|
|
/**
|
|
|
|
* True if OSX believes that our view has keyboard focus.
|
|
|
|
*/
|
2013-07-17 06:08:44 +04:00
|
|
|
bool IsFocused();
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
static CFArrayRef CreateAllIMEModeList();
|
2011-07-21 04:33:16 +04:00
|
|
|
static void DebugPrintAllIMEModes();
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2010-08-16 12:20:27 +04:00
|
|
|
// Don't use ::TSMGetActiveDocument() API directly, the document may not
|
|
|
|
// be what you want.
|
|
|
|
static TSMDocumentID GetCurrentTSMDocumentID();
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
protected:
|
|
|
|
// We cannot do some jobs in the given stack by some reasons.
|
|
|
|
// Following flags and the timer provide the execution pending mechanism,
|
|
|
|
// See the comment in nsCocoaTextInputHandler.mm.
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
enum {
|
2013-07-11 11:46:36 +04:00
|
|
|
kNotifyIMEOfFocusChangeInGecko = 1,
|
Bug 1388647 - part2: Make IMEInputHandler of Cocoa widget handle request to commit/cancel composition synchronously r=m_kato
When Gecko started to support Cocoa widget, we needed to use NSInputManager.
That allowed applications to access only focused IME context. Therefore, commit
composition request handler for Cocoa is designed as handling asynchronosly if
it's requested when the window is not active or is being inactivated.
Additionally, the asynchronous handling isn't perfect. We hit some MOZ_ASSERT()
now in some places. E.g., in SelectedRange(), it doesn't assume that it's
called during deactive.
On the other hand, NSInputManager was alreay obsolete and we already stopped using it
(bug 810225). Instead, we're using NSTextInputContext and it allows applications
to access IME anytime. Therefore, if we make IMEInputHandler handles commit/cancel
composition requests synchronsly, that behaves same as the other platforms. So, we
can get rid of macOS specific issue completely.
MozReview-Commit-ID: X7aWmGq95x
--HG--
extra : rebase_source : a472a03e3ef6f424fe73c2d438b8326bed80278d
2017-08-09 12:41:19 +03:00
|
|
|
kSyncASCIICapableOnly = 2
|
2009-10-01 06:52:50 +04:00
|
|
|
};
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mPendingMethods;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
IMEInputHandler(nsChildView* aWidget, NSView<mozView> *aNativeView);
|
2011-05-08 14:19:15 +04:00
|
|
|
virtual ~IMEInputHandler();
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
void ResetTimer();
|
|
|
|
|
|
|
|
virtual void ExecutePendingMethods();
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
/**
|
|
|
|
* InsertTextAsCommittingComposition() commits current composition. If there
|
|
|
|
* is no composition, this starts a composition and commits it immediately.
|
|
|
|
*
|
|
|
|
* @param aAttrString A string which is committed.
|
2013-07-11 11:46:35 +04:00
|
|
|
* @param aReplacementRange The range which will be replaced with the
|
|
|
|
* aAttrString instead of current selection.
|
2011-02-23 21:06:26 +03:00
|
|
|
*/
|
2013-07-11 11:46:35 +04:00
|
|
|
void InsertTextAsCommittingComposition(NSAttributedString* aAttrString,
|
|
|
|
NSRange* aReplacementRange);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
/**
|
|
|
|
* MaybeDispatchCurrentKeydownEvent() dispatches eKeyDown event for current
|
|
|
|
* key event. If eKeyDown for current key event has already been dispatched,
|
|
|
|
* this does nothing.
|
|
|
|
*
|
|
|
|
* @param aIsProcessedByIME true if current key event is handled by IME.
|
|
|
|
* @return true if the caller can continue to handle
|
|
|
|
* current key event. Otherwise, false. E.g.,
|
|
|
|
* focus is moved, the widget has been destroyed
|
|
|
|
* or something.
|
|
|
|
*/
|
|
|
|
bool MaybeDispatchCurrentKeydownEvent(bool aIsProcessedByIME);
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
private:
|
|
|
|
// If mIsIMEComposing is true, the composition string is stored here.
|
|
|
|
NSString* mIMECompositionString;
|
2015-09-19 05:01:57 +03:00
|
|
|
// If mIsIMEComposing is true, the start offset of the composition string.
|
|
|
|
uint32_t mIMECompositionStart;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-02-19 07:55:34 +03:00
|
|
|
NSRange mMarkedRange;
|
2013-07-11 11:46:35 +04:00
|
|
|
NSRange mSelectedRange;
|
2011-02-19 07:55:34 +03:00
|
|
|
|
2015-02-10 18:28:05 +03:00
|
|
|
NSRange mRangeForWritingMode; // range within which mWritingMode applies
|
|
|
|
mozilla::WritingMode mWritingMode;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsIMEComposing;
|
Bug 1343451 - part 4: Make TextInputHandler dispatches eKeyDown event with marking it as "processed by IME" r=m_kato
First of all, TextInputHandler::HandleKeyDown() dispatches an eKeyDown event
before sending IME. This is different behavior from Gecko on the other
platforms and it means TextInputHandler does not know if the eKeyDown event
will be handled by IME. Therefore, we need to make TextInputHandler dispatch
an eKeyDown event dispatch when it needs to dispatch another event. Therefore,
this patch makes TextInputHandler not dispatch an eKeyDown even from
its HandleKeyDown() unless it's already has composition (because if it's
already had composition, any eKeyDown event except modifier keys should be
marked as "processed by IME" for compatibility with the other browsers).
For dispatching eKeyDown event only once for a native keydown event,
this patch implements TextInputHandlerBase::MaybeDispatchCurrentKeydownEvent()
to check whether eKeyDown event has already been dispatched for the event
and if it's not so, dispatches eKeyDown event.
Note that on macOS, dead keys are implemented as IME. However, we need to
treat dead keys as is. Therefore, if current keydown event is a dead keydown
event, MaybeDispatchCurrentKeydownEvent() should NOT mark dispatching
eKeyDown event and its following eKeyDown event as "processed by IME".
MozReview-Commit-ID: 7epk8wdAznd
--HG--
extra : rebase_source : 0ed30ff3e108170fd96eabe626e0530473f2f3b1
2018-02-23 17:09:43 +03:00
|
|
|
// If the composition started with dead key, mIsDeadKeyComposing is set to
|
|
|
|
// true.
|
|
|
|
bool mIsDeadKeyComposing;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsIMEEnabled;
|
|
|
|
bool mIsASCIICapableOnly;
|
|
|
|
bool mIgnoreIMECommit;
|
2013-07-11 11:46:35 +04:00
|
|
|
bool mIMEHasFocus;
|
2009-10-01 06:52:50 +04:00
|
|
|
|
|
|
|
void KillIMEComposition();
|
|
|
|
void SendCommittedText(NSString *aString);
|
|
|
|
void OpenSystemPreferredLanguageIME();
|
|
|
|
|
|
|
|
// Pending methods
|
2013-07-11 11:46:36 +04:00
|
|
|
void NotifyIMEOfFocusChangeInGecko();
|
2009-10-01 06:52:50 +04:00
|
|
|
void SyncASCIICapableOnly();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool sStaticMembersInitialized;
|
2009-10-01 06:52:50 +04:00
|
|
|
static CFStringRef sLatestIMEOpenedModeInputSourceID;
|
|
|
|
static void InitStaticMembers();
|
|
|
|
static void OnCurrentTextInputSourceChange(CFNotificationCenterRef aCenter,
|
|
|
|
void* aObserver,
|
|
|
|
CFStringRef aName,
|
|
|
|
const void* aObject,
|
|
|
|
CFDictionaryRef aUserInfo);
|
|
|
|
|
|
|
|
static void FlushPendingMethods(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2011-02-17 10:41:36 +03:00
|
|
|
/**
|
|
|
|
* ConvertToTextRangeStyle converts the given native underline style to
|
|
|
|
* our defined text range type.
|
|
|
|
*
|
|
|
|
* @param aUnderlineStyle NSUnderlineStyleSingle or
|
|
|
|
* NSUnderlineStyleThick.
|
|
|
|
* @param aSelectedRange Current selected range (or caret position).
|
|
|
|
* @return NS_TEXTRANGE_*.
|
|
|
|
*/
|
2016-06-04 03:49:21 +03:00
|
|
|
TextRangeType ConvertToTextRangeType(uint32_t aUnderlineStyle,
|
|
|
|
NSRange& aSelectedRange);
|
2011-02-17 10:41:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GetRangeCount() computes the range count of aAttrString.
|
|
|
|
*
|
|
|
|
* @param aAttrString An NSAttributedString instance whose number of
|
|
|
|
* NSUnderlineStyleAttributeName ranges you with
|
|
|
|
* to know.
|
|
|
|
* @return The count of NSUnderlineStyleAttributeName
|
|
|
|
* ranges in aAttrString.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetRangeCount(NSAttributedString *aString);
|
2011-02-17 10:41:36 +03:00
|
|
|
|
|
|
|
/**
|
2014-03-04 17:48:27 +04:00
|
|
|
* CreateTextRangeArray() returns text ranges for clauses and/or caret.
|
2011-02-17 10:41:36 +03:00
|
|
|
*
|
|
|
|
* @param aAttrString An NSAttributedString instance which indicates
|
|
|
|
* current composition string.
|
|
|
|
* @param aSelectedRange Current selected range (or caret position).
|
2014-03-04 17:48:27 +04:00
|
|
|
* @return The result is set to the
|
|
|
|
* NSUnderlineStyleAttributeName ranges in
|
|
|
|
* aAttrString.
|
2011-02-17 10:41:36 +03:00
|
|
|
*/
|
2014-03-04 17:48:27 +04:00
|
|
|
already_AddRefed<mozilla::TextRangeArray>
|
|
|
|
CreateTextRangeArray(NSAttributedString *aAttrString,
|
|
|
|
NSRange& aSelectedRange);
|
2011-02-17 10:41:36 +03:00
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
/**
|
|
|
|
* DispatchCompositionStartEvent() dispatches a compositionstart event and
|
|
|
|
* initializes the members indicating composition state.
|
|
|
|
*
|
|
|
|
* @return true if it can continues handling composition.
|
|
|
|
* Otherwise, e.g., canceled by the web page,
|
|
|
|
* this returns false.
|
|
|
|
*/
|
|
|
|
bool DispatchCompositionStartEvent();
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
/**
|
|
|
|
* DispatchCompositionChangeEvent() dispatches a compositionchange event on
|
|
|
|
* mWidget and modifies the members indicating composition state.
|
|
|
|
*
|
|
|
|
* @param aText User text input.
|
|
|
|
* @param aAttrString An NSAttributedString instance which indicates
|
|
|
|
* current composition string.
|
|
|
|
* @param aSelectedRange Current selected range (or caret position).
|
|
|
|
*
|
|
|
|
* @return true if it can continues handling composition.
|
|
|
|
* Otherwise, e.g., canceled by the web page,
|
|
|
|
* this returns false.
|
|
|
|
*/
|
|
|
|
bool DispatchCompositionChangeEvent(const nsString& aText,
|
|
|
|
NSAttributedString* aAttrString,
|
|
|
|
NSRange& aSelectedRange);
|
|
|
|
|
2015-09-19 05:01:57 +03:00
|
|
|
/**
|
|
|
|
* DispatchCompositionCommitEvent() dispatches a compositioncommit event or
|
|
|
|
* compositioncommitasis event. If aCommitString is null, dispatches
|
|
|
|
* compositioncommitasis event. I.e., if aCommitString is null, this
|
|
|
|
* commits the composition with the last data. Otherwise, commits the
|
|
|
|
* composition with aCommitString value.
|
|
|
|
*
|
|
|
|
* @return true if the widget isn't destroyed.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool DispatchCompositionCommitEvent(const nsAString* aCommitString = nullptr);
|
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
// The focused IME handler. Please note that the handler might lost the
|
|
|
|
// actual focus by deactivating the application. If we are active, this
|
|
|
|
// must have the actual focused handle.
|
|
|
|
// We cannot access to the NSInputManager during we aren't active, so, the
|
|
|
|
// focused handler can have an IME transaction even if we are deactive.
|
2011-05-08 14:19:15 +04:00
|
|
|
static IMEInputHandler* sFocusedIMEHandler;
|
2015-04-11 01:18:05 +03:00
|
|
|
|
|
|
|
static bool sCachedIsForRTLLangage;
|
2009-10-01 06:52:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2011-05-08 14:19:15 +04:00
|
|
|
* TextInputHandler implements the NSTextInput protocol.
|
2009-10-01 06:52:50 +04:00
|
|
|
*/
|
2011-05-08 14:19:15 +04:00
|
|
|
class TextInputHandler : public IMEInputHandler
|
2009-10-01 06:52:50 +04:00
|
|
|
{
|
|
|
|
public:
|
2011-08-02 05:20:52 +04:00
|
|
|
static NSUInteger sLastModifierState;
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2009-10-01 06:52:50 +04:00
|
|
|
static CFArrayRef CreateAllKeyboardLayoutList();
|
2011-07-21 04:33:16 +04:00
|
|
|
static void DebugPrintAllKeyboardLayouts();
|
2009-10-01 06:52:50 +04:00
|
|
|
|
2011-05-08 14:19:23 +04:00
|
|
|
TextInputHandler(nsChildView* aWidget, NSView<mozView> *aNativeView);
|
2011-05-08 14:19:15 +04:00
|
|
|
virtual ~TextInputHandler();
|
2011-02-23 21:06:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* KeyDown event handler.
|
|
|
|
*
|
2011-07-21 04:33:16 +04:00
|
|
|
* @param aNativeEvent A native NSKeyDown event.
|
2017-05-16 05:59:35 +03:00
|
|
|
* @param aUniqueId A unique ID for the event.
|
|
|
|
* @return TRUE if the event is dispatched to web
|
|
|
|
* contents or chrome contents. Otherwise, FALSE.
|
2011-02-23 21:06:26 +03:00
|
|
|
*/
|
2017-05-16 05:59:35 +03:00
|
|
|
bool HandleKeyDownEvent(NSEvent* aNativeEvent, uint32_t aUniqueId);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
/**
|
|
|
|
* KeyUp event handler.
|
|
|
|
*
|
|
|
|
* @param aNativeEvent A native NSKeyUp event.
|
|
|
|
*/
|
|
|
|
void HandleKeyUpEvent(NSEvent* aNativeEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FlagsChanged event handler.
|
|
|
|
*
|
|
|
|
* @param aNativeEvent A native NSFlagsChanged event.
|
|
|
|
*/
|
|
|
|
void HandleFlagsChanged(NSEvent* aNativeEvent);
|
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
/**
|
|
|
|
* Insert the string to content. I.e., this is a text input event handler.
|
|
|
|
* If this is called during keydown event handling, this may dispatch a
|
2015-08-29 02:58:27 +03:00
|
|
|
* eKeyPress event. If this is called during composition, this commits
|
2011-02-23 21:06:26 +03:00
|
|
|
* the composition by the aAttrString.
|
|
|
|
*
|
|
|
|
* @param aAttrString An inserted string.
|
2013-07-11 11:46:35 +04:00
|
|
|
* @param aReplacementRange The range which will be replaced with the
|
|
|
|
* aAttrString instead of current selection.
|
2011-02-23 21:06:26 +03:00
|
|
|
*/
|
2013-07-11 11:46:35 +04:00
|
|
|
void InsertText(NSAttributedString *aAttrString,
|
|
|
|
NSRange* aReplacementRange = nullptr);
|
2011-02-23 21:06:26 +03:00
|
|
|
|
2017-04-27 15:44:58 +03:00
|
|
|
/**
|
2017-12-02 04:46:31 +03:00
|
|
|
* Handles aCommand. This may cause dispatching an eKeyPress event.
|
Bug 1403759 - part 2: Handle edit/selection commands like insertNewline: in TextInputHandler::HandleCommand() r=m_kato
Let's make TextInputHandler::HandleCommand() handle other
commands which are caused by Backspace, Delete, Tab, ArrowUp,
ArrowDown, ArrowRight, ArrowLeft, PageUp, PageDown, Home, End
and Escape keys with various modifiers.
This patch makes Korean users can do most key operation in
editor even with composing Hangul character.
Note that this patch has a hack for cancelOperation: command.
The command is typically fired for Escape key press. However,
it's also fired for Command + Period. Unfortunately, this
behavior is really odd if subclass of NSResponder implements
|void cancelOperation:(id)sender|. If it's implemented,
Cocoa doesn't call its |void keyDown:(NSEvent)theEvent|.
Instead, it calls only |void doCommandBySelector:(SEL)aSelector|
and |void cancelOperation:(id)sender| when Command + Period is
pressed. Therefore, we cannot dispatch keydown nor keypress
event for this key combination if we implement it. Therefore,
this patch doesn't implement the method but handle it in
doCommandBySelector even though the super class of ChildView
cannot handle the command with this path.
MozReview-Commit-ID: 4hS23SiwNJv
--HG--
extra : rebase_source : 38ac1ea494b5f786ecd5c9327efbacd460b59faf
2017-12-02 08:53:10 +03:00
|
|
|
*
|
|
|
|
* @param aCommand The command which receives from Cocoa.
|
|
|
|
* @return true if this handles the command even if it does
|
|
|
|
* nothing actually. Otherwise, false.
|
2017-04-27 15:44:58 +03:00
|
|
|
*/
|
Bug 1403759 - part 2: Handle edit/selection commands like insertNewline: in TextInputHandler::HandleCommand() r=m_kato
Let's make TextInputHandler::HandleCommand() handle other
commands which are caused by Backspace, Delete, Tab, ArrowUp,
ArrowDown, ArrowRight, ArrowLeft, PageUp, PageDown, Home, End
and Escape keys with various modifiers.
This patch makes Korean users can do most key operation in
editor even with composing Hangul character.
Note that this patch has a hack for cancelOperation: command.
The command is typically fired for Escape key press. However,
it's also fired for Command + Period. Unfortunately, this
behavior is really odd if subclass of NSResponder implements
|void cancelOperation:(id)sender|. If it's implemented,
Cocoa doesn't call its |void keyDown:(NSEvent)theEvent|.
Instead, it calls only |void doCommandBySelector:(SEL)aSelector|
and |void cancelOperation:(id)sender| when Command + Period is
pressed. Therefore, we cannot dispatch keydown nor keypress
event for this key combination if we implement it. Therefore,
this patch doesn't implement the method but handle it in
doCommandBySelector even though the super class of ChildView
cannot handle the command with this path.
MozReview-Commit-ID: 4hS23SiwNJv
--HG--
extra : rebase_source : 38ac1ea494b5f786ecd5c9327efbacd460b59faf
2017-12-02 08:53:10 +03:00
|
|
|
bool HandleCommand(Command aCommand);
|
2017-04-27 15:44:58 +03:00
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
/**
|
|
|
|
* doCommandBySelector event handler.
|
|
|
|
*
|
|
|
|
* @param aSelector A selector of the command.
|
|
|
|
* @return TRUE if the command is consumed. Otherwise,
|
|
|
|
* FALSE.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool DoCommandBySelector(const char* aSelector);
|
2011-07-21 04:33:16 +04:00
|
|
|
|
2011-02-23 21:06:26 +03:00
|
|
|
/**
|
|
|
|
* KeyPressWasHandled() checks whether keypress event was handled or not.
|
|
|
|
*
|
|
|
|
* @return TRUE if keypress event for latest native key
|
|
|
|
* event was handled. Otherwise, FALSE.
|
|
|
|
* If this handler isn't handling any key events,
|
|
|
|
* always returns FALSE.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool KeyPressWasHandled()
|
2011-02-23 21:06:26 +03:00
|
|
|
{
|
2011-10-05 06:19:24 +04:00
|
|
|
KeyEventState* currentKeyEvent = GetCurrentKeyEvent();
|
|
|
|
return currentKeyEvent && currentKeyEvent->mKeyPressHandled;
|
2011-02-23 21:06:26 +03:00
|
|
|
}
|
2011-07-21 04:33:16 +04:00
|
|
|
|
|
|
|
protected:
|
2012-10-19 05:17:07 +04:00
|
|
|
// Stores the association of device dependent modifier flags with a modifier
|
|
|
|
// keyCode. Being device dependent, this association may differ from one kind
|
|
|
|
// of hardware to the next.
|
|
|
|
struct ModifierKey
|
|
|
|
{
|
|
|
|
NSUInteger flags;
|
|
|
|
unsigned short keyCode;
|
|
|
|
|
|
|
|
ModifierKey(NSUInteger aFlags, unsigned short aKeyCode) :
|
|
|
|
flags(aFlags), keyCode(aKeyCode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NSUInteger GetDeviceDependentFlags() const
|
|
|
|
{
|
|
|
|
return (flags & ~NSDeviceIndependentModifierFlagsMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSUInteger GetDeviceIndependentFlags() const
|
|
|
|
{
|
|
|
|
return (flags & NSDeviceIndependentModifierFlagsMask);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
typedef nsTArray<ModifierKey> ModifierKeyArray;
|
|
|
|
ModifierKeyArray mModifierKeys;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetModifierKeyForNativeKeyCode() returns the stored ModifierKey for
|
|
|
|
* the key.
|
|
|
|
*/
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey*
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForNativeKeyCode(unsigned short aKeyCode) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetModifierKeyForDeviceDependentFlags() returns the stored ModifierKey for
|
|
|
|
* the device dependent flags.
|
|
|
|
*/
|
2013-08-29 08:26:43 +04:00
|
|
|
const ModifierKey*
|
2012-10-19 05:17:07 +04:00
|
|
|
GetModifierKeyForDeviceDependentFlags(NSUInteger aFlags) const;
|
|
|
|
|
2011-07-21 04:33:16 +04:00
|
|
|
/**
|
|
|
|
* DispatchKeyEventForFlagsChanged() dispatches keydown event or keyup event
|
|
|
|
* for the aNativeEvent.
|
|
|
|
*
|
|
|
|
* @param aNativeEvent A native flagschanged event which you want to
|
|
|
|
* dispatch our key event for.
|
|
|
|
* @param aDispatchKeyDown TRUE if you want to dispatch a keydown event.
|
|
|
|
* Otherwise, i.e., to dispatch keyup event,
|
|
|
|
* FALSE.
|
|
|
|
*/
|
|
|
|
void DispatchKeyEventForFlagsChanged(NSEvent* aNativeEvent,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDispatchKeyDown);
|
2009-10-01 06:52:50 +04:00
|
|
|
};
|
|
|
|
|
2011-05-08 14:19:15 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // TextInputHandler_h_
|