Bug 1334594 - Call NSTextInputClient's insertText:replacementRange: instead of NSTextInput's insertText: from IMEInputHandler::SendCommittedText(). r=m_kato, a=jcristau
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 07 Feb 2017 19:03:14 +0900
changeset 378376 8ee7930272cb4e486f7f6b926ea9837a9d5ca0de
parent 378375 7ce21ea51bc3b5be991b97254a15fd40a4aae13a
child 378377 d666803190e57a9d9cb424c7d53ab2a6f2ef882a
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato, jcristau
bugs1334594, 1180564
milestone53.0a2
Bug 1334594 - Call NSTextInputClient's insertText:replacementRange: instead of NSTextInput's insertText: from IMEInputHandler::SendCommittedText(). r=m_kato, a=jcristau Bug 1180564 dropped NSTextInput protocl implementation from ChildView but IMEInputHandler::SendCommittedText() still calls it via mView. Therefore, it fails to commit composition in widget level. Instead, we it should call insertText:replacementRange: of NSTextInputClient protocol. Additionally, this patch adds a last resort path. If calling insertText:replacementRange: didn't commit composition in widget level, it calls TextInputHandler::InsertText() directly. MozReview-Commit-ID: BZZypBqC0Mx
widget/cocoa/TextInputHandler.mm
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -3752,17 +3752,34 @@ IMEInputHandler::SendCommittedText(NSStr
   NS_ENSURE_TRUE(mWidget, );
   // XXX We should send the string without mView.
   if (!mView) {
     return;
   }
 
   NSAttributedString* attrStr =
     [[NSAttributedString alloc] initWithString:aString];
-  [mView insertText:attrStr];
+  if ([mView conformsToProtocol:@protocol(NSTextInputClient)]) {
+    NSObject<NSTextInputClient>* textInputClient =
+      static_cast<NSObject<NSTextInputClient>*>(mView);
+    [textInputClient insertText:attrStr
+               replacementRange:NSMakeRange(NSNotFound, 0)];
+  }
+
+  // Last resort.  If we cannot retrieve NSTextInputProtocol from mView
+  // or blocking to call our InsertText(), we should call InsertText()
+  // directly to commit composition forcibly.
+  if (mIsIMEComposing) {
+    MOZ_LOG(gLog, LogLevel::Info,
+      ("%p IMEInputHandler::SendCommittedText, trying to insert text directly "
+       "due to IME not calling our InsertText()", this));
+    static_cast<TextInputHandler*>(this)->InsertText(attrStr);
+    MOZ_ASSERT(!mIsIMEComposing);
+  }
+
   [attrStr release];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 void
 IMEInputHandler::KillIMEComposition()
 {