Title: [240288] trunk/Source/WebKit
Revision
240288
Author
[email protected]
Date
2019-01-22 13:15:35 -0800 (Tue, 22 Jan 2019)

Log Message

[iOS] WebKit should handle shift state changes when using the software keyboard
https://bugs.webkit.org/show_bug.cgi?id=191475
<rdar://problem/45949246>

Reviewed by Brent Fulgham.

Implement UIKit SPI to be notified of shift state changes to the software keyboard
and dispatch a synthetic keydown or keyup event for either the Shift key or Caps Lock
key.

A side benefit of this change is that we now show and hide the caps lock indicator
in a focused password field when caps lock is enabled or disabled using the software
keyboard, respectively.

* Platform/spi/ios/UIKitSPI.h: Expose more SPI.
* SourcesCocoa.txt:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView modifierFlagsDidChangeFrom:to:]): Create a synthetic flags changed
web event based on the state change and dispatch it.
(-[WKContentView _didHandleKeyEvent:eventWasHandled:]): Early return if the event
was a synethic flags change event so that we do not notify UIKit about this event
as it does not know anything about such synthetic events.
* UIProcess/ios/WKSyntheticFlagsChangedWebEvent.h: Added.
* UIProcess/ios/WKSyntheticFlagsChangedWebEvent.mm: Added.
(-[WKSyntheticFlagsChangedWebEvent initWithKeyCode:modifiers:keyDown:]):
(-[WKSyntheticFlagsChangedWebEvent initWithCapsLockState:]):
(-[WKSyntheticFlagsChangedWebEvent initWithShiftState:]):
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (240287 => 240288)


--- trunk/Source/WebKit/ChangeLog	2019-01-22 21:02:30 UTC (rev 240287)
+++ trunk/Source/WebKit/ChangeLog	2019-01-22 21:15:35 UTC (rev 240288)
@@ -1,5 +1,36 @@
 2019-01-22  Daniel Bates  <[email protected]>
 
+        [iOS] WebKit should handle shift state changes when using the software keyboard
+        https://bugs.webkit.org/show_bug.cgi?id=191475
+        <rdar://problem/45949246>
+
+        Reviewed by Brent Fulgham.
+
+        Implement UIKit SPI to be notified of shift state changes to the software keyboard
+        and dispatch a synthetic keydown or keyup event for either the Shift key or Caps Lock
+        key.
+
+        A side benefit of this change is that we now show and hide the caps lock indicator
+        in a focused password field when caps lock is enabled or disabled using the software
+        keyboard, respectively.
+
+        * Platform/spi/ios/UIKitSPI.h: Expose more SPI.
+        * SourcesCocoa.txt:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView modifierFlagsDidChangeFrom:to:]): Create a synthetic flags changed
+        web event based on the state change and dispatch it.
+        (-[WKContentView _didHandleKeyEvent:eventWasHandled:]): Early return if the event
+        was a synethic flags change event so that we do not notify UIKit about this event
+        as it does not know anything about such synthetic events.
+        * UIProcess/ios/WKSyntheticFlagsChangedWebEvent.h: Added.
+        * UIProcess/ios/WKSyntheticFlagsChangedWebEvent.mm: Added.
+        (-[WKSyntheticFlagsChangedWebEvent initWithKeyCode:modifiers:keyDown:]):
+        (-[WKSyntheticFlagsChangedWebEvent initWithCapsLockState:]):
+        (-[WKSyntheticFlagsChangedWebEvent initWithShiftState:]):
+        * WebKit.xcodeproj/project.pbxproj:
+
+2019-01-22  Daniel Bates  <[email protected]>
+
         [iOS] Interpret text key commands on keydown and app key commands on keypress
         https://bugs.webkit.org/show_bug.cgi?id=192897
         <rdar://problem/46857378>

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


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2019-01-22 21:02:30 UTC (rev 240287)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2019-01-22 21:15:35 UTC (rev 240288)
@@ -393,6 +393,9 @@
 - (void)insertDictationResult:(NSArray *)dictationResult withCorrectionIdentifier:(id)correctionIdentifier;
 - (void)replaceRangeWithTextWithoutClosingTyping:(UITextRange *)range replacementText:(NSString *)text;
 - (void)setBottomBufferHeight:(CGFloat)bottomBuffer;
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+- (void)modifierFlagsDidChangeFrom:(UIKeyModifierFlags)oldFlags to:(UIKeyModifierFlags)newFlags;
+#endif
 @property (nonatomic) UITextGranularity selectionGranularity;
 @required
 - (BOOL)hasContent;

Modified: trunk/Source/WebKit/SourcesCocoa.txt (240287 => 240288)


--- trunk/Source/WebKit/SourcesCocoa.txt	2019-01-22 21:02:30 UTC (rev 240287)
+++ trunk/Source/WebKit/SourcesCocoa.txt	2019-01-22 21:15:35 UTC (rev 240288)
@@ -405,6 +405,7 @@
 UIProcess/ios/WKPDFView.mm
 UIProcess/ios/WKScrollView.mm
 UIProcess/ios/WKSyntheticClickTapGestureRecognizer.m
+UIProcess/ios/WKSyntheticFlagsChangedWebEvent.mm
 UIProcess/ios/WKSystemPreviewView.mm
 UIProcess/ios/WKWebEvent.mm
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (240287 => 240288)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-01-22 21:02:30 UTC (rev 240287)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-01-22 21:15:35 UTC (rev 240288)
@@ -56,6 +56,7 @@
 #import "WKPreviewElementInfoInternal.h"
 #import "WKQuickboardListViewController.h"
 #import "WKSelectMenuListViewController.h"
+#import "WKSyntheticFlagsChangedWebEvent.h"
 #import "WKTextInputListViewController.h"
 #import "WKTimePickerViewController.h"
 #import "WKUIDelegatePrivate.h"
@@ -3921,6 +3922,25 @@
     return CGRectZero;
 }
 
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+- (void)modifierFlagsDidChangeFrom:(UIKeyModifierFlags)oldFlags to:(UIKeyModifierFlags)newFlags
+{
+    auto dispatchSyntheticFlagsChangedEvents = [&] (UIKeyModifierFlags flags, bool keyDown) {
+        if (flags & UIKeyModifierShift)
+            [self handleKeyWebEvent:adoptNS([[WKSyntheticFlagsChangedWebEvent alloc] initWithShiftState:keyDown]).get()];
+        if (flags & UIKeyModifierAlphaShift)
+            [self handleKeyWebEvent:adoptNS([[WKSyntheticFlagsChangedWebEvent alloc] initWithCapsLockState:keyDown]).get()];
+    };
+
+    UIKeyModifierFlags removedFlags = oldFlags & ~newFlags;
+    UIKeyModifierFlags addedFlags = newFlags & ~oldFlags;
+    if (removedFlags)
+        dispatchSyntheticFlagsChangedEvents(removedFlags, false);
+    if (addedFlags)
+        dispatchSyntheticFlagsChangedEvents(addedFlags, true);
+}
+#endif
+
 // Web events.
 - (BOOL)requiresKeyEvents
 {
@@ -3965,6 +3985,11 @@
 
 - (void)_didHandleKeyEvent:(::WebEvent *)event eventWasHandled:(BOOL)eventWasHandled
 {
+#if USE(UIKIT_KEYBOARD_ADDITIONS)
+    if ([event isKindOfClass:[WKSyntheticFlagsChangedWebEvent class]])
+        return;
+#endif
+
     if (!(event.keyboardFlags & WebEventKeyboardInputModifierFlagsChanged))
         [_keyboardScrollingAnimator handleKeyEvent:event];
     

Added: trunk/Source/WebKit/UIProcess/ios/WKSyntheticFlagsChangedWebEvent.h (0 => 240288)


--- trunk/Source/WebKit/UIProcess/ios/WKSyntheticFlagsChangedWebEvent.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKSyntheticFlagsChangedWebEvent.h	2019-01-22 21:15:35 UTC (rev 240288)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if USE(UIKIT_KEYBOARD_ADDITIONS) && PLATFORM(IOS_FAMILY)
+
+#import <WebCore/WebEvent.h>
+
+@interface WKSyntheticFlagsChangedWebEvent : WebEvent
+
+- (instancetype)initWithCapsLockState:(BOOL)keyDown;
+- (instancetype)initWithShiftState:(BOOL)keyDown;
+
+@end
+
+#endif // USE(UIKIT_KEYBOARD_ADDITIONS) && PLATFORM(IOS_FAMILY)

Added: trunk/Source/WebKit/UIProcess/ios/WKSyntheticFlagsChangedWebEvent.mm (0 => 240288)


--- trunk/Source/WebKit/UIProcess/ios/WKSyntheticFlagsChangedWebEvent.mm	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/ios/WKSyntheticFlagsChangedWebEvent.mm	2019-01-22 21:15:35 UTC (rev 240288)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKSyntheticFlagsChangedWebEvent.h"
+
+#if USE(UIKIT_KEYBOARD_ADDITIONS) && PLATFORM(IOS_FAMILY)
+
+#import <pal/spi/cocoa/IOKitSPI.h>
+#import <pal/spi/ios/GraphicsServicesSPI.h>
+
+@implementation WKSyntheticFlagsChangedWebEvent
+
+- (instancetype)initWithKeyCode:(uint16_t)keyCode modifiers:(WebEventFlags)modifiers keyDown:(BOOL)keyDown
+{
+    self = [super initWithKeyEventType:(keyDown ? WebEventKeyDown : WebEventKeyUp) timeStamp:GSCurrentEventTimestamp() characters:@"" charactersIgnoringModifiers:@"" modifiers:modifiers isRepeating:NO withFlags:WebEventKeyboardInputModifierFlagsChanged withInputManagerHint:nil keyCode:keyCode isTabKey:(keyCode == kHIDUsage_KeyboardTab)];
+    return self;
+}
+
+- (instancetype)initWithCapsLockState:(BOOL)keyDown
+{
+    return [self initWithKeyCode:kHIDUsage_KeyboardCapsLock modifiers:(keyDown ? WebEventFlagMaskLeftCapsLockKey : 0) keyDown:keyDown];
+}
+
+- (instancetype)initWithShiftState:(BOOL)keyDown
+{
+    return [self initWithKeyCode:kHIDUsage_KeyboardLeftShift modifiers:(keyDown ? WebEventFlagMaskLeftShiftKey : 0) keyDown:keyDown];
+}
+
+@end
+
+#endif // USE(UIKIT_KEYBOARD_ADDITIONS) && PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (240287 => 240288)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-01-22 21:02:30 UTC (rev 240287)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2019-01-22 21:15:35 UTC (rev 240288)
@@ -1558,6 +1558,7 @@
 		CE1A0BD51A48E6C60054EF74 /* ManagedConfigurationSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BCF1A48E6C60054EF74 /* ManagedConfigurationSPI.h */; };
 		CE1A0BD61A48E6C60054EF74 /* TCCSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BD01A48E6C60054EF74 /* TCCSPI.h */; };
 		CE1A0BD71A48E6C60054EF74 /* TextInputSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1A0BD11A48E6C60054EF74 /* TextInputSPI.h */; };
+		CE5B4C8821B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5B4C8621B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h */; };
 		CEC8F9CB1FDF5870002635E7 /* WKWebProcessPlugInNodeHandlePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = CEC8F9CA1FDF5870002635E7 /* WKWebProcessPlugInNodeHandlePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CEDA12E3152CD1B300D9E08D /* WebAlternativeTextClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CEDA12DE152CCAE800D9E08D /* WebAlternativeTextClient.h */; };
 		CEE4AE2B1A5DCF430002F49B /* UIKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = CEE4AE2A1A5DCF430002F49B /* UIKitSPI.h */; };
@@ -4385,6 +4386,8 @@
 		CE1A0BCF1A48E6C60054EF74 /* ManagedConfigurationSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ManagedConfigurationSPI.h; sourceTree = "<group>"; };
 		CE1A0BD01A48E6C60054EF74 /* TCCSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TCCSPI.h; sourceTree = "<group>"; };
 		CE1A0BD11A48E6C60054EF74 /* TextInputSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextInputSPI.h; sourceTree = "<group>"; };
+		CE5B4C8621B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = WKSyntheticFlagsChangedWebEvent.h; path = ios/WKSyntheticFlagsChangedWebEvent.h; sourceTree = "<group>"; };
+		CE5B4C8721B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = WKSyntheticFlagsChangedWebEvent.mm; path = ios/WKSyntheticFlagsChangedWebEvent.mm; sourceTree = "<group>"; };
 		CEC8F9CA1FDF5870002635E7 /* WKWebProcessPlugInNodeHandlePrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInNodeHandlePrivate.h; sourceTree = "<group>"; };
 		CEDA12DE152CCAE800D9E08D /* WebAlternativeTextClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebAlternativeTextClient.h; sourceTree = "<group>"; };
 		CEDA12DF152CCAE800D9E08D /* WebAlternativeTextClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebAlternativeTextClient.cpp; sourceTree = "<group>"; };
@@ -5853,6 +5856,8 @@
 				0FCB4E4518BBE044000FCFC9 /* WKScrollView.mm */,
 				26F10BE619187E2E001D0E68 /* WKSyntheticClickTapGestureRecognizer.h */,
 				26F10BE719187E2E001D0E68 /* WKSyntheticClickTapGestureRecognizer.m */,
+				CE5B4C8621B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h */,
+				CE5B4C8721B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.mm */,
 				316B8B622054B55800BD4A62 /* WKSystemPreviewView.h */,
 				316B8B612054B55800BD4A62 /* WKSystemPreviewView.mm */,
 				2D1E8221216FFF5000A15265 /* WKWebEvent.h */,
@@ -9849,6 +9854,7 @@
 				BC40761A124FF0370068F20A /* WKStringCF.h in Headers */,
 				BC9099801256A98200083756 /* WKStringPrivate.h in Headers */,
 				26F10BE819187E2E001D0E68 /* WKSyntheticClickTapGestureRecognizer.h in Headers */,
+				CE5B4C8821B73D870022E64F /* WKSyntheticFlagsChangedWebEvent.h in Headers */,
 				316B8B642054B55800BD4A62 /* WKSystemPreviewView.h in Headers */,
 				51F886A61F2C228100C193EF /* WKTestingSupport.h in Headers */,
 				31D755C11D91B81500843BD1 /* WKTextChecker.h in Headers */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to