Title: [236669] trunk/Source/WebKit
Revision
236669
Author
dba...@webkit.org
Date
2018-10-01 10:41:25 -0700 (Mon, 01 Oct 2018)

Log Message

[iOS] Wrong key event may be sent to UIKit
https://bugs.webkit.org/show_bug.cgi?id=189992

Reviewed by Simon Fraser.

Retain a clone of a received UIEvent if it is for a hardware key event so as to ensure that we
notify the UIKit keyboard code of the correct keyboard event.

Currently the UIProcess retains the UIEvent associated with a keyboard event so as to defer
notifying the UIKit keyboard code (via -_handleKeyUIEvent) about a received keyboard event until
after the WebProcess has processed the raw key event. If this UIEvent is for a hardware keyboard
event then it is not sufficient to retain it to preserve its value because UIKit uses a singleton
UIEvent for all hardware keyboard events ;=> its value will be clobbered as each hardware keyboard
event is received. Instead we need to explicitly clone a UIEvent for a hardware key event before
retaining it.

* Platform/spi/ios/UIKitSPI.h: Forward declare SPI.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView handleKeyEvent:]): Clone the UIEvent if it is for a hardware key event.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (236668 => 236669)


--- trunk/Source/WebKit/ChangeLog	2018-10-01 17:40:48 UTC (rev 236668)
+++ trunk/Source/WebKit/ChangeLog	2018-10-01 17:41:25 UTC (rev 236669)
@@ -1,3 +1,25 @@
+2018-10-01  Daniel Bates  <daba...@apple.com>
+
+        [iOS] Wrong key event may be sent to UIKit
+        https://bugs.webkit.org/show_bug.cgi?id=189992
+
+        Reviewed by Simon Fraser.
+
+        Retain a clone of a received UIEvent if it is for a hardware key event so as to ensure that we
+        notify the UIKit keyboard code of the correct keyboard event.
+
+        Currently the UIProcess retains the UIEvent associated with a keyboard event so as to defer
+        notifying the UIKit keyboard code (via -_handleKeyUIEvent) about a received keyboard event until
+        after the WebProcess has processed the raw key event. If this UIEvent is for a hardware keyboard
+        event then it is not sufficient to retain it to preserve its value because UIKit uses a singleton
+        UIEvent for all hardware keyboard events ;=> its value will be clobbered as each hardware keyboard
+        event is received. Instead we need to explicitly clone a UIEvent for a hardware key event before
+        retaining it.
+
+        * Platform/spi/ios/UIKitSPI.h: Forward declare SPI.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView handleKeyEvent:]): Clone the UIEvent if it is for a hardware key event.
+
 2018-10-01  Alex Christensen  <achristen...@webkit.org>
 
         Deprecate ObjC SPI in Deprecated Xcode group

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (236668 => 236669)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2018-10-01 17:40:48 UTC (rev 236668)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2018-10-01 17:41:25 UTC (rev 236669)
@@ -1003,6 +1003,7 @@
 @end
 
 @interface UIPhysicalKeyboardEvent ()
+- (UIPhysicalKeyboardEvent *)_cloneEvent NS_RETURNS_RETAINED;
 @property (nonatomic, readonly) CFIndex _keyCode;
 @end
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (236668 => 236669)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-10-01 17:40:48 UTC (rev 236668)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2018-10-01 17:41:25 UTC (rev 236669)
@@ -3745,6 +3745,15 @@
     if (event == _uiEventBeingResent)
         return;
 
+    uint16_t keyCode;
+    BOOL isHardwareKeyboardEvent = !!event._hidEvent;
+    if (!isHardwareKeyboardEvent)
+        keyCode = 0;
+    else {
+        UIPhysicalKeyboardEvent *keyEvent = (UIPhysicalKeyboardEvent *)event;
+        keyCode = keyEvent._keyCode;
+        event = [[keyEvent _cloneEvent] autorelease]; // UIKit uses a singleton for hardware keyboard events.
+    }
     WKWebEvent *webEvent = [[[WKWebEvent alloc] initWithKeyEventType:(event._isKeyDown) ? WebEventKeyDown : WebEventKeyUp
                                                            timeStamp:event.timestamp
                                                           characters:event._modifiedInput
@@ -3752,7 +3761,7 @@
                                                            modifiers:event._modifierFlags
                                                          isRepeating:(event._inputFlags & kUIKeyboardInputRepeat)
                                                            withFlags:event._inputFlags
-                                                             keyCode:event._hidEvent ? ((UIPhysicalKeyboardEvent *)event)._keyCode : 0
+                                                             keyCode:keyCode
                                                             isTabKey:[event._modifiedInput isEqualToString:@"\t"]
                                                         characterSet:WebEventCharacterSetUnicode] autorelease];
     webEvent.uiEvent = event;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to