Bug 1270985 - Hide mouse cursor in native keydown event handler if Command key isn't pressed. r=m_kato, a=lizzard
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Jun 2016 14:37:51 +0900
changeset 341653 804b78a09df71fb081761064750cbbc6fc47611c
parent 341652 e579b0b53a2081789aa29b7fa336377c79ae210c
child 341654 dd0fbfbe790f880c80f126916e1c4e38436f9ad6
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, lizzard
Bug 1270985 - Hide mouse cursor in native keydown event handler if Command key isn't pressed. r=m_kato, a=lizzard 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\", "
      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;
 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);
 TextInputHandlerBase::InitKeyEvent(NSEvent *aNativeKeyEvent,
                                    WidgetKeyboardEvent& aKeyEvent,
                                    const nsAString* aInsertString)