Bug 1270985 Hide mouse cursor in native keydown event handler if Command key isn't pressed r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Jun 2016 14:37:51 +0900
changeset 376559 756030e56a7cc8dccc5b9d568dc090c57886d1c1
parent 376275 ec20b463c04f57a4bfca1edb987fcb9e9707c364
child 523190 c402615d09f2ec20dae737bf6775914753fead53
push id20618
push usermasayuki@d-toybox.com
push dateWed, 08 Jun 2016 09:25:04 +0000
reviewersm_kato
bugs1270985
milestone50.0a1
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
widget/cocoa/TextInputHandler.mm
--- 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)
 {