Title: [167774] trunk/Source/WebKit2
Revision
167774
Author
enr...@apple.com
Date
2014-04-24 14:44:42 -0700 (Thu, 24 Apr 2014)

Log Message

[iOS WebKit2] Should properly handle focus redirect (keyboard state changes when focus changes).
https://bugs.webkit.org/show_bug.cgi?id=132136
<rdar://problem/16238336>

Reviewed by Benjamin Poulain.

Focusing a field from _javascript_ should not make the keyboard or the select picker
appear unless the user has already started interacting with one of the fields in the page.
Adding a parameter to StartAssistingNode to indicate whether the focus change is a result
of a user action.

* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::startAssistingNode):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _startAssistingNode:userIsInteracting:userObject:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::startAssistingNode):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
(WebKit::WebPage::dispatchTouchEvent):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::handleTap):
(WebKit::WebPage::elementDidFocus):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (167773 => 167774)


--- trunk/Source/WebKit2/ChangeLog	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/ChangeLog	2014-04-24 21:44:42 UTC (rev 167774)
@@ -1,3 +1,35 @@
+2014-04-24  Enrica Casucci  <enr...@apple.com>
+
+        [iOS WebKit2] Should properly handle focus redirect (keyboard state changes when focus changes).
+        https://bugs.webkit.org/show_bug.cgi?id=132136
+        <rdar://problem/16238336>
+
+        Reviewed by Benjamin Poulain.
+
+        Focusing a field from _javascript_ should not make the keyboard or the select picker
+        appear unless the user has already started interacting with one of the fields in the page.
+        Adding a parameter to StartAssistingNode to indicate whether the focus change is a result
+        of a user action.
+
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::startAssistingNode):
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _startAssistingNode:userIsInteracting:userObject:]):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::startAssistingNode):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::WebPage):
+        (WebKit::WebPage::dispatchTouchEvent):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::handleTap):
+        (WebKit::WebPage::elementDidFocus):
+
 2014-04-24  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         FontCache::fontCache() never returns nullptr so it can be made to return a reference instead

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2014-04-24 21:44:42 UTC (rev 167774)
@@ -243,7 +243,7 @@
     virtual void didCommitLayerTree(const RemoteLayerTreeTransaction&) = 0;
     virtual void dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition) = 0;
 
-    virtual void startAssistingNode(const AssistedNodeInformation&, API::Object* userData) = 0;
+    virtual void startAssistingNode(const AssistedNodeInformation&, bool userIsInteracting, API::Object* userData) = 0;
     virtual void stopAssistingNode() = 0;
     virtual void selectionDidChange() = 0;
     virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) = 0;

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2014-04-24 21:44:42 UTC (rev 167774)
@@ -1356,7 +1356,7 @@
     void dynamicViewportUpdateChangedTarget(double newTargetScale, const WebCore::FloatPoint& newScrollPosition);
     void didGetTapHighlightGeometries(uint64_t requestID, const WebCore::Color& color, const Vector<WebCore::FloatQuad>& geometries, const WebCore::IntSize& topLeftRadius, const WebCore::IntSize& topRightRadius, const WebCore::IntSize& bottomLeftRadius, const WebCore::IntSize& bottomRightRadius);
 
-    void startAssistingNode(const AssistedNodeInformation&, IPC::MessageDecoder&);
+    void startAssistingNode(const AssistedNodeInformation&, bool userIsInteracting, IPC::MessageDecoder&);
     void stopAssistingNode();
 
 #if ENABLE(INSPECTOR)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2014-04-24 21:44:42 UTC (rev 167774)
@@ -320,7 +320,7 @@
     DynamicViewportUpdateChangedTarget(double newTargetScale, WebCore::FloatPoint newScrollPosition)
     DidGetTapHighlightGeometries(uint64_t requestID, WebCore::Color color, Vector<WebCore::FloatQuad> geometries, WebCore::IntSize topLeftRadius, WebCore::IntSize topRightRadius, WebCore::IntSize bottomLeftRadius, WebCore::IntSize bottomRightRadius)
 
-    StartAssistingNode(WebKit::AssistedNodeInformation information, WebKit::InjectedBundleUserMessageEncoder userData) Variadic
+    StartAssistingNode(WebKit::AssistedNodeInformation information, bool userIsInteracting, WebKit::InjectedBundleUserMessageEncoder userData) Variadic
     StopAssistingNode()
     NotifyRevealedSelection()
 

Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h	2014-04-24 21:44:42 UTC (rev 167774)
@@ -109,7 +109,7 @@
     virtual void didCommitLayerTree(const RemoteLayerTreeTransaction&) override;
     virtual void dynamicViewportUpdateChangedTarget(double newScale, const WebCore::FloatPoint& newScrollPosition) override;
 
-    virtual void startAssistingNode(const AssistedNodeInformation&, API::Object* userData) override;
+    virtual void startAssistingNode(const AssistedNodeInformation&, bool userIsInteracting, API::Object* userData) override;
     virtual void stopAssistingNode() override;
     virtual void selectionDidChange() override;
     virtual bool interpretKeyEvent(const NativeWebKeyboardEvent&, bool isCharEvent) override;

Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm	2014-04-24 21:44:42 UTC (rev 167774)
@@ -373,7 +373,7 @@
     [m_webView _dynamicViewportUpdateChangedTargetToScale:newScale position:newScrollPosition];
 }
 
-void PageClientImpl::startAssistingNode(const AssistedNodeInformation& nodeInformation, API::Object* userData)
+void PageClientImpl::startAssistingNode(const AssistedNodeInformation& nodeInformation, bool userIsInteracting, API::Object* userData)
 {
     MESSAGE_CHECK(!userData || userData->type() == API::Object::Type::Data);
 
@@ -389,7 +389,7 @@
         }
     }
 
-    [m_contentView _startAssistingNode:nodeInformation userObject:userObject];
+    [m_contentView _startAssistingNode:nodeInformation userIsInteracting:userIsInteracting userObject:userObject];
 }
 
 void PageClientImpl::stopAssistingNode()

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.h	2014-04-24 21:44:42 UTC (rev 167774)
@@ -133,7 +133,7 @@
 - (void)_webTouchEvent:(const WebKit::NativeWebTouchEvent&)touchEvent preventsNativeGestures:(BOOL)preventsDefault;
 - (void)_didGetTapHighlightForRequest:(uint64_t)requestID color:(const WebCore::Color&)color quads:(const Vector<WebCore::FloatQuad>&)highlightedQuads topLeftRadius:(const WebCore::IntSize&)topLeftRadius topRightRadius:(const WebCore::IntSize&)topRightRadius bottomLeftRadius:(const WebCore::IntSize&)bottomLeftRadius bottomRightRadius:(const WebCore::IntSize&)bottomRightRadius;
 
-- (void)_startAssistingNode:(const WebKit::AssistedNodeInformation&)information userObject:(NSObject <NSSecureCoding> *)userObject;
+- (void)_startAssistingNode:(const WebKit::AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting userObject:(NSObject <NSSecureCoding> *)userObject;
 - (void)_stopAssistingNode;
 - (void)_selectionChanged;
 - (void)_updateChangedSelection;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm	2014-04-24 21:44:42 UTC (rev 167774)
@@ -1979,8 +1979,11 @@
     return _formAccessoryView.get();
 }
 
-- (void)_startAssistingNode:(const AssistedNodeInformation&)information userObject:(NSObject <NSSecureCoding> *)userObject
+- (void)_startAssistingNode:(const AssistedNodeInformation&)information userIsInteracting:(BOOL)userIsInteracting userObject:(NSObject <NSSecureCoding> *)userObject
 {
+    if (!userIsInteracting && !_textSelectionAssistant)
+        return;
+
     _isEditable = YES;
     _assistedNodeInformation = information;
     _inputPeripheral = nil;

Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (167773 => 167774)


--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2014-04-24 21:44:42 UTC (rev 167774)
@@ -488,14 +488,14 @@
     m_pageClient.didGetTapHighlightGeometries(requestID, color, highlightedQuads, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
 }
 
-void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, IPC::MessageDecoder& decoder)
+void WebPageProxy::startAssistingNode(const AssistedNodeInformation& information, bool userIsInteracting, IPC::MessageDecoder& decoder)
 {
     RefPtr<API::Object> userData;
     WebContextUserMessageDecoder messageDecoder(userData, process());
     if (!decoder.decode(messageDecoder))
         return;
 
-    m_pageClient.startAssistingNode(information, userData.get());
+    m_pageClient.startAssistingNode(information, userIsInteracting, userData.get());
 }
 
 void WebPageProxy::stopAssistingNode()

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (167773 => 167774)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2014-04-24 21:44:42 UTC (rev 167774)
@@ -286,6 +286,7 @@
     , m_hasReceivedVisibleContentRectsAfterDidCommitLoad(false)
     , m_scaleWasSetByUIProcess(false)
     , m_userHasChangedPageScaleFactor(false)
+    , m_userIsInteracting(false)
     , m_screenSize(parameters.screenSize)
     , m_availableScreenSize(parameters.availableScreenSize)
     , m_inDynamicSizeUpdate(false)
@@ -1955,9 +1956,25 @@
 #if ENABLE(IOS_TOUCH_EVENTS)
 void WebPage::dispatchTouchEvent(const WebTouchEvent& touchEvent, bool& handled)
 {
+    RefPtr<Frame> oldFocusedFrame = m_page->focusController().focusedFrame();
+    RefPtr<Element> oldFocusedElement = oldFocusedFrame ? oldFocusedFrame->document()->focusedElement() : nullptr;
+    m_userIsInteracting = true;
+
     m_lastInteractionLocation = touchEvent.position();
     CurrentEvent currentEvent(touchEvent);
     handled = handleTouchEvent(touchEvent, m_page.get());
+
+    RefPtr<Frame> newFocusedFrame = m_page->focusController().focusedFrame();
+    RefPtr<Element> newFocusedElement = newFocusedFrame ? newFocusedFrame->document()->focusedElement() : nullptr;
+
+    // If the focus has not changed, we need to notify the client anyway, since it might be
+    // necessary to start assisting the node.
+    // If the node has been focused by _javascript_ without user interaction, the
+    // keyboard is not on screen.
+    if (newFocusedElement && newFocusedElement == oldFocusedElement)
+        elementDidFocus(newFocusedElement.get());
+
+    m_userIsInteracting = false;
 }
 
 void WebPage::touchEventSync(const WebTouchEvent& touchEvent, bool& handled)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (167773 => 167774)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2014-04-24 21:44:42 UTC (rev 167774)
@@ -1162,6 +1162,7 @@
     bool m_hasReceivedVisibleContentRectsAfterDidCommitLoad;
     bool m_scaleWasSetByUIProcess;
     bool m_userHasChangedPageScaleFactor;
+    bool m_userIsInteracting;
     WebCore::FloatSize m_screenSize;
     WebCore::FloatSize m_availableScreenSize;
     WebCore::IntSize m_blockSelectionDesiredSize;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (167773 => 167774)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2014-04-24 21:20:54 UTC (rev 167773)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2014-04-24 21:44:42 UTC (rev 167774)
@@ -312,9 +312,25 @@
     if (WKObservedContentChange() != WKContentNoChange)
         return;
 
+    RefPtr<Frame> oldFocusedFrame = m_page->focusController().focusedFrame();
+    RefPtr<Element> oldFocusedElement = oldFocusedFrame ? oldFocusedFrame->document()->focusedElement() : nullptr;
+    m_userIsInteracting = true;
+
     m_lastInteractionLocation = roundedAdjustedPoint;
     mainframe.eventHandler().handleMousePressEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MousePressed, 1, false, false, false, false, 0));
     mainframe.eventHandler().handleMouseReleaseEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MouseReleased, 1, false, false, false, false, 0));
+
+    RefPtr<Frame> newFocusedFrame = m_page->focusController().focusedFrame();
+    RefPtr<Element> newFocusedElement = newFocusedFrame ? newFocusedFrame->document()->focusedElement() : nullptr;
+
+    // If the focus has not changed, we need to notify the client anyway, since it might be
+    // necessary to start assisting the node.
+    // If the node has been focused by _javascript_ without user interaction, the
+    // keyboard is not on screen.
+    if (newFocusedElement && newFocusedElement == oldFocusedElement)
+        elementDidFocus(newFocusedElement.get());
+
+    m_userIsInteracting = false;
 }
 
 void WebPage::tapHighlightAtPosition(uint64_t requestID, const FloatPoint& position)
@@ -1747,7 +1763,7 @@
         getAssistedNodeInformation(information);
         RefPtr<API::Object> userData;
         m_formClient->willBeginInputSession(this, toElement(node), WebFrame::fromCoreFrame(*node->document().frame()), userData);
-        send(Messages::WebPageProxy::StartAssistingNode(information, InjectedBundleUserMessageEncoder(userData.get())));
+        send(Messages::WebPageProxy::StartAssistingNode(information, m_userIsInteracting, InjectedBundleUserMessageEncoder(userData.get())));
     }
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to