2009-05-04 02:20:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sts=2 sw=2 et cin: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
#include "IMMHandler.h"
|
2009-05-04 02:20:11 +04:00
|
|
|
#include "nsWindow.h"
|
2013-07-18 12:12:31 +04:00
|
|
|
#include "nsWindowDefs.h"
|
2012-01-04 14:21:44 +04:00
|
|
|
#include "WinUtils.h"
|
2012-05-03 12:35:02 +04:00
|
|
|
#include "KeyboardLayout.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-01-04 14:21:44 +04:00
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2013-09-25 15:21:20 +04:00
|
|
|
#include "mozilla/MiscEvents.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
|
2015-05-15 04:18:07 +03:00
|
|
|
#ifndef IME_PROP_ACCEPT_WIDE_VKEY
|
|
|
|
#define IME_PROP_ACCEPT_WIDE_VKEY 0x20
|
|
|
|
#endif
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// from http://download.microsoft.com/download/6/0/9/60908e9e-d2c1-47db-98f6-216af76a235f/msime.h
|
|
|
|
// The document for this has been removed from MSDN...
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
#define RWM_MOUSE TEXT("MSIMEMouseOperation")
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
#define IMEMOUSE_NONE 0x00 // no mouse button was pushed
|
|
|
|
#define IMEMOUSE_LDOWN 0x01
|
|
|
|
#define IMEMOUSE_RDOWN 0x02
|
|
|
|
#define IMEMOUSE_MDOWN 0x04
|
|
|
|
#define IMEMOUSE_WUP 0x10 // wheel up
|
|
|
|
#define IMEMOUSE_WDOWN 0x20 // wheel down
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
static const char*
|
|
|
|
GetBoolName(bool aBool)
|
|
|
|
{
|
|
|
|
return aBool ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:07 +03:00
|
|
|
static void
|
|
|
|
HandleSeparator(nsACString& aDesc)
|
|
|
|
{
|
|
|
|
if (!aDesc.IsEmpty()) {
|
|
|
|
aDesc.AppendLiteral(" | ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GetIMEGeneralPropertyName : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
2016-12-16 11:00:43 +03:00
|
|
|
explicit GetIMEGeneralPropertyName(DWORD aFlags)
|
2015-05-15 04:18:07 +03:00
|
|
|
{
|
|
|
|
if (!aFlags) {
|
|
|
|
AppendLiteral("no flags");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aFlags & IME_PROP_AT_CARET) {
|
|
|
|
AppendLiteral("IME_PROP_AT_CARET");
|
|
|
|
}
|
|
|
|
if (aFlags & IME_PROP_SPECIAL_UI) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("IME_PROP_SPECIAL_UI");
|
|
|
|
}
|
|
|
|
if (aFlags & IME_PROP_CANDLIST_START_FROM_1) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("IME_PROP_CANDLIST_START_FROM_1");
|
|
|
|
}
|
|
|
|
if (aFlags & IME_PROP_UNICODE) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("IME_PROP_UNICODE");
|
|
|
|
}
|
|
|
|
if (aFlags & IME_PROP_COMPLETE_ON_UNSELECT) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("IME_PROP_COMPLETE_ON_UNSELECT");
|
|
|
|
}
|
|
|
|
if (aFlags & IME_PROP_ACCEPT_WIDE_VKEY) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("IME_PROP_ACCEPT_WIDE_VKEY");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual ~GetIMEGeneralPropertyName() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GetIMEUIPropertyName : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
2016-12-16 11:00:43 +03:00
|
|
|
explicit GetIMEUIPropertyName(DWORD aFlags)
|
2015-05-15 04:18:07 +03:00
|
|
|
{
|
|
|
|
if (!aFlags) {
|
|
|
|
AppendLiteral("no flags");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aFlags & UI_CAP_2700) {
|
|
|
|
AppendLiteral("UI_CAP_2700");
|
|
|
|
}
|
|
|
|
if (aFlags & UI_CAP_ROT90) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("UI_CAP_ROT90");
|
|
|
|
}
|
|
|
|
if (aFlags & UI_CAP_ROTANY) {
|
|
|
|
HandleSeparator(*this);
|
|
|
|
AppendLiteral("UI_CAP_ROTANY");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual ~GetIMEUIPropertyName() {}
|
|
|
|
};
|
|
|
|
|
2015-05-15 04:18:07 +03:00
|
|
|
class GetWritingModeName : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
2016-12-16 11:00:43 +03:00
|
|
|
explicit GetWritingModeName(const WritingMode& aWritingMode)
|
2015-05-15 04:18:07 +03:00
|
|
|
{
|
|
|
|
if (!aWritingMode.IsVertical()) {
|
|
|
|
Assign("Horizontal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aWritingMode.IsVerticalLR()) {
|
|
|
|
Assign("Vertical (LR)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Assign("Vertical (RL)");
|
|
|
|
}
|
|
|
|
virtual ~GetWritingModeName() {}
|
|
|
|
};
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
class GetReconvertStringLog : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
2016-12-16 11:00:43 +03:00
|
|
|
explicit GetReconvertStringLog(RECONVERTSTRING* aReconv)
|
2015-07-23 06:31:28 +03:00
|
|
|
{
|
|
|
|
AssignLiteral("{ dwSize=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwSize));
|
|
|
|
AppendLiteral(", dwVersion=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwVersion));
|
|
|
|
AppendLiteral(", dwStrLen=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwStrLen));
|
|
|
|
AppendLiteral(", dwStrOffset=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwStrOffset));
|
|
|
|
AppendLiteral(", dwCompStrLen=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwCompStrLen));
|
|
|
|
AppendLiteral(", dwCompStrOffset=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwCompStrOffset));
|
|
|
|
AppendLiteral(", dwTargetStrLen=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwTargetStrLen));
|
|
|
|
AppendLiteral(", dwTargetStrOffset=");
|
|
|
|
AppendInt(static_cast<uint32_t>(aReconv->dwTargetStrOffset));
|
|
|
|
AppendLiteral(", result str=\"");
|
|
|
|
if (aReconv->dwStrLen) {
|
|
|
|
char16_t* strStart =
|
|
|
|
reinterpret_cast<char16_t*>(
|
|
|
|
reinterpret_cast<char*>(aReconv) + aReconv->dwStrOffset);
|
|
|
|
nsDependentString str(strStart, aReconv->dwStrLen);
|
|
|
|
Append(NS_ConvertUTF16toUTF8(str));
|
|
|
|
}
|
|
|
|
AppendLiteral("\" }");
|
|
|
|
}
|
|
|
|
virtual ~GetReconvertStringLog() {}
|
|
|
|
};
|
2009-06-18 09:20:14 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
2009-06-18 09:20:14 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
static IMMHandler* gIMMHandler = nullptr;
|
2009-06-18 09:20:14 +04:00
|
|
|
|
2016-05-11 12:01:34 +03:00
|
|
|
LazyLogModule gIMMLog("nsIMM32HandlerWidgets");
|
2015-07-23 06:31:28 +03:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* IMEContext
|
|
|
|
******************************************************************************/
|
2009-06-18 09:20:14 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext::IMEContext(HWND aWnd)
|
|
|
|
: mWnd(aWnd)
|
|
|
|
, mIMC(::ImmGetContext(aWnd))
|
|
|
|
{
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2017-06-07 05:42:27 +03:00
|
|
|
IMEContext::IMEContext(nsWindowBase* aWindowBase)
|
|
|
|
: mWnd(aWindowBase->GetWindowHandle())
|
|
|
|
, mIMC(::ImmGetContext(aWindowBase->GetWindowHandle()))
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:57 +03:00
|
|
|
void
|
|
|
|
IMEContext::Init(HWND aWnd)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
mWnd = aWnd;
|
|
|
|
mIMC = ::ImmGetContext(mWnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-06-07 05:42:27 +03:00
|
|
|
IMEContext::Init(nsWindowBase* aWindowBase)
|
2015-12-11 09:15:57 +03:00
|
|
|
{
|
2017-06-07 05:42:27 +03:00
|
|
|
Init(aWindowBase->GetWindowHandle());
|
2015-12-11 09:15:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContext::Clear()
|
|
|
|
{
|
|
|
|
if (mWnd && mIMC) {
|
|
|
|
::ImmReleaseContext(mWnd, mIMC);
|
|
|
|
}
|
|
|
|
mWnd = nullptr;
|
|
|
|
mIMC = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* IMMHandler
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
static UINT sWM_MSIME_MOUSE = 0; // mouse message for MSIME 98/2000
|
|
|
|
|
|
|
|
WritingMode IMMHandler::sWritingModeOfCompositionFont;
|
|
|
|
nsString IMMHandler::sIMEName;
|
|
|
|
UINT IMMHandler::sCodePage = 0;
|
|
|
|
DWORD IMMHandler::sIMEProperty = 0;
|
|
|
|
DWORD IMMHandler::sIMEUIProperty = 0;
|
|
|
|
bool IMMHandler::sAssumeVerticalWritingModeNotSupported = false;
|
|
|
|
bool IMMHandler::sHasFocus = false;
|
2016-01-13 06:44:39 +03:00
|
|
|
bool IMMHandler::sNativeCaretIsCreatedForPlugin = false;
|
2015-07-23 06:31:28 +03:00
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::EnsureHandlerInstance()
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler) {
|
|
|
|
gIMMHandler = new IMMHandler();
|
|
|
|
}
|
|
|
|
}
|
2009-05-07 07:49:14 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::Initialize()
|
|
|
|
{
|
2009-05-04 02:20:11 +04:00
|
|
|
if (!sWM_MSIME_MOUSE) {
|
|
|
|
sWM_MSIME_MOUSE = ::RegisterWindowMessage(RWM_MOUSE);
|
|
|
|
}
|
2015-05-15 04:18:07 +03:00
|
|
|
sAssumeVerticalWritingModeNotSupported =
|
|
|
|
Preferences::GetBool(
|
|
|
|
"intl.imm.vertical_writing.always_assume_not_supported", false);
|
2015-05-15 04:18:08 +03:00
|
|
|
InitKeyboardLayout(nullptr, ::GetKeyboardLayout(0));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::Terminate()
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler)
|
2009-05-04 02:20:11 +04:00
|
|
|
return;
|
2015-07-23 06:31:28 +03:00
|
|
|
delete gIMMHandler;
|
|
|
|
gIMMHandler = nullptr;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::IsComposingOnOurEditor()
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler && gIMMHandler->mIsComposing;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::IsComposingOnPlugin()
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler && gIMMHandler->mIsComposingOnPlugin;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::IsComposingWindow(nsWindow* aWindow)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler && gIMMHandler->mComposingWindow == aWindow;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::IsTopLevelWindowOfComposition(nsWindow* aWindow)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler || !gIMMHandler->mComposingWindow) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
HWND wnd = gIMMHandler->mComposingWindow->GetWindowHandle();
|
2012-01-04 14:21:44 +04:00
|
|
|
return WinUtils::GetTopLevelHWND(wnd, true) == aWindow->GetWindowHandle();
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
2015-05-15 04:18:07 +03:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::IsJapanist2003Active()
|
2015-05-15 04:18:07 +03:00
|
|
|
{
|
|
|
|
return sIMEName.EqualsLiteral("Japanist 2003");
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::IsGoogleJapaneseInputActive()
|
2015-05-15 04:18:08 +03:00
|
|
|
{
|
|
|
|
// NOTE: Even on Windows for en-US, the name of Google Japanese Input is
|
|
|
|
// written in Japanese.
|
|
|
|
return sIMEName.Equals(L"Google \x65E5\x672C\x8A9E\x5165\x529B "
|
|
|
|
L"IMM32 \x30E2\x30B8\x30E5\x30FC\x30EB");
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::ShouldDrawCompositionStringOurselves()
|
2009-05-07 07:49:14 +04:00
|
|
|
{
|
|
|
|
// If current IME has special UI or its composition window should not
|
|
|
|
// positioned to caret position, we should now draw composition string
|
|
|
|
// ourselves.
|
|
|
|
return !(sIMEProperty & IME_PROP_SPECIAL_UI) &&
|
|
|
|
(sIMEProperty & IME_PROP_AT_CARET);
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::IsVerticalWritingSupported()
|
2015-05-15 04:18:07 +03:00
|
|
|
{
|
|
|
|
// Even if IME claims that they support vertical writing mode but it may not
|
|
|
|
// support vertical writing mode for its candidate window.
|
|
|
|
if (sAssumeVerticalWritingModeNotSupported) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-15 04:18:08 +03:00
|
|
|
// Google Japanese Input doesn't support vertical writing mode. We should
|
|
|
|
// return false if it's active IME.
|
|
|
|
if (IsGoogleJapaneseInputActive()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-15 04:18:07 +03:00
|
|
|
return !!(sIMEUIProperty & (UI_CAP_2700 | UI_CAP_ROT90 | UI_CAP_ROTANY));
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::InitKeyboardLayout(nsWindow* aWindow,
|
|
|
|
HKL aKeyboardLayout)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-05-15 04:18:07 +03:00
|
|
|
UINT IMENameLength = ::ImmGetDescriptionW(aKeyboardLayout, nullptr, 0);
|
|
|
|
if (IMENameLength) {
|
|
|
|
// Add room for the terminating null character
|
|
|
|
sIMEName.SetLength(++IMENameLength);
|
|
|
|
IMENameLength =
|
2017-06-13 02:20:49 +03:00
|
|
|
::ImmGetDescriptionW(aKeyboardLayout, sIMEName.get(),
|
2015-05-15 04:18:07 +03:00
|
|
|
IMENameLength);
|
|
|
|
// Adjust the length to ignore the terminating null character
|
|
|
|
sIMEName.SetLength(IMENameLength);
|
|
|
|
} else {
|
|
|
|
sIMEName.Truncate();
|
2015-05-15 04:18:07 +03:00
|
|
|
}
|
|
|
|
|
2009-05-07 07:49:14 +04:00
|
|
|
WORD langID = LOWORD(aKeyboardLayout);
|
|
|
|
::GetLocaleInfoW(MAKELCID(langID, SORT_DEFAULT),
|
|
|
|
LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
|
|
|
|
(PWSTR)&sCodePage, sizeof(sCodePage) / sizeof(WCHAR));
|
|
|
|
sIMEProperty = ::ImmGetProperty(aKeyboardLayout, IGP_PROPERTY);
|
2015-05-15 04:18:07 +03:00
|
|
|
sIMEUIProperty = ::ImmGetProperty(aKeyboardLayout, IGP_UI);
|
2015-05-15 04:18:08 +03:00
|
|
|
|
|
|
|
// If active IME is a TIP of TSF, we cannot retrieve the name with IMM32 API.
|
|
|
|
// For hacking some bugs of some TIP, we should set an IME name from the
|
|
|
|
// pref.
|
|
|
|
if (sCodePage == 932 && sIMEName.IsEmpty()) {
|
2017-07-31 07:23:50 +03:00
|
|
|
Preferences::GetString("intl.imm.japanese.assume_active_tip_name_as",
|
|
|
|
sIMEName);
|
2015-05-15 04:18:08 +03:00
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:08 +03:00
|
|
|
// Whether the IME supports vertical writing mode might be changed or
|
|
|
|
// some IMEs may need specific font for their UI. Therefore, we should
|
|
|
|
// update composition font forcibly here.
|
|
|
|
if (aWindow) {
|
|
|
|
MaybeAdjustCompositionFont(aWindow, sWritingModeOfCompositionFont, true);
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("InitKeyboardLayout, aKeyboardLayout=%08x (\"%s\"), sCodePage=%lu, "
|
2015-05-15 04:18:07 +03:00
|
|
|
"sIMEProperty=%s, sIMEUIProperty=%s",
|
2015-05-15 04:18:07 +03:00
|
|
|
aKeyboardLayout, NS_ConvertUTF16toUTF8(sIMEName).get(),
|
2015-05-15 04:18:07 +03:00
|
|
|
sCodePage, GetIMEGeneralPropertyName(sIMEProperty).get(),
|
|
|
|
GetIMEUIPropertyName(sIMEUIProperty).get()));
|
2009-05-07 07:49:14 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
UINT
|
|
|
|
IMMHandler::GetKeyboardCodePage()
|
2009-05-07 07:49:14 +04:00
|
|
|
{
|
|
|
|
return sCodePage;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
2017-04-11 15:24:55 +03:00
|
|
|
IMENotificationRequests
|
|
|
|
IMMHandler::GetIMENotificationRequests()
|
2014-03-06 10:13:50 +04:00
|
|
|
{
|
2017-04-11 15:24:55 +03:00
|
|
|
return IMENotificationRequests(
|
|
|
|
IMENotificationRequests::NOTIFY_POSITION_CHANGE |
|
|
|
|
IMENotificationRequests::NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR);
|
2014-03-06 10:13:50 +04:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
// used for checking the lParam of WM_IME_COMPOSITION
|
|
|
|
#define IS_COMPOSING_LPARAM(lParam) \
|
|
|
|
((lParam) & (GCS_COMPSTR | GCS_COMPATTR | GCS_COMPCLAUSE | GCS_CURSORPOS))
|
|
|
|
#define IS_COMMITTING_LPARAM(lParam) ((lParam) & GCS_RESULTSTR)
|
|
|
|
// Some IMEs (e.g., the standard IME for Korean) don't have caret position,
|
2014-10-07 14:01:47 +04:00
|
|
|
// then, we should not set caret position to compositionchange event.
|
2009-05-04 02:20:11 +04:00
|
|
|
#define NO_IME_CARET -1
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::IMMHandler()
|
|
|
|
: mComposingWindow(nullptr)
|
|
|
|
, mCursorPosition(NO_IME_CARET)
|
|
|
|
, mCompositionStart(0)
|
|
|
|
, mIsComposing(false)
|
|
|
|
, mIsComposingOnPlugin(false)
|
|
|
|
, mNativeCaretIsCreated(false)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2016-07-05 12:35:43 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Debug, ("IMMHandler is created"));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::~IMMHandler()
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
if (mIsComposing) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("~IMMHandler, ERROR, the instance is still composing"));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
2016-07-05 12:35:43 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Debug, ("IMMHandler is destroyed"));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::EnsureClauseArray(int32_t aCount)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_MIN(aCount, 0);
|
2013-03-30 22:15:27 +04:00
|
|
|
mClauseArray.SetCapacity(aCount + 32);
|
2009-05-04 02:20:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::EnsureAttributeArray(int32_t aCount)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_MIN(aCount, 0);
|
2013-03-30 22:15:27 +04:00
|
|
|
mAttributeArray.SetCapacity(aCount + 64);
|
2009-05-04 02:20:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::CommitComposition(nsWindow* aWindow, bool aForce)
|
|
|
|
{
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CommitComposition, aForce=%s, aWindow=%p, hWnd=%08x, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"mComposingWindow=%p%s",
|
|
|
|
GetBoolName(aForce), aWindow, aWindow->GetWindowHandle(),
|
|
|
|
gIMMHandler ? gIMMHandler->mComposingWindow : nullptr,
|
|
|
|
gIMMHandler && gIMMHandler->mComposingWindow ?
|
2010-08-08 13:23:25 +04:00
|
|
|
IsComposingOnOurEditor() ? " (composing on editor)" :
|
|
|
|
" (composing on plug-in)" : ""));
|
|
|
|
if (!aForce && !IsComposingWindow(aWindow)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-07 16:02:07 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
bool associated = context.AssociateDefaultContext();
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CommitComposition, associated=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
GetBoolName(associated)));
|
2011-07-07 16:02:07 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
if (context.IsValid()) {
|
|
|
|
::ImmNotifyIME(context.get(), NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
|
|
|
|
::ImmNotifyIME(context.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2011-07-07 16:02:07 +04:00
|
|
|
|
|
|
|
if (associated) {
|
2015-07-23 06:31:28 +03:00
|
|
|
context.Disassociate();
|
2011-07-07 16:02:07 +04:00
|
|
|
}
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::CancelComposition(nsWindow* aWindow, bool aForce)
|
|
|
|
{
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CancelComposition, aForce=%s, aWindow=%p, hWnd=%08x, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"mComposingWindow=%p%s",
|
|
|
|
GetBoolName(aForce), aWindow, aWindow->GetWindowHandle(),
|
|
|
|
gIMMHandler ? gIMMHandler->mComposingWindow : nullptr,
|
|
|
|
gIMMHandler && gIMMHandler->mComposingWindow ?
|
2010-08-08 13:23:25 +04:00
|
|
|
IsComposingOnOurEditor() ? " (composing on editor)" :
|
|
|
|
" (composing on plug-in)" : ""));
|
|
|
|
if (!aForce && !IsComposingWindow(aWindow)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-07-07 16:02:07 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
bool associated = context.AssociateDefaultContext();
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CancelComposition, associated=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
GetBoolName(associated)));
|
2011-07-07 16:02:07 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
if (context.IsValid()) {
|
|
|
|
::ImmNotifyIME(context.get(), NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2011-07-07 16:02:07 +04:00
|
|
|
|
|
|
|
if (associated) {
|
2015-07-23 06:31:28 +03:00
|
|
|
context.Disassociate();
|
2011-07-07 16:02:07 +04:00
|
|
|
}
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
// static
|
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnFocusChange(bool aFocus, nsWindow* aWindow)
|
2015-07-22 06:40:32 +03:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnFocusChange(aFocus=%s, aWindow=%p), sHasFocus=%s, "
|
2016-01-13 06:44:39 +03:00
|
|
|
"IsComposingWindow(aWindow)=%s, aWindow->Destroyed()=%s, "
|
|
|
|
"sNativeCaretIsCreatedForPlugin=%s",
|
2015-11-17 10:47:06 +03:00
|
|
|
GetBoolName(aFocus), aWindow, GetBoolName(sHasFocus),
|
|
|
|
GetBoolName(IsComposingWindow(aWindow)),
|
2016-01-13 06:44:39 +03:00
|
|
|
GetBoolName(aWindow->Destroyed()),
|
|
|
|
GetBoolName(sNativeCaretIsCreatedForPlugin)));
|
2015-07-22 06:40:32 +03:00
|
|
|
|
2016-01-13 06:44:39 +03:00
|
|
|
if (!aFocus) {
|
|
|
|
if (sNativeCaretIsCreatedForPlugin) {
|
|
|
|
::DestroyCaret();
|
|
|
|
sNativeCaretIsCreatedForPlugin = false;
|
|
|
|
}
|
|
|
|
if (IsComposingWindow(aWindow) && aWindow->Destroyed()) {
|
|
|
|
CancelComposition(aWindow);
|
|
|
|
}
|
2015-11-17 10:47:06 +03:00
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
if (gIMMHandler) {
|
|
|
|
gIMMHandler->mSelection.Clear();
|
2015-07-22 06:40:32 +03:00
|
|
|
}
|
|
|
|
sHasFocus = aFocus;
|
|
|
|
}
|
|
|
|
|
2014-01-16 14:05:09 +04:00
|
|
|
// static
|
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnUpdateComposition(nsWindow* aWindow)
|
2014-01-16 14:05:09 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler) {
|
2014-04-07 05:11:12 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-01-16 14:05:09 +04:00
|
|
|
|
|
|
|
if (aWindow->PluginHasFocus()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
2015-07-23 06:31:28 +03:00
|
|
|
gIMMHandler->SetIMERelatedWindowsPos(aWindow, context);
|
2014-01-16 14:05:09 +04:00
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:08 +03:00
|
|
|
// static
|
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnSelectionChange(nsWindow* aWindow,
|
|
|
|
const IMENotification& aIMENotification,
|
|
|
|
bool aIsIMMActive)
|
2015-05-15 04:18:08 +03:00
|
|
|
{
|
2015-07-22 06:40:32 +03:00
|
|
|
if (!aIMENotification.mSelectionChangeData.mCausedByComposition &&
|
|
|
|
aIsIMMActive) {
|
|
|
|
MaybeAdjustCompositionFont(aWindow,
|
|
|
|
aIMENotification.mSelectionChangeData.GetWritingMode());
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
// MaybeAdjustCompositionFont() may create gIMMHandler. So, check it
|
2015-07-22 06:40:32 +03:00
|
|
|
// after a call of MaybeAdjustCompositionFont().
|
2015-07-23 06:31:28 +03:00
|
|
|
if (gIMMHandler) {
|
|
|
|
gIMMHandler->mSelection.Update(aIMENotification);
|
2015-05-15 04:18:08 +03:00
|
|
|
}
|
2015-05-15 04:18:08 +03:00
|
|
|
}
|
2015-05-15 04:18:08 +03:00
|
|
|
|
2015-05-15 04:18:08 +03:00
|
|
|
// static
|
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::MaybeAdjustCompositionFont(nsWindow* aWindow,
|
|
|
|
const WritingMode& aWritingMode,
|
|
|
|
bool aForceUpdate)
|
2015-05-15 04:18:08 +03:00
|
|
|
{
|
2015-05-15 04:18:08 +03:00
|
|
|
switch (sCodePage) {
|
|
|
|
case 932: // Japanese Shift-JIS
|
|
|
|
case 936: // Simlified Chinese GBK
|
|
|
|
case 949: // Korean
|
|
|
|
case 950: // Traditional Chinese Big5
|
|
|
|
EnsureHandlerInstance();
|
|
|
|
break;
|
|
|
|
default:
|
2015-05-15 04:18:08 +03:00
|
|
|
// If there is no instance of nsIMM32Hander, we shouldn't waste footprint.
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler) {
|
2015-05-15 04:18:08 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-05-15 04:18:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Like Navi-Bar of ATOK, some IMEs may require proper composition font even
|
|
|
|
// before sending WM_IME_STARTCOMPOSITION.
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
2015-12-29 16:57:37 +03:00
|
|
|
gIMMHandler->AdjustCompositionFont(aWindow, context, aWritingMode,
|
|
|
|
aForceUpdate);
|
2015-05-15 04:18:08 +03:00
|
|
|
}
|
2014-01-16 14:05:09 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::ProcessInputLangChangeMessage(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mResult = 0;
|
|
|
|
aResult.mConsumed = false;
|
2010-08-08 13:23:25 +04:00
|
|
|
// We don't need to create the instance of the handler here.
|
2015-07-23 06:31:28 +03:00
|
|
|
if (gIMMHandler) {
|
|
|
|
gIMMHandler->OnInputLangChange(aWindow, wParam, lParam, aResult);
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2015-05-15 04:18:08 +03:00
|
|
|
InitKeyboardLayout(aWindow, reinterpret_cast<HKL>(lParam));
|
2010-08-08 13:23:25 +04:00
|
|
|
// We can release the instance here, because the instance may be never
|
|
|
|
// used. E.g., the new keyboard layout may not use IME, or it may use TSF.
|
|
|
|
Terminate();
|
|
|
|
// Don't return as "processed", the messages should be processed on nsWindow
|
|
|
|
// too.
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::ProcessMessage(nsWindow* aWindow,
|
|
|
|
UINT msg,
|
|
|
|
WPARAM& wParam,
|
|
|
|
LPARAM& lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2010-08-08 13:23:25 +04:00
|
|
|
// XXX We store the composing window in mComposingWindow. If IME messages are
|
2009-05-04 02:20:11 +04:00
|
|
|
// sent to different window, we should commit the old transaction. And also
|
|
|
|
// if the new window handle is not focused, probably, we should not start
|
|
|
|
// the composition, however, such case should not be, it's just bad scenario.
|
|
|
|
|
2015-12-29 16:57:37 +03:00
|
|
|
// When a plug-in has focus, we should dispatch the IME events to
|
|
|
|
// the plug-in at first.
|
|
|
|
if (aWindow->PluginHasFocus()) {
|
|
|
|
bool ret = false;
|
|
|
|
if (ProcessMessageForPlugin(aWindow, msg, wParam, lParam, ret, aResult)) {
|
|
|
|
return ret;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mResult = 0;
|
2009-05-04 02:20:11 +04:00
|
|
|
switch (msg) {
|
|
|
|
case WM_INPUTLANGCHANGE:
|
2013-07-18 12:12:31 +04:00
|
|
|
return ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_STARTCOMPOSITION:
|
|
|
|
EnsureHandlerInstance();
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler->OnIMEStartComposition(aWindow, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_COMPOSITION:
|
|
|
|
EnsureHandlerInstance();
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler->OnIMEComposition(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_ENDCOMPOSITION:
|
|
|
|
EnsureHandlerInstance();
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler->OnIMEEndComposition(aWindow, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_CHAR:
|
2013-07-18 12:12:31 +04:00
|
|
|
return OnIMEChar(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_NOTIFY:
|
2013-07-18 12:12:31 +04:00
|
|
|
return OnIMENotify(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_REQUEST:
|
|
|
|
EnsureHandlerInstance();
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler->OnIMERequest(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_SELECT:
|
2013-07-18 12:12:31 +04:00
|
|
|
return OnIMESelect(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
case WM_IME_SETCONTEXT:
|
2013-07-18 12:12:31 +04:00
|
|
|
return OnIMESetContext(aWindow, wParam, lParam, aResult);
|
2010-06-02 06:14:11 +04:00
|
|
|
case WM_KEYDOWN:
|
2013-07-18 12:12:31 +04:00
|
|
|
return OnKeyDownEvent(aWindow, wParam, lParam, aResult);
|
2010-08-08 13:23:25 +04:00
|
|
|
case WM_CHAR:
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
return gIMMHandler->OnChar(aWindow, wParam, lParam, aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
default:
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::ProcessMessageForPlugin(nsWindow* aWindow,
|
|
|
|
UINT msg,
|
|
|
|
WPARAM& wParam,
|
|
|
|
LPARAM& lParam,
|
2015-12-29 16:57:37 +03:00
|
|
|
bool& aRet,
|
2015-07-23 06:31:28 +03:00
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mResult = 0;
|
|
|
|
aResult.mConsumed = false;
|
2009-05-04 02:20:11 +04:00
|
|
|
switch (msg) {
|
2010-08-08 13:23:25 +04:00
|
|
|
case WM_INPUTLANGCHANGEREQUEST:
|
|
|
|
case WM_INPUTLANGCHANGE:
|
2011-10-02 06:16:19 +04:00
|
|
|
aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
|
2015-12-29 16:57:37 +03:00
|
|
|
aRet = ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
|
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
case WM_IME_CHAR:
|
|
|
|
EnsureHandlerInstance();
|
2015-12-29 16:57:37 +03:00
|
|
|
aRet = gIMMHandler->OnIMECharOnPlugin(aWindow, wParam, lParam, aResult);
|
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
case WM_IME_SETCONTEXT:
|
2015-12-29 16:57:37 +03:00
|
|
|
aRet = OnIMESetContextOnPlugin(aWindow, wParam, lParam, aResult);
|
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
case WM_CHAR:
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler) {
|
2015-12-29 16:57:37 +03:00
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2015-12-29 16:57:37 +03:00
|
|
|
aRet = gIMMHandler->OnCharOnPlugin(aWindow, wParam, lParam, aResult);
|
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
case WM_IME_COMPOSITIONFULL:
|
|
|
|
case WM_IME_CONTROL:
|
|
|
|
case WM_IME_KEYDOWN:
|
|
|
|
case WM_IME_KEYUP:
|
|
|
|
case WM_IME_SELECT:
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed =
|
|
|
|
aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
|
2015-12-29 16:57:37 +03:00
|
|
|
aRet = true;
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2015-12-29 16:57:38 +03:00
|
|
|
case WM_IME_REQUEST:
|
|
|
|
// Our plugin implementation is alwasy OOP. So WM_IME_REQUEST doesn't
|
|
|
|
// allow that parameter is pointer and shouldn't handle into Gecko.
|
|
|
|
aRet = false;
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
/****************************************************************************
|
|
|
|
* message handlers
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnInputLangChange(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnInputLangChange, hWnd=%08x, wParam=%08x, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam, lParam));
|
|
|
|
|
2013-03-06 10:14:32 +04:00
|
|
|
aWindow->NotifyIME(REQUEST_TO_COMMIT_COMPOSITION);
|
2009-05-04 02:20:11 +04:00
|
|
|
NS_ASSERTION(!mIsComposing, "ResetInputState failed");
|
|
|
|
|
|
|
|
if (mIsComposing) {
|
|
|
|
HandleEndComposition(aWindow);
|
|
|
|
}
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMEStartComposition(nsWindow* aWindow,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEStartComposition, hWnd=%08x, mIsComposing=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
aWindow->GetWindowHandle(), GetBoolName(mIsComposing)));
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = ShouldDrawCompositionStringOurselves();
|
2009-05-04 02:20:11 +04:00
|
|
|
if (mIsComposing) {
|
2010-07-28 19:55:33 +04:00
|
|
|
NS_WARNING("Composition has been already started");
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
HandleStartComposition(aWindow, context);
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMEComposition(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEComposition, hWnd=%08x, lParam=%08x, mIsComposing=%s, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"GCS_RESULTSTR=%s, GCS_COMPSTR=%s, GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, "
|
|
|
|
"GCS_CURSORPOS=%s,",
|
|
|
|
aWindow->GetWindowHandle(), lParam, GetBoolName(mIsComposing),
|
|
|
|
GetBoolName(lParam & GCS_RESULTSTR), GetBoolName(lParam & GCS_COMPSTR),
|
|
|
|
GetBoolName(lParam & GCS_COMPATTR), GetBoolName(lParam & GCS_COMPCLAUSE),
|
|
|
|
GetBoolName(lParam & GCS_CURSORPOS)));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
aResult.mConsumed = HandleComposition(aWindow, context, lParam);
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMEEndComposition(nsWindow* aWindow,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEEndComposition, hWnd=%08x, mIsComposing=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
aWindow->GetWindowHandle(), GetBoolName(mIsComposing)));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = ShouldDrawCompositionStringOurselves();
|
2009-05-04 02:20:11 +04:00
|
|
|
if (!mIsComposing) {
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2012-02-07 17:16:41 +04:00
|
|
|
// Korean IME posts WM_IME_ENDCOMPOSITION first when we hit space during
|
|
|
|
// composition. Then, we should ignore the message and commit the composition
|
|
|
|
// string at following WM_IME_COMPOSITION.
|
|
|
|
MSG compositionMsg;
|
2013-03-18 08:41:24 +04:00
|
|
|
if (WinUtils::PeekMessage(&compositionMsg, aWindow->GetWindowHandle(),
|
|
|
|
WM_IME_STARTCOMPOSITION, WM_IME_COMPOSITION,
|
|
|
|
PM_NOREMOVE) &&
|
2012-02-07 17:16:41 +04:00
|
|
|
compositionMsg.message == WM_IME_COMPOSITION &&
|
|
|
|
IS_COMMITTING_LPARAM(compositionMsg.lParam)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEEndComposition, WM_IME_ENDCOMPOSITION is followed by "
|
2012-02-07 17:16:41 +04:00
|
|
|
"WM_IME_COMPOSITION, ignoring the message..."));
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2012-02-07 17:16:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, e.g., ChangJie doesn't post WM_IME_COMPOSITION before
|
|
|
|
// WM_IME_ENDCOMPOSITION when composition string becomes empty.
|
2014-10-07 14:01:47 +04:00
|
|
|
// Then, we should dispatch a compositionupdate event, a compositionchange
|
|
|
|
// event and a compositionend event.
|
|
|
|
// XXX Shouldn't we dispatch the compositionchange event with actual or
|
|
|
|
// latest composition string?
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEEndComposition, mCompositionString=\"%s\"%s",
|
2012-02-07 17:16:41 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mCompositionString).get(),
|
|
|
|
mCompositionString.IsEmpty() ? "" : ", but canceling it..."));
|
|
|
|
|
2014-11-25 08:02:33 +03:00
|
|
|
HandleEndComposition(aWindow, &EmptyString());
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnIMEChar(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEChar, hWnd=%08x, char=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam));
|
|
|
|
|
2014-10-07 14:01:47 +04:00
|
|
|
// We don't need to fire any compositionchange events from here. This method
|
|
|
|
// will be called when the composition string of the current IME is not drawn
|
|
|
|
// by us and some characters are committed. In that case, the committed
|
|
|
|
// string was processed in nsWindow::OnIMEComposition already.
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
// We need to consume the message so that Windows don't send two WM_CHAR msgs
|
|
|
|
aResult.mConsumed = true;
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnIMECompositionFull(nsWindow* aWindow,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMECompositionFull, hWnd=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
|
|
|
|
// not implement yet
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnIMENotify(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
switch (wParam) {
|
|
|
|
case IMN_CHANGECANDIDATE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_CHANGECANDIDATE, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), lParam));
|
|
|
|
break;
|
|
|
|
case IMN_CLOSECANDIDATE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_CLOSECANDIDATE, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), lParam));
|
|
|
|
break;
|
|
|
|
case IMN_CLOSESTATUSWINDOW:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_CLOSESTATUSWINDOW",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_GUIDELINE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_GUIDELINE",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_OPENCANDIDATE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_OPENCANDIDATE, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), lParam));
|
|
|
|
break;
|
|
|
|
case IMN_OPENSTATUSWINDOW:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_OPENSTATUSWINDOW",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_SETCANDIDATEPOS:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETCANDIDATEPOS, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), lParam));
|
|
|
|
break;
|
|
|
|
case IMN_SETCOMPOSITIONFONT:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETCOMPOSITIONFONT",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_SETCOMPOSITIONWINDOW:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETCOMPOSITIONWINDOW",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_SETCONVERSIONMODE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETCONVERSIONMODE",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_SETOPENSTATUS:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETOPENSTATUS",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_SETSENTENCEMODE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETSENTENCEMODE",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_SETSTATUSWINDOWPOS:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_SETSTATUSWINDOWPOS",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
case IMN_PRIVATE:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMENotify, hWnd=%08x, IMN_PRIVATE",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// not implement yet
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMERequest(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
switch (wParam) {
|
|
|
|
case IMR_RECONVERTSTRING:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMERequest, hWnd=%08x, IMR_RECONVERTSTRING",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = HandleReconvert(aWindow, lParam, &aResult.mResult);
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
case IMR_QUERYCHARPOSITION:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMERequest, hWnd=%08x, IMR_QUERYCHARPOSITION",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle()));
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed =
|
|
|
|
HandleQueryCharPosition(aWindow, lParam, &aResult.mResult);
|
|
|
|
return true;
|
2009-12-17 07:40:24 +03:00
|
|
|
case IMR_DOCUMENTFEED:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMERequest, hWnd=%08x, IMR_DOCUMENTFEED",
|
2009-12-17 07:40:24 +03:00
|
|
|
aWindow->GetWindowHandle()));
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = HandleDocumentFeed(aWindow, lParam, &aResult.mResult);
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
default:
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMERequest, hWnd=%08x, wParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam));
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnIMESelect(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMESelect, hWnd=%08x, wParam=%08x, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam, lParam));
|
|
|
|
|
|
|
|
// not implement yet
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnIMESetContext(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMESetContext, hWnd=%08x, %s, lParam=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam));
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
// NOTE: If the aWindow is top level window of the composing window because
|
|
|
|
// when a window on deactive window gets focus, WM_IME_SETCONTEXT (wParam is
|
|
|
|
// TRUE) is sent to the top level window first. After that,
|
|
|
|
// WM_IME_SETCONTEXT (wParam is FALSE) is sent to the top level window.
|
|
|
|
// Finally, WM_IME_SETCONTEXT (wParam is TRUE) is sent to the focused window.
|
|
|
|
// The top level window never becomes composing window, so, we can ignore
|
|
|
|
// the WM_IME_SETCONTEXT on the top level window.
|
|
|
|
if (IsTopLevelWindowOfComposition(aWindow)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMESetContext, hWnd=%08x is top level window"));
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// When IME context is activating on another window,
|
|
|
|
// we should commit the old composition on the old window.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool cancelComposition = false;
|
2015-07-23 06:31:28 +03:00
|
|
|
if (wParam && gIMMHandler) {
|
2010-08-08 13:23:25 +04:00
|
|
|
cancelComposition =
|
2015-07-23 06:31:28 +03:00
|
|
|
gIMMHandler->CommitCompositionOnPreviousWindow(aWindow);
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2009-05-07 07:49:14 +04:00
|
|
|
if (wParam && (lParam & ISC_SHOWUICOMPOSITIONWINDOW) &&
|
|
|
|
ShouldDrawCompositionStringOurselves()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMESetContext, ISC_SHOWUICOMPOSITIONWINDOW is removed"));
|
2009-05-04 02:20:11 +04:00
|
|
|
lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
|
|
|
|
}
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
// We should sent WM_IME_SETCONTEXT to the DefWndProc here because the
|
|
|
|
// ancestor windows shouldn't receive this message. If they receive the
|
|
|
|
// message, we cannot know whether which window is the target of the message.
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mResult = ::DefWindowProc(aWindow->GetWindowHandle(),
|
|
|
|
WM_IME_SETCONTEXT, wParam, lParam);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
|
|
|
// Cancel composition on the new window if we committed our composition on
|
|
|
|
// another window.
|
|
|
|
if (cancelComposition) {
|
2011-10-02 06:16:19 +04:00
|
|
|
CancelComposition(aWindow, true);
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = true;
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnChar(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2013-07-18 12:12:31 +04:00
|
|
|
// The return value must be same as aResult.mConsumed because only when we
|
|
|
|
// consume the message, the caller shouldn't do anything anymore but
|
|
|
|
// otherwise, the caller should handle the message.
|
|
|
|
aResult.mConsumed = false;
|
2010-08-08 13:23:25 +04:00
|
|
|
if (IsIMECharRecordsEmpty()) {
|
2013-07-18 12:12:31 +04:00
|
|
|
return aResult.mConsumed;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
WPARAM recWParam;
|
|
|
|
LPARAM recLParam;
|
|
|
|
DequeueIMECharRecords(recWParam, recLParam);
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnChar, aWindow=%p, wParam=%08x, lParam=%08x, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"recorded: wParam=%08x, lParam=%08x",
|
|
|
|
aWindow->GetWindowHandle(), wParam, lParam, recWParam, recLParam));
|
2010-08-08 13:23:25 +04:00
|
|
|
// If an unexpected char message comes, we should reset the records,
|
|
|
|
// of course, this shouldn't happen.
|
|
|
|
if (recWParam != wParam || recLParam != lParam) {
|
|
|
|
ResetIMECharRecords();
|
2013-07-18 12:12:31 +04:00
|
|
|
return aResult.mConsumed;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
// Eat the char message which is caused by WM_IME_CHAR because we should
|
|
|
|
// have processed the IME messages, so, this message could be come from
|
|
|
|
// a windowless plug-in.
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = true;
|
|
|
|
return aResult.mConsumed;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* message handlers for plug-in
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMEStartCompositionOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
2015-12-29 16:57:38 +03:00
|
|
|
LPARAM lParam)
|
2015-07-23 06:31:28 +03:00
|
|
|
{
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEStartCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
aWindow->GetWindowHandle(), GetBoolName(mIsComposingOnPlugin)));
|
2011-10-02 06:16:19 +04:00
|
|
|
mIsComposingOnPlugin = true;
|
2016-03-16 07:47:48 +03:00
|
|
|
mDispatcher = GetTextEventDispatcherFor(aWindow);
|
2010-08-08 13:23:25 +04:00
|
|
|
mComposingWindow = aWindow;
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
SetIMERelatedWindowsPosOnPlugin(aWindow, context);
|
2015-05-15 04:18:07 +03:00
|
|
|
// On widnowless plugin, we should assume that the focused editor is always
|
|
|
|
// in horizontal writing mode.
|
2015-12-29 16:57:37 +03:00
|
|
|
AdjustCompositionFont(aWindow, context, WritingMode());
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMECompositionOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
2015-12-29 16:57:38 +03:00
|
|
|
LPARAM lParam)
|
2015-07-23 06:31:28 +03:00
|
|
|
{
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMECompositionOnPlugin, hWnd=%08x, lParam=%08x, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"mIsComposingOnPlugin=%s, GCS_RESULTSTR=%s, GCS_COMPSTR=%s, "
|
|
|
|
"GCS_COMPATTR=%s, GCS_COMPCLAUSE=%s, GCS_CURSORPOS=%s",
|
|
|
|
aWindow->GetWindowHandle(), lParam, GetBoolName(mIsComposingOnPlugin),
|
|
|
|
GetBoolName(lParam & GCS_RESULTSTR), GetBoolName(lParam & GCS_COMPSTR),
|
|
|
|
GetBoolName(lParam & GCS_COMPATTR), GetBoolName(lParam & GCS_COMPCLAUSE),
|
|
|
|
GetBoolName(lParam & GCS_CURSORPOS)));
|
2010-08-08 13:23:25 +04:00
|
|
|
// We should end composition if there is a committed string.
|
|
|
|
if (IS_COMMITTING_LPARAM(lParam)) {
|
2011-10-02 06:16:19 +04:00
|
|
|
mIsComposingOnPlugin = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
mComposingWindow = nullptr;
|
2016-03-16 07:47:48 +03:00
|
|
|
mDispatcher = nullptr;
|
2015-12-29 16:57:38 +03:00
|
|
|
return;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
// Continue composition if there is still a string being composed.
|
|
|
|
if (IS_COMPOSING_LPARAM(lParam)) {
|
2011-10-02 06:16:19 +04:00
|
|
|
mIsComposingOnPlugin = true;
|
2016-03-16 07:47:48 +03:00
|
|
|
mDispatcher = GetTextEventDispatcherFor(aWindow);
|
2010-08-08 13:23:25 +04:00
|
|
|
mComposingWindow = aWindow;
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
SetIMERelatedWindowsPosOnPlugin(aWindow, context);
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMEEndCompositionOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
2015-12-29 16:57:38 +03:00
|
|
|
LPARAM lParam)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMEEndCompositionOnPlugin, hWnd=%08x, mIsComposingOnPlugin=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
aWindow->GetWindowHandle(), GetBoolName(mIsComposingOnPlugin)));
|
2010-08-08 13:23:25 +04:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
mIsComposingOnPlugin = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
mComposingWindow = nullptr;
|
2016-03-16 07:47:48 +03:00
|
|
|
mDispatcher = nullptr;
|
2013-12-18 05:43:15 +04:00
|
|
|
|
|
|
|
if (mNativeCaretIsCreated) {
|
|
|
|
::DestroyCaret();
|
|
|
|
mNativeCaretIsCreated = false;
|
|
|
|
}
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnIMECharOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMECharOnPlugin, hWnd=%08x, char=%08x, scancode=%08x",
|
2010-08-08 13:23:25 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam, lParam));
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed =
|
2011-10-02 06:16:19 +04:00
|
|
|
aWindow->DispatchPluginEvent(WM_IME_CHAR, wParam, lParam, true);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
if (!aResult.mConsumed) {
|
2010-08-08 13:23:25 +04:00
|
|
|
// Record the WM_CHAR messages which are going to be coming.
|
|
|
|
EnsureHandlerInstance();
|
|
|
|
EnqueueIMECharRecords(wParam, lParam);
|
|
|
|
}
|
2013-07-18 12:12:31 +04:00
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnIMESetContextOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnIMESetContextOnPlugin, hWnd=%08x, %s, lParam=%08x",
|
2010-08-08 13:23:25 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam));
|
|
|
|
|
|
|
|
// If the IME context becomes active on a plug-in, we should commit
|
|
|
|
// our composition. And also we should cancel the composition on new
|
|
|
|
// window. Note that if IsTopLevelWindowOfComposition(aWindow) returns
|
|
|
|
// true, we should ignore the message here, see the comment in
|
|
|
|
// OnIMESetContext() for the detail.
|
2015-07-23 06:31:28 +03:00
|
|
|
if (wParam && gIMMHandler && !IsTopLevelWindowOfComposition(aWindow)) {
|
|
|
|
if (gIMMHandler->CommitCompositionOnPreviousWindow(aWindow)) {
|
2010-08-08 13:23:25 +04:00
|
|
|
CancelComposition(aWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dispatch message to the plug-in.
|
|
|
|
// XXX When a windowless plug-in gets focus, we should send
|
|
|
|
// WM_IME_SETCONTEXT
|
2011-10-02 06:16:19 +04:00
|
|
|
aWindow->DispatchPluginEvent(WM_IME_SETCONTEXT, wParam, lParam, false);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
|
|
|
// We should send WM_IME_SETCONTEXT to the DefWndProc here. It shouldn't
|
|
|
|
// be received on ancestor windows, see OnIMESetContext() for the detail.
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mResult = ::DefWindowProc(aWindow->GetWindowHandle(),
|
|
|
|
WM_IME_SETCONTEXT, wParam, lParam);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
|
|
|
// Don't synchronously dispatch the pending events when we receive
|
|
|
|
// WM_IME_SETCONTEXT because we get it during plugin destruction.
|
|
|
|
// (bug 491848)
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = true;
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnCharOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-12-29 16:57:38 +03:00
|
|
|
NS_WARNING("OnCharOnPlugin");
|
|
|
|
if (mIsComposing) {
|
|
|
|
aWindow->NotifyIME(REQUEST_TO_COMMIT_COMPOSITION);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
// We should never consume char message on windowless plugin.
|
|
|
|
aResult.mConsumed = false;
|
2010-08-08 13:23:25 +04:00
|
|
|
if (IsIMECharRecordsEmpty()) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
WPARAM recWParam;
|
|
|
|
LPARAM recLParam;
|
|
|
|
DequeueIMECharRecords(recWParam, recLParam);
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnCharOnPlugin, aWindow=%p, wParam=%08x, lParam=%08x, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"recorded: wParam=%08x, lParam=%08x",
|
|
|
|
aWindow->GetWindowHandle(), wParam, lParam, recWParam, recLParam));
|
2010-08-08 13:23:25 +04:00
|
|
|
// If an unexpected char message comes, we should reset the records,
|
|
|
|
// of course, this shouldn't happen.
|
|
|
|
if (recWParam != wParam || recLParam != lParam) {
|
|
|
|
ResetIMECharRecords();
|
|
|
|
}
|
|
|
|
// WM_CHAR on plug-in is always handled by nsWindow.
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
/****************************************************************************
|
|
|
|
* others
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
TextEventDispatcher*
|
|
|
|
IMMHandler::GetTextEventDispatcherFor(nsWindow* aWindow)
|
|
|
|
{
|
|
|
|
return aWindow == mComposingWindow && mDispatcher ?
|
2016-03-17 07:56:15 +03:00
|
|
|
mDispatcher.get() : aWindow->GetTextEventDispatcher();
|
2016-03-16 07:47:48 +03:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::HandleStartComposition(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mIsComposing,
|
|
|
|
"HandleStartComposition is called but mIsComposing is TRUE");
|
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
Selection& selection = GetSelection();
|
|
|
|
if (!selection.EnsureValidSelection(aWindow)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleStartComposition, FAILED, due to "
|
2015-07-22 06:40:32 +03:00
|
|
|
"Selection::EnsureValidSelection() failure"));
|
2009-05-15 04:46:24 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:37 +03:00
|
|
|
AdjustCompositionFont(aWindow, aContext, selection.mWritingMode);
|
2015-05-15 04:18:07 +03:00
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
mCompositionStart = selection.mOffset;
|
2015-07-26 06:29:47 +03:00
|
|
|
mCursorPosition = NO_IME_CARET;
|
2009-05-15 04:46:24 +04:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> dispatcher = GetTextEventDispatcherFor(aWindow);
|
|
|
|
nsresult rv = dispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleStartComposition, FAILED due to "
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::BeginNativeInputTransaction() failure"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WidgetEventTime eventTime = aWindow->CurrentMessageWidgetEventTime();
|
|
|
|
nsEventStatus status;
|
|
|
|
rv = dispatcher->StartComposition(status, &eventTime);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleStartComposition, FAILED, due to "
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::StartComposition() failure"));
|
|
|
|
return;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
mIsComposing = true;
|
2010-08-08 13:23:25 +04:00
|
|
|
mComposingWindow = aWindow;
|
2016-03-16 07:47:48 +03:00
|
|
|
mDispatcher = dispatcher;
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleStartComposition, START composition, mCompositionStart=%ld",
|
2009-05-15 04:46:24 +04:00
|
|
|
mCompositionStart));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::HandleComposition(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext,
|
|
|
|
LPARAM lParam)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
// for bug #60050
|
|
|
|
// MS-IME 95/97/98/2000 may send WM_IME_COMPOSITION with non-conversion
|
|
|
|
// mode before it send WM_IME_STARTCOMPOSITION.
|
2010-07-28 19:55:33 +04:00
|
|
|
// However, ATOK sends a WM_IME_COMPOSITION before WM_IME_STARTCOMPOSITION,
|
|
|
|
// and if we access ATOK via some APIs, ATOK will sometimes fail to
|
|
|
|
// initialize its state. If WM_IME_STARTCOMPOSITION is already in the
|
|
|
|
// message queue, we should ignore the strange WM_IME_COMPOSITION message and
|
|
|
|
// skip to the next. So, we should look for next composition message
|
|
|
|
// (WM_IME_STARTCOMPOSITION or WM_IME_ENDCOMPOSITION or WM_IME_COMPOSITION),
|
|
|
|
// and if it's WM_IME_STARTCOMPOSITION, and one more next composition message
|
|
|
|
// is WM_IME_COMPOSITION, current IME is ATOK, probably. Otherwise, we
|
|
|
|
// should start composition forcibly.
|
|
|
|
if (!mIsComposing) {
|
|
|
|
MSG msg1, msg2;
|
|
|
|
HWND wnd = aWindow->GetWindowHandle();
|
2013-03-18 08:41:24 +04:00
|
|
|
if (WinUtils::PeekMessage(&msg1, wnd, WM_IME_STARTCOMPOSITION,
|
|
|
|
WM_IME_COMPOSITION, PM_NOREMOVE) &&
|
2010-07-28 19:55:33 +04:00
|
|
|
msg1.message == WM_IME_STARTCOMPOSITION &&
|
2013-03-18 08:41:24 +04:00
|
|
|
WinUtils::PeekMessage(&msg2, wnd, WM_IME_ENDCOMPOSITION,
|
|
|
|
WM_IME_COMPOSITION, PM_NOREMOVE) &&
|
2010-07-28 19:55:33 +04:00
|
|
|
msg2.message == WM_IME_COMPOSITION) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, Ignores due to find a "
|
2015-07-23 06:31:28 +03:00
|
|
|
"WM_IME_STARTCOMPOSITION"));
|
2010-07-28 19:55:33 +04:00
|
|
|
return ShouldDrawCompositionStringOurselves();
|
|
|
|
}
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool startCompositionMessageHasBeenSent = mIsComposing;
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// This catches a fixed result
|
|
|
|
//
|
|
|
|
if (IS_COMMITTING_LPARAM(lParam)) {
|
|
|
|
if (!mIsComposing) {
|
2015-07-23 06:31:28 +03:00
|
|
|
HandleStartComposition(aWindow, aContext);
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
GetCompositionString(aContext, GCS_RESULTSTR, mCompositionString);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_RESULTSTR"));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2014-11-25 08:02:33 +03:00
|
|
|
HandleEndComposition(aWindow, &mCompositionString);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
if (!IS_COMPOSING_LPARAM(lParam)) {
|
|
|
|
return ShouldDrawCompositionStringOurselves();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// This provides us with a composition string
|
|
|
|
//
|
|
|
|
if (!mIsComposing) {
|
2015-07-23 06:31:28 +03:00
|
|
|
HandleStartComposition(aWindow, aContext);
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// 1. Get GCS_COMPSTR
|
|
|
|
//--------------------------------------------------------
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_COMPSTR"));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2014-11-25 08:02:33 +03:00
|
|
|
nsAutoString previousCompositionString(mCompositionString);
|
2015-07-23 06:31:28 +03:00
|
|
|
GetCompositionString(aContext, GCS_COMPSTR, mCompositionString);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2012-02-05 16:19:31 +04:00
|
|
|
if (!IS_COMPOSING_LPARAM(lParam)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, lParam doesn't indicate composing, "
|
2014-11-25 08:02:33 +03:00
|
|
|
"mCompositionString=\"%s\", previousCompositionString=\"%s\"",
|
2012-02-05 16:19:31 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mCompositionString).get(),
|
2014-11-25 08:02:33 +03:00
|
|
|
NS_ConvertUTF16toUTF8(previousCompositionString).get()));
|
2012-02-05 16:19:31 +04:00
|
|
|
|
|
|
|
// If composition string isn't changed, we can trust the lParam.
|
|
|
|
// So, we need to do nothing.
|
2014-11-25 08:02:33 +03:00
|
|
|
if (previousCompositionString == mCompositionString) {
|
2012-02-05 16:19:31 +04:00
|
|
|
return ShouldDrawCompositionStringOurselves();
|
|
|
|
}
|
|
|
|
|
|
|
|
// IME may send WM_IME_COMPOSITION without composing lParam values
|
|
|
|
// when composition string becomes empty (e.g., using Backspace key).
|
2014-10-07 14:01:47 +04:00
|
|
|
// If composition string is empty, we should dispatch a compositionchange
|
2014-11-25 08:02:33 +03:00
|
|
|
// event with empty string and clear the clause information.
|
2012-02-05 16:19:31 +04:00
|
|
|
if (mCompositionString.IsEmpty()) {
|
2014-11-25 08:02:33 +03:00
|
|
|
mClauseArray.Clear();
|
|
|
|
mAttributeArray.Clear();
|
|
|
|
mCursorPosition = 0;
|
2015-07-23 06:31:28 +03:00
|
|
|
DispatchCompositionChangeEvent(aWindow, aContext);
|
2012-02-05 16:19:31 +04:00
|
|
|
return ShouldDrawCompositionStringOurselves();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we cannot trust the lParam value. We might need to
|
2014-10-07 14:01:47 +04:00
|
|
|
// dispatch compositionchange event with the latest composition string
|
|
|
|
// information.
|
2012-02-05 16:19:31 +04:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=296339
|
|
|
|
if (mCompositionString.IsEmpty() && !startCompositionMessageHasBeenSent) {
|
|
|
|
// In this case, maybe, the sender is MSPinYin. That sends *only*
|
|
|
|
// WM_IME_COMPOSITION with GCS_COMP* and GCS_RESULT* when
|
|
|
|
// user inputted the Chinese full stop. So, that doesn't send
|
|
|
|
// WM_IME_STARTCOMPOSITION and WM_IME_ENDCOMPOSITION.
|
|
|
|
// If WM_IME_STARTCOMPOSITION was not sent and the composition
|
|
|
|
// string is null (it indicates the composition transaction ended),
|
|
|
|
// WM_IME_ENDCOMPOSITION may not be sent. If so, we cannot run
|
|
|
|
// HandleEndComposition() in other place.
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, Aborting GCS_COMPSTR"));
|
2009-05-04 02:20:11 +04:00
|
|
|
HandleEndComposition(aWindow);
|
|
|
|
return IS_COMMITTING_LPARAM(lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// 2. Get GCS_COMPCLAUSE
|
|
|
|
//--------------------------------------------------------
|
|
|
|
long clauseArrayLength =
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmGetCompositionStringW(aContext.get(), GCS_COMPCLAUSE, nullptr, 0);
|
2012-08-22 19:56:38 +04:00
|
|
|
clauseArrayLength /= sizeof(uint32_t);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
if (clauseArrayLength > 0) {
|
|
|
|
nsresult rv = EnsureClauseArray(clauseArrayLength);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
// Intelligent ABC IME (Simplified Chinese IME, the code page is 936)
|
|
|
|
// will crash in ImmGetCompositionStringW for GCS_COMPCLAUSE (bug 424663).
|
|
|
|
// See comment 35 of the bug for the detail. Therefore, we should use A
|
|
|
|
// API for it, however, we should not kill Unicode support on all IMEs.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useA_API = !(sIMEProperty & IME_PROP_UNICODE);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_COMPCLAUSE, useA_API=%s",
|
2009-05-04 02:20:11 +04:00
|
|
|
useA_API ? "TRUE" : "FALSE"));
|
|
|
|
|
|
|
|
long clauseArrayLength2 =
|
|
|
|
useA_API ?
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmGetCompositionStringA(aContext.get(), GCS_COMPCLAUSE,
|
2009-05-04 02:20:11 +04:00
|
|
|
mClauseArray.Elements(),
|
2012-08-22 19:56:38 +04:00
|
|
|
mClauseArray.Capacity() * sizeof(uint32_t)) :
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmGetCompositionStringW(aContext.get(), GCS_COMPCLAUSE,
|
2009-05-04 02:20:11 +04:00
|
|
|
mClauseArray.Elements(),
|
2012-08-22 19:56:38 +04:00
|
|
|
mClauseArray.Capacity() * sizeof(uint32_t));
|
|
|
|
clauseArrayLength2 /= sizeof(uint32_t);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
if (clauseArrayLength != clauseArrayLength2) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_COMPCLAUSE, clauseArrayLength=%ld but "
|
2015-07-23 06:31:28 +03:00
|
|
|
"clauseArrayLength2=%ld",
|
2009-05-04 02:20:11 +04:00
|
|
|
clauseArrayLength, clauseArrayLength2));
|
|
|
|
if (clauseArrayLength > clauseArrayLength2)
|
|
|
|
clauseArrayLength = clauseArrayLength2;
|
|
|
|
}
|
|
|
|
|
2016-09-14 05:07:19 +03:00
|
|
|
if (useA_API && clauseArrayLength > 0) {
|
2009-05-04 02:20:11 +04:00
|
|
|
// Convert each values of sIMECompClauseArray. The values mean offset of
|
|
|
|
// the clauses in ANSI string. But we need the values in Unicode string.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString compANSIStr;
|
2009-05-04 02:20:11 +04:00
|
|
|
if (ConvertToANSIString(mCompositionString, GetKeyboardCodePage(),
|
|
|
|
compANSIStr)) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t maxlen = compANSIStr.Length();
|
2016-09-14 05:07:19 +03:00
|
|
|
mClauseArray.SetLength(clauseArrayLength);
|
2009-05-04 02:20:11 +04:00
|
|
|
mClauseArray[0] = 0; // first value must be 0
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 1; i < clauseArrayLength; i++) {
|
2013-01-15 16:22:03 +04:00
|
|
|
uint32_t len = std::min(mClauseArray[i], maxlen);
|
2009-05-04 02:20:11 +04:00
|
|
|
mClauseArray[i] = ::MultiByteToWideChar(GetKeyboardCodePage(),
|
|
|
|
MB_PRECOMPOSED,
|
|
|
|
(LPCSTR)compANSIStr.get(),
|
2013-10-08 22:48:20 +04:00
|
|
|
len, nullptr, 0);
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// compClauseArrayLength may be negative. I.e., ImmGetCompositionStringW
|
|
|
|
// may return an error code.
|
2013-01-15 16:22:03 +04:00
|
|
|
mClauseArray.SetLength(std::max<long>(0, clauseArrayLength));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_COMPCLAUSE, mClauseLength=%ld",
|
2009-05-04 02:20:11 +04:00
|
|
|
mClauseArray.Length()));
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// 3. Get GCS_COMPATTR
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// This provides us with the attribute string necessary
|
|
|
|
// for doing hiliting
|
|
|
|
long attrArrayLength =
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmGetCompositionStringW(aContext.get(), GCS_COMPATTR, nullptr, 0);
|
2012-08-22 19:56:38 +04:00
|
|
|
attrArrayLength /= sizeof(uint8_t);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
if (attrArrayLength > 0) {
|
|
|
|
nsresult rv = EnsureAttributeArray(attrArrayLength);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2009-05-04 02:20:11 +04:00
|
|
|
attrArrayLength =
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmGetCompositionStringW(aContext.get(), GCS_COMPATTR,
|
2009-05-04 02:20:11 +04:00
|
|
|
mAttributeArray.Elements(),
|
2012-08-22 19:56:38 +04:00
|
|
|
mAttributeArray.Capacity() * sizeof(uint8_t));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// attrStrLen may be negative. I.e., ImmGetCompositionStringW may return an
|
|
|
|
// error code.
|
2013-01-15 16:22:03 +04:00
|
|
|
mAttributeArray.SetLength(std::max<long>(0, attrArrayLength));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_COMPATTR, mAttributeLength=%ld",
|
2009-05-04 02:20:11 +04:00
|
|
|
mAttributeArray.Length()));
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// 4. Get GCS_CURSOPOS
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Some IMEs (e.g., the standard IME for Korean) don't have caret position.
|
|
|
|
if (lParam & GCS_CURSORPOS) {
|
|
|
|
mCursorPosition =
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmGetCompositionStringW(aContext.get(), GCS_CURSORPOS, nullptr, 0);
|
2009-05-04 02:20:11 +04:00
|
|
|
if (mCursorPosition < 0) {
|
|
|
|
mCursorPosition = NO_IME_CARET; // The result is error
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCursorPosition = NO_IME_CARET;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mCursorPosition <= (long)mCompositionString.Length(),
|
|
|
|
"illegal pos");
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleComposition, GCS_CURSORPOS, mCursorPosition=%d",
|
2009-05-04 02:20:11 +04:00
|
|
|
mCursorPosition));
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
2014-10-07 14:01:47 +04:00
|
|
|
// 5. Send the compositionchange event
|
2009-05-04 02:20:11 +04:00
|
|
|
//--------------------------------------------------------
|
2015-07-23 06:31:28 +03:00
|
|
|
DispatchCompositionChangeEvent(aWindow, aContext);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
return ShouldDrawCompositionStringOurselves();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::HandleEndComposition(nsWindow* aWindow,
|
|
|
|
const nsAString* aCommitString)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_ASSERT(mIsComposing,
|
2009-05-04 02:20:11 +04:00
|
|
|
"HandleEndComposition is called but mIsComposing is FALSE");
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleEndComposition(aWindow=0x%p, aCommitString=0x%p (\"%s\"))",
|
2014-11-25 08:02:33 +03:00
|
|
|
aWindow, aCommitString,
|
|
|
|
aCommitString ? NS_ConvertUTF16toUTF8(*aCommitString).get() : ""));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
if (mNativeCaretIsCreated) {
|
|
|
|
::DestroyCaret();
|
2011-10-02 06:16:19 +04:00
|
|
|
mNativeCaretIsCreated = false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> dispatcher = GetTextEventDispatcherFor(aWindow);
|
|
|
|
nsresult rv = dispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleEndComposition, FAILED due to "
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::BeginNativeInputTransaction() failure"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
WidgetEventTime eventTime = aWindow->CurrentMessageWidgetEventTime();
|
|
|
|
nsEventStatus status;
|
|
|
|
rv = dispatcher->CommitComposition(status, aCommitString, &eventTime);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleStartComposition, FAILED, due to "
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::CommitComposition() failure"));
|
|
|
|
return;
|
2014-11-25 08:02:33 +03:00
|
|
|
}
|
2011-10-02 06:16:19 +04:00
|
|
|
mIsComposing = false;
|
2016-03-16 07:47:48 +03:00
|
|
|
// XXX aWindow and mComposingWindow are always same??
|
2012-07-30 18:20:58 +04:00
|
|
|
mComposingWindow = nullptr;
|
2016-03-16 07:47:48 +03:00
|
|
|
mDispatcher = nullptr;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::HandleReconvert(nsWindow* aWindow,
|
|
|
|
LPARAM lParam,
|
|
|
|
LRESULT* oResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
*oResult = 0;
|
|
|
|
RECONVERTSTRING* pReconv = reinterpret_cast<RECONVERTSTRING*>(lParam);
|
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
Selection& selection = GetSelection();
|
|
|
|
if (!selection.EnsureValidSelection(aWindow)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, FAILED, due to "
|
2015-07-22 06:40:32 +03:00
|
|
|
"Selection::EnsureValidSelection() failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
uint32_t len = selection.Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t needSize = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
|
2009-12-17 07:40:24 +03:00
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
if (!pReconv) {
|
|
|
|
// Return need size to reconvert.
|
2009-12-17 07:40:24 +03:00
|
|
|
if (len == 0) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, There are not selected text"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
2009-12-17 07:40:24 +03:00
|
|
|
*oResult = needSize;
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, succeeded, result=%ld",
|
2009-05-04 02:20:11 +04:00
|
|
|
*oResult));
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pReconv->dwSize < needSize) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, FAILED, pReconv->dwSize=%ld, needSize=%ld",
|
2009-05-04 02:20:11 +04:00
|
|
|
pReconv->dwSize, needSize));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*oResult = needSize;
|
|
|
|
|
2009-12-17 07:40:24 +03:00
|
|
|
// Fill reconvert struct
|
2009-05-04 02:20:11 +04:00
|
|
|
pReconv->dwVersion = 0;
|
|
|
|
pReconv->dwStrLen = len;
|
|
|
|
pReconv->dwStrOffset = sizeof(RECONVERTSTRING);
|
|
|
|
pReconv->dwCompStrLen = len;
|
|
|
|
pReconv->dwCompStrOffset = 0;
|
|
|
|
pReconv->dwTargetStrLen = len;
|
|
|
|
pReconv->dwTargetStrOffset = 0;
|
|
|
|
|
2009-12-17 07:40:24 +03:00
|
|
|
::CopyMemory(reinterpret_cast<LPVOID>(lParam + sizeof(RECONVERTSTRING)),
|
2015-07-22 06:40:32 +03:00
|
|
|
selection.mString.get(), len * sizeof(WCHAR));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, SUCCEEDED, pReconv=%s, result=%ld",
|
2015-07-23 06:31:28 +03:00
|
|
|
GetReconvertStringLog(pReconv).get(), *oResult));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::HandleQueryCharPosition(nsWindow* aWindow,
|
|
|
|
LPARAM lParam,
|
|
|
|
LRESULT* oResult)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = mIsComposing ? mCompositionString.Length() : 0;
|
2011-10-02 06:16:19 +04:00
|
|
|
*oResult = false;
|
2009-05-04 02:20:11 +04:00
|
|
|
IMECHARPOSITION* pCharPosition = reinterpret_cast<IMECHARPOSITION*>(lParam);
|
|
|
|
if (!pCharPosition) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleQueryCharPosition, FAILED, due to pCharPosition is null"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
if (pCharPosition->dwSize < sizeof(IMECHARPOSITION)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, FAILED, pCharPosition->dwSize=%ld, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"sizeof(IMECHARPOSITION)=%ld",
|
2009-05-04 02:20:11 +04:00
|
|
|
pCharPosition->dwSize, sizeof(IMECHARPOSITION)));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
if (::GetFocus() != aWindow->GetWindowHandle()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleReconvert, FAILED, ::GetFocus()=%08x, OurWindowHandle=%08x",
|
2009-05-04 02:20:11 +04:00
|
|
|
::GetFocus(), aWindow->GetWindowHandle()));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
if (pCharPosition->dwCharPos > len) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleQueryCharPosition, FAILED, pCharPosition->dwCharPos=%ld, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"len=%ld",
|
|
|
|
pCharPosition->dwCharPos, len));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect r;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ret =
|
2009-05-04 02:20:11 +04:00
|
|
|
GetCharacterRectOfSelectedTextAt(aWindow, pCharPosition->dwCharPos, r);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(ret, false);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect screenRect;
|
2009-05-04 02:20:11 +04:00
|
|
|
// We always need top level window that is owner window of the popup window
|
|
|
|
// even if the content of the popup window has focus.
|
2011-10-02 06:16:19 +04:00
|
|
|
ResolveIMECaretPos(aWindow->GetTopLevelWindow(false),
|
2012-07-30 18:20:58 +04:00
|
|
|
r, nullptr, screenRect);
|
2015-05-15 04:18:08 +03:00
|
|
|
|
|
|
|
// XXX This might need to check writing mode. However, MSDN doesn't explain
|
|
|
|
// how to set the values in vertical writing mode. Additionally, IME
|
|
|
|
// doesn't work well with top-left of the character (this is explicitly
|
|
|
|
// documented) and its horizontal width. So, it might be better to set
|
|
|
|
// top-right corner of the character and horizontal width, but we're not
|
|
|
|
// sure if it doesn't cause any problems with a lot of IMEs...
|
2009-05-04 02:20:11 +04:00
|
|
|
pCharPosition->pt.x = screenRect.x;
|
|
|
|
pCharPosition->pt.y = screenRect.y;
|
|
|
|
|
|
|
|
pCharPosition->cLineHeight = r.height;
|
|
|
|
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent editorRect(true, eQueryEditorRect, aWindow);
|
2015-05-15 04:18:08 +03:00
|
|
|
aWindow->InitEvent(editorRect);
|
2015-11-17 10:47:06 +03:00
|
|
|
DispatchEvent(aWindow, editorRect);
|
2015-05-15 04:18:08 +03:00
|
|
|
if (NS_WARN_IF(!editorRect.mSucceeded)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleQueryCharPosition, eQueryEditorRect failed"));
|
2015-05-15 04:18:08 +03:00
|
|
|
::GetWindowRect(aWindow->GetWindowHandle(), &pCharPosition->rcDocument);
|
|
|
|
} else {
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect editorRectInWindow = editorRect.mReply.mRect;
|
2015-05-15 04:18:08 +03:00
|
|
|
nsWindow* window = editorRect.mReply.mFocusedWidget ?
|
|
|
|
static_cast<nsWindow*>(editorRect.mReply.mFocusedWidget) : aWindow;
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect editorRectInScreen;
|
2015-05-15 04:18:08 +03:00
|
|
|
ResolveIMECaretPos(window, editorRectInWindow, nullptr, editorRectInScreen);
|
|
|
|
::SetRect(&pCharPosition->rcDocument,
|
|
|
|
editorRectInScreen.x, editorRectInScreen.y,
|
|
|
|
editorRectInScreen.XMost(), editorRectInScreen.YMost());
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
*oResult = TRUE;
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleQueryCharPosition, SUCCEEDED, pCharPosition={ pt={ x=%d, "
|
2015-05-15 04:18:08 +03:00
|
|
|
"y=%d }, cLineHeight=%d, rcDocument={ left=%d, top=%d, right=%d, "
|
|
|
|
"bottom=%d } }",
|
|
|
|
pCharPosition->pt.x, pCharPosition->pt.y, pCharPosition->cLineHeight,
|
|
|
|
pCharPosition->rcDocument.left, pCharPosition->rcDocument.top,
|
|
|
|
pCharPosition->rcDocument.right, pCharPosition->rcDocument.bottom));
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::HandleDocumentFeed(nsWindow* aWindow,
|
|
|
|
LPARAM lParam,
|
|
|
|
LRESULT* oResult)
|
2009-12-17 07:40:24 +03:00
|
|
|
{
|
|
|
|
*oResult = 0;
|
|
|
|
RECONVERTSTRING* pReconv = reinterpret_cast<RECONVERTSTRING*>(lParam);
|
|
|
|
|
2015-11-10 08:37:32 +03:00
|
|
|
LayoutDeviceIntPoint point(0, 0);
|
2009-12-17 07:40:24 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasCompositionString =
|
2009-12-17 07:40:24 +03:00
|
|
|
mIsComposing && ShouldDrawCompositionStringOurselves();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t targetOffset, targetLength;
|
2009-12-17 07:40:24 +03:00
|
|
|
if (!hasCompositionString) {
|
2015-07-22 06:40:32 +03:00
|
|
|
Selection& selection = GetSelection();
|
|
|
|
if (!selection.EnsureValidSelection(aWindow)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, FAILED, due to "
|
2015-07-22 06:40:32 +03:00
|
|
|
"Selection::EnsureValidSelection() failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
2015-07-22 06:40:32 +03:00
|
|
|
targetOffset = int32_t(selection.mOffset);
|
|
|
|
targetLength = int32_t(selection.Length());
|
2009-12-17 07:40:24 +03:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
targetOffset = int32_t(mCompositionStart);
|
|
|
|
targetLength = int32_t(mCompositionString.Length());
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
// XXX nsString::Find and nsString::RFind take int32_t for offset, so,
|
2009-12-17 07:40:24 +03:00
|
|
|
// we cannot support this message when the current offset is larger than
|
2012-09-28 10:57:33 +04:00
|
|
|
// INT32_MAX.
|
2009-12-17 07:40:24 +03:00
|
|
|
if (targetOffset < 0 || targetLength < 0 ||
|
|
|
|
targetOffset + targetLength < 0) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, FAILED, due to the selection is out of "
|
2015-07-23 06:31:28 +03:00
|
|
|
"range"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get all contents of the focused editor.
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent textContent(true, eQueryTextContent, aWindow);
|
2012-09-28 10:57:33 +04:00
|
|
|
textContent.InitForQueryTextContent(0, UINT32_MAX);
|
2009-12-17 07:40:24 +03:00
|
|
|
aWindow->InitEvent(textContent, &point);
|
2015-11-17 10:47:06 +03:00
|
|
|
DispatchEvent(aWindow, textContent);
|
2009-12-17 07:40:24 +03:00
|
|
|
if (!textContent.mSucceeded) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, FAILED, due to eQueryTextContent failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString str(textContent.mReply.mString);
|
2012-08-22 19:56:38 +04:00
|
|
|
if (targetOffset > int32_t(str.Length())) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, FAILED, due to the caret offset is invalid"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the focused paragraph, we decide that it starts from the previous CRLF
|
|
|
|
// (or start of the editor) to the next one (or the end of the editor).
|
2015-10-23 04:12:15 +03:00
|
|
|
int32_t paragraphStart = str.RFind("\n", false, targetOffset, -1) + 1;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t paragraphEnd =
|
2011-10-02 06:16:19 +04:00
|
|
|
str.Find("\r", false, targetOffset + targetLength, -1);
|
2009-12-17 07:40:24 +03:00
|
|
|
if (paragraphEnd < 0) {
|
|
|
|
paragraphEnd = str.Length();
|
|
|
|
}
|
|
|
|
nsDependentSubstring paragraph(str, paragraphStart,
|
|
|
|
paragraphEnd - paragraphStart);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = paragraph.Length();
|
|
|
|
uint32_t needSize = sizeof(RECONVERTSTRING) + len * sizeof(WCHAR);
|
2009-12-17 07:40:24 +03:00
|
|
|
|
|
|
|
if (!pReconv) {
|
|
|
|
*oResult = needSize;
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, succeeded, result=%ld",
|
2009-12-17 07:40:24 +03:00
|
|
|
*oResult));
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pReconv->dwSize < needSize) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, FAILED, pReconv->dwSize=%ld, needSize=%ld",
|
2009-12-17 07:40:24 +03:00
|
|
|
pReconv->dwSize, needSize));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fill reconvert struct
|
|
|
|
pReconv->dwVersion = 0;
|
|
|
|
pReconv->dwStrLen = len;
|
|
|
|
pReconv->dwStrOffset = sizeof(RECONVERTSTRING);
|
|
|
|
if (hasCompositionString) {
|
|
|
|
pReconv->dwCompStrLen = targetLength;
|
|
|
|
pReconv->dwCompStrOffset =
|
|
|
|
(targetOffset - paragraphStart) * sizeof(WCHAR);
|
|
|
|
// Set composition target clause information
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offset, length;
|
2009-12-17 07:40:24 +03:00
|
|
|
if (!GetTargetClauseRange(&offset, &length)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, FAILED, due to GetTargetClauseRange() "
|
2015-07-23 06:31:28 +03:00
|
|
|
"failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
pReconv->dwTargetStrLen = length;
|
|
|
|
pReconv->dwTargetStrOffset = (offset - paragraphStart) * sizeof(WCHAR);
|
|
|
|
} else {
|
|
|
|
pReconv->dwTargetStrLen = targetLength;
|
|
|
|
pReconv->dwTargetStrOffset =
|
|
|
|
(targetOffset - paragraphStart) * sizeof(WCHAR);
|
|
|
|
// There is no composition string, so, the length is zero but we should
|
|
|
|
// set the cursor offset to the composition str offset.
|
|
|
|
pReconv->dwCompStrLen = 0;
|
|
|
|
pReconv->dwCompStrOffset = pReconv->dwTargetStrOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
*oResult = needSize;
|
|
|
|
::CopyMemory(reinterpret_cast<LPVOID>(lParam + sizeof(RECONVERTSTRING)),
|
|
|
|
paragraph.BeginReading(), len * sizeof(WCHAR));
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("HandleDocumentFeed, SUCCEEDED, pReconv=%s, result=%ld",
|
2015-07-23 06:31:28 +03:00
|
|
|
GetReconvertStringLog(pReconv).get(), *oResult));
|
2009-12-17 07:40:24 +03:00
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::CommitCompositionOnPreviousWindow(nsWindow* aWindow)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
|
|
|
if (!mComposingWindow || mComposingWindow == aWindow) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CommitCompositionOnPreviousWindow, mIsComposing=%s",
|
2015-12-29 16:57:37 +03:00
|
|
|
GetBoolName(mIsComposing)));
|
2010-08-08 13:23:25 +04:00
|
|
|
|
|
|
|
// If we have composition, we should dispatch composition events internally.
|
|
|
|
if (mIsComposing) {
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(mComposingWindow);
|
|
|
|
NS_ASSERTION(context.IsValid(), "IME context must be valid");
|
2010-08-08 13:23:25 +04:00
|
|
|
|
|
|
|
HandleEndComposition(mComposingWindow);
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:37 +03:00
|
|
|
return false;
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
|
|
|
|
2016-06-04 03:49:21 +03:00
|
|
|
static TextRangeType
|
2012-08-22 19:56:38 +04:00
|
|
|
PlatformToNSAttr(uint8_t aAttr)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
switch (aAttr)
|
|
|
|
{
|
|
|
|
case ATTR_INPUT_ERROR:
|
|
|
|
// case ATTR_FIXEDCONVERTED:
|
|
|
|
case ATTR_INPUT:
|
2016-06-03 12:48:37 +03:00
|
|
|
return TextRangeType::eRawClause;
|
2009-05-04 02:20:11 +04:00
|
|
|
case ATTR_CONVERTED:
|
2016-06-03 13:05:32 +03:00
|
|
|
return TextRangeType::eConvertedClause;
|
2009-05-04 02:20:11 +04:00
|
|
|
case ATTR_TARGET_NOTCONVERTED:
|
2016-06-03 12:57:21 +03:00
|
|
|
return TextRangeType::eSelectedRawClause;
|
2009-05-04 02:20:11 +04:00
|
|
|
case ATTR_TARGET_CONVERTED:
|
2016-06-03 13:15:21 +03:00
|
|
|
return TextRangeType::eSelectedClause;
|
2009-05-04 02:20:11 +04:00
|
|
|
default:
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ASSERTION(false, "unknown attribute");
|
2016-06-03 12:40:06 +03:00
|
|
|
return TextRangeType::eCaret;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-17 10:47:06 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::DispatchEvent(nsWindow* aWindow, WidgetGUIEvent& aEvent)
|
|
|
|
{
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchEvent(aWindow=0x%p, aEvent={ mMessage=%s }, "
|
2015-11-17 10:47:06 +03:00
|
|
|
"aWindow->Destroyed()=%s",
|
|
|
|
aWindow, ToChar(aEvent.mMessage), GetBoolName(aWindow->Destroyed())));
|
|
|
|
|
|
|
|
if (aWindow->Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aWindow->DispatchWindowEvent(&aEvent);
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::DispatchCompositionChangeEvent(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mIsComposing, "conflict state");
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent"));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2014-11-25 08:02:33 +03:00
|
|
|
// If we don't need to draw composition string ourselves, we don't need to
|
|
|
|
// fire compositionchange event during composing.
|
|
|
|
if (!ShouldDrawCompositionStringOurselves()) {
|
2009-05-04 02:20:11 +04:00
|
|
|
// But we need to adjust composition window pos and native caret pos, here.
|
2015-07-23 06:31:28 +03:00
|
|
|
SetIMERelatedWindowsPos(aWindow, aContext);
|
2009-05-04 02:20:11 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsWindow> kungFuDeathGrip(aWindow);
|
2016-03-16 07:47:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> dispatcher = GetTextEventDispatcherFor(aWindow);
|
|
|
|
nsresult rv = dispatcher->BeginNativeInputTransaction();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, FAILED due to "
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::BeginNativeInputTransaction() failure"));
|
|
|
|
return;
|
|
|
|
}
|
2011-09-22 13:17:40 +04:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
// NOTE: Calling SetIMERelatedWindowsPos() from this method will be failure
|
|
|
|
// in e10s mode. compositionchange event will notify this of
|
2016-05-31 05:39:15 +03:00
|
|
|
// NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, then
|
|
|
|
// SetIMERelatedWindowsPos() will be called.
|
2014-03-04 17:48:27 +04:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
// XXX Sogou (Simplified Chinese IME) returns contradictory values:
|
|
|
|
// The cursor position is actual cursor position. However, other values
|
|
|
|
// (composition string and attributes) are empty.
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2014-11-25 08:02:33 +03:00
|
|
|
if (mCompositionString.IsEmpty()) {
|
|
|
|
// Don't append clause information if composition string is empty.
|
2016-03-16 07:47:48 +03:00
|
|
|
} else if (mClauseArray.IsEmpty()) {
|
2009-05-04 02:20:11 +04:00
|
|
|
// Some IMEs don't return clause array information, then, we assume that
|
|
|
|
// all characters in the composition string are in one clause.
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, mClauseArray.Length()=0"));
|
2016-03-16 07:47:48 +03:00
|
|
|
rv =dispatcher->SetPendingComposition(mCompositionString, nullptr);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, FAILED due to"
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::SetPendingComposition() failure"));
|
|
|
|
return;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
} else {
|
|
|
|
// iterate over the attributes
|
2016-03-16 07:47:48 +03:00
|
|
|
rv = dispatcher->SetPendingCompositionString(mCompositionString);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, FAILED due to"
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::SetPendingCompositionString() failure"));
|
|
|
|
return;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t lastOffset = 0;
|
|
|
|
for (uint32_t i = 0; i < mClauseArray.Length() - 1; i++) {
|
|
|
|
uint32_t current = mClauseArray[i + 1];
|
2009-05-04 02:20:11 +04:00
|
|
|
if (current > mCompositionString.Length()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, mClauseArray[%ld]=%lu. "
|
2015-07-23 06:31:28 +03:00
|
|
|
"This is larger than mCompositionString.Length()=%lu",
|
2009-05-04 02:20:11 +04:00
|
|
|
i + 1, current, mCompositionString.Length()));
|
2012-08-22 19:56:38 +04:00
|
|
|
current = int32_t(mCompositionString.Length());
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
uint32_t length = current - lastOffset;
|
2016-09-14 05:09:00 +03:00
|
|
|
if (NS_WARN_IF(lastOffset >= mAttributeArray.Length())) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
|
|
|
("DispatchCompositionChangeEvent, FAILED due to invalid data of "
|
|
|
|
"mClauseArray or mAttributeArray"));
|
|
|
|
return;
|
|
|
|
}
|
2016-06-04 03:49:21 +03:00
|
|
|
TextRangeType textRangeType =
|
|
|
|
PlatformToNSAttr(mAttributeArray[lastOffset]);
|
|
|
|
rv = dispatcher->AppendClauseToPendingComposition(length, textRangeType);
|
2016-03-16 07:47:48 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, FAILED due to"
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::AppendClauseToPendingComposition() failure"));
|
|
|
|
return;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
lastOffset = current;
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, index=%ld, rangeType=%s, "
|
2016-03-16 07:47:48 +03:00
|
|
|
"range length=%lu",
|
2016-06-04 03:49:21 +03:00
|
|
|
i, ToChar(textRangeType), length));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCursorPosition == NO_IME_CARET) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, no caret"));
|
2016-03-16 07:47:48 +03:00
|
|
|
} else {
|
|
|
|
uint32_t cursor = static_cast<uint32_t>(mCursorPosition);
|
|
|
|
if (cursor > mCompositionString.Length()) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CreateTextRangeArray, mCursorPosition=%ld. "
|
2016-03-16 07:47:48 +03:00
|
|
|
"This is larger than mCompositionString.Length()=%lu",
|
|
|
|
mCursorPosition, mCompositionString.Length()));
|
|
|
|
cursor = mCompositionString.Length();
|
|
|
|
}
|
2015-08-17 14:58:38 +03:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
// If caret is in the target clause, the target clause will be painted as
|
|
|
|
// normal selection range. Since caret shouldn't be in selection range on
|
|
|
|
// Windows, we shouldn't append caret range in such case.
|
|
|
|
const TextRangeArray* clauses = dispatcher->GetPendingCompositionClauses();
|
|
|
|
const TextRange* targetClause =
|
|
|
|
clauses ? clauses->GetTargetClause() : nullptr;
|
|
|
|
if (targetClause &&
|
|
|
|
cursor >= targetClause->mStartOffset &&
|
|
|
|
cursor <= targetClause->mEndOffset) {
|
|
|
|
// Forget the caret position specified by IME since Gecko's caret position
|
|
|
|
// will be at the end of composition string.
|
|
|
|
mCursorPosition = NO_IME_CARET;
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("CreateTextRangeArray, no caret due to it's in the target "
|
2016-03-16 07:47:48 +03:00
|
|
|
"clause, now, mCursorPosition is NO_IME_CARET"));
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
if (mCursorPosition != NO_IME_CARET) {
|
|
|
|
rv = dispatcher->SetCaretInPendingComposition(cursor, 0);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, FAILED due to"
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::SetCaretInPendingComposition() failure"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-04 17:48:27 +04:00
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
WidgetEventTime eventTime = aWindow->CurrentMessageWidgetEventTime();
|
|
|
|
nsEventStatus status;
|
|
|
|
rv = dispatcher->FlushPendingComposition(status, &eventTime);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("DispatchCompositionChangeEvent, FAILED due to"
|
2016-03-16 07:47:48 +03:00
|
|
|
"TextEventDispatcher::FlushPendingComposition() failure"));
|
|
|
|
return;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::GetCompositionString(const IMEContext& aContext,
|
|
|
|
DWORD aIndex,
|
|
|
|
nsAString& aCompositionString) const
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2014-11-25 08:02:33 +03:00
|
|
|
aCompositionString.Truncate();
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
// Retrieve the size of the required output buffer.
|
2015-07-23 06:31:28 +03:00
|
|
|
long lRtn = ::ImmGetCompositionStringW(aContext.get(), aIndex, nullptr, 0);
|
2009-05-04 02:20:11 +04:00
|
|
|
if (lRtn < 0 ||
|
2014-11-25 08:02:33 +03:00
|
|
|
!aCompositionString.SetLength((lRtn / sizeof(WCHAR)) + 1,
|
2015-01-28 12:00:40 +03:00
|
|
|
mozilla::fallible)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCompositionString, FAILED, due to OOM"));
|
2009-05-04 02:20:11 +04:00
|
|
|
return; // Error or out of memory.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually retrieve the composition string information.
|
2015-07-23 06:31:28 +03:00
|
|
|
lRtn = ::ImmGetCompositionStringW(aContext.get(), aIndex,
|
2014-11-25 08:02:33 +03:00
|
|
|
(LPVOID)aCompositionString.BeginWriting(),
|
2009-05-04 02:20:11 +04:00
|
|
|
lRtn + sizeof(WCHAR));
|
2014-11-25 08:02:33 +03:00
|
|
|
aCompositionString.SetLength(lRtn / sizeof(WCHAR));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCompositionString, succeeded, aCompositionString=\"%s\"",
|
2014-11-25 08:02:33 +03:00
|
|
|
NS_ConvertUTF16toUTF8(aCompositionString).get()));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::GetTargetClauseRange(uint32_t* aOffset,
|
|
|
|
uint32_t* aLength)
|
2009-12-17 07:40:24 +03:00
|
|
|
{
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(aOffset, false);
|
|
|
|
NS_ENSURE_TRUE(mIsComposing, false);
|
|
|
|
NS_ENSURE_TRUE(ShouldDrawCompositionStringOurselves(), false);
|
2009-12-17 07:40:24 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool found = false;
|
2009-12-17 07:40:24 +03:00
|
|
|
*aOffset = mCompositionStart;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mAttributeArray.Length(); i++) {
|
2009-12-17 07:40:24 +03:00
|
|
|
if (mAttributeArray[i] == ATTR_TARGET_NOTCONVERTED ||
|
|
|
|
mAttributeArray[i] == ATTR_TARGET_CONVERTED) {
|
|
|
|
*aOffset = mCompositionStart + i;
|
2011-10-02 06:16:19 +04:00
|
|
|
found = true;
|
2009-12-17 07:40:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aLength) {
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
// The all composition string is targetted when there is no ATTR_TARGET_*
|
|
|
|
// clause. E.g., there is only ATTR_INPUT
|
|
|
|
*aLength = mCompositionString.Length();
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offsetInComposition = *aOffset - mCompositionStart;
|
2009-12-17 07:40:24 +03:00
|
|
|
*aLength = mCompositionString.Length() - offsetInComposition;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = offsetInComposition; i < mAttributeArray.Length(); i++) {
|
2009-12-17 07:40:24 +03:00
|
|
|
if (mAttributeArray[i] != ATTR_TARGET_NOTCONVERTED &&
|
|
|
|
mAttributeArray[i] != ATTR_TARGET_CONVERTED) {
|
|
|
|
*aLength = i - offsetInComposition;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-12-17 07:40:24 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-06-20 12:19:05 +03:00
|
|
|
IMMHandler::ConvertToANSIString(const nsString& aStr,
|
2015-07-23 06:31:28 +03:00
|
|
|
UINT aCodePage,
|
|
|
|
nsACString& aANSIStr)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
int len = ::WideCharToMultiByte(aCodePage, 0,
|
|
|
|
(LPCWSTR)aStr.get(), aStr.Length(),
|
2013-10-08 22:48:20 +04:00
|
|
|
nullptr, 0, nullptr, nullptr);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(len >= 0, false);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-01-28 12:00:40 +03:00
|
|
|
if (!aANSIStr.SetLength(len, mozilla::fallible)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("ConvertToANSIString, FAILED, due to OOM"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
::WideCharToMultiByte(aCodePage, 0, (LPCWSTR)aStr.get(), aStr.Length(),
|
2013-10-08 22:48:20 +04:00
|
|
|
(LPSTR)aANSIStr.BeginWriting(), len, nullptr, nullptr);
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::GetCharacterRectOfSelectedTextAt(nsWindow* aWindow,
|
|
|
|
uint32_t aOffset,
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect& aCharRect,
|
2015-07-23 06:31:28 +03:00
|
|
|
WritingMode* aWritingMode)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-11-10 08:37:32 +03:00
|
|
|
LayoutDeviceIntPoint point(0, 0);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
Selection& selection = GetSelection();
|
|
|
|
if (!selection.EnsureValidSelection(aWindow)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCharacterRectOfSelectedTextAt, FAILED, due to "
|
2015-07-22 06:40:32 +03:00
|
|
|
"Selection::EnsureValidSelection() failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-26 06:29:47 +03:00
|
|
|
// If the offset is larger than the end of composition string or selected
|
|
|
|
// string, we should return false since such case must be a bug of the caller
|
|
|
|
// or the active IME. If it's an IME's bug, we need to set targetLength to
|
|
|
|
// aOffset.
|
|
|
|
uint32_t targetLength =
|
|
|
|
mIsComposing ? mCompositionString.Length() : selection.Length();
|
|
|
|
if (NS_WARN_IF(aOffset > targetLength)) {
|
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCharacterRectOfSelectedTextAt, FAILED, due to "
|
2015-07-26 06:29:47 +03:00
|
|
|
"aOffset is too large (aOffset=%u, targetLength=%u, mIsComposing=%s)",
|
|
|
|
aOffset, targetLength, GetBoolName(mIsComposing)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is caret, we might be able to use caret rect.
|
|
|
|
uint32_t caretOffset = UINT32_MAX;
|
|
|
|
// There is a caret only when the normal selection is collapsed.
|
|
|
|
if (selection.Collapsed()) {
|
|
|
|
if (mIsComposing) {
|
|
|
|
// If it's composing, mCursorPosition is the offset to caret in
|
|
|
|
// the composition string.
|
|
|
|
if (mCursorPosition != NO_IME_CARET) {
|
|
|
|
MOZ_ASSERT(mCursorPosition >= 0);
|
2016-06-15 07:52:03 +03:00
|
|
|
caretOffset = mCursorPosition;
|
2015-07-26 06:29:47 +03:00
|
|
|
} else if (!ShouldDrawCompositionStringOurselves() ||
|
|
|
|
mCompositionString.IsEmpty()) {
|
|
|
|
// Otherwise, if there is no composition string, we should assume that
|
|
|
|
// there is a caret at the start of composition string.
|
2016-06-15 07:52:03 +03:00
|
|
|
caretOffset = 0;
|
2015-07-26 06:29:47 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If there is no composition, the selection offset is the caret offset.
|
2016-06-15 07:52:03 +03:00
|
|
|
caretOffset = 0;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-26 06:29:47 +03:00
|
|
|
// If there is a caret and retrieving offset is same as the caret offset,
|
|
|
|
// we should use the caret rect.
|
2016-06-15 07:52:03 +03:00
|
|
|
if (aOffset != caretOffset) {
|
2015-09-11 15:21:26 +03:00
|
|
|
WidgetQueryContentEvent charRect(true, eQueryTextRect, aWindow);
|
2016-06-15 07:52:03 +03:00
|
|
|
WidgetQueryContentEvent::Options options;
|
|
|
|
options.mRelativeToInsertionPoint = true;
|
|
|
|
charRect.InitForQueryTextRect(aOffset, 1, options);
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->InitEvent(charRect, &point);
|
2015-11-17 10:47:06 +03:00
|
|
|
DispatchEvent(aWindow, charRect);
|
2009-05-04 02:20:11 +04:00
|
|
|
if (charRect.mSucceeded) {
|
2015-11-12 16:22:44 +03:00
|
|
|
aCharRect = charRect.mReply.mRect;
|
2015-05-15 04:18:07 +03:00
|
|
|
if (aWritingMode) {
|
|
|
|
*aWritingMode = charRect.GetWritingMode();
|
|
|
|
}
|
2015-08-20 05:40:14 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Debug,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCharacterRectOfSelectedTextAt, Succeeded, aOffset=%u, "
|
2015-05-15 04:18:07 +03:00
|
|
|
"aCharRect={ x: %ld, y: %ld, width: %ld, height: %ld }, "
|
|
|
|
"charRect.GetWritingMode()=%s",
|
2015-07-23 06:31:28 +03:00
|
|
|
aOffset, aCharRect.x, aCharRect.y, aCharRect.width, aCharRect.height,
|
2015-05-15 04:18:07 +03:00
|
|
|
GetWritingModeName(charRect.GetWritingMode()).get()));
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:07 +03:00
|
|
|
return GetCaretRect(aWindow, aCharRect, aWritingMode);
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::GetCaretRect(nsWindow* aWindow,
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect& aCaretRect,
|
2015-07-23 06:31:28 +03:00
|
|
|
WritingMode* aWritingMode)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-11-10 08:37:32 +03:00
|
|
|
LayoutDeviceIntPoint point(0, 0);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent caretRect(true, eQueryCaretRect, aWindow);
|
2016-06-15 07:52:03 +03:00
|
|
|
WidgetQueryContentEvent::Options options;
|
|
|
|
options.mRelativeToInsertionPoint = true;
|
|
|
|
caretRect.InitForQueryCaretRect(0, options);
|
2009-05-04 02:20:11 +04:00
|
|
|
aWindow->InitEvent(caretRect, &point);
|
2015-11-17 10:47:06 +03:00
|
|
|
DispatchEvent(aWindow, caretRect);
|
2009-05-04 02:20:11 +04:00
|
|
|
if (!caretRect.mSucceeded) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCaretRect, FAILED, due to eQueryCaretRect failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
2015-11-12 16:22:44 +03:00
|
|
|
aCaretRect = caretRect.mReply.mRect;
|
2015-05-15 04:18:07 +03:00
|
|
|
if (aWritingMode) {
|
|
|
|
*aWritingMode = caretRect.GetWritingMode();
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("GetCaretRect, SUCCEEDED, "
|
2015-05-15 04:18:07 +03:00
|
|
|
"aCaretRect={ x: %ld, y: %ld, width: %ld, height: %ld }, "
|
|
|
|
"caretRect.GetWritingMode()=%s",
|
|
|
|
aCaretRect.x, aCaretRect.y, aCaretRect.width, aCaretRect.height,
|
|
|
|
GetWritingModeName(caretRect.GetWritingMode()).get()));
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::SetIMERelatedWindowsPos(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect r;
|
2009-05-04 02:20:11 +04:00
|
|
|
// Get first character rect of current a normal selected text or a composing
|
|
|
|
// string.
|
2015-05-15 04:18:07 +03:00
|
|
|
WritingMode writingMode;
|
|
|
|
bool ret = GetCharacterRectOfSelectedTextAt(aWindow, 0, r, &writingMode);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(ret, false);
|
|
|
|
nsWindow* toplevelWindow = aWindow->GetTopLevelWindow(false);
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect firstSelectedCharRect;
|
2009-05-04 02:20:11 +04:00
|
|
|
ResolveIMECaretPos(toplevelWindow, r, aWindow, firstSelectedCharRect);
|
|
|
|
|
|
|
|
// Set native caret size/position to our caret. Some IMEs honor it. E.g.,
|
|
|
|
// "Intelligent ABC" (Simplified Chinese) and "MS PinYin 3.0" (Simplified
|
|
|
|
// Chinese) on XP.
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect caretRect(firstSelectedCharRect);
|
2009-05-04 02:20:11 +04:00
|
|
|
if (GetCaretRect(aWindow, r)) {
|
|
|
|
ResolveIMECaretPos(toplevelWindow, r, aWindow, caretRect);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("failed to get caret rect");
|
|
|
|
caretRect.width = 1;
|
|
|
|
}
|
|
|
|
if (!mNativeCaretIsCreated) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mNativeCaretIsCreated = ::CreateCaret(aWindow->GetWindowHandle(), nullptr,
|
2009-05-04 02:20:11 +04:00
|
|
|
caretRect.width, caretRect.height);
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPos, mNativeCaretIsCreated=%s, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"width=%ld, height=%ld",
|
|
|
|
GetBoolName(mNativeCaretIsCreated), caretRect.width, caretRect.height));
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
::SetCaretPos(caretRect.x, caretRect.y);
|
|
|
|
|
|
|
|
if (ShouldDrawCompositionStringOurselves()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPos, Set candidate window"));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
// Get a rect of first character in current target in composition string.
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect firstTargetCharRect, lastTargetCharRect;
|
2009-05-04 02:20:11 +04:00
|
|
|
if (mIsComposing && !mCompositionString.IsEmpty()) {
|
|
|
|
// If there are no targetted selection, we should use it's first character
|
|
|
|
// rect instead.
|
2015-05-15 04:18:07 +03:00
|
|
|
uint32_t offset, length;
|
|
|
|
if (!GetTargetClauseRange(&offset, &length)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPos, FAILED, due to "
|
2015-07-23 06:31:28 +03:00
|
|
|
"GetTargetClauseRange() failure"));
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
2009-12-17 07:40:24 +03:00
|
|
|
ret = GetCharacterRectOfSelectedTextAt(aWindow,
|
2015-05-15 04:18:07 +03:00
|
|
|
offset - mCompositionStart,
|
|
|
|
firstTargetCharRect, &writingMode);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(ret, false);
|
2015-05-15 04:18:07 +03:00
|
|
|
if (length) {
|
|
|
|
ret = GetCharacterRectOfSelectedTextAt(aWindow,
|
|
|
|
offset + length - 1 - mCompositionStart, lastTargetCharRect);
|
|
|
|
NS_ENSURE_TRUE(ret, false);
|
|
|
|
} else {
|
|
|
|
lastTargetCharRect = firstTargetCharRect;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
} else {
|
|
|
|
// If there are no composition string, we should use a first character
|
|
|
|
// rect.
|
2015-05-15 04:18:07 +03:00
|
|
|
ret = GetCharacterRectOfSelectedTextAt(aWindow, 0,
|
|
|
|
firstTargetCharRect, &writingMode);
|
2011-10-02 06:16:19 +04:00
|
|
|
NS_ENSURE_TRUE(ret, false);
|
2015-05-15 04:18:07 +03:00
|
|
|
lastTargetCharRect = firstTargetCharRect;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
2015-05-15 04:18:07 +03:00
|
|
|
ResolveIMECaretPos(toplevelWindow, firstTargetCharRect,
|
|
|
|
aWindow, firstTargetCharRect);
|
|
|
|
ResolveIMECaretPos(toplevelWindow, lastTargetCharRect,
|
|
|
|
aWindow, lastTargetCharRect);
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect targetClauseRect;
|
2015-05-15 04:18:07 +03:00
|
|
|
targetClauseRect.UnionRect(firstTargetCharRect, lastTargetCharRect);
|
|
|
|
|
|
|
|
// Move the candidate window to proper position from the target clause as
|
|
|
|
// far as possible.
|
2009-05-04 02:20:11 +04:00
|
|
|
CANDIDATEFORM candForm;
|
|
|
|
candForm.dwIndex = 0;
|
2015-05-15 04:18:07 +03:00
|
|
|
if (!writingMode.IsVertical() || IsVerticalWritingSupported()) {
|
|
|
|
candForm.dwStyle = CFS_EXCLUDE;
|
|
|
|
// Candidate window shouldn't overlap the target clause in any writing
|
|
|
|
// mode.
|
|
|
|
candForm.rcArea.left = targetClauseRect.x;
|
|
|
|
candForm.rcArea.right = targetClauseRect.XMost();
|
|
|
|
candForm.rcArea.top = targetClauseRect.y;
|
|
|
|
candForm.rcArea.bottom = targetClauseRect.YMost();
|
|
|
|
if (!writingMode.IsVertical()) {
|
|
|
|
// In horizontal layout, current point of interest should be top-left
|
|
|
|
// of the first character.
|
|
|
|
candForm.ptCurrentPos.x = firstTargetCharRect.x;
|
|
|
|
candForm.ptCurrentPos.y = firstTargetCharRect.y;
|
|
|
|
} else if (writingMode.IsVerticalRL()) {
|
|
|
|
// In vertical layout (RL), candidate window should be positioned right
|
|
|
|
// side of target clause. However, we don't set vertical writing font
|
|
|
|
// to the IME. Therefore, the candidate window may be positioned
|
|
|
|
// bottom-left of target clause rect with these information.
|
|
|
|
candForm.ptCurrentPos.x = targetClauseRect.x;
|
|
|
|
candForm.ptCurrentPos.y = targetClauseRect.y;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(writingMode.IsVerticalLR(), "Did we miss some causes?");
|
|
|
|
// In vertical layout (LR), candidate window should be poisitioned left
|
|
|
|
// side of target clause. Although, we don't set vertical writing font
|
|
|
|
// to the IME, the candidate window may be positioned bottom-right of
|
|
|
|
// the target clause rect with these information.
|
|
|
|
candForm.ptCurrentPos.x = targetClauseRect.XMost();
|
|
|
|
candForm.ptCurrentPos.y = targetClauseRect.y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If vertical writing is not supported by IME, let's set candidate
|
|
|
|
// window position to the bottom-left of the target clause because
|
|
|
|
// the position must be the safest position to prevent the candidate
|
|
|
|
// window to overlap with the target clause.
|
|
|
|
candForm.dwStyle = CFS_CANDIDATEPOS;
|
|
|
|
candForm.ptCurrentPos.x = targetClauseRect.x;
|
|
|
|
candForm.ptCurrentPos.y = targetClauseRect.YMost();
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPos, Calling ImmSetCandidateWindow()... "
|
2015-05-15 04:18:07 +03:00
|
|
|
"ptCurrentPos={ x=%d, y=%d }, "
|
|
|
|
"rcArea={ left=%d, top=%d, right=%d, bottom=%d }, "
|
|
|
|
"writingMode=%s",
|
|
|
|
candForm.ptCurrentPos.x, candForm.ptCurrentPos.y,
|
|
|
|
candForm.rcArea.left, candForm.rcArea.top,
|
|
|
|
candForm.rcArea.right, candForm.rcArea.bottom,
|
|
|
|
GetWritingModeName(writingMode).get()));
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmSetCandidateWindow(aContext.get(), &candForm);
|
2009-05-04 02:20:11 +04:00
|
|
|
} else {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPos, Set composition window"));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
// Move the composition window to caret position (if selected some
|
|
|
|
// characters, we should use first character rect of them).
|
|
|
|
// And in this mode, IME adjusts the candidate window position
|
|
|
|
// automatically. So, we don't need to set it.
|
|
|
|
COMPOSITIONFORM compForm;
|
|
|
|
compForm.dwStyle = CFS_POINT;
|
2015-05-15 04:18:07 +03:00
|
|
|
compForm.ptCurrentPos.x =
|
|
|
|
!writingMode.IsVerticalLR() ? firstSelectedCharRect.x :
|
|
|
|
firstSelectedCharRect.XMost();
|
2009-05-04 02:20:11 +04:00
|
|
|
compForm.ptCurrentPos.y = firstSelectedCharRect.y;
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmSetCompositionWindow(aContext.get(), &compForm);
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2011-10-02 06:16:19 +04:00
|
|
|
return true;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2013-12-18 05:43:15 +04:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext)
|
2013-12-18 05:43:15 +04:00
|
|
|
{
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent editorRectEvent(true, eQueryEditorRect, aWindow);
|
2013-12-18 05:43:15 +04:00
|
|
|
aWindow->InitEvent(editorRectEvent);
|
2015-11-17 10:47:06 +03:00
|
|
|
DispatchEvent(aWindow, editorRectEvent);
|
2013-12-18 05:43:15 +04:00
|
|
|
if (!editorRectEvent.mSucceeded) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPosOnPlugin, "
|
2015-09-10 04:40:06 +03:00
|
|
|
"FAILED, due to eQueryEditorRect failure"));
|
2013-12-18 05:43:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clip the plugin rect by the client rect of the window because composition
|
|
|
|
// window needs to be specified the position in the client area.
|
|
|
|
nsWindow* toplevelWindow = aWindow->GetTopLevelWindow(false);
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntRect pluginRectInScreen =
|
|
|
|
editorRectEvent.mReply.mRect + toplevelWindow->WidgetToScreenOffset();
|
2016-08-19 02:03:04 +03:00
|
|
|
LayoutDeviceIntRect winRectInScreen = aWindow->GetClientBounds();
|
2013-12-18 05:43:15 +04:00
|
|
|
// composition window cannot be positioned on the edge of client area.
|
|
|
|
winRectInScreen.width--;
|
|
|
|
winRectInScreen.height--;
|
2015-11-12 16:08:31 +03:00
|
|
|
LayoutDeviceIntRect clippedPluginRect;
|
2013-12-18 05:43:15 +04:00
|
|
|
clippedPluginRect.x =
|
|
|
|
std::min(std::max(pluginRectInScreen.x, winRectInScreen.x),
|
|
|
|
winRectInScreen.XMost());
|
|
|
|
clippedPluginRect.y =
|
|
|
|
std::min(std::max(pluginRectInScreen.y, winRectInScreen.y),
|
|
|
|
winRectInScreen.YMost());
|
|
|
|
int32_t xMost = std::min(pluginRectInScreen.XMost(), winRectInScreen.XMost());
|
|
|
|
int32_t yMost = std::min(pluginRectInScreen.YMost(), winRectInScreen.YMost());
|
|
|
|
clippedPluginRect.width = std::max(0, xMost - clippedPluginRect.x);
|
|
|
|
clippedPluginRect.height = std::max(0, yMost - clippedPluginRect.y);
|
2015-11-12 16:08:31 +03:00
|
|
|
clippedPluginRect -= aWindow->WidgetToScreenOffset();
|
2013-12-18 05:43:15 +04:00
|
|
|
|
|
|
|
// Cover the plugin with native caret. This prevents IME's window and plugin
|
|
|
|
// overlap.
|
|
|
|
if (mNativeCaretIsCreated) {
|
|
|
|
::DestroyCaret();
|
|
|
|
}
|
|
|
|
mNativeCaretIsCreated =
|
|
|
|
::CreateCaret(aWindow->GetWindowHandle(), nullptr,
|
|
|
|
clippedPluginRect.width, clippedPluginRect.height);
|
|
|
|
::SetCaretPos(clippedPluginRect.x, clippedPluginRect.y);
|
|
|
|
|
|
|
|
// Set the composition window to bottom-left of the clipped plugin.
|
|
|
|
// As far as we know, there is no IME for RTL language. Therefore, this code
|
|
|
|
// must not need to take care of RTL environment.
|
|
|
|
COMPOSITIONFORM compForm;
|
|
|
|
compForm.dwStyle = CFS_POINT;
|
|
|
|
compForm.ptCurrentPos.x = clippedPluginRect.BottomLeft().x;
|
|
|
|
compForm.ptCurrentPos.y = clippedPluginRect.BottomLeft().y;
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!::ImmSetCompositionWindow(aContext.get(), &compForm)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("SetIMERelatedWindowsPosOnPlugin, "
|
2015-07-23 06:31:28 +03:00
|
|
|
"FAILED, due to ::ImmSetCompositionWindow() failure"));
|
2013-12-18 05:43:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
void
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::ResolveIMECaretPos(nsIWidget* aReferenceWidget,
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect& aCursorRect,
|
2015-07-23 06:31:28 +03:00
|
|
|
nsIWidget* aNewOriginWidget,
|
2015-11-12 16:22:44 +03:00
|
|
|
LayoutDeviceIntRect& aOutRect)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
aOutRect = aCursorRect;
|
|
|
|
|
|
|
|
if (aReferenceWidget == aNewOriginWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aReferenceWidget)
|
2015-11-12 16:22:44 +03:00
|
|
|
aOutRect.MoveBy(aReferenceWidget->WidgetToScreenOffset());
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
if (aNewOriginWidget)
|
2015-11-12 16:22:44 +03:00
|
|
|
aOutRect.MoveBy(-aNewOriginWidget->WidgetToScreenOffset());
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:07 +03:00
|
|
|
static void
|
|
|
|
SetHorizontalFontToLogFont(const nsAString& aFontFace,
|
|
|
|
LOGFONTW& aLogFont)
|
|
|
|
{
|
|
|
|
aLogFont.lfEscapement = aLogFont.lfOrientation = 0;
|
|
|
|
if (NS_WARN_IF(aFontFace.Length() > LF_FACESIZE - 1)) {
|
|
|
|
memcpy(aLogFont.lfFaceName, L"System", sizeof(L"System"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(aLogFont.lfFaceName, aFontFace.BeginReading(),
|
|
|
|
aFontFace.Length() * sizeof(wchar_t));
|
|
|
|
aLogFont.lfFaceName[aFontFace.Length()] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetVerticalFontToLogFont(const nsAString& aFontFace,
|
|
|
|
LOGFONTW& aLogFont)
|
|
|
|
{
|
|
|
|
aLogFont.lfEscapement = aLogFont.lfOrientation = 2700;
|
|
|
|
if (NS_WARN_IF(aFontFace.Length() > LF_FACESIZE - 2)) {
|
|
|
|
memcpy(aLogFont.lfFaceName, L"@System", sizeof(L"@System"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aLogFont.lfFaceName[0] = '@';
|
|
|
|
memcpy(&aLogFont.lfFaceName[1], aFontFace.BeginReading(),
|
|
|
|
aFontFace.Length() * sizeof(wchar_t));
|
|
|
|
aLogFont.lfFaceName[aFontFace.Length() + 1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-12-29 16:57:37 +03:00
|
|
|
IMMHandler::AdjustCompositionFont(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext,
|
2015-07-23 06:31:28 +03:00
|
|
|
const WritingMode& aWritingMode,
|
|
|
|
bool aForceUpdate)
|
2015-05-15 04:18:07 +03:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
// An instance of IMMHandler is destroyed when active IME is changed.
|
2015-05-15 04:18:07 +03:00
|
|
|
// Therefore, we need to store the information which are set to the IM
|
|
|
|
// context to static variables since IM context is never recreated.
|
|
|
|
static bool sCompositionFontsInitialized = false;
|
2017-07-31 07:23:50 +03:00
|
|
|
static nsString sCompositionFont;
|
|
|
|
static bool sCompositionFontPrefDone = false;
|
|
|
|
if (!sCompositionFontPrefDone) {
|
|
|
|
sCompositionFontPrefDone = true;
|
|
|
|
Preferences::GetString("intl.imm.composition_font", sCompositionFont);
|
|
|
|
}
|
2015-05-15 04:18:07 +03:00
|
|
|
|
|
|
|
// If composition font is customized by pref, we need to modify the
|
|
|
|
// composition font of the IME context at first time even if the writing mode
|
|
|
|
// is horizontal.
|
2015-05-15 04:18:08 +03:00
|
|
|
bool setCompositionFontForcibly = aForceUpdate ||
|
|
|
|
(!sCompositionFontsInitialized && !sCompositionFont.IsEmpty());
|
2015-05-15 04:18:07 +03:00
|
|
|
|
|
|
|
static WritingMode sCurrentWritingMode;
|
|
|
|
static nsString sCurrentIMEName;
|
|
|
|
if (!setCompositionFontForcibly &&
|
2015-05-15 04:18:08 +03:00
|
|
|
sWritingModeOfCompositionFont == aWritingMode &&
|
2015-05-15 04:18:07 +03:00
|
|
|
sCurrentIMEName == sIMEName) {
|
|
|
|
// Nothing to do if writing mode isn't being changed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decide composition fonts for both horizontal writing mode and vertical
|
|
|
|
// writing mode. If the font isn't specified by the pref, use default
|
|
|
|
// font which is already set to the IM context. And also in vertical writing
|
|
|
|
// mode, insert '@' to the start of the font.
|
|
|
|
if (!sCompositionFontsInitialized) {
|
|
|
|
sCompositionFontsInitialized = true;
|
|
|
|
// sCompositionFontH must not start with '@' and its length is less than
|
|
|
|
// LF_FACESIZE since it needs to end with null terminating character.
|
|
|
|
if (sCompositionFont.IsEmpty() ||
|
|
|
|
sCompositionFont.Length() > LF_FACESIZE - 1 ||
|
|
|
|
sCompositionFont[0] == '@') {
|
|
|
|
LOGFONTW defaultLogFont;
|
2015-07-23 06:31:28 +03:00
|
|
|
if (NS_WARN_IF(!::ImmGetCompositionFont(aContext.get(),
|
2015-05-15 04:18:07 +03:00
|
|
|
&defaultLogFont))) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("AdjustCompositionFont, ::ImmGetCompositionFont() failed"));
|
2015-05-15 04:18:07 +03:00
|
|
|
sCompositionFont.AssignLiteral("System");
|
|
|
|
} else {
|
|
|
|
// The font face is typically, "System".
|
|
|
|
sCompositionFont.Assign(defaultLogFont.lfFaceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("AdjustCompositionFont, sCompositionFont=\"%s\" is initialized",
|
2015-05-15 04:18:07 +03:00
|
|
|
NS_ConvertUTF16toUTF8(sCompositionFont).get()));
|
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:07 +03:00
|
|
|
static nsString sCompositionFontForJapanist2003;
|
|
|
|
if (IsJapanist2003Active() && sCompositionFontForJapanist2003.IsEmpty()) {
|
|
|
|
const char* kCompositionFontForJapanist2003 =
|
|
|
|
"intl.imm.composition_font.japanist_2003";
|
2017-07-31 07:23:50 +03:00
|
|
|
Preferences::GetString(kCompositionFontForJapanist2003,
|
|
|
|
sCompositionFontForJapanist2003);
|
2015-05-15 04:18:07 +03:00
|
|
|
// If the font name is not specified properly, let's use
|
|
|
|
// "MS PGothic" instead.
|
|
|
|
if (sCompositionFontForJapanist2003.IsEmpty() ||
|
|
|
|
sCompositionFontForJapanist2003.Length() > LF_FACESIZE - 2 ||
|
|
|
|
sCompositionFontForJapanist2003[0] == '@') {
|
|
|
|
sCompositionFontForJapanist2003.AssignLiteral("MS PGothic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:08 +03:00
|
|
|
sWritingModeOfCompositionFont = aWritingMode;
|
2015-05-15 04:18:07 +03:00
|
|
|
sCurrentIMEName = sIMEName;
|
|
|
|
|
|
|
|
LOGFONTW logFont;
|
|
|
|
memset(&logFont, 0, sizeof(logFont));
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!::ImmGetCompositionFont(aContext.get(), &logFont)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("AdjustCompositionFont, ::ImmGetCompositionFont() failed"));
|
2015-05-15 04:18:07 +03:00
|
|
|
logFont.lfFaceName[0] = 0;
|
|
|
|
}
|
|
|
|
// Need to reset some information which should be recomputed with new font.
|
|
|
|
logFont.lfWidth = 0;
|
|
|
|
logFont.lfWeight = FW_DONTCARE;
|
|
|
|
logFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
|
|
|
|
logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
|
|
|
logFont.lfPitchAndFamily = DEFAULT_PITCH;
|
|
|
|
|
2015-12-29 16:57:37 +03:00
|
|
|
if (!aWindow->PluginHasFocus() &&
|
|
|
|
aWritingMode.IsVertical() && IsVerticalWritingSupported()) {
|
2015-05-15 04:18:07 +03:00
|
|
|
SetVerticalFontToLogFont(
|
|
|
|
IsJapanist2003Active() ? sCompositionFontForJapanist2003 :
|
|
|
|
sCompositionFont, logFont);
|
2015-05-15 04:18:07 +03:00
|
|
|
} else {
|
2015-05-15 04:18:07 +03:00
|
|
|
SetHorizontalFontToLogFont(
|
|
|
|
IsJapanist2003Active() ? sCompositionFontForJapanist2003 :
|
|
|
|
sCompositionFont, logFont);
|
2015-05-15 04:18:07 +03:00
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Warning,
|
2016-07-05 12:35:43 +03:00
|
|
|
("AdjustCompositionFont, calling ::ImmSetCompositionFont(\"%s\")",
|
2015-05-15 04:18:07 +03:00
|
|
|
NS_ConvertUTF16toUTF8(nsDependentString(logFont.lfFaceName)).get()));
|
2015-07-23 06:31:28 +03:00
|
|
|
::ImmSetCompositionFontW(aContext.get(), &logFont);
|
2015-05-15 04:18:07 +03:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IMMHandler::OnMouseButtonEvent(nsWindow* aWindow,
|
|
|
|
const IMENotification& aIMENotification)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2014-09-11 07:41:15 +04:00
|
|
|
// We don't need to create the instance of the handler here.
|
2015-07-23 06:31:28 +03:00
|
|
|
if (!gIMMHandler) {
|
2014-09-11 07:41:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-07-18 12:12:31 +04:00
|
|
|
|
2014-09-11 07:41:15 +04:00
|
|
|
if (!sWM_MSIME_MOUSE || !IsComposingOnOurEditor() ||
|
2011-10-26 06:10:43 +04:00
|
|
|
!ShouldDrawCompositionStringOurselves()) {
|
2014-09-11 07:41:15 +04:00
|
|
|
return NS_OK;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2014-09-11 07:41:15 +04:00
|
|
|
// We need to handle only mousedown event.
|
2015-08-29 02:58:30 +03:00
|
|
|
if (aIMENotification.mMouseButtonEventData.mEventMessage != eMouseDown) {
|
2014-09-11 07:41:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the character under the cursor is not in the composition string,
|
|
|
|
// we don't need to notify IME of it.
|
2015-07-23 06:31:28 +03:00
|
|
|
uint32_t compositionStart = gIMMHandler->mCompositionStart;
|
2014-09-11 07:41:15 +04:00
|
|
|
uint32_t compositionEnd =
|
2015-07-23 06:31:28 +03:00
|
|
|
compositionStart + gIMMHandler->mCompositionString.Length();
|
2014-09-11 07:41:15 +04:00
|
|
|
if (aIMENotification.mMouseButtonEventData.mOffset < compositionStart ||
|
|
|
|
aIMENotification.mMouseButtonEventData.mOffset >= compositionEnd) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BYTE button;
|
|
|
|
switch (aIMENotification.mMouseButtonEventData.mButton) {
|
|
|
|
case WidgetMouseEventBase::eLeftButton:
|
|
|
|
button = IMEMOUSE_LDOWN;
|
|
|
|
break;
|
|
|
|
case WidgetMouseEventBase::eMiddleButton:
|
|
|
|
button = IMEMOUSE_MDOWN;
|
|
|
|
break;
|
|
|
|
case WidgetMouseEventBase::eRightButton:
|
|
|
|
button = IMEMOUSE_RDOWN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_OK;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// calcurate positioning and offset
|
|
|
|
// char : JCH1|JCH2|JCH3
|
|
|
|
// offset: 0011 1122 2233
|
|
|
|
// positioning: 2301 2301 2301
|
2014-09-11 07:41:15 +04:00
|
|
|
nsIntPoint cursorPos =
|
|
|
|
aIMENotification.mMouseButtonEventData.mCursorPos.AsIntPoint();
|
|
|
|
nsIntRect charRect =
|
|
|
|
aIMENotification.mMouseButtonEventData.mCharRect.AsIntRect();
|
|
|
|
int32_t cursorXInChar = cursorPos.x - charRect.x;
|
2011-10-26 06:10:43 +04:00
|
|
|
// The event might hit to zero-width character, see bug 694913.
|
|
|
|
// The reason might be:
|
|
|
|
// * There are some zero-width characters are actually.
|
|
|
|
// * font-size is specified zero.
|
|
|
|
// But nobody reproduced this bug actually...
|
|
|
|
// We should assume that user clicked on right most of the zero-width
|
|
|
|
// character in such case.
|
|
|
|
int positioning = 1;
|
2014-09-11 07:41:15 +04:00
|
|
|
if (charRect.width > 0) {
|
|
|
|
positioning = cursorXInChar * 4 / charRect.width;
|
2011-10-26 06:10:43 +04:00
|
|
|
positioning = (positioning + 2) % 4;
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2014-09-11 07:41:15 +04:00
|
|
|
int offset =
|
|
|
|
aIMENotification.mMouseButtonEventData.mOffset - compositionStart;
|
2009-05-15 04:46:24 +04:00
|
|
|
if (positioning < 2) {
|
2009-05-04 02:20:11 +04:00
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnMouseButtonEvent, x,y=%ld,%ld, offset=%ld, positioning=%ld",
|
2014-09-11 07:41:15 +04:00
|
|
|
cursorPos.x, cursorPos.y, offset, positioning));
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
// send MS_MSIME_MOUSE message to default IME window.
|
|
|
|
HWND imeWnd = ::ImmGetDefaultIMEWnd(aWindow->GetWindowHandle());
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
2014-09-11 07:41:15 +04:00
|
|
|
if (::SendMessageW(imeWnd, sWM_MSIME_MOUSE,
|
|
|
|
MAKELONG(MAKEWORD(button, positioning), offset),
|
2015-07-23 06:31:28 +03:00
|
|
|
(LPARAM) context.get()) == 1) {
|
2014-09-11 07:41:15 +04:00
|
|
|
return NS_SUCCESS_EVENT_CONSUMED;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMMHandler::OnKeyDownEvent(nsWindow* aWindow,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
|
|
|
MSGResult& aResult)
|
2010-06-02 06:14:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("OnKeyDownEvent, hWnd=%08x, wParam=%08x, lParam=%08x",
|
2010-06-02 06:14:11 +04:00
|
|
|
aWindow->GetWindowHandle(), wParam, lParam));
|
2013-07-18 12:12:31 +04:00
|
|
|
aResult.mConsumed = false;
|
2010-06-02 06:14:11 +04:00
|
|
|
switch (wParam) {
|
2010-09-15 06:13:12 +04:00
|
|
|
case VK_TAB:
|
|
|
|
case VK_PRIOR:
|
|
|
|
case VK_NEXT:
|
|
|
|
case VK_END:
|
|
|
|
case VK_HOME:
|
|
|
|
case VK_LEFT:
|
|
|
|
case VK_UP:
|
|
|
|
case VK_RIGHT:
|
|
|
|
case VK_DOWN:
|
2015-08-20 11:31:10 +03:00
|
|
|
case VK_RETURN:
|
2010-09-15 06:13:12 +04:00
|
|
|
// If IME didn't process the key message (the virtual key code wasn't
|
|
|
|
// converted to VK_PROCESSKEY), and the virtual key code event causes
|
2015-08-20 11:31:10 +03:00
|
|
|
// moving caret or editing text with keeping composing state, we should
|
|
|
|
// cancel the composition here because we cannot support moving
|
|
|
|
// composition string with DOM events (IE also cancels the composition
|
|
|
|
// in same cases). Then, this event will be dispatched.
|
2010-09-15 06:13:12 +04:00
|
|
|
if (IsComposingOnOurEditor()) {
|
|
|
|
// NOTE: We don't need to cancel the composition on another window.
|
2011-10-02 06:16:19 +04:00
|
|
|
CancelComposition(aWindow, false);
|
2010-09-15 06:13:12 +04:00
|
|
|
}
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-06-02 06:14:11 +04:00
|
|
|
default:
|
2011-10-02 06:16:19 +04:00
|
|
|
return false;
|
2010-06-02 06:14:11 +04:00
|
|
|
}
|
|
|
|
}
|
2015-07-22 06:40:32 +03:00
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMMHandler::SetCandidateWindow(nsWindow* aWindow, CANDIDATEFORM* aForm)
|
|
|
|
{
|
2016-08-09 11:46:44 +03:00
|
|
|
// Hack for ATOK 2011 - 2016 (Japanese IME). They refer native caret
|
|
|
|
// position at deciding candidate window position. Note that we cannot
|
|
|
|
// check active IME since TIPs are wrapped and hidden by CUAS.
|
2016-02-02 11:06:14 +03:00
|
|
|
if (aWindow->PluginHasFocus()) {
|
2016-01-13 06:44:39 +03:00
|
|
|
// We cannot retrieve proper character height from plugin. Therefore,
|
|
|
|
// we should assume that the caret height is always 20px since if less than
|
|
|
|
// this height, candidate window may overlap with composition string when
|
|
|
|
// there is no enough space under composition string to show candidate
|
|
|
|
// window.
|
|
|
|
static const int32_t kCaretHeight = 20;
|
|
|
|
if (sNativeCaretIsCreatedForPlugin) {
|
|
|
|
::DestroyCaret();
|
|
|
|
}
|
|
|
|
sNativeCaretIsCreatedForPlugin =
|
|
|
|
::CreateCaret(aWindow->GetWindowHandle(), nullptr, 0, kCaretHeight);
|
|
|
|
if (sNativeCaretIsCreatedForPlugin) {
|
|
|
|
LayoutDeviceIntPoint caretPosition(aForm->ptCurrentPos.x,
|
|
|
|
aForm->ptCurrentPos.y - kCaretHeight);
|
|
|
|
nsWindow* toplevelWindow = aWindow->GetTopLevelWindow(false);
|
|
|
|
if (toplevelWindow && toplevelWindow != aWindow) {
|
|
|
|
caretPosition += toplevelWindow->WidgetToScreenOffset();
|
|
|
|
caretPosition -= aWindow->WidgetToScreenOffset();
|
|
|
|
}
|
|
|
|
::SetCaretPos(caretPosition.x, caretPosition.y);
|
|
|
|
}
|
|
|
|
}
|
2015-12-29 16:57:38 +03:00
|
|
|
IMEContext context(aWindow);
|
2016-01-13 06:44:39 +03:00
|
|
|
::ImmSetCandidateWindow(context.get(), aForm);
|
2015-12-29 16:57:38 +03:00
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
// staitc
|
|
|
|
void
|
|
|
|
IMMHandler::DefaultProcOfPluginEvent(nsWindow* aWindow, const NPEvent* aEvent)
|
|
|
|
{
|
|
|
|
switch (aEvent->event) {
|
|
|
|
case WM_IME_STARTCOMPOSITION:
|
|
|
|
EnsureHandlerInstance();
|
|
|
|
gIMMHandler->OnIMEStartCompositionOnPlugin(aWindow, aEvent->wParam,
|
|
|
|
aEvent->lParam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_IME_COMPOSITION:
|
|
|
|
if (gIMMHandler) {
|
|
|
|
gIMMHandler->OnIMECompositionOnPlugin(aWindow, aEvent->wParam,
|
|
|
|
aEvent->lParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_IME_ENDCOMPOSITION:
|
|
|
|
if (gIMMHandler) {
|
|
|
|
gIMMHandler->OnIMEEndCompositionOnPlugin(aWindow, aEvent->wParam,
|
|
|
|
aEvent->lParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
/******************************************************************************
|
2015-07-23 06:31:28 +03:00
|
|
|
* IMMHandler::Selection
|
2015-07-22 06:40:32 +03:00
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::Selection::IsValid() const
|
2015-07-22 06:40:32 +03:00
|
|
|
{
|
|
|
|
if (!mIsValid || NS_WARN_IF(mOffset == UINT32_MAX)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
CheckedInt<uint32_t> endOffset =
|
|
|
|
CheckedInt<uint32_t>(mOffset) + Length();
|
|
|
|
return endOffset.isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::Selection::Update(const IMENotification& aIMENotification)
|
2015-07-22 06:40:32 +03:00
|
|
|
{
|
|
|
|
mOffset = aIMENotification.mSelectionChangeData.mOffset;
|
|
|
|
mString = aIMENotification.mSelectionChangeData.String();
|
|
|
|
mWritingMode = aIMENotification.mSelectionChangeData.GetWritingMode();
|
|
|
|
mIsValid = true;
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("Selection::Update, aIMENotification={ mSelectionChangeData={ "
|
2015-07-22 06:40:32 +03:00
|
|
|
"mOffset=%u, mLength=%u, GetWritingMode()=%s } }",
|
|
|
|
mOffset, mString.Length(), GetWritingModeName(mWritingMode).get()));
|
|
|
|
|
|
|
|
if (!IsValid()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("Selection::Update, FAILED, due to invalid range"));
|
2015-07-22 06:40:32 +03:00
|
|
|
Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::Selection::Init(nsWindow* aWindow)
|
2015-07-22 06:40:32 +03:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent selection(true, eQuerySelectedText, aWindow);
|
2015-11-10 08:37:32 +03:00
|
|
|
LayoutDeviceIntPoint point(0, 0);
|
2015-07-22 06:40:32 +03:00
|
|
|
aWindow->InitEvent(selection, &point);
|
2015-11-17 10:47:06 +03:00
|
|
|
DispatchEvent(aWindow, selection);
|
2015-07-22 06:40:32 +03:00
|
|
|
if (NS_WARN_IF(!selection.mSucceeded)) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("Selection::Init, FAILED, due to eQuerySelectedText failure"));
|
2015-07-22 06:40:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If the window is destroyed during querying selected text, we shouldn't
|
|
|
|
// do anymore.
|
|
|
|
if (aWindow->Destroyed()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("Selection::Init, FAILED, due to the widget destroyed"));
|
2015-07-22 06:40:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mOffset = selection.mReply.mOffset;
|
|
|
|
mString = selection.mReply.mString;
|
|
|
|
mWritingMode = selection.GetWritingMode();
|
|
|
|
mIsValid = true;
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Info,
|
2016-07-05 12:35:43 +03:00
|
|
|
("Selection::Init, selection={ mReply={ mOffset=%u, "
|
2015-07-22 06:40:32 +03:00
|
|
|
"mString.Length()=%u, mWritingMode=%s } }",
|
|
|
|
mOffset, mString.Length(), GetWritingModeName(mWritingMode).get()));
|
|
|
|
|
|
|
|
if (!IsValid()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_LOG(gIMMLog, LogLevel::Error,
|
2016-07-05 12:35:43 +03:00
|
|
|
("Selection::Init, FAILED, due to invalid range"));
|
2015-07-22 06:40:32 +03:00
|
|
|
Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::Selection::EnsureValidSelection(nsWindow* aWindow)
|
2015-07-22 06:40:32 +03:00
|
|
|
{
|
|
|
|
if (IsValid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return Init(aWindow);
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|