[iOS] Automatic focus of input field is flaky
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2019 23:30:52 +0000 (23:30 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Mar 2019 23:30:52 +0000 (23:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196302

Reviewed by Brent Fulgham.

Sometimes the status of whether a keyboard is connected can be incorrect, both in the UI process, and in
the WebContent process. Fix this by sending the keyboard status to the WebContent process as part of the
Web page creation parameters. Stop caching the keyboard status in the Web process proxy, and call
[UIKeyboard isInHardwareKeyboardMode] instead, since this method is swizzled in the test harness.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(hardwareKeyboardAvailabilityChangedCallback):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
* UIProcess/WebPageProxy.h:
* UIProcess/WebProcessProxy.cpp:
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::setKeyboardIsAttached): Deleted.
(WebKit::WebProcessProxy::keyboardIsAttached const): Deleted.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::isInHardwareKeyboardMode):
(WebKit::WebPageProxy::applicationWillEnterForeground):
* WebProcess/WebPage/WebPage.cpp:
* WebProcess/WebPage/WebPage.h:

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

Source/WebKit/ChangeLog
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h

index a16593b..63820da 100644 (file)
@@ -1,3 +1,36 @@
+2019-03-28  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Automatic focus of input field is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=196302
+
+        Reviewed by Brent Fulgham.
+
+        Sometimes the status of whether a keyboard is connected can be incorrect, both in the UI process, and in
+        the WebContent process. Fix this by sending the keyboard status to the WebContent process as part of the
+        Web page creation parameters. Stop caching the keyboard status in the Web process proxy, and call
+        [UIKeyboard isInHardwareKeyboardMode] instead, since this method is swizzled in the test harness.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (hardwareKeyboardAvailabilityChangedCallback):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebProcessProxy.cpp:
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::setKeyboardIsAttached): Deleted.
+        (WebKit::WebProcessProxy::keyboardIsAttached const): Deleted.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::isInHardwareKeyboardMode):
+        (WebKit::WebPageProxy::applicationWillEnterForeground):
+        * WebProcess/WebPage/WebPage.cpp:
+        * WebProcess/WebPage/WebPage.h:
+
 2019-03-28  Tim Horton  <timothy_horton@apple.com>
 
         Fix the build.
index 5905745..9831a66 100644 (file)
@@ -93,6 +93,7 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << viewportConfigurationViewSize;
     encoder << maximumUnobscuredSize;
     encoder << deviceOrientation;
+    encoder << keyboardIsAttached;
 #endif
 #if PLATFORM(COCOA)
     encoder << smartInsertDeleteEnabled;
@@ -273,6 +274,8 @@ Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decod
         return WTF::nullopt;
     if (!decoder.decode(parameters.deviceOrientation))
         return WTF::nullopt;
+    if (!decoder.decode(parameters.keyboardIsAttached))
+        return WTF::nullopt;
 #endif
 
 #if PLATFORM(COCOA)
index 976c886..45eba4d 100644 (file)
@@ -151,6 +151,7 @@ struct WebPageCreationParameters {
     WebCore::FloatSize viewportConfigurationViewSize;
     WebCore::FloatSize maximumUnobscuredSize;
     int32_t deviceOrientation { 0 };
+    bool keyboardIsAttached { false };
 #endif
 #if PLATFORM(COCOA)
     bool smartInsertDeleteEnabled;
index d90e8ea..ec6cc7f 100644 (file)
@@ -3322,9 +3322,7 @@ static void hardwareKeyboardAvailabilityChangedCallback(CFNotificationCenterRef,
 {
     ASSERT(observer);
     WKWebView *webView = (__bridge WKWebView *)observer;
-    auto keyboardIsAttached = GSEventIsHardwareKeyboardAttached();
-    webView._page->process().setKeyboardIsAttached(keyboardIsAttached);
-    webView._page->hardwareKeyboardAvailabilityChanged(keyboardIsAttached);
+    webView._page->hardwareKeyboardAvailabilityChanged(GSEventIsHardwareKeyboardAttached());
 }
 
 - (void)_windowDidRotate:(NSNotification *)notification
index 362e984..aa71eb7 100644 (file)
@@ -7022,6 +7022,7 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
     parameters.viewportConfigurationLayoutSizeScaleFactor = m_viewportConfigurationLayoutSizeScaleFactor;
     parameters.maximumUnobscuredSize = m_maximumUnobscuredSize;
     parameters.deviceOrientation = m_deviceOrientation;
+    parameters.keyboardIsAttached = isInHardwareKeyboardMode();
 #endif
 
 #if PLATFORM(MAC)
index 1447351..ac7feb5 100644 (file)
@@ -2050,6 +2050,10 @@ private:
     SpeechSynthesisData& speechSynthesisData();
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+    static bool isInHardwareKeyboardMode();
+#endif
+
     WeakPtr<PageClient> m_pageClient;
     Ref<API::PageConfiguration> m_configuration;
 
index 93ab682..a253ae5 100644 (file)
@@ -275,11 +275,6 @@ public:
     void sendProcessDidResume() override;
     void didSetAssertionState(AssertionState) override;
 
-#if PLATFORM(IOS_FAMILY)
-    void setKeyboardIsAttached(bool keyboardIsAttached) { m_keyboardIsAttached = keyboardIsAttached; }
-    bool keyboardIsAttached() const { return m_keyboardIsAttached; }
-#endif
-
 #if PLATFORM(COCOA)
     enum SandboxExtensionType : uint32_t {
         None = 0,
@@ -475,10 +470,6 @@ private:
     ProcessThrottler::BackgroundActivityToken m_backgroundActivityTokenForFullscreenFormControls;
 #endif
 
-#if PLATFORM(IOS_FAMILY)
-    bool m_keyboardIsAttached { false };
-#endif
-
 #if PLATFORM(COCOA)
     MediaCaptureSandboxExtensions m_mediaCaptureSandboxExtensions { SandboxExtensionType::None };
 #endif
index 8ba657a..4f9ef13 100644 (file)
@@ -4930,7 +4930,7 @@ static RetainPtr<NSObject <WKFormPeripheral>> createInputPeripheralWithView(WebK
                 if (_isChangingFocus)
                     return YES;
 
-                if (_page->process().keyboardIsAttached())
+                if ([UIKeyboard isInHardwareKeyboardMode])
                     return YES;
 #endif
             }
index b0a8523..2e8580e 100644 (file)
@@ -663,12 +663,16 @@ void WebPageProxy::applicationDidFinishSnapshottingAfterEnteringBackground()
     m_process->send(Messages::WebPage::ApplicationDidFinishSnapshottingAfterEnteringBackground(), m_pageID);
 }
 
+bool WebPageProxy::isInHardwareKeyboardMode()
+{
+    return [UIKeyboard isInHardwareKeyboardMode];
+}
+
 void WebPageProxy::applicationWillEnterForeground()
 {
     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
     m_process->send(Messages::WebPage::ApplicationWillEnterForeground(isSuspendedUnderLock), m_pageID);
-    m_process->setKeyboardIsAttached([UIKeyboard isInHardwareKeyboardMode]);
-    m_process->send(Messages::WebPage::HardwareKeyboardAvailabilityChanged(m_process->keyboardIsAttached()), m_pageID);
+    m_process->send(Messages::WebPage::HardwareKeyboardAvailabilityChanged(isInHardwareKeyboardMode()), m_pageID);
 }
 
 void WebPageProxy::applicationWillResignActive()
index a7cf18e..b9e6382 100644 (file)
@@ -406,6 +406,7 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
     , m_availableScreenSize(parameters.availableScreenSize)
     , m_overrideScreenSize(parameters.overrideScreenSize)
     , m_deviceOrientation(parameters.deviceOrientation)
+    , m_keyboardIsAttached(parameters.keyboardIsAttached)
 #endif
     , m_layerVolatilityTimer(*this, &WebPage::layerVolatilityTimerFired)
     , m_activityState(parameters.activityState)
index 81b692c..dad5d92 100644 (file)
@@ -1804,6 +1804,7 @@ private:
     WebCore::IntSize m_blockSelectionDesiredSize;
     WebCore::FloatSize m_maximumUnobscuredSize;
     int32_t m_deviceOrientation { 0 };
+    bool m_keyboardIsAttached { false };
     bool m_inDynamicSizeUpdate { false };
     HashMap<std::pair<WebCore::IntSize, double>, WebCore::IntPoint> m_dynamicSizeUpdateHistory;
     RefPtr<WebCore::Node> m_pendingSyntheticClickNode;
@@ -1884,9 +1885,6 @@ private:
     OptionSet<LayerTreeFreezeReason> m_LayerTreeFreezeReasons;
     bool m_isSuspended { false };
     bool m_needsFontAttributes { false };
-#if PLATFORM(IOS_FAMILY)
-    bool m_keyboardIsAttached { false };
-#endif
 };
 
 } // namespace WebKit