2009-05-04 02:20:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
#ifndef IMMHandler_h_
|
|
|
|
#define IMMHandler_h_
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include <windows.h>
|
2014-03-04 17:48:27 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2009-05-04 02:20:11 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2014-03-06 10:13:50 +04:00
|
|
|
#include "nsIWidget.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2016-03-16 07:47:48 +03:00
|
|
|
#include "mozilla/TextEventDispatcher.h"
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "nsRect.h"
|
2015-05-15 04:18:08 +03:00
|
|
|
#include "WritingModes.h"
|
2015-12-29 16:57:38 +03:00
|
|
|
#include "npapi.h"
|
2009-05-04 02:20:11 +04:00
|
|
|
|
|
|
|
class nsWindow;
|
2017-06-07 05:42:27 +03:00
|
|
|
class nsWindowBase;
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
struct MSGResult;
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
class IMEContext final
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-12-11 09:15:57 +03:00
|
|
|
IMEContext()
|
|
|
|
: mWnd(nullptr)
|
|
|
|
, mIMC(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
explicit IMEContext(HWND aWnd);
|
2017-06-07 05:42:27 +03:00
|
|
|
explicit IMEContext(nsWindowBase* aWindowBase);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
~IMEContext()
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-12-11 09:15:57 +03:00
|
|
|
Clear();
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HIMC get() const
|
|
|
|
{
|
|
|
|
return mIMC;
|
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:57 +03:00
|
|
|
void Init(HWND aWnd);
|
2017-06-07 05:42:27 +03:00
|
|
|
void Init(nsWindowBase* aWindowBase);
|
2015-12-11 09:15:57 +03:00
|
|
|
void Clear();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsValid() const
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
return !!mIMC;
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
void SetOpenState(bool aOpen) const
|
|
|
|
{
|
|
|
|
if (!mIMC) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
::ImmSetOpenStatus(mIMC, aOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetOpenState() const
|
|
|
|
{
|
|
|
|
if (!mIMC) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (::ImmGetOpenStatus(mIMC) != FALSE);
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
bool AssociateDefaultContext()
|
|
|
|
{
|
|
|
|
// We assume that there is only default IMC, no new IMC has been created.
|
|
|
|
if (mIMC) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-08 22:48:20 +04:00
|
|
|
if (!::ImmAssociateContextEx(mWnd, nullptr, IACE_DEFAULT)) {
|
2013-02-25 08:00:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mIMC = ::ImmGetContext(mWnd);
|
2013-10-08 22:48:20 +04:00
|
|
|
return (mIMC != nullptr);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Disassociate()
|
|
|
|
{
|
|
|
|
if (!mIMC) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-08 22:48:20 +04:00
|
|
|
if (!::ImmAssociateContextEx(mWnd, nullptr, 0)) {
|
2013-02-25 08:00:06 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
::ImmReleaseContext(mWnd, mIMC);
|
2013-10-08 22:48:20 +04:00
|
|
|
mIMC = nullptr;
|
2013-02-25 08:00:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
protected:
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext(const IMEContext& aOther)
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
2015-07-23 06:31:28 +03:00
|
|
|
MOZ_CRASH("Don't copy IMEContext");
|
2009-05-04 02:20:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HWND mWnd;
|
|
|
|
HIMC mIMC;
|
|
|
|
};
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
class IMMHandler final
|
2009-05-04 02:20:11 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void Initialize();
|
|
|
|
static void Terminate();
|
2013-07-18 12:12:31 +04:00
|
|
|
|
|
|
|
// If Process*() returns true, the caller shouldn't do anything anymore.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ProcessMessage(nsWindow* aWindow, UINT msg,
|
2013-07-18 12:12:31 +04:00
|
|
|
WPARAM& wParam, LPARAM& lParam,
|
|
|
|
MSGResult& aResult);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsComposing()
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
2015-12-29 16:57:37 +03:00
|
|
|
return IsComposingOnOurEditor();
|
2010-08-08 13:23:25 +04:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsComposingOn(nsWindow* aWindow)
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
|
|
|
return IsComposing() && IsComposingWindow(aWindow);
|
|
|
|
}
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2011-07-07 16:02:07 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
/**
|
|
|
|
* IsIMEAvailable() returns TRUE when current keyboard layout has IME.
|
|
|
|
* Otherwise, FALSE.
|
|
|
|
*/
|
2013-03-23 18:18:52 +04:00
|
|
|
static bool IsIMEAvailable() { return !!::ImmIsIME(::GetKeyboardLayout(0)); }
|
2011-07-07 16:02:07 +04:00
|
|
|
#endif
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
// If aForce is TRUE, these methods doesn't check whether we have composition
|
|
|
|
// or not. If you don't set it to TRUE, these method doesn't commit/cancel
|
|
|
|
// the composition on uexpected window.
|
2011-09-29 10:19:26 +04:00
|
|
|
static void CommitComposition(nsWindow* aWindow, bool aForce = false);
|
|
|
|
static void CancelComposition(nsWindow* aWindow, bool aForce = false);
|
2015-07-22 06:40:32 +03:00
|
|
|
static void OnFocusChange(bool aFocus, nsWindow* aWindow);
|
2014-01-16 14:05:09 +04:00
|
|
|
static void OnUpdateComposition(nsWindow* aWindow);
|
2015-05-15 04:18:08 +03:00
|
|
|
static void OnSelectionChange(nsWindow* aWindow,
|
2015-07-22 06:40:32 +03:00
|
|
|
const IMENotification& aIMENotification,
|
|
|
|
bool aIsIMMActive);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
2017-04-11 15:24:55 +03:00
|
|
|
static IMENotificationRequests GetIMENotificationRequests();
|
2014-03-06 10:13:50 +04:00
|
|
|
|
2014-09-11 07:41:15 +04:00
|
|
|
// Returns NS_SUCCESS_EVENT_CONSUMED if the mouse button event is consumed by
|
|
|
|
// IME. Otherwise, NS_OK.
|
|
|
|
static nsresult OnMouseButtonEvent(nsWindow* aWindow,
|
|
|
|
const IMENotification& aIMENotification);
|
2015-12-29 16:57:38 +03:00
|
|
|
static void SetCandidateWindow(nsWindow* aWindow, CANDIDATEFORM* aForm);
|
2015-12-29 16:57:38 +03:00
|
|
|
static void DefaultProcOfPluginEvent(nsWindow* aWindow,
|
|
|
|
const NPEvent* aEvent);
|
2014-09-11 07:41:15 +04:00
|
|
|
|
Bug 1409155 - IMEHandler should not associate IMC with any window if active IME is ATOK 2010 or earlier with x64 build on Win8 or later r=m_kato
ATOK started to be TIP of TSF since 2011. Older than it, i.e., ATOK 2010 and
earlier have a lot of problems even for daily use. Perhaps, the reason is
Win 8 has a lot of changes around IMM-IME support and TSF, and ATOK 2010 is
released earlier than Win 8.
ATOK 2006 crashes while converting a word with candidate window.
ATOK 2007 doesn't paint and resize suggest window and candidate window
correctly (showing white window or too big window).
ATOK 2008 and ATOK 2009 crash when user just opens their open state.
ATOK 2010 isn't installable newly on Win 7 or later, but we have a lot of
crash reports.
Note that ATOK 2006 is the first version supporting Win XP x64. So, ATOK 2005
must not support x64 apps.
Unfortunately, we cannot block loading DLLs of them. Therefore, IMEHandler
should disassociate IMC from active window when user changes active keyboard
layout to the legacy ATOK and not associate IME with any window when
SetInputContext() is called even with "enabled". Additionally, when user
changes active keyboard layout from the legacy ATOK to one of the other
keyboard layouts, IMEHandler should associate IMC with current window for
new active IME.
MozReview-Commit-ID: RVYwmYxzO7
--HG--
extra : rebase_source : c237a3aca6ceb6a1f7251bd9421e4b905be5bc6c
2017-10-25 17:51:27 +03:00
|
|
|
#define DECL_IS_IME_ACTIVE(aReadableName) \
|
|
|
|
static bool Is ## aReadableName ## Active(); \
|
|
|
|
|
|
|
|
// Japanese IMEs
|
|
|
|
DECL_IS_IME_ACTIVE(ATOK2006)
|
|
|
|
DECL_IS_IME_ACTIVE(ATOK2007)
|
|
|
|
DECL_IS_IME_ACTIVE(ATOK2008)
|
|
|
|
DECL_IS_IME_ACTIVE(ATOK2009)
|
|
|
|
DECL_IS_IME_ACTIVE(ATOK2010)
|
|
|
|
DECL_IS_IME_ACTIVE(GoogleJapaneseInput)
|
|
|
|
DECL_IS_IME_ACTIVE(Japanist2003)
|
|
|
|
|
|
|
|
#undef DECL_IS_IME_ACTIVE
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsActiveIMEInBlockList() returns true if we know active keyboard layout's
|
|
|
|
* IME has some crash bugs or something which make some damage to us. When
|
|
|
|
* this returns true, IMC shouldn't be associated with any windows.
|
|
|
|
*/
|
|
|
|
static bool IsActiveIMEInBlockList();
|
2017-09-29 09:15:14 +03:00
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
protected:
|
|
|
|
static void EnsureHandlerInstance();
|
2009-05-07 07:49:14 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsComposingOnOurEditor();
|
|
|
|
static bool IsComposingOnPlugin();
|
|
|
|
static bool IsComposingWindow(nsWindow* aWindow);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ShouldDrawCompositionStringOurselves();
|
2015-05-15 04:18:07 +03:00
|
|
|
static bool IsVerticalWritingSupported();
|
2015-05-15 04:18:08 +03:00
|
|
|
// aWindow can be nullptr if it's called without receiving WM_INPUTLANGCHANGE.
|
|
|
|
static void InitKeyboardLayout(nsWindow* aWindow, HKL aKeyboardLayout);
|
2009-05-07 07:49:14 +04:00
|
|
|
static UINT GetKeyboardCodePage();
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
/**
|
|
|
|
* Checks whether the window is top level window of the composing window.
|
|
|
|
* In this method, the top level window means in all windows, not only in all
|
|
|
|
* OUR windows. I.e., if the aWindow is embedded, this always returns FALSE.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsTopLevelWindowOfComposition(nsWindow* aWindow);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ProcessInputLangChangeMessage(nsWindow* aWindow,
|
2010-08-08 13:23:25 +04:00
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam,
|
2013-07-18 12:12:31 +04:00
|
|
|
MSGResult& aResult);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool ProcessMessageForPlugin(nsWindow* aWindow, UINT msg,
|
2009-05-04 02:20:11 +04:00
|
|
|
WPARAM &wParam, LPARAM &lParam,
|
2015-12-29 16:57:37 +03:00
|
|
|
bool &aRet, MSGResult& aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler();
|
|
|
|
~IMMHandler();
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
// On*() methods return true if the caller of message handler shouldn't do
|
|
|
|
// anything anymore. Otherwise, false.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool OnKeyDownEvent(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
2013-07-18 12:12:31 +04:00
|
|
|
MSGResult& aResult);
|
2010-06-02 06:14:11 +04:00
|
|
|
|
2013-07-18 12:12:31 +04:00
|
|
|
bool OnIMEStartComposition(nsWindow* aWindow, MSGResult& aResult);
|
2015-12-29 16:57:38 +03:00
|
|
|
void OnIMEStartCompositionOnPlugin(nsWindow* aWindow,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
2013-07-18 12:12:31 +04:00
|
|
|
bool OnIMEComposition(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
2015-12-29 16:57:38 +03:00
|
|
|
void OnIMECompositionOnPlugin(nsWindow* aWindow, WPARAM wParam,
|
|
|
|
LPARAM lParam);
|
2013-07-18 12:12:31 +04:00
|
|
|
bool OnIMEEndComposition(nsWindow* aWindow, MSGResult& aResult);
|
2015-12-29 16:57:38 +03:00
|
|
|
void OnIMEEndCompositionOnPlugin(nsWindow* aWindow, WPARAM wParam,
|
|
|
|
LPARAM lParam);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool OnIMERequest(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
2013-07-18 12:12:31 +04:00
|
|
|
MSGResult& aResult);
|
|
|
|
bool OnIMECharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
2013-07-18 12:12:31 +04:00
|
|
|
bool OnChar(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
|
|
|
bool OnCharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
|
|
|
void OnInputLangChange(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2009-05-07 07:49:14 +04:00
|
|
|
// These message handlers don't use instance members, we should not create
|
|
|
|
// the instance by the messages. So, they should be static.
|
2013-07-18 12:12:31 +04:00
|
|
|
static bool OnIMEChar(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
|
|
|
static bool OnIMESetContext(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool OnIMESetContextOnPlugin(nsWindow* aWindow,
|
2013-07-18 12:12:31 +04:00
|
|
|
WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
|
|
|
static bool OnIMECompositionFull(nsWindow* aWindow, MSGResult& aResult);
|
|
|
|
static bool OnIMENotify(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
|
|
|
static bool OnIMESelect(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
|
|
|
|
MSGResult& aResult);
|
2009-05-07 07:49:14 +04:00
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
// The result of Handle* method mean "Processed" when it's TRUE.
|
|
|
|
void HandleStartComposition(nsWindow* aWindow,
|
2015-07-23 06:31:28 +03:00
|
|
|
const IMEContext& aContext);
|
|
|
|
bool HandleComposition(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext,
|
|
|
|
LPARAM lParam);
|
2014-11-25 08:02:33 +03:00
|
|
|
// If aCommitString is null, this commits composition with the latest
|
|
|
|
// dispatched data. Otherwise, commits composition with the value.
|
|
|
|
void HandleEndComposition(nsWindow* aWindow,
|
|
|
|
const nsAString* aCommitString = nullptr);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HandleReconvert(nsWindow* aWindow, LPARAM lParam, LRESULT *oResult);
|
|
|
|
bool HandleQueryCharPosition(nsWindow* aWindow, LPARAM lParam,
|
2009-05-04 02:20:11 +04:00
|
|
|
LRESULT *oResult);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HandleDocumentFeed(nsWindow* aWindow, LPARAM lParam, LRESULT *oResult);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
/**
|
|
|
|
* When a window's IME context is activating but we have composition on
|
|
|
|
* another window, we should commit our composition because IME context is
|
|
|
|
* shared by all our windows (including plug-ins).
|
|
|
|
* @param aWindow is a new activated window.
|
|
|
|
* If aWindow is our composing window, this method does nothing.
|
|
|
|
* Otherwise, this commits the composition on the previous window.
|
|
|
|
* If this method did commit a composition, this returns TRUE.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CommitCompositionOnPreviousWindow(nsWindow* aWindow);
|
2010-08-08 13:23:25 +04:00
|
|
|
|
2009-05-04 02:20:11 +04:00
|
|
|
/**
|
|
|
|
* ResolveIMECaretPos
|
|
|
|
* Convert the caret rect of a composition event to another widget's
|
|
|
|
* coordinate system.
|
|
|
|
*
|
|
|
|
* @param aReferenceWidget The origin widget of aCursorRect.
|
|
|
|
* Typically, this is mReferenceWidget of the
|
|
|
|
* composing events. If the aCursorRect is in screen
|
2012-07-30 18:20:58 +04:00
|
|
|
* coordinates, set nullptr.
|
2009-05-04 02:20:11 +04:00
|
|
|
* @param aCursorRect The cursor rect.
|
|
|
|
* @param aNewOriginWidget aOutRect will be in this widget's coordinates. If
|
2012-07-30 18:20:58 +04:00
|
|
|
* this is nullptr, aOutRect will be in screen
|
2009-05-04 02:20:11 +04:00
|
|
|
* coordinates.
|
|
|
|
* @param aOutRect The converted cursor rect.
|
|
|
|
*/
|
|
|
|
void ResolveIMECaretPos(nsIWidget* aReferenceWidget,
|
2015-11-12 16:22:44 +03:00
|
|
|
mozilla::LayoutDeviceIntRect& aCursorRect,
|
2009-05-04 02:20:11 +04:00
|
|
|
nsIWidget* aNewOriginWidget,
|
2015-11-12 16:22:44 +03:00
|
|
|
mozilla::LayoutDeviceIntRect& aOutRect);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2017-06-20 12:19:05 +03:00
|
|
|
bool ConvertToANSIString(const nsString& aStr,
|
2009-05-04 02:20:11 +04:00
|
|
|
UINT aCodePage,
|
|
|
|
nsACString& aANSIStr);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool SetIMERelatedWindowsPos(nsWindow* aWindow,
|
2015-07-23 06:31:28 +03:00
|
|
|
const IMEContext& aContext);
|
2013-12-18 05:43:15 +04:00
|
|
|
void SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow,
|
2015-07-23 06:31:28 +03:00
|
|
|
const IMEContext& aContext);
|
2015-07-26 06:29:47 +03:00
|
|
|
/**
|
|
|
|
* GetCharacterRectOfSelectedTextAt() returns character rect of the offset
|
|
|
|
* from the selection start or the start of composition string if there is
|
|
|
|
* a composition.
|
|
|
|
*
|
|
|
|
* @param aWindow The window which has focus.
|
|
|
|
* @param aOffset Offset from the selection start or the start of
|
|
|
|
* composition string when there is a composition.
|
|
|
|
* This must be in the selection range or
|
|
|
|
* the composition string.
|
|
|
|
* @param aCharRect The result.
|
|
|
|
* @param aWritingMode The writing mode of current selection. When this
|
|
|
|
* is nullptr, this assumes that the selection is in
|
|
|
|
* horizontal writing mode.
|
|
|
|
* @return true if this succeeded to retrieve the rect.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
2015-05-15 04:18:07 +03:00
|
|
|
bool GetCharacterRectOfSelectedTextAt(
|
|
|
|
nsWindow* aWindow,
|
|
|
|
uint32_t aOffset,
|
2015-11-12 16:22:44 +03:00
|
|
|
mozilla::LayoutDeviceIntRect& aCharRect,
|
2015-05-15 04:18:07 +03:00
|
|
|
mozilla::WritingMode* aWritingMode = nullptr);
|
2015-07-26 06:29:47 +03:00
|
|
|
/**
|
|
|
|
* GetCaretRect() returns caret rect at current selection start.
|
|
|
|
*
|
|
|
|
* @param aWindow The window which has focus.
|
|
|
|
* @param aCaretRect The result.
|
|
|
|
* @param aWritingMode The writing mode of current selection. When this
|
|
|
|
* is nullptr, this assumes that the selection is in
|
|
|
|
* horizontal writing mode.
|
|
|
|
* @return true if this succeeded to retrieve the rect.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
2015-05-15 04:18:07 +03:00
|
|
|
bool GetCaretRect(nsWindow* aWindow,
|
2015-11-12 16:22:44 +03:00
|
|
|
mozilla::LayoutDeviceIntRect& aCaretRect,
|
2015-05-15 04:18:07 +03:00
|
|
|
mozilla::WritingMode* aWritingMode = nullptr);
|
2015-07-23 06:31:28 +03:00
|
|
|
void GetCompositionString(const IMEContext& aContext,
|
2014-11-25 08:02:33 +03:00
|
|
|
DWORD aIndex,
|
|
|
|
nsAString& aCompositionString) const;
|
2015-05-15 04:18:07 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* AdjustCompositionFont() makes IME vertical writing mode if it's supported.
|
2015-05-15 04:18:08 +03:00
|
|
|
* If aForceUpdate is true, it will update composition font even if writing
|
|
|
|
* mode isn't being changed.
|
2015-05-15 04:18:07 +03:00
|
|
|
*/
|
2015-12-29 16:57:37 +03:00
|
|
|
void AdjustCompositionFont(nsWindow* aWindow,
|
|
|
|
const IMEContext& aContext,
|
2015-05-15 04:18:08 +03:00
|
|
|
const mozilla::WritingMode& aWritingMode,
|
|
|
|
bool aForceUpdate = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MaybeAdjustCompositionFont() calls AdjustCompositionFont() when the
|
|
|
|
* locale of active IME is CJK. Note that this creates an instance even
|
|
|
|
* when there is no composition but the locale is CJK.
|
|
|
|
*/
|
|
|
|
static void MaybeAdjustCompositionFont(
|
|
|
|
nsWindow* aWindow,
|
|
|
|
const mozilla::WritingMode& aWritingMode,
|
|
|
|
bool aForceUpdate = false);
|
|
|
|
|
2009-12-17 07:40:24 +03:00
|
|
|
/**
|
|
|
|
* Get the current target clause of composition string.
|
|
|
|
* If there are one or more characters whose attribute is ATTR_TARGET_*,
|
|
|
|
* this returns the first character's offset and its length.
|
|
|
|
* Otherwise, e.g., the all characters are ATTR_INPUT, this returns
|
|
|
|
* the composition string range because the all is the current target.
|
|
|
|
*
|
|
|
|
* aLength can be null (default), but aOffset must not be null.
|
|
|
|
*
|
|
|
|
* The aOffset value is offset in the contents. So, when you need offset
|
|
|
|
* in the composition string, you need to subtract mCompositionStart from it.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
bool GetTargetClauseRange(uint32_t *aOffset, uint32_t *aLength = nullptr);
|
2014-11-25 08:02:33 +03:00
|
|
|
|
2015-11-17 10:47:06 +03:00
|
|
|
/**
|
|
|
|
* DispatchEvent() dispatches aEvent if aWidget hasn't been destroyed yet.
|
|
|
|
*/
|
|
|
|
static void DispatchEvent(nsWindow* aWindow, WidgetGUIEvent& aEvent);
|
|
|
|
|
2014-11-25 08:02:33 +03:00
|
|
|
/**
|
2015-09-11 15:21:27 +03:00
|
|
|
* DispatchCompositionChangeEvent() dispatches eCompositionChange event
|
2014-11-25 08:02:33 +03:00
|
|
|
* with clause information (it'll be retrieved by CreateTextRangeArray()).
|
|
|
|
* I.e., this should be called only during composing. If a composition is
|
|
|
|
* being committed, only HandleCompositionEnd() should be called.
|
|
|
|
*
|
|
|
|
* @param aWindow The window which has the composition.
|
2015-07-23 06:31:28 +03:00
|
|
|
* @param aContext Native IME context which has the composition.
|
2014-11-25 08:02:33 +03:00
|
|
|
*/
|
2014-10-07 14:01:49 +04:00
|
|
|
void DispatchCompositionChangeEvent(nsWindow* aWindow,
|
2015-07-23 06:31:28 +03:00
|
|
|
const IMEContext& aContext);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult EnsureClauseArray(int32_t aCount);
|
|
|
|
nsresult EnsureAttributeArray(int32_t aCount);
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
/**
|
|
|
|
* When WM_IME_CHAR is received and passed to DefWindowProc, we need to
|
|
|
|
* record the messages. In other words, we should record the messages
|
|
|
|
* when we receive WM_IME_CHAR on windowless plug-in (if we have focus,
|
|
|
|
* we always eat them). When focus is moved from a windowless plug-in to
|
|
|
|
* our window during composition, WM_IME_CHAR messages were received when
|
|
|
|
* the plug-in has focus. However, WM_CHAR messages are received after the
|
|
|
|
* plug-in lost focus. So, we need to ignore the WM_CHAR messages because
|
|
|
|
* they make unexpected text input events on us.
|
|
|
|
*/
|
|
|
|
nsTArray<MSG> mPassedIMEChar;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsIMECharRecordsEmpty()
|
2010-08-08 13:23:25 +04:00
|
|
|
{
|
|
|
|
return mPassedIMEChar.IsEmpty();
|
|
|
|
}
|
|
|
|
void ResetIMECharRecords()
|
|
|
|
{
|
|
|
|
mPassedIMEChar.Clear();
|
|
|
|
}
|
|
|
|
void DequeueIMECharRecords(WPARAM &wParam, LPARAM &lParam)
|
|
|
|
{
|
|
|
|
MSG msg = mPassedIMEChar.ElementAt(0);
|
|
|
|
wParam = msg.wParam;
|
|
|
|
lParam = msg.lParam;
|
|
|
|
mPassedIMEChar.RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
void EnqueueIMECharRecords(WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
msg.wParam = wParam;
|
|
|
|
msg.lParam = lParam;
|
|
|
|
mPassedIMEChar.AppendElement(msg);
|
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
TextEventDispatcher* GetTextEventDispatcherFor(nsWindow* aWindow);
|
|
|
|
|
2010-08-08 13:23:25 +04:00
|
|
|
nsWindow* mComposingWindow;
|
2016-03-16 07:47:48 +03:00
|
|
|
RefPtr<TextEventDispatcher> mDispatcher;
|
2009-05-04 02:20:11 +04:00
|
|
|
nsString mCompositionString;
|
2013-03-30 22:15:27 +04:00
|
|
|
InfallibleTArray<uint32_t> mClauseArray;
|
|
|
|
InfallibleTArray<uint8_t> mAttributeArray;
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mCursorPosition;
|
|
|
|
uint32_t mCompositionStart;
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-07-22 06:40:32 +03:00
|
|
|
struct Selection
|
|
|
|
{
|
|
|
|
nsString mString;
|
|
|
|
uint32_t mOffset;
|
|
|
|
mozilla::WritingMode mWritingMode;
|
|
|
|
bool mIsValid;
|
|
|
|
|
|
|
|
Selection()
|
|
|
|
: mOffset(UINT32_MAX)
|
|
|
|
, mIsValid(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mOffset = UINT32_MAX;
|
|
|
|
mIsValid = false;
|
|
|
|
}
|
|
|
|
uint32_t Length() const { return mString.Length(); }
|
2015-07-26 06:29:47 +03:00
|
|
|
bool Collapsed() const { return !Length(); }
|
2015-07-22 06:40:32 +03:00
|
|
|
|
|
|
|
bool IsValid() const;
|
|
|
|
bool Update(const IMENotification& aIMENotification);
|
|
|
|
bool Init(nsWindow* aWindow);
|
|
|
|
bool EnsureValidSelection(nsWindow* aWindow);
|
2015-08-04 11:05:25 +03:00
|
|
|
private:
|
|
|
|
Selection(const Selection& aOther) = delete;
|
|
|
|
void operator =(const Selection& aOther) = delete;
|
2015-07-22 06:40:32 +03:00
|
|
|
};
|
2015-08-04 11:05:25 +03:00
|
|
|
// mSelection stores the latest selection data only when sHasFocus is true.
|
|
|
|
// Don't access mSelection directly. You should use GetSelection() for
|
|
|
|
// getting proper state.
|
2015-07-22 06:40:32 +03:00
|
|
|
Selection mSelection;
|
2015-08-04 11:05:25 +03:00
|
|
|
|
|
|
|
Selection& GetSelection()
|
|
|
|
{
|
|
|
|
// When IME has focus, mSelection is automatically updated by
|
|
|
|
// NOTIFY_IME_OF_SELECTION_CHANGE.
|
|
|
|
if (sHasFocus) {
|
|
|
|
return mSelection;
|
|
|
|
}
|
|
|
|
// Otherwise, i.e., While IME doesn't have focus, we cannot observe
|
|
|
|
// selection changes. So, in such case, we need to query selection
|
|
|
|
// when it's necessary.
|
|
|
|
static Selection sTempSelection;
|
|
|
|
sTempSelection.Clear();
|
|
|
|
return sTempSelection;
|
|
|
|
}
|
2015-07-22 06:40:32 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsComposing;
|
|
|
|
bool mIsComposingOnPlugin;
|
|
|
|
bool mNativeCaretIsCreated;
|
2009-05-04 02:20:11 +04:00
|
|
|
|
2015-05-15 04:18:08 +03:00
|
|
|
static mozilla::WritingMode sWritingModeOfCompositionFont;
|
2015-05-15 04:18:07 +03:00
|
|
|
static nsString sIMEName;
|
2009-05-07 07:49:14 +04:00
|
|
|
static UINT sCodePage;
|
|
|
|
static DWORD sIMEProperty;
|
2015-05-15 04:18:07 +03:00
|
|
|
static DWORD sIMEUIProperty;
|
|
|
|
static bool sAssumeVerticalWritingModeNotSupported;
|
2015-07-22 06:40:32 +03:00
|
|
|
static bool sHasFocus;
|
2016-01-13 06:44:39 +03:00
|
|
|
static bool sNativeCaretIsCreatedForPlugin;
|
2009-05-04 02:20:11 +04:00
|
|
|
};
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // IMMHandler_h_
|