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
--- 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];