[iOS] Move calls to [UIKeyboard isInHardwareKeyboardMode] to the UI process.
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Feb 2019 21:39:52 +0000 (21:39 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Feb 2019 21:39:52 +0000 (21:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193683
<rdar://problem/47634345>

Reviewed by Brent Fulgham.

When a keyboard is attached/deattached or the application becomes foreground, send a message from
the UI process to the WebContent process, notifying whether a keyboard is attached or not. Also,
cache the value of [UIKeyboard isInHardwareKeyboardMode] in the UI process, since this call seems
to be expensive.

* UIProcess/API/Cocoa/WKWebView.mm:
(hardwareKeyboardAvailabilityChangedCallback):
* UIProcess/WebPageProxy.h:
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::setKeyboardIsAttached):
(WebKit::WebProcessProxy::keyboardIsAttached const):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applicationWillEnterForeground):
(WebKit::WebPageProxy::hardwareKeyboardAvailabilityChanged):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState const):
(WebKit::WebPage::hardwareKeyboardAvailabilityChanged):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
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.h
Source/WebKit/WebProcess/WebPage/WebPage.messages.in
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

index f7ed493..429392c 100644 (file)
@@ -1,3 +1,33 @@
+2019-02-28  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Move calls to [UIKeyboard isInHardwareKeyboardMode] to the UI process.
+        https://bugs.webkit.org/show_bug.cgi?id=193683
+        <rdar://problem/47634345>
+
+        Reviewed by Brent Fulgham.
+
+        When a keyboard is attached/deattached or the application becomes foreground, send a message from
+        the UI process to the WebContent process, notifying whether a keyboard is attached or not. Also,
+        cache the value of [UIKeyboard isInHardwareKeyboardMode] in the UI process, since this call seems
+        to be expensive.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (hardwareKeyboardAvailabilityChangedCallback):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebProcessProxy.h:
+        (WebKit::WebProcessProxy::setKeyboardIsAttached):
+        (WebKit::WebProcessProxy::keyboardIsAttached const):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applicationWillEnterForeground):
+        (WebKit::WebPageProxy::hardwareKeyboardAvailabilityChanged):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::platformEditorState const):
+        (WebKit::WebPage::hardwareKeyboardAvailabilityChanged):
+
 2019-02-28  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [CoordinatedGraphics] Remove COORDINATED_GRAPHICS_THREADED option
index 05dd0e6..0153d48 100644 (file)
@@ -3304,7 +3304,9 @@ static void hardwareKeyboardAvailabilityChangedCallback(CFNotificationCenterRef,
 {
     ASSERT(observer);
     WKWebView *webView = (__bridge WKWebView *)observer;
-    webView._page->hardwareKeyboardAvailabilityChanged();
+    auto keyboardIsAttached = GSEventIsHardwareKeyboardAttached();
+    webView._page->process().setKeyboardIsAttached(keyboardIsAttached);
+    webView._page->hardwareKeyboardAvailabilityChanged(keyboardIsAttached);
 }
 
 - (void)_windowDidRotate:(NSNotification *)notification
index 8be426c..2a539f5 100644 (file)
@@ -685,7 +685,7 @@ public:
     void storeSelectionForAccessibility(bool);
     void startAutoscrollAtPosition(const WebCore::FloatPoint& positionInWindow);
     void cancelAutoscroll();
-    void hardwareKeyboardAvailabilityChanged();
+    void hardwareKeyboardAvailabilityChanged(bool keyboardIsAttached);
     bool isScrollingOrZooming() const { return m_isScrollingOrZooming; }
     void requestEvasionRectsAboveSelection(CompletionHandler<void(const Vector<WebCore::FloatRect>&)>&&);
 #if ENABLE(DATA_INTERACTION)
index 91ad456..0ba43e1 100644 (file)
@@ -269,6 +269,11 @@ 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,
@@ -458,6 +463,10 @@ 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 82d8bc0..df7f72e 100644 (file)
@@ -4849,7 +4849,7 @@ static const double minimumFocusedElementAreaForSuppressingSelectionAssistant =
                 if (_isChangingFocus)
                     return YES;
 
-                if (UIKeyboard.isInHardwareKeyboardMode)
+                if (_page->process().keyboardIsAttached())
                     return YES;
 #endif
             }
index 2d80f80..2ba637d 100644 (file)
@@ -670,6 +670,8 @@ 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);
 }
 
 void WebPageProxy::applicationWillResignActive()
@@ -1107,10 +1109,10 @@ void WebPageProxy::setIsScrollingOrZooming(bool isScrollingOrZooming)
         m_validationBubble->show();
 }
 
-void WebPageProxy::hardwareKeyboardAvailabilityChanged()
+void WebPageProxy::hardwareKeyboardAvailabilityChanged(bool keyboardIsAttached)
 {
     updateCurrentModifierState();
-    m_process->send(Messages::WebPage::HardwareKeyboardAvailabilityChanged(), m_pageID);
+    m_process->send(Messages::WebPage::HardwareKeyboardAvailabilityChanged(keyboardIsAttached), m_pageID);
 }
 
 void WebPageProxy::requestEvasionRectsAboveSelection(CompletionHandler<void(const Vector<WebCore::FloatRect>&)>&& callback)
index 2f6d79d..9ee06fb 100644 (file)
@@ -937,7 +937,7 @@ public:
     bool platformPrefersTextLegibilityBasedZoomScaling() const;
     const WebCore::ViewportConfiguration& viewportConfiguration() const { return m_viewportConfiguration; }
 
-    void hardwareKeyboardAvailabilityChanged();
+    void hardwareKeyboardAvailabilityChanged(bool keyboardIsAttached);
 
     void updateStringForFind(const String&);
 #endif
@@ -1843,6 +1843,9 @@ private:
     OptionSet<LayerTreeFreezeReason> m_LayerTreeFreezeReasons;
     bool m_isSuspended { false };
     bool m_needsFontAttributes { false };
+#if PLATFORM(IOS_FAMILY)
+    bool m_keyboardIsAttached { false };
+#endif
 };
 
 } // namespace WebKit
index 64950a9..cb0b570 100644 (file)
@@ -108,7 +108,7 @@ messages -> WebPage LegacyReceiver {
     StartAutoscrollAtPosition(WebCore::FloatPoint positionInWindow)
     CancelAutoscroll()
     RequestFocusedElementInformation(WebKit::CallbackID callbackID)
-    HardwareKeyboardAvailabilityChanged()
+    HardwareKeyboardAvailabilityChanged(bool keyboardIsAttached)
 #endif
 
     SetControlledByAutomation(bool controlled)
index 5197fe2..d6d14b1 100644 (file)
@@ -203,7 +203,7 @@ void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePost
     bool needsLayout = !frame.view() || frame.view()->needsLayout();
     bool requiresPostLayoutData = frame.editor().hasComposition();
 #if !PLATFORM(IOSMAC)
-    requiresPostLayoutData |= [UIKeyboard isInHardwareKeyboardMode];
+    requiresPostLayoutData |= m_keyboardIsAttached;
 #endif
     if (shouldIncludePostLayoutData == IncludePostLayoutDataHint::No && needsLayout && !requiresPostLayoutData) {
         result.isMissingPostLayoutData = true;
@@ -3234,8 +3234,10 @@ String WebPage::platformUserAgent(const URL&) const
     return String();
 }
 
-void WebPage::hardwareKeyboardAvailabilityChanged()
+void WebPage::hardwareKeyboardAvailabilityChanged(bool keyboardIsAttached)
 {
+    m_keyboardIsAttached = keyboardIsAttached;
+
     if (auto* focusedFrame = m_page->focusController().focusedFrame())
         focusedFrame->eventHandler().capsLockStateMayHaveChanged();
 }