2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2015-05-19 18:15:34 +00:00
|
|
|
#include "mozilla/Logging.h"
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
#include "mozilla/IMEStateManager.h"
|
2013-11-20 09:32:46 +00:00
|
|
|
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-06-16 23:02:39 +00:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2014-08-29 10:08:43 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
2016-12-16 03:16:31 +00:00
|
|
|
#include "mozilla/SizePrintfMacros.h"
|
2014-04-03 04:18:37 +00:00
|
|
|
#include "mozilla/TextComposition.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
2016-08-23 04:09:32 +00:00
|
|
|
#include "mozilla/Unused.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
2014-08-28 05:06:41 +00:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
|
2013-11-20 09:32:46 +00:00
|
|
|
#include "HTMLInputElement.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "IMEContentObserver.h"
|
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "nsContentUtils.h"
|
2006-04-11 16:37:58 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-11-27 11:51:53 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2014-11-05 13:12:44 +00:00
|
|
|
#include "nsIEditor.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "nsIForm.h"
|
|
|
|
#include "nsIFormControl.h"
|
2009-02-10 20:56:51 +00:00
|
|
|
#include "nsINode.h"
|
2010-10-18 16:37:00 +00:00
|
|
|
#include "nsIObserverService.h"
|
2014-03-08 01:20:08 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsPresContext.h"
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
namespace mozilla {
|
2011-11-27 11:51:52 +00:00
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
using namespace dom;
|
|
|
|
using namespace widget;
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
/**
|
|
|
|
* When a method is called, log its arguments and/or related static variables
|
2015-06-03 22:25:57 +00:00
|
|
|
* with LogLevel::Info. However, if it puts too many logs like
|
2014-07-16 05:13:28 +00:00
|
|
|
* OnDestroyPresContext(), should long only when the method actually does
|
2016-07-05 10:05:23 +00:00
|
|
|
* something. In this case, the log should start with "<method name>".
|
2014-07-16 05:13:28 +00:00
|
|
|
*
|
|
|
|
* When a method quits due to unexpected situation, log the reason with
|
2015-06-03 22:25:57 +00:00
|
|
|
* LogLevel::Error. In this case, the log should start with
|
2016-07-05 10:05:23 +00:00
|
|
|
* "<method name>(), FAILED". The indent makes the log look easier.
|
2014-07-16 05:13:28 +00:00
|
|
|
*
|
|
|
|
* When a method does something only in some situations and it may be important
|
2015-06-03 22:25:57 +00:00
|
|
|
* for debug, log the information with LogLevel::Debug. In this case, the log
|
2016-07-05 10:05:23 +00:00
|
|
|
* should start with " <method name>(),".
|
2014-07-16 05:13:28 +00:00
|
|
|
*/
|
2015-11-23 19:09:25 +00:00
|
|
|
LazyLogModule sISMLog("IMEStateManager");
|
2014-07-16 05:13:28 +00:00
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetBoolName(bool aBool)
|
|
|
|
{
|
|
|
|
return aBool ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetActionCauseName(InputContextAction::Cause aCause)
|
|
|
|
{
|
|
|
|
switch (aCause) {
|
|
|
|
case InputContextAction::CAUSE_UNKNOWN:
|
|
|
|
return "CAUSE_UNKNOWN";
|
|
|
|
case InputContextAction::CAUSE_UNKNOWN_CHROME:
|
|
|
|
return "CAUSE_UNKNOWN_CHROME";
|
|
|
|
case InputContextAction::CAUSE_KEY:
|
|
|
|
return "CAUSE_KEY";
|
|
|
|
case InputContextAction::CAUSE_MOUSE:
|
|
|
|
return "CAUSE_MOUSE";
|
2015-12-08 14:56:27 +00:00
|
|
|
case InputContextAction::CAUSE_TOUCH:
|
|
|
|
return "CAUSE_TOUCH";
|
2014-07-16 05:13:28 +00:00
|
|
|
default:
|
|
|
|
return "illegal value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetActionFocusChangeName(InputContextAction::FocusChange aFocusChange)
|
|
|
|
{
|
|
|
|
switch (aFocusChange) {
|
|
|
|
case InputContextAction::FOCUS_NOT_CHANGED:
|
|
|
|
return "FOCUS_NOT_CHANGED";
|
|
|
|
case InputContextAction::GOT_FOCUS:
|
|
|
|
return "GOT_FOCUS";
|
|
|
|
case InputContextAction::LOST_FOCUS:
|
|
|
|
return "LOST_FOCUS";
|
|
|
|
case InputContextAction::MENU_GOT_PSEUDO_FOCUS:
|
|
|
|
return "MENU_GOT_PSEUDO_FOCUS";
|
|
|
|
case InputContextAction::MENU_LOST_PSEUDO_FOCUS:
|
|
|
|
return "MENU_LOST_PSEUDO_FOCUS";
|
|
|
|
default:
|
|
|
|
return "illegal value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetIMEStateEnabledName(IMEState::Enabled aEnabled)
|
|
|
|
{
|
|
|
|
switch (aEnabled) {
|
|
|
|
case IMEState::DISABLED:
|
|
|
|
return "DISABLED";
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
return "ENABLED";
|
|
|
|
case IMEState::PASSWORD:
|
|
|
|
return "PASSWORD";
|
|
|
|
case IMEState::PLUGIN:
|
|
|
|
return "PLUGIN";
|
|
|
|
default:
|
|
|
|
return "illegal value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetIMEStateSetOpenName(IMEState::Open aOpen)
|
|
|
|
{
|
|
|
|
switch (aOpen) {
|
|
|
|
case IMEState::DONT_CHANGE_OPEN_STATE:
|
|
|
|
return "DONT_CHANGE_OPEN_STATE";
|
|
|
|
case IMEState::OPEN:
|
|
|
|
return "OPEN";
|
|
|
|
case IMEState::CLOSED:
|
|
|
|
return "CLOSED";
|
|
|
|
default:
|
|
|
|
return "illegal value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
StaticRefPtr<nsIContent> IMEStateManager::sContent;
|
2016-09-20 05:12:09 +00:00
|
|
|
StaticRefPtr<nsPresContext> IMEStateManager::sPresContext;
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 02:27:56 +00:00
|
|
|
nsIWidget* IMEStateManager::sFocusedIMEWidget = nullptr;
|
|
|
|
nsIWidget* IMEStateManager::sActiveInputContextWidget = nullptr;
|
2015-07-01 13:19:11 +00:00
|
|
|
StaticRefPtr<TabParent> IMEStateManager::sActiveTabParent;
|
2015-07-01 13:19:11 +00:00
|
|
|
StaticRefPtr<IMEContentObserver> IMEStateManager::sActiveIMEContentObserver;
|
|
|
|
TextCompositionArray* IMEStateManager::sTextCompositions = nullptr;
|
2014-03-08 01:20:07 +00:00
|
|
|
bool IMEStateManager::sInstalledMenuKeyboardListener = false;
|
2014-07-17 05:08:44 +00:00
|
|
|
bool IMEStateManager::sIsGettingNewIMEState = false;
|
2015-06-16 23:02:39 +00:00
|
|
|
bool IMEStateManager::sCheckForIMEUnawareWebApps = false;
|
2015-06-27 00:23:31 +00:00
|
|
|
bool IMEStateManager::sRemoteHasFocus = false;
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::Init()
|
|
|
|
{
|
2015-06-16 23:02:39 +00:00
|
|
|
Preferences::AddBoolVarCache(
|
|
|
|
&sCheckForIMEUnawareWebApps,
|
|
|
|
"intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition",
|
|
|
|
false);
|
2014-07-16 05:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2012-09-26 05:47:45 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::Shutdown()
|
2012-09-26 05:47:45 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-12-16 03:16:31 +00:00
|
|
|
("Shutdown(), sTextCompositions=0x%p, sTextCompositions->Length()=%" PRIuSIZE,
|
2014-07-16 05:13:28 +00:00
|
|
|
sTextCompositions, sTextCompositions ? sTextCompositions->Length() : 0));
|
|
|
|
|
2012-09-26 05:47:45 +00:00
|
|
|
MOZ_ASSERT(!sTextCompositions || !sTextCompositions->Length());
|
|
|
|
delete sTextCompositions;
|
|
|
|
sTextCompositions = nullptr;
|
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::OnTabParentDestroying(TabParent* aTabParent)
|
|
|
|
{
|
|
|
|
if (sActiveTabParent != aTabParent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnTabParentDestroying(aTabParent=0x%p), "
|
2015-07-01 13:19:11 +00:00
|
|
|
"The active TabParent is being destroyed", aTabParent));
|
|
|
|
|
|
|
|
// The active remote process might have crashed.
|
|
|
|
sActiveTabParent = nullptr;
|
|
|
|
|
|
|
|
// TODO: Need to cancel composition without TextComposition and make
|
|
|
|
// disable IME.
|
|
|
|
}
|
|
|
|
|
2015-11-13 04:05:54 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::WidgetDestroyed(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
if (sFocusedIMEWidget == aWidget) {
|
|
|
|
sFocusedIMEWidget = nullptr;
|
|
|
|
}
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 02:27:56 +00:00
|
|
|
if (sActiveInputContextWidget == aWidget) {
|
|
|
|
sActiveInputContextWidget = nullptr;
|
|
|
|
}
|
2015-11-13 04:05:54 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::StopIMEStateManagement()
|
|
|
|
{
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("StopIMEStateManagement()"));
|
2015-07-01 13:19:11 +00:00
|
|
|
|
|
|
|
// NOTE: Don't set input context from here since this has already lost
|
|
|
|
// the rights to change input context.
|
|
|
|
|
|
|
|
if (sTextCompositions && sPresContext) {
|
|
|
|
NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, sPresContext);
|
|
|
|
}
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 02:27:56 +00:00
|
|
|
sActiveInputContextWidget = nullptr;
|
2015-07-01 13:19:11 +00:00
|
|
|
sPresContext = nullptr;
|
|
|
|
sContent = nullptr;
|
|
|
|
sActiveTabParent = nullptr;
|
|
|
|
DestroyIMEContentObserver();
|
|
|
|
}
|
|
|
|
|
2016-06-14 12:06:34 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::MaybeStartOffsetUpdatedInChild(nsIWidget* aWidget,
|
|
|
|
uint32_t aStartOffset)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!sTextCompositions)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Warning,
|
2016-07-05 10:05:23 +00:00
|
|
|
("MaybeStartOffsetUpdatedInChild(aWidget=0x%p, aStartOffset=%u), "
|
|
|
|
"called when there is no composition", aWidget, aStartOffset));
|
2016-06-14 12:06:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<TextComposition> composition = GetTextCompositionFor(aWidget);
|
|
|
|
if (NS_WARN_IF(!composition)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Warning,
|
2016-07-05 10:05:23 +00:00
|
|
|
("MaybeStartOffsetUpdatedInChild(aWidget=0x%p, aStartOffset=%u), "
|
|
|
|
"called when there is no composition", aWidget, aStartOffset));
|
2016-06-14 12:06:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (composition->NativeOffsetOfStartComposition() == aStartOffset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("MaybeStartOffsetUpdatedInChild(aWidget=0x%p, aStartOffset=%u), "
|
|
|
|
"old offset=%u",
|
2016-06-14 12:06:34 +00:00
|
|
|
aWidget, aStartOffset, composition->NativeOffsetOfStartComposition()));
|
|
|
|
composition->OnStartOffsetUpdatedInChild(aStartOffset);
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2006-04-11 16:37:58 +00:00
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnDestroyPresContext(nsPresContext* aPresContext)
|
2006-04-11 16:37:58 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
2012-09-26 05:47:45 +00:00
|
|
|
|
|
|
|
// First, if there is a composition in the aPresContext, clean up it.
|
|
|
|
if (sTextCompositions) {
|
|
|
|
TextCompositionArray::index_type i =
|
|
|
|
sTextCompositions->IndexOf(aPresContext);
|
|
|
|
if (i != TextCompositionArray::NoIndex) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnDestroyPresContext(), "
|
2016-12-16 03:16:31 +00:00
|
|
|
"removing TextComposition instance from the array (index=%" PRIuSIZE ")", i));
|
2012-09-26 05:47:45 +00:00
|
|
|
// there should be only one composition per presContext object.
|
2014-02-25 06:59:28 +00:00
|
|
|
sTextCompositions->ElementAt(i)->Destroy();
|
2012-09-26 05:47:45 +00:00
|
|
|
sTextCompositions->RemoveElementAt(i);
|
2014-07-16 05:13:28 +00:00
|
|
|
if (sTextCompositions->IndexOf(aPresContext) !=
|
|
|
|
TextCompositionArray::NoIndex) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnDestroyPresContext(), FAILED to remove "
|
2014-07-16 05:13:28 +00:00
|
|
|
"TextComposition instance from the array"));
|
|
|
|
MOZ_CRASH("Failed to remove TextComposition instance from the array");
|
|
|
|
}
|
2012-09-26 05:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:20:08 +00:00
|
|
|
if (aPresContext != sPresContext) {
|
2006-04-11 16:37:58 +00:00
|
|
|
return NS_OK;
|
2014-03-08 01:20:08 +00:00
|
|
|
}
|
2012-11-09 08:40:39 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnDestroyPresContext(aPresContext=0x%p), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"sPresContext=0x%p, sContent=0x%p, sTextCompositions=0x%p",
|
2016-09-20 05:12:09 +00:00
|
|
|
aPresContext, sPresContext.get(), sContent.get(), sTextCompositions));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
|
|
|
DestroyIMEContentObserver();
|
2012-11-09 08:40:39 +00:00
|
|
|
|
2013-02-06 02:50:02 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = sPresContext->GetRootWidget();
|
2009-12-04 08:03:27 +00:00
|
|
|
if (widget) {
|
2012-07-30 14:20:58 +00:00
|
|
|
IMEState newState = GetNewIMEState(sPresContext, nullptr);
|
2011-11-27 11:51:52 +00:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::LOST_FOCUS);
|
2012-07-30 14:20:58 +00:00
|
|
|
SetIMEState(newState, nullptr, widget, action);
|
2009-12-04 08:03:27 +00:00
|
|
|
}
|
2015-07-01 13:19:11 +00:00
|
|
|
sContent = nullptr;
|
2012-07-30 14:20:58 +00:00
|
|
|
sPresContext = nullptr;
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveTabParent = nullptr;
|
2006-04-11 16:37:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2006-04-11 16:37:58 +00:00
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnRemoveContent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
2006-04-11 16:37:58 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aPresContext);
|
2012-09-26 05:47:45 +00:00
|
|
|
|
|
|
|
// First, if there is a composition in the aContent, clean up it.
|
|
|
|
if (sTextCompositions) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextComposition> compositionInContent =
|
2012-09-26 05:47:45 +00:00
|
|
|
sTextCompositions->GetCompositionInContent(aPresContext, aContent);
|
2012-09-26 05:47:51 +00:00
|
|
|
|
2012-09-26 05:47:45 +00:00
|
|
|
if (compositionInContent) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnRemoveContent(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"composition is in the content"));
|
|
|
|
|
2012-09-26 05:47:45 +00:00
|
|
|
// Try resetting the native IME state. Be aware, typically, this method
|
|
|
|
// is called during the content being removed. Then, the native
|
|
|
|
// composition events which are caused by following APIs are ignored due
|
|
|
|
// to unsafe to run script (in PresShell::HandleEvent()).
|
2016-08-30 14:44:52 +00:00
|
|
|
DebugOnly<void*> widget = aPresContext->GetRootWidget();
|
2014-09-26 00:05:11 +00:00
|
|
|
MOZ_ASSERT(widget, "Why is there no widget?");
|
|
|
|
nsresult rv =
|
|
|
|
compositionInContent->NotifyIME(REQUEST_TO_CANCEL_COMPOSITION);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
compositionInContent->NotifyIME(REQUEST_TO_COMMIT_COMPOSITION);
|
2012-09-26 05:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
if (!sPresContext || !sContent ||
|
2012-09-26 05:47:45 +00:00
|
|
|
!nsContentUtils::ContentIsDescendantOf(sContent, aContent)) {
|
2006-04-11 16:37:58 +00:00
|
|
|
return NS_OK;
|
2012-09-26 05:47:45 +00:00
|
|
|
}
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnRemoveContent(aPresContext=0x%p, aContent=0x%p), "
|
|
|
|
"sPresContext=0x%p, sContent=0x%p, sTextCompositions=0x%p",
|
2016-09-20 05:12:09 +00:00
|
|
|
aPresContext, aContent, sPresContext.get(), sContent.get(), sTextCompositions));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
|
|
|
DestroyIMEContentObserver();
|
2012-11-09 08:40:39 +00:00
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
// Current IME transaction should commit
|
2013-02-06 02:50:02 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = sPresContext->GetRootWidget();
|
2008-07-14 02:56:18 +00:00
|
|
|
if (widget) {
|
2012-07-30 14:20:58 +00:00
|
|
|
IMEState newState = GetNewIMEState(sPresContext, nullptr);
|
2011-11-27 11:51:52 +00:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::LOST_FOCUS);
|
2012-07-30 14:20:58 +00:00
|
|
|
SetIMEState(newState, nullptr, widget, action);
|
2006-04-11 16:37:58 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
sContent = nullptr;
|
2012-07-30 14:20:58 +00:00
|
|
|
sPresContext = nullptr;
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveTabParent = nullptr;
|
2006-04-11 16:37:58 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2006-04-11 16:37:58 +00:00
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnChangeFocus(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
InputContextAction::Cause aCause)
|
2011-11-27 11:51:52 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnChangeFocus(aPresContext=0x%p, aContent=0x%p, aCause=%s)",
|
2014-07-16 05:13:28 +00:00
|
|
|
aPresContext, aContent, GetActionCauseName(aCause)));
|
|
|
|
|
2011-11-27 11:51:52 +00:00
|
|
|
InputContextAction action(aCause);
|
|
|
|
return OnChangeFocusInternal(aPresContext, aContent, action);
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2011-11-27 11:51:52 +00:00
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnChangeFocusInternal(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
InputContextAction aAction)
|
2006-04-11 16:37:58 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TabParent> newTabParent = TabParent::GetFrom(aContent);
|
2015-07-01 13:19:11 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnChangeFocusInternal(aPresContext=0x%p, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"aContent=0x%p (TabParent=0x%p), aAction={ mCause=%s, mFocusChange=%s }), "
|
|
|
|
"sPresContext=0x%p, sContent=0x%p, sActiveTabParent=0x%p, "
|
|
|
|
"sActiveIMEContentObserver=0x%p, sInstalledMenuKeyboardListener=%s",
|
|
|
|
aPresContext, aContent, newTabParent.get(),
|
|
|
|
GetActionCauseName(aAction.mCause),
|
2014-07-16 05:13:28 +00:00
|
|
|
GetActionFocusChangeName(aAction.mFocusChange),
|
2016-09-20 05:12:09 +00:00
|
|
|
sPresContext.get(), sContent.get(), sActiveTabParent.get(),
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveIMEContentObserver.get(),
|
|
|
|
GetBoolName(sInstalledMenuKeyboardListener)));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2012-10-30 23:22:22 +00:00
|
|
|
bool focusActuallyChanging =
|
2015-07-01 13:19:11 +00:00
|
|
|
(sContent != aContent || sPresContext != aPresContext ||
|
|
|
|
sActiveTabParent != newTabParent);
|
2012-10-30 23:22:22 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> oldWidget =
|
2013-02-06 02:50:02 +00:00
|
|
|
sPresContext ? sPresContext->GetRootWidget() : nullptr;
|
2012-10-30 23:22:22 +00:00
|
|
|
if (oldWidget && focusActuallyChanging) {
|
|
|
|
// If we're deactivating, we shouldn't commit composition forcibly because
|
|
|
|
// the user may want to continue the composition.
|
|
|
|
if (aPresContext) {
|
|
|
|
NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, oldWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
if (sActiveIMEContentObserver &&
|
|
|
|
(aPresContext || !sActiveIMEContentObserver->KeepAliveDuringDeactive()) &&
|
|
|
|
!sActiveIMEContentObserver->IsManaging(aPresContext, aContent)) {
|
2014-07-16 05:13:28 +00:00
|
|
|
DestroyIMEContentObserver();
|
2012-10-26 00:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!aPresContext) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"no nsPresContext is being activated"));
|
2012-10-26 00:49:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
nsIContentParent* currentContentParent =
|
|
|
|
sActiveTabParent ? sActiveTabParent->Manager() : nullptr;
|
|
|
|
nsIContentParent* newContentParent =
|
|
|
|
newTabParent ? newTabParent->Manager() : nullptr;
|
|
|
|
if (sActiveTabParent && currentContentParent != newContentParent) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), notifying previous "
|
2015-07-01 13:19:11 +00:00
|
|
|
"focused child process of parent process or another child process "
|
|
|
|
"getting focus"));
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << sActiveTabParent->SendStopIMEStateManagement();
|
2015-07-01 13:19:11 +00:00
|
|
|
}
|
|
|
|
|
2012-10-30 23:22:22 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget =
|
|
|
|
(sPresContext == aPresContext) ? oldWidget.get() :
|
2013-02-06 02:50:02 +00:00
|
|
|
aPresContext->GetRootWidget();
|
2014-07-16 05:13:28 +00:00
|
|
|
if (NS_WARN_IF(!widget)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), FAILED due to "
|
2014-07-16 05:13:28 +00:00
|
|
|
"no widget to manage its IME state"));
|
2006-04-11 16:37:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
// If a child process has focus, we should disable IME state until the child
|
|
|
|
// process actually gets focus because if user types keys before that they
|
|
|
|
// are handled by IME.
|
|
|
|
IMEState newState =
|
|
|
|
newTabParent ? IMEState(IMEState::DISABLED) :
|
|
|
|
GetNewIMEState(aPresContext, aContent);
|
|
|
|
bool setIMEState = true;
|
|
|
|
|
|
|
|
if (newTabParent) {
|
2015-07-01 13:19:11 +00:00
|
|
|
if (aAction.mFocusChange == InputContextAction::MENU_GOT_PSEUDO_FOCUS ||
|
|
|
|
aAction.mFocusChange == InputContextAction::MENU_LOST_PSEUDO_FOCUS) {
|
|
|
|
// XXX When menu keyboard listener is being uninstalled, IME state needs
|
|
|
|
// to be restored by the child process asynchronously. Therefore,
|
|
|
|
// some key events which are fired immediately after closing menu
|
|
|
|
// may not be handled by IME.
|
2015-11-02 05:53:26 +00:00
|
|
|
Unused << newTabParent->
|
2015-07-01 13:19:11 +00:00
|
|
|
SendMenuKeyboardListenerInstalled(sInstalledMenuKeyboardListener);
|
|
|
|
setIMEState = sInstalledMenuKeyboardListener;
|
|
|
|
} else if (focusActuallyChanging) {
|
2015-07-01 13:19:11 +00:00
|
|
|
InputContext context = widget->GetInputContext();
|
|
|
|
if (context.mIMEState.mEnabled == IMEState::DISABLED) {
|
|
|
|
setIMEState = false;
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), doesn't set IME "
|
2015-07-01 13:19:11 +00:00
|
|
|
"state because focused element (or document) is in a child process "
|
|
|
|
"and the IME state is already disabled"));
|
|
|
|
} else {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), will disable IME "
|
2015-07-01 13:19:11 +00:00
|
|
|
"until new focused element (or document) in the child process "
|
|
|
|
"will get focus actually"));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// When focus is NOT changed actually, we shouldn't set IME state since
|
|
|
|
// that means that the window is being activated and the child process
|
|
|
|
// may have composition. Then, we shouldn't commit the composition with
|
|
|
|
// making IME state disabled.
|
|
|
|
setIMEState = false;
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), doesn't set IME "
|
2015-07-01 13:19:11 +00:00
|
|
|
"state because focused element (or document) is already in the child "
|
|
|
|
"process"));
|
2006-04-11 16:37:58 +00:00
|
|
|
}
|
2015-07-01 13:19:11 +00:00
|
|
|
}
|
2012-10-30 23:22:22 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
if (setIMEState) {
|
|
|
|
if (!focusActuallyChanging) {
|
|
|
|
// actual focus isn't changing, but if IME enabled state is changing,
|
|
|
|
// we should do it.
|
|
|
|
InputContext context = widget->GetInputContext();
|
|
|
|
if (context.mIMEState.mEnabled == newState.mEnabled) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), "
|
2015-07-01 13:19:11 +00:00
|
|
|
"neither focus nor IME state is changing"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
aAction.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
|
|
|
|
|
|
|
|
// Even if focus isn't changing actually, we should commit current
|
|
|
|
// composition here since the IME state is changing.
|
|
|
|
if (sPresContext && oldWidget && !focusActuallyChanging) {
|
|
|
|
NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, oldWidget);
|
|
|
|
}
|
|
|
|
} else if (aAction.mFocusChange == InputContextAction::FOCUS_NOT_CHANGED) {
|
|
|
|
// If aContent isn't null or aContent is null but editable, somebody gets
|
|
|
|
// focus.
|
|
|
|
bool gotFocus = aContent || (newState.mEnabled == IMEState::ENABLED);
|
|
|
|
aAction.mFocusChange =
|
|
|
|
gotFocus ? InputContextAction::GOT_FOCUS :
|
|
|
|
InputContextAction::LOST_FOCUS;
|
2012-10-30 23:22:22 +00:00
|
|
|
}
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
// Update IME state for new focus widget
|
|
|
|
SetIMEState(newState, aContent, widget, aAction);
|
|
|
|
}
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveTabParent = newTabParent;
|
2006-04-11 16:37:58 +00:00
|
|
|
sPresContext = aPresContext;
|
2015-07-01 13:19:11 +00:00
|
|
|
sContent = aContent;
|
2006-04-11 16:37:58 +00:00
|
|
|
|
2015-10-10 01:21:01 +00:00
|
|
|
// Don't call CreateIMEContentObserver() here except when a plugin gets
|
|
|
|
// focus because it will be called from the focus event handler of focused
|
|
|
|
// editor.
|
|
|
|
if (newState.mEnabled == IMEState::PLUGIN) {
|
|
|
|
CreateIMEContentObserver(nullptr);
|
2015-11-10 02:49:05 +00:00
|
|
|
if (sActiveIMEContentObserver) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnChangeFocusInternal(), an "
|
2015-11-10 02:49:05 +00:00
|
|
|
"IMEContentObserver instance is created for plugin and trying to "
|
|
|
|
"flush its pending notifications..."));
|
|
|
|
sActiveIMEContentObserver->TryToFlushPendingNotifications();
|
|
|
|
}
|
2015-10-10 01:21:01 +00:00
|
|
|
}
|
2012-10-26 00:49:13 +00:00
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2007-05-02 15:34:35 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnInstalledMenuKeyboardListener(bool aInstalling)
|
2007-05-02 15:34:35 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnInstalledMenuKeyboardListener(aInstalling=%s), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"sInstalledMenuKeyboardListener=%s",
|
|
|
|
GetBoolName(aInstalling), GetBoolName(sInstalledMenuKeyboardListener)));
|
|
|
|
|
2007-05-02 15:34:35 +00:00
|
|
|
sInstalledMenuKeyboardListener = aInstalling;
|
2011-04-20 12:47:40 +00:00
|
|
|
|
2011-11-27 11:51:52 +00:00
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
aInstalling ? InputContextAction::MENU_GOT_PSEUDO_FOCUS :
|
|
|
|
InputContextAction::MENU_LOST_PSEUDO_FOCUS);
|
|
|
|
OnChangeFocusInternal(sPresContext, sContent, action);
|
2007-05-02 15:34:35 +00:00
|
|
|
}
|
|
|
|
|
2014-08-29 10:08:43 +00:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEStateManager::OnMouseButtonEventInEditor(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
2017-02-08 13:02:49 +00:00
|
|
|
WidgetMouseEvent* aMouseEvent)
|
2014-08-29 10:08:43 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnMouseButtonEventInEditor(aPresContext=0x%p, "
|
2014-08-29 10:08:43 +00:00
|
|
|
"aContent=0x%p, aMouseEvent=0x%p), sPresContext=0x%p, sContent=0x%p",
|
2016-09-20 05:12:09 +00:00
|
|
|
aPresContext, aContent, aMouseEvent, sPresContext.get(), sContent.get()));
|
2014-08-29 10:08:43 +00:00
|
|
|
|
2017-02-08 13:02:49 +00:00
|
|
|
if (NS_WARN_IF(!aMouseEvent)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
|
|
|
(" OnMouseButtonEventInEditor(), aMouseEvent is nullptr"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-29 10:08:43 +00:00
|
|
|
if (sPresContext != aPresContext || sContent != aContent) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnMouseButtonEventInEditor(), "
|
2014-08-29 10:08:43 +00:00
|
|
|
"the mouse event isn't fired on the editor managed by ISM"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sActiveIMEContentObserver) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnMouseButtonEventInEditor(), "
|
2014-08-29 10:08:43 +00:00
|
|
|
"there is no active IMEContentObserver"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sActiveIMEContentObserver->IsManaging(aPresContext, aContent)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnMouseButtonEventInEditor(), "
|
2014-08-29 10:08:43 +00:00
|
|
|
"the active IMEContentObserver isn't managing the editor"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool consumed =
|
2017-02-08 13:02:49 +00:00
|
|
|
sActiveIMEContentObserver->OnMouseButtonEvent(aPresContext, aMouseEvent);
|
2014-08-29 10:08:43 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
if (MOZ_LOG_TEST(sISMLog, LogLevel::Info)) {
|
2015-05-14 17:13:23 +00:00
|
|
|
nsAutoString eventType;
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnMouseButtonEventInEditor(), "
|
2017-02-08 13:02:49 +00:00
|
|
|
"mouse event (mMessage=%s, button=%d) is %s",
|
|
|
|
ToChar(aMouseEvent->mMessage), aMouseEvent->button,
|
2015-05-14 17:13:23 +00:00
|
|
|
consumed ? "consumed" : "not consumed"));
|
|
|
|
}
|
2014-08-29 10:08:43 +00:00
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2011-11-27 11:51:53 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnClickInEditor(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
2017-02-08 13:29:14 +00:00
|
|
|
const WidgetMouseEvent* aMouseEvent)
|
2011-11-27 11:51:53 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnClickInEditor(aPresContext=0x%p, aContent=0x%p, aMouseEvent=0x%p), "
|
|
|
|
"sPresContext=0x%p, sContent=0x%p",
|
2016-09-20 05:12:09 +00:00
|
|
|
aPresContext, aContent, aMouseEvent, sPresContext.get(), sContent.get()));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2017-02-08 13:29:14 +00:00
|
|
|
if (NS_WARN_IF(!aMouseEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-27 11:51:53 +00:00
|
|
|
if (sPresContext != aPresContext || sContent != aContent) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnClickInEditor(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the mouse event isn't fired on the editor managed by ISM"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-06 02:50:02 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = aPresContext->GetRootWidget();
|
2012-09-14 10:00:31 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(widget);
|
2011-11-27 11:51:53 +00:00
|
|
|
|
2017-02-08 13:29:14 +00:00
|
|
|
if (!aMouseEvent->IsTrusted()) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnClickInEditor(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the mouse event isn't a trusted event"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return; // ignore untrusted event.
|
|
|
|
}
|
|
|
|
|
2017-02-08 13:29:14 +00:00
|
|
|
if (aMouseEvent->button) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnClickInEditor(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the mouse event isn't a left mouse button event"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return; // not a left click event.
|
|
|
|
}
|
|
|
|
|
2017-02-08 13:29:14 +00:00
|
|
|
if (aMouseEvent->mClickCount != 1) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnClickInEditor(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the mouse event isn't a single click event"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return; // should notify only first click event.
|
|
|
|
}
|
|
|
|
|
2015-12-08 14:56:27 +00:00
|
|
|
InputContextAction::Cause cause =
|
2017-02-08 13:29:14 +00:00
|
|
|
aMouseEvent->inputSource == nsIDOMMouseEvent::MOZ_SOURCE_TOUCH ?
|
2015-12-08 14:56:27 +00:00
|
|
|
InputContextAction::CAUSE_TOUCH : InputContextAction::CAUSE_MOUSE;
|
|
|
|
|
|
|
|
InputContextAction action(cause, InputContextAction::FOCUS_NOT_CHANGED);
|
2011-11-27 11:51:53 +00:00
|
|
|
IMEState newState = GetNewIMEState(aPresContext, aContent);
|
|
|
|
SetIMEState(newState, aContent, widget, action);
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-10-26 00:49:13 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::OnFocusInEditor(nsPresContext* aPresContext,
|
2014-11-05 13:12:44 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIEditor* aEditor)
|
2012-10-26 00:49:13 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnFocusInEditor(aPresContext=0x%p, aContent=0x%p, aEditor=0x%p), "
|
|
|
|
"sPresContext=0x%p, sContent=0x%p, sActiveIMEContentObserver=0x%p",
|
2016-09-20 05:12:09 +00:00
|
|
|
aPresContext, aContent, aEditor, sPresContext.get(), sContent.get(),
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveIMEContentObserver.get()));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2012-10-26 00:49:13 +00:00
|
|
|
if (sPresContext != aPresContext || sContent != aContent) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnFocusInEditor(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"an editor not managed by ISM gets focus"));
|
2012-10-26 00:49:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
// If the IMEContentObserver instance isn't managing the editor actually,
|
2012-11-09 08:40:39 +00:00
|
|
|
// we need to recreate the instance.
|
2014-03-08 01:20:07 +00:00
|
|
|
if (sActiveIMEContentObserver) {
|
|
|
|
if (sActiveIMEContentObserver->IsManaging(aPresContext, aContent)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnFocusInEditor(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the editor is already being managed by sActiveIMEContentObserver"));
|
2012-11-09 08:40:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-16 05:13:28 +00:00
|
|
|
DestroyIMEContentObserver();
|
2012-11-09 08:40:39 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 13:12:44 +00:00
|
|
|
CreateIMEContentObserver(aEditor);
|
2015-11-10 02:49:05 +00:00
|
|
|
|
|
|
|
// Let's flush the focus notification now.
|
|
|
|
if (sActiveIMEContentObserver) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnFocusInEditor(), new IMEContentObserver is "
|
2015-11-10 02:49:05 +00:00
|
|
|
"created, trying to flush pending notifications..."));
|
|
|
|
sActiveIMEContentObserver->TryToFlushPendingNotifications();
|
|
|
|
}
|
2012-10-26 00:49:13 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 17:06:10 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::OnEditorInitialized(nsIEditor* aEditor)
|
|
|
|
{
|
|
|
|
if (!sActiveIMEContentObserver ||
|
|
|
|
sActiveIMEContentObserver->GetEditor() != aEditor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnEditorInitialized(aEditor=0x%p)",
|
2015-06-04 17:06:10 +00:00
|
|
|
aEditor));
|
|
|
|
|
|
|
|
sActiveIMEContentObserver->UnsuppressNotifyingIME();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::OnEditorDestroying(nsIEditor* aEditor)
|
|
|
|
{
|
|
|
|
if (!sActiveIMEContentObserver ||
|
|
|
|
sActiveIMEContentObserver->GetEditor() != aEditor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnEditorDestroying(aEditor=0x%p)",
|
2015-06-04 17:06:10 +00:00
|
|
|
aEditor));
|
|
|
|
|
|
|
|
// The IMEContentObserver shouldn't notify IME of anything until reframing
|
|
|
|
// is finished.
|
|
|
|
sActiveIMEContentObserver->SuppressNotifyingIME();
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2010-05-04 17:40:39 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::UpdateIMEState(const IMEState& aNewIMEState,
|
2014-11-05 13:12:44 +00:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIEditor* aEditor)
|
2010-05-04 17:40:39 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("UpdateIMEState(aNewIMEState={ mEnabled=%s, "
|
2014-11-05 13:12:44 +00:00
|
|
|
"mOpen=%s }, aContent=0x%p, aEditor=0x%p), "
|
2014-07-17 05:08:44 +00:00
|
|
|
"sPresContext=0x%p, sContent=0x%p, sActiveIMEContentObserver=0x%p, "
|
|
|
|
"sIsGettingNewIMEState=%s",
|
2014-07-16 05:13:28 +00:00
|
|
|
GetIMEStateEnabledName(aNewIMEState.mEnabled),
|
2014-11-05 13:12:44 +00:00
|
|
|
GetIMEStateSetOpenName(aNewIMEState.mOpen), aContent, aEditor,
|
2016-09-20 05:12:09 +00:00
|
|
|
sPresContext.get(), sContent.get(), sActiveIMEContentObserver.get(),
|
2014-07-17 05:08:44 +00:00
|
|
|
GetBoolName(sIsGettingNewIMEState)));
|
|
|
|
|
|
|
|
if (sIsGettingNewIMEState) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" UpdateIMEState(), "
|
2014-07-17 05:08:44 +00:00
|
|
|
"does nothing because of called while getting new IME state"));
|
|
|
|
return;
|
|
|
|
}
|
2014-07-16 05:13:28 +00:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!sPresContext)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" UpdateIMEState(), FAILED due to "
|
2014-07-16 05:13:28 +00:00
|
|
|
"no managing nsPresContext"));
|
2010-05-04 17:40:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-02-06 02:50:02 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = sPresContext->GetRootWidget();
|
2014-07-16 05:13:28 +00:00
|
|
|
if (NS_WARN_IF(!widget)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" UpdateIMEState(), FAILED due to "
|
2014-07-16 05:13:28 +00:00
|
|
|
"no widget for the managing nsPresContext"));
|
2010-05-04 17:40:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-26 07:45:26 +00:00
|
|
|
// Even if there is active IMEContentObserver, it may not be observing the
|
|
|
|
// editor with current editable root content due to reframed. In such case,
|
|
|
|
// We should try to reinitialize the IMEContentObserver.
|
|
|
|
if (sActiveIMEContentObserver && IsIMEObserverNeeded(aNewIMEState)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" UpdateIMEState(), try to reinitialize the "
|
2015-05-26 07:45:26 +00:00
|
|
|
"active IMEContentObserver"));
|
|
|
|
if (!sActiveIMEContentObserver->MaybeReinitialize(widget, sPresContext,
|
|
|
|
aContent, aEditor)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" UpdateIMEState(), failed to reinitialize the "
|
2015-05-26 07:45:26 +00:00
|
|
|
"active IMEContentObserver"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no active IMEContentObserver or it isn't observing the
|
|
|
|
// editor correctly, we should recreate it.
|
2012-11-09 08:40:39 +00:00
|
|
|
bool createTextStateManager =
|
2014-03-08 01:20:07 +00:00
|
|
|
(!sActiveIMEContentObserver ||
|
|
|
|
!sActiveIMEContentObserver->IsManaging(sPresContext, aContent));
|
2010-05-27 02:04:14 +00:00
|
|
|
|
2012-11-09 08:40:39 +00:00
|
|
|
bool updateIMEState =
|
|
|
|
(widget->GetInputContext().mIMEState.mEnabled != aNewIMEState.mEnabled);
|
2010-05-04 17:40:39 +00:00
|
|
|
|
2012-11-09 08:40:39 +00:00
|
|
|
if (updateIMEState) {
|
|
|
|
// commit current composition before modifying IME state.
|
|
|
|
NotifyIME(REQUEST_TO_COMMIT_COMPOSITION, widget);
|
|
|
|
}
|
2012-10-26 00:49:13 +00:00
|
|
|
|
2012-11-09 08:40:39 +00:00
|
|
|
if (createTextStateManager) {
|
2014-07-16 05:13:28 +00:00
|
|
|
DestroyIMEContentObserver();
|
2012-11-09 08:40:39 +00:00
|
|
|
}
|
2012-10-26 00:49:13 +00:00
|
|
|
|
2012-11-09 08:40:39 +00:00
|
|
|
if (updateIMEState) {
|
|
|
|
InputContextAction action(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::FOCUS_NOT_CHANGED);
|
|
|
|
SetIMEState(aNewIMEState, aContent, widget, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (createTextStateManager) {
|
2015-11-10 02:49:05 +00:00
|
|
|
// XXX In this case, it might not be enough safe to notify IME of anything.
|
|
|
|
// So, don't try to flush pending notifications of IMEContentObserver
|
|
|
|
// here.
|
2014-11-05 13:12:44 +00:00
|
|
|
CreateIMEContentObserver(aEditor);
|
2012-11-09 08:40:39 +00:00
|
|
|
}
|
2010-05-04 17:40:39 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2011-11-27 11:51:53 +00:00
|
|
|
IMEState
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::GetNewIMEState(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
2006-04-11 16:37:58 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("GetNewIMEState(aPresContext=0x%p, aContent=0x%p), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"sInstalledMenuKeyboardListener=%s",
|
|
|
|
aPresContext, aContent, GetBoolName(sInstalledMenuKeyboardListener)));
|
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
// On Printing or Print Preview, we don't need IME.
|
|
|
|
if (aPresContext->Type() == nsPresContext::eContext_PrintPreview ||
|
|
|
|
aPresContext->Type() == nsPresContext::eContext_Print) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" GetNewIMEState() returns DISABLED because "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the nsPresContext is for print or print preview"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return IMEState(IMEState::DISABLED);
|
2006-04-11 16:37:58 +00:00
|
|
|
}
|
|
|
|
|
2011-11-27 11:51:53 +00:00
|
|
|
if (sInstalledMenuKeyboardListener) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" GetNewIMEState() returns DISABLED because "
|
2014-07-16 05:13:28 +00:00
|
|
|
"menu keyboard listener was installed"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return IMEState(IMEState::DISABLED);
|
|
|
|
}
|
2007-05-02 15:34:35 +00:00
|
|
|
|
2008-02-13 12:51:00 +00:00
|
|
|
if (!aContent) {
|
|
|
|
// Even if there are no focused content, the focused document might be
|
|
|
|
// editable, such case is design mode.
|
|
|
|
nsIDocument* doc = aPresContext->Document();
|
2011-11-27 11:51:53 +00:00
|
|
|
if (doc && doc->HasFlag(NODE_IS_EDITABLE)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" GetNewIMEState() returns ENABLED because "
|
2014-07-16 05:13:28 +00:00
|
|
|
"design mode editor has focus"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return IMEState(IMEState::ENABLED);
|
|
|
|
}
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" GetNewIMEState() returns DISABLED because "
|
2014-07-16 05:13:28 +00:00
|
|
|
"no content has focus"));
|
2011-11-27 11:51:53 +00:00
|
|
|
return IMEState(IMEState::DISABLED);
|
2008-02-13 12:51:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-17 05:08:44 +00:00
|
|
|
// nsIContent::GetDesiredIMEState() may cause a call of UpdateIMEState()
|
2016-07-08 04:10:13 +00:00
|
|
|
// from EditorBase::PostCreate() because GetDesiredIMEState() needs to
|
|
|
|
// retrieve an editor instance for the element if it's editable element.
|
2014-07-17 05:08:44 +00:00
|
|
|
// For avoiding such nested IME state updates, we should set
|
|
|
|
// sIsGettingNewIMEState here and UpdateIMEState() should check it.
|
|
|
|
GettingNewIMEStateBlocker blocker;
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
IMEState newIMEState = aContent->GetDesiredIMEState();
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" GetNewIMEState() returns { mEnabled=%s, "
|
2014-07-16 05:13:28 +00:00
|
|
|
"mOpen=%s }",
|
|
|
|
GetIMEStateEnabledName(newIMEState.mEnabled),
|
|
|
|
GetIMEStateSetOpenName(newIMEState.mOpen)));
|
|
|
|
return newIMEState;
|
2006-04-11 16:37:58 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 23:02:39 +00:00
|
|
|
static bool
|
|
|
|
MayBeIMEUnawareWebApp(nsINode* aNode)
|
|
|
|
{
|
|
|
|
bool haveKeyEventsListener = false;
|
|
|
|
|
|
|
|
while (aNode) {
|
|
|
|
EventListenerManager* const mgr = aNode->GetExistingListenerManager();
|
|
|
|
if (mgr) {
|
|
|
|
if (mgr->MayHaveInputOrCompositionEventListener()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
haveKeyEventsListener |= mgr->MayHaveKeyEventListener();
|
|
|
|
}
|
|
|
|
aNode = aNode->GetParentNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return haveKeyEventsListener;
|
|
|
|
}
|
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::SetInputContextForChildProcess(
|
|
|
|
TabParent* aTabParent,
|
|
|
|
const InputContext& aInputContext,
|
|
|
|
const InputContextAction& aAction)
|
|
|
|
{
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("SetInputContextForChildProcess(aTabParent=0x%p, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"aInputContext={ mIMEState={ mEnabled=%s, mOpen=%s }, "
|
|
|
|
"mHTMLInputType=\"%s\", mHTMLInputInputmode=\"%s\", mActionHint=\"%s\" }, "
|
2016-12-16 03:16:31 +00:00
|
|
|
"aAction={ mCause=%s, mAction=%s }), sPresContext=0x%p, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"sActiveTabParent=0x%p",
|
|
|
|
aTabParent, GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled),
|
|
|
|
GetIMEStateSetOpenName(aInputContext.mIMEState.mOpen),
|
|
|
|
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(),
|
|
|
|
GetActionCauseName(aAction.mCause),
|
|
|
|
GetActionFocusChangeName(aAction.mFocusChange),
|
2016-09-20 05:12:09 +00:00
|
|
|
sPresContext.get(), sActiveTabParent.get()));
|
2015-07-01 13:19:11 +00:00
|
|
|
|
2015-07-16 05:29:18 +00:00
|
|
|
if (aTabParent != sActiveTabParent) {
|
2015-07-01 13:19:11 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" SetInputContextForChildProcess(), FAILED, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"because non-focused tab parent tries to set input context"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!sPresContext)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" SetInputContextForChildProcess(), FAILED, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"due to no focused presContext"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = sPresContext->GetRootWidget();
|
|
|
|
if (NS_WARN_IF(!widget)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" SetInputContextForChildProcess(), FAILED, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"due to no widget in the focused presContext"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aInputContext.mOrigin == InputContext::ORIGIN_CONTENT);
|
|
|
|
|
|
|
|
SetInputContext(widget, aInputContext, aAction);
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2006-04-11 16:37:58 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::SetIMEState(const IMEState& aState,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIWidget* aWidget,
|
|
|
|
InputContextAction aAction)
|
2006-04-11 16:37:58 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("SetIMEState(aState={ mEnabled=%s, mOpen=%s }, "
|
2015-07-01 13:19:11 +00:00
|
|
|
"aContent=0x%p (TabParent=0x%p), aWidget=0x%p, aAction={ mCause=%s, "
|
|
|
|
"mFocusChange=%s })",
|
2014-07-16 05:13:28 +00:00
|
|
|
GetIMEStateEnabledName(aState.mEnabled),
|
2015-07-01 13:19:11 +00:00
|
|
|
GetIMEStateSetOpenName(aState.mOpen), aContent,
|
|
|
|
TabParent::GetFrom(aContent), aWidget,
|
2014-07-16 05:13:28 +00:00
|
|
|
GetActionCauseName(aAction.mCause),
|
|
|
|
GetActionFocusChangeName(aAction.mFocusChange)));
|
|
|
|
|
2012-09-14 10:00:31 +00:00
|
|
|
NS_ENSURE_TRUE_VOID(aWidget);
|
2011-11-27 11:51:53 +00:00
|
|
|
|
|
|
|
InputContext context;
|
2011-11-27 11:51:53 +00:00
|
|
|
context.mIMEState = aState;
|
2015-06-16 23:02:39 +00:00
|
|
|
context.mMayBeIMEUnaware = context.mIMEState.IsEditable() &&
|
|
|
|
sCheckForIMEUnawareWebApps && MayBeIMEUnawareWebApp(aContent);
|
2011-11-27 11:51:53 +00:00
|
|
|
|
2015-03-03 11:09:00 +00:00
|
|
|
if (aContent &&
|
|
|
|
aContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea)) {
|
|
|
|
if (!aContent->IsHTMLElement(nsGkAtoms::textarea)) {
|
2013-11-20 09:32:46 +00:00
|
|
|
// <input type=number> has an anonymous <input type=text> descendant
|
|
|
|
// that gets focus whenever anyone tries to focus the number control. We
|
|
|
|
// need to check if aContent is one of those anonymous text controls and,
|
|
|
|
// if so, use the number control instead:
|
|
|
|
nsIContent* content = aContent;
|
|
|
|
HTMLInputElement* inputElement =
|
|
|
|
HTMLInputElement::FromContentOrNull(aContent);
|
|
|
|
if (inputElement) {
|
|
|
|
HTMLInputElement* ownerNumberControl =
|
|
|
|
inputElement->GetOwnerNumberControl();
|
|
|
|
if (ownerNumberControl) {
|
|
|
|
content = ownerNumberControl; // an <input type=number>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
context.mHTMLInputType);
|
2013-03-29 16:00:59 +00:00
|
|
|
} else {
|
|
|
|
context.mHTMLInputType.Assign(nsGkAtoms::textarea->GetUTF16String());
|
|
|
|
}
|
2013-05-01 15:58:30 +00:00
|
|
|
|
2016-02-01 17:57:29 +00:00
|
|
|
if (Preferences::GetBool("dom.forms.inputmode", false) ||
|
|
|
|
nsContentUtils::IsChromeDoc(aContent->OwnerDoc())) {
|
2013-05-01 15:58:30 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::inputmode,
|
|
|
|
context.mHTMLInputInputmode);
|
|
|
|
}
|
|
|
|
|
2011-11-27 11:51:53 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::moz_action_hint,
|
|
|
|
context.mActionHint);
|
|
|
|
|
2014-07-18 16:53:41 +00:00
|
|
|
// Get the input content corresponding to the focused node,
|
|
|
|
// which may be an anonymous child of the input content.
|
|
|
|
nsIContent* inputContent = aContent->FindFirstNonChromeOnlyAccessContent();
|
|
|
|
|
|
|
|
// If we don't have an action hint and
|
|
|
|
// return won't submit the form, use "next".
|
|
|
|
if (context.mActionHint.IsEmpty() &&
|
2015-03-03 11:09:00 +00:00
|
|
|
inputContent->IsHTMLElement(nsGkAtoms::input)) {
|
2011-11-27 11:51:53 +00:00
|
|
|
bool willSubmit = false;
|
2014-07-18 16:53:41 +00:00
|
|
|
nsCOMPtr<nsIFormControl> control(do_QueryInterface(inputContent));
|
2016-06-07 06:03:34 +00:00
|
|
|
mozilla::dom::Element* formElement = nullptr;
|
2011-11-27 11:51:53 +00:00
|
|
|
nsCOMPtr<nsIForm> form;
|
|
|
|
if (control) {
|
2016-06-07 06:03:34 +00:00
|
|
|
formElement = control->GetFormElement();
|
2011-11-27 11:51:53 +00:00
|
|
|
// is this a form and does it have a default submit element?
|
2014-03-08 01:20:08 +00:00
|
|
|
if ((form = do_QueryInterface(formElement)) &&
|
|
|
|
form->GetDefaultSubmitElement()) {
|
2011-11-27 11:51:53 +00:00
|
|
|
willSubmit = true;
|
|
|
|
// is this an html form and does it only have a single text input element?
|
2015-03-03 11:09:00 +00:00
|
|
|
} else if (formElement && formElement->IsHTMLElement(nsGkAtoms::form) &&
|
2014-03-08 01:20:08 +00:00
|
|
|
!static_cast<dom::HTMLFormElement*>(formElement)->
|
|
|
|
ImplicitSubmissionIsDisabled()) {
|
2011-11-27 11:51:53 +00:00
|
|
|
willSubmit = true;
|
2011-01-31 14:23:58 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 01:20:08 +00:00
|
|
|
context.mActionHint.Assign(
|
2017-04-01 02:49:00 +00:00
|
|
|
willSubmit ? (control->ControlType() == NS_FORM_INPUT_SEARCH ?
|
2014-03-08 01:20:08 +00:00
|
|
|
NS_LITERAL_STRING("search") : NS_LITERAL_STRING("go")) :
|
|
|
|
(formElement ?
|
|
|
|
NS_LITERAL_STRING("next") : EmptyString()));
|
2010-11-23 06:48:03 +00:00
|
|
|
}
|
2011-11-27 11:51:53 +00:00
|
|
|
}
|
2010-11-23 06:48:03 +00:00
|
|
|
|
2011-11-27 11:51:53 +00:00
|
|
|
// XXX I think that we should use nsContentUtils::IsCallerChrome() instead
|
|
|
|
// of the process type.
|
|
|
|
if (aAction.mCause == InputContextAction::CAUSE_UNKNOWN &&
|
2015-07-04 01:29:00 +00:00
|
|
|
!XRE_IsContentProcess()) {
|
2011-11-27 11:51:53 +00:00
|
|
|
aAction.mCause = InputContextAction::CAUSE_UNKNOWN_CHROME;
|
2006-04-11 16:37:58 +00:00
|
|
|
}
|
2011-11-27 11:51:53 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
SetInputContext(aWidget, context, aAction);
|
|
|
|
}
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2015-07-01 13:19:11 +00:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::SetInputContext(nsIWidget* aWidget,
|
|
|
|
const InputContext& aInputContext,
|
|
|
|
const InputContextAction& aAction)
|
|
|
|
{
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("SetInputContext(aWidget=0x%p, aInputContext={ "
|
2015-07-01 13:19:11 +00:00
|
|
|
"mIMEState={ mEnabled=%s, mOpen=%s }, mHTMLInputType=\"%s\", "
|
|
|
|
"mHTMLInputInputmode=\"%s\", mActionHint=\"%s\" }, "
|
|
|
|
"aAction={ mCause=%s, mAction=%s }), sActiveTabParent=0x%p",
|
|
|
|
aWidget,
|
|
|
|
GetIMEStateEnabledName(aInputContext.mIMEState.mEnabled),
|
|
|
|
GetIMEStateSetOpenName(aInputContext.mIMEState.mOpen),
|
|
|
|
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputType).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aInputContext.mHTMLInputInputmode).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(aInputContext.mActionHint).get(),
|
2014-07-16 05:13:28 +00:00
|
|
|
GetActionCauseName(aAction.mCause),
|
2015-07-01 13:19:11 +00:00
|
|
|
GetActionFocusChangeName(aAction.mFocusChange),
|
|
|
|
sActiveTabParent.get()));
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(aWidget);
|
|
|
|
|
|
|
|
aWidget->SetInputContext(aInputContext, aAction);
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 02:27:56 +00:00
|
|
|
sActiveInputContextWidget = aWidget;
|
2006-04-11 16:37:58 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-09-26 05:47:45 +00:00
|
|
|
void
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::EnsureTextCompositionArray()
|
2012-09-26 05:47:45 +00:00
|
|
|
{
|
|
|
|
if (sTextCompositions) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sTextCompositions = new TextCompositionArray();
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-09-26 05:47:45 +00:00
|
|
|
void
|
2014-10-07 10:01:49 +00:00
|
|
|
IMEStateManager::DispatchCompositionEvent(
|
|
|
|
nsINode* aEventTargetNode,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetCompositionEvent* aCompositionEvent,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
EventDispatchingCallback* aCallBack,
|
|
|
|
bool aIsSynthesized)
|
2012-09-26 05:47:45 +00:00
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TabParent> tabParent =
|
2015-07-03 02:49:36 +00:00
|
|
|
aEventTargetNode->IsContent() ?
|
|
|
|
TabParent::GetFrom(aEventTargetNode->AsContent()) : nullptr;
|
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("DispatchCompositionEvent(aNode=0x%p, "
|
2015-12-11 06:15:57 +00:00
|
|
|
"aPresContext=0x%p, aCompositionEvent={ mMessage=%s, "
|
2016-12-16 03:16:31 +00:00
|
|
|
"mNativeIMEContext={ mRawNativeIMEContext=0x%" PRIXPTR ", "
|
|
|
|
"mOriginProcessID=0x%" PRIX64 " }, mWidget(0x%p)={ "
|
|
|
|
"GetNativeIMEContext()={ mRawNativeIMEContext=0x%" PRIXPTR ", "
|
|
|
|
"mOriginProcessID=0x%" PRIX64 " }, Destroyed()=%s }, "
|
2014-09-26 00:05:11 +00:00
|
|
|
"mFlags={ mIsTrusted=%s, mPropagationStopped=%s } }, "
|
2015-07-03 02:49:36 +00:00
|
|
|
"aIsSynthesized=%s), tabParent=%p",
|
2014-07-16 05:13:28 +00:00
|
|
|
aEventTargetNode, aPresContext,
|
2015-09-17 03:05:44 +00:00
|
|
|
ToChar(aCompositionEvent->mMessage),
|
2015-12-11 06:15:57 +00:00
|
|
|
aCompositionEvent->mNativeIMEContext.mRawNativeIMEContext,
|
|
|
|
aCompositionEvent->mNativeIMEContext.mOriginProcessID,
|
2016-04-14 08:03:14 +00:00
|
|
|
aCompositionEvent->mWidget.get(),
|
|
|
|
aCompositionEvent->mWidget->GetNativeIMEContext().mRawNativeIMEContext,
|
|
|
|
aCompositionEvent->mWidget->GetNativeIMEContext().mOriginProcessID,
|
|
|
|
GetBoolName(aCompositionEvent->mWidget->Destroyed()),
|
2014-10-07 10:01:49 +00:00
|
|
|
GetBoolName(aCompositionEvent->mFlags.mIsTrusted),
|
|
|
|
GetBoolName(aCompositionEvent->mFlags.mPropagationStopped),
|
2015-07-03 02:49:36 +00:00
|
|
|
GetBoolName(aIsSynthesized), tabParent.get()));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2016-03-17 07:01:30 +00:00
|
|
|
if (!aCompositionEvent->IsTrusted() ||
|
2016-03-17 07:21:57 +00:00
|
|
|
aCompositionEvent->PropagationStopped()) {
|
2012-09-26 05:47:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-11 12:21:27 +00:00
|
|
|
MOZ_ASSERT(aCompositionEvent->mMessage != eCompositionUpdate,
|
2014-10-03 06:33:49 +00:00
|
|
|
"compositionupdate event shouldn't be dispatched manually");
|
2014-10-03 06:33:47 +00:00
|
|
|
|
2012-09-26 05:47:45 +00:00
|
|
|
EnsureTextCompositionArray();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextComposition> composition =
|
2015-12-04 09:50:34 +00:00
|
|
|
sTextCompositions->GetCompositionFor(aCompositionEvent);
|
2012-09-26 05:47:45 +00:00
|
|
|
if (!composition) {
|
2014-09-26 00:05:11 +00:00
|
|
|
// If synthesized event comes after delayed native composition events
|
|
|
|
// for request of commit or cancel, we should ignore it.
|
|
|
|
if (NS_WARN_IF(aIsSynthesized)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" DispatchCompositionEvent(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"adding new TextComposition to the array"));
|
2015-09-11 12:21:27 +00:00
|
|
|
MOZ_ASSERT(aCompositionEvent->mMessage == eCompositionStart);
|
2014-10-07 10:01:49 +00:00
|
|
|
composition =
|
2015-07-03 02:49:36 +00:00
|
|
|
new TextComposition(aPresContext, aEventTargetNode, tabParent,
|
|
|
|
aCompositionEvent);
|
2014-01-28 08:19:29 +00:00
|
|
|
sTextCompositions->AppendElement(composition);
|
2012-09-26 05:47:45 +00:00
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
2015-09-11 12:21:27 +00:00
|
|
|
MOZ_ASSERT(aCompositionEvent->mMessage != eCompositionStart);
|
2012-09-26 05:47:45 +00:00
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
|
|
|
// Dispatch the event on composing target.
|
2014-10-07 10:01:49 +00:00
|
|
|
composition->DispatchCompositionEvent(aCompositionEvent, aStatus, aCallBack,
|
|
|
|
aIsSynthesized);
|
2012-09-26 05:47:45 +00:00
|
|
|
|
|
|
|
// WARNING: the |composition| might have been destroyed already.
|
|
|
|
|
|
|
|
// Remove the ended composition from the array.
|
2014-09-26 00:05:11 +00:00
|
|
|
// NOTE: When TextComposition is synthesizing compositionend event for
|
|
|
|
// emulating a commit, the instance shouldn't be removed from the array
|
|
|
|
// because IME may perform it later. Then, we need to ignore the
|
|
|
|
// following commit events in TextComposition::DispatchEvent().
|
2014-09-26 00:05:12 +00:00
|
|
|
// However, if commit or cancel for a request is performed synchronously
|
|
|
|
// during not safe to dispatch events, PresShell must have discarded
|
|
|
|
// compositionend event. Then, the synthesized compositionend event is
|
|
|
|
// the last event for the composition. In this case, we need to
|
|
|
|
// destroy the TextComposition with synthesized compositionend event.
|
|
|
|
if ((!aIsSynthesized ||
|
|
|
|
composition->WasNativeCompositionEndEventDiscarded()) &&
|
2014-11-25 05:02:30 +00:00
|
|
|
aCompositionEvent->CausesDOMCompositionEndEvent()) {
|
2012-09-26 05:47:45 +00:00
|
|
|
TextCompositionArray::index_type i =
|
2016-04-14 08:03:14 +00:00
|
|
|
sTextCompositions->IndexOf(aCompositionEvent->mWidget);
|
2012-09-26 05:47:45 +00:00
|
|
|
if (i != TextCompositionArray::NoIndex) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" DispatchCompositionEvent(), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"removing TextComposition from the array since NS_COMPOSTION_END "
|
|
|
|
"was dispatched"));
|
2014-02-25 06:59:28 +00:00
|
|
|
sTextCompositions->ElementAt(i)->Destroy();
|
2012-09-26 05:47:45 +00:00
|
|
|
sTextCompositions->RemoveElementAt(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 13:14:41 +00:00
|
|
|
// static
|
|
|
|
IMEContentObserver*
|
|
|
|
IMEStateManager::GetActiveContentObserver()
|
|
|
|
{
|
|
|
|
return sActiveIMEContentObserver;
|
|
|
|
}
|
|
|
|
|
2015-07-17 02:25:00 +00:00
|
|
|
// static
|
|
|
|
nsIContent*
|
|
|
|
IMEStateManager::GetRootContent(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIDocument* doc = aPresContext->Document();
|
|
|
|
if (NS_WARN_IF(!doc)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return doc->GetRootElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEStateManager::HandleSelectionEvent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aEventTargetContent,
|
|
|
|
WidgetSelectionEvent* aSelectionEvent)
|
|
|
|
{
|
|
|
|
nsIContent* eventTargetContent =
|
|
|
|
aEventTargetContent ? aEventTargetContent :
|
|
|
|
GetRootContent(aPresContext);
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TabParent> tabParent =
|
2015-07-17 02:25:00 +00:00
|
|
|
eventTargetContent ? TabParent::GetFrom(eventTargetContent) : nullptr;
|
|
|
|
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("HandleSelectionEvent(aPresContext=0x%p, "
|
2015-08-22 01:34:51 +00:00
|
|
|
"aEventTargetContent=0x%p, aSelectionEvent={ mMessage=%s, "
|
2015-07-17 02:25:00 +00:00
|
|
|
"mFlags={ mIsTrusted=%s } }), tabParent=%p",
|
|
|
|
aPresContext, aEventTargetContent,
|
2015-09-17 03:05:44 +00:00
|
|
|
ToChar(aSelectionEvent->mMessage),
|
2015-07-17 02:25:00 +00:00
|
|
|
GetBoolName(aSelectionEvent->mFlags.mIsTrusted),
|
|
|
|
tabParent.get()));
|
|
|
|
|
2016-03-17 07:01:30 +00:00
|
|
|
if (!aSelectionEvent->IsTrusted()) {
|
2015-07-17 02:25:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextComposition> composition = sTextCompositions ?
|
2016-04-14 08:03:14 +00:00
|
|
|
sTextCompositions->GetCompositionFor(aSelectionEvent->mWidget) : nullptr;
|
2015-07-17 02:25:00 +00:00
|
|
|
if (composition) {
|
|
|
|
// When there is a composition, TextComposition should guarantee that the
|
|
|
|
// selection event will be handled in same target as composition events.
|
|
|
|
composition->HandleSelectionEvent(aSelectionEvent);
|
|
|
|
} else {
|
|
|
|
// When there is no composition, the selection event should be handled
|
|
|
|
// in the aPresContext or tabParent.
|
|
|
|
TextComposition::HandleSelectionEvent(aPresContext, tabParent,
|
|
|
|
aSelectionEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-26 00:05:12 +00:00
|
|
|
// static
|
|
|
|
void
|
2014-10-07 10:01:49 +00:00
|
|
|
IMEStateManager::OnCompositionEventDiscarded(
|
2015-07-03 02:49:36 +00:00
|
|
|
WidgetCompositionEvent* aCompositionEvent)
|
2014-09-26 00:05:12 +00:00
|
|
|
{
|
|
|
|
// Note that this method is never called for synthesized events for emulating
|
|
|
|
// commit or cancel composition.
|
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("OnCompositionEventDiscarded(aCompositionEvent={ "
|
2016-12-16 03:16:31 +00:00
|
|
|
"mMessage=%s, mNativeIMEContext={ mRawNativeIMEContext=0x%" PRIXPTR ", "
|
|
|
|
"mOriginProcessID=0x%" PRIX64 " }, mWidget(0x%p)={ "
|
|
|
|
"GetNativeIMEContext()={ mRawNativeIMEContext=0x%" PRIXPTR ", "
|
|
|
|
"mOriginProcessID=0x%" PRIX64 " }, Destroyed()=%s }, "
|
2015-12-11 06:15:57 +00:00
|
|
|
"mFlags={ mIsTrusted=%s } })",
|
2015-09-17 03:05:44 +00:00
|
|
|
ToChar(aCompositionEvent->mMessage),
|
2015-12-11 06:15:57 +00:00
|
|
|
aCompositionEvent->mNativeIMEContext.mRawNativeIMEContext,
|
|
|
|
aCompositionEvent->mNativeIMEContext.mOriginProcessID,
|
2016-04-14 08:03:14 +00:00
|
|
|
aCompositionEvent->mWidget.get(),
|
|
|
|
aCompositionEvent->mWidget->GetNativeIMEContext().mRawNativeIMEContext,
|
|
|
|
aCompositionEvent->mWidget->GetNativeIMEContext().mOriginProcessID,
|
|
|
|
GetBoolName(aCompositionEvent->mWidget->Destroyed()),
|
2014-10-07 10:01:49 +00:00
|
|
|
GetBoolName(aCompositionEvent->mFlags.mIsTrusted)));
|
2014-09-26 00:05:12 +00:00
|
|
|
|
2016-03-17 07:01:30 +00:00
|
|
|
if (!aCompositionEvent->IsTrusted()) {
|
2014-09-26 00:05:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore compositionstart for now because sTextCompositions may not have
|
|
|
|
// been created yet.
|
2015-09-11 12:21:27 +00:00
|
|
|
if (aCompositionEvent->mMessage == eCompositionStart) {
|
2014-09-26 00:05:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextComposition> composition =
|
2016-04-14 08:03:14 +00:00
|
|
|
sTextCompositions->GetCompositionFor(aCompositionEvent->mWidget);
|
2014-10-14 15:40:06 +00:00
|
|
|
if (!composition) {
|
|
|
|
// If the PresShell has been being destroyed during composition,
|
|
|
|
// a TextComposition instance for the composition was already removed from
|
|
|
|
// the array and destroyed in OnDestroyPresContext(). Therefore, we may
|
|
|
|
// fail to retrieve a TextComposition instance here.
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" OnCompositionEventDiscarded(), "
|
2014-10-14 15:40:06 +00:00
|
|
|
"TextComposition instance for the widget has already gone"));
|
|
|
|
return;
|
|
|
|
}
|
2014-10-07 10:01:49 +00:00
|
|
|
composition->OnCompositionEventDiscarded(aCompositionEvent);
|
2014-09-26 00:05:12 +00:00
|
|
|
}
|
|
|
|
|
2012-09-26 05:47:51 +00:00
|
|
|
// static
|
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::NotifyIME(IMEMessage aMessage,
|
2015-06-27 00:23:31 +00:00
|
|
|
nsIWidget* aWidget,
|
|
|
|
bool aOriginIsRemote)
|
2012-09-26 05:47:51 +00:00
|
|
|
{
|
2015-06-27 00:23:31 +00:00
|
|
|
return IMEStateManager::NotifyIME(IMENotification(aMessage), aWidget,
|
|
|
|
aOriginIsRemote);
|
|
|
|
}
|
2014-09-26 00:05:12 +00:00
|
|
|
|
2015-06-27 00:23:31 +00:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IMEStateManager::NotifyIME(const IMENotification& aNotification,
|
|
|
|
nsIWidget* aWidget,
|
|
|
|
bool aOriginIsRemote)
|
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("NotifyIME(aNotification={ mMessage=%s }, "
|
2015-06-27 00:23:31 +00:00
|
|
|
"aWidget=0x%p, aOriginIsRemote=%s), sFocusedIMEWidget=0x%p, "
|
|
|
|
"sRemoteHasFocus=%s",
|
2016-05-31 02:39:15 +00:00
|
|
|
ToChar(aNotification.mMessage), aWidget,
|
2015-11-13 04:05:54 +00:00
|
|
|
GetBoolName(aOriginIsRemote), sFocusedIMEWidget,
|
2015-06-27 00:23:31 +00:00
|
|
|
GetBoolName(sRemoteHasFocus)));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!aWidget)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED due to no widget"));
|
2014-07-16 05:13:28 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2015-06-27 00:23:31 +00:00
|
|
|
switch (aNotification.mMessage) {
|
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
2015-06-27 00:23:31 +00:00
|
|
|
if (sFocusedIMEWidget) {
|
|
|
|
if (NS_WARN_IF(!sRemoteHasFocus && !aOriginIsRemote)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), although, this process is "
|
2015-06-27 00:23:31 +00:00
|
|
|
"getting IME focus but there was focused IME widget"));
|
|
|
|
} else {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), tries to notify IME of "
|
2015-06-27 00:23:31 +00:00
|
|
|
"blur first because remote process's blur notification hasn't "
|
|
|
|
"been received yet..."));
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWidget> focusedIMEWidget(sFocusedIMEWidget);
|
|
|
|
sFocusedIMEWidget = nullptr;
|
|
|
|
sRemoteHasFocus = false;
|
|
|
|
focusedIMEWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR));
|
|
|
|
}
|
|
|
|
sRemoteHasFocus = aOriginIsRemote;
|
|
|
|
sFocusedIMEWidget = aWidget;
|
|
|
|
return aWidget->NotifyIME(aNotification);
|
|
|
|
case NOTIFY_IME_OF_BLUR: {
|
|
|
|
if (!sRemoteHasFocus && aOriginIsRemote) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), received blur notification "
|
2015-06-27 00:23:31 +00:00
|
|
|
"after another one has focus, nothing to do..."));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(sRemoteHasFocus && !aOriginIsRemote)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED, received blur "
|
2015-06-27 00:23:31 +00:00
|
|
|
"notification from this process but the remote has focus"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!sFocusedIMEWidget && aOriginIsRemote) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), received blur notification "
|
2015-06-27 00:23:31 +00:00
|
|
|
"but the remote has already lost focus"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!sFocusedIMEWidget)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED, received blur "
|
2015-06-27 00:23:31 +00:00
|
|
|
"notification but there is no focused IME widget"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(sFocusedIMEWidget != aWidget)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED, received blur "
|
2015-06-27 00:23:31 +00:00
|
|
|
"notification but there is no focused IME widget"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIWidget> focusedIMEWidget(sFocusedIMEWidget);
|
|
|
|
sFocusedIMEWidget = nullptr;
|
|
|
|
sRemoteHasFocus = false;
|
|
|
|
return focusedIMEWidget->NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR));
|
|
|
|
}
|
2015-06-27 00:23:31 +00:00
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
case NOTIFY_IME_OF_TEXT_CHANGE:
|
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
|
|
|
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
|
2016-07-14 03:11:56 +00:00
|
|
|
case NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED:
|
2015-06-27 00:23:31 +00:00
|
|
|
if (!sRemoteHasFocus && aOriginIsRemote) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), received content change "
|
2015-06-27 00:23:31 +00:00
|
|
|
"notification from the remote but it's already lost focus"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(sRemoteHasFocus && !aOriginIsRemote)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED, received content "
|
2015-06-27 00:23:31 +00:00
|
|
|
"change notification from this process but the remote has already "
|
|
|
|
"gotten focus"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!sFocusedIMEWidget) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), received content change "
|
2015-06-27 00:23:31 +00:00
|
|
|
"notification but there is no focused IME widget"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(sFocusedIMEWidget != aWidget)) {
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED, received content "
|
2015-06-27 00:23:31 +00:00
|
|
|
"change notification for IME which has already lost focus, so, "
|
|
|
|
"nothing to do..."));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-06-27 00:23:31 +00:00
|
|
|
return aWidget->NotifyIME(aNotification);
|
|
|
|
default:
|
|
|
|
// Other notifications should be sent only when there is composition.
|
|
|
|
// So, we need to handle the others below.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextComposition> composition;
|
2015-06-27 00:23:31 +00:00
|
|
|
if (sTextCompositions) {
|
|
|
|
composition = sTextCompositions->GetCompositionFor(aWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSynthesizedForTests =
|
|
|
|
composition && composition->IsSynthesizedForTests();
|
|
|
|
|
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), composition=0x%p, "
|
2015-06-27 00:23:31 +00:00
|
|
|
"composition->IsSynthesizedForTests()=%s",
|
|
|
|
composition.get(), GetBoolName(isSynthesizedForTests)));
|
|
|
|
|
|
|
|
switch (aNotification.mMessage) {
|
2014-09-26 00:05:12 +00:00
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
return composition ?
|
|
|
|
composition->RequestToCommit(aWidget, false) : NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
return composition ?
|
|
|
|
composition->RequestToCommit(aWidget, true) : NS_OK;
|
2012-09-26 05:47:51 +00:00
|
|
|
default:
|
2014-09-26 00:05:12 +00:00
|
|
|
MOZ_CRASH("Unsupported notification");
|
2012-09-26 05:47:51 +00:00
|
|
|
}
|
2014-09-26 00:05:12 +00:00
|
|
|
MOZ_CRASH(
|
|
|
|
"Failed to handle the notification for non-synthesized composition");
|
|
|
|
return NS_ERROR_FAILURE;
|
2012-09-26 05:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::NotifyIME(IMEMessage aMessage,
|
2015-06-27 00:23:31 +00:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
bool aOriginIsRemote)
|
2012-09-26 05:47:51 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("NotifyIME(aMessage=%s, aPresContext=0x%p, aOriginIsRemote=%s)",
|
2016-05-31 02:39:15 +00:00
|
|
|
ToChar(aMessage), aPresContext, GetBoolName(aOriginIsRemote)));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2012-09-26 05:47:51 +00:00
|
|
|
NS_ENSURE_TRUE(aPresContext, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2013-02-06 02:50:02 +00:00
|
|
|
nsIWidget* widget = aPresContext->GetRootWidget();
|
2014-07-16 05:13:28 +00:00
|
|
|
if (NS_WARN_IF(!widget)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" NotifyIME(), FAILED due to no widget for the "
|
2014-07-16 05:13:28 +00:00
|
|
|
"nsPresContext"));
|
2012-09-26 05:47:51 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2015-06-27 00:23:31 +00:00
|
|
|
return NotifyIME(aMessage, widget, aOriginIsRemote);
|
2012-09-26 05:47:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-10-26 00:49:13 +00:00
|
|
|
bool
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::IsEditable(nsINode* node)
|
2012-10-26 00:49:13 +00:00
|
|
|
{
|
2012-05-24 21:49:44 +00:00
|
|
|
if (node->IsEditable()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// |node| might be readwrite (for example, a text control)
|
2014-03-08 01:20:08 +00:00
|
|
|
if (node->IsElement() &&
|
|
|
|
node->AsElement()->State().HasState(NS_EVENT_STATE_MOZ_READWRITE)) {
|
2012-05-24 21:49:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-10-26 00:49:13 +00:00
|
|
|
nsINode*
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::GetRootEditableNode(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
2009-02-10 20:56:51 +00:00
|
|
|
{
|
|
|
|
if (aContent) {
|
2012-07-30 14:20:58 +00:00
|
|
|
nsINode* root = nullptr;
|
2011-03-23 14:45:21 +00:00
|
|
|
nsINode* node = aContent;
|
2012-05-24 21:49:44 +00:00
|
|
|
while (node && IsEditable(node)) {
|
2014-09-26 00:10:49 +00:00
|
|
|
// If the node has independent selection like <input type="text"> or
|
|
|
|
// <textarea>, the node should be the root editable node for aContent.
|
|
|
|
// FYI: <select> element also has independent selection but IsEditable()
|
|
|
|
// returns false.
|
|
|
|
// XXX: If somebody adds new editable element which has independent
|
|
|
|
// selection but doesn't own editor, we'll need more checks here.
|
|
|
|
if (node->IsContent() &&
|
|
|
|
node->AsContent()->HasIndependentSelection()) {
|
|
|
|
return node;
|
|
|
|
}
|
2011-03-23 14:45:21 +00:00
|
|
|
root = node;
|
2012-10-09 12:31:24 +00:00
|
|
|
node = node->GetParentNode();
|
2009-02-10 20:56:51 +00:00
|
|
|
}
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
if (aPresContext) {
|
|
|
|
nsIDocument* document = aPresContext->Document();
|
2014-03-08 01:20:08 +00:00
|
|
|
if (document && document->IsEditable()) {
|
2009-02-10 20:56:51 +00:00
|
|
|
return document;
|
2014-03-08 01:20:08 +00:00
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-02-10 20:56:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-10-30 23:22:22 +00:00
|
|
|
bool
|
2015-05-26 07:45:26 +00:00
|
|
|
IMEStateManager::IsIMEObserverNeeded(const IMEState& aState)
|
2012-10-30 23:22:22 +00:00
|
|
|
{
|
2015-10-10 01:21:01 +00:00
|
|
|
return aState.MaybeEditable();
|
2012-10-30 23:22:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-10-26 00:49:13 +00:00
|
|
|
void
|
2014-07-16 05:13:28 +00:00
|
|
|
IMEStateManager::DestroyIMEContentObserver()
|
2009-02-10 20:56:51 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("DestroyIMEContentObserver(), sActiveIMEContentObserver=0x%p",
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveIMEContentObserver.get()));
|
2014-07-16 05:13:28 +00:00
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
if (!sActiveIMEContentObserver) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" DestroyIMEContentObserver() does nothing"));
|
2012-10-26 00:49:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" DestroyIMEContentObserver(), destroying "
|
2014-07-16 05:13:28 +00:00
|
|
|
"the active IMEContentObserver..."));
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<IMEContentObserver> tsm = sActiveIMEContentObserver.get();
|
2015-07-01 13:19:11 +00:00
|
|
|
sActiveIMEContentObserver = nullptr;
|
2012-11-09 08:40:39 +00:00
|
|
|
tsm->Destroy();
|
2009-02-10 20:56:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2012-10-26 00:49:13 +00:00
|
|
|
void
|
2014-11-05 13:12:44 +00:00
|
|
|
IMEStateManager::CreateIMEContentObserver(nsIEditor* aEditor)
|
2009-02-10 20:56:51 +00:00
|
|
|
{
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Info,
|
2016-07-05 10:05:23 +00:00
|
|
|
("CreateIMEContentObserver(aEditor=0x%p), "
|
2014-07-16 05:13:28 +00:00
|
|
|
"sPresContext=0x%p, sContent=0x%p, sActiveIMEContentObserver=0x%p, "
|
|
|
|
"sActiveIMEContentObserver->IsManaging(sPresContext, sContent)=%s",
|
2016-09-20 05:12:09 +00:00
|
|
|
aEditor, sPresContext.get(), sContent.get(), sActiveIMEContentObserver.get(),
|
2014-07-16 05:13:28 +00:00
|
|
|
GetBoolName(sActiveIMEContentObserver ?
|
|
|
|
sActiveIMEContentObserver->IsManaging(sPresContext, sContent) : false)));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(sActiveIMEContentObserver)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" CreateIMEContentObserver(), FAILED due to "
|
2014-07-16 05:13:28 +00:00
|
|
|
"there is already an active IMEContentObserver"));
|
2014-03-08 01:20:07 +00:00
|
|
|
MOZ_ASSERT(sActiveIMEContentObserver->IsManaging(sPresContext, sContent));
|
2012-10-26 00:49:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
|
2013-02-06 02:50:02 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = sPresContext->GetRootWidget();
|
2012-10-26 00:49:13 +00:00
|
|
|
if (!widget) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Error,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" CreateIMEContentObserver(), FAILED due to "
|
2014-07-16 05:13:28 +00:00
|
|
|
"there is a root widget for the nsPresContext"));
|
2012-10-26 00:49:13 +00:00
|
|
|
return; // Sometimes, there are no widgets.
|
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
|
2015-05-26 07:45:26 +00:00
|
|
|
// If it's not text editable, we don't need to create IMEContentObserver.
|
|
|
|
if (!IsIMEObserverNeeded(widget->GetInputContext().mIMEState)) {
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" CreateIMEContentObserver() doesn't create "
|
2014-07-16 05:13:28 +00:00
|
|
|
"IMEContentObserver because of non-editable IME state"));
|
2012-10-30 23:22:22 +00:00
|
|
|
return;
|
2012-10-26 00:49:13 +00:00
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
MOZ_LOG(sISMLog, LogLevel::Debug,
|
2016-07-05 10:05:23 +00:00
|
|
|
(" CreateIMEContentObserver() is creating an "
|
2014-07-16 05:13:28 +00:00
|
|
|
"IMEContentObserver instance..."));
|
2014-03-08 01:20:07 +00:00
|
|
|
sActiveIMEContentObserver = new IMEContentObserver();
|
2012-11-16 16:43:04 +00:00
|
|
|
|
2014-03-08 01:20:07 +00:00
|
|
|
// IMEContentObserver::Init() might create another IMEContentObserver
|
|
|
|
// instance. So, sActiveIMEContentObserver would be replaced with new one.
|
2012-11-16 16:43:04 +00:00
|
|
|
// We should hold the current instance here.
|
2016-08-24 18:12:09 +00:00
|
|
|
RefPtr<IMEContentObserver> activeIMEContentObserver(sActiveIMEContentObserver);
|
|
|
|
activeIMEContentObserver->Init(widget, sPresContext, sContent, aEditor);
|
2009-02-10 20:56:51 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 05:13:28 +00:00
|
|
|
// static
|
2009-02-10 20:56:51 +00:00
|
|
|
nsresult
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::GetFocusSelectionAndRoot(nsISelection** aSelection,
|
|
|
|
nsIContent** aRootContent)
|
2009-02-10 20:56:51 +00:00
|
|
|
{
|
2014-03-08 01:20:07 +00:00
|
|
|
if (!sActiveIMEContentObserver) {
|
2009-02-10 20:56:51 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2014-03-08 01:20:07 +00:00
|
|
|
}
|
2014-03-08 01:20:07 +00:00
|
|
|
return sActiveIMEContentObserver->GetSelectionAndRoot(aSelection,
|
|
|
|
aRootContent);
|
2009-02-10 20:56:51 +00:00
|
|
|
}
|
2013-11-07 00:11:11 +00:00
|
|
|
|
2014-02-12 13:02:55 +00:00
|
|
|
// static
|
|
|
|
already_AddRefed<TextComposition>
|
2014-03-08 01:20:07 +00:00
|
|
|
IMEStateManager::GetTextCompositionFor(nsIWidget* aWidget)
|
2013-11-07 00:11:11 +00:00
|
|
|
{
|
2014-02-12 13:02:55 +00:00
|
|
|
if (!sTextCompositions) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<TextComposition> textComposition =
|
2014-02-12 13:02:55 +00:00
|
|
|
sTextCompositions->GetCompositionFor(aWidget);
|
|
|
|
return textComposition.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<TextComposition>
|
2015-12-04 09:50:34 +00:00
|
|
|
IMEStateManager::GetTextCompositionFor(
|
2015-12-04 09:50:43 +00:00
|
|
|
const WidgetCompositionEvent* aCompositionEvent)
|
2015-12-04 09:50:34 +00:00
|
|
|
{
|
2015-12-04 09:50:43 +00:00
|
|
|
if (!sTextCompositions) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<TextComposition> textComposition =
|
|
|
|
sTextCompositions->GetCompositionFor(aCompositionEvent);
|
|
|
|
return textComposition.forget();
|
2015-12-04 09:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
already_AddRefed<TextComposition>
|
2015-12-04 09:50:43 +00:00
|
|
|
IMEStateManager::GetTextCompositionFor(nsPresContext* aPresContext)
|
2014-02-12 13:02:55 +00:00
|
|
|
{
|
2015-12-04 09:50:34 +00:00
|
|
|
if (!sTextCompositions) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<TextComposition> textComposition =
|
2015-12-04 09:50:43 +00:00
|
|
|
sTextCompositions->GetCompositionFor(aPresContext);
|
2015-12-04 09:50:34 +00:00
|
|
|
return textComposition.forget();
|
2013-11-07 00:11:11 +00:00
|
|
|
}
|
2014-03-08 01:20:07 +00:00
|
|
|
|
|
|
|
} // namespace mozilla
|