2015-01-28 09:27:30 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-02-19 09:50:18 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-08-26 23:25:42 +03:00
|
|
|
#include "mozilla/StaticPrefs_dom.h"
|
2015-01-28 09:27:30 +03:00
|
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
#include "mozilla/TextEventDispatcher.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsView.h"
|
2017-07-25 17:27:31 +03:00
|
|
|
#include "PuppetWidget.h"
|
2015-01-28 09:27:30 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* TextEventDispatcher
|
|
|
|
*****************************************************************************/
|
|
|
|
TextEventDispatcher::TextEventDispatcher(nsIWidget* aWidget)
|
|
|
|
: mWidget(aWidget),
|
2015-02-19 09:50:20 +03:00
|
|
|
mDispatchingEvent(0),
|
2016-03-16 07:47:47 +03:00
|
|
|
mInputTransactionType(eNoInputTransaction),
|
2015-01-28 09:27:31 +03:00
|
|
|
mIsComposing(false),
|
2018-01-12 05:31:53 +03:00
|
|
|
mIsHandlingComposition(false),
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
mHasFocus(false) {
|
2015-01-28 09:27:30 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mWidget, "aWidget must not be nullptr");
|
2015-02-19 09:50:18 +03:00
|
|
|
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
ClearNotificationRequests();
|
2015-01-28 09:27:30 +03:00
|
|
|
}
|
|
|
|
|
2015-02-10 11:09:29 +03:00
|
|
|
nsresult TextEventDispatcher::BeginInputTransaction(
|
|
|
|
TextEventDispatcherListener* aListener) {
|
2016-03-16 07:47:48 +03:00
|
|
|
return BeginInputTransactionInternal(aListener,
|
|
|
|
eSameProcessSyncInputTransaction);
|
2015-01-28 09:27:30 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:47 +03:00
|
|
|
nsresult TextEventDispatcher::BeginTestInputTransaction(
|
2016-03-16 07:47:48 +03:00
|
|
|
TextEventDispatcherListener* aListener, bool aIsAPZAware) {
|
|
|
|
return BeginInputTransactionInternal(
|
|
|
|
aListener, aIsAPZAware ? eAsyncTestInputTransaction
|
|
|
|
: eSameProcessSyncTestInputTransaction);
|
2016-03-16 07:47:47 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:47 +03:00
|
|
|
nsresult TextEventDispatcher::BeginNativeInputTransaction() {
|
|
|
|
if (NS_WARN_IF(!mWidget)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
RefPtr<TextEventDispatcherListener> listener =
|
|
|
|
mWidget->GetNativeTextEventDispatcherListener();
|
|
|
|
if (NS_WARN_IF(!listener)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return BeginInputTransactionInternal(listener, eNativeInputTransaction);
|
2015-01-28 09:27:32 +03:00
|
|
|
}
|
|
|
|
|
2015-02-10 11:09:29 +03:00
|
|
|
nsresult TextEventDispatcher::BeginInputTransactionInternal(
|
|
|
|
TextEventDispatcherListener* aListener, InputTransactionType aType) {
|
2015-01-28 09:27:32 +03:00
|
|
|
if (NS_WARN_IF(!aListener)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
|
|
|
|
if (listener) {
|
2016-03-16 07:47:47 +03:00
|
|
|
if (listener == aListener && mInputTransactionType == aType) {
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
UpdateNotificationRequests();
|
2015-01-28 09:27:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-02-19 09:50:20 +03:00
|
|
|
// If this has composition or is dispatching an event, any other listener
|
2015-02-19 09:50:21 +03:00
|
|
|
// can steal ownership. Especially, if the latter case is allowed,
|
|
|
|
// nobody cannot begin input transaction with this if a modal dialog is
|
|
|
|
// opened during dispatching an event.
|
|
|
|
if (IsComposing() || IsDispatchingEvent()) {
|
2015-01-28 09:27:32 +03:00
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mListener = do_GetWeakReference(aListener);
|
2016-03-16 07:47:47 +03:00
|
|
|
mInputTransactionType = aType;
|
2015-01-28 09:27:32 +03:00
|
|
|
if (listener && listener != aListener) {
|
|
|
|
listener->OnRemovedFrom(this);
|
2015-01-28 09:27:30 +03:00
|
|
|
}
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
UpdateNotificationRequests();
|
2015-01-28 09:27:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:27:31 +03:00
|
|
|
nsresult TextEventDispatcher::BeginInputTransactionFor(
|
|
|
|
const WidgetGUIEvent* aEvent, PuppetWidget* aPuppetWidget) {
|
|
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
|
|
|
MOZ_ASSERT(!IsDispatchingEvent());
|
|
|
|
|
|
|
|
switch (aEvent->mMessage) {
|
|
|
|
case eKeyDown:
|
|
|
|
case eKeyPress:
|
|
|
|
case eKeyUp:
|
|
|
|
MOZ_ASSERT(aEvent->mClass == eKeyboardEventClass);
|
|
|
|
break;
|
|
|
|
case eCompositionStart:
|
|
|
|
case eCompositionChange:
|
|
|
|
case eCompositionCommit:
|
|
|
|
case eCompositionCommitAsIs:
|
|
|
|
MOZ_ASSERT(aEvent->mClass == eCompositionEventClass);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->mFlags.mIsSynthesizedForTests) {
|
|
|
|
// If the event is for an automated test and this instance dispatched
|
|
|
|
// an event to the parent process, we can assume that this is already
|
|
|
|
// initialized properly.
|
|
|
|
if (mInputTransactionType == eAsyncTestInputTransaction) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Even if the event coming from the parent process is synthesized for
|
|
|
|
// tests, this process should treat it as "sync" test here because
|
|
|
|
// it won't be go back to the parent process.
|
|
|
|
nsresult rv = BeginInputTransactionInternal(
|
|
|
|
static_cast<TextEventDispatcherListener*>(aPuppetWidget),
|
|
|
|
eSameProcessSyncTestInputTransaction);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsresult rv = BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emulate modifying members which indicate the state of composition.
|
|
|
|
// If we need to manage more states and/or more complexly, we should create
|
|
|
|
// internal methods which are called by both here and each event dispatcher
|
|
|
|
// method of this class.
|
|
|
|
switch (aEvent->mMessage) {
|
|
|
|
case eKeyDown:
|
|
|
|
case eKeyPress:
|
|
|
|
case eKeyUp:
|
|
|
|
return NS_OK;
|
|
|
|
case eCompositionStart:
|
|
|
|
MOZ_ASSERT(!mIsComposing);
|
2018-01-12 05:31:53 +03:00
|
|
|
mIsComposing = mIsHandlingComposition = true;
|
2017-07-25 17:27:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
case eCompositionChange:
|
|
|
|
MOZ_ASSERT(mIsComposing);
|
2018-01-12 05:31:53 +03:00
|
|
|
MOZ_ASSERT(mIsHandlingComposition);
|
|
|
|
mIsComposing = mIsHandlingComposition = true;
|
2017-07-25 17:27:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
case eCompositionCommit:
|
|
|
|
case eCompositionCommitAsIs:
|
|
|
|
MOZ_ASSERT(mIsComposing);
|
2018-01-12 05:31:53 +03:00
|
|
|
MOZ_ASSERT(mIsHandlingComposition);
|
2017-07-25 17:27:31 +03:00
|
|
|
mIsComposing = false;
|
2018-01-12 05:31:53 +03:00
|
|
|
mIsHandlingComposition = true;
|
2017-07-25 17:27:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("You forgot to handle the event");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
}
|
2015-06-11 06:53:42 +03:00
|
|
|
void TextEventDispatcher::EndInputTransaction(
|
|
|
|
TextEventDispatcherListener* aListener) {
|
|
|
|
if (NS_WARN_IF(IsComposing()) || NS_WARN_IF(IsDispatchingEvent())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:47 +03:00
|
|
|
mInputTransactionType = eNoInputTransaction;
|
|
|
|
|
2015-06-11 06:53:42 +03:00
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
|
|
|
|
if (NS_WARN_IF(!listener)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(listener != aListener)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mListener = nullptr;
|
|
|
|
listener->OnRemovedFrom(this);
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
UpdateNotificationRequests();
|
2015-06-11 06:53:42 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:30 +03:00
|
|
|
void TextEventDispatcher::OnDestroyWidget() {
|
|
|
|
mWidget = nullptr;
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
mHasFocus = false;
|
|
|
|
ClearNotificationRequests();
|
2015-01-28 09:27:30 +03:00
|
|
|
mPendingComposition.Clear();
|
2015-01-28 09:27:32 +03:00
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
|
|
|
|
mListener = nullptr;
|
2016-03-16 07:47:47 +03:00
|
|
|
mInputTransactionType = eNoInputTransaction;
|
2015-01-28 09:27:32 +03:00
|
|
|
if (listener) {
|
|
|
|
listener->OnRemovedFrom(this);
|
|
|
|
}
|
2015-01-28 09:27:30 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
nsresult TextEventDispatcher::GetState() const {
|
2015-01-28 09:27:32 +03:00
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
|
|
|
|
if (!listener) {
|
2015-01-28 09:27:31 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:18 +03:00
|
|
|
void TextEventDispatcher::InitEvent(WidgetGUIEvent& aEvent) const {
|
2016-03-28 07:29:42 +03:00
|
|
|
aEvent.mTime = PR_IntervalNow();
|
2016-04-18 17:09:02 +03:00
|
|
|
aEvent.mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2016-03-16 07:47:48 +03:00
|
|
|
aEvent.mFlags.mIsSynthesizedForTests = IsForTests();
|
2015-12-11 09:15:57 +03:00
|
|
|
if (aEvent.mClass != eCompositionEventClass) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-16 07:47:47 +03:00
|
|
|
void* pseudoIMEContext = GetPseudoIMEContext();
|
|
|
|
if (pseudoIMEContext) {
|
|
|
|
aEvent.AsCompositionEvent()->mNativeIMEContext.InitWithRawNativeIMEContext(
|
|
|
|
pseudoIMEContext);
|
2015-12-11 09:15:57 +03:00
|
|
|
}
|
2016-03-16 07:47:47 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
MOZ_ASSERT(!XRE_IsContentProcess(),
|
|
|
|
"Why did the content process start native event transaction?");
|
|
|
|
MOZ_ASSERT(aEvent.AsCompositionEvent()->mNativeIMEContext.IsValid(),
|
|
|
|
"Native IME context shouldn't be invalid");
|
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
2015-01-28 09:27:31 +03:00
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:20 +03:00
|
|
|
nsresult TextEventDispatcher::DispatchEvent(nsIWidget* aWidget,
|
|
|
|
WidgetGUIEvent& aEvent,
|
|
|
|
nsEventStatus& aStatus) {
|
2015-08-04 12:52:00 +03:00
|
|
|
MOZ_ASSERT(!aEvent.AsInputEvent(), "Use DispatchInputEvent()");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> kungFuDeathGrip(this);
|
2015-08-04 12:52:00 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget(aWidget);
|
|
|
|
mDispatchingEvent++;
|
|
|
|
nsresult rv = widget->DispatchEvent(&aEvent, aStatus);
|
|
|
|
mDispatchingEvent--;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult TextEventDispatcher::DispatchInputEvent(nsIWidget* aWidget,
|
|
|
|
WidgetInputEvent& aEvent,
|
2016-03-16 07:47:48 +03:00
|
|
|
nsEventStatus& aStatus) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> kungFuDeathGrip(this);
|
2015-02-19 09:50:20 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget(aWidget);
|
|
|
|
mDispatchingEvent++;
|
2015-03-25 01:00:52 +03:00
|
|
|
|
2015-08-04 12:52:00 +03:00
|
|
|
// If the event is dispatched via nsIWidget::DispatchInputEvent(), it
|
|
|
|
// sends the event to the parent process first since APZ needs to handle it
|
|
|
|
// first. However, some callers (e.g., keyboard apps on B2G and tests
|
|
|
|
// expecting synchronous dispatch) don't want this to do that.
|
2015-03-25 01:00:52 +03:00
|
|
|
nsresult rv = NS_OK;
|
2016-03-16 07:47:48 +03:00
|
|
|
if (ShouldSendInputEventToAPZ()) {
|
2015-08-04 12:52:00 +03:00
|
|
|
aStatus = widget->DispatchInputEvent(&aEvent);
|
2015-03-25 01:00:52 +03:00
|
|
|
} else {
|
|
|
|
rv = widget->DispatchEvent(&aEvent, aStatus);
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:20 +03:00
|
|
|
mDispatchingEvent--;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
nsresult TextEventDispatcher::StartComposition(
|
|
|
|
nsEventStatus& aStatus, const WidgetEventTime* aEventTime) {
|
2015-01-28 09:27:31 +03:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsresult rv = GetState();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
if (NS_WARN_IF(mIsComposing)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:27:31 +03:00
|
|
|
// When you change some members from here, you may need same change in
|
|
|
|
// BeginInputTransactionFor().
|
2018-01-12 05:31:53 +03:00
|
|
|
mIsComposing = mIsHandlingComposition = true;
|
2015-09-11 15:21:27 +03:00
|
|
|
WidgetCompositionEvent compositionStartEvent(true, eCompositionStart,
|
2015-02-19 09:50:20 +03:00
|
|
|
mWidget);
|
2015-01-28 09:27:31 +03:00
|
|
|
InitEvent(compositionStartEvent);
|
2016-03-16 07:47:48 +03:00
|
|
|
if (aEventTime) {
|
|
|
|
compositionStartEvent.AssignEventTime(*aEventTime);
|
|
|
|
}
|
2015-02-19 09:50:20 +03:00
|
|
|
rv = DispatchEvent(mWidget, compositionStartEvent, aStatus);
|
2015-01-28 09:27:31 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
nsresult TextEventDispatcher::StartCompositionAutomaticallyIfNecessary(
|
2016-03-16 07:47:48 +03:00
|
|
|
nsEventStatus& aStatus, const WidgetEventTime* aEventTime) {
|
2015-01-28 09:27:31 +03:00
|
|
|
if (IsComposing()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
nsresult rv = StartComposition(aStatus, aEventTime);
|
2015-01-28 09:27:31 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If started composition has already been committed, we shouldn't dispatch
|
|
|
|
// the compositionchange event.
|
|
|
|
if (!IsComposing()) {
|
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that the widget might be destroyed during a call of
|
|
|
|
// StartComposition(). In such case, we shouldn't keep dispatching next
|
|
|
|
// event.
|
|
|
|
rv = GetState();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(rv != NS_ERROR_NOT_INITIALIZED,
|
|
|
|
"aDispatcher must still be initialized in this case");
|
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return NS_OK; // Don't throw exception in this case
|
|
|
|
}
|
|
|
|
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
nsresult TextEventDispatcher::CommitComposition(
|
2016-03-16 07:47:48 +03:00
|
|
|
nsEventStatus& aStatus, const nsAString* aCommitString,
|
|
|
|
const WidgetEventTime* aEventTime) {
|
2015-01-28 09:27:31 +03:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsresult rv = GetState();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:32 +03:00
|
|
|
// When there is no composition, caller shouldn't try to commit composition
|
|
|
|
// with non-existing composition string nor commit composition with empty
|
|
|
|
// string.
|
|
|
|
if (NS_WARN_IF(!IsComposing() &&
|
|
|
|
(!aCommitString || aCommitString->IsEmpty()))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget(mWidget);
|
2016-03-16 07:47:48 +03:00
|
|
|
rv = StartCompositionAutomaticallyIfNecessary(aStatus, aEventTime);
|
2015-01-28 09:27:31 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (aStatus == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:27:31 +03:00
|
|
|
// When you change some members from here, you may need same change in
|
|
|
|
// BeginInputTransactionFor().
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
// End current composition and make this free for other IMEs.
|
|
|
|
mIsComposing = false;
|
|
|
|
|
2015-09-11 15:21:27 +03:00
|
|
|
EventMessage message =
|
|
|
|
aCommitString ? eCompositionCommit : eCompositionCommitAsIs;
|
2015-01-28 09:27:31 +03:00
|
|
|
WidgetCompositionEvent compositionCommitEvent(true, message, widget);
|
|
|
|
InitEvent(compositionCommitEvent);
|
2016-03-16 07:47:48 +03:00
|
|
|
if (aEventTime) {
|
|
|
|
compositionCommitEvent.AssignEventTime(*aEventTime);
|
|
|
|
}
|
2015-09-11 15:21:27 +03:00
|
|
|
if (message == eCompositionCommit) {
|
2015-01-28 09:27:31 +03:00
|
|
|
compositionCommitEvent.mData = *aCommitString;
|
2019-02-19 09:28:19 +03:00
|
|
|
// If aCommitString comes from TextInputProcessor, it may be void, but
|
|
|
|
// editor requires non-void string even when it's empty.
|
|
|
|
compositionCommitEvent.mData.SetIsVoid(false);
|
2017-03-16 10:26:43 +03:00
|
|
|
// Don't send CRLF nor CR, replace it with LF here.
|
2020-07-01 11:29:29 +03:00
|
|
|
compositionCommitEvent.mData.ReplaceSubstring(u"\r\n"_ns, u"\n"_ns);
|
|
|
|
compositionCommitEvent.mData.ReplaceSubstring(u"\r"_ns, u"\n"_ns);
|
2015-01-28 09:27:31 +03:00
|
|
|
}
|
2015-02-19 09:50:20 +03:00
|
|
|
rv = DispatchEvent(widget, compositionCommitEvent, aStatus);
|
2015-01-28 09:27:31 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
nsresult TextEventDispatcher::NotifyIME(
|
|
|
|
const IMENotification& aIMENotification) {
|
2016-03-16 07:47:47 +03:00
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2018-01-12 05:31:53 +03:00
|
|
|
switch (aIMENotification.mMessage) {
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
mHasFocus = false;
|
|
|
|
ClearNotificationRequests();
|
|
|
|
break;
|
|
|
|
case NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED:
|
|
|
|
// If content handles composition events when native IME doesn't have
|
|
|
|
// composition, that means that we completely finished handling
|
|
|
|
// composition(s). Note that when focused content is in a remote
|
|
|
|
// process, this is sent when all dispatched composition events
|
|
|
|
// have been handled in the remote process.
|
|
|
|
if (!IsComposing()) {
|
|
|
|
mIsHandlingComposition = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:47 +03:00
|
|
|
// First, send the notification to current input transaction's listener.
|
2015-01-28 09:27:32 +03:00
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
|
2016-03-16 07:47:47 +03:00
|
|
|
if (listener) {
|
|
|
|
rv = listener->NotifyIME(this, aIMENotification);
|
2015-01-28 09:27:32 +03:00
|
|
|
}
|
2016-03-16 07:47:47 +03:00
|
|
|
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
if (!mWidget) {
|
2016-03-16 07:47:47 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If current input transaction isn't for native event handler, we should
|
|
|
|
// send the notification to the native text event dispatcher listener
|
|
|
|
// since native event handler may need to do something from
|
|
|
|
// TextEventDispatcherListener::NotifyIME() even before there is no
|
|
|
|
// input transaction yet. For example, native IME handler may need to
|
|
|
|
// create new context at receiving NOTIFY_IME_OF_FOCUS. In this case,
|
|
|
|
// mListener may not be initialized since input transaction should be
|
|
|
|
// initialized immediately before dispatching every WidgetKeyboardEvent
|
|
|
|
// and WidgetCompositionEvent (dispatching events always occurs after
|
|
|
|
// focus move).
|
|
|
|
nsCOMPtr<TextEventDispatcherListener> nativeListener =
|
|
|
|
mWidget->GetNativeTextEventDispatcherListener();
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
if (listener != nativeListener && nativeListener) {
|
|
|
|
switch (aIMENotification.mMessage) {
|
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
// It's not necessary to notify native IME of requests.
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
// Even if current input transaction's listener returns NS_OK or
|
|
|
|
// something, we need to notify native IME of notifications because
|
|
|
|
// when user typing after TIP does something, the changed information
|
|
|
|
// is necessary for them.
|
|
|
|
nsresult rv2 = nativeListener->NotifyIME(this, aIMENotification);
|
|
|
|
// But return the result from current listener except when the
|
|
|
|
// notification isn't handled.
|
|
|
|
if (rv == NS_ERROR_NOT_IMPLEMENTED) {
|
|
|
|
rv = rv2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIMENotification.mMessage == NOTIFY_IME_OF_FOCUS) {
|
|
|
|
mHasFocus = true;
|
|
|
|
UpdateNotificationRequests();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEventDispatcher::ClearNotificationRequests() {
|
|
|
|
mIMENotificationRequests = IMENotificationRequests();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEventDispatcher::UpdateNotificationRequests() {
|
|
|
|
ClearNotificationRequests();
|
|
|
|
|
|
|
|
// If it doesn't has focus, no notifications are available.
|
|
|
|
if (!mHasFocus || !mWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a listener, its requests are necessary.
|
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener = do_QueryReferent(mListener);
|
|
|
|
if (listener) {
|
|
|
|
mIMENotificationRequests = listener->GetIMENotificationRequests();
|
2016-03-16 07:47:47 +03:00
|
|
|
}
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
|
|
|
|
// Even if this is in non-native input transaction, native IME needs
|
|
|
|
// requests. So, add native IME requests too.
|
|
|
|
if (!IsInNativeInputTransaction()) {
|
|
|
|
nsCOMPtr<TextEventDispatcherListener> nativeListener =
|
|
|
|
mWidget->GetNativeTextEventDispatcherListener();
|
|
|
|
if (nativeListener) {
|
|
|
|
mIMENotificationRequests |= nativeListener->GetIMENotificationRequests();
|
2016-03-16 07:47:47 +03:00
|
|
|
}
|
2015-01-28 09:27:32 +03:00
|
|
|
}
|
2015-01-28 09:27:31 +03:00
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:18 +03:00
|
|
|
bool TextEventDispatcher::DispatchKeyboardEvent(
|
|
|
|
EventMessage aMessage, const WidgetKeyboardEvent& aKeyboardEvent,
|
2016-03-16 07:47:48 +03:00
|
|
|
nsEventStatus& aStatus, void* aData) {
|
|
|
|
return DispatchKeyboardEventInternal(aMessage, aKeyboardEvent, aStatus,
|
|
|
|
aData);
|
2015-02-19 09:50:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEventDispatcher::DispatchKeyboardEventInternal(
|
|
|
|
EventMessage aMessage, const WidgetKeyboardEvent& aKeyboardEvent,
|
Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.
Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents(). Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--. Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().
The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events. Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.
With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout. Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.
FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified. Therefore, this patch includes the fix of these bugs
MozReview-Commit-ID: JVm7ZJVug0O
--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 14:52:03 +03:00
|
|
|
nsEventStatus& aStatus, void* aData, uint32_t aIndexOfKeypress,
|
|
|
|
bool aNeedsCallback) {
|
2016-04-22 19:22:49 +03:00
|
|
|
// Note that this method is also used for dispatching key events on a plugin
|
|
|
|
// because key events on a plugin should be dispatched same as normal key
|
|
|
|
// events. Then, only some handlers which need to intercept key events
|
|
|
|
// before the focused plugin (e.g., reserved shortcut key handlers) can
|
|
|
|
// consume the events.
|
|
|
|
MOZ_ASSERT(WidgetKeyboardEvent::IsKeyDownOrKeyDownOnPlugin(aMessage) ||
|
|
|
|
WidgetKeyboardEvent::IsKeyUpOrKeyUpOnPlugin(aMessage) ||
|
2015-08-29 02:58:27 +03:00
|
|
|
aMessage == eKeyPress,
|
|
|
|
"Invalid aMessage value");
|
2015-02-19 09:50:18 +03:00
|
|
|
nsresult rv = GetState();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the key shouldn't cause keypress events, don't this patch them.
|
2015-08-29 02:58:27 +03:00
|
|
|
if (aMessage == eKeyPress && !aKeyboardEvent.ShouldCauseKeypressEvents()) {
|
2015-02-19 09:50:18 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:18 +03:00
|
|
|
// Basically, key events shouldn't be dispatched during composition.
|
2016-04-22 19:22:49 +03:00
|
|
|
// Note that plugin process has different IME context. Therefore, we don't
|
|
|
|
// need to check our composition state when the key event is fired on a
|
|
|
|
// plugin.
|
|
|
|
if (IsComposing() && !WidgetKeyboardEvent::IsKeyEventOnPlugin(aMessage)) {
|
2015-02-19 09:50:18 +03:00
|
|
|
// However, if we need to behave like other browsers, we need the keydown
|
|
|
|
// and keyup events. Note that this behavior is also allowed by D3E spec.
|
|
|
|
// FYI: keypress events must not be fired during composition.
|
2019-08-26 23:25:42 +03:00
|
|
|
if (!StaticPrefs::dom_keyboardevent_dispatch_during_composition() ||
|
|
|
|
aMessage == eKeyPress) {
|
2015-02-19 09:50:18 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// XXX If there was mOnlyContentDispatch for this case, it might be useful
|
|
|
|
// because our chrome doesn't assume that key events are fired during
|
|
|
|
// composition.
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:20 +03:00
|
|
|
WidgetKeyboardEvent keyEvent(true, aMessage, mWidget);
|
2015-02-19 09:50:18 +03:00
|
|
|
InitEvent(keyEvent);
|
|
|
|
keyEvent.AssignKeyEventData(aKeyboardEvent, false);
|
2018-10-02 15:16:45 +03:00
|
|
|
// Command arrays are not duplicated by AssignKeyEventData() due to
|
|
|
|
// both performance and footprint reasons. So, when TextInputProcessor
|
|
|
|
// emulates real text input, the arrays may be initialized all commands
|
|
|
|
// already. If so, we need to duplicate the arrays here.
|
|
|
|
if (keyEvent.mIsSynthesizedByTIP) {
|
|
|
|
keyEvent.AssignCommands(aKeyboardEvent);
|
|
|
|
}
|
2015-02-19 09:50:18 +03:00
|
|
|
|
|
|
|
if (aStatus == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
// If the key event should be dispatched as consumed event, marking it here.
|
Bug 1435717 - Make calling WidgetEvent::PreventDefault*() stop cross process forwarding too r=smaug
Currently, if an event is consumed in the main process, EventStateManager
does not send it to remote process. However, this is unexpected behavior
for some WidgetKeyboardEvent dispatchers. OS sometimes has consumed native
key events before sending applications. For example, Alt key on Windows
should activate menu bar of focused window but Alt key may be consumed before
focused window receives the event. In such case, we mark Alt keyboard event
as "consumed before dispatch", and chrome treat it like as its preventDefault()
is called in web content. (Note that for compatibility with other browsers,
the consumed state is not exposed to web content. So, Event.defaultPrevented
returns false in web content.)
Therefore, we need to treat "consumed" state and "cross process forwarding"
state separately. This patch makes calling WidgetEvent::PreventDefault()
always stops cross process forwarding for backward compatibility. Additionally,
for the special case mentioned above, this patch makes
WidgetEvent::PreventDefaultBeforeDispatch() take additional argument,
|aIfStopCrossProcessForwarding|. If this is CrossProcessForwarding::eStop,
the event won't be sent to remote process as same as calling PreventDefault().
Otherwise, CrossProcessForwarding::eHold, PreventDefaultBeforeDispatch() call
does not change "cross process forwarding" state. I.e., if the event's
StopCrossProcessForwarding() and PreventDefault() are not called until
EventStateManager::PostHandleEvent(), the event will be sent to remote process
as usual.
MozReview-Commit-ID: IQGWJvXetxV
--HG--
extra : rebase_source : 4ccdd500e80b8fe29e469ac3b85578e1c07c8358
2018-06-25 12:17:18 +03:00
|
|
|
// This is useful to prevent double action. This is intended to the system
|
|
|
|
// has already consumed the event but we need to dispatch the event for
|
|
|
|
// compatibility with older version and other browsers. So, we should not
|
|
|
|
// stop cross process forwarding of them.
|
|
|
|
keyEvent.PreventDefaultBeforeDispatch(CrossProcessForwarding::eAllow);
|
2015-02-19 09:50:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Corrects each member for the specific key event type.
|
2016-03-19 14:57:11 +03:00
|
|
|
if (keyEvent.mKeyNameIndex != KEY_NAME_INDEX_USE_STRING) {
|
2015-02-19 09:50:18 +03:00
|
|
|
MOZ_ASSERT(!aIndexOfKeypress,
|
2016-03-19 14:57:11 +03:00
|
|
|
"aIndexOfKeypress must be 0 for non-printable key");
|
|
|
|
// If the keyboard event isn't caused by printable key, its charCode should
|
2015-02-19 09:50:18 +03:00
|
|
|
// be 0.
|
2016-03-19 14:57:11 +03:00
|
|
|
keyEvent.SetCharCode(0);
|
2015-02-19 09:50:18 +03:00
|
|
|
} else {
|
2016-04-22 19:22:49 +03:00
|
|
|
if (WidgetKeyboardEvent::IsKeyDownOrKeyDownOnPlugin(aMessage) ||
|
|
|
|
WidgetKeyboardEvent::IsKeyUpOrKeyUpOnPlugin(aMessage)) {
|
2016-03-19 14:57:11 +03:00
|
|
|
MOZ_RELEASE_ASSERT(
|
|
|
|
!aIndexOfKeypress,
|
|
|
|
"aIndexOfKeypress must be 0 for either eKeyDown or eKeyUp");
|
|
|
|
} else {
|
|
|
|
MOZ_RELEASE_ASSERT(
|
|
|
|
!aIndexOfKeypress || aIndexOfKeypress < keyEvent.mKeyValue.Length(),
|
|
|
|
"aIndexOfKeypress must be 0 - mKeyValue.Length() - 1");
|
|
|
|
}
|
2019-10-03 13:53:39 +03:00
|
|
|
char16_t ch =
|
2015-02-19 09:50:18 +03:00
|
|
|
keyEvent.mKeyValue.IsEmpty() ? 0 : keyEvent.mKeyValue[aIndexOfKeypress];
|
2016-03-19 14:57:11 +03:00
|
|
|
keyEvent.SetCharCode(static_cast<uint32_t>(ch));
|
|
|
|
if (aMessage == eKeyPress) {
|
|
|
|
// keyCode of eKeyPress events of printable keys should be always 0.
|
2016-05-12 11:13:49 +03:00
|
|
|
keyEvent.mKeyCode = 0;
|
2016-03-19 14:57:11 +03:00
|
|
|
// eKeyPress events are dispatched for every character.
|
|
|
|
// So, each key value of eKeyPress events should be a character.
|
|
|
|
if (ch) {
|
|
|
|
keyEvent.mKeyValue.Assign(ch);
|
|
|
|
} else {
|
|
|
|
keyEvent.mKeyValue.Truncate();
|
|
|
|
}
|
2015-02-19 09:50:18 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-22 19:22:49 +03:00
|
|
|
if (WidgetKeyboardEvent::IsKeyUpOrKeyUpOnPlugin(aMessage)) {
|
2015-02-19 09:50:18 +03:00
|
|
|
// mIsRepeat of keyup event must be false.
|
|
|
|
keyEvent.mIsRepeat = false;
|
|
|
|
}
|
|
|
|
// mIsComposing should be initialized later.
|
|
|
|
keyEvent.mIsComposing = false;
|
2016-03-16 07:47:48 +03:00
|
|
|
if (mInputTransactionType == eNativeInputTransaction) {
|
|
|
|
// Copy mNativeKeyEvent here because for safety for other users of
|
|
|
|
// AssignKeyEventData(), it doesn't copy this.
|
|
|
|
keyEvent.mNativeKeyEvent = aKeyboardEvent.mNativeKeyEvent;
|
|
|
|
} else {
|
|
|
|
// If it's not a keyboard event for native key event, we should ensure that
|
|
|
|
// mNativeKeyEvent and mPluginEvent are null/empty.
|
|
|
|
keyEvent.mNativeKeyEvent = nullptr;
|
|
|
|
keyEvent.mPluginEvent.Clear();
|
|
|
|
}
|
2015-02-19 09:50:18 +03:00
|
|
|
// TODO: Manage mUniqueId here.
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
// Request the alternative char codes for the key event.
|
2016-03-19 14:57:11 +03:00
|
|
|
// eKeyDown also needs alternative char codes because nsXBLWindowKeyHandler
|
|
|
|
// needs to check if a following keypress event is reserved by chrome for
|
|
|
|
// stopping propagation of its preceding keydown event.
|
2016-05-12 11:57:21 +03:00
|
|
|
keyEvent.mAlternativeCharCodes.Clear();
|
2016-04-22 19:22:49 +03:00
|
|
|
if ((WidgetKeyboardEvent::IsKeyDownOrKeyDownOnPlugin(aMessage) ||
|
|
|
|
aMessage == eKeyPress) &&
|
Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.
Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents(). Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--. Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().
The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events. Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.
With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout. Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.
FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified. Therefore, this patch includes the fix of these bugs
MozReview-Commit-ID: JVm7ZJVug0O
--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 14:52:03 +03:00
|
|
|
(aNeedsCallback || keyEvent.IsControl() || keyEvent.IsAlt() ||
|
2016-03-16 07:47:48 +03:00
|
|
|
keyEvent.IsMeta() || keyEvent.IsOS())) {
|
|
|
|
nsCOMPtr<TextEventDispatcherListener> listener =
|
|
|
|
do_QueryReferent(mListener);
|
|
|
|
if (listener) {
|
2016-03-16 07:47:48 +03:00
|
|
|
DebugOnly<WidgetKeyboardEvent> original(keyEvent);
|
2016-03-16 07:47:48 +03:00
|
|
|
listener->WillDispatchKeyboardEvent(this, keyEvent, aIndexOfKeypress,
|
|
|
|
aData);
|
2016-03-16 07:47:48 +03:00
|
|
|
MOZ_ASSERT(keyEvent.mMessage ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mMessage);
|
2016-05-12 11:13:49 +03:00
|
|
|
MOZ_ASSERT(keyEvent.mKeyCode ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mKeyCode);
|
2016-05-12 12:17:22 +03:00
|
|
|
MOZ_ASSERT(keyEvent.mLocation ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mLocation);
|
2016-03-16 07:47:48 +03:00
|
|
|
MOZ_ASSERT(keyEvent.mIsRepeat ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mIsRepeat);
|
|
|
|
MOZ_ASSERT(keyEvent.mIsComposing ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mIsComposing);
|
|
|
|
MOZ_ASSERT(keyEvent.mKeyNameIndex ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mKeyNameIndex);
|
|
|
|
MOZ_ASSERT(keyEvent.mCodeNameIndex ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mCodeNameIndex);
|
|
|
|
MOZ_ASSERT(keyEvent.mKeyValue ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mKeyValue);
|
|
|
|
MOZ_ASSERT(keyEvent.mCodeValue ==
|
|
|
|
static_cast<WidgetKeyboardEvent&>(original).mCodeValue);
|
2016-03-16 07:47:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-26 23:25:42 +03:00
|
|
|
if (StaticPrefs::
|
|
|
|
dom_keyboardevent_keypress_dispatch_non_printable_keys_only_system_group_in_content() &&
|
2018-01-25 17:27:07 +03:00
|
|
|
keyEvent.mMessage == eKeyPress &&
|
2018-02-14 15:21:18 +03:00
|
|
|
!keyEvent.ShouldKeyPressEventBeFiredOnContent()) {
|
2018-03-23 06:06:55 +03:00
|
|
|
// Note that even if we set it to true, this may be overwritten by
|
|
|
|
// PresShell::DispatchEventToDOM().
|
2018-01-25 17:27:07 +03:00
|
|
|
keyEvent.mFlags.mOnlySystemGroupDispatchInContent = true;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
DispatchInputEvent(mWidget, keyEvent, aStatus);
|
2015-02-19 09:50:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEventDispatcher::MaybeDispatchKeypressEvents(
|
|
|
|
const WidgetKeyboardEvent& aKeyboardEvent, nsEventStatus& aStatus,
|
Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.
Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents(). Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--. Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().
The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events. Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.
With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout. Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.
FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified. Therefore, this patch includes the fix of these bugs
MozReview-Commit-ID: JVm7ZJVug0O
--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 14:52:03 +03:00
|
|
|
void* aData, bool aNeedsCallback) {
|
2015-02-19 09:50:18 +03:00
|
|
|
// If the key event was consumed, keypress event shouldn't be fired.
|
|
|
|
if (aStatus == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:49 +03:00
|
|
|
// If the key shouldn't cause keypress events, don't fire them.
|
|
|
|
if (!aKeyboardEvent.ShouldCauseKeypressEvents()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-19 09:50:18 +03:00
|
|
|
// If the key isn't a printable key or just inputting one character or
|
|
|
|
// no character, we should dispatch only one keypress. Otherwise, i.e.,
|
|
|
|
// if the key is a printable key and inputs multiple characters, keypress
|
|
|
|
// event should be dispatched the count of inputting characters times.
|
|
|
|
size_t keypressCount =
|
|
|
|
aKeyboardEvent.mKeyNameIndex != KEY_NAME_INDEX_USE_STRING
|
|
|
|
? 1
|
|
|
|
: std::max(static_cast<nsAString::size_type>(1),
|
|
|
|
aKeyboardEvent.mKeyValue.Length());
|
|
|
|
bool isDispatched = false;
|
|
|
|
bool consumed = false;
|
|
|
|
for (size_t i = 0; i < keypressCount; i++) {
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
2015-08-29 02:58:27 +03:00
|
|
|
if (!DispatchKeyboardEventInternal(eKeyPress, aKeyboardEvent, aStatus,
|
Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.
Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents(). Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--. Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().
The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events. Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.
With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout. Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.
FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified. Therefore, this patch includes the fix of these bugs
MozReview-Commit-ID: JVm7ZJVug0O
--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 14:52:03 +03:00
|
|
|
aData, i, aNeedsCallback)) {
|
2015-02-19 09:50:18 +03:00
|
|
|
// The widget must have been gone.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
isDispatched = true;
|
|
|
|
if (!consumed) {
|
|
|
|
consumed = (aStatus == nsEventStatus_eConsumeNoDefault);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If one of the keypress event was consumed, return ConsumeNoDefault.
|
|
|
|
if (consumed) {
|
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isDispatched;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:30 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* TextEventDispatcher::PendingComposition
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
TextEventDispatcher::PendingComposition::PendingComposition() { Clear(); }
|
|
|
|
|
|
|
|
void TextEventDispatcher::PendingComposition::Clear() {
|
|
|
|
mString.Truncate();
|
2015-01-28 09:27:31 +03:00
|
|
|
mClauses = nullptr;
|
2016-06-03 12:32:22 +03:00
|
|
|
mCaret.mRangeType = TextRangeType::eUninitialized;
|
2017-03-15 13:09:30 +03:00
|
|
|
mReplacedNativeLineBreakers = false;
|
2015-01-28 09:27:30 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
void TextEventDispatcher::PendingComposition::EnsureClauseArray() {
|
|
|
|
if (mClauses) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mClauses = new TextRangeArray();
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:30 +03:00
|
|
|
nsresult TextEventDispatcher::PendingComposition::SetString(
|
|
|
|
const nsAString& aString) {
|
2017-03-15 13:09:30 +03:00
|
|
|
MOZ_ASSERT(!mReplacedNativeLineBreakers);
|
2015-01-28 09:27:30 +03:00
|
|
|
mString = aString;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-04 03:49:21 +03:00
|
|
|
nsresult TextEventDispatcher::PendingComposition::AppendClause(
|
|
|
|
uint32_t aLength, TextRangeType aTextRangeType) {
|
2017-03-15 13:09:30 +03:00
|
|
|
MOZ_ASSERT(!mReplacedNativeLineBreakers);
|
|
|
|
|
2015-01-28 09:27:30 +03:00
|
|
|
if (NS_WARN_IF(!aLength)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2016-06-04 03:49:21 +03:00
|
|
|
switch (aTextRangeType) {
|
2016-06-03 12:48:37 +03:00
|
|
|
case TextRangeType::eRawClause:
|
2016-06-03 12:57:21 +03:00
|
|
|
case TextRangeType::eSelectedRawClause:
|
2016-06-03 13:05:32 +03:00
|
|
|
case TextRangeType::eConvertedClause:
|
2016-06-03 13:15:21 +03:00
|
|
|
case TextRangeType::eSelectedClause: {
|
2015-01-28 09:27:31 +03:00
|
|
|
EnsureClauseArray();
|
2015-01-28 09:27:30 +03:00
|
|
|
TextRange textRange;
|
|
|
|
textRange.mStartOffset =
|
|
|
|
mClauses->IsEmpty() ? 0 : mClauses->LastElement().mEndOffset;
|
|
|
|
textRange.mEndOffset = textRange.mStartOffset + aLength;
|
2016-06-04 03:49:21 +03:00
|
|
|
textRange.mRangeType = aTextRangeType;
|
2015-01-28 09:27:30 +03:00
|
|
|
mClauses->AppendElement(textRange);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult TextEventDispatcher::PendingComposition::SetCaret(uint32_t aOffset,
|
|
|
|
uint32_t aLength) {
|
2017-03-15 13:09:30 +03:00
|
|
|
MOZ_ASSERT(!mReplacedNativeLineBreakers);
|
|
|
|
|
2015-01-28 09:27:30 +03:00
|
|
|
mCaret.mStartOffset = aOffset;
|
|
|
|
mCaret.mEndOffset = mCaret.mStartOffset + aLength;
|
2016-06-03 12:40:06 +03:00
|
|
|
mCaret.mRangeType = TextRangeType::eCaret;
|
2015-01-28 09:27:30 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
nsresult TextEventDispatcher::PendingComposition::Set(
|
|
|
|
const nsAString& aString, const TextRangeArray* aRanges) {
|
|
|
|
Clear();
|
|
|
|
|
2017-03-15 12:59:34 +03:00
|
|
|
nsresult rv = SetString(aString);
|
2016-03-16 07:47:48 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aRanges || aRanges->IsEmpty()) {
|
2017-03-15 12:59:34 +03:00
|
|
|
// Create dummy range if mString isn't empty.
|
|
|
|
if (!mString.IsEmpty()) {
|
|
|
|
rv = AppendClause(mString.Length(), TextRangeType::eRawClause);
|
2016-03-16 07:47:48 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2017-03-15 12:59:34 +03:00
|
|
|
ReplaceNativeLineBreakers();
|
2016-03-16 07:47:48 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust offsets in the ranges for XP linefeed character (only \n).
|
|
|
|
for (uint32_t i = 0; i < aRanges->Length(); ++i) {
|
|
|
|
TextRange range = aRanges->ElementAt(i);
|
2016-06-03 12:40:06 +03:00
|
|
|
if (range.mRangeType == TextRangeType::eCaret) {
|
2016-03-16 07:47:48 +03:00
|
|
|
mCaret = range;
|
|
|
|
} else {
|
|
|
|
EnsureClauseArray();
|
|
|
|
mClauses->AppendElement(range);
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 12:59:34 +03:00
|
|
|
ReplaceNativeLineBreakers();
|
2016-03-16 07:47:48 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-15 12:59:34 +03:00
|
|
|
void TextEventDispatcher::PendingComposition::ReplaceNativeLineBreakers() {
|
2017-03-15 13:09:30 +03:00
|
|
|
mReplacedNativeLineBreakers = true;
|
|
|
|
|
2017-03-15 12:59:34 +03:00
|
|
|
// If the composition string is empty, we don't need to do anything.
|
|
|
|
if (mString.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString nativeString(mString);
|
2017-03-16 10:26:43 +03:00
|
|
|
// Don't expose CRLF nor CR to web contents, instead, use LF.
|
2020-07-01 11:29:29 +03:00
|
|
|
mString.ReplaceSubstring(u"\r\n"_ns, u"\n"_ns);
|
|
|
|
mString.ReplaceSubstring(u"\r"_ns, u"\n"_ns);
|
2017-03-15 12:59:34 +03:00
|
|
|
|
|
|
|
// If the length isn't changed, we don't need to adjust any offset and length
|
|
|
|
// of mClauses nor mCaret.
|
|
|
|
if (nativeString.Length() == mString.Length()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mClauses) {
|
|
|
|
for (TextRange& clause : *mClauses) {
|
|
|
|
AdjustRange(clause, nativeString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mCaret.mRangeType == TextRangeType::eCaret) {
|
|
|
|
AdjustRange(mCaret, nativeString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 12:51:32 +03:00
|
|
|
// static
|
|
|
|
void TextEventDispatcher::PendingComposition::AdjustRange(
|
|
|
|
TextRange& aRange, const nsAString& aNativeString) {
|
|
|
|
TextRange nativeRange = aRange;
|
|
|
|
// XXX Following code wastes runtime cost because this causes computing
|
|
|
|
// mStartOffset for each clause from the start of composition string.
|
|
|
|
// If we'd make TextRange have only its length, we don't need to do
|
|
|
|
// this. However, this must not be so serious problem because
|
|
|
|
// composition string is usually short and separated as a few clauses.
|
|
|
|
if (nativeRange.mStartOffset > 0) {
|
|
|
|
nsAutoString preText(Substring(aNativeString, 0, nativeRange.mStartOffset));
|
2020-07-01 11:29:29 +03:00
|
|
|
preText.ReplaceSubstring(u"\r\n"_ns, u"\n"_ns);
|
2017-03-15 12:51:32 +03:00
|
|
|
aRange.mStartOffset = preText.Length();
|
|
|
|
}
|
|
|
|
if (nativeRange.Length() == 0) {
|
|
|
|
aRange.mEndOffset = aRange.mStartOffset;
|
|
|
|
} else {
|
|
|
|
nsAutoString clause(Substring(aNativeString, nativeRange.mStartOffset,
|
|
|
|
nativeRange.Length()));
|
2020-07-01 11:29:29 +03:00
|
|
|
clause.ReplaceSubstring(u"\r\n"_ns, u"\n"_ns);
|
2017-03-15 12:51:32 +03:00
|
|
|
aRange.mEndOffset = aRange.mStartOffset + clause.Length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
nsresult TextEventDispatcher::PendingComposition::Flush(
|
|
|
|
TextEventDispatcher* aDispatcher, nsEventStatus& aStatus,
|
|
|
|
const WidgetEventTime* aEventTime) {
|
2015-01-28 09:27:30 +03:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
nsresult rv = aDispatcher->GetState();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
2015-01-28 09:27:30 +03:00
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
if (mClauses && !mClauses->IsEmpty() &&
|
2015-01-28 09:27:30 +03:00
|
|
|
mClauses->LastElement().mEndOffset != mString.Length()) {
|
|
|
|
NS_WARNING(
|
|
|
|
"Sum of length of the all clauses must be same as the string "
|
|
|
|
"length");
|
|
|
|
Clear();
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2016-06-03 12:40:06 +03:00
|
|
|
if (mCaret.mRangeType == TextRangeType::eCaret) {
|
2015-01-28 09:27:30 +03:00
|
|
|
if (mCaret.mEndOffset > mString.Length()) {
|
|
|
|
NS_WARNING("Caret position is out of the composition string");
|
|
|
|
Clear();
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
2015-01-28 09:27:31 +03:00
|
|
|
EnsureClauseArray();
|
2015-01-28 09:27:30 +03:00
|
|
|
mClauses->AppendElement(mCaret);
|
|
|
|
}
|
|
|
|
|
2017-03-15 13:09:30 +03:00
|
|
|
// If the composition string is set without Set(), we need to replace native
|
|
|
|
// line breakers in the composition string with XP line breaker.
|
|
|
|
if (!mReplacedNativeLineBreakers) {
|
|
|
|
ReplaceNativeLineBreakers();
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> kungFuDeathGrip(aDispatcher);
|
2015-01-28 09:27:31 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget(aDispatcher->mWidget);
|
2015-09-11 15:21:27 +03:00
|
|
|
WidgetCompositionEvent compChangeEvent(true, eCompositionChange, widget);
|
2015-01-28 09:27:31 +03:00
|
|
|
aDispatcher->InitEvent(compChangeEvent);
|
2016-03-16 07:47:48 +03:00
|
|
|
if (aEventTime) {
|
|
|
|
compChangeEvent.AssignEventTime(*aEventTime);
|
|
|
|
}
|
2015-01-28 09:27:30 +03:00
|
|
|
compChangeEvent.mData = mString;
|
2019-02-19 09:28:19 +03:00
|
|
|
// If mString comes from TextInputProcessor, it may be void, but editor
|
|
|
|
// requires non-void string even when it's empty.
|
|
|
|
compChangeEvent.mData.SetIsVoid(false);
|
2015-01-28 09:27:31 +03:00
|
|
|
if (mClauses) {
|
|
|
|
MOZ_ASSERT(!mClauses->IsEmpty(),
|
|
|
|
"mClauses must be non-empty array when it's not nullptr");
|
2015-01-28 09:27:30 +03:00
|
|
|
compChangeEvent.mRanges = mClauses;
|
|
|
|
}
|
|
|
|
|
2015-01-28 09:27:31 +03:00
|
|
|
// While this method dispatches a composition event, some other event handler
|
|
|
|
// cause more clauses to be added. So, we should clear pending composition
|
|
|
|
// before dispatching the event.
|
2015-01-28 09:27:30 +03:00
|
|
|
Clear();
|
2015-01-28 09:27:31 +03:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
rv = aDispatcher->StartCompositionAutomaticallyIfNecessary(aStatus,
|
|
|
|
aEventTime);
|
2015-01-28 09:27:31 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (aStatus == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-02-19 09:50:20 +03:00
|
|
|
rv = aDispatcher->DispatchEvent(widget, compChangeEvent, aStatus);
|
2015-01-28 09:27:30 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|