1- AppKit IME implementation
1+ ## AppKit IME implementation notes
22
3- Of interest are other project's client implementations:
4- * [ Chromium] ( < https://github.com/chromium/chromium/blob/c9acbb5436a6676d081f34b372ff1ba28a8f44b7/components/remote_cocoa/app_shim/bridged_content_view.mm > ) ,
5- * [ Firefox] ( < https://github.com/mozilla-firefox/firefox/blob/4d26a0d0b80b56b95f9f7958a6d16dd4dfb35c1a/widget/cocoa/nsCocoaWindow.mm#L2918 > ) ,
6- * [ Java Swing] ( < https://github.com/openjdk/jdk/blob/ee90f00b3b38b7cf4da340deb48f04bdaee22710/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m > ) ,
7- * [ Qt] ( < https://github.com/qt/qtbase/blob/e0da96d7f7306592dc05c6fe6a0e81b1c72e7b07/src/plugins/platforms/cocoa/qnsview_complextext.mm > )
8- (see also [ their input context] ( < https://github.com/qt/qtbase/blob/e0da96d7f7306592dc05c6fe6a0e81b1c72e7b07/src/plugins/platforms/cocoa/qcocoainputcontext.mm > ) )
3+ - (for best viewing experience, ` cd winit-appkit && cargo doc --document-private-items ` , open the ` ime ` module in the
4+ generated docs)
95
10- First, some context on API surfaces related to IME on AppKit. On the logical server side, the IME application which
11- manages the marked text and interprets user input, we have
6+ ### Other Implementations
7+ See also these other implementations of IME on AppKit
8+
9+ - [ Chromium] ( < https://github.com/chromium/chromium/blob/c9acbb5436a6676d081f34b372ff1ba28a8f44b7/components/remote_cocoa/app_shim/bridged_content_view.mm > ) ,
10+ - [ Firefox] ( < https://github.com/mozilla-firefox/firefox/blob/4d26a0d0b80b56b95f9f7958a6d16dd4dfb35c1a/widget/cocoa/nsCocoaWindow.mm#L2918 > ) ,
11+ - [ Java AWT] ( < https://github.com/openjdk/jdk/blob/ee90f00b3b38b7cf4da340deb48f04bdaee22710/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m > ) ,
12+ - [ Qt] ( < https://github.com/qt/qtbase/blob/e0da96d7f7306592dc05c6fe6a0e81b1c72e7b07/src/plugins/platforms/cocoa/qnsview_complextext.mm > )
13+ (see also [ their input context wrapper] ( < https://github.com/qt/qtbase/blob/e0da96d7f7306592dc05c6fe6a0e81b1c72e7b07/src/plugins/platforms/cocoa/qcocoainputcontext.mm > ) )
14+
15+ ### Context
16+ First, some context on API surfaces related to IME on AppKit. On the server side, which manages the client's marked text
17+ and interprets user input, we have
1218[ ` IMKTextInput ` ] ( < https://web.archive.org/web/20081224174350/http://developer.apple.com/documentation/Cocoa/Reference/IMKTextInput_Protocol/Reference/IMKTextInput_Protocol.html > )
13- (the link points to an archive because the docs have mysteriously disappeared from official apple sources since), which
14- forwards requests from the server to clients , along with the
19+ (the link points to an archive because the docs have mysteriously disappeared from official apple sources since), which
20+ forwards requests from the server to a client , along with the
1521[ ` IMKServerInput ` ] ( < https://developer.apple.com/documentation/inputmethodkit/imkserverinput?language=objc > ) informal
1622protocol, which handles events received from clients. The client <-> server communications are mediated by internal
1723` TextServicesManager ` APIs, which include an OS service process that likely handles IME app discovery, bringup, IPC
@@ -22,6 +28,15 @@ read-only [`NSTextInputContext`] field on our [`NSView`]. Generally, most method
2228straightforwards, the difficulty comes from subtle and hard to predict interactions between these methods and the
2329existing cocoa event handling mechanisms for key presses.
2430
25- Particularly, some functions in [ ` NSTextInputClient ` ] are dispatched through a call to
26- [ ` doCommandBySelector: ` ] ( NSView::doCommandBySelector ) on the view, and not dispatched directly
31+ ### IME Event Handling
32+ When the application determines a key [ ` NSEvent ` ] should be interpreted as a text input and an IME is present (i.e.
33+ [ ` inputContext ` ] ( NSView::inputContext ) ` != nil ` ), the event is forwarded to the [ ` inputContext ` ] ( NSView::inputContext ) 's
34+ [ ` handleEvent: ` ] ( NSTextInputContext::handleEvent ) , via [ ` NSView ` ] 's override of
35+ [ ` interpretKeyEvents: ` ] ( NSResponder::interpretKeyEvents ) , which [ we are instructed not to override
36+ further] ( < https://developer.apple.com/documentation/appkit/nsresponder/interpretkeyevents(_:) > ) .
2737
38+ Calls to functions defined in [ ` NSTextInputClient ` ] are dispatched through [ `-[ NSTextInputClient
39+ doCommandBySelector:] `] ( NSTextInputClient::doCommandBySelector ) which, confusingly, is "method punned" with
40+ [ ` -[NSStandardKeyBindingResponding doCommandBySelector:] ` ] ( NSStandardKeyBindingResponding::doCommandBySelector )
41+ (Objective C nas no namespacing, so the method for selector ` doCommandBySelector: ` must implement the functionality
42+ required by both protocols).
0 commit comments