Bug 1683226 - part 7: Get rid of remaining all IMM message handlers for plugin r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D100119
This commit is contained in:
Masayuki Nakano 2020-12-21 06:17:36 +00:00
parent 8698fade12
commit 942e0a3e09
5 changed files with 1 additions and 321 deletions

View File

@ -273,11 +273,6 @@ bool IMMHandler::IsComposingOnOurEditor() {
return gIMMHandler && gIMMHandler->mIsComposing;
}
// static
bool IMMHandler::IsComposingOnPlugin() {
return gIMMHandler && gIMMHandler->mIsComposingOnPlugin;
}
// static
bool IMMHandler::IsComposingWindow(nsWindow* aWindow) {
return gIMMHandler && gIMMHandler->mComposingWindow == aWindow;
@ -382,8 +377,7 @@ IMMHandler::IMMHandler()
: mComposingWindow(nullptr),
mCursorPosition(NO_IME_CARET),
mCompositionStart(0),
mIsComposing(false),
mIsComposingOnPlugin(false) {
mIsComposing(false) {
MOZ_LOG(gIMMLog, LogLevel::Debug, ("IMMHandler is created"));
}
@ -569,15 +563,6 @@ bool IMMHandler::ProcessMessage(nsWindow* aWindow, UINT msg, WPARAM& wParam,
// if the new window handle is not focused, probably, we should not start
// the composition, however, such case should not be, it's just bad scenario.
// When a plug-in has focus, we should dispatch the IME events to
// the plug-in at first.
if (aWindow->PluginHasFocus()) {
bool ret = false;
if (ProcessMessageForPlugin(aWindow, msg, wParam, lParam, ret, aResult)) {
return ret;
}
}
aResult.mResult = 0;
switch (msg) {
case WM_INPUTLANGCHANGE:
@ -614,49 +599,6 @@ bool IMMHandler::ProcessMessage(nsWindow* aWindow, UINT msg, WPARAM& wParam,
};
}
// static
bool IMMHandler::ProcessMessageForPlugin(nsWindow* aWindow, UINT msg,
WPARAM& wParam, LPARAM& lParam,
bool& aRet, MSGResult& aResult) {
aResult.mResult = 0;
aResult.mConsumed = false;
switch (msg) {
case WM_INPUTLANGCHANGEREQUEST:
case WM_INPUTLANGCHANGE:
aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
aRet = ProcessInputLangChangeMessage(aWindow, wParam, lParam, aResult);
return true;
case WM_IME_CHAR:
EnsureHandlerInstance();
aRet = gIMMHandler->OnIMECharOnPlugin(aWindow, wParam, lParam, aResult);
return true;
case WM_IME_SETCONTEXT:
aRet = OnIMESetContextOnPlugin(aWindow, wParam, lParam, aResult);
return true;
case WM_CHAR:
if (!gIMMHandler) {
return true;
}
aRet = gIMMHandler->OnCharOnPlugin(aWindow, wParam, lParam, aResult);
return true;
case WM_IME_COMPOSITIONFULL:
case WM_IME_CONTROL:
case WM_IME_KEYDOWN:
case WM_IME_KEYUP:
case WM_IME_SELECT:
aResult.mConsumed =
aWindow->DispatchPluginEvent(msg, wParam, lParam, false);
aRet = true;
return true;
case WM_IME_REQUEST:
// Our plugin implementation is alwasy OOP. So WM_IME_REQUEST doesn't
// allow that parameter is pointer and shouldn't handle into Gecko.
aRet = false;
return true;
}
return false;
}
/****************************************************************************
* message handlers
****************************************************************************/
@ -982,92 +924,6 @@ bool IMMHandler::OnChar(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
return aResult.mConsumed;
}
/****************************************************************************
* message handlers for plug-in
****************************************************************************/
bool IMMHandler::OnIMECharOnPlugin(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam, MSGResult& aResult) {
MOZ_LOG(gIMMLog, LogLevel::Info,
("OnIMECharOnPlugin, hWnd=%08x, char=%08x, scancode=%08x",
aWindow->GetWindowHandle(), wParam, lParam));
aResult.mConsumed =
aWindow->DispatchPluginEvent(WM_IME_CHAR, wParam, lParam, true);
if (!aResult.mConsumed) {
// Record the WM_CHAR messages which are going to be coming.
EnsureHandlerInstance();
EnqueueIMECharRecords(wParam, lParam);
}
return true;
}
// static
bool IMMHandler::OnIMESetContextOnPlugin(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam, MSGResult& aResult) {
MOZ_LOG(gIMMLog, LogLevel::Info,
("OnIMESetContextOnPlugin, hWnd=%08x, %s, lParam=%08x",
aWindow->GetWindowHandle(), wParam ? "Active" : "Deactive", lParam));
// If the IME context becomes active on a plug-in, we should commit
// our composition. And also we should cancel the composition on new
// window. Note that if IsTopLevelWindowOfComposition(aWindow) returns
// true, we should ignore the message here, see the comment in
// OnIMESetContext() for the detail.
if (wParam && gIMMHandler && !IsTopLevelWindowOfComposition(aWindow)) {
if (gIMMHandler->CommitCompositionOnPreviousWindow(aWindow)) {
CancelComposition(aWindow);
}
}
// Dispatch message to the plug-in.
// XXX When a windowless plug-in gets focus, we should send
// WM_IME_SETCONTEXT
aWindow->DispatchPluginEvent(WM_IME_SETCONTEXT, wParam, lParam, false);
// We should send WM_IME_SETCONTEXT to the DefWndProc here. It shouldn't
// be received on ancestor windows, see OnIMESetContext() for the detail.
aResult.mResult = ::DefWindowProc(aWindow->GetWindowHandle(),
WM_IME_SETCONTEXT, wParam, lParam);
// Don't synchronously dispatch the pending events when we receive
// WM_IME_SETCONTEXT because we get it during plugin destruction.
// (bug 491848)
aResult.mConsumed = true;
return true;
}
bool IMMHandler::OnCharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
MSGResult& aResult) {
NS_WARNING("OnCharOnPlugin");
if (mIsComposing) {
aWindow->NotifyIME(REQUEST_TO_COMMIT_COMPOSITION);
return true;
}
// We should never consume char message on windowless plugin.
aResult.mConsumed = false;
if (IsIMECharRecordsEmpty()) {
return false;
}
WPARAM recWParam;
LPARAM recLParam;
DequeueIMECharRecords(recWParam, recLParam);
MOZ_LOG(gIMMLog, LogLevel::Info,
("OnCharOnPlugin, aWindow=%p, wParam=%08x, lParam=%08x, "
"recorded: wParam=%08x, lParam=%08x",
aWindow->GetWindowHandle(), wParam, lParam, recWParam, recLParam));
// If an unexpected char message comes, we should reset the records,
// of course, this shouldn't happen.
if (recWParam != wParam || recLParam != lParam) {
ResetIMECharRecords();
}
// WM_CHAR on plug-in is always handled by nsWindow.
return false;
}
/****************************************************************************
* others
****************************************************************************/
@ -2181,62 +2037,6 @@ bool IMMHandler::SetIMERelatedWindowsPos(nsWindow* aWindow,
return true;
}
void IMMHandler::SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow,
const IMEContext& aContext) {
WidgetQueryContentEvent queryEditorRectEvent(true, eQueryEditorRect, aWindow);
aWindow->InitEvent(queryEditorRectEvent);
DispatchEvent(aWindow, queryEditorRectEvent);
if (queryEditorRectEvent.Failed()) {
MOZ_LOG(gIMMLog, LogLevel::Info,
("SetIMERelatedWindowsPosOnPlugin, "
"FAILED, due to eQueryEditorRect failure"));
return;
}
// Clip the plugin rect by the client rect of the window because composition
// window needs to be specified the position in the client area.
nsWindow* toplevelWindow = aWindow->GetTopLevelWindow(false);
LayoutDeviceIntRect pluginRectInScreen =
queryEditorRectEvent.mReply->mRect +
toplevelWindow->WidgetToScreenOffset();
LayoutDeviceIntRect winRectInScreen = aWindow->GetClientBounds();
// composition window cannot be positioned on the edge of client area.
winRectInScreen.SizeTo(winRectInScreen.Width() - 1,
winRectInScreen.Height() - 1);
LayoutDeviceIntRect clippedPluginRect;
clippedPluginRect.MoveTo(
std::min(std::max(pluginRectInScreen.X(), winRectInScreen.X()),
winRectInScreen.XMost()),
std::min(std::max(pluginRectInScreen.Y(), winRectInScreen.Y()),
winRectInScreen.YMost()));
int32_t xMost = std::min(pluginRectInScreen.XMost(), winRectInScreen.XMost());
int32_t yMost = std::min(pluginRectInScreen.YMost(), winRectInScreen.YMost());
clippedPluginRect.SizeTo(std::max(0, xMost - clippedPluginRect.X()),
std::max(0, yMost - clippedPluginRect.Y()));
clippedPluginRect -= aWindow->WidgetToScreenOffset();
// Cover the plugin with native caret. This prevents IME's window and plugin
// overlap. But if a11y modules is handling native caret, we shouldn't touch
// it.
if (!IMEHandler::IsA11yHandlingNativeCaret()) {
IMEHandler::CreateNativeCaret(aWindow, clippedPluginRect);
}
// Set the composition window to bottom-left of the clipped plugin.
// As far as we know, there is no IME for RTL language. Therefore, this code
// must not need to take care of RTL environment.
COMPOSITIONFORM compForm;
compForm.dwStyle = CFS_POINT;
compForm.ptCurrentPos.x = clippedPluginRect.BottomLeft().x;
compForm.ptCurrentPos.y = clippedPluginRect.BottomLeft().y;
if (!::ImmSetCompositionWindow(aContext.get(), &compForm)) {
MOZ_LOG(gIMMLog, LogLevel::Info,
("SetIMERelatedWindowsPosOnPlugin, "
"FAILED, due to ::ImmSetCompositionWindow() failure"));
return;
}
}
void IMMHandler::ResolveIMECaretPos(nsIWidget* aReferenceWidget,
LayoutDeviceIntRect& aCursorRect,
nsIWidget* aNewOriginWidget,

View File

@ -152,7 +152,6 @@ class IMMHandler final {
static void EnsureHandlerInstance();
static bool IsComposingOnOurEditor();
static bool IsComposingOnPlugin();
static bool IsComposingWindow(nsWindow* aWindow);
static bool ShouldDrawCompositionStringOurselves();
@ -170,9 +169,6 @@ class IMMHandler final {
static bool ProcessInputLangChangeMessage(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam, MSGResult& aResult);
static bool ProcessMessageForPlugin(nsWindow* aWindow, UINT msg,
WPARAM& wParam, LPARAM& lParam,
bool& aRet, MSGResult& aResult);
IMMHandler();
~IMMHandler();
@ -183,23 +179,13 @@ class IMMHandler final {
MSGResult& aResult);
bool OnIMEStartComposition(nsWindow* aWindow, MSGResult& aResult);
void OnIMEStartCompositionOnPlugin(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam);
bool OnIMEComposition(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
MSGResult& aResult);
void OnIMECompositionOnPlugin(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam);
bool OnIMEEndComposition(nsWindow* aWindow, MSGResult& aResult);
void OnIMEEndCompositionOnPlugin(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam);
bool OnIMERequest(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
MSGResult& aResult);
bool OnIMECharOnPlugin(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
MSGResult& aResult);
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);
@ -209,8 +195,6 @@ class IMMHandler final {
MSGResult& aResult);
static bool OnIMESetContext(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
MSGResult& aResult);
static bool OnIMESetContextOnPlugin(nsWindow* aWindow, WPARAM wParam,
LPARAM lParam, MSGResult& aResult);
static bool OnIMECompositionFull(nsWindow* aWindow, MSGResult& aResult);
static bool OnIMENotify(nsWindow* aWindow, WPARAM wParam, LPARAM lParam,
MSGResult& aResult);
@ -265,8 +249,6 @@ class IMMHandler final {
nsACString& aANSIStr);
bool SetIMERelatedWindowsPos(nsWindow* aWindow, const IMEContext& aContext);
void SetIMERelatedWindowsPosOnPlugin(nsWindow* aWindow,
const IMEContext& aContext);
/**
* GetCharacterRectOfSelectedTextAt() returns character rect of the offset
* from the selection start or the start of composition string if there is
@ -438,7 +420,6 @@ class IMMHandler final {
}
bool mIsComposing;
bool mIsComposingOnPlugin;
static mozilla::WritingMode sWritingModeOfCompositionFont;
static nsString sIMEName;

View File

@ -436,10 +436,6 @@ void IMEHandler::SetInputContext(nsWindow* aWindow, InputContext& aInputContext,
// Assume that SetInputContext() is called only when aWindow has focus.
sPluginHasFocus = (aInputContext.mIMEState.mEnabled == IMEEnabled::Plugin);
if (sPluginHasFocus) {
// Update some cached system settings in the plugin.
aWindow->DispatchPluginSettingEvents();
}
if (aInputContext.mHTMLInputInputmode.EqualsLiteral("none")) {
IMEHandler::MaybeDismissOnScreenKeyboard(aWindow, Sync::Yes);

View File

@ -4425,25 +4425,6 @@ bool nsWindow::DispatchPluginEvent(UINT aMessage, WPARAM aWParam,
return ret;
}
void nsWindow::DispatchPluginSettingEvents() {
// Update scroll wheel properties.
{
LRESULT lresult;
MSGResult msgResult(&lresult);
MSG msg =
WinUtils::InitMSG(WM_SETTINGCHANGE, SPI_SETWHEELSCROLLLINES, 0, mWnd);
ProcessMessageForPlugin(msg, msgResult);
}
{
LRESULT lresult;
MSGResult msgResult(&lresult);
MSG msg =
WinUtils::InitMSG(WM_SETTINGCHANGE, SPI_SETWHEELSCROLLCHARS, 0, mWnd);
ProcessMessageForPlugin(msg, msgResult);
}
}
void nsWindow::DispatchCustomEvent(const nsString& eventName) {
if (Document* doc = GetDocument()) {
if (nsPIDOMWindowOuter* win = doc->GetWindow()) {
@ -5115,75 +5096,6 @@ const char16_t* GetQuitType() {
return nullptr;
}
// The main windows message processing method for plugins.
// The result means whether this method processed the native
// event for plugin. If false, the native event should be
// processed by the caller self.
bool nsWindow::ProcessMessageForPlugin(MSG aMsg, MSGResult& aResult) {
aResult.mResult = 0;
aResult.mConsumed = true;
bool eventDispatched = false;
switch (aMsg.message) {
case WM_CHAR:
case WM_SYSCHAR:
aResult.mResult = ProcessCharMessage(aMsg, &eventDispatched);
break;
case WM_KEYUP:
case WM_SYSKEYUP:
aResult.mResult = ProcessKeyUpMessage(aMsg, &eventDispatched);
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
aResult.mResult = ProcessKeyDownMessage(aMsg, &eventDispatched);
break;
case WM_SETTINGCHANGE: {
// If there was a change in scroll wheel settings then shove the new
// value into the unused lParam so that the client doesn't need to ask
// for it.
if ((aMsg.wParam != SPI_SETWHEELSCROLLLINES) &&
(aMsg.wParam != SPI_SETWHEELSCROLLCHARS)) {
return false;
}
UINT wheelDelta = 0;
UINT getMsg = (aMsg.wParam == SPI_SETWHEELSCROLLLINES)
? SPI_GETWHEELSCROLLLINES
: SPI_GETWHEELSCROLLCHARS;
if (NS_WARN_IF(!::SystemParametersInfo(getMsg, 0, &wheelDelta, 0))) {
// Use system default scroll amount, 3, when
// SPI_GETWHEELSCROLLLINES/CHARS isn't available.
wheelDelta = 3;
}
aMsg.lParam = wheelDelta;
break;
}
case WM_DEADCHAR:
case WM_SYSDEADCHAR:
case WM_CUT:
case WM_COPY:
case WM_PASTE:
case WM_CLEAR:
case WM_UNDO:
break;
default:
return false;
}
if (!eventDispatched) {
aResult.mConsumed = nsWindowBase::DispatchPluginEvent(aMsg);
}
if (!Destroyed()) {
DispatchPendingEvents();
}
return true;
}
static void ForceFontUpdate() {
// update device context font cache
// Dirty but easiest way:
@ -5211,13 +5123,6 @@ bool nsWindow::ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam,
return true;
}
if (PluginHasFocus()) {
MSG nativeMsg = WinUtils::InitMSG(aMessage, aWParam, aLParam, mWnd);
if (ProcessMessageForPlugin(nativeMsg, aResult)) {
return true;
}
}
return false;
}

View File

@ -360,7 +360,6 @@ class nsWindow final : public nsWindowBase {
virtual nsresult OnWindowedPluginKeyEvent(
const mozilla::NativeEventData& aKeyEventData,
nsIKeyEventInPluginCallback* aCallback) override;
void DispatchPluginSettingEvents();
void GetCompositorWidgetInitData(
mozilla::widget::CompositorWidgetInitData* aInitData) override;
@ -444,7 +443,6 @@ class nsWindow final : public nsWindowBase {
LRESULT* aRetValue);
bool ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam,
LPARAM& aLParam, MSGResult& aResult);
bool ProcessMessageForPlugin(MSG aMsg, MSGResult& aResult);
LRESULT ProcessCharMessage(const MSG& aMsg, bool* aEventDispatched);
LRESULT ProcessKeyUpMessage(const MSG& aMsg, bool* aEventDispatched);
LRESULT ProcessKeyDownMessage(const MSG& aMsg, bool* aEventDispatched);