2009-02-10 12:56:51 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
#include <olectl.h>
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#endif // MOZ_LOGGING
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsWindow.h"
|
2013-01-07 07:18:11 -08:00
|
|
|
#ifdef MOZ_METRO
|
|
|
|
#include "winrt/MetroWidget.h"
|
|
|
|
#endif
|
2009-02-23 00:56:33 -08:00
|
|
|
#include "nsPrintfCString.h"
|
2012-09-11 16:53:12 -07:00
|
|
|
#include "WinUtils.h"
|
2011-05-27 01:15:20 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-11-21 19:35:42 -08:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
2011-05-27 01:15:20 -07:00
|
|
|
|
2013-01-30 02:45:42 -08:00
|
|
|
#define INPUTSCOPE_INIT_GUID
|
|
|
|
#include "nsTextStore.h"
|
|
|
|
|
2011-05-27 01:15:20 -07:00
|
|
|
using namespace mozilla;
|
2011-11-27 03:51:52 -08:00
|
|
|
using namespace mozilla::widget;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2014-01-13 18:00:59 -08:00
|
|
|
static const char* kPrefNameTSFEnabled = "intl.tsf.enable";
|
|
|
|
|
|
|
|
static const char* kLegacyPrefNameTSFEnabled = "intl.enable_tsf_support";
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
#ifdef PR_LOGGING
|
2012-09-11 16:53:12 -07:00
|
|
|
/**
|
|
|
|
* TSF related code should log its behavior even on release build especially
|
|
|
|
* in the interface methods.
|
|
|
|
*
|
|
|
|
* In interface methods, use PR_LOG_ALWAYS.
|
|
|
|
* In internal methods, use PR_LOG_DEBUG for logging normal behavior.
|
|
|
|
* For logging error, use PR_LOG_ERROR.
|
|
|
|
*
|
|
|
|
* When an instance method is called, start with following text:
|
|
|
|
* "TSF: 0x%p nsFoo::Bar(", the 0x%p should be the "this" of the nsFoo.
|
|
|
|
* after that, start with:
|
|
|
|
* "TSF: 0x%p nsFoo::Bar("
|
|
|
|
* In an internal method, start with following text:
|
|
|
|
* "TSF: 0x%p nsFoo::Bar("
|
|
|
|
* When a static method is called, start with following text:
|
|
|
|
* "TSF: nsFoo::Bar("
|
|
|
|
*/
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
PRLogModuleInfo* sTextStoreLog = nullptr;
|
2013-01-26 06:35:21 -08:00
|
|
|
#endif // #ifdef PR_LOGGING
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
/* InputScopeImpl */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
class InputScopeImpl MOZ_FINAL : public ITfInputScope
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
InputScopeImpl(const nsTArray<InputScope>& aList) :
|
|
|
|
mRefCnt(1),
|
|
|
|
mInputScopes(aList)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p InputScopeImpl()", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) AddRef(void) { return ++mRefCnt; }
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) Release(void)
|
|
|
|
{
|
|
|
|
--mRefCnt;
|
|
|
|
if (mRefCnt) {
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p InputScopeImpl::Release() final", this));
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP QueryInterface(REFIID riid, void** ppv)
|
|
|
|
{
|
2013-10-08 11:48:20 -07:00
|
|
|
*ppv=nullptr;
|
2013-01-26 06:35:21 -08:00
|
|
|
if ( (IID_IUnknown == riid) || (IID_ITfInputScope == riid) ) {
|
|
|
|
*ppv = static_cast<ITfInputScope*>(this);
|
|
|
|
}
|
|
|
|
if (*ppv) {
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP GetInputScopes(InputScope** pprgInputScopes, UINT* pcCount)
|
|
|
|
{
|
|
|
|
uint32_t count = (mInputScopes.IsEmpty() ? 1 : mInputScopes.Length());
|
|
|
|
|
|
|
|
InputScope* pScope = (InputScope*) CoTaskMemAlloc(sizeof(InputScope) * count);
|
|
|
|
NS_ENSURE_TRUE(pScope, E_OUTOFMEMORY);
|
|
|
|
|
|
|
|
if (mInputScopes.IsEmpty()) {
|
|
|
|
*pScope = IS_DEFAULT;
|
|
|
|
*pcCount = 1;
|
|
|
|
*pprgInputScopes = pScope;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcCount = 0;
|
|
|
|
|
|
|
|
for (uint32_t idx = 0; idx < count; idx++) {
|
|
|
|
*(pScope + idx) = mInputScopes[idx];
|
|
|
|
(*pcCount)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pprgInputScopes = pScope;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP GetPhrase(BSTR **ppbstrPhrases, UINT *pcCount) { return E_NOTIMPL; }
|
|
|
|
STDMETHODIMP GetRegularExpression(BSTR *pbstrRegExp) { return E_NOTIMPL; }
|
|
|
|
STDMETHODIMP GetSRGS(BSTR *pbstrSRGS) { return E_NOTIMPL; }
|
|
|
|
STDMETHODIMP GetXML(BSTR *pbstrXML) { return E_NOTIMPL; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
DWORD mRefCnt;
|
|
|
|
nsTArray<InputScope> mInputScopes;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
/* nsTextStore */
|
|
|
|
/******************************************************************/
|
|
|
|
|
2013-10-08 11:48:20 -07:00
|
|
|
ITfThreadMgr* nsTextStore::sTsfThreadMgr = nullptr;
|
|
|
|
ITfMessagePump* nsTextStore::sMessagePump = nullptr;
|
|
|
|
ITfKeystrokeMgr* nsTextStore::sKeystrokeMgr = nullptr;
|
|
|
|
ITfDisplayAttributeMgr* nsTextStore::sDisplayAttrMgr = nullptr;
|
|
|
|
ITfCategoryMgr* nsTextStore::sCategoryMgr = nullptr;
|
|
|
|
ITfDocumentMgr* nsTextStore::sTsfDisabledDocumentMgr = nullptr;
|
|
|
|
ITfContext* nsTextStore::sTsfDisabledContext = nullptr;
|
2014-01-13 18:01:00 -08:00
|
|
|
ITfInputProcessorProfiles* nsTextStore::sInputProcessorProfiles = nullptr;
|
2013-01-26 06:35:21 -08:00
|
|
|
DWORD nsTextStore::sTsfClientId = 0;
|
2013-10-08 11:48:20 -07:00
|
|
|
nsTextStore* nsTextStore::sTsfTextStore = nullptr;
|
2013-01-26 06:35:21 -08:00
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
bool nsTextStore::sCreateNativeCaretForATOK = false;
|
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
UINT nsTextStore::sFlushTIPInputMessage = 0;
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
#define TEXTSTORE_DEFAULT_VIEW (1)
|
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
#ifdef PR_LOGGING
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetBoolName(bool aBool)
|
|
|
|
{
|
|
|
|
return aBool ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
static void
|
|
|
|
HandleSeparator(nsCString& aDesc)
|
|
|
|
{
|
|
|
|
if (!aDesc.IsEmpty()) {
|
|
|
|
aDesc.AppendLiteral(" | ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const nsCString
|
|
|
|
GetFindFlagName(DWORD aFindFlag)
|
|
|
|
{
|
|
|
|
nsAutoCString description;
|
|
|
|
if (!aFindFlag) {
|
|
|
|
description.AppendLiteral("no flags (0)");
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
if (aFindFlag & TS_ATTR_FIND_BACKWARDS) {
|
|
|
|
description.AppendLiteral("TS_ATTR_FIND_BACKWARDS");
|
|
|
|
}
|
|
|
|
if (aFindFlag & TS_ATTR_FIND_WANT_OFFSET) {
|
|
|
|
HandleSeparator(description);
|
|
|
|
description.AppendLiteral("TS_ATTR_FIND_WANT_OFFSET");
|
|
|
|
}
|
|
|
|
if (aFindFlag & TS_ATTR_FIND_UPDATESTART) {
|
|
|
|
HandleSeparator(description);
|
|
|
|
description.AppendLiteral("TS_ATTR_FIND_UPDATESTART");
|
|
|
|
}
|
|
|
|
if (aFindFlag & TS_ATTR_FIND_WANT_VALUE) {
|
|
|
|
HandleSeparator(description);
|
|
|
|
description.AppendLiteral("TS_ATTR_FIND_WANT_VALUE");
|
|
|
|
}
|
|
|
|
if (aFindFlag & TS_ATTR_FIND_WANT_END) {
|
|
|
|
HandleSeparator(description);
|
|
|
|
description.AppendLiteral("TS_ATTR_FIND_WANT_END");
|
|
|
|
}
|
|
|
|
if (aFindFlag & TS_ATTR_FIND_HIDDEN) {
|
|
|
|
HandleSeparator(description);
|
|
|
|
description.AppendLiteral("TS_ATTR_FIND_HIDDEN");
|
|
|
|
}
|
|
|
|
if (description.IsEmpty()) {
|
|
|
|
description.AppendLiteral("Unknown (");
|
|
|
|
description.AppendInt(static_cast<uint32_t>(aFindFlag));
|
|
|
|
description.AppendLiteral(")");
|
|
|
|
}
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
static const char*
|
|
|
|
GetIMEEnabledName(IMEState::Enabled aIMEEnabled)
|
|
|
|
{
|
|
|
|
switch (aIMEEnabled) {
|
|
|
|
case IMEState::DISABLED:
|
|
|
|
return "DISABLED";
|
|
|
|
case IMEState::ENABLED:
|
|
|
|
return "ENABLED";
|
|
|
|
case IMEState::PASSWORD:
|
|
|
|
return "PASSWORD";
|
|
|
|
case IMEState::PLUGIN:
|
|
|
|
return "PLUGIN";
|
|
|
|
default:
|
|
|
|
return "Invalid";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 17:04:02 -07:00
|
|
|
static const char*
|
|
|
|
GetFocusChangeName(InputContextAction::FocusChange aFocusChange)
|
|
|
|
{
|
|
|
|
switch (aFocusChange) {
|
|
|
|
case InputContextAction::FOCUS_NOT_CHANGED:
|
|
|
|
return "FOCUS_NOT_CHANGED";
|
|
|
|
case InputContextAction::GOT_FOCUS:
|
|
|
|
return "GOT_FOCUS";
|
|
|
|
case InputContextAction::LOST_FOCUS:
|
|
|
|
return "LOST_FOCUS";
|
|
|
|
case InputContextAction::MENU_GOT_PSEUDO_FOCUS:
|
|
|
|
return "MENU_GOT_PSEUDO_FOCUS";
|
|
|
|
case InputContextAction::MENU_LOST_PSEUDO_FOCUS:
|
|
|
|
return "MENU_LOST_PSEUDO_FOCUS";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
static nsCString
|
|
|
|
GetCLSIDNameStr(REFCLSID aCLSID)
|
|
|
|
{
|
|
|
|
LPOLESTR str = nullptr;
|
|
|
|
HRESULT hr = ::StringFromCLSID(aCLSID, &str);
|
|
|
|
if (FAILED(hr) || !str || !str[0]) {
|
|
|
|
return EmptyCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString result;
|
|
|
|
result = NS_ConvertUTF16toUTF8(str);
|
|
|
|
::CoTaskMemFree(str);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-01-13 18:01:00 -08:00
|
|
|
static nsCString
|
|
|
|
GetGUIDNameStr(REFGUID aGUID)
|
|
|
|
{
|
|
|
|
OLECHAR str[40];
|
|
|
|
int len = ::StringFromGUID2(aGUID, str, ArrayLength(str));
|
|
|
|
if (!len || !str[0]) {
|
|
|
|
return EmptyCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ConvertUTF16toUTF8(str);
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
static nsCString
|
|
|
|
GetRIIDNameStr(REFIID aRIID)
|
|
|
|
{
|
|
|
|
LPOLESTR str = nullptr;
|
|
|
|
HRESULT hr = ::StringFromIID(aRIID, &str);
|
|
|
|
if (FAILED(hr) || !str || !str[0]) {
|
|
|
|
return EmptyCString();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString key(L"Interface\\");
|
|
|
|
key += str;
|
|
|
|
|
|
|
|
nsAutoCString result;
|
2013-12-03 07:12:57 -08:00
|
|
|
wchar_t buf[256];
|
2012-09-11 16:53:12 -07:00
|
|
|
if (WinUtils::GetRegistryKey(HKEY_CLASSES_ROOT, key.get(), nullptr,
|
|
|
|
buf, sizeof(buf))) {
|
|
|
|
result = NS_ConvertUTF16toUTF8(buf);
|
|
|
|
} else {
|
|
|
|
result = NS_ConvertUTF16toUTF8(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
::CoTaskMemFree(str);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetCommonReturnValueName(HRESULT aResult)
|
|
|
|
{
|
|
|
|
switch (aResult) {
|
|
|
|
case S_OK:
|
|
|
|
return "S_OK";
|
|
|
|
case E_ABORT:
|
|
|
|
return "E_ABORT";
|
|
|
|
case E_ACCESSDENIED:
|
|
|
|
return "E_ACCESSDENIED";
|
|
|
|
case E_FAIL:
|
|
|
|
return "E_FAIL";
|
|
|
|
case E_HANDLE:
|
|
|
|
return "E_HANDLE";
|
|
|
|
case E_INVALIDARG:
|
|
|
|
return "E_INVALIDARG";
|
|
|
|
case E_NOINTERFACE:
|
|
|
|
return "E_NOINTERFACE";
|
|
|
|
case E_NOTIMPL:
|
|
|
|
return "E_NOTIMPL";
|
|
|
|
case E_OUTOFMEMORY:
|
|
|
|
return "E_OUTOFMEMORY";
|
|
|
|
case E_POINTER:
|
|
|
|
return "E_POINTER";
|
|
|
|
case E_UNEXPECTED:
|
|
|
|
return "E_UNEXPECTED";
|
|
|
|
default:
|
|
|
|
return SUCCEEDED(aResult) ? "Succeeded" : "Failed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetTextStoreReturnValueName(HRESULT aResult)
|
|
|
|
{
|
|
|
|
switch (aResult) {
|
|
|
|
case TS_E_FORMAT:
|
|
|
|
return "TS_E_FORMAT";
|
|
|
|
case TS_E_INVALIDPOINT:
|
|
|
|
return "TS_E_INVALIDPOINT";
|
|
|
|
case TS_E_INVALIDPOS:
|
|
|
|
return "TS_E_INVALIDPOS";
|
|
|
|
case TS_E_NOINTERFACE:
|
|
|
|
return "TS_E_NOINTERFACE";
|
|
|
|
case TS_E_NOLAYOUT:
|
|
|
|
return "TS_E_NOLAYOUT";
|
|
|
|
case TS_E_NOLOCK:
|
|
|
|
return "TS_E_NOLOCK";
|
|
|
|
case TS_E_NOOBJECT:
|
|
|
|
return "TS_E_NOOBJECT";
|
|
|
|
case TS_E_NOSELECTION:
|
|
|
|
return "TS_E_NOSELECTION";
|
|
|
|
case TS_E_NOSERVICE:
|
|
|
|
return "TS_E_NOSERVICE";
|
|
|
|
case TS_E_READONLY:
|
|
|
|
return "TS_E_READONLY";
|
|
|
|
case TS_E_SYNCHRONOUS:
|
|
|
|
return "TS_E_SYNCHRONOUS";
|
|
|
|
case TS_S_ASYNC:
|
|
|
|
return "TS_S_ASYNC";
|
|
|
|
default:
|
|
|
|
return GetCommonReturnValueName(aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const nsCString
|
|
|
|
GetSinkMaskNameStr(DWORD aSinkMask)
|
|
|
|
{
|
|
|
|
nsAutoCString description;
|
|
|
|
if (aSinkMask & TS_AS_TEXT_CHANGE) {
|
|
|
|
description.AppendLiteral("TS_AS_TEXT_CHANGE");
|
|
|
|
}
|
|
|
|
if (aSinkMask & TS_AS_SEL_CHANGE) {
|
2013-01-26 06:35:21 -08:00
|
|
|
HandleSeparator(description);
|
2012-09-11 16:53:12 -07:00
|
|
|
description.AppendLiteral("TS_AS_SEL_CHANGE");
|
|
|
|
}
|
|
|
|
if (aSinkMask & TS_AS_LAYOUT_CHANGE) {
|
2013-01-26 06:35:21 -08:00
|
|
|
HandleSeparator(description);
|
2012-09-11 16:53:12 -07:00
|
|
|
description.AppendLiteral("TS_AS_LAYOUT_CHANGE");
|
|
|
|
}
|
|
|
|
if (aSinkMask & TS_AS_ATTR_CHANGE) {
|
2013-01-26 06:35:21 -08:00
|
|
|
HandleSeparator(description);
|
2012-09-11 16:53:12 -07:00
|
|
|
description.AppendLiteral("TS_AS_ATTR_CHANGE");
|
|
|
|
}
|
|
|
|
if (aSinkMask & TS_AS_STATUS_CHANGE) {
|
2013-01-26 06:35:21 -08:00
|
|
|
HandleSeparator(description);
|
2012-09-11 16:53:12 -07:00
|
|
|
description.AppendLiteral("TS_AS_STATUS_CHANGE");
|
|
|
|
}
|
|
|
|
if (description.IsEmpty()) {
|
|
|
|
description.AppendLiteral("not-specified");
|
|
|
|
}
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetActiveSelEndName(TsActiveSelEnd aSelEnd)
|
|
|
|
{
|
|
|
|
return aSelEnd == TS_AE_NONE ? "TS_AE_NONE" :
|
|
|
|
aSelEnd == TS_AE_START ? "TS_AE_START" :
|
|
|
|
aSelEnd == TS_AE_END ? "TS_AE_END" : "Unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const nsCString
|
|
|
|
GetLockFlagNameStr(DWORD aLockFlags)
|
|
|
|
{
|
|
|
|
nsAutoCString description;
|
|
|
|
if ((aLockFlags & TS_LF_READWRITE) == TS_LF_READWRITE) {
|
|
|
|
description.AppendLiteral("TS_LF_READWRITE");
|
|
|
|
} else if (aLockFlags & TS_LF_READ) {
|
|
|
|
description.AppendLiteral("TS_LF_READ");
|
|
|
|
}
|
|
|
|
if (aLockFlags & TS_LF_SYNC) {
|
|
|
|
if (!description.IsEmpty()) {
|
|
|
|
description.AppendLiteral(" | ");
|
|
|
|
}
|
|
|
|
description.AppendLiteral("TS_LF_SYNC");
|
|
|
|
}
|
|
|
|
if (description.IsEmpty()) {
|
|
|
|
description.AppendLiteral("not-specified");
|
|
|
|
}
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
GetTextRunTypeName(TsRunType aRunType)
|
|
|
|
{
|
|
|
|
switch (aRunType) {
|
|
|
|
case TS_RT_PLAIN:
|
|
|
|
return "TS_RT_PLAIN";
|
|
|
|
case TS_RT_HIDDEN:
|
|
|
|
return "TS_RT_HIDDEN";
|
|
|
|
case TS_RT_OPAQUE:
|
|
|
|
return "TS_RT_OPAQUE";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
static nsCString
|
|
|
|
GetColorName(const TF_DA_COLOR &aColor)
|
|
|
|
{
|
|
|
|
switch (aColor.type) {
|
|
|
|
case TF_CT_NONE:
|
|
|
|
return NS_LITERAL_CSTRING("TF_CT_NONE");
|
|
|
|
case TF_CT_SYSCOLOR:
|
|
|
|
return nsPrintfCString("TF_CT_SYSCOLOR, nIndex:0x%08X",
|
|
|
|
static_cast<int32_t>(aColor.nIndex));
|
|
|
|
case TF_CT_COLORREF:
|
|
|
|
return nsPrintfCString("TF_CT_COLORREF, cr:0x%08X",
|
|
|
|
static_cast<int32_t>(aColor.cr));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return nsPrintfCString("Unknown(%08X)",
|
|
|
|
static_cast<int32_t>(aColor.type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
GetLineStyleName(TF_DA_LINESTYLE aLineStyle)
|
|
|
|
{
|
|
|
|
switch (aLineStyle) {
|
|
|
|
case TF_LS_NONE:
|
|
|
|
return NS_LITERAL_CSTRING("TF_LS_NONE");
|
|
|
|
case TF_LS_SOLID:
|
|
|
|
return NS_LITERAL_CSTRING("TF_LS_SOLID");
|
|
|
|
case TF_LS_DOT:
|
|
|
|
return NS_LITERAL_CSTRING("TF_LS_DOT");
|
|
|
|
case TF_LS_DASH:
|
|
|
|
return NS_LITERAL_CSTRING("TF_LS_DASH");
|
|
|
|
case TF_LS_SQUIGGLE:
|
|
|
|
return NS_LITERAL_CSTRING("TF_LS_SQUIGGLE");
|
|
|
|
default: {
|
|
|
|
return nsPrintfCString("Unknown(%08X)", static_cast<int32_t>(aLineStyle));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
GetClauseAttrName(TF_DA_ATTR_INFO aAttr)
|
|
|
|
{
|
|
|
|
switch (aAttr) {
|
|
|
|
case TF_ATTR_INPUT:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_INPUT");
|
|
|
|
case TF_ATTR_TARGET_CONVERTED:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_TARGET_CONVERTED");
|
|
|
|
case TF_ATTR_CONVERTED:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_CONVERTED");
|
|
|
|
case TF_ATTR_TARGET_NOTCONVERTED:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_TARGET_NOTCONVERTED");
|
|
|
|
case TF_ATTR_INPUT_ERROR:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_INPUT_ERROR");
|
|
|
|
case TF_ATTR_FIXEDCONVERTED:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_FIXEDCONVERTED");
|
|
|
|
case TF_ATTR_OTHER:
|
|
|
|
return NS_LITERAL_CSTRING("TF_ATTR_OTHER");
|
|
|
|
default: {
|
|
|
|
return nsPrintfCString("Unknown(%08X)", static_cast<int32_t>(aAttr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
GetDisplayAttrStr(const TF_DISPLAYATTRIBUTE &aDispAttr)
|
|
|
|
{
|
|
|
|
nsAutoCString str;
|
|
|
|
str = "crText:{ ";
|
|
|
|
str += GetColorName(aDispAttr.crText);
|
|
|
|
str += " }, crBk:{ ";
|
|
|
|
str += GetColorName(aDispAttr.crBk);
|
|
|
|
str += " }, lsStyle: ";
|
|
|
|
str += GetLineStyleName(aDispAttr.lsStyle);
|
|
|
|
str += ", fBoldLine: ";
|
|
|
|
str += GetBoolName(aDispAttr.fBoldLine);
|
|
|
|
str += ", crLine:{ ";
|
|
|
|
str += GetColorName(aDispAttr.crLine);
|
|
|
|
str += " }, bAttr: ";
|
|
|
|
str += GetClauseAttrName(aDispAttr.bAttr);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
#endif // #ifdef PR_LOGGING
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
nsTextStore::nsTextStore()
|
2013-03-12 20:01:30 -07:00
|
|
|
: mContent(mComposition, mSelection)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
|
|
|
mRefCnt = 1;
|
|
|
|
mEditCookie = 0;
|
2014-01-13 18:01:00 -08:00
|
|
|
mIPProfileCookie = TF_INVALID_COOKIE;
|
2014-01-30 18:17:25 -08:00
|
|
|
mLangProfileCookie = TF_INVALID_COOKIE;
|
2009-02-10 12:56:51 -08:00
|
|
|
mSinkMask = 0;
|
|
|
|
mLock = 0;
|
|
|
|
mLockQueued = 0;
|
2013-01-26 06:35:21 -08:00
|
|
|
mInputScopeDetected = false;
|
|
|
|
mInputScopeRequested = false;
|
2013-03-12 20:01:29 -07:00
|
|
|
mIsRecordingActionsWithoutLock = false;
|
2014-02-04 23:36:17 -08:00
|
|
|
mPendingOnSelectionChange = false;
|
|
|
|
mPendingOnLayoutChange = false;
|
2014-01-30 18:17:24 -08:00
|
|
|
mNativeCaretIsCreated = false;
|
2014-01-30 18:17:25 -08:00
|
|
|
mIsIMM_IME = false;
|
|
|
|
mOnActivatedCalled = false;
|
2013-03-12 20:01:29 -07:00
|
|
|
// We hope that 5 or more actions don't occur at once.
|
|
|
|
mPendingActions.SetCapacity(5);
|
2014-01-13 18:01:00 -08:00
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::nsTestStore() SUCCEEDED", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsTextStore::Init(ITfThreadMgr* aThreadMgr)
|
|
|
|
{
|
|
|
|
nsRefPtr<ITfSource> source;
|
|
|
|
HRESULT hr =
|
|
|
|
aThreadMgr->QueryInterface(IID_ITfSource, getter_AddRefs(source));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::Init() FAILED to get ITfSource instance "
|
|
|
|
"(0x%08X)", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-13 18:01:00 -08:00
|
|
|
// On Vista or later, Windows let us know activate IME changed only with
|
2014-01-30 18:17:25 -08:00
|
|
|
// ITfInputProcessorProfileActivationSink. However, it's not available on XP.
|
|
|
|
// On XP, ITfActiveLanguageProfileNotifySink is available for it.
|
|
|
|
// NOTE: Each OnActivated() should be called when TSF becomes available.
|
2014-01-13 18:01:00 -08:00
|
|
|
if (IsVistaOrLater()) {
|
2014-01-30 18:17:25 -08:00
|
|
|
hr = source->AdviseSink(IID_ITfInputProcessorProfileActivationSink,
|
|
|
|
static_cast<ITfInputProcessorProfileActivationSink*>(this),
|
|
|
|
&mIPProfileCookie);
|
|
|
|
if (FAILED(hr) || mIPProfileCookie == TF_INVALID_COOKIE) {
|
2014-01-13 18:01:00 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-30 18:17:25 -08:00
|
|
|
("TSF: 0x%p nsTextStore::Init() FAILED to install "
|
|
|
|
"ITfInputProcessorProfileActivationSink (0x%08X)", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hr = source->AdviseSink(IID_ITfActiveLanguageProfileNotifySink,
|
|
|
|
static_cast<ITfActiveLanguageProfileNotifySink*>(this),
|
|
|
|
&mLangProfileCookie);
|
|
|
|
if (FAILED(hr) || mLangProfileCookie == TF_INVALID_COOKIE) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::Init() FAILED to install "
|
|
|
|
"ITfActiveLanguageProfileNotifySink (0x%08X)", this, hr));
|
|
|
|
return false;
|
2014-01-13 18:01:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-30 18:17:25 -08:00
|
|
|
("TSF: 0x%p nsTextStore::Init(), "
|
|
|
|
"mIPProfileCookie=0x%08X, mLangProfileCookie=0x%08X",
|
|
|
|
this, mIPProfileCookie, mLangProfileCookie));
|
|
|
|
|
|
|
|
return true;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTextStore::~nsTextStore()
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore instance is destroyed, "
|
2014-01-30 18:17:25 -08:00
|
|
|
"mWidget=0x%p, mDocumentMgr=0x%p, mContext=0x%p, mIPProfileCookie=0x%08X, "
|
|
|
|
"mLangProfileCookie=0x%08X",
|
2014-01-13 18:01:00 -08:00
|
|
|
this, mWidget.get(), mDocumentMgr.get(), mContext.get(),
|
2014-01-30 18:17:25 -08:00
|
|
|
mIPProfileCookie, mLangProfileCookie));
|
2014-01-13 18:01:00 -08:00
|
|
|
|
|
|
|
if (mIPProfileCookie != TF_INVALID_COOKIE) {
|
2014-01-30 18:17:25 -08:00
|
|
|
nsRefPtr<ITfSource> source;
|
|
|
|
HRESULT hr =
|
|
|
|
sTsfThreadMgr->QueryInterface(IID_ITfSource, getter_AddRefs(source));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p ~nsTextStore FAILED to get ITfSource instance "
|
|
|
|
"(0x%08X)", this, hr));
|
|
|
|
} else {
|
|
|
|
hr = source->UnadviseSink(mIPProfileCookie);
|
2014-01-13 18:01:00 -08:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-30 18:17:25 -08:00
|
|
|
("TSF: 0x%p ~nsTextStore FAILED to uninstall "
|
|
|
|
"ITfInputProcessorProfileActivationSink (0x%08X)",
|
|
|
|
this, hr));
|
2014-01-13 18:01:00 -08:00
|
|
|
}
|
2014-01-30 18:17:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLangProfileCookie != TF_INVALID_COOKIE) {
|
|
|
|
nsRefPtr<ITfSource> source;
|
|
|
|
HRESULT hr =
|
|
|
|
sTsfThreadMgr->QueryInterface(IID_ITfSource, getter_AddRefs(source));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p ~nsTextStore FAILED to get ITfSource instance "
|
|
|
|
"(0x%08X)", this, hr));
|
2014-01-13 18:01:00 -08:00
|
|
|
} else {
|
2014-01-30 18:17:25 -08:00
|
|
|
hr = source->UnadviseSink(mLangProfileCookie);
|
2014-01-13 18:01:00 -08:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-30 18:17:25 -08:00
|
|
|
("TSF: 0x%p ~nsTextStore FAILED to uninstall "
|
|
|
|
"ITfActiveLanguageProfileNotifySink (0x%08X)",
|
|
|
|
this, hr));
|
2014-01-13 18:01:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-03-26 17:04:02 -07:00
|
|
|
nsTextStore::Create(nsWindowBase* aWidget)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-03-26 17:04:02 -07:00
|
|
|
("TSF: 0x%p nsTextStore::Create(aWidget=0x%p)",
|
|
|
|
this, aWidget));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
EnsureInitActiveTIPKeyboard();
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
if (mDocumentMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::Create() FAILED due to already initialized",
|
|
|
|
this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create document manager
|
|
|
|
HRESULT hr = sTsfThreadMgr->CreateDocumentMgr(
|
|
|
|
getter_AddRefs(mDocumentMgr));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::Create() FAILED to create DocumentMgr "
|
|
|
|
"(0x%08X)", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-07 07:18:11 -08:00
|
|
|
mWidget = aWidget;
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// Create context and add it to document manager
|
|
|
|
hr = mDocumentMgr->CreateContext(sTsfClientId, 0,
|
|
|
|
static_cast<ITextStoreACP*>(this),
|
|
|
|
getter_AddRefs(mContext), &mEditCookie);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::Create() FAILED to create the context "
|
|
|
|
"(0x%08X)", this, hr));
|
2013-10-08 11:48:20 -07:00
|
|
|
mDocumentMgr = nullptr;
|
2012-09-11 16:53:12 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mDocumentMgr->Push(mContext);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::Create() FAILED to push the context (0x%08X)",
|
|
|
|
this, hr));
|
|
|
|
// XXX Why don't we use NS_IF_RELEASE() here??
|
2013-10-08 11:48:20 -07:00
|
|
|
mContext = nullptr;
|
|
|
|
mDocumentMgr = nullptr;
|
2012-09-11 16:53:12 -07:00
|
|
|
return false;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::Create() succeeded: "
|
|
|
|
"mDocumentMgr=0x%p, mContext=0x%p, mEditCookie=0x%08X",
|
2012-09-14 07:13:46 -07:00
|
|
|
this, mDocumentMgr.get(), mContext.get(), mEditCookie));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
return true;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-02-10 12:56:51 -08:00
|
|
|
nsTextStore::Destroy(void)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-23 01:36:01 -08:00
|
|
|
("TSF: 0x%p nsTextStore::Destroy(), mComposition.IsComposing()=%s",
|
|
|
|
this, GetBoolName(mComposition.IsComposing())));
|
|
|
|
|
|
|
|
// If there is composition, TSF keeps the composition even after the text
|
|
|
|
// store destroyed. So, we should clear the composition here.
|
|
|
|
if (mComposition.IsComposing()) {
|
|
|
|
NS_WARNING("Composition is still alive at destroying the text store");
|
|
|
|
CommitCompositionInternal(false);
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
mContent.Clear();
|
2013-03-12 20:01:29 -07:00
|
|
|
mSelection.MarkDirty();
|
|
|
|
|
2013-01-07 07:18:11 -08:00
|
|
|
if (mWidget) {
|
2009-02-10 12:56:51 -08:00
|
|
|
// When blurred, Tablet Input Panel posts "blur" messages
|
|
|
|
// and try to insert text when the message is retrieved later.
|
|
|
|
// But by that time the text store is already destroyed,
|
|
|
|
// so try to get the message early
|
|
|
|
MSG msg;
|
2013-03-17 21:41:24 -07:00
|
|
|
if (WinUtils::PeekMessage(&msg, mWidget->GetWindowHandle(),
|
|
|
|
sFlushTIPInputMessage, sFlushTIPInputMessage,
|
|
|
|
PM_REMOVE)) {
|
2009-02-10 12:56:51 -08:00
|
|
|
::DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
}
|
2013-10-08 11:48:20 -07:00
|
|
|
mContext = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
if (mDocumentMgr) {
|
|
|
|
mDocumentMgr->Pop(TF_POPF_ALL);
|
2013-10-08 11:48:20 -07:00
|
|
|
mDocumentMgr = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2013-10-08 11:48:20 -07:00
|
|
|
mSink = nullptr;
|
2013-01-07 07:18:11 -08:00
|
|
|
mWidget = nullptr;
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::Destroy() succeeded", this));
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::QueryInterface(REFIID riid,
|
|
|
|
void** ppv)
|
|
|
|
{
|
2013-10-08 11:48:20 -07:00
|
|
|
*ppv=nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
if ( (IID_IUnknown == riid) || (IID_ITextStoreACP == riid) ) {
|
|
|
|
*ppv = static_cast<ITextStoreACP*>(this);
|
|
|
|
} else if (IID_ITfContextOwnerCompositionSink == riid) {
|
|
|
|
*ppv = static_cast<ITfContextOwnerCompositionSink*>(this);
|
2014-01-30 18:17:25 -08:00
|
|
|
} else if (IID_ITfActiveLanguageProfileNotifySink == riid) {
|
|
|
|
*ppv = static_cast<ITfActiveLanguageProfileNotifySink*>(this);
|
2014-01-13 18:01:00 -08:00
|
|
|
} else if (IID_ITfInputProcessorProfileActivationSink == riid) {
|
|
|
|
*ppv = static_cast<ITfInputProcessorProfileActivationSink*>(this);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
if (*ppv) {
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::QueryInterface() FAILED, riid=%s",
|
|
|
|
this, GetRIIDNameStr(riid).get()));
|
2009-02-10 12:56:51 -08:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) nsTextStore::AddRef()
|
|
|
|
{
|
|
|
|
return ++mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) nsTextStore::Release()
|
|
|
|
{
|
|
|
|
--mRefCnt;
|
|
|
|
if (0 != mRefCnt)
|
|
|
|
return mRefCnt;
|
|
|
|
delete this;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::AdviseSink(REFIID riid,
|
|
|
|
IUnknown *punk,
|
|
|
|
DWORD dwMask)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::AdviseSink(riid=%s, punk=0x%p, dwMask=%s), "
|
|
|
|
"mSink=0x%p, mSinkMask=%s",
|
|
|
|
this, GetRIIDNameStr(riid).get(), punk, GetSinkMaskNameStr(dwMask).get(),
|
2012-09-14 07:13:46 -07:00
|
|
|
mSink.get(), GetSinkMaskNameStr(mSinkMask).get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (!punk) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to the null punk",
|
|
|
|
this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IID_ITextStoreACPSink != riid) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to "
|
|
|
|
"unsupported interface", this));
|
|
|
|
return E_INVALIDARG; // means unsupported interface.
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
if (!mSink) {
|
|
|
|
// Install sink
|
|
|
|
punk->QueryInterface(IID_ITextStoreACPSink, getter_AddRefs(mSink));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!mSink) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to "
|
|
|
|
"punk not having the interface", this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
} else {
|
|
|
|
// If sink is already installed we check to see if they are the same
|
|
|
|
// Get IUnknown from both sides for comparison
|
|
|
|
nsRefPtr<IUnknown> comparison1, comparison2;
|
|
|
|
punk->QueryInterface(IID_IUnknown, getter_AddRefs(comparison1));
|
|
|
|
mSink->QueryInterface(IID_IUnknown, getter_AddRefs(comparison2));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (comparison1 != comparison2) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::AdviseSink() FAILED due to "
|
|
|
|
"the sink being different from the stored sink", this));
|
2009-02-10 12:56:51 -08:00
|
|
|
return CONNECT_E_ADVISELIMIT;
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
// Update mask either for a new sink or an existing sink
|
|
|
|
mSinkMask = dwMask;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::UnadviseSink(IUnknown *punk)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::UnadviseSink(punk=0x%p), mSink=0x%p",
|
2012-09-14 07:13:46 -07:00
|
|
|
this, punk, mSink.get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (!punk) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::UnadviseSink() FAILED due to the null punk",
|
|
|
|
this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
if (!mSink) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::UnadviseSink() FAILED due to "
|
|
|
|
"any sink not stored", this));
|
|
|
|
return CONNECT_E_NOCONNECTION;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
// Get IUnknown from both sides for comparison
|
|
|
|
nsRefPtr<IUnknown> comparison1, comparison2;
|
|
|
|
punk->QueryInterface(IID_IUnknown, getter_AddRefs(comparison1));
|
|
|
|
mSink->QueryInterface(IID_IUnknown, getter_AddRefs(comparison2));
|
|
|
|
// Unadvise only if sinks are the same
|
2012-09-11 16:53:12 -07:00
|
|
|
if (comparison1 != comparison2) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::UnadviseSink() FAILED due to "
|
|
|
|
"the sink being different from the stored sink", this));
|
|
|
|
return CONNECT_E_NOCONNECTION;
|
|
|
|
}
|
2013-10-08 11:48:20 -07:00
|
|
|
mSink = nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
mSinkMask = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::RequestLock(DWORD dwLockFlags,
|
|
|
|
HRESULT *phrSession)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock(dwLockFlags=%s, phrSession=0x%p), "
|
|
|
|
"mLock=%s", this, GetLockFlagNameStr(dwLockFlags).get(), phrSession,
|
|
|
|
GetLockFlagNameStr(mLock).get()));
|
|
|
|
|
|
|
|
if (!mSink) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock() FAILED due to "
|
|
|
|
"any sink not stored", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if (!phrSession) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock() FAILED due to "
|
|
|
|
"null phrSession", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mLock) {
|
2009-02-10 12:56:51 -08:00
|
|
|
// put on lock
|
|
|
|
mLock = dwLockFlags & (~TS_LF_SYNC);
|
2014-01-31 03:23:36 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p Locking (%s) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
|
|
|
|
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
|
|
this, GetLockFlagNameStr(mLock).get()));
|
2009-02-10 12:56:51 -08:00
|
|
|
*phrSession = mSink->OnLockGranted(mLock);
|
2013-03-12 20:01:29 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p Unlocked (%s) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
|
|
|
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
|
|
|
|
this, GetLockFlagNameStr(mLock).get()));
|
2014-01-30 18:17:24 -08:00
|
|
|
DidLockGranted();
|
2009-02-10 12:56:51 -08:00
|
|
|
while (mLockQueued) {
|
|
|
|
mLock = mLockQueued;
|
|
|
|
mLockQueued = 0;
|
2013-03-12 20:01:29 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p Locking for the request in the queue (%s) >>>>>>>>>>>>>>"
|
|
|
|
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
2012-09-11 16:53:12 -07:00
|
|
|
this, GetLockFlagNameStr(mLock).get()));
|
2009-02-10 12:56:51 -08:00
|
|
|
mSink->OnLockGranted(mLock);
|
2013-03-12 20:01:29 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p Unlocked (%s) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
|
|
|
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<",
|
|
|
|
this, GetLockFlagNameStr(mLock).get()));
|
2014-01-30 18:17:24 -08:00
|
|
|
DidLockGranted();
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2014-02-04 23:36:17 -08:00
|
|
|
|
|
|
|
// The document is now completely unlocked.
|
2009-02-10 12:56:51 -08:00
|
|
|
mLock = 0;
|
2014-02-04 23:36:17 -08:00
|
|
|
|
|
|
|
if (mPendingOnLayoutChange) {
|
|
|
|
mPendingOnLayoutChange = false;
|
|
|
|
if (mSink) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock(), "
|
|
|
|
"calling ITextStoreACPSink::OnLayoutChange()...", this));
|
|
|
|
mSink->OnLayoutChange(TS_LC_CHANGE, TEXTSTORE_DEFAULT_VIEW);
|
|
|
|
}
|
|
|
|
// The layout change caused by composition string change should cause
|
|
|
|
// calling ITfContextOwnerServices::OnLayoutChange() too.
|
|
|
|
if (mContext) {
|
|
|
|
nsRefPtr<ITfContextOwnerServices> service;
|
|
|
|
mContext->QueryInterface(IID_ITfContextOwnerServices,
|
|
|
|
getter_AddRefs(service));
|
|
|
|
if (service) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock(), "
|
|
|
|
"calling ITfContextOwnerServices::OnLayoutChange()...",
|
|
|
|
this));
|
|
|
|
service->OnLayoutChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPendingOnSelectionChange) {
|
|
|
|
mPendingOnSelectionChange = false;
|
|
|
|
if (mSink) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock(), "
|
|
|
|
"calling ITextStoreACPSink::OnSelectionChange()...", this));
|
|
|
|
mSink->OnSelectionChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-31 03:23:36 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2012-09-11 16:53:12 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RequestLock() succeeded: *phrSession=%s",
|
|
|
|
this, GetTextStoreReturnValueName(*phrSession)));
|
|
|
|
return S_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
// only time when reentrant lock is allowed is when caller holds a
|
|
|
|
// read-only lock and is requesting an async write lock
|
|
|
|
if (IsReadLocked() && !IsReadWriteLocked() && IsReadWriteLock(dwLockFlags) &&
|
|
|
|
!(dwLockFlags & TS_LF_SYNC)) {
|
|
|
|
*phrSession = TS_S_ASYNC;
|
|
|
|
mLockQueued = dwLockFlags & (~TS_LF_SYNC);
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock() stores the request in the "
|
|
|
|
"queue, *phrSession=TS_S_ASYNC", this));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// no more locks allowed
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RequestLock() didn't allow to lock, "
|
|
|
|
"*phrSession=TS_E_SYNCHRONOUS", this));
|
|
|
|
*phrSession = TS_E_SYNCHRONOUS;
|
|
|
|
return E_FAIL;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2014-01-30 18:17:24 -08:00
|
|
|
void
|
|
|
|
nsTextStore::DidLockGranted()
|
|
|
|
{
|
|
|
|
if (mNativeCaretIsCreated) {
|
|
|
|
::DestroyCaret();
|
|
|
|
mNativeCaretIsCreated = false;
|
|
|
|
}
|
|
|
|
if (IsReadWriteLocked()) {
|
|
|
|
FlushPendingActions();
|
|
|
|
}
|
2014-02-04 23:36:17 -08:00
|
|
|
|
|
|
|
// If the widget has gone, we don't need to notify anything.
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
mPendingOnSelectionChange = false;
|
|
|
|
mPendingOnLayoutChange = false;
|
|
|
|
}
|
2014-01-30 18:17:24 -08:00
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
void
|
|
|
|
nsTextStore::FlushPendingActions()
|
|
|
|
{
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
mPendingActions.Clear();
|
2013-03-12 20:01:30 -07:00
|
|
|
mContent.Clear();
|
2014-02-04 23:36:17 -08:00
|
|
|
mPendingOnSelectionChange = false;
|
|
|
|
mPendingOnLayoutChange = false;
|
2013-03-12 20:01:29 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
mContent.Clear();
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
nsRefPtr<nsWindowBase> kungFuDeathGrip(mWidget);
|
|
|
|
for (uint32_t i = 0; i < mPendingActions.Length(); i++) {
|
|
|
|
PendingAction& action = mPendingActions[i];
|
|
|
|
switch (action.mType) {
|
|
|
|
case PendingAction::COMPOSITION_START: {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions() "
|
|
|
|
"flushing COMPOSITION_START={ mSelectionStart=%d, "
|
|
|
|
"mSelectionLength=%d }",
|
|
|
|
this, action.mSelectionStart, action.mSelectionLength));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mComposition.mLastData.IsEmpty());
|
|
|
|
|
|
|
|
// Select composition range so the new composition replaces the range
|
2013-10-01 00:23:01 -07:00
|
|
|
WidgetSelectionEvent selectionSet(true, NS_SELECTION_SET, mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(selectionSet);
|
|
|
|
selectionSet.mOffset = static_cast<uint32_t>(action.mSelectionStart);
|
|
|
|
selectionSet.mLength = static_cast<uint32_t>(action.mSelectionLength);
|
|
|
|
selectionSet.mReversed = false;
|
|
|
|
mWidget->DispatchWindowEvent(&selectionSet);
|
|
|
|
if (!selectionSet.mSucceeded) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions() "
|
|
|
|
"FAILED due to NS_SELECTION_SET failure", this));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions() "
|
|
|
|
"dispatching compositionstart event...", this));
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent compositionStart(true, NS_COMPOSITION_START,
|
|
|
|
mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(compositionStart);
|
|
|
|
mWidget->DispatchWindowEvent(&compositionStart);
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PendingAction::COMPOSITION_UPDATE: {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions() "
|
|
|
|
"flushing COMPOSITION_UPDATE={ mData=\"%s\", "
|
2014-03-04 05:48:27 -08:00
|
|
|
"mRanges=0x%p, mRanges->Length()=%d }",
|
2014-03-10 06:32:05 -07:00
|
|
|
this, NS_ConvertUTF16toUTF8(action.mData).get(), action.mRanges.get(),
|
2014-03-04 05:48:27 -08:00
|
|
|
action.mRanges ? action.mRanges->Length() : 0));
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2014-03-04 05:48:27 -08:00
|
|
|
if (!action.mRanges) {
|
|
|
|
NS_WARNING("How does this case occur?");
|
|
|
|
action.mRanges = new TextRangeArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust offsets in the ranges for XP linefeed character (only \n).
|
|
|
|
// XXX Following code is the safest approach. However, it wastes
|
|
|
|
// a little performance. For ensuring the clauses do not
|
|
|
|
// overlap each other, we should redesign TextRange later.
|
|
|
|
for (uint32_t i = 0; i < action.mRanges->Length(); ++i) {
|
|
|
|
TextRange& range = action.mRanges->ElementAt(i);
|
|
|
|
TextRange nativeRange = range;
|
|
|
|
if (nativeRange.mStartOffset > 0) {
|
|
|
|
nsAutoString preText(
|
|
|
|
Substring(action.mData, 0, nativeRange.mStartOffset));
|
|
|
|
preText.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
|
|
|
|
NS_LITERAL_STRING("\n"));
|
|
|
|
range.mStartOffset = preText.Length();
|
|
|
|
}
|
|
|
|
if (nativeRange.Length() == 0) {
|
|
|
|
range.mEndOffset = range.mStartOffset;
|
|
|
|
} else {
|
|
|
|
nsAutoString clause(
|
|
|
|
Substring(action.mData,
|
|
|
|
nativeRange.mStartOffset, nativeRange.Length()));
|
|
|
|
clause.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
|
|
|
|
NS_LITERAL_STRING("\n"));
|
|
|
|
range.mEndOffset = range.mStartOffset + clause.Length();
|
2013-03-12 20:01:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
action.mData.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
|
|
|
|
NS_LITERAL_STRING("\n"));
|
|
|
|
|
|
|
|
if (action.mData != mComposition.mLastData) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions(), "
|
|
|
|
"dispatching compositionupdate event...", this));
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent compositionUpdate(true, NS_COMPOSITION_UPDATE,
|
|
|
|
mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(compositionUpdate);
|
|
|
|
compositionUpdate.data = action.mData;
|
|
|
|
mComposition.mLastData = compositionUpdate.data;
|
|
|
|
mWidget->DispatchWindowEvent(&compositionUpdate);
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(action.mData == mComposition.mLastData);
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions(), "
|
|
|
|
"dispatching text event...", this));
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent textEvent(true, NS_TEXT_TEXT, mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(textEvent);
|
|
|
|
textEvent.theText = mComposition.mLastData;
|
2014-03-04 05:48:27 -08:00
|
|
|
if (action.mRanges->IsEmpty()) {
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRange wholeRange;
|
2013-03-12 20:01:29 -07:00
|
|
|
wholeRange.mStartOffset = 0;
|
|
|
|
wholeRange.mEndOffset = textEvent.theText.Length();
|
|
|
|
wholeRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
2014-03-04 05:48:27 -08:00
|
|
|
action.mRanges->AppendElement(wholeRange);
|
2013-03-12 20:01:29 -07:00
|
|
|
}
|
2014-03-04 05:48:27 -08:00
|
|
|
textEvent.mRanges = action.mRanges;
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->DispatchWindowEvent(&textEvent);
|
|
|
|
// Be aware, the mWidget might already have been destroyed.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PendingAction::COMPOSITION_END: {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions() "
|
|
|
|
"flushing COMPOSITION_END={ mData=\"%s\" }",
|
|
|
|
this, NS_ConvertUTF16toUTF8(action.mData).get()));
|
|
|
|
|
|
|
|
action.mData.ReplaceSubstring(NS_LITERAL_STRING("\r\n"),
|
|
|
|
NS_LITERAL_STRING("\n"));
|
|
|
|
if (action.mData != mComposition.mLastData) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions(), "
|
|
|
|
"dispatching compositionupdate event...", this));
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent compositionUpdate(true, NS_COMPOSITION_UPDATE,
|
|
|
|
mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(compositionUpdate);
|
|
|
|
compositionUpdate.data = action.mData;
|
|
|
|
mComposition.mLastData = compositionUpdate.data;
|
|
|
|
mWidget->DispatchWindowEvent(&compositionUpdate);
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(action.mData == mComposition.mLastData);
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions(), "
|
|
|
|
"dispatching text event...", this));
|
2013-10-01 00:22:59 -07:00
|
|
|
WidgetTextEvent textEvent(true, NS_TEXT_TEXT, mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(textEvent);
|
|
|
|
textEvent.theText = mComposition.mLastData;
|
|
|
|
mWidget->DispatchWindowEvent(&textEvent);
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions(), "
|
|
|
|
"dispatching compositionend event...", this));
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetCompositionEvent compositionEnd(true, NS_COMPOSITION_END,
|
|
|
|
mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
compositionEnd.data = mComposition.mLastData;
|
|
|
|
mWidget->InitEvent(compositionEnd);
|
|
|
|
mWidget->DispatchWindowEvent(&compositionEnd);
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mComposition.mLastData.Truncate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PendingAction::SELECTION_SET: {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions() "
|
|
|
|
"flushing SELECTION_SET={ mSelectionStart=%d, "
|
|
|
|
"mSelectionLength=%d, mSelectionReversed=%s }",
|
|
|
|
this, action.mSelectionStart, action.mSelectionLength,
|
|
|
|
GetBoolName(action.mSelectionReversed)));
|
|
|
|
|
2013-10-01 00:23:01 -07:00
|
|
|
WidgetSelectionEvent selectionSet(true, NS_SELECTION_SET, mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
selectionSet.mOffset =
|
|
|
|
static_cast<uint32_t>(action.mSelectionStart);
|
|
|
|
selectionSet.mLength =
|
|
|
|
static_cast<uint32_t>(action.mSelectionLength);
|
|
|
|
selectionSet.mReversed = action.mSelectionReversed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("unexpected action type");
|
2013-03-12 20:01:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mWidget && !mWidget->Destroyed()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::FlushPendingActions(), "
|
|
|
|
"qutting since the mWidget has gone", this));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mPendingActions.Clear();
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetStatus(TS_STATUS *pdcs)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetStatus(pdcs=0x%p)", this, pdcs));
|
|
|
|
|
|
|
|
if (!pdcs) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetStatus() FAILED due to null pdcs", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
pdcs->dwDynamicFlags = 0;
|
|
|
|
// we use a "flat" text model for TSF support so no hidden text
|
|
|
|
pdcs->dwStaticFlags = TS_SS_NOHIDDENTEXT;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::QueryInsert(LONG acpTestStart,
|
|
|
|
LONG acpTestEnd,
|
|
|
|
ULONG cch,
|
|
|
|
LONG *pacpResultStart,
|
|
|
|
LONG *pacpResultEnd)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2012-09-11 16:53:12 -07:00
|
|
|
("TSF: 0x%p nsTextStore::QueryInsert(acpTestStart=%ld, "
|
|
|
|
"acpTestEnd=%ld, cch=%lu, pacpResultStart=0x%p, pacpResultEnd=0x%p)",
|
|
|
|
this, acpTestStart, acpTestEnd, cch, acpTestStart, acpTestEnd));
|
|
|
|
|
|
|
|
if (!pacpResultStart || !pacpResultEnd) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::QueryInsert() FAILED due to "
|
|
|
|
"the null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acpTestStart < 0 || acpTestStart > acpTestEnd) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::QueryInsert() FAILED due to "
|
|
|
|
"wrong argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// XXX need to adjust to cluster boundary
|
|
|
|
// Assume we are given good offsets for now
|
|
|
|
*pacpResultStart = acpTestStart;
|
|
|
|
*pacpResultEnd = acpTestStart + cch;
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2012-09-11 16:53:12 -07:00
|
|
|
("TSF: 0x%p nsTextStore::QueryInsert() succeeded: "
|
|
|
|
"*pacpResultStart=%ld, *pacpResultEnd=%ld)",
|
|
|
|
this, *pacpResultStart, *pacpResultEnd));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetSelection(ULONG ulIndex,
|
|
|
|
ULONG ulCount,
|
|
|
|
TS_SELECTION_ACP *pSelection,
|
|
|
|
ULONG *pcFetched)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetSelection(ulIndex=%lu, ulCount=%lu, "
|
|
|
|
"pSelection=0x%p, pcFetched=0x%p)",
|
|
|
|
this, ulIndex, ulCount, pSelection, pcFetched));
|
|
|
|
|
|
|
|
if (!IsReadLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetSelection() FAILED due to not locked",
|
|
|
|
this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
if (!ulCount || !pSelection || !pcFetched) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetSelection() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
*pcFetched = 0;
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (ulIndex != static_cast<ULONG>(TS_DEFAULT_SELECTION) &&
|
|
|
|
ulIndex != 0) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetSelection() FAILED due to "
|
|
|
|
"unsupported selection", this));
|
|
|
|
return TS_E_NOSELECTION;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::GetSelection() FAILED due to "
|
|
|
|
"CurrentSelection() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2013-03-12 20:01:29 -07:00
|
|
|
*pSelection = currentSel.ACP();
|
2012-09-11 16:53:12 -07:00
|
|
|
*pcFetched = 1;
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetSelection() succeeded", this));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
nsTextStore::Content&
|
|
|
|
nsTextStore::CurrentContent()
|
|
|
|
{
|
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
|
|
|
mContent.Clear();
|
|
|
|
return mContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mContent.IsInitialized()) {
|
|
|
|
MOZ_ASSERT(mWidget && !mWidget->Destroyed());
|
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent queryText(true, NS_QUERY_TEXT_CONTENT, mWidget);
|
2013-03-12 20:01:30 -07:00
|
|
|
queryText.InitForQueryTextContent(0, UINT32_MAX);
|
|
|
|
mWidget->InitEvent(queryText);
|
|
|
|
mWidget->DispatchWindowEvent(&queryText);
|
|
|
|
NS_ENSURE_TRUE(queryText.mSucceeded, mContent);
|
|
|
|
|
|
|
|
mContent.Init(queryText.mReply.mString);
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::CurrentContent(): "
|
|
|
|
"mContent={ mText.Length()=%d }",
|
|
|
|
this, mContent.Text().Length()));
|
|
|
|
|
|
|
|
return mContent;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
nsTextStore::Selection&
|
|
|
|
nsTextStore::CurrentSelection()
|
2012-09-11 16:53:12 -07:00
|
|
|
{
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mSelection.IsDirty()) {
|
|
|
|
// If the window has never been available, we should crash since working
|
|
|
|
// with broken values may make TIP confused.
|
|
|
|
if (!mWidget || mWidget->Destroyed()) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent querySelection(true, NS_QUERY_SELECTED_TEXT,
|
|
|
|
mWidget);
|
2013-03-12 20:01:29 -07:00
|
|
|
mWidget->InitEvent(querySelection);
|
|
|
|
mWidget->DispatchWindowEvent(&querySelection);
|
|
|
|
NS_ENSURE_TRUE(querySelection.mSucceeded, mSelection);
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
mSelection.SetSelection(querySelection.mReply.mOffset,
|
|
|
|
querySelection.mReply.mString.Length(),
|
|
|
|
querySelection.mReply.mReversed);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::CurrentSelection(): "
|
|
|
|
"acpStart=%d, acpEnd=%d (length=%d), reverted=%s",
|
|
|
|
this, mSelection.StartOffset(), mSelection.EndOffset(),
|
|
|
|
mSelection.Length(),
|
|
|
|
GetBoolName(mSelection.IsReversed())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
return mSelection;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2009-02-23 00:56:33 -08:00
|
|
|
static HRESULT
|
|
|
|
GetRangeExtent(ITfRange* aRange, LONG* aStart, LONG* aLength)
|
|
|
|
{
|
|
|
|
nsRefPtr<ITfRangeACP> rangeACP;
|
|
|
|
aRange->QueryInterface(IID_ITfRangeACP, getter_AddRefs(rangeACP));
|
|
|
|
NS_ENSURE_TRUE(rangeACP, E_FAIL);
|
|
|
|
return rangeACP->GetExtent(aStart, aLength);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t
|
2009-02-23 00:56:33 -08:00
|
|
|
GetGeckoSelectionValue(TF_DISPLAYATTRIBUTE &aDisplayAttr)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t result;
|
2009-02-23 00:56:33 -08:00
|
|
|
switch (aDisplayAttr.bAttr) {
|
|
|
|
case TF_ATTR_TARGET_CONVERTED:
|
|
|
|
result = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
|
|
|
break;
|
|
|
|
case TF_ATTR_CONVERTED:
|
|
|
|
result = NS_TEXTRANGE_CONVERTEDTEXT;
|
|
|
|
break;
|
|
|
|
case TF_ATTR_TARGET_NOTCONVERTED:
|
|
|
|
result = NS_TEXTRANGE_SELECTEDRAWTEXT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_TEXTRANGE_RAWINPUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
nsTextStore::GetDisplayAttribute(ITfProperty* aAttrProperty,
|
|
|
|
ITfRange* aRange,
|
|
|
|
TF_DISPLAYATTRIBUTE* aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aAttrProperty, E_FAIL);
|
|
|
|
NS_ENSURE_TRUE(aRange, E_FAIL);
|
|
|
|
NS_ENSURE_TRUE(aResult, E_FAIL);
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
2012-09-11 16:53:12 -07:00
|
|
|
if (PR_LOG_TEST(sTextStoreLog, PR_LOG_DEBUG)) {
|
|
|
|
LONG start = 0, length = 0;
|
|
|
|
hr = GetRangeExtent(aRange, &start, &length);
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute(): "
|
|
|
|
"GetDisplayAttribute range=%ld-%ld (hr=%s)",
|
2013-03-12 20:01:29 -07:00
|
|
|
this, start - mComposition.mStart,
|
|
|
|
start - mComposition.mStart + length,
|
2012-09-11 16:53:12 -07:00
|
|
|
GetCommonReturnValueName(hr)));
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
VARIANT propValue;
|
|
|
|
::VariantInit(&propValue);
|
|
|
|
hr = aAttrProperty->GetValue(TfEditCookie(mEditCookie), aRange, &propValue);
|
|
|
|
if (FAILED(hr)) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to "
|
|
|
|
"ITfProperty::GetValue() failed", this));
|
2009-02-23 00:56:33 -08:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
if (VT_I4 != propValue.vt) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to "
|
|
|
|
"ITfProperty::GetValue() returns non-VT_I4 value", this));
|
2009-02-23 00:56:33 -08:00
|
|
|
::VariantClear(&propValue);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(sCategoryMgr, E_FAIL);
|
|
|
|
GUID guid;
|
|
|
|
hr = sCategoryMgr->GetGUID(DWORD(propValue.lVal), &guid);
|
|
|
|
::VariantClear(&propValue);
|
|
|
|
if (FAILED(hr)) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to "
|
|
|
|
"ITfCategoryMgr::GetGUID() failed", this));
|
2009-02-23 00:56:33 -08:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(sDisplayAttrMgr, E_FAIL);
|
|
|
|
nsRefPtr<ITfDisplayAttributeInfo> info;
|
|
|
|
hr = sDisplayAttrMgr->GetDisplayAttributeInfo(guid, getter_AddRefs(info),
|
2013-10-08 11:48:20 -07:00
|
|
|
nullptr);
|
2009-02-23 00:56:33 -08:00
|
|
|
if (FAILED(hr) || !info) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to "
|
|
|
|
"ITfDisplayAttributeMgr::GetDisplayAttributeInfo() failed", this));
|
2009-02-23 00:56:33 -08:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = info->GetAttributeInfo(aResult);
|
|
|
|
if (FAILED(hr)) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute() FAILED due to "
|
|
|
|
"ITfDisplayAttributeInfo::GetAttributeInfo() failed", this));
|
2009-02-23 00:56:33 -08:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::GetDisplayAttribute() succeeded: "
|
2012-09-11 16:53:12 -07:00
|
|
|
"Result={ %s }", this, GetDisplayAttrStr(*aResult).get()));
|
2009-02-23 00:56:33 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-08 01:39:03 -08:00
|
|
|
HRESULT
|
2013-03-12 20:01:30 -07:00
|
|
|
nsTextStore::RestartCompositionIfNecessary(ITfRange* aRangeNew)
|
2009-03-08 01:39:03 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary("
|
|
|
|
"aRangeNew=0x%p), mComposition.mView=0x%p",
|
2013-03-12 20:01:29 -07:00
|
|
|
this, aRangeNew, mComposition.mView.get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (!mComposition.IsComposing()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED "
|
|
|
|
"due to no composition view", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2009-03-08 01:39:03 -08:00
|
|
|
|
|
|
|
HRESULT hr;
|
2013-03-12 20:01:29 -07:00
|
|
|
nsRefPtr<ITfCompositionView> pComposition(mComposition.mView);
|
2009-03-08 01:39:03 -08:00
|
|
|
nsRefPtr<ITfRange> composingRange(aRangeNew);
|
|
|
|
if (!composingRange) {
|
|
|
|
hr = pComposition->GetRange(getter_AddRefs(composingRange));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED "
|
|
|
|
"due to pComposition->GetRange() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
2009-03-08 01:39:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get starting offset of the composition
|
|
|
|
LONG compStart = 0, compLength = 0;
|
|
|
|
hr = GetRangeExtent(composingRange, &compStart, &compLength);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() FAILED "
|
|
|
|
"due to GetRangeExtent() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary(), "
|
|
|
|
"range=%ld-%ld, mComposition={ mStart=%ld, mString.Length()=%lu }",
|
2013-03-12 20:01:29 -07:00
|
|
|
this, compStart, compStart + compLength, mComposition.mStart,
|
|
|
|
mComposition.mString.Length()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mComposition.mStart != compStart ||
|
|
|
|
mComposition.mString.Length() != (ULONG)compLength) {
|
2009-03-08 01:39:03 -08:00
|
|
|
// If the queried composition length is different from the length
|
|
|
|
// of our composition string, OnUpdateComposition is being called
|
|
|
|
// because a part of the original composition was committed.
|
|
|
|
// Reflect that by committing existing composition and starting
|
2013-03-12 20:01:30 -07:00
|
|
|
// a new one. RecordCompositionEndAction() followed by
|
|
|
|
// RecordCompositionStartAction() will accomplish this automagically.
|
|
|
|
RecordCompositionEndAction();
|
2013-03-12 20:01:30 -07:00
|
|
|
RecordCompositionStartAction(pComposition, composingRange, true);
|
2009-03-08 01:39:03 -08:00
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RestartCompositionIfNecessary() succeeded",
|
|
|
|
this));
|
2009-03-08 01:39:03 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2009-04-22 20:27:12 -07:00
|
|
|
GetColor(const TF_DA_COLOR &aTSFColor, nscolor &aResult)
|
|
|
|
{
|
|
|
|
switch (aTSFColor.type) {
|
|
|
|
case TF_CT_SYSCOLOR: {
|
|
|
|
DWORD sysColor = ::GetSysColor(aTSFColor.nIndex);
|
|
|
|
aResult = NS_RGB(GetRValue(sysColor), GetGValue(sysColor),
|
|
|
|
GetBValue(sysColor));
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
}
|
|
|
|
case TF_CT_COLORREF:
|
|
|
|
aResult = NS_RGB(GetRValue(aTSFColor.cr), GetGValue(aTSFColor.cr),
|
|
|
|
GetBValue(aTSFColor.cr));
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
case TF_CT_NONE:
|
|
|
|
default:
|
2011-10-01 19:16:19 -07:00
|
|
|
return false;
|
2009-04-22 20:27:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-22 08:56:38 -07:00
|
|
|
GetLineStyle(TF_DA_LINESTYLE aTSFLineStyle, uint8_t &aTextRangeLineStyle)
|
2009-04-22 20:27:12 -07:00
|
|
|
{
|
|
|
|
switch (aTSFLineStyle) {
|
|
|
|
case TF_LS_NONE:
|
2013-10-01 00:22:59 -07:00
|
|
|
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_NONE;
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
case TF_LS_SOLID:
|
2013-10-01 00:22:59 -07:00
|
|
|
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_SOLID;
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
case TF_LS_DOT:
|
2013-10-01 00:22:59 -07:00
|
|
|
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_DOTTED;
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
case TF_LS_DASH:
|
2013-10-01 00:22:59 -07:00
|
|
|
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_DASHED;
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
case TF_LS_SQUIGGLE:
|
2013-10-01 00:22:59 -07:00
|
|
|
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_WAVY;
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-04-22 20:27:12 -07:00
|
|
|
default:
|
2011-10-01 19:16:19 -07:00
|
|
|
return false;
|
2009-04-22 20:27:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
HRESULT
|
2013-03-12 20:01:29 -07:00
|
|
|
nsTextStore::RecordCompositionUpdateAction()
|
2009-02-23 00:56:33 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction(), "
|
2013-03-12 20:01:29 -07:00
|
|
|
"mComposition={ mView=0x%p, mString=\"%s\" }",
|
|
|
|
this, mComposition.mView.get(),
|
|
|
|
NS_ConvertUTF16toUTF8(mComposition.mString).get()));
|
2009-02-23 00:56:33 -08:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (!mComposition.IsComposing()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED "
|
2012-09-11 16:53:12 -07:00
|
|
|
"due to no composition view", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
|
|
|
|
// Getting display attributes is *really* complicated!
|
|
|
|
// We first get the context and the property objects to query for
|
|
|
|
// attributes, but since a big range can have a variety of values for
|
|
|
|
// the attribute, we have to find out all the ranges that have distinct
|
|
|
|
// attribute values. Then we query for what the value represents through
|
2013-10-01 00:22:59 -07:00
|
|
|
// the display attribute manager and translate that to TextRange to be
|
2009-02-23 00:56:33 -08:00
|
|
|
// sent in NS_TEXT_TEXT
|
|
|
|
|
|
|
|
nsRefPtr<ITfProperty> attrPropetry;
|
|
|
|
HRESULT hr = mContext->GetProperty(GUID_PROP_ATTRIBUTE,
|
|
|
|
getter_AddRefs(attrPropetry));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr) || !attrPropetry) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED "
|
2012-09-11 16:53:12 -07:00
|
|
|
"due to mContext->GetProperty() failure", this));
|
|
|
|
return FAILED(hr) ? hr : E_FAIL;
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfRange> composingRange;
|
2013-03-12 20:01:29 -07:00
|
|
|
hr = mComposition.mView->GetRange(getter_AddRefs(composingRange));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() "
|
2013-03-12 20:01:29 -07:00
|
|
|
"FAILED due to mComposition.mView->GetRange() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
|
|
|
|
nsRefPtr<IEnumTfRanges> enumRanges;
|
|
|
|
hr = attrPropetry->EnumRanges(TfEditCookie(mEditCookie),
|
|
|
|
getter_AddRefs(enumRanges), composingRange);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr) || !enumRanges) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED "
|
2012-09-11 16:53:12 -07:00
|
|
|
"due to attrPropetry->EnumRanges() failure", this));
|
|
|
|
return FAILED(hr) ? hr : E_FAIL;
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
// First, put the log of content and selection here.
|
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() FAILED "
|
|
|
|
"due to CurrentSelection() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
PendingAction* action = GetPendingCompositionUpdate();
|
|
|
|
action->mData = mComposition.mString;
|
2014-03-04 05:48:27 -08:00
|
|
|
// The ranges might already have been initialized, however, if this is
|
|
|
|
// called again, that means we need to overwrite the ranges with current
|
2013-03-12 20:01:29 -07:00
|
|
|
// information.
|
2014-03-04 05:48:27 -08:00
|
|
|
action->mRanges->Clear();
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRange newRange;
|
2009-02-23 00:56:33 -08:00
|
|
|
// No matter if we have display attribute info or not,
|
|
|
|
// we always pass in at least one range to NS_TEXT_TEXT
|
|
|
|
newRange.mStartOffset = 0;
|
2013-03-12 20:01:29 -07:00
|
|
|
newRange.mEndOffset = action->mData.Length();
|
2009-02-23 00:56:33 -08:00
|
|
|
newRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
2014-03-04 05:48:27 -08:00
|
|
|
action->mRanges->AppendElement(newRange);
|
2009-02-23 00:56:33 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfRange> range;
|
2013-10-08 11:48:20 -07:00
|
|
|
while (S_OK == enumRanges->Next(1, getter_AddRefs(range), nullptr) && range) {
|
2009-02-23 00:56:33 -08:00
|
|
|
|
|
|
|
LONG start = 0, length = 0;
|
|
|
|
if (FAILED(GetRangeExtent(range, &start, &length)))
|
|
|
|
continue;
|
|
|
|
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRange newRange;
|
2013-03-12 20:01:29 -07:00
|
|
|
newRange.mStartOffset = uint32_t(start - mComposition.mStart);
|
2009-02-23 00:56:33 -08:00
|
|
|
// The end of the last range in the array is
|
|
|
|
// always kept at the end of composition
|
2013-03-12 20:01:29 -07:00
|
|
|
newRange.mEndOffset = mComposition.mString.Length();
|
2009-02-23 00:56:33 -08:00
|
|
|
|
|
|
|
TF_DISPLAYATTRIBUTE attr;
|
|
|
|
hr = GetDisplayAttribute(attrPropetry, range, &attr);
|
2009-04-22 20:27:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
newRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
|
|
|
} else {
|
|
|
|
newRange.mRangeType = GetGeckoSelectionValue(attr);
|
|
|
|
if (GetColor(attr.crText, newRange.mRangeStyle.mForegroundColor)) {
|
|
|
|
newRange.mRangeStyle.mDefinedStyles |=
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRangeStyle::DEFINED_FOREGROUND_COLOR;
|
2009-04-22 20:27:12 -07:00
|
|
|
}
|
|
|
|
if (GetColor(attr.crBk, newRange.mRangeStyle.mBackgroundColor)) {
|
|
|
|
newRange.mRangeStyle.mDefinedStyles |=
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRangeStyle::DEFINED_BACKGROUND_COLOR;
|
2009-04-22 20:27:12 -07:00
|
|
|
}
|
|
|
|
if (GetColor(attr.crLine, newRange.mRangeStyle.mUnderlineColor)) {
|
|
|
|
newRange.mRangeStyle.mDefinedStyles |=
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRangeStyle::DEFINED_UNDERLINE_COLOR;
|
2009-04-22 20:27:12 -07:00
|
|
|
}
|
|
|
|
if (GetLineStyle(attr.lsStyle, newRange.mRangeStyle.mLineStyle)) {
|
|
|
|
newRange.mRangeStyle.mDefinedStyles |=
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRangeStyle::DEFINED_LINESTYLE;
|
2009-04-22 20:27:12 -07:00
|
|
|
newRange.mRangeStyle.mIsBoldLine = attr.fBoldLine != 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
|
2014-03-04 05:48:27 -08:00
|
|
|
TextRange& lastRange = action->mRanges->LastElement();
|
2009-02-23 00:56:33 -08:00
|
|
|
if (lastRange.mStartOffset == newRange.mStartOffset) {
|
|
|
|
// Replace range if last range is the same as this one
|
|
|
|
// So that ranges don't overlap and confuse the editor
|
|
|
|
lastRange = newRange;
|
|
|
|
} else {
|
|
|
|
lastRange.mEndOffset = newRange.mStartOffset;
|
2014-03-04 05:48:27 -08:00
|
|
|
action->mRanges->AppendElement(newRange);
|
2009-02-23 00:56:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 17:45:15 -07:00
|
|
|
// We need to hack for Korean Input System which is Korean standard TIP.
|
|
|
|
// It sets no change style to IME selection (the selection is always only
|
|
|
|
// one). So, the composition string looks like normal (or committed) string.
|
2013-03-12 20:01:29 -07:00
|
|
|
// At this time, current selection range is same as the composition string
|
|
|
|
// range. Other applications set a wide caret which covers the composition
|
|
|
|
// string, however, Gecko doesn't support the wide caret drawing now (Gecko
|
|
|
|
// doesn't support XOR drawing), unfortunately. For now, we should change
|
|
|
|
// the range style to undefined.
|
2014-03-04 05:48:27 -08:00
|
|
|
if (!currentSel.IsCollapsed() && action->mRanges->Length() == 1) {
|
|
|
|
TextRange& range = action->mRanges->ElementAt(0);
|
2013-03-12 20:01:29 -07:00
|
|
|
LONG start = currentSel.MinOffset();
|
|
|
|
LONG end = currentSel.MaxOffset();
|
2013-03-12 20:01:29 -07:00
|
|
|
if ((LONG)range.mStartOffset == start - mComposition.mStart &&
|
|
|
|
(LONG)range.mEndOffset == end - mComposition.mStart &&
|
2009-05-14 17:45:15 -07:00
|
|
|
range.mRangeStyle.IsNoChangeStyle()) {
|
|
|
|
range.mRangeStyle.Clear();
|
|
|
|
// The looks of selected type is better than others.
|
|
|
|
range.mRangeType = NS_TEXTRANGE_SELECTEDRAWTEXT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The caret position has to be collapsed.
|
2013-03-12 20:01:29 -07:00
|
|
|
LONG caretPosition = currentSel.MaxOffset();
|
2013-03-12 20:01:29 -07:00
|
|
|
caretPosition -= mComposition.mStart;
|
2013-10-01 00:22:59 -07:00
|
|
|
TextRange caretRange;
|
2012-08-22 08:56:38 -07:00
|
|
|
caretRange.mStartOffset = caretRange.mEndOffset = uint32_t(caretPosition);
|
2009-05-14 17:45:15 -07:00
|
|
|
caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
2014-03-04 05:48:27 -08:00
|
|
|
action->mRanges->AppendElement(caretRange);
|
2009-05-14 17:45:15 -07:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionUpdateAction() "
|
2012-09-11 16:53:12 -07:00
|
|
|
"succeeded", this));
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
return S_OK;
|
2009-02-23 00:56:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
nsTextStore::SetSelectionInternal(const TS_SELECTION_ACP* pSelection,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aDispatchTextEvent)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::SetSelectionInternal(pSelection={ "
|
|
|
|
"acpStart=%ld, acpEnd=%ld, style={ ase=%s, fInterimChar=%s} }, "
|
|
|
|
"aDispatchTextEvent=%s), mComposition.IsComposing()=%s",
|
2012-09-11 16:53:12 -07:00
|
|
|
this, pSelection->acpStart, pSelection->acpEnd,
|
2014-01-31 03:23:36 -08:00
|
|
|
GetActiveSelEndName(pSelection->style.ase),
|
|
|
|
GetBoolName(pSelection->style.fInterimChar),
|
2012-09-11 16:53:12 -07:00
|
|
|
GetBoolName(aDispatchTextEvent),
|
2013-03-12 20:01:29 -07:00
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
MOZ_ASSERT(IsReadWriteLocked());
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to "
|
|
|
|
"CurrentSelection() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mComposition.IsComposing()) {
|
2009-03-08 01:39:03 -08:00
|
|
|
if (aDispatchTextEvent) {
|
2013-03-12 20:01:30 -07:00
|
|
|
HRESULT hr = RestartCompositionIfNecessary();
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to "
|
2013-03-12 20:01:30 -07:00
|
|
|
"RestartCompositionIfNecessary() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
2013-03-12 20:01:29 -07:00
|
|
|
if (pSelection->acpStart < mComposition.mStart ||
|
2013-03-12 20:01:30 -07:00
|
|
|
pSelection->acpEnd > mComposition.EndOffset()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to "
|
|
|
|
"the selection being out of the composition string", this));
|
|
|
|
return TS_E_INVALIDPOS;
|
2009-03-08 01:39:03 -08:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
// Emulate selection during compositions
|
2013-03-12 20:01:29 -07:00
|
|
|
currentSel.SetSelection(*pSelection);
|
2009-02-23 00:56:33 -08:00
|
|
|
if (aDispatchTextEvent) {
|
2013-03-12 20:01:29 -07:00
|
|
|
HRESULT hr = RecordCompositionUpdateAction();
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelectionInternal() FAILED due to "
|
2013-03-12 20:01:29 -07:00
|
|
|
"RecordCompositionUpdateAction() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
2009-02-23 00:56:33 -08:00
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
return S_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2013-03-12 20:01:29 -07:00
|
|
|
|
|
|
|
PendingAction* action = mPendingActions.AppendElement();
|
|
|
|
action->mType = PendingAction::SELECTION_SET;
|
|
|
|
action->mSelectionStart = pSelection->acpStart;
|
|
|
|
action->mSelectionLength = pSelection->acpEnd - pSelection->acpStart;
|
|
|
|
action->mSelectionReversed = (pSelection->style.ase == TS_AE_START);
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
currentSel.SetSelection(*pSelection);
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::SetSelection(ULONG ulCount,
|
|
|
|
const TS_SELECTION_ACP *pSelection)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::SetSelection(ulCount=%lu, pSelection=%p { "
|
|
|
|
"acpStart=%ld, acpEnd=%ld, style={ ase=%s, fInterimChar=%s } }), "
|
|
|
|
"mComposition.IsComposing()=%s",
|
|
|
|
this, ulCount, pSelection,
|
|
|
|
pSelection ? pSelection->acpStart : 0,
|
|
|
|
pSelection ? pSelection->acpEnd : 0,
|
|
|
|
pSelection ? GetActiveSelEndName(pSelection->style.ase) : "",
|
|
|
|
pSelection ? GetBoolName(pSelection->style.fInterimChar) : "",
|
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (!IsReadWriteLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelection() FAILED due to "
|
|
|
|
"not locked (read-write)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
if (ulCount != 1) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelection() FAILED due to "
|
|
|
|
"trying setting multiple selection", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
if (!pSelection) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelection() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
HRESULT hr = SetSelectionInternal(pSelection, true);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelection() FAILED due to "
|
|
|
|
"SetSelectionInternal() failure", this));
|
|
|
|
} else {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::SetSelection() succeeded", this));
|
|
|
|
}
|
|
|
|
return hr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetText(LONG acpStart,
|
|
|
|
LONG acpEnd,
|
|
|
|
WCHAR *pchPlain,
|
|
|
|
ULONG cchPlainReq,
|
|
|
|
ULONG *pcchPlainOut,
|
|
|
|
TS_RUNINFO *prgRunInfo,
|
|
|
|
ULONG ulRunInfoReq,
|
|
|
|
ULONG *pulRunInfoOut,
|
|
|
|
LONG *pacpNext)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-03-12 20:01:29 -07:00
|
|
|
("TSF: 0x%p nsTextStore::GetText(acpStart=%ld, acpEnd=%ld, pchPlain=0x%p, "
|
|
|
|
"cchPlainReq=%lu, pcchPlainOut=0x%p, prgRunInfo=0x%p, ulRunInfoReq=%lu, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"pulRunInfoOut=0x%p, pacpNext=0x%p), mComposition={ mStart=%ld, "
|
2014-01-31 03:23:36 -08:00
|
|
|
"mString.Length()=%lu, IsComposing()=%s }",
|
2013-03-12 20:01:29 -07:00
|
|
|
this, acpStart, acpEnd, pchPlain, cchPlainReq, pcchPlainOut,
|
|
|
|
prgRunInfo, ulRunInfoReq, pulRunInfoOut, pacpNext,
|
2013-03-12 20:01:30 -07:00
|
|
|
mComposition.mStart, mComposition.mString.Length(),
|
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (!IsReadLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() FAILED due to "
|
|
|
|
"not locked (read)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pcchPlainOut || (!pchPlain && !prgRunInfo) ||
|
|
|
|
!cchPlainReq != !pchPlain || !ulRunInfoReq != !prgRunInfo) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() FAILED due to "
|
|
|
|
"invalid argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acpStart < 0 || acpEnd < -1 || (acpEnd != -1 && acpStart > acpEnd)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() FAILED due to "
|
|
|
|
"invalid position", this));
|
|
|
|
return TS_E_INVALIDPOS;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-10-28 07:05:51 -07:00
|
|
|
// Making sure to null-terminate string just to be on the safe side
|
2009-02-10 12:56:51 -08:00
|
|
|
*pcchPlainOut = 0;
|
2010-08-20 11:19:38 -07:00
|
|
|
if (pchPlain && cchPlainReq) *pchPlain = 0;
|
2009-02-10 12:56:51 -08:00
|
|
|
if (pulRunInfoOut) *pulRunInfoOut = 0;
|
|
|
|
if (pacpNext) *pacpNext = acpStart;
|
|
|
|
if (prgRunInfo && ulRunInfoReq) {
|
|
|
|
prgRunInfo->uCount = 0;
|
|
|
|
prgRunInfo->type = TS_RT_PLAIN;
|
|
|
|
}
|
2013-03-12 20:01:30 -07:00
|
|
|
|
|
|
|
Content& currentContent = CurrentContent();
|
|
|
|
if (!currentContent.IsInitialized()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() FAILED due to "
|
|
|
|
"CurrentContent() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if (currentContent.Text().Length() < static_cast<uint32_t>(acpStart)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() FAILED due to "
|
|
|
|
"acpStart is larger offset than the actual text length", this));
|
|
|
|
return TS_E_INVALIDPOS;
|
|
|
|
}
|
|
|
|
if (acpEnd != -1 &&
|
|
|
|
currentContent.Text().Length() < static_cast<uint32_t>(acpEnd)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() FAILED due to "
|
|
|
|
"acpEnd is larger offset than the actual text length", this));
|
|
|
|
return TS_E_INVALIDPOS;
|
|
|
|
}
|
|
|
|
uint32_t length = (acpEnd == -1) ?
|
|
|
|
currentContent.Text().Length() - static_cast<uint32_t>(acpStart) :
|
|
|
|
static_cast<uint32_t>(acpEnd - acpStart);
|
2009-02-10 12:56:51 -08:00
|
|
|
if (cchPlainReq && cchPlainReq - 1 < length) {
|
|
|
|
length = cchPlainReq - 1;
|
|
|
|
}
|
|
|
|
if (length) {
|
|
|
|
if (pchPlain && cchPlainReq) {
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* startChar =
|
2013-03-12 20:01:30 -07:00
|
|
|
currentContent.Text().BeginReading() + acpStart;
|
|
|
|
memcpy(pchPlain, startChar, length * sizeof(*pchPlain));
|
2010-08-20 11:19:38 -07:00
|
|
|
pchPlain[length] = 0;
|
2009-02-10 12:56:51 -08:00
|
|
|
*pcchPlainOut = length;
|
|
|
|
}
|
|
|
|
if (prgRunInfo && ulRunInfoReq) {
|
|
|
|
prgRunInfo->uCount = length;
|
|
|
|
prgRunInfo->type = TS_RT_PLAIN;
|
|
|
|
if (pulRunInfoOut) *pulRunInfoOut = 1;
|
|
|
|
}
|
|
|
|
if (pacpNext) *pacpNext = acpStart + length;
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetText() succeeded: pcchPlainOut=0x%p, "
|
|
|
|
"*prgRunInfo={ uCount=%lu, type=%s }, *pulRunInfoOut=%lu, "
|
|
|
|
"*pacpNext=%ld)",
|
|
|
|
this, pcchPlainOut, prgRunInfo ? prgRunInfo->uCount : 0,
|
|
|
|
prgRunInfo ? GetTextRunTypeName(prgRunInfo->type) : "N/A",
|
|
|
|
pulRunInfoOut ? pulRunInfoOut : 0, pacpNext ? pacpNext : 0));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::SetText(DWORD dwFlags,
|
|
|
|
LONG acpStart,
|
|
|
|
LONG acpEnd,
|
|
|
|
const WCHAR *pchText,
|
|
|
|
ULONG cch,
|
|
|
|
TS_TEXTCHANGE *pChange)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::SetText(dwFlags=%s, acpStart=%ld, "
|
|
|
|
"acpEnd=%ld, pchText=0x%p \"%s\", cch=%lu, pChange=0x%p), "
|
|
|
|
"mComposition.IsComposing()=%s",
|
2012-09-11 16:53:12 -07:00
|
|
|
this, dwFlags == TS_ST_CORRECTION ? "TS_ST_CORRECTION" :
|
|
|
|
"not-specified",
|
|
|
|
acpStart, acpEnd, pchText,
|
|
|
|
pchText && cch ?
|
|
|
|
NS_ConvertUTF16toUTF8(pchText, cch).get() : "",
|
2013-03-12 20:01:29 -07:00
|
|
|
cch, pChange, GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// Per SDK documentation, and since we don't have better
|
|
|
|
// ways to do this, this method acts as a helper to
|
|
|
|
// call SetSelection followed by InsertTextAtSelection
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!IsReadWriteLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetText() FAILED due to "
|
|
|
|
"not locked (read)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
TS_SELECTION_ACP selection;
|
|
|
|
selection.acpStart = acpStart;
|
|
|
|
selection.acpEnd = acpEnd;
|
|
|
|
selection.style.ase = TS_AE_END;
|
|
|
|
selection.style.fInterimChar = 0;
|
|
|
|
// Set selection to desired range
|
2012-09-11 16:53:12 -07:00
|
|
|
HRESULT hr = SetSelectionInternal(&selection);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetText() FAILED due to "
|
|
|
|
"SetSelectionInternal() failure", this));
|
|
|
|
return hr;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
// Replace just selected text
|
2012-12-30 16:33:49 -08:00
|
|
|
if (!InsertTextAtSelectionInternal(nsDependentSubstring(pchText, cch),
|
2012-09-13 21:51:00 -07:00
|
|
|
pChange)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::SetText() FAILED due to "
|
|
|
|
"InsertTextAtSelectionInternal() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::SetText() succeeded: pChange={ "
|
|
|
|
"acpStart=%ld, acpOldEnd=%ld, acpNewEnd=%ld }",
|
|
|
|
this, pChange ? pChange->acpStart : 0,
|
|
|
|
pChange ? pChange->acpOldEnd : 0, pChange ? pChange->acpNewEnd : 0));
|
|
|
|
return S_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetFormattedText(LONG acpStart,
|
|
|
|
LONG acpEnd,
|
|
|
|
IDataObject **ppDataObject)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetFormattedText() called "
|
|
|
|
"but not supported (E_NOTIMPL)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// no support for formatted text
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetEmbedded(LONG acpPos,
|
|
|
|
REFGUID rguidService,
|
|
|
|
REFIID riid,
|
|
|
|
IUnknown **ppunk)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetEmbedded() called "
|
|
|
|
"but not supported (E_NOTIMPL)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// embedded objects are not supported
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::QueryInsertEmbedded(const GUID *pguidService,
|
|
|
|
const FORMATETC *pFormatEtc,
|
|
|
|
BOOL *pfInsertable)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::QueryInsertEmbedded() called "
|
|
|
|
"but not supported, *pfInsertable=FALSE (S_OK)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// embedded objects are not supported
|
|
|
|
*pfInsertable = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::InsertEmbedded(DWORD dwFlags,
|
|
|
|
LONG acpStart,
|
|
|
|
LONG acpEnd,
|
|
|
|
IDataObject *pDataObject,
|
|
|
|
TS_TEXTCHANGE *pChange)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertEmbedded() called "
|
|
|
|
"but not supported (E_NOTIMPL)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// embedded objects are not supported
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
void
|
|
|
|
nsTextStore::SetInputScope(const nsString& aHTMLInputType)
|
|
|
|
{
|
|
|
|
mInputScopes.Clear();
|
|
|
|
if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html
|
|
|
|
if (aHTMLInputType.EqualsLiteral("url")) {
|
|
|
|
mInputScopes.AppendElement(IS_URL);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("search")) {
|
|
|
|
mInputScopes.AppendElement(IS_SEARCH);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("email")) {
|
|
|
|
mInputScopes.AppendElement(IS_EMAIL_SMTPEMAILADDRESS);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("password")) {
|
|
|
|
mInputScopes.AppendElement(IS_PASSWORD);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("datetime") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("datetime-local")) {
|
|
|
|
mInputScopes.AppendElement(IS_DATE_FULLDATE);
|
|
|
|
mInputScopes.AppendElement(IS_TIME_FULLTIME);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("date") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("month") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("week")) {
|
|
|
|
mInputScopes.AppendElement(IS_DATE_FULLDATE);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("time")) {
|
|
|
|
mInputScopes.AppendElement(IS_TIME_FULLTIME);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("tel")) {
|
|
|
|
mInputScopes.AppendElement(IS_TELEPHONE_FULLTELEPHONENUMBER);
|
|
|
|
mInputScopes.AppendElement(IS_TELEPHONE_LOCALNUMBER);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("number")) {
|
|
|
|
mInputScopes.AppendElement(IS_NUMBER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
nsTextStore::ProcessScopeRequest(DWORD dwFlags,
|
|
|
|
ULONG cFilterAttrs,
|
|
|
|
const TS_ATTRID *paFilterAttrs)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::ProcessScopeRequest(dwFlags=%s, "
|
|
|
|
"cFilterAttrs=%ld",
|
|
|
|
this, GetFindFlagName(dwFlags).get(), cFilterAttrs));
|
2013-01-26 06:35:21 -08:00
|
|
|
|
|
|
|
// This is a little weird! RequestSupportedAttrs gives us advanced notice
|
|
|
|
// of a support query via RetrieveRequestedAttrs for a specific attribute.
|
|
|
|
// RetrieveRequestedAttrs needs to return valid data for all attributes we
|
|
|
|
// support, but the text service will only want the input scope object
|
|
|
|
// returned in RetrieveRequestedAttrs if the dwFlags passed in here contains
|
|
|
|
// TS_ATTR_FIND_WANT_VALUE.
|
|
|
|
mInputScopeDetected = mInputScopeRequested = false;
|
|
|
|
|
|
|
|
// Currently we only support GUID_PROP_INPUTSCOPE
|
|
|
|
for (uint32_t idx = 0; idx < cFilterAttrs; ++idx) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::ProcessScopeRequest() "
|
2014-01-31 03:23:36 -08:00
|
|
|
"requested attr=%s",
|
|
|
|
this, GetCLSIDNameStr(paFilterAttrs[idx]).get()));
|
2013-01-26 06:35:21 -08:00
|
|
|
if (IsEqualGUID(paFilterAttrs[idx], GUID_PROP_INPUTSCOPE)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::ProcessScopeRequest() "
|
|
|
|
"GUID_PROP_INPUTSCOPE queried", this));
|
|
|
|
mInputScopeDetected = true;
|
|
|
|
if (dwFlags & TS_ATTR_FIND_WANT_VALUE) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::ProcessScopeRequest() "
|
|
|
|
"TS_ATTR_FIND_WANT_VALUE specified", this));
|
|
|
|
mInputScopeRequested = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::RequestSupportedAttrs(DWORD dwFlags,
|
|
|
|
ULONG cFilterAttrs,
|
|
|
|
const TS_ATTRID *paFilterAttrs)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::RequestSupportedAttrs(dwFlags=%s, "
|
|
|
|
"cFilterAttrs=%lu)",
|
|
|
|
this, GetFindFlagName(dwFlags).get(), cFilterAttrs));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
return ProcessScopeRequest(dwFlags, cFilterAttrs, paFilterAttrs);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::RequestAttrsAtPosition(LONG acpPos,
|
|
|
|
ULONG cFilterAttrs,
|
|
|
|
const TS_ATTRID *paFilterAttrs,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::RequestAttrsAtPosition(acpPos=%ld, "
|
|
|
|
"cFilterAttrs=%lu, dwFlags=%s)",
|
|
|
|
this, acpPos, cFilterAttrs, GetFindFlagName(dwFlags).get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
return ProcessScopeRequest(dwFlags | TS_ATTR_FIND_WANT_VALUE,
|
|
|
|
cFilterAttrs, paFilterAttrs);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::RequestAttrsTransitioningAtPosition(LONG acpPos,
|
|
|
|
ULONG cFilterAttrs,
|
|
|
|
const TS_ATTRID *paFilterAttr,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::RequestAttrsTransitioningAtPosition("
|
|
|
|
"acpPos=%ld, cFilterAttrs=%lu, dwFlags=%s) called but not supported "
|
|
|
|
"(S_OK)",
|
|
|
|
this, acpPos, cFilterAttrs, GetFindFlagName(dwFlags).get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// no per character attributes defined
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::FindNextAttrTransition(LONG acpStart,
|
|
|
|
LONG acpHalt,
|
|
|
|
ULONG cFilterAttrs,
|
|
|
|
const TS_ATTRID *paFilterAttrs,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LONG *pacpNext,
|
|
|
|
BOOL *pfFound,
|
|
|
|
LONG *plFoundOffset)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!pacpNext || !pfFound || !plFoundOffset) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::FindNextAttrTransition() FAILED due to "
|
2012-09-11 16:53:12 -07:00
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-01-26 06:35:21 -08:00
|
|
|
("TSF: 0x%p nsTextStore::FindNextAttrTransition() called "
|
2012-09-11 16:53:12 -07:00
|
|
|
"but not supported (S_OK)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// no per character attributes defined
|
|
|
|
*pacpNext = *plFoundOffset = acpHalt;
|
|
|
|
*pfFound = FALSE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::RetrieveRequestedAttrs(ULONG ulCount,
|
|
|
|
TS_ATTRVAL *paAttrVals,
|
|
|
|
ULONG *pcFetched)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!pcFetched || !ulCount || !paAttrVals) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-01-26 06:35:21 -08:00
|
|
|
("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() FAILED due to "
|
2012-09-11 16:53:12 -07:00
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-01-26 06:35:21 -08:00
|
|
|
("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() called "
|
|
|
|
"ulCount=%d", this, ulCount));
|
|
|
|
|
|
|
|
if (mInputScopeDetected || mInputScopeRequested) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() for "
|
|
|
|
"GUID_PROP_INPUTSCOPE: "
|
|
|
|
"mInputScopeDetected=%s mInputScopeRequested=%s",
|
|
|
|
this, GetBoolName(mInputScopeDetected),
|
|
|
|
GetBoolName(mInputScopeRequested)));
|
|
|
|
|
|
|
|
paAttrVals->idAttr = GUID_PROP_INPUTSCOPE;
|
|
|
|
paAttrVals->dwOverlapId = 0;
|
|
|
|
paAttrVals->varValue.vt = VT_EMPTY;
|
|
|
|
*pcFetched = 1;
|
|
|
|
|
|
|
|
if (mInputScopeRequested) {
|
|
|
|
paAttrVals->varValue.vt = VT_UNKNOWN;
|
|
|
|
paAttrVals->varValue.punkVal = (IUnknown*) new InputScopeImpl(mInputScopes);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInputScopeDetected = mInputScopeRequested = false;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RetrieveRequestedAttrs() called "
|
|
|
|
"for unknown TS_ATTRVAL, *pcFetched=0 (S_OK)", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-01-26 06:35:21 -08:00
|
|
|
paAttrVals->dwOverlapId = 0;
|
|
|
|
paAttrVals->varValue.vt = VT_EMPTY;
|
2009-02-10 12:56:51 -08:00
|
|
|
*pcFetched = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetEndACP(LONG *pacp)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetEndACP(pacp=0x%p)", this, pacp));
|
|
|
|
|
|
|
|
if (!IsReadLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetEndACP() FAILED due to "
|
|
|
|
"not locked (read)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pacp) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetEndACP() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
Content& currentContent = CurrentContent();
|
|
|
|
if (!currentContent.IsInitialized()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetEndACP() FAILED due to "
|
2013-03-12 20:01:30 -07:00
|
|
|
"CurrentContent() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2013-03-12 20:01:30 -07:00
|
|
|
*pacp = static_cast<LONG>(currentContent.Text().Length());
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetActiveView(TsViewCookie *pvcView)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetActiveView(pvcView=0x%p)", this, pvcView));
|
|
|
|
|
|
|
|
if (!pvcView) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetActiveView() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
*pvcView = TEXTSTORE_DEFAULT_VIEW;
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetActiveView() succeeded: *pvcView=%ld",
|
|
|
|
this, *pvcView));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetACPFromPoint(TsViewCookie vcView,
|
|
|
|
const POINT *pt,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LONG *pacp)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!IsReadLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to "
|
|
|
|
"not locked (read)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vcView != TEXTSTORE_DEFAULT_VIEW) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to "
|
|
|
|
"called with invalid view", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
if (mContent.IsLayoutChanged()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetACPFromPoint() FAILED due to "
|
|
|
|
"layout not recomputed", this));
|
2014-02-04 23:36:17 -08:00
|
|
|
mPendingOnLayoutChange = true;
|
2013-03-12 20:01:30 -07:00
|
|
|
return TS_E_NOLAYOUT;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetACPFromPoint(vcView=%ld, "
|
|
|
|
"pt(0x%p)={ x=%ld, y=%ld }, dwFlags=%s, pacp=0x%p) called "
|
|
|
|
"but not supported (E_NOTIMPL)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// not supported for now
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetTextExt(TsViewCookie vcView,
|
|
|
|
LONG acpStart,
|
|
|
|
LONG acpEnd,
|
|
|
|
RECT *prc,
|
|
|
|
BOOL *pfClipped)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt(vcView=%ld, "
|
|
|
|
"acpStart=%ld, acpEnd=%ld, prc=0x%p, pfClipped=0x%p)",
|
|
|
|
this, vcView, acpStart, acpEnd, prc, pfClipped));
|
|
|
|
|
|
|
|
if (!IsReadLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"not locked (read)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vcView != TEXTSTORE_DEFAULT_VIEW) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"called with invalid view", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prc || !pfClipped) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acpStart < 0 || acpEnd < acpStart) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"invalid position", this));
|
|
|
|
return TS_E_INVALIDPOS;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
if (mContent.IsLayoutChangedAfter(acpEnd)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"layout not recomputed at %d", this, acpEnd));
|
2014-02-04 23:36:17 -08:00
|
|
|
mPendingOnLayoutChange = true;
|
2013-03-12 20:01:30 -07:00
|
|
|
return TS_E_NOLAYOUT;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// use NS_QUERY_TEXT_RECT to get rect in system, screen coordinates
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent event(true, NS_QUERY_TEXT_RECT, mWidget);
|
2013-01-07 07:18:11 -08:00
|
|
|
mWidget->InitEvent(event);
|
2009-02-10 12:56:51 -08:00
|
|
|
event.InitForQueryTextRect(acpStart, acpEnd - acpStart);
|
2013-01-07 07:18:11 -08:00
|
|
|
mWidget->DispatchWindowEvent(&event);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!event.mSucceeded) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"NS_QUERY_TEXT_RECT failure", this));
|
|
|
|
return TS_E_INVALIDPOS; // but unexpected failure, maybe.
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
// IMEs don't like empty rects, fix here
|
|
|
|
if (event.mReply.mRect.width <= 0)
|
|
|
|
event.mReply.mRect.width = 1;
|
|
|
|
if (event.mReply.mRect.height <= 0)
|
|
|
|
event.mReply.mRect.height = 1;
|
|
|
|
|
2013-01-07 07:18:11 -08:00
|
|
|
if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop) {
|
|
|
|
// convert to unclipped screen rect
|
|
|
|
nsWindow* refWindow = static_cast<nsWindow*>(
|
|
|
|
event.mReply.mFocusedWidget ? event.mReply.mFocusedWidget : mWidget);
|
|
|
|
// Result rect is in top level widget coordinates
|
|
|
|
refWindow = refWindow->GetTopLevelWindow(false);
|
|
|
|
if (!refWindow) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"no top level window", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-01-07 07:18:11 -08:00
|
|
|
event.mReply.mRect.MoveBy(refWindow->WidgetToScreenOffset());
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// get bounding screen rect to test for clipping
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!GetScreenExtInternal(*prc)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() FAILED due to "
|
|
|
|
"GetScreenExtInternal() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
// clip text rect to bounding rect
|
|
|
|
RECT textRect;
|
|
|
|
::SetRect(&textRect, event.mReply.mRect.x, event.mReply.mRect.y,
|
|
|
|
event.mReply.mRect.XMost(), event.mReply.mRect.YMost());
|
|
|
|
if (!::IntersectRect(prc, prc, &textRect))
|
|
|
|
// Text is not visible
|
|
|
|
::SetRectEmpty(prc);
|
|
|
|
|
|
|
|
// not equal if text rect was clipped
|
|
|
|
*pfClipped = !::EqualRect(prc, &textRect);
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2014-01-30 18:17:24 -08:00
|
|
|
// ATOK refers native caret position and size on Desktop applications for
|
|
|
|
// deciding candidate window. Therefore, we need to create native caret
|
|
|
|
// for hacking the bug.
|
2014-01-30 18:17:25 -08:00
|
|
|
if (sCreateNativeCaretForATOK &&
|
|
|
|
StringBeginsWith(
|
|
|
|
mActiveTIPKeyboardDescription, NS_LITERAL_STRING("ATOK ")) &&
|
2014-01-30 18:17:24 -08:00
|
|
|
mComposition.IsComposing() &&
|
|
|
|
mComposition.mStart <= acpStart && mComposition.EndOffset() >= acpStart &&
|
|
|
|
mComposition.mStart <= acpEnd && mComposition.EndOffset() >= acpEnd) {
|
|
|
|
if (mNativeCaretIsCreated) {
|
|
|
|
::DestroyCaret();
|
|
|
|
mNativeCaretIsCreated = false;
|
|
|
|
}
|
|
|
|
CreateNativeCaret();
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetTextExt() succeeded: "
|
|
|
|
"*prc={ left=%ld, top=%ld, right=%ld, bottom=%ld }, *pfClipped=%s",
|
|
|
|
this, prc->left, prc->top, prc->right, prc->bottom,
|
|
|
|
GetBoolName(*pfClipped)));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetScreenExt(TsViewCookie vcView,
|
|
|
|
RECT *prc)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExt(vcView=%ld, prc=0x%p)",
|
|
|
|
this, vcView, prc));
|
|
|
|
|
|
|
|
if (vcView != TEXTSTORE_DEFAULT_VIEW) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to "
|
|
|
|
"called with invalid view", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prc) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetScreenExtInternal(*prc)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to "
|
|
|
|
"GetScreenExtInternal() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExt() succeeded: "
|
|
|
|
"*prc={ left=%ld, top=%ld, right=%ld, bottom=%ld }",
|
|
|
|
this, prc->left, prc->top, prc->right, prc->bottom));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsTextStore::GetScreenExtInternal(RECT &aScreenExt)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExtInternal()", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// use NS_QUERY_EDITOR_RECT to get rect in system, screen coordinates
|
2013-10-01 00:23:00 -07:00
|
|
|
WidgetQueryContentEvent event(true, NS_QUERY_EDITOR_RECT, mWidget);
|
2013-01-07 07:18:11 -08:00
|
|
|
mWidget->InitEvent(event);
|
|
|
|
mWidget->DispatchWindowEvent(&event);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!event.mSucceeded) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to "
|
|
|
|
"NS_QUERY_EDITOR_RECT failure", this));
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-01-07 07:18:11 -08:00
|
|
|
if (XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Metro) {
|
|
|
|
nsIntRect boundRect;
|
|
|
|
if (NS_FAILED(mWidget->GetClientBounds(boundRect))) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to "
|
|
|
|
"failed to get the client bounds", this));
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
::SetRect(&aScreenExt, boundRect.x, boundRect.y,
|
2009-02-10 12:56:51 -08:00
|
|
|
boundRect.XMost(), boundRect.YMost());
|
|
|
|
} else {
|
2013-01-07 07:18:11 -08:00
|
|
|
NS_ASSERTION(XRE_GetWindowsEnvironment() == WindowsEnvironmentType_Desktop,
|
|
|
|
"environment isn't WindowsEnvironmentType_Desktop!");
|
|
|
|
nsWindow* refWindow = static_cast<nsWindow*>(
|
|
|
|
event.mReply.mFocusedWidget ?
|
|
|
|
event.mReply.mFocusedWidget : mWidget);
|
|
|
|
// Result rect is in top level widget coordinates
|
|
|
|
refWindow = refWindow->GetTopLevelWindow(false);
|
|
|
|
if (!refWindow) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to "
|
|
|
|
"no top level window", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect boundRect;
|
|
|
|
if (NS_FAILED(refWindow->GetClientBounds(boundRect))) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExtInternal() FAILED due to "
|
|
|
|
"failed to get the client bounds", this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
boundRect.MoveTo(0, 0);
|
|
|
|
|
|
|
|
// Clip frame rect to window rect
|
|
|
|
boundRect.IntersectRect(event.mReply.mRect, boundRect);
|
|
|
|
if (!boundRect.IsEmpty()) {
|
|
|
|
boundRect.MoveBy(refWindow->WidgetToScreenOffset());
|
|
|
|
::SetRect(&aScreenExt, boundRect.x, boundRect.y,
|
|
|
|
boundRect.XMost(), boundRect.YMost());
|
|
|
|
} else {
|
|
|
|
::SetRectEmpty(&aScreenExt);
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExtInternal() succeeded: "
|
|
|
|
"aScreenExt={ left=%ld, top=%ld, right=%ld, bottom=%ld }",
|
|
|
|
this, aScreenExt.left, aScreenExt.top,
|
|
|
|
aScreenExt.right, aScreenExt.bottom));
|
|
|
|
return true;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::GetWnd(TsViewCookie vcView,
|
|
|
|
HWND *phwnd)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-01-07 07:18:11 -08:00
|
|
|
("TSF: 0x%p nsTextStore::GetWnd(vcView=%ld, phwnd=0x%p), "
|
|
|
|
"mWidget=0x%p",
|
2013-01-09 06:41:58 -08:00
|
|
|
this, vcView, phwnd, mWidget.get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (vcView != TEXTSTORE_DEFAULT_VIEW) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetWnd() FAILED due to "
|
|
|
|
"called with invalid view", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!phwnd) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::GetScreenExt() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2013-01-07 07:18:11 -08:00
|
|
|
*phwnd = mWidget->GetWindowHandle();
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::GetWnd() succeeded: *phwnd=0x%p",
|
|
|
|
this, static_cast<void*>(*phwnd)));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::InsertTextAtSelection(DWORD dwFlags,
|
|
|
|
const WCHAR *pchText,
|
|
|
|
ULONG cch,
|
|
|
|
LONG *pacpStart,
|
|
|
|
LONG *pacpEnd,
|
|
|
|
TS_TEXTCHANGE *pChange)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2012-09-11 16:53:12 -07:00
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection(dwFlags=%s, "
|
|
|
|
"pchText=0x%p \"%s\", cch=%lu, pacpStart=0x%p, pacpEnd=0x%p, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"pChange=0x%p), IsComposing()=%s",
|
2012-09-11 16:53:12 -07:00
|
|
|
this, dwFlags == 0 ? "0" :
|
|
|
|
dwFlags == TF_IAS_NOQUERY ? "TF_IAS_NOQUERY" :
|
|
|
|
dwFlags == TF_IAS_QUERYONLY ? "TF_IAS_QUERYONLY" : "Unknown",
|
|
|
|
pchText,
|
|
|
|
pchText && cch ? NS_ConvertUTF16toUTF8(pchText, cch).get() : "",
|
|
|
|
cch, pacpStart, pacpEnd, pChange,
|
2013-03-12 20:01:29 -07:00
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
|
|
|
if (cch && !pchText) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
|
|
|
"null pchText", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
if (TS_IAS_QUERYONLY == dwFlags) {
|
2012-09-13 18:38:58 -07:00
|
|
|
if (!IsReadLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
|
|
|
"not locked (read)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!pacpStart || !pacpEnd) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2012-09-13 21:51:00 -07:00
|
|
|
|
|
|
|
// Get selection first
|
2013-03-12 20:01:29 -07:00
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
2012-09-13 21:51:00 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
2013-03-12 20:01:29 -07:00
|
|
|
"CurrentSelection() failure", this));
|
2012-09-13 21:51:00 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// Simulate text insertion
|
2013-03-12 20:01:29 -07:00
|
|
|
*pacpStart = currentSel.StartOffset();
|
|
|
|
*pacpEnd = currentSel.EndOffset();
|
2009-02-10 12:56:51 -08:00
|
|
|
if (pChange) {
|
2013-03-12 20:01:29 -07:00
|
|
|
pChange->acpStart = currentSel.StartOffset();
|
|
|
|
pChange->acpOldEnd = currentSel.EndOffset();
|
|
|
|
pChange->acpNewEnd = currentSel.StartOffset() + static_cast<LONG>(cch);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
} else {
|
2012-09-13 18:38:58 -07:00
|
|
|
if (!IsReadWriteLocked()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
|
|
|
"not locked (read-write)", this));
|
|
|
|
return TS_E_NOLOCK;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!pChange) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
|
|
|
"null pChange", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2012-09-13 21:51:00 -07:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
if (TS_IAS_NOQUERY != dwFlags && (!pacpStart || !pacpEnd)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
|
|
|
"null argument", this));
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2012-12-30 16:33:49 -08:00
|
|
|
if (!InsertTextAtSelectionInternal(nsDependentSubstring(pchText, cch),
|
2012-09-13 21:51:00 -07:00
|
|
|
pChange)) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() FAILED due to "
|
2012-09-13 21:51:00 -07:00
|
|
|
"InsertTextAtSelectionInternal() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2012-09-13 21:51:00 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
if (TS_IAS_NOQUERY != dwFlags) {
|
|
|
|
*pacpStart = pChange->acpStart;
|
|
|
|
*pacpEnd = pChange->acpNewEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2012-09-11 16:53:12 -07:00
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelection() succeeded: "
|
|
|
|
"*pacpStart=%ld, *pacpEnd=%ld, "
|
|
|
|
"*pChange={ acpStart=%ld, acpOldEnd=%ld, acpNewEnd=%ld })",
|
|
|
|
this, pacpStart ? *pacpStart : 0, pacpEnd ? *pacpEnd : 0,
|
|
|
|
pChange ? pChange->acpStart: 0, pChange ? pChange->acpOldEnd : 0,
|
|
|
|
pChange ? pChange->acpNewEnd : 0));
|
2012-09-13 19:35:23 -07:00
|
|
|
return S_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2012-09-13 21:51:00 -07:00
|
|
|
bool
|
|
|
|
nsTextStore::InsertTextAtSelectionInternal(const nsAString &aInsertStr,
|
|
|
|
TS_TEXTCHANGE* aTextChange)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelectionInternal("
|
2013-03-12 20:01:29 -07:00
|
|
|
"aInsertStr=\"%s\", aTextChange=0x%p), IsComposing=%s",
|
2012-09-13 21:51:00 -07:00
|
|
|
this, NS_ConvertUTF16toUTF8(aInsertStr).get(), aTextChange,
|
2013-03-12 20:01:29 -07:00
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-13 21:51:00 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
Content& currentContent = CurrentContent();
|
|
|
|
if (!currentContent.IsInitialized()) {
|
2013-03-12 20:01:29 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelectionInternal() failed "
|
2013-03-12 20:01:30 -07:00
|
|
|
"due to CurrentContent() failure()", this));
|
2013-03-12 20:01:29 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-13 21:51:00 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
TS_SELECTION_ACP oldSelection = currentContent.Selection().ACP();
|
|
|
|
if (!mComposition.IsComposing()) {
|
2012-09-13 21:51:00 -07:00
|
|
|
// Use a temporary composition to contain the text
|
2013-03-12 20:01:29 -07:00
|
|
|
PendingAction* compositionStart = mPendingActions.AppendElement();
|
|
|
|
compositionStart->mType = PendingAction::COMPOSITION_START;
|
|
|
|
compositionStart->mSelectionStart = oldSelection.acpStart;
|
|
|
|
compositionStart->mSelectionLength =
|
|
|
|
oldSelection.acpEnd - oldSelection.acpStart;
|
2012-09-13 21:51:00 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
PendingAction* compositionEnd = mPendingActions.AppendElement();
|
|
|
|
compositionEnd->mType = PendingAction::COMPOSITION_END;
|
|
|
|
compositionEnd->mData = aInsertStr;
|
2012-09-13 21:51:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
currentContent.ReplaceSelectedTextWith(aInsertStr);
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2012-09-13 21:51:00 -07:00
|
|
|
if (aTextChange) {
|
|
|
|
aTextChange->acpStart = oldSelection.acpStart;
|
|
|
|
aTextChange->acpOldEnd = oldSelection.acpEnd;
|
2013-03-12 20:01:30 -07:00
|
|
|
aTextChange->acpNewEnd = currentContent.Selection().EndOffset();
|
2012-09-13 21:51:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertTextAtSelectionInternal() succeeded: "
|
2013-01-07 07:18:11 -08:00
|
|
|
"mWidget=0x%p, mWidget->Destroyed()=%s, aTextChange={ acpStart=%ld, "
|
2012-09-13 21:51:00 -07:00
|
|
|
"acpOldEnd=%ld, acpNewEnd=%ld }",
|
2013-01-09 06:41:58 -08:00
|
|
|
this, mWidget.get(),
|
|
|
|
GetBoolName(mWidget ? mWidget->Destroyed() : true),
|
2012-09-13 21:51:00 -07:00
|
|
|
aTextChange ? aTextChange->acpStart : 0,
|
|
|
|
aTextChange ? aTextChange->acpOldEnd : 0,
|
|
|
|
aTextChange ? aTextChange->acpNewEnd : 0));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::InsertEmbeddedAtSelection(DWORD dwFlags,
|
|
|
|
IDataObject *pDataObject,
|
|
|
|
LONG *pacpStart,
|
|
|
|
LONG *pacpEnd,
|
|
|
|
TS_TEXTCHANGE *pChange)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::InsertEmbeddedAtSelection() called "
|
|
|
|
"but not supported (E_NOTIMPL)", this));
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// embedded objects are not supported
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2013-03-12 20:01:30 -07:00
|
|
|
nsTextStore::RecordCompositionStartAction(ITfCompositionView* pComposition,
|
|
|
|
ITfRange* aRange,
|
|
|
|
bool aPreserveSelection)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionStartAction("
|
2012-09-11 16:53:12 -07:00
|
|
|
"pComposition=0x%p, aRange=0x%p, aPreserveSelection=%s), "
|
2013-03-12 20:01:29 -07:00
|
|
|
"mComposition.mView=0x%p",
|
2012-09-11 16:53:12 -07:00
|
|
|
this, pComposition, aRange, GetBoolName(aPreserveSelection),
|
2013-03-12 20:01:29 -07:00
|
|
|
mComposition.mView.get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
LONG start = 0, length = 0;
|
|
|
|
HRESULT hr = GetRangeExtent(aRange, &start, &length);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionStartAction() FAILED "
|
|
|
|
"due to GetRangeExtent() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
Content& currentContent = CurrentContent();
|
|
|
|
if (!currentContent.IsInitialized()) {
|
2013-03-12 20:01:29 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionStartAction() FAILED "
|
|
|
|
"due to CurrentContent() failure", this));
|
2013-03-12 20:01:29 -07:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
PendingAction* action = mPendingActions.AppendElement();
|
|
|
|
action->mType = PendingAction::COMPOSITION_START;
|
2013-03-12 20:01:30 -07:00
|
|
|
action->mSelectionStart = start;
|
|
|
|
action->mSelectionLength = length;
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
currentContent.StartComposition(pComposition, *action, aPreserveSelection);
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2014-01-31 03:23:36 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2013-03-12 20:01:30 -07:00
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionStartAction() succeeded: "
|
2013-03-12 20:01:30 -07:00
|
|
|
"mComposition={ mStart=%ld, mString.Length()=%ld, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"mSelection={ acpStart=%ld, acpEnd=%ld, style.ase=%s, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"style.fInterimChar=%s } }",
|
2013-03-12 20:01:30 -07:00
|
|
|
this, mComposition.mStart, mComposition.mString.Length(),
|
2013-03-12 20:01:30 -07:00
|
|
|
mSelection.StartOffset(), mSelection.EndOffset(),
|
|
|
|
GetActiveSelEndName(mSelection.ActiveSelEnd()),
|
|
|
|
GetBoolName(mSelection.IsInterimChar())));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
HRESULT
|
|
|
|
nsTextStore::RecordCompositionEndAction()
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionEndAction(), "
|
|
|
|
"mComposition={ mView=0x%p, mString=\"%s\" }",
|
|
|
|
this, mComposition.mView.get(),
|
|
|
|
NS_ConvertUTF16toUTF8(mComposition.mString).get()));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mComposition.IsComposing());
|
|
|
|
|
|
|
|
PendingAction* action = mPendingActions.AppendElement();
|
|
|
|
action->mType = PendingAction::COMPOSITION_END;
|
|
|
|
action->mData = mComposition.mString;
|
|
|
|
|
|
|
|
Content& currentContent = CurrentContent();
|
|
|
|
if (!currentContent.IsInitialized()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionEndAction() FAILED due "
|
|
|
|
"to CurrentContent() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
currentContent.EndComposition(*action);
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::RecordCompositionEndAction(), succeeded",
|
|
|
|
this));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::OnStartComposition(ITfCompositionView* pComposition,
|
|
|
|
BOOL* pfOk)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnStartComposition(pComposition=0x%p, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"pfOk=0x%p), mComposition.mView=0x%p",
|
|
|
|
this, pComposition, pfOk, mComposition.mView.get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
AutoPendingActionAndContentFlusher flusher(this);
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
*pfOk = FALSE;
|
|
|
|
|
|
|
|
// Only one composition at a time
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mComposition.IsComposing()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnStartComposition() FAILED due to "
|
|
|
|
"there is another composition already (but returns S_OK)", this));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfRange> range;
|
|
|
|
HRESULT hr = pComposition->GetRange(getter_AddRefs(range));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnStartComposition() FAILED due to "
|
|
|
|
"pComposition->GetRange() failure", this));
|
|
|
|
return hr;
|
|
|
|
}
|
2013-03-12 20:01:30 -07:00
|
|
|
hr = RecordCompositionStartAction(pComposition, range, false);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnStartComposition() FAILED due to "
|
2013-03-12 20:01:30 -07:00
|
|
|
"RecordCompositionStartAction() failure", this));
|
2009-02-23 22:36:20 -08:00
|
|
|
return hr;
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-23 22:36:20 -08:00
|
|
|
|
|
|
|
*pfOk = TRUE;
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnStartComposition() succeeded", this));
|
2009-02-23 22:36:20 -08:00
|
|
|
return S_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::OnUpdateComposition(ITfCompositionView* pComposition,
|
|
|
|
ITfRange* pRangeNew)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition(pComposition=0x%p, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"pRangeNew=0x%p), mComposition.mView=0x%p",
|
|
|
|
this, pComposition, pRangeNew, mComposition.mView.get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
AutoPendingActionAndContentFlusher flusher(this);
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!mDocumentMgr || !mContext) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to "
|
|
|
|
"not ready for the composition", this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
2013-03-12 20:01:29 -07:00
|
|
|
if (!mComposition.IsComposing()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to "
|
|
|
|
"no active composition", this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mComposition.mView != pComposition) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to "
|
|
|
|
"different composition view specified", this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// pRangeNew is null when the update is not complete
|
|
|
|
if (!pRangeNew) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() succeeded but "
|
|
|
|
"not complete", this));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
HRESULT hr = RestartCompositionIfNecessary(pRangeNew);
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to "
|
2013-03-12 20:01:30 -07:00
|
|
|
"RestartCompositionIfNecessary() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
hr = RecordCompositionUpdateAction();
|
2012-09-11 16:53:12 -07:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to "
|
2013-03-12 20:01:29 -07:00
|
|
|
"RecordCompositionUpdateAction() failure", this));
|
2012-09-11 16:53:12 -07:00
|
|
|
return hr;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(sTextStoreLog, PR_LOG_ALWAYS)) {
|
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() FAILED due to "
|
|
|
|
"CurrentSelection() failure", this));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnUpdateComposition() succeeded: "
|
2013-03-12 20:01:30 -07:00
|
|
|
"mComposition={ mStart=%ld, mString=\"%s\" }, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"CurrentSelection()={ acpStart=%ld, acpEnd=%ld, style.ase=%s }",
|
2013-03-12 20:01:30 -07:00
|
|
|
this, mComposition.mStart,
|
2013-03-12 20:01:29 -07:00
|
|
|
NS_ConvertUTF16toUTF8(mComposition.mString).get(),
|
|
|
|
currentSel.StartOffset(), currentSel.EndOffset(),
|
|
|
|
GetActiveSelEndName(currentSel.ActiveSelEnd())));
|
|
|
|
}
|
|
|
|
#endif // #ifdef PR_LOGGING
|
2012-09-11 16:53:12 -07:00
|
|
|
return S_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::OnEndComposition(ITfCompositionView* pComposition)
|
|
|
|
{
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2012-09-11 16:53:12 -07:00
|
|
|
("TSF: 0x%p nsTextStore::OnEndComposition(pComposition=0x%p), "
|
2013-03-12 20:01:29 -07:00
|
|
|
"mComposition={ mView=0x%p, mString=\"%s\" }",
|
|
|
|
this, pComposition, mComposition.mView.get(),
|
|
|
|
NS_ConvertUTF16toUTF8(mComposition.mString).get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
AutoPendingActionAndContentFlusher flusher(this);
|
2013-03-12 20:01:29 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (!mComposition.IsComposing()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnEndComposition() FAILED due to "
|
|
|
|
"no active composition", this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mComposition.mView != pComposition) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnEndComposition() FAILED due to "
|
|
|
|
"different composition view specified", this));
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
HRESULT hr = RecordCompositionEndAction();
|
|
|
|
if (FAILED(hr)) {
|
2013-03-12 20:01:30 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnEndComposition() FAILED due to "
|
2013-03-12 20:01:30 -07:00
|
|
|
"RecordCompositionEndAction() failure", this));
|
|
|
|
return hr;
|
2013-03-12 20:01:30 -07:00
|
|
|
}
|
2011-09-22 02:17:40 -07:00
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnEndComposition(), succeeded", this));
|
2009-02-10 12:56:51 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::OnActivated(REFCLSID clsid, REFGUID guidProfile,
|
|
|
|
BOOL fActivated)
|
|
|
|
{
|
|
|
|
// NOTE: This is installed only on XP or Server 2003.
|
|
|
|
if (fActivated) {
|
|
|
|
// TODO: We should check if the profile's category is keyboard or not.
|
|
|
|
mOnActivatedCalled = true;
|
|
|
|
mIsIMM_IME = IsIMM_IME(::GetKeyboardLayout(0));
|
|
|
|
|
|
|
|
LANGID langID;
|
|
|
|
HRESULT hr = sInputProcessorProfiles->GetCurrentLanguage(&langID);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::OnActivated() FAILED due to "
|
|
|
|
"GetCurrentLanguage() failure, hr=0x%08X", hr));
|
|
|
|
} else if (IsTIPCategoryKeyboard(clsid, langID, guidProfile)) {
|
|
|
|
GetTIPDescription(clsid, langID, guidProfile,
|
|
|
|
mActiveTIPKeyboardDescription);
|
|
|
|
} else if (clsid == CLSID_NULL || guidProfile == GUID_NULL) {
|
|
|
|
// Perhaps, this case is that keyboard layout without TIP is activated.
|
|
|
|
mActiveTIPKeyboardDescription.Truncate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnActivated(rclsid=%s, guidProfile=%s, "
|
|
|
|
"fActivated=%s), mIsIMM_IME=%s, mActiveTIPDescription=\"%s\"",
|
|
|
|
this, GetCLSIDNameStr(clsid).get(),
|
|
|
|
GetGUIDNameStr(guidProfile).get(), GetBoolName(fActivated),
|
|
|
|
GetBoolName(mIsIMM_IME),
|
|
|
|
NS_ConvertUTF16toUTF8(mActiveTIPKeyboardDescription).get()));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-13 18:01:00 -08:00
|
|
|
STDMETHODIMP
|
|
|
|
nsTextStore::OnActivated(DWORD dwProfileType,
|
|
|
|
LANGID langid,
|
|
|
|
REFCLSID rclsid,
|
|
|
|
REFGUID catid,
|
|
|
|
REFGUID guidProfile,
|
|
|
|
HKL hkl,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
2014-01-30 18:17:25 -08:00
|
|
|
// NOTE: This is installed only on Vista or later. However, this may be
|
|
|
|
// called by EnsureInitActiveLanguageProfile() even on XP or Server
|
|
|
|
// 2003.
|
|
|
|
if ((dwFlags & TF_IPSINK_FLAG_ACTIVE) &&
|
|
|
|
(dwProfileType == TF_PROFILETYPE_KEYBOARDLAYOUT ||
|
|
|
|
catid == GUID_TFCAT_TIP_KEYBOARD)) {
|
|
|
|
mOnActivatedCalled = true;
|
2014-01-13 18:01:00 -08:00
|
|
|
mIsIMM_IME = IsIMM_IME(hkl);
|
2014-01-30 18:17:25 -08:00
|
|
|
GetTIPDescription(rclsid, langid, guidProfile,
|
|
|
|
mActiveTIPKeyboardDescription);
|
2014-01-13 18:01:00 -08:00
|
|
|
}
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnActivated(dwProfileType=%s (0x%08X), "
|
|
|
|
"langid=0x%08X, rclsid=%s, catid=%s, guidProfile=%s, hkl=0x%08X, "
|
2014-01-30 18:17:25 -08:00
|
|
|
"dwFlags=0x%08X (TF_IPSINK_FLAG_ACTIVE: %s)), mIsIMM_IME=%s, "
|
|
|
|
"mActiveTIPDescription=\"%s\"",
|
2014-01-13 18:01:00 -08:00
|
|
|
this, dwProfileType == TF_PROFILETYPE_INPUTPROCESSOR ?
|
|
|
|
"TF_PROFILETYPE_INPUTPROCESSOR" :
|
|
|
|
dwProfileType == TF_PROFILETYPE_KEYBOARDLAYOUT ?
|
|
|
|
"TF_PROFILETYPE_KEYBOARDLAYOUT" : "Unknown", dwProfileType,
|
|
|
|
langid, GetCLSIDNameStr(rclsid).get(), GetGUIDNameStr(catid).get(),
|
|
|
|
GetGUIDNameStr(guidProfile).get(), hkl, dwFlags,
|
|
|
|
GetBoolName(dwFlags & TF_IPSINK_FLAG_ACTIVE),
|
2014-01-30 18:17:25 -08:00
|
|
|
GetBoolName(mIsIMM_IME),
|
|
|
|
NS_ConvertUTF16toUTF8(mActiveTIPKeyboardDescription).get()));
|
2014-01-13 18:01:00 -08:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// static
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult
|
2013-01-07 07:18:11 -08:00
|
|
|
nsTextStore::OnFocusChange(bool aGotFocus,
|
|
|
|
nsWindowBase* aFocusedWidget,
|
2011-11-27 03:51:53 -08:00
|
|
|
IMEState::Enabled aIMEEnabled)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: nsTextStore::OnFocusChange(aGotFocus=%s, "
|
2013-01-07 07:18:11 -08:00
|
|
|
"aFocusedWidget=0x%p, aIMEEnabled=%s), sTsfThreadMgr=0x%p, "
|
|
|
|
"sTsfTextStore=0x%p",
|
|
|
|
GetBoolName(aGotFocus), aFocusedWidget,
|
|
|
|
GetIMEEnabledName(aIMEEnabled), sTsfThreadMgr, sTsfTextStore));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
// no change notifications if TSF is disabled
|
2013-02-24 20:00:06 -08:00
|
|
|
NS_ENSURE_TRUE(sTsfThreadMgr && sTsfTextStore, NS_ERROR_NOT_AVAILABLE);
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-26 17:04:02 -07:00
|
|
|
nsRefPtr<ITfDocumentMgr> prevFocusedDocumentMgr;
|
|
|
|
if (aGotFocus && (aIMEEnabled == IMEState::ENABLED ||
|
|
|
|
aIMEEnabled == IMEState::PASSWORD)) {
|
|
|
|
bool bRet = sTsfTextStore->Create(aFocusedWidget);
|
2009-03-08 19:38:12 -07:00
|
|
|
NS_ENSURE_TRUE(bRet, NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(sTsfTextStore->mDocumentMgr, NS_ERROR_FAILURE);
|
2013-03-26 17:04:02 -07:00
|
|
|
if (aIMEEnabled == IMEState::PASSWORD) {
|
|
|
|
MarkContextAsKeyboardDisabled(sTsfTextStore->mContext);
|
|
|
|
nsRefPtr<ITfContext> topContext;
|
|
|
|
sTsfTextStore->mDocumentMgr->GetTop(getter_AddRefs(topContext));
|
|
|
|
if (topContext && topContext != sTsfTextStore->mContext) {
|
|
|
|
MarkContextAsKeyboardDisabled(topContext);
|
|
|
|
}
|
|
|
|
}
|
2009-03-08 19:38:12 -07:00
|
|
|
HRESULT hr = sTsfThreadMgr->SetFocus(sTsfTextStore->mDocumentMgr);
|
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE);
|
2013-03-26 17:04:02 -07:00
|
|
|
// Use AssociateFocus() for ensuring that any native focus event
|
|
|
|
// never steal focus from our documentMgr.
|
|
|
|
hr = sTsfThreadMgr->AssociateFocus(aFocusedWidget->GetWindowHandle(),
|
|
|
|
sTsfTextStore->mDocumentMgr,
|
|
|
|
getter_AddRefs(prevFocusedDocumentMgr));
|
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE);
|
2009-02-10 12:56:51 -08:00
|
|
|
} else {
|
2013-03-26 17:04:02 -07:00
|
|
|
if (ThinksHavingFocus()) {
|
|
|
|
DebugOnly<HRESULT> hr = sTsfThreadMgr->AssociateFocus(
|
|
|
|
sTsfTextStore->mWidget->GetWindowHandle(),
|
2013-10-08 11:48:20 -07:00
|
|
|
nullptr, getter_AddRefs(prevFocusedDocumentMgr));
|
2013-03-26 17:04:02 -07:00
|
|
|
NS_ASSERTION(SUCCEEDED(hr), "Disassociating focus failed");
|
|
|
|
NS_ASSERTION(prevFocusedDocumentMgr == sTsfTextStore->mDocumentMgr,
|
|
|
|
"different documentMgr has been associated with the window");
|
|
|
|
sTsfTextStore->Destroy();
|
|
|
|
}
|
|
|
|
HRESULT hr = sTsfThreadMgr->SetFocus(sTsfDisabledDocumentMgr);
|
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-13 05:04:45 -08:00
|
|
|
// static
|
|
|
|
nsIMEUpdatePreference
|
|
|
|
nsTextStore::GetIMEUpdatePreference()
|
|
|
|
{
|
|
|
|
if (sTsfThreadMgr && sTsfTextStore && sTsfTextStore->mDocumentMgr) {
|
|
|
|
nsRefPtr<ITfDocumentMgr> docMgr;
|
|
|
|
sTsfThreadMgr->GetFocus(getter_AddRefs(docMgr));
|
2013-07-11 00:46:34 -07:00
|
|
|
if (docMgr == sTsfTextStore->mDocumentMgr) {
|
2014-02-25 16:48:02 -08:00
|
|
|
nsIMEUpdatePreference updatePreference(
|
|
|
|
nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE |
|
|
|
|
nsIMEUpdatePreference::NOTIFY_TEXT_CHANGE |
|
2014-02-27 23:45:16 -08:00
|
|
|
nsIMEUpdatePreference::NOTIFY_POSITION_CHANGE |
|
2014-02-25 16:48:02 -08:00
|
|
|
nsIMEUpdatePreference::NOTIFY_DURING_DEACTIVE);
|
|
|
|
// nsTextStore shouldn't notify TSF of selection change and text change
|
|
|
|
// which are caused by composition.
|
|
|
|
updatePreference.DontNotifyChangesCausedByComposition();
|
|
|
|
return updatePreference;
|
2013-07-11 00:46:34 -07:00
|
|
|
}
|
2012-11-13 05:04:45 -08:00
|
|
|
}
|
2014-02-25 16:48:02 -08:00
|
|
|
return nsIMEUpdatePreference();
|
2012-11-13 05:04:45 -08:00
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
nsresult
|
2014-02-17 16:00:15 -08:00
|
|
|
nsTextStore::OnTextChangeInternal(const IMENotification& aIMENotification)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2014-02-17 16:00:15 -08:00
|
|
|
("TSF: 0x%p nsTextStore::OnTextChangeInternal(aIMENotification={ "
|
|
|
|
"mMessage=0x%08X, mTextChangeData={ mStartOffset=%lu, "
|
|
|
|
"mOldEndOffset=%lu, mNewEndOffset=%lu}), mSink=0x%p, mSinkMask=%s, "
|
2014-01-23 01:36:01 -08:00
|
|
|
"mComposition.IsComposing()=%s",
|
2014-02-17 16:00:15 -08:00
|
|
|
this, aIMENotification.mMessage,
|
|
|
|
aIMENotification.mTextChangeData.mStartOffset,
|
|
|
|
aIMENotification.mTextChangeData.mOldEndOffset,
|
|
|
|
aIMENotification.mTextChangeData.mNewEndOffset, mSink.get(),
|
2014-01-23 01:36:01 -08:00
|
|
|
GetSinkMaskNameStr(mSinkMask).get(),
|
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (IsReadLocked()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSelection.MarkDirty();
|
|
|
|
|
2014-01-23 01:36:01 -08:00
|
|
|
if (!mSink || !(mSinkMask & TS_AS_TEXT_CHANGE)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2014-02-17 16:00:15 -08:00
|
|
|
if (!aIMENotification.mTextChangeData.IsInInt32Range()) {
|
2014-01-23 01:36:01 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::OnTextChangeInternal() FAILED due to "
|
|
|
|
"offset is too big for calling mSink->OnTextChange()...",
|
|
|
|
this));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2014-01-23 01:36:01 -08:00
|
|
|
// Some TIPs are confused by text change notification during composition.
|
|
|
|
// Especially, some of them stop working for composition in our process.
|
|
|
|
// For preventing it, let's commit the composition.
|
|
|
|
if (mComposition.IsComposing()) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-23 01:36:01 -08:00
|
|
|
("TSF: 0x%p nsTextStore::OnTextChangeInternal(), "
|
|
|
|
"committing the composition for avoiding making TIP confused...",
|
|
|
|
this));
|
|
|
|
CommitCompositionInternal(false);
|
|
|
|
return NS_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2014-01-23 01:36:01 -08:00
|
|
|
|
|
|
|
TS_TEXTCHANGE textChange;
|
2014-02-17 16:00:15 -08:00
|
|
|
textChange.acpStart =
|
|
|
|
static_cast<LONG>(aIMENotification.mTextChangeData.mStartOffset);
|
|
|
|
textChange.acpOldEnd =
|
|
|
|
static_cast<LONG>(aIMENotification.mTextChangeData.mOldEndOffset);
|
|
|
|
textChange.acpNewEnd =
|
|
|
|
static_cast<LONG>(aIMENotification.mTextChangeData.mNewEndOffset);
|
2014-01-23 01:36:01 -08:00
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-02-17 16:00:15 -08:00
|
|
|
("TSF: 0x%p nsTextStore::OnTextChangeInternal(), calling "
|
2014-01-23 01:36:01 -08:00
|
|
|
"mSink->OnTextChange(0, { acpStart=%ld, acpOldEnd=%ld, "
|
|
|
|
"acpNewEnd=%ld })...", this, textChange.acpStart,
|
|
|
|
textChange.acpOldEnd, textChange.acpNewEnd));
|
|
|
|
mSink->OnTextChange(0, &textChange);
|
|
|
|
|
2014-01-23 00:01:16 -08:00
|
|
|
return NS_OK;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextStore::OnSelectionChangeInternal(void)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(), "
|
2014-01-23 01:36:01 -08:00
|
|
|
"mSink=0x%p, mSinkMask=%s, mIsRecordingActionsWithoutLock=%s, "
|
|
|
|
"mComposition.IsComposing()=%s",
|
2013-03-12 20:01:29 -07:00
|
|
|
this, mSink.get(), GetSinkMaskNameStr(mSinkMask).get(),
|
2014-01-23 01:36:01 -08:00
|
|
|
GetBoolName(mIsRecordingActionsWithoutLock),
|
|
|
|
GetBoolName(mComposition.IsComposing())));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (IsReadLocked()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSelection.MarkDirty();
|
|
|
|
|
2014-01-23 01:36:01 -08:00
|
|
|
if (!mSink || !(mSinkMask & TS_AS_SEL_CHANGE)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some TIPs are confused by selection change notification during composition.
|
|
|
|
// Especially, some of them stop working for composition in our process.
|
|
|
|
// For preventing it, let's commit the composition.
|
|
|
|
if (mComposition.IsComposing()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(), "
|
|
|
|
"committing the composition for avoiding making TIP confused...",
|
|
|
|
this));
|
|
|
|
CommitCompositionInternal(false);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsRecordingActionsWithoutLock) {
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(), calling "
|
|
|
|
"mSink->OnSelectionChange()...", this));
|
2014-01-23 01:36:01 -08:00
|
|
|
mSink->OnSelectionChange();
|
|
|
|
} else {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::OnSelectionChangeInternal(), pending "
|
|
|
|
"a call of mSink->OnSelectionChange()...", this));
|
2014-02-04 23:36:17 -08:00
|
|
|
mPendingOnSelectionChange = true;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-23 22:36:20 -08:00
|
|
|
nsresult
|
2014-02-27 23:45:16 -08:00
|
|
|
nsTextStore::OnLayoutChangeInternal()
|
2009-02-23 22:36:20 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mContext, NS_ERROR_FAILURE);
|
|
|
|
NS_ENSURE_TRUE(mSink, NS_ERROR_FAILURE);
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-02-27 23:45:16 -08:00
|
|
|
("TSF: 0x%p nsTextStore::OnLayoutChangeInternal(), calling "
|
2012-09-11 16:53:12 -07:00
|
|
|
"mSink->OnLayoutChange()...", this));
|
2009-02-23 22:36:20 -08:00
|
|
|
HRESULT hr = mSink->OnLayoutChange(TS_LC_CHANGE, TEXTSTORE_DEFAULT_VIEW);
|
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-30 18:17:24 -08:00
|
|
|
void
|
|
|
|
nsTextStore::CreateNativeCaret()
|
|
|
|
{
|
|
|
|
// This method must work only on desktop application.
|
|
|
|
if (XRE_GetWindowsEnvironment() != WindowsEnvironmentType_Desktop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::CreateNativeCaret(), "
|
2014-01-30 18:17:24 -08:00
|
|
|
"mComposition.IsComposing()=%s",
|
|
|
|
this, GetBoolName(mComposition.IsComposing())));
|
|
|
|
|
|
|
|
Selection& currentSel = CurrentSelection();
|
|
|
|
if (currentSel.IsDirty()) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to "
|
|
|
|
"CurrentSelection() failure", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX If this is called without composition and the selection isn't
|
|
|
|
// collapsed, is it OK?
|
|
|
|
uint32_t caretOffset = currentSel.MaxOffset();
|
|
|
|
|
|
|
|
WidgetQueryContentEvent queryCaretRect(true, NS_QUERY_CARET_RECT, mWidget);
|
|
|
|
queryCaretRect.InitForQueryCaretRect(caretOffset);
|
|
|
|
mWidget->InitEvent(queryCaretRect);
|
|
|
|
mWidget->DispatchWindowEvent(&queryCaretRect);
|
|
|
|
if (!queryCaretRect.mSucceeded) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to "
|
|
|
|
"NS_QUERY_CARET_RECT failure (offset=%d)", this, caretOffset));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect& caretRect = queryCaretRect.mReply.mRect;
|
|
|
|
mNativeCaretIsCreated = ::CreateCaret(mWidget->GetWindowHandle(), nullptr,
|
|
|
|
caretRect.width, caretRect.height);
|
|
|
|
if (!mNativeCaretIsCreated) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to "
|
|
|
|
"CreateCaret() failure", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow* window = static_cast<nsWindow*>(mWidget.get());
|
|
|
|
nsWindow* toplevelWindow = window->GetTopLevelWindow(false);
|
|
|
|
if (!toplevelWindow) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::CreateNativeCaret() FAILED due to "
|
|
|
|
"no top level window", this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toplevelWindow != window) {
|
|
|
|
caretRect.MoveBy(toplevelWindow->WidgetToScreenOffset());
|
|
|
|
caretRect.MoveBy(-window->WidgetToScreenOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
::SetCaretPos(caretRect.x, caretRect.y);
|
|
|
|
}
|
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
bool
|
|
|
|
nsTextStore::EnsureInitActiveTIPKeyboard()
|
|
|
|
{
|
|
|
|
if (mOnActivatedCalled) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsVistaOrLater()) {
|
|
|
|
nsRefPtr<ITfInputProcessorProfileMgr> profileMgr;
|
|
|
|
HRESULT hr =
|
|
|
|
sInputProcessorProfiles->QueryInterface(IID_ITfInputProcessorProfileMgr,
|
|
|
|
getter_AddRefs(profileMgr));
|
|
|
|
if (FAILED(hr) || !profileMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), FAILED "
|
|
|
|
"to get input processor profile manager, hr=0x%08X", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TF_INPUTPROCESSORPROFILE profile;
|
|
|
|
hr = profileMgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &profile);
|
|
|
|
if (hr == S_FALSE) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), FAILED "
|
|
|
|
"to get active keyboard layout profile due to no active profile, "
|
|
|
|
"hr=0x%08X", this, hr));
|
|
|
|
// XXX Should we call OnActivated() with arguments like non-TIP in this
|
|
|
|
// case?
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), FAILED "
|
|
|
|
"to get active TIP keyboard, hr=0x%08X", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), "
|
|
|
|
"calling OnActivated() manually...", this));
|
|
|
|
OnActivated(profile.dwProfileType, profile.langid, profile.clsid,
|
|
|
|
profile.catid, profile.guidProfile, ::GetKeyboardLayout(0),
|
|
|
|
TF_IPSINK_FLAG_ACTIVE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
LANGID langID;
|
|
|
|
HRESULT hr = sInputProcessorProfiles->GetCurrentLanguage(&langID);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), FAILED "
|
|
|
|
"to get current language ID, hr=0x%08X", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IEnumTfLanguageProfiles> enumLangProfiles;
|
|
|
|
hr = sInputProcessorProfiles->EnumLanguageProfiles(langID,
|
|
|
|
getter_AddRefs(enumLangProfiles));
|
|
|
|
if (FAILED(hr) || !enumLangProfiles) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), FAILED "
|
|
|
|
"to get language profiles enumerator, hr=0x%08X", this, hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TF_LANGUAGEPROFILE profile;
|
|
|
|
ULONG fetch = 0;
|
|
|
|
while (SUCCEEDED(enumLangProfiles->Next(1, &profile, &fetch)) && fetch) {
|
|
|
|
if (!profile.fActive || profile.catid != GUID_TFCAT_TIP_KEYBOARD) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), "
|
|
|
|
"calling OnActivated() manually...", this));
|
|
|
|
bool isTIP = profile.guidProfile != GUID_NULL;
|
|
|
|
OnActivated(isTIP ? TF_PROFILETYPE_INPUTPROCESSOR :
|
|
|
|
TF_PROFILETYPE_KEYBOARDLAYOUT,
|
|
|
|
profile.langid, profile.clsid, profile.catid,
|
|
|
|
profile.guidProfile, ::GetKeyboardLayout(0),
|
|
|
|
TF_IPSINK_FLAG_ACTIVE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::EnsureInitActiveLanguageProfile(), "
|
|
|
|
"calling OnActivated() without active TIP manually...", this));
|
|
|
|
OnActivated(TF_PROFILETYPE_KEYBOARDLAYOUT,
|
|
|
|
langID, CLSID_NULL, GUID_TFCAT_TIP_KEYBOARD,
|
|
|
|
GUID_NULL, ::GetKeyboardLayout(0),
|
|
|
|
TF_IPSINK_FLAG_ACTIVE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-10 12:56:51 -08:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTextStore::CommitCompositionInternal(bool aDiscard)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: 0x%p nsTextStore::CommitCompositionInternal(aDiscard=%s), "
|
2013-03-12 20:01:29 -07:00
|
|
|
"mSink=0x%p, mContext=0x%p, mComposition.mView=0x%p, "
|
2013-03-12 20:01:29 -07:00
|
|
|
"mComposition.mString=\"%s\"",
|
2013-03-12 20:01:29 -07:00
|
|
|
this, GetBoolName(aDiscard), mSink.get(), mContext.get(),
|
|
|
|
mComposition.mView.get(),
|
2013-03-12 20:01:29 -07:00
|
|
|
NS_ConvertUTF16toUTF8(mComposition.mString).get()));
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
if (mComposition.IsComposing() && aDiscard) {
|
2013-03-12 20:01:30 -07:00
|
|
|
LONG endOffset = mComposition.EndOffset();
|
2013-03-12 20:01:29 -07:00
|
|
|
mComposition.mString.Truncate(0);
|
2009-02-10 12:56:51 -08:00
|
|
|
if (mSink && !mLock) {
|
|
|
|
TS_TEXTCHANGE textChange;
|
2013-03-12 20:01:29 -07:00
|
|
|
textChange.acpStart = mComposition.mStart;
|
2013-03-12 20:01:30 -07:00
|
|
|
textChange.acpOldEnd = endOffset;
|
2013-03-12 20:01:29 -07:00
|
|
|
textChange.acpNewEnd = mComposition.mStart;
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: 0x%p nsTextStore::CommitCompositionInternal(), calling"
|
|
|
|
"mSink->OnTextChange(0, { acpStart=%ld, acpOldEnd=%ld, "
|
|
|
|
"acpNewEnd=%ld })...", this, textChange.acpStart,
|
|
|
|
textChange.acpOldEnd, textChange.acpNewEnd));
|
2009-02-10 12:56:51 -08:00
|
|
|
mSink->OnTextChange(0, &textChange);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Terminate two contexts, the base context (mContext) and the top
|
|
|
|
// if the top context is not the same as the base context
|
|
|
|
nsRefPtr<ITfContext> context = mContext;
|
|
|
|
do {
|
|
|
|
if (context) {
|
|
|
|
nsRefPtr<ITfContextOwnerCompositionServices> services;
|
|
|
|
context->QueryInterface(IID_ITfContextOwnerCompositionServices,
|
|
|
|
getter_AddRefs(services));
|
2012-09-11 16:53:12 -07:00
|
|
|
if (services) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: 0x%p nsTextStore::CommitCompositionInternal(), "
|
|
|
|
"requesting TerminateComposition() for the context 0x%p...",
|
2012-09-14 07:13:46 -07:00
|
|
|
this, context.get()));
|
2013-10-08 11:48:20 -07:00
|
|
|
services->TerminateComposition(nullptr);
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
if (context != mContext)
|
|
|
|
break;
|
|
|
|
if (mDocumentMgr)
|
|
|
|
mDocumentMgr->GetTop(getter_AddRefs(context));
|
|
|
|
} while (context != mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-02-10 12:56:51 -08:00
|
|
|
GetCompartment(IUnknown* pUnk,
|
|
|
|
const GUID& aID,
|
|
|
|
ITfCompartment** aCompartment)
|
|
|
|
{
|
2011-10-01 19:16:19 -07:00
|
|
|
if (!pUnk) return false;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfCompartmentMgr> compMgr;
|
|
|
|
pUnk->QueryInterface(IID_ITfCompartmentMgr, getter_AddRefs(compMgr));
|
2011-10-01 19:16:19 -07:00
|
|
|
if (!compMgr) return false;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
return SUCCEEDED(compMgr->GetCompartment(aID, aCompartment)) &&
|
2013-10-08 11:48:20 -07:00
|
|
|
(*aCompartment) != nullptr;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// static
|
2009-02-10 12:56:51 -08:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTextStore::SetIMEOpenState(bool aState)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: nsTextStore::SetIMEOpenState(aState=%s)", GetBoolName(aState)));
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfCompartment> comp;
|
|
|
|
if (!GetCompartment(sTsfThreadMgr,
|
|
|
|
GUID_COMPARTMENT_KEYBOARD_OPENCLOSE,
|
2012-09-11 16:53:12 -07:00
|
|
|
getter_AddRefs(comp))) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: nsTextStore::SetIMEOpenState() FAILED due to"
|
|
|
|
"no compartment available"));
|
2009-02-10 12:56:51 -08:00
|
|
|
return;
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
VARIANT variant;
|
|
|
|
variant.vt = VT_I4;
|
|
|
|
variant.lVal = aState;
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: nsTextStore::SetIMEOpenState(), setting "
|
|
|
|
"0x%04X to GUID_COMPARTMENT_KEYBOARD_OPENCLOSE...",
|
|
|
|
variant.lVal));
|
2009-02-10 12:56:51 -08:00
|
|
|
comp->SetValue(sTsfClientId, &variant);
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// static
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-02-10 12:56:51 -08:00
|
|
|
nsTextStore::GetIMEOpenState(void)
|
|
|
|
{
|
|
|
|
nsRefPtr<ITfCompartment> comp;
|
|
|
|
if (!GetCompartment(sTsfThreadMgr,
|
|
|
|
GUID_COMPARTMENT_KEYBOARD_OPENCLOSE,
|
|
|
|
getter_AddRefs(comp)))
|
2011-10-01 19:16:19 -07:00
|
|
|
return false;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
VARIANT variant;
|
|
|
|
::VariantInit(&variant);
|
|
|
|
if (SUCCEEDED(comp->GetValue(&variant)) && variant.vt == VT_I4)
|
|
|
|
return variant.lVal != 0;
|
|
|
|
|
|
|
|
::VariantClear(&variant); // clear up in case variant.vt != VT_I4
|
2011-10-01 19:16:19 -07:00
|
|
|
return false;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2013-03-26 17:04:02 -07:00
|
|
|
// static
|
2009-02-10 12:56:51 -08:00
|
|
|
void
|
2013-03-26 17:04:02 -07:00
|
|
|
nsTextStore::SetInputContext(nsWindowBase* aWidget,
|
|
|
|
const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
2013-03-26 17:04:02 -07:00
|
|
|
("TSF: nsTextStore::SetInputContext(aWidget=%p, "
|
|
|
|
"aContext.mIMEState.mEnabled=%s, aAction.mFocusChange=%s), "
|
|
|
|
"ThinksHavingFocus()=%s",
|
|
|
|
aWidget, GetIMEEnabledName(aContext.mIMEState.mEnabled),
|
|
|
|
GetFocusChangeName(aAction.mFocusChange),
|
|
|
|
GetBoolName(ThinksHavingFocus())));
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-26 17:04:02 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(sTsfTextStore);
|
|
|
|
sTsfTextStore->SetInputScope(aContext.mHTMLInputType);
|
|
|
|
|
|
|
|
if (aAction.mFocusChange != InputContextAction::FOCUS_NOT_CHANGED) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If focus isn't actually changed but the enabled state is changed,
|
|
|
|
// emulate the focus move.
|
|
|
|
if (!ThinksHavingFocus() &&
|
|
|
|
aContext.mIMEState.mEnabled == IMEState::ENABLED) {
|
|
|
|
OnFocusChange(true, aWidget, aContext.mIMEState.mEnabled);
|
|
|
|
} else if (ThinksHavingFocus() &&
|
|
|
|
aContext.mIMEState.mEnabled != IMEState::ENABLED) {
|
|
|
|
OnFocusChange(false, aWidget, aContext.mIMEState.mEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsTextStore::MarkContextAsKeyboardDisabled(ITfContext* aContext)
|
|
|
|
{
|
|
|
|
VARIANT variant_int4_value1;
|
|
|
|
variant_int4_value1.vt = VT_I4;
|
|
|
|
variant_int4_value1.lVal = 1;
|
2009-02-10 12:56:51 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfCompartment> comp;
|
2013-03-26 17:04:02 -07:00
|
|
|
if (!GetCompartment(aContext,
|
|
|
|
GUID_COMPARTMENT_KEYBOARD_DISABLED,
|
|
|
|
getter_AddRefs(comp))) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::MarkContextAsKeyboardDisabled() failed"
|
|
|
|
"aContext=0x%p...", aContext));
|
|
|
|
return;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
|
2013-03-26 17:04:02 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: nsTextStore::MarkContextAsKeyboardDisabled(), setting "
|
|
|
|
"to disable context 0x%p...",
|
|
|
|
aContext));
|
|
|
|
comp->SetValue(sTsfClientId, &variant_int4_value1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsTextStore::MarkContextAsEmpty(ITfContext* aContext)
|
|
|
|
{
|
|
|
|
VARIANT variant_int4_value1;
|
|
|
|
variant_int4_value1.vt = VT_I4;
|
|
|
|
variant_int4_value1.lVal = 1;
|
|
|
|
|
|
|
|
nsRefPtr<ITfCompartment> comp;
|
|
|
|
if (!GetCompartment(aContext,
|
|
|
|
GUID_COMPARTMENT_EMPTYCONTEXT,
|
|
|
|
getter_AddRefs(comp))) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::MarkContextAsEmpty() failed"
|
|
|
|
"aContext=0x%p...", aContext));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_DEBUG,
|
|
|
|
("TSF: nsTextStore::MarkContextAsEmpty(), setting "
|
|
|
|
"to mark empty context 0x%p...", aContext));
|
|
|
|
comp->SetValue(sTsfClientId, &variant_int4_value1);
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
nsTextStore::IsTIPCategoryKeyboard(REFCLSID aTextService, LANGID aLangID,
|
|
|
|
REFGUID aProfile)
|
|
|
|
{
|
|
|
|
if (aTextService == CLSID_NULL || aProfile == GUID_NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IEnumTfLanguageProfiles> enumLangProfiles;
|
|
|
|
HRESULT hr =
|
|
|
|
sInputProcessorProfiles->EnumLanguageProfiles(aLangID,
|
|
|
|
getter_AddRefs(enumLangProfiles));
|
|
|
|
if (FAILED(hr) || !enumLangProfiles) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::IsTIPCategoryKeyboard(), FAILED "
|
|
|
|
"to get language profiles enumerator, hr=0x%08X", hr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TF_LANGUAGEPROFILE profile;
|
|
|
|
ULONG fetch = 0;
|
|
|
|
while (SUCCEEDED(enumLangProfiles->Next(1, &profile, &fetch)) && fetch) {
|
|
|
|
// XXX We're not sure a profile is registered with two or more categories.
|
|
|
|
if (profile.clsid == aTextService &&
|
|
|
|
profile.guidProfile == aProfile &&
|
|
|
|
profile.catid == GUID_TFCAT_TIP_KEYBOARD) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsTextStore::GetTIPDescription(REFCLSID aTextService, LANGID aLangID,
|
|
|
|
REFGUID aProfile, nsAString& aDescription)
|
|
|
|
{
|
|
|
|
aDescription.Truncate();
|
|
|
|
|
|
|
|
if (aTextService == CLSID_NULL || aProfile == GUID_NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BSTR description = nullptr;
|
|
|
|
HRESULT hr =
|
|
|
|
sInputProcessorProfiles->GetLanguageProfileDescription(aTextService,
|
|
|
|
aLangID,
|
|
|
|
aProfile,
|
|
|
|
&description);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: nsTextStore::InitActiveTIPDescription() FAILED due to "
|
2014-01-30 18:17:25 -08:00
|
|
|
"GetLanguageProfileDescription() failure, hr=0x%08X", hr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (description && description[0]) {
|
|
|
|
aDescription.Assign(description);
|
|
|
|
}
|
|
|
|
::SysFreeString(description);
|
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// static
|
2009-02-10 12:56:51 -08:00
|
|
|
void
|
2014-01-21 04:33:52 -08:00
|
|
|
nsTextStore::Initialize()
|
2009-02-10 12:56:51 -08:00
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
2012-09-11 16:53:12 -07:00
|
|
|
if (!sTextStoreLog) {
|
2009-02-10 12:56:51 -08:00
|
|
|
sTextStoreLog = PR_NewLogModule("nsTextStoreWidgets");
|
2012-09-11 16:53:12 -07:00
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
#endif
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: nsTextStore::Initialize() is called..."));
|
|
|
|
|
|
|
|
if (sTsfThreadMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED due to already initialized"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-13 18:00:59 -08:00
|
|
|
bool enableTsf = Preferences::GetBool(kPrefNameTSFEnabled, false);
|
|
|
|
// Migrate legacy TSF pref to new pref. This should be removed in next
|
|
|
|
// release cycle or later.
|
|
|
|
if (!enableTsf && Preferences::GetBool(kLegacyPrefNameTSFEnabled, false)) {
|
|
|
|
enableTsf = true;
|
|
|
|
Preferences::SetBool(kPrefNameTSFEnabled, true);
|
|
|
|
Preferences::ClearUser(kLegacyPrefNameTSFEnabled);
|
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
2014-01-21 04:33:52 -08:00
|
|
|
("TSF: nsTextStore::Initialize(), TSF is %s",
|
2012-09-11 16:53:12 -07:00
|
|
|
enableTsf ? "enabled" : "disabled"));
|
|
|
|
if (!enableTsf) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-13 18:01:00 -08:00
|
|
|
// XXX MSDN documents that ITfInputProcessorProfiles is available only on
|
|
|
|
// desktop apps. However, there is no known way to obtain
|
|
|
|
// ITfInputProcessorProfileMgr instance without ITfInputProcessorProfiles
|
|
|
|
// instance.
|
2014-01-21 04:33:52 -08:00
|
|
|
nsRefPtr<ITfInputProcessorProfiles> inputProcessorProfiles;
|
2014-01-13 18:01:00 -08:00
|
|
|
HRESULT hr =
|
|
|
|
::CoCreateInstance(CLSID_TF_InputProcessorProfiles, nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER,
|
|
|
|
IID_ITfInputProcessorProfiles,
|
2014-01-21 04:33:52 -08:00
|
|
|
getter_AddRefs(inputProcessorProfiles));
|
|
|
|
if (FAILED(hr) || !inputProcessorProfiles) {
|
2014-01-13 18:01:00 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to create input processor "
|
2014-01-21 04:33:52 -08:00
|
|
|
"profiles, hr=0x%08X", hr));
|
2014-01-13 18:01:00 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
nsRefPtr<ITfThreadMgr> threadMgr;
|
|
|
|
hr = ::CoCreateInstance(CLSID_TF_ThreadMgr, nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER, IID_ITfThreadMgr,
|
|
|
|
getter_AddRefs(threadMgr));
|
|
|
|
if (FAILED(hr) || !threadMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to "
|
|
|
|
"create the thread manager, hr=0x%08X", hr));
|
|
|
|
return;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2014-01-21 04:33:52 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfMessagePump> messagePump;
|
|
|
|
hr = threadMgr->QueryInterface(IID_ITfMessagePump,
|
|
|
|
getter_AddRefs(messagePump));
|
|
|
|
if (FAILED(hr) || !messagePump) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to "
|
|
|
|
"QI message pump from the thread manager, hr=0x%08X", hr));
|
|
|
|
return;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2014-01-21 04:33:52 -08:00
|
|
|
|
|
|
|
nsRefPtr<ITfKeystrokeMgr> keystrokeMgr;
|
|
|
|
hr = threadMgr->QueryInterface(IID_ITfKeystrokeMgr,
|
|
|
|
getter_AddRefs(keystrokeMgr));
|
|
|
|
if (FAILED(hr) || !keystrokeMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to "
|
|
|
|
"QI keystroke manager from the thread manager, hr=0x%08X", hr));
|
|
|
|
return;
|
2009-02-23 00:56:33 -08:00
|
|
|
}
|
2014-01-21 04:33:52 -08:00
|
|
|
|
|
|
|
hr = threadMgr->Activate(&sTsfClientId);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to activate, hr=0x%08X", hr));
|
|
|
|
return;
|
2009-02-23 00:56:33 -08:00
|
|
|
}
|
2013-03-26 17:04:02 -07:00
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
nsRefPtr<ITfDisplayAttributeMgr> displayAttributeMgr;
|
|
|
|
hr = ::CoCreateInstance(CLSID_TF_DisplayAttributeMgr, nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER, IID_ITfDisplayAttributeMgr,
|
|
|
|
getter_AddRefs(displayAttributeMgr));
|
|
|
|
if (FAILED(hr) || !displayAttributeMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to create "
|
|
|
|
"a display attribute manager instance, hr=0x%08X", hr));
|
|
|
|
return;
|
2013-03-26 17:04:02 -07:00
|
|
|
}
|
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
nsRefPtr<ITfCategoryMgr> categoryMgr;
|
|
|
|
hr = ::CoCreateInstance(CLSID_TF_CategoryMgr, nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr,
|
|
|
|
getter_AddRefs(categoryMgr));
|
|
|
|
if (FAILED(hr) || !categoryMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to create "
|
|
|
|
"a category manager instance, hr=0x%08X", hr));
|
|
|
|
return;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2012-09-11 16:53:12 -07:00
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
nsRefPtr<ITfDocumentMgr> disabledDocumentMgr;
|
|
|
|
hr = threadMgr->CreateDocumentMgr(getter_AddRefs(disabledDocumentMgr));
|
|
|
|
if (FAILED(hr) || !disabledDocumentMgr) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to create "
|
|
|
|
"a document manager for disabled mode, hr=0x%08X", hr));
|
|
|
|
return;
|
2013-03-17 21:41:24 -07:00
|
|
|
}
|
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
nsRefPtr<ITfContext> disabledContext;
|
|
|
|
DWORD editCookie = 0;
|
|
|
|
hr = disabledDocumentMgr->CreateContext(sTsfClientId, 0, nullptr,
|
|
|
|
getter_AddRefs(disabledContext),
|
|
|
|
&editCookie);
|
|
|
|
if (FAILED(hr) || !disabledContext) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to create "
|
|
|
|
"a context for disabled mode, hr=0x%08X", hr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkContextAsKeyboardDisabled(disabledContext);
|
|
|
|
MarkContextAsEmpty(disabledContext);
|
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: nsTextStore::Initialize() is creating "
|
|
|
|
"an nsTextStore instance..."));
|
|
|
|
nsRefPtr<nsTextStore> textStore = new nsTextStore();
|
|
|
|
if (!textStore->Init(threadMgr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::Initialize() FAILED to initialize nsTextStore "
|
|
|
|
"instance"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-21 04:33:52 -08:00
|
|
|
inputProcessorProfiles.swap(sInputProcessorProfiles);
|
|
|
|
threadMgr.swap(sTsfThreadMgr);
|
|
|
|
messagePump.swap(sMessagePump);
|
|
|
|
keystrokeMgr.swap(sKeystrokeMgr);
|
|
|
|
displayAttributeMgr.swap(sDisplayAttrMgr);
|
|
|
|
categoryMgr.swap(sCategoryMgr);
|
|
|
|
disabledDocumentMgr.swap(sTsfDisabledDocumentMgr);
|
|
|
|
disabledContext.swap(sTsfDisabledContext);
|
2014-01-30 18:17:25 -08:00
|
|
|
textStore.swap(sTsfTextStore);
|
2014-01-21 04:33:52 -08:00
|
|
|
|
2014-01-30 18:17:25 -08:00
|
|
|
sCreateNativeCaretForATOK =
|
|
|
|
Preferences::GetBool("intl.tsf.hack.atok.create_native_caret", true);
|
2014-01-21 04:33:52 -08:00
|
|
|
|
|
|
|
MOZ_ASSERT(!sFlushTIPInputMessage);
|
|
|
|
sFlushTIPInputMessage = ::RegisterWindowMessageW(L"Flush TIP Input Message");
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS,
|
|
|
|
("TSF: nsTextStore::Initialize(), sTsfThreadMgr=0x%p, "
|
|
|
|
"sTsfClientId=0x%08X, sTsfTextStore=0x%p, sDisplayAttrMgr=0x%p, "
|
2014-01-30 18:17:25 -08:00
|
|
|
"sCategoryMgr=0x%p, sTsfDisabledDocumentMgr=0x%p, sTsfDisabledContext=%p, "
|
|
|
|
"sCreateNativeCaretForATOK=%s",
|
2013-03-26 17:04:02 -07:00
|
|
|
sTsfThreadMgr, sTsfClientId, sTsfTextStore, sDisplayAttrMgr, sCategoryMgr,
|
2014-01-30 18:17:25 -08:00
|
|
|
sTsfDisabledDocumentMgr, sTsfDisabledContext,
|
|
|
|
GetBoolName(sCreateNativeCaretForATOK)));
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
|
|
|
|
2012-09-11 16:53:12 -07:00
|
|
|
// static
|
2009-02-10 12:56:51 -08:00
|
|
|
void
|
|
|
|
nsTextStore::Terminate(void)
|
|
|
|
{
|
2012-09-11 16:53:12 -07:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ALWAYS, ("TSF: nsTextStore::Terminate()"));
|
|
|
|
|
2009-02-23 00:56:33 -08:00
|
|
|
NS_IF_RELEASE(sDisplayAttrMgr);
|
|
|
|
NS_IF_RELEASE(sCategoryMgr);
|
2009-02-10 12:56:51 -08:00
|
|
|
NS_IF_RELEASE(sTsfTextStore);
|
2013-03-26 17:04:02 -07:00
|
|
|
NS_IF_RELEASE(sTsfDisabledDocumentMgr);
|
|
|
|
NS_IF_RELEASE(sTsfDisabledContext);
|
2014-01-13 18:01:00 -08:00
|
|
|
NS_IF_RELEASE(sInputProcessorProfiles);
|
2012-09-11 16:53:12 -07:00
|
|
|
sTsfClientId = 0;
|
2009-02-10 12:56:51 -08:00
|
|
|
if (sTsfThreadMgr) {
|
|
|
|
sTsfThreadMgr->Deactivate();
|
|
|
|
NS_RELEASE(sTsfThreadMgr);
|
2013-03-17 21:41:24 -07:00
|
|
|
NS_RELEASE(sMessagePump);
|
|
|
|
NS_RELEASE(sKeystrokeMgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
nsTextStore::ProcessRawKeyMessage(const MSG& aMsg)
|
|
|
|
{
|
|
|
|
if (!sKeystrokeMgr) {
|
|
|
|
return false; // not in TSF mode
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2013-03-17 21:41:24 -07:00
|
|
|
|
|
|
|
if (aMsg.message == WM_KEYDOWN) {
|
|
|
|
BOOL eaten;
|
|
|
|
HRESULT hr = sKeystrokeMgr->TestKeyDown(aMsg.wParam, aMsg.lParam, &eaten);
|
|
|
|
if (FAILED(hr) || !eaten) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hr = sKeystrokeMgr->KeyDown(aMsg.wParam, aMsg.lParam, &eaten);
|
|
|
|
return SUCCEEDED(hr) && eaten;
|
|
|
|
}
|
|
|
|
if (aMsg.message == WM_KEYUP) {
|
|
|
|
BOOL eaten;
|
|
|
|
HRESULT hr = sKeystrokeMgr->TestKeyUp(aMsg.wParam, aMsg.lParam, &eaten);
|
|
|
|
if (FAILED(hr) || !eaten) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hr = sKeystrokeMgr->KeyUp(aMsg.wParam, aMsg.lParam, &eaten);
|
|
|
|
return SUCCEEDED(hr) && eaten;
|
|
|
|
}
|
|
|
|
return false;
|
2009-02-10 12:56:51 -08:00
|
|
|
}
|
2013-02-24 20:00:05 -08:00
|
|
|
|
2014-01-13 18:01:00 -08:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsTextStore::ProcessMessage(nsWindowBase* aWindow, UINT aMessage,
|
|
|
|
WPARAM& aWParam, LPARAM& aLParam,
|
|
|
|
MSGResult& aResult)
|
|
|
|
{
|
|
|
|
switch (aMessage) {
|
|
|
|
case WM_IME_SETCONTEXT:
|
|
|
|
// If a windowless plugin had focus and IME was handled on it, composition
|
|
|
|
// window was set the position. After that, even in TSF mode, WinXP keeps
|
|
|
|
// to use composition window at the position if the active IME is not
|
|
|
|
// aware TSF. For avoiding this issue, we need to hide the composition
|
|
|
|
// window here.
|
|
|
|
if (aWParam) {
|
|
|
|
aLParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
/******************************************************************/
|
|
|
|
/* nsTextStore::Composition */
|
|
|
|
/******************************************************************/
|
|
|
|
|
2013-03-12 20:01:29 -07:00
|
|
|
void
|
2013-03-12 20:01:29 -07:00
|
|
|
nsTextStore::Composition::Start(ITfCompositionView* aCompositionView,
|
|
|
|
LONG aCompositionStartOffset,
|
|
|
|
const nsAString& aCompositionString)
|
2013-03-12 20:01:29 -07:00
|
|
|
{
|
2013-03-12 20:01:29 -07:00
|
|
|
mView = aCompositionView;
|
|
|
|
mString = aCompositionString;
|
|
|
|
mStart = aCompositionStartOffset;
|
2013-03-12 20:01:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStore::Composition::End()
|
|
|
|
{
|
|
|
|
mView = nullptr;
|
|
|
|
mString.Truncate();
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:01:30 -07:00
|
|
|
/******************************************************************************
|
|
|
|
* nsTextStore::Content
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
const nsDependentSubstring
|
|
|
|
nsTextStore::Content::GetSelectedText() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
return GetSubstring(static_cast<uint32_t>(mSelection.StartOffset()),
|
|
|
|
static_cast<uint32_t>(mSelection.Length()));
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsDependentSubstring
|
|
|
|
nsTextStore::Content::GetSubstring(uint32_t aStart, uint32_t aLength) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
return nsDependentSubstring(mText, aStart, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStore::Content::ReplaceSelectedTextWith(const nsAString& aString)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
ReplaceTextWith(mSelection.StartOffset(), mSelection.Length(), aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t
|
|
|
|
FirstDifferentCharOffset(const nsAString& aStr1, const nsAString& aStr2)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aStr1 != aStr2);
|
|
|
|
uint32_t i = 0;
|
|
|
|
uint32_t minLength = std::min(aStr1.Length(), aStr2.Length());
|
|
|
|
for (; i < minLength && aStr1[i] == aStr2[i]; i++) {
|
|
|
|
/* nothing to do */
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength,
|
|
|
|
const nsAString& aReplaceString)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
const nsDependentSubstring replacedString =
|
|
|
|
GetSubstring(static_cast<uint32_t>(aStart),
|
|
|
|
static_cast<uint32_t>(aLength));
|
|
|
|
if (aReplaceString != replacedString) {
|
|
|
|
uint32_t firstDifferentOffset =
|
|
|
|
static_cast<uint32_t>(aStart) + FirstDifferentCharOffset(aReplaceString,
|
|
|
|
replacedString);
|
|
|
|
mMinTextModifiedOffset =
|
|
|
|
std::min(mMinTextModifiedOffset, firstDifferentOffset);
|
|
|
|
if (mComposition.IsComposing()) {
|
|
|
|
// Emulate text insertion during compositions, because during a
|
|
|
|
// composition, editor expects the whole composition string to
|
|
|
|
// be sent in NS_TEXT_TEXT, not just the inserted part.
|
|
|
|
// The actual NS_TEXT_TEXT will be sent in SetSelection or
|
|
|
|
// OnUpdateComposition.
|
|
|
|
MOZ_ASSERT(aStart >= mComposition.mStart);
|
|
|
|
MOZ_ASSERT(aStart + aLength <= mComposition.EndOffset());
|
|
|
|
mComposition.mString.Replace(
|
|
|
|
static_cast<uint32_t>(aStart - mComposition.mStart),
|
|
|
|
static_cast<uint32_t>(aLength), aReplaceString);
|
|
|
|
}
|
|
|
|
mText.Replace(static_cast<uint32_t>(aStart),
|
|
|
|
static_cast<uint32_t>(aLength), aReplaceString);
|
|
|
|
}
|
|
|
|
// Selection should be collapsed at the end of the inserted string.
|
|
|
|
mSelection.CollapseAt(
|
|
|
|
static_cast<uint32_t>(aStart) + aReplaceString.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStore::Content::StartComposition(ITfCompositionView* aCompositionView,
|
|
|
|
const PendingAction& aCompStart,
|
|
|
|
bool aPreserveSelection)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
MOZ_ASSERT(aCompositionView);
|
|
|
|
MOZ_ASSERT(!mComposition.mView);
|
|
|
|
MOZ_ASSERT(aCompStart.mType == PendingAction::COMPOSITION_START);
|
|
|
|
|
|
|
|
mComposition.Start(aCompositionView, aCompStart.mSelectionStart,
|
|
|
|
GetSubstring(static_cast<uint32_t>(aCompStart.mSelectionStart),
|
|
|
|
static_cast<uint32_t>(aCompStart.mSelectionLength)));
|
|
|
|
if (!aPreserveSelection) {
|
|
|
|
mSelection.SetSelection(mComposition.mStart, mComposition.mString.Length(),
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsTextStore::Content::EndComposition(const PendingAction& aCompEnd)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mInitialized);
|
|
|
|
MOZ_ASSERT(mComposition.mView);
|
|
|
|
MOZ_ASSERT(aCompEnd.mType == PendingAction::COMPOSITION_END);
|
|
|
|
|
|
|
|
mSelection.CollapseAt(mComposition.mStart + aCompEnd.mData.Length());
|
|
|
|
mComposition.End();
|
|
|
|
}
|
|
|
|
|
2013-02-24 20:00:05 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
nsTextStore::CurrentKeyboardLayoutHasIME()
|
|
|
|
{
|
2014-01-13 18:01:00 -08:00
|
|
|
if (!sInputProcessorProfiles) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
|
|
|
("TSF: nsTextStore::CurrentKeyboardLayoutHasIME() FAILED due to there is "
|
|
|
|
"no input processor profiles instance"));
|
2013-02-24 20:00:05 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsRefPtr<ITfInputProcessorProfileMgr> profileMgr;
|
2014-01-13 18:01:00 -08:00
|
|
|
HRESULT hr =
|
|
|
|
sInputProcessorProfiles->QueryInterface(IID_ITfInputProcessorProfileMgr,
|
|
|
|
getter_AddRefs(profileMgr));
|
2013-02-24 20:00:05 -08:00
|
|
|
if (FAILED(hr) || !profileMgr) {
|
|
|
|
// On Windows Vista or later, ImmIsIME() API always returns true.
|
|
|
|
// If we failed to obtain the profile manager, we cannot know if current
|
|
|
|
// keyboard layout has IME.
|
2013-11-21 19:35:42 -08:00
|
|
|
if (IsVistaOrLater()) {
|
2013-02-24 20:00:05 -08:00
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: nsTextStore::CurrentKeyboardLayoutHasIME() FAILED to query "
|
2013-02-24 20:00:05 -08:00
|
|
|
"ITfInputProcessorProfileMgr"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If the profiles instance doesn't have ITfInputProcessorProfileMgr
|
|
|
|
// interface, that means probably we're running on WinXP or WinServer2003
|
|
|
|
// (except WinServer2003 R2). Then, we should use ImmIsIME().
|
|
|
|
return ::ImmIsIME(::GetKeyboardLayout(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TF_INPUTPROCESSORPROFILE profile;
|
|
|
|
hr = profileMgr->GetActiveProfile(GUID_TFCAT_TIP_KEYBOARD, &profile);
|
|
|
|
if (hr == S_FALSE) {
|
|
|
|
return false; // not found or not active
|
|
|
|
}
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
PR_LOG(sTextStoreLog, PR_LOG_ERROR,
|
2014-01-31 03:23:36 -08:00
|
|
|
("TSF: nsTextStore::CurrentKeyboardLayoutHasIME() FAILED to retreive "
|
2013-02-24 20:00:05 -08:00
|
|
|
"active profile"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (profile.dwProfileType == TF_PROFILETYPE_INPUTPROCESSOR);
|
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|