Title: [181836] trunk/Source/WebKit2
Revision
181836
Author
[email protected]
Date
2015-03-22 14:44:50 -0700 (Sun, 22 Mar 2015)

Log Message

[iOS] Expose WebPageProxy::setInitialFocus as SPI
https://bugs.webkit.org/show_bug.cgi?id=142951

Reviewed by Anders Carlsson.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]): New SPI.
Just calls through to WKWebContentView, but allows a nil completion handler.
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

* UIProcess/API/mac/WKView.mm:
(-[WKView becomeFirstResponder]): Pass an empty lambda for the new callback parameter to
WebPageProxy::setInitialFocus.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setInitialFocus): Added a void callback parameter and made sure to
call it.
* UIProcess/WebPageProxy.h:

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):
Added. Calls WebPageProxy::setInitialFocus, and once that completes, checks if anything was
focused and if so, becomes first responder, then calls the completion handler.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setInitialFocus): Added a callbackID parameter, and made sure to send the
callback message. Added a temporary change of m_userIsInteracting to true, so that the UI
process won’t ignore any StartAssistingNode message resulting from the focus change.
* WebProcess/WebPage/WebPage.h:

* WebProcess/WebPage/WebPage.messages.in: Added a callbackID parameter to SetInitialFocus.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (181835 => 181836)


--- trunk/Source/WebKit2/ChangeLog	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/ChangeLog	2015-03-22 21:44:50 UTC (rev 181836)
@@ -1,3 +1,38 @@
+2015-03-22  Dan Bernstein  <[email protected]>
+
+        [iOS] Expose WebPageProxy::setInitialFocus as SPI
+        https://bugs.webkit.org/show_bug.cgi?id=142951
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]): New SPI.
+        Just calls through to WKWebContentView, but allows a nil completion handler.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView becomeFirstResponder]): Pass an empty lambda for the new callback parameter to
+        WebPageProxy::setInitialFocus.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setInitialFocus): Added a void callback parameter and made sure to
+        call it.
+        * UIProcess/WebPageProxy.h:
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _becomeFirstResponderWithSelectionMovingForward:completionHandler:]):
+        Added. Calls WebPageProxy::setInitialFocus, and once that completes, checks if anything was
+        focused and if so, becomes first responder, then calls the completion handler.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setInitialFocus): Added a callbackID parameter, and made sure to send the
+        callback message. Added a temporary change of m_userIsInteracting to true, so that the UI
+        process won’t ignore any StartAssistingNode message resulting from the focus change.
+        * WebProcess/WebPage/WebPage.h:
+
+        * WebProcess/WebPage/WebPage.messages.in: Added a callbackID parameter to SetInitialFocus.
+
 2015-03-21  Dean Jackson  <[email protected]>
 
         Remove the prefix for CSS Transforms

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2015-03-22 21:44:50 UTC (rev 181836)
@@ -90,6 +90,7 @@
 #import "RemoteLayerTreeDrawingAreaProxy.h"
 #import "RemoteScrollingCoordinatorProxy.h"
 #import "UIKitSPI.h"
+#import "WKContentViewInteraction.h"
 #import "WKPDFView.h"
 #import "WKScrollView.h"
 #import "WKWebViewContentProviderRegistry.h"
@@ -1786,6 +1787,21 @@
     } copy] autorelease];
 }
 
+- (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler
+{
+    typeof(completionHandler) completionHandlerCopy = nil;
+    if (completionHandler)
+        completionHandlerCopy = Block_copy(completionHandler);
+
+    [_contentView _becomeFirstResponderWithSelectionMovingForward:selectingForward completionHandler:[completionHandlerCopy](BOOL didBecomeFirstResponder) {
+        if (!completionHandlerCopy)
+            return;
+
+        completionHandlerCopy(didBecomeFirstResponder);
+        Block_release(completionHandlerCopy);
+    }];
+}
+
 #endif
 
 - (void)_didRelaunchProcess

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2015-03-22 21:44:50 UTC (rev 181836)
@@ -155,6 +155,8 @@
 // will not count as becoming inactive and unfocused. The returned block must be called to exit the state.
 - (void (^)(void))_retainActiveFocusedState WK_AVAILABLE(NA, WK_IOS_TBA);
 
+- (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler WK_AVAILABLE(NA, WK_IOS_TBA);
+
 #else
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
 @property (nonatomic, setter=_setDrawsTransparentBackground:) BOOL _drawsTransparentBackground;

Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-03-22 21:44:50 UTC (rev 181836)
@@ -401,7 +401,7 @@
         NSEvent *keyboardEvent = nil;
         if ([event type] == NSKeyDown || [event type] == NSKeyUp)
             keyboardEvent = event;
-        _data->_page->setInitialFocus(direction == NSSelectingNext, keyboardEvent != nil, NativeWebKeyboardEvent(keyboardEvent, false, Vector<KeypressCommand>()));
+        _data->_page->setInitialFocus(direction == NSSelectingNext, keyboardEvent != nil, NativeWebKeyboardEvent(keyboardEvent, false, Vector<KeypressCommand>()), [](CallbackBase::Error) { });
     }
     return YES;
 }

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-03-22 21:44:50 UTC (rev 181836)
@@ -1419,11 +1419,15 @@
     return m_pageClient.viewSize();
 }
 
-void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent)
+void WebPageProxy::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& keyboardEvent, std::function<void (CallbackBase::Error)> callbackFunction)
 {
-    if (!isValid())
+    if (!isValid()) {
+        callbackFunction(CallbackBase::Error::OwnerWasInvalidated);
         return;
-    m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent), m_pageID);
+    }
+
+    uint64_t callbackID = m_callbacks.put(WTF::move(callbackFunction), m_process->throttler().backgroundActivityToken());
+    m_process->send(Messages::WebPage::SetInitialFocus(forward, isKeyboardEventValid, keyboardEvent, callbackID), m_pageID);
 }
 
 void WebPageProxy::setWindowResizerSize(const IntSize& windowResizerSize)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-03-22 21:44:50 UTC (rev 181836)
@@ -389,7 +389,7 @@
     void viewWillStartLiveResize();
     void viewWillEndLiveResize();
 
-    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&);
+    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&, std::function<void (CallbackBase::Error)>);
     void setWindowResizerSize(const WebCore::IntSize&);
     
     void clearSelection();

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h	2015-03-22 21:44:50 UTC (rev 181836)
@@ -196,6 +196,7 @@
 - (Vector<WebKit::OptionItem>&) assistedNodeSelectOptions;
 - (void)_enableInspectorNodeSearch;
 - (void)_disableInspectorNodeSearch;
+- (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler;
 @end
 
 #endif // PLATFORM(IOS)

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (181835 => 181836)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2015-03-22 21:44:50 UTC (rev 181836)
@@ -2053,6 +2053,16 @@
 
 }
 
+- (void)_becomeFirstResponderWithSelectionMovingForward:(BOOL)selectingForward completionHandler:(void (^)(BOOL didBecomeFirstResponder))completionHandler
+{
+    auto completionHandlerCopy = Block_copy(completionHandler);
+    _page->setInitialFocus(selectingForward, false, WebKit::WebKeyboardEvent(), [self, completionHandlerCopy](WebKit::CallbackBase::Error) {
+        BOOL didBecomeFirstResponder = _assistedNodeInformation.elementType != InputType::None && [self becomeFirstResponder];
+        completionHandlerCopy(didBecomeFirstResponder);
+        Block_release(completionHandlerCopy);
+    });
+}
+
 - (void)accessoryAutoFill
 {
     id <_WKFormDelegate> formDelegate = [_webView _formDelegate];

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (181835 => 181836)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-03-22 21:44:50 UTC (rev 181836)
@@ -167,6 +167,7 @@
 #include <runtime/JSCJSValue.h>
 #include <runtime/JSLock.h>
 #include <wtf/RunLoop.h>
+#include <wtf/TemporaryChange.h>
 
 #if ENABLE(MHTML)
 #include <WebCore/MHTMLArchive.h>
@@ -2207,11 +2208,15 @@
         view->willEndLiveResize();
 }
 
-void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& event)
+void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent& event, uint64_t callbackID)
 {
     if (!m_page)
         return;
 
+#if PLATFORM(IOS)
+    TemporaryChange<bool> userIsInteractingChange { m_userIsInteracting, true };
+#endif
+
     Frame& frame = m_page->focusController().focusedOrMainFrame();
     frame.document()->setFocusedElement(0);
 
@@ -2219,10 +2224,13 @@
         PlatformKeyboardEvent platformEvent(platform(event));
         platformEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
         m_page->focusController().setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, &KeyboardEvent::create(platformEvent, frame.document()->defaultView()).get());
+
+        send(Messages::WebPageProxy::VoidCallback(callbackID));
         return;
     }
 
     m_page->focusController().setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, 0);
+    send(Messages::WebPageProxy::VoidCallback(callbackID));
 }
 
 void WebPage::setWindowResizerSize(const IntSize& windowResizerSize)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (181835 => 181836)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-03-22 21:44:50 UTC (rev 181836)
@@ -928,7 +928,7 @@
     void goBack(uint64_t navigationID, uint64_t);
     void goToBackForwardItem(uint64_t navigationID, uint64_t);
     void tryRestoreScrollPosition();
-    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&);
+    void setInitialFocus(bool forward, bool isKeyboardEventValid, const WebKeyboardEvent&, uint64_t callbackID);
     void setWindowResizerSize(const WebCore::IntSize&);
     void updateIsInWindow(bool isInitialState = false);
     void setViewState(WebCore::ViewState::Flags, bool wantsDidUpdateViewState, const Vector<uint64_t>& callbackIDs);

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (181835 => 181836)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-03-22 19:35:26 UTC (rev 181835)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-03-22 21:44:50 UTC (rev 181836)
@@ -21,7 +21,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebPage LegacyReceiver {
-    SetInitialFocus(bool forward, bool isKeyboardEventValid, WebKit::WebKeyboardEvent event)
+    SetInitialFocus(bool forward, bool isKeyboardEventValid, WebKit::WebKeyboardEvent event, uint64_t callbackID)
     SetViewState(unsigned viewState, bool wantsDidUpdateViewState, Vector<uint64_t> callbackIDs)
     SetLayerHostingMode(unsigned layerHostingMode)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to