Google Docs & Yahoo! Japan: Can’t compose characters with Chinese or Japanese keyboard
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 May 2019 20:41:02 +0000 (20:41 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 6 May 2019 20:41:02 +0000 (20:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197474
<rdar://problem/47219324>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Fix up some #if defs to compile more Mac code when building on iOS.

* dom/KeyboardEvent.cpp:
(WebCore::KeyboardEvent::KeyboardEvent):
* platform/PlatformKeyboardEvent.h:
(WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):

Source/WebKit:

Adopt UIKit SPI (added in <rdar://problem/50181162>) to ask the Input Manager to handle
the key event. If the Input Manager handled it then we pass along this information to
WebCore, just as we do for Mac, so that it can alter its event handling logic. Otherwise,
we handle the event as we do now.

A large part of this patch is fixing up #if defs to compile more Mac code when building
on iOS.

* Platform/spi/ios/UIKitSPI.h: Expose more SPI.
* Shared/NativeWebKeyboardEvent.h:
* Shared/WebEvent.h:
* Shared/WebEventConversion.cpp:
(WebKit::WebKit2PlatformKeyboardEvent::WebKit2PlatformKeyboardEvent):
* Shared/WebKeyboardEvent.cpp:
(WebKit::WebKeyboardEvent::WebKeyboardEvent):
(WebKit::WebKeyboardEvent::encode const):
(WebKit::WebKeyboardEvent::decode):
* Shared/ios/NativeWebKeyboardEventIOS.mm:
(WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
* Shared/ios/WebIOSEventFactory.h:
* Shared/ios/WebIOSEventFactory.mm:
(WebIOSEventFactory::createWebKeyboardEvent):
Compile more Mac code on iOS. Just like on Mac we maintain some bookkeeping on
whether an event was handled by the Input Manager.

* UIProcess/Automation/ios/WebAutomationSessionIOS.mm:
(WebKit::WebAutomationSession::sendSynthesizedEventsToPage): Pass NativeWebKeyboardEvent::HandledByInputMethod::No
to keep the behavior we have now.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView cleanupInteraction]):
(-[WKContentView shouldSuppressUpdateCandidateView]): Added. Used to tell UIKit whether to
suppress updating/showing the candidate view.
(-[WKContentView setMarkedText:selectedRange:]):
Bookkeeping to track whether we need to delay showing/updating the inline candidate view.
The concept in UIKit is deferment, but at the time of writing its simply a request to delay
the update for 0.4 seconds. We opt into this delay only for the first key that begins
marked text (i.e. the transition from no marked text to marked text). We do this because we
may not have up-to-date editor state at the time UIKit is ready to show/update the inline
candidate view for us to answer -textFirstRect and -textLastRect, which UIKit calls as part
of computing the frame rect for the inline candidate view on screen. Once we receive up-to-date
editor state, in -selectionChanged, we tell UIKit to layout the keyboard, which ultimately
causes it to re-compute the frame rect for the inline candidate view and show it.

(-[WKContentView handleKeyWebEvent:]): Pass NativeWebKeyboardEvent::HandledByInputMethod::No
to keep the behavior we have now.
(-[WKContentView handleKeyWebEvent:withCompletionHandler:]): Ask the keyboard to handle the
event using the Input Manager. If it was handled then there is no need to delay calling the
completion handler, call it, then tell the web process about the key event and that it was
already handled by the Input Manager.
(-[WKContentView _selectionChanged]): Tell the keyboard to update the candidate view, if needed.
* WebProcess/WebCoreSupport/ios/WebEditorClientIOS.mm:
(WebKit::WebEditorClient::handleInputMethodKeydown): Mark the event as default handled if
the UI process told us that the event was handled by the Input Manager just like we do on Mac.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244975 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/KeyboardEvent.cpp
Source/WebCore/platform/PlatformKeyboardEvent.h
Source/WebKit/ChangeLog
Source/WebKit/Platform/spi/ios/UIKitSPI.h
Source/WebKit/Shared/NativeWebKeyboardEvent.h
Source/WebKit/Shared/WebEvent.h
Source/WebKit/Shared/WebEventConversion.cpp
Source/WebKit/Shared/WebKeyboardEvent.cpp
Source/WebKit/Shared/ios/NativeWebKeyboardEventIOS.mm
Source/WebKit/Shared/ios/WebIOSEventFactory.h
Source/WebKit/Shared/ios/WebIOSEventFactory.mm
Source/WebKit/UIProcess/Automation/ios/WebAutomationSessionIOS.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebProcess/WebCoreSupport/ios/WebEditorClientIOS.mm

index 22b67eb..b965910 100644 (file)
@@ -1,3 +1,18 @@
+2019-05-06  Daniel Bates  <dabates@apple.com>
+
+        Google Docs & Yahoo! Japan: Can’t compose characters with Chinese or Japanese keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=197474
+        <rdar://problem/47219324>
+
+        Reviewed by Ryosuke Niwa.
+
+        Fix up some #if defs to compile more Mac code when building on iOS.
+
+        * dom/KeyboardEvent.cpp:
+        (WebCore::KeyboardEvent::KeyboardEvent):
+        * platform/PlatformKeyboardEvent.h:
+        (WebCore::PlatformKeyboardEvent::PlatformKeyboardEvent):
+
 2019-05-06  Chris Dumez  <cdumez@apple.com>
 
         Add assertions to CachedFrame to help figure out crash in CachedFrame constructor
index 23de812..4ec6c9e 100644 (file)
@@ -107,8 +107,10 @@ inline KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, RefPtr<Win
     , m_location(keyLocationCode(key))
     , m_repeat(key.isAutoRepeat())
     , m_isComposing(view && is<DOMWindow>(view->window()) && downcast<DOMWindow>(*view->window()).frame() && downcast<DOMWindow>(*view->window()).frame()->editor().hasComposition())
-#if USE(APPKIT)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS)
     , m_handledByInputMethod(key.handledByInputMethod())
+#endif
+#if USE(APPKIT)
     , m_keypressCommands(key.commands())
 #endif
 {
index 519b6cd..b7a02a9 100644 (file)
@@ -53,9 +53,6 @@ namespace WebCore {
         PlatformKeyboardEvent()
             : PlatformEvent(PlatformEvent::KeyDown)
             , m_windowsVirtualKeyCode(0)
-#if USE(APPKIT) || PLATFORM(GTK)
-            , m_handledByInputMethod(false)
-#endif
             , m_autoRepeat(false)
             , m_isKeypad(false)
             , m_isSystemKey(false)
@@ -84,9 +81,6 @@ namespace WebCore {
 #endif
             , m_keyIdentifier(keyIdentifier)
             , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
-#if USE(APPKIT) || PLATFORM(GTK)
-            , m_handledByInputMethod(false)
-#endif
             , m_autoRepeat(isAutoRepeat)
             , m_isKeypad(isKeypad)
             , m_isSystemKey(isSystemKey)
@@ -122,7 +116,7 @@ namespace WebCore {
         int windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
         void setWindowsVirtualKeyCode(int code) { m_windowsVirtualKeyCode = code; }
 
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
         bool handledByInputMethod() const { return m_handledByInputMethod; }
 #endif
 #if USE(APPKIT)
@@ -185,8 +179,8 @@ namespace WebCore {
 #endif
         String m_keyIdentifier;
         int m_windowsVirtualKeyCode;
-#if USE(APPKIT) || PLATFORM(GTK)
-        bool m_handledByInputMethod;
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
+        bool m_handledByInputMethod { false };
 #endif
 #if USE(APPKIT)
         Vector<KeypressCommand> m_commands;
index 525a69b..db17075 100644 (file)
@@ -1,3 +1,67 @@
+2019-05-06  Daniel Bates  <dabates@apple.com>
+
+        Google Docs & Yahoo! Japan: Can’t compose characters with Chinese or Japanese keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=197474
+        <rdar://problem/47219324>
+
+        Reviewed by Ryosuke Niwa.
+
+        Adopt UIKit SPI (added in <rdar://problem/50181162>) to ask the Input Manager to handle
+        the key event. If the Input Manager handled it then we pass along this information to
+        WebCore, just as we do for Mac, so that it can alter its event handling logic. Otherwise,
+        we handle the event as we do now.
+
+        A large part of this patch is fixing up #if defs to compile more Mac code when building
+        on iOS.
+
+        * Platform/spi/ios/UIKitSPI.h: Expose more SPI.
+        * Shared/NativeWebKeyboardEvent.h:
+        * Shared/WebEvent.h:
+        * Shared/WebEventConversion.cpp:
+        (WebKit::WebKit2PlatformKeyboardEvent::WebKit2PlatformKeyboardEvent):
+        * Shared/WebKeyboardEvent.cpp:
+        (WebKit::WebKeyboardEvent::WebKeyboardEvent):
+        (WebKit::WebKeyboardEvent::encode const):
+        (WebKit::WebKeyboardEvent::decode):
+        * Shared/ios/NativeWebKeyboardEventIOS.mm:
+        (WebKit::NativeWebKeyboardEvent::NativeWebKeyboardEvent):
+        * Shared/ios/WebIOSEventFactory.h:
+        * Shared/ios/WebIOSEventFactory.mm:
+        (WebIOSEventFactory::createWebKeyboardEvent):
+        Compile more Mac code on iOS. Just like on Mac we maintain some bookkeeping on
+        whether an event was handled by the Input Manager.
+
+        * UIProcess/Automation/ios/WebAutomationSessionIOS.mm:
+        (WebKit::WebAutomationSession::sendSynthesizedEventsToPage): Pass NativeWebKeyboardEvent::HandledByInputMethod::No
+        to keep the behavior we have now.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView cleanupInteraction]):
+        (-[WKContentView shouldSuppressUpdateCandidateView]): Added. Used to tell UIKit whether to
+        suppress updating/showing the candidate view.
+        (-[WKContentView setMarkedText:selectedRange:]):
+        Bookkeeping to track whether we need to delay showing/updating the inline candidate view.
+        The concept in UIKit is deferment, but at the time of writing its simply a request to delay
+        the update for 0.4 seconds. We opt into this delay only for the first key that begins
+        marked text (i.e. the transition from no marked text to marked text). We do this because we
+        may not have up-to-date editor state at the time UIKit is ready to show/update the inline
+        candidate view for us to answer -textFirstRect and -textLastRect, which UIKit calls as part
+        of computing the frame rect for the inline candidate view on screen. Once we receive up-to-date
+        editor state, in -selectionChanged, we tell UIKit to layout the keyboard, which ultimately
+        causes it to re-compute the frame rect for the inline candidate view and show it.
+
+        (-[WKContentView handleKeyWebEvent:]): Pass NativeWebKeyboardEvent::HandledByInputMethod::No
+        to keep the behavior we have now. 
+        (-[WKContentView handleKeyWebEvent:withCompletionHandler:]): Ask the keyboard to handle the
+        event using the Input Manager. If it was handled then there is no need to delay calling the
+        completion handler, call it, then tell the web process about the key event and that it was
+        already handled by the Input Manager.
+        (-[WKContentView _selectionChanged]): Tell the keyboard to update the candidate view, if needed.
+        * WebProcess/WebCoreSupport/ios/WebEditorClientIOS.mm:
+        (WebKit::WebEditorClient::handleInputMethodKeydown): Mark the event as default handled if
+        the UI process told us that the event was handled by the Input Manager just like we do on Mac.
+
 2019-05-06  Alex Christensen  <achristensen@webkit.org>
 
         Null check m_mainFrame in WebPageProxy.cpp
index d867fa1..c262b37 100644 (file)
@@ -386,6 +386,10 @@ typedef enum {
 @property (nonatomic, retain) UIColor *selectionHighlightColor;
 @end
 
+@protocol UITextInputDelegatePrivate
+- (void)layoutHasChanged;
+@end
+
 @class UITextInputArrowKeyHistory;
 
 @protocol UITextInputPrivate <UITextInput, UITextInputTokenizer, UITextInputTraits_Private>
@@ -1121,6 +1125,7 @@ typedef NS_OPTIONS(NSInteger, UIWKDocumentRequestFlags) {
 - (void)prepareKeyboardInputModeFromPreferences:(UIKeyboardInputMode *)lastUsedMode;
 - (BOOL)handleKeyTextCommandForCurrentEvent;
 - (BOOL)handleKeyAppCommandForCurrentEvent;
+- (BOOL)handleKeyInputMethodCommandForCurrentEvent;
 @property (nonatomic, readonly) UIKeyboardInputMode *currentInputModeInPreference;
 @end
 
index 0a8c93b..c0a64e3 100644 (file)
@@ -65,12 +65,14 @@ namespace WebKit {
 class NativeWebKeyboardEvent : public WebKeyboardEvent {
 public:
 #if USE(APPKIT)
+    // FIXME: Share iOS's HandledByInputMethod enum here instead of passing a boolean.
     NativeWebKeyboardEvent(NSEvent *, bool handledByInputMethod, bool replacesSoftSpace, const Vector<WebCore::KeypressCommand>&);
 #elif PLATFORM(GTK)
     NativeWebKeyboardEvent(const NativeWebKeyboardEvent&);
     NativeWebKeyboardEvent(GdkEvent*, const WebCore::CompositionResults&, InputMethodFilter::EventFakedForComposition, Vector<String>&& commands);
 #elif PLATFORM(IOS_FAMILY)
-    NativeWebKeyboardEvent(::WebEvent *);
+    enum class HandledByInputMethod : bool { No, Yes };
+    NativeWebKeyboardEvent(::WebEvent *, HandledByInputMethod);
 #elif USE(LIBWPE)
     NativeWebKeyboardEvent(struct wpe_input_keyboard_event*);
 #elif PLATFORM(WIN)
index ed408fe..28286f6 100644 (file)
@@ -259,7 +259,7 @@ public:
 #elif PLATFORM(GTK)
     WebKeyboardEvent(Type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool handledByInputMethod, Vector<String>&& commands, bool isKeypad, OptionSet<Modifier>, WallTime timestamp);
 #elif PLATFORM(IOS_FAMILY)
-    WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier>, WallTime timestamp);
+    WebKeyboardEvent(Type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier>, WallTime timestamp);
 #elif USE(LIBWPE)
     WebKeyboardEvent(Type, const String& text, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, bool isKeypad, OptionSet<Modifier>, WallTime timestamp);
 #else
@@ -278,7 +278,7 @@ public:
     int32_t windowsVirtualKeyCode() const { return m_windowsVirtualKeyCode; }
     int32_t nativeVirtualKeyCode() const { return m_nativeVirtualKeyCode; }
     int32_t macCharCode() const { return m_macCharCode; }
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
     bool handledByInputMethod() const { return m_handledByInputMethod; }
 #endif
 #if USE(APPKIT)
@@ -308,7 +308,7 @@ private:
     int32_t m_windowsVirtualKeyCode;
     int32_t m_nativeVirtualKeyCode;
     int32_t m_macCharCode;
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
     bool m_handledByInputMethod;
 #endif
 #if USE(APPKIT)
index 153de81..9631d42 100644 (file)
@@ -221,8 +221,10 @@ public:
 #endif
         m_keyIdentifier = webEvent.keyIdentifier();
         m_windowsVirtualKeyCode = webEvent.windowsVirtualKeyCode();
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
         m_handledByInputMethod = webEvent.handledByInputMethod();
+#endif
+#if USE(APPKIT) || PLATFORM(GTK)
         m_commands = webEvent.commands();
 #endif
         m_autoRepeat = webEvent.isAutoRepeat();
index 30b3f68..a5a23cf 100644 (file)
@@ -83,7 +83,7 @@ WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String&
 
 #elif PLATFORM(IOS_FAMILY)
 
-WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, WallTime timestamp)
+WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String& unmodifiedText, const String& key, const String& code, const String& keyIdentifier, int windowsVirtualKeyCode, int nativeVirtualKeyCode, int macCharCode, bool handledByInputMethod, bool isAutoRepeat, bool isKeypad, bool isSystemKey, OptionSet<Modifier> modifiers, WallTime timestamp)
     : WebEvent(type, modifiers, timestamp)
     , m_text(text)
     , m_unmodifiedText(unmodifiedText)
@@ -97,6 +97,9 @@ WebKeyboardEvent::WebKeyboardEvent(Type type, const String& text, const String&
     , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
     , m_nativeVirtualKeyCode(nativeVirtualKeyCode)
     , m_macCharCode(macCharCode)
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    , m_handledByInputMethod(handledByInputMethod)
+#endif
     , m_isAutoRepeat(isAutoRepeat)
     , m_isKeypad(isKeypad)
     , m_isSystemKey(isSystemKey)
@@ -166,8 +169,10 @@ void WebKeyboardEvent::encode(IPC::Encoder& encoder) const
     encoder << m_windowsVirtualKeyCode;
     encoder << m_nativeVirtualKeyCode;
     encoder << m_macCharCode;
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
     encoder << m_handledByInputMethod;
+#endif
+#if USE(APPKIT) || PLATFORM(GTK)
     encoder << m_commands;
 #endif
     encoder << m_isAutoRepeat;
@@ -200,9 +205,11 @@ bool WebKeyboardEvent::decode(IPC::Decoder& decoder, WebKeyboardEvent& result)
         return false;
     if (!decoder.decode(result.m_macCharCode))
         return false;
-#if USE(APPKIT) || PLATFORM(GTK)
+#if USE(APPKIT) || USE(UIKIT_KEYBOARD_ADDITIONS) || PLATFORM(GTK)
     if (!decoder.decode(result.m_handledByInputMethod))
         return false;
+#endif
+#if USE(APPKIT) || PLATFORM(GTK)
     if (!decoder.decode(result.m_commands))
         return false;
 #endif
index ccceb9a..d046fda 100644 (file)
@@ -34,8 +34,8 @@
 
 namespace WebKit {
 
-NativeWebKeyboardEvent::NativeWebKeyboardEvent(::WebEvent *event)
-    : WebKeyboardEvent(WebIOSEventFactory::createWebKeyboardEvent(event))
+NativeWebKeyboardEvent::NativeWebKeyboardEvent(::WebEvent *event, HandledByInputMethod handledByInputMethod)
+    : WebKeyboardEvent(WebIOSEventFactory::createWebKeyboardEvent(event, handledByInputMethod == HandledByInputMethod::Yes))
     , m_nativeEvent(event)
 {
 }
index 8579c33..138feaa 100644 (file)
@@ -33,7 +33,7 @@
 
 class WebIOSEventFactory {
 public:
-    static WebKit::WebKeyboardEvent createWebKeyboardEvent(::WebEvent *);
+    static WebKit::WebKeyboardEvent createWebKeyboardEvent(::WebEvent *, bool handledByInputMethod);
     static WebKit::WebMouseEvent createWebMouseEvent(::WebEvent *);
 
     static UIKeyModifierFlags toUIKeyModifierFlags(OptionSet<WebKit::WebEvent::Modifier>);
index 25c16ec..9d0a097 100644 (file)
@@ -64,7 +64,7 @@ static OptionSet<WebKit::WebEvent::Modifier> modifiersForEvent(::WebEvent *event
     return modifiers;
 }
 
-WebKit::WebKeyboardEvent WebIOSEventFactory::createWebKeyboardEvent(::WebEvent *event)
+WebKit::WebKeyboardEvent WebIOSEventFactory::createWebKeyboardEvent(::WebEvent *event, bool handledByInputMethod)
 {
     WebKit::WebEvent::Type type = (event.type == WebEventKeyUp) ? WebKit::WebEvent::KeyUp : WebKit::WebEvent::KeyDown;
     String text;
@@ -109,7 +109,7 @@ WebKit::WebKeyboardEvent WebIOSEventFactory::createWebKeyboardEvent(::WebEvent *
         unmodifiedText = text;
     }
 
-    return WebKit::WebKeyboardEvent(type, text, unmodifiedText, key, code, keyIdentifier, windowsVirtualKeyCode, nativeVirtualKeyCode, macCharCode, autoRepeat, isKeypad, isSystemKey, modifiers, WallTime::fromRawSeconds(timestamp));
+    return WebKit::WebKeyboardEvent { type, text, unmodifiedText, key, code, keyIdentifier, windowsVirtualKeyCode, nativeVirtualKeyCode, macCharCode, handledByInputMethod, autoRepeat, isKeypad, isSystemKey, modifiers, WallTime::fromRawSeconds(timestamp) };
 }
 
 WebKit::WebMouseEvent WebIOSEventFactory::createWebMouseEvent(::WebEvent *event)
index 48ba280..3c5cad8 100644 (file)
@@ -58,7 +58,7 @@ void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArr
 
         case WebEventKeyDown:
         case WebEventKeyUp:
-            page.handleKeyboardEvent(NativeWebKeyboardEvent(event));
+            page.handleKeyboardEvent(NativeWebKeyboardEvent(event, NativeWebKeyboardEvent::HandledByInputMethod::No));
             break;
         }
     }
index 05a05b0..68cfc5b 100644 (file)
@@ -324,6 +324,10 @@ struct WKAutoCorrectionData {
 
     BOOL _keyboardDidRequestDismissal;
 
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    BOOL _candidateViewNeedsUpdate;
+#endif
+
     BOOL _becomingFirstResponder;
     BOOL _resigningFirstResponder;
     BOOL _needsDeferredEndScrollingSelectionUpdate;
index 12e8f3d..77de7c8 100644 (file)
@@ -839,6 +839,10 @@ static inline bool hasFocusedElement(WebKit::FocusedElementInformation focusedEl
 
     _focusRequiresStrongPasswordAssistance = NO;
 
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    _candidateViewNeedsUpdate = NO;
+#endif
+
     if (_interactionViewsContainerView) {
         [self.layer removeObserver:self forKeyPath:@"transform"];
         [_interactionViewsContainerView removeFromSuperview];
@@ -4040,6 +4044,9 @@ static void selectionChangedWithTouch(WKContentView *view, const WebCore::IntPoi
 
 - (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange
 {
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    _candidateViewNeedsUpdate = !self.hasMarkedText;
+#endif
     _markedText = markedText;
     _page->setCompositionAsync(markedText, Vector<WebCore::CompositionUnderline>(), selectedRange, WebKit::EditingRange());
 }
@@ -4423,6 +4430,7 @@ static NSString *contentTypeFromFieldName(WebCore::AutofillFieldName fieldName)
 }
 
 #if USE(UIKIT_KEYBOARD_ADDITIONS)
+
 - (void)modifierFlagsDidChangeFrom:(UIKeyModifierFlags)oldFlags to:(UIKeyModifierFlags)newFlags
 {
     auto dispatchSyntheticFlagsChangedEvents = [&] (UIKeyModifierFlags flags, bool keyDown) {
@@ -4439,6 +4447,12 @@ static NSString *contentTypeFromFieldName(WebCore::AutofillFieldName fieldName)
     if (addedFlags)
         dispatchSyntheticFlagsChangedEvents(addedFlags, true);
 }
+
+- (BOOL)shouldSuppressUpdateCandidateView
+{
+    return _candidateViewNeedsUpdate;
+}
+
 #endif
 
 // Web events.
@@ -4483,15 +4497,24 @@ static NSString *contentTypeFromFieldName(WebCore::AutofillFieldName fieldName)
 
 - (void)handleKeyWebEvent:(::WebEvent *)theEvent
 {
-    _page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent));
+    _page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent, WebKit::NativeWebKeyboardEvent::HandledByInputMethod::No));
 }
 
 - (void)handleKeyWebEvent:(::WebEvent *)theEvent withCompletionHandler:(void (^)(::WebEvent *theEvent, BOOL wasHandled))completionHandler
 {
     [self _handleDOMPasteRequestWithResult:WebCore::DOMPasteAccessResponse::DeniedForGesture];
 
+    using HandledByInputMethod = WebKit::NativeWebKeyboardEvent::HandledByInputMethod;
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    auto* keyboard = [UIKeyboardImpl sharedInstance];
+    if ([keyboard respondsToSelector:@selector(handleKeyInputMethodCommandForCurrentEvent)] && [keyboard handleKeyInputMethodCommandForCurrentEvent]) {
+        completionHandler(theEvent, YES);
+        _page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent, HandledByInputMethod::Yes));
+        return;
+    }
+#endif
     _keyWebEventHandler = makeBlockPtr(completionHandler);
-    _page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent));
+    _page->handleKeyboardEvent(WebKit::NativeWebKeyboardEvent(theEvent, HandledByInputMethod::No));
 }
 
 - (void)_didHandleKeyEvent:(::WebEvent *)event eventWasHandled:(BOOL)eventWasHandled
@@ -5633,6 +5656,14 @@ static BOOL allPasteboardItemOriginsMatchOrigin(UIPasteboard *pasteboard, const
     if (_usingGestureForSelection)
         [self _updateChangedSelection];
 
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    if (_candidateViewNeedsUpdate) {
+        _candidateViewNeedsUpdate = NO;
+        if ([self.inputDelegate respondsToSelector:@selector(layoutHasChanged)])
+            [(id <UITextInputDelegatePrivate>)self.inputDelegate layoutHasChanged];
+    }
+#endif
+
     [_webView _didChangeEditorState];
 }
 
index 3b595ff..74bdc18 100644 (file)
@@ -44,7 +44,12 @@ void WebEditorClient::handleKeyboardEvent(KeyboardEvent& event)
 
 void WebEditorClient::handleInputMethodKeydown(KeyboardEvent&)
 {
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    if (event->handledByInputMethod())
+        event->setDefaultHandled();
+#else
     notImplemented();
+#endif
 }
 
 void WebEditorClient::setInsertionPasteboard(const String&)