Bug 1376417 - part1: IMEInputHandler should notify Cocoa of layout change with [NSTextInputContext invalidateCharacterCoordinates] r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 29 Jun 2017 16:03:57 +0900
changeset 602024 1dcd07ee533a5a1fecbbe09c5ae061ce1e9c9612
parent 602023 7f3e8bf840762341ab4e1d92dbefb2b91880fec5
child 602025 b877b5d469318781518a902589e4afdc1693dd39
push id66247
push usermasayuki@d-toybox.com
push dateThu, 29 Jun 2017 13:33:09 +0000
reviewersm_kato
bugs1376417
milestone56.0a1
Bug 1376417 - part1: IMEInputHandler should notify Cocoa of layout change with [NSTextInputContext invalidateCharacterCoordinates] r?m_kato I found invalidateCharacterCoordinates in NSTextInputContext. It's available 10.6 and later. Calling this API does NOT make visible candidate window follow window move nor something to change layout, though. But we should call it. MozReview-Commit-ID: KbllLDwlMOz
widget/cocoa/TextInputHandler.h
widget/cocoa/TextInputHandler.mm
--- a/widget/cocoa/TextInputHandler.h
+++ b/widget/cocoa/TextInputHandler.h
@@ -808,16 +808,17 @@ public:
                       void* aData) override;
 
 public:
   virtual bool OnDestroyWidget(nsChildView* aDestroyingWidget) override;
 
   virtual void OnFocusChangeInGecko(bool aFocus);
 
   void OnSelectionChange(const IMENotification& aIMENotification);
+  void OnLayoutChange();
 
   /**
    * Call [NSTextInputContext handleEvent] for mouse event support of IME
    */
   bool OnHandleEvent(NSEvent* aEvent);
 
   /**
    * SetMarkedText() is a handler of setMarkedText of NSTextInput.
--- a/widget/cocoa/TextInputHandler.mm
+++ b/widget/cocoa/TextInputHandler.mm
@@ -2767,16 +2767,19 @@ IMEInputHandler::NotifyIME(TextEventDisp
       OnFocusChangeInGecko(true);
       return NS_OK;
     case NOTIFY_IME_OF_BLUR:
       OnFocusChangeInGecko(false);
       return NS_OK;
     case NOTIFY_IME_OF_SELECTION_CHANGE:
       OnSelectionChange(aNotification);
       return NS_OK;
+    case NOTIFY_IME_OF_POSITION_CHANGE:
+      OnLayoutChange();
+      return NS_OK;
     default:
       return NS_ERROR_NOT_IMPLEMENTED;
   }
 }
 
 NS_IMETHODIMP_(IMENotificationRequests)
 IMEInputHandler::GetIMENotificationRequests()
 {
@@ -4265,16 +4268,30 @@ IMEInputHandler::OnSelectionChange(const
   mRangeForWritingMode =
     NSMakeRange(aIMENotification.mSelectionChangeData.mOffset,
                 aIMENotification.mSelectionChangeData.Length());
   if (mIMEHasFocus) {
     mSelectedRange = mRangeForWritingMode;
   }
 }
 
+void
+IMEInputHandler::OnLayoutChange()
+{
+  NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
+
+  if (!IsFocused()) {
+    return;
+  }
+  NSTextInputContext* inputContext = [mView inputContext];
+  [inputContext invalidateCharacterCoordinates];
+
+  NS_OBJC_END_TRY_ABORT_BLOCK;
+}
+
 bool
 IMEInputHandler::OnHandleEvent(NSEvent* aEvent)
 {
   if (!IsFocused()) {
     return false;
   }
   NSTextInputContext* inputContext = [mView inputContext];
   return [inputContext handleEvent:aEvent];