2013-02-25 08:00:05 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WinIMEHandler.h"
|
2014-01-14 06:00:59 +04:00
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
#include "nsIMM32Handler.h"
|
2013-07-18 12:12:31 +04:00
|
|
|
#include "nsWindowDefs.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
#include "nsTextStore.h"
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
#include "nsWindow.h"
|
2013-03-18 08:41:24 +04:00
|
|
|
#include "WinUtils.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* IMEHandler
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
bool IMEHandler::sIsInTSFMode = false;
|
2014-01-14 06:00:59 +04:00
|
|
|
bool IMEHandler::sIsIMMEnabled = true;
|
2013-02-25 08:00:07 +04:00
|
|
|
bool IMEHandler::sPluginHasFocus = false;
|
2014-02-18 02:32:52 +04:00
|
|
|
decltype(SetInputScopes)* IMEHandler::sSetInputScopes = nullptr;
|
2013-02-25 08:00:05 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::Initialize()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
nsTextStore::Initialize();
|
|
|
|
sIsInTSFMode = nsTextStore::IsInTSFMode();
|
2014-01-14 06:00:59 +04:00
|
|
|
sIsIMMEnabled =
|
|
|
|
!sIsInTSFMode || Preferences::GetBool("intl.tsf.support_imm", true);
|
2013-04-29 19:41:45 +04:00
|
|
|
if (!sIsInTSFMode) {
|
|
|
|
// When full nsTextStore is not available, try to use SetInputScopes API
|
2013-06-27 20:06:45 +04:00
|
|
|
// to enable at least InputScope. Use GET_MODULE_HANDLE_EX_FLAG_PIN to
|
|
|
|
// ensure that msctf.dll will not be unloaded.
|
|
|
|
HMODULE module = nullptr;
|
|
|
|
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll",
|
|
|
|
&module)) {
|
2014-02-18 02:32:52 +04:00
|
|
|
sSetInputScopes = reinterpret_cast<decltype(SetInputScopes)*>(
|
2013-06-27 20:06:45 +04:00
|
|
|
GetProcAddress(module, "SetInputScopes"));
|
|
|
|
}
|
2013-04-29 19:41:45 +04:00
|
|
|
}
|
2013-02-25 08:00:05 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
nsIMM32Handler::Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::Terminate()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (sIsInTSFMode) {
|
|
|
|
nsTextStore::Terminate();
|
|
|
|
sIsInTSFMode = false;
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
nsIMM32Handler::Terminate();
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:07 +04:00
|
|
|
// static
|
|
|
|
void*
|
|
|
|
IMEHandler::GetNativeData(uint32_t aDataType)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
void* result = nsTextStore::GetNativeData(aDataType);
|
|
|
|
if (!result || !(*(static_cast<void**>(result)))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// XXX During the TSF module test, sIsInTSFMode must be true. After that,
|
|
|
|
// the value should be restored but currently, there is no way for that.
|
|
|
|
// When the TSF test is enabled again, we need to fix this. Perhaps,
|
|
|
|
// sending a message can fix this.
|
|
|
|
sIsInTSFMode = true;
|
|
|
|
return result;
|
|
|
|
#else // #ifdef NS_ENABLE_TSF
|
|
|
|
return nullptr;
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF #else
|
|
|
|
}
|
|
|
|
|
2013-03-18 08:41:24 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::ProcessRawKeyMessage(const MSG& aMsg)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (IsTSFAvailable()) {
|
|
|
|
return nsTextStore::ProcessRawKeyMessage(aMsg);
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
return false; // noting to do in IMM mode.
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage,
|
|
|
|
WPARAM& aWParam, LPARAM& aLParam,
|
2013-07-18 12:12:31 +04:00
|
|
|
MSGResult& aResult)
|
2013-02-25 08:00:05 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2014-01-14 06:01:00 +04:00
|
|
|
nsTextStore::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult);
|
|
|
|
if (aResult.mConsumed) {
|
2013-02-25 08:00:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-14 06:01:00 +04:00
|
|
|
// If we don't support IMM in TSF mode, we don't use nsIMM32Handler.
|
2014-01-14 06:01:00 +04:00
|
|
|
if (!sIsIMMEnabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-14 06:01:00 +04:00
|
|
|
// IME isn't implemented with IMM, nsIMM32Handler shouldn't handle any
|
|
|
|
// messages.
|
|
|
|
if (!nsTextStore::IsIMM_IME()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
return nsIMM32Handler::ProcessMessage(aWindow, aMessage, aWParam, aLParam,
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult);
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsComposing()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2013-02-25 08:00:05 +04:00
|
|
|
return nsTextStore::IsComposing();
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
return nsIMM32Handler::IsComposing();
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsComposingOn(nsWindow* aWindow)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2013-02-25 08:00:05 +04:00
|
|
|
return nsTextStore::IsComposingOn(aWindow);
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
return nsIMM32Handler::IsComposingOn(aWindow);
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IMEHandler::NotifyIME(nsWindow* aWindow,
|
|
|
|
NotificationToIME aNotification)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2013-02-25 08:00:06 +04:00
|
|
|
switch (aNotification) {
|
2013-02-25 08:00:06 +04:00
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
return nsTextStore::OnSelectionChange();
|
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
|
|
|
return nsTextStore::OnFocusChange(true, aWindow,
|
|
|
|
aWindow->GetInputContext().mIMEState.mEnabled);
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
return nsTextStore::OnFocusChange(false, aWindow,
|
|
|
|
aWindow->GetInputContext().mIMEState.mEnabled);
|
2013-02-25 08:00:06 +04:00
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
if (nsTextStore::IsComposingOn(aWindow)) {
|
|
|
|
nsTextStore::CommitComposition(false);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
if (nsTextStore::IsComposingOn(aWindow)) {
|
|
|
|
nsTextStore::CommitComposition(true);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
|
|
|
switch (aNotification) {
|
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
nsIMM32Handler::CommitComposition(aWindow);
|
|
|
|
return NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
nsIMM32Handler::CancelComposition(aWindow);
|
|
|
|
return NS_OK;
|
2014-01-16 14:05:09 +04:00
|
|
|
case NOTIFY_IME_OF_COMPOSITION_UPDATE:
|
|
|
|
nsIMM32Handler::OnUpdateComposition(aWindow);
|
|
|
|
return NS_OK;
|
2013-02-25 08:00:07 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
// If a plugin gets focus while TSF has focus, we need to notify TSF of
|
|
|
|
// the blur.
|
|
|
|
if (nsTextStore::ThinksHavingFocus()) {
|
|
|
|
return nsTextStore::OnFocusChange(false, aWindow,
|
|
|
|
aWindow->GetInputContext().mIMEState.mEnabled);
|
|
|
|
}
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
#endif //NS_ENABLE_TSF
|
2013-02-25 08:00:06 +04:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IMEHandler::NotifyIMEOfTextChange(uint32_t aStart,
|
|
|
|
uint32_t aOldEnd,
|
|
|
|
uint32_t aNewEnd)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2013-02-25 08:00:06 +04:00
|
|
|
return nsTextStore::OnTextChange(aStart, aOldEnd, aNewEnd);
|
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
nsIMEUpdatePreference
|
|
|
|
IMEHandler::GetUpdatePreference()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2013-02-25 08:00:06 +04:00
|
|
|
return nsTextStore::GetIMEUpdatePreference();
|
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
2013-07-11 11:46:34 +04:00
|
|
|
return nsIMEUpdatePreference();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::GetOpenState(nsWindow* aWindow)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2013-02-25 08:00:06 +04:00
|
|
|
return nsTextStore::GetIMEOpenState();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
|
|
|
nsIMEContext IMEContext(aWindow->GetWindowHandle());
|
2013-02-25 08:00:06 +04:00
|
|
|
return IMEContext.GetOpenState();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2013-02-25 08:00:06 +04:00
|
|
|
void
|
|
|
|
IMEHandler::OnDestroyWindow(nsWindow* aWindow)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
2013-04-29 19:41:45 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:06 +04:00
|
|
|
// We need to do nothing here for TSF. Just restore the default context
|
|
|
|
// if it's been disassociated.
|
2013-04-29 19:41:45 +04:00
|
|
|
if (!sIsInTSFMode) {
|
|
|
|
// MSDN says we need to set IS_DEFAULT to avoid memory leak when we use
|
|
|
|
// SetInputScopes API. Use an empty string to do this.
|
|
|
|
SetInputScopeForIMM32(aWindow, EmptyString());
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
2014-01-14 06:00:59 +04:00
|
|
|
AssociateIMEContext(aWindow, true);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2013-03-27 04:04:02 +04:00
|
|
|
IMEHandler::SetInputContext(nsWindow* aWindow,
|
|
|
|
InputContext& aInputContext,
|
|
|
|
const InputContextAction& aAction)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
|
|
|
// FYI: If there is no composition, this call will do nothing.
|
|
|
|
NotifyIME(aWindow, REQUEST_TO_COMMIT_COMPOSITION);
|
|
|
|
|
2014-01-14 06:00:59 +04:00
|
|
|
const InputContext& oldInputContext = aWindow->GetInputContext();
|
|
|
|
|
2013-02-25 08:00:07 +04:00
|
|
|
// Assume that SetInputContext() is called only when aWindow has focus.
|
|
|
|
sPluginHasFocus = (aInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
bool enable = WinUtils::IsIMEEnabled(aInputContext);
|
2013-02-25 08:00:06 +04:00
|
|
|
bool adjustOpenState = (enable &&
|
|
|
|
aInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE);
|
|
|
|
bool open = (adjustOpenState &&
|
|
|
|
aInputContext.mIMEState.mOpen == IMEState::OPEN);
|
|
|
|
|
|
|
|
aInputContext.mNativeIMEContext = nullptr;
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
// Note that even while a plugin has focus, we need to notify TSF of that.
|
2013-02-25 08:00:06 +04:00
|
|
|
if (sIsInTSFMode) {
|
2013-03-27 04:04:02 +04:00
|
|
|
nsTextStore::SetInputContext(aWindow, aInputContext, aAction);
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
|
|
|
aInputContext.mNativeIMEContext = nsTextStore::GetTextStore();
|
2014-01-14 06:00:59 +04:00
|
|
|
if (sIsIMMEnabled) {
|
|
|
|
// Associate IME context for IMM-IMEs.
|
|
|
|
AssociateIMEContext(aWindow, enable);
|
|
|
|
} else if (oldInputContext.mIMEState.mEnabled == IMEState::PLUGIN) {
|
|
|
|
// Disassociate the IME context from the window when plugin loses focus
|
|
|
|
// in pure TSF mode.
|
|
|
|
AssociateIMEContext(aWindow, false);
|
|
|
|
}
|
2013-03-27 04:04:02 +04:00
|
|
|
if (adjustOpenState) {
|
|
|
|
nsTextStore::SetIMEOpenState(open);
|
|
|
|
}
|
|
|
|
return;
|
2013-02-25 08:00:07 +04:00
|
|
|
}
|
2013-06-27 20:06:45 +04:00
|
|
|
} else {
|
|
|
|
// Set at least InputScope even when TextStore is not available.
|
2013-04-29 19:41:45 +04:00
|
|
|
SetInputScopeForIMM32(aWindow, aInputContext.mHTMLInputType);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
2013-02-25 08:00:06 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:06 +04:00
|
|
|
|
2014-01-14 06:00:59 +04:00
|
|
|
AssociateIMEContext(aWindow, enable);
|
2013-02-25 08:00:06 +04:00
|
|
|
|
2014-01-14 06:00:59 +04:00
|
|
|
nsIMEContext IMEContext(aWindow->GetWindowHandle());
|
2013-02-25 08:00:06 +04:00
|
|
|
if (adjustOpenState) {
|
|
|
|
IMEContext.SetOpenState(open);
|
|
|
|
}
|
2014-01-14 06:00:59 +04:00
|
|
|
|
|
|
|
if (aInputContext.mNativeIMEContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The old InputContext must store the default IMC or old TextStore.
|
|
|
|
// When IME context is disassociated from the window, use it.
|
|
|
|
aInputContext.mNativeIMEContext = enable ?
|
|
|
|
static_cast<void*>(IMEContext.get()) : oldInputContext.mNativeIMEContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::AssociateIMEContext(nsWindow* aWindow, bool aEnable)
|
|
|
|
{
|
|
|
|
nsIMEContext IMEContext(aWindow->GetWindowHandle());
|
|
|
|
if (aEnable) {
|
|
|
|
IMEContext.AssociateDefaultContext();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't disassociate the context after the window is destroyed.
|
|
|
|
if (aWindow->Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IMEContext.Disassociate();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
void
|
2013-02-25 08:00:06 +04:00
|
|
|
IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
2013-02-25 08:00:06 +04:00
|
|
|
// For a11y, the default enabled state should be 'enabled'.
|
|
|
|
aInputContext.mIMEState.mEnabled = IMEState::ENABLED;
|
|
|
|
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (sIsInTSFMode) {
|
2013-03-27 04:04:02 +04:00
|
|
|
nsTextStore::SetInputContext(aWindow, aInputContext,
|
|
|
|
InputContextAction(InputContextAction::CAUSE_UNKNOWN,
|
|
|
|
InputContextAction::GOT_FOCUS));
|
2013-02-25 08:00:06 +04:00
|
|
|
aInputContext.mNativeIMEContext = nsTextStore::GetTextStore();
|
|
|
|
MOZ_ASSERT(aInputContext.mNativeIMEContext);
|
2014-01-14 06:00:59 +04:00
|
|
|
// IME context isn't necessary in pure TSF mode.
|
|
|
|
if (!sIsIMMEnabled) {
|
|
|
|
AssociateIMEContext(aWindow, false);
|
|
|
|
}
|
2013-02-25 08:00:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
// NOTE: mNativeIMEContext may be null if IMM module isn't installed.
|
2013-02-25 08:00:06 +04:00
|
|
|
nsIMEContext IMEContext(aWindow->GetWindowHandle());
|
2013-02-25 08:00:06 +04:00
|
|
|
aInputContext.mNativeIMEContext = static_cast<void*>(IMEContext.get());
|
|
|
|
MOZ_ASSERT(aInputContext.mNativeIMEContext || !CurrentKeyboardLayoutHasIME());
|
|
|
|
// If no IME context is available, we should set the widget's pointer since
|
|
|
|
// nullptr indicates there is only one context per process on the platform.
|
|
|
|
if (!aInputContext.mNativeIMEContext) {
|
|
|
|
aInputContext.mNativeIMEContext = static_cast<void*>(aWindow);
|
|
|
|
}
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::CurrentKeyboardLayoutHasIME()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (sIsInTSFMode) {
|
|
|
|
return nsTextStore::CurrentKeyboardLayoutHasIME();
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
|
|
|
return nsIMM32Handler::IsIMEAvailable();
|
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
2013-04-29 19:41:45 +04:00
|
|
|
// static
|
2013-06-27 20:06:45 +04:00
|
|
|
void
|
2013-04-29 19:41:45 +04:00
|
|
|
IMEHandler::SetInputScopeForIMM32(nsWindow* aWindow,
|
2013-06-27 20:06:45 +04:00
|
|
|
const nsAString& aHTMLInputType)
|
2013-04-29 19:41:45 +04:00
|
|
|
{
|
|
|
|
if (sIsInTSFMode || !sSetInputScopes || aWindow->Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UINT arraySize = 0;
|
|
|
|
const InputScope* scopes = nullptr;
|
2013-06-27 20:06:45 +04:00
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html
|
|
|
|
if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_DEFAULT };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("url")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_URL };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("search")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_SEARCH };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("email")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_EMAIL_SMTPEMAILADDRESS };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("password")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_PASSWORD };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("datetime") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("datetime-local")) {
|
|
|
|
static const InputScope inputScopes[] = {
|
|
|
|
IS_DATE_FULLDATE, IS_TIME_FULLTIME };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("date") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("month") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("week")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_DATE_FULLDATE };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("time")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_TIME_FULLTIME };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("tel")) {
|
|
|
|
static const InputScope inputScopes[] = {
|
|
|
|
IS_TELEPHONE_FULLTELEPHONENUMBER, IS_TELEPHONE_LOCALNUMBER };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("number")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_NUMBER };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
2013-04-29 19:41:45 +04:00
|
|
|
}
|
|
|
|
if (scopes && arraySize > 0) {
|
|
|
|
sSetInputScopes(aWindow->GetWindowHandle(), scopes, arraySize, nullptr, 0,
|
|
|
|
nullptr, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|