Bug 1270985 Hide mouse cursor in native keydown event handler if Command key isn't pressed r?m_kato
Currently, TextInputHandler::DispatchEvent() isn't used for WidgetKeyboardEvent nor WidgetCompositionEvent since TextEventDispatcher directly uses nsIWidget::DispatchEvent(). Therefore, old code hiding mouse cursor at dispatching eKeyPress event is never run in current mozilla-central since TextInputHandler dispatches eKeyPress events via TextEventDispatcher.
Additionally, it's not enough to hide mouse cursor only when widget dispatches eKeyPress events because if IME starts composition, eKeyPress event won't be fired until finishing the composition. So, I think that we should hide mouse cursor at receiving native keydown events. The event handler receives keydown events before IME handles them. Additionally, modifier key events which won't cause eKeyPress events are not using native keydown event handler, fortunately. So, I believe that it's the best place to do it.
MozReview-Commit-ID: 9dnpiVEV2Lx
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -1517,16 +1517,26 @@ TextInputHandler::HandleKeyDownEvent(NSE
("%p TextInputHandler::HandleKeyDownEvent, aNativeEvent=%p, "
"type=%s, keyCode=%lld (0x%X), modifierFlags=0x%X, characters=\"%s\", "
"charactersIgnoringModifiers=\"%s\"",
this, aNativeEvent, GetNativeKeyEventType(aNativeEvent),
[aNativeEvent keyCode], [aNativeEvent keyCode],
[aNativeEvent modifierFlags], GetCharacters([aNativeEvent characters]),
GetCharacters([aNativeEvent charactersIgnoringModifiers])));
+ // Except when Command key is pressed, we should hide mouse cursor until
+ // next mousemove. Handling here means that:
+ // - Don't hide mouse cursor at pressing modifier key
+ // - Hide mouse cursor even if the key event will be handled by IME (i.e.,
+ // even without dispatching eKeyPress events)
+ // - Hide mouse cursor even when a plugin has focus
+ if (!([aNativeEvent modifierFlags] & NSCommandKeyMask)) {
+ [NSCursor setHiddenUntilMouseMoves:YES];
+ }
+
RefPtr<nsChildView> kungFuDeathGrip(mWidget);
KeyEventState* currentKeyEvent = PushKeyEvent(aNativeEvent);
AutoKeyEventStateCleaner remover(this);
ComplexTextInputPanel* ctiPanel = ComplexTextInputPanel::GetSharedComplexTextInputPanel();
if (ctiPanel && ctiPanel->IsInComposition()) {
nsAutoString committed;
@@ -3958,24 +3968,16 @@ TextInputHandlerBase::OnDestroyWidget(ns
mWidget = nullptr;
mDispatcher = nullptr;
return true;
}
bool
TextInputHandlerBase::DispatchEvent(WidgetGUIEvent& aEvent)
{
- if (aEvent.mMessage == eKeyPress) {
- WidgetInputEvent& inputEvent = *aEvent.AsInputEvent();
- if (!inputEvent.IsMeta()) {
- MOZ_LOG(gLog, LogLevel::Info,
- ("%p TextInputHandlerBase::DispatchEvent, hiding mouse cursor", this));
- [NSCursor setHiddenUntilMouseMoves:YES];
- }
- }
return mWidget->DispatchWindowEvent(aEvent);
}
void
TextInputHandlerBase::InitKeyEvent(NSEvent *aNativeKeyEvent,
WidgetKeyboardEvent& aKeyEvent,
const nsAString* aInsertString)
{