bug 1112212 - Set flag in InputContext for IME-unaware webapps; r=masayuki

This commit is contained in:
Jim Chen 2015-06-16 19:02:39 -04:00
Родитель 337c08cab7
Коммит ada45abfc5
4 изменённых файлов: 42 добавлений и 1 удалений

Просмотреть файл

@ -9,6 +9,7 @@
#include "mozilla/IMEStateManager.h"
#include "mozilla/Attributes.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Preferences.h"
@ -181,6 +182,7 @@ nsIContent* IMEStateManager::sContent = nullptr;
nsPresContext* IMEStateManager::sPresContext = nullptr;
bool IMEStateManager::sInstalledMenuKeyboardListener = false;
bool IMEStateManager::sIsGettingNewIMEState = false;
bool IMEStateManager::sCheckForIMEUnawareWebApps = false;
// sActiveIMEContentObserver points to the currently active IMEContentObserver.
// sActiveIMEContentObserver is null if there is no focused editor.
@ -194,6 +196,11 @@ IMEStateManager::Init()
if (!sISMLog) {
sISMLog = PR_NewLogModule("IMEStateManager");
}
Preferences::AddBoolVarCache(
&sCheckForIMEUnawareWebApps,
"intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition",
false);
}
// static
@ -812,6 +819,25 @@ private:
uint32_t mState;
};
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;
}
// static
void
IMEStateManager::SetIMEState(const IMEState& aState,
@ -833,6 +859,8 @@ IMEStateManager::SetIMEState(const IMEState& aState,
InputContext context;
context.mIMEState = aState;
context.mMayBeIMEUnaware = context.mIMEState.IsEditable() &&
sCheckForIMEUnawareWebApps && MayBeIMEUnawareWebApp(aContent);
if (aContent &&
aContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea)) {

Просмотреть файл

@ -169,6 +169,7 @@ protected:
static nsPresContext* sPresContext;
static bool sInstalledMenuKeyboardListener;
static bool sIsGettingNewIMEState;
static bool sCheckForIMEUnawareWebApps;
class MOZ_STACK_CLASS GettingNewIMEStateBlocker final
{

Просмотреть файл

@ -1793,6 +1793,13 @@ pref("intl.locale.matchOS", false);
pref("intl.fallbackCharsetList.ISO-8859-1", "windows-1252");
pref("font.language.group", "chrome://global/locale/intl.properties");
// Android-specific pref to use key-events-only mode for IME-unaware webapps.
#ifdef MOZ_WIDGET_ANDROID
pref("intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition", true);
#else
pref("intl.ime.hack.on_ime_unaware_apps.fire_key_events_for_composition", false);
#endif
// these locales have right-to-left UI
pref("intl.uidirection.ar", "rtl");
pref("intl.uidirection.he", "rtl");

Просмотреть файл

@ -423,6 +423,7 @@ struct InputContext {
InputContext()
: mNativeIMEContext(nullptr)
, mOrigin(XRE_IsParentProcess() ? ORIGIN_MAIN : ORIGIN_CONTENT)
, mMayBeIMEUnaware(false)
{}
bool IsPasswordEditor() const
@ -446,7 +447,6 @@ struct InputContext {
be nullptr. */
void* mNativeIMEContext;
/**
* mOrigin indicates whether this focus event refers to main or remote content.
*/
@ -459,6 +459,11 @@ struct InputContext {
};
Origin mOrigin;
/* True if the webapp may be unaware of IME events such as input event or
* composiion events. This enables a key-events-only mode on Android for
* compatibility with webapps relying on key listeners. */
bool mMayBeIMEUnaware;
bool IsOriginMainProcess() const
{
return mOrigin == ORIGIN_MAIN;