Title: [181972] trunk/Source/WebKit2
Revision
181972
Author
[email protected]
Date
2015-03-25 14:19:05 -0700 (Wed, 25 Mar 2015)

Log Message

Web Inspector: Switching tabs to window with inspector open prohibits typing into console
https://bugs.webkit.org/show_bug.cgi?id=126800

Reviewed by Anders Carlsson.

This is a regression from r85356 and r83814. These two patches made WKWebView clear its selection
when WKView resigns the first responder without ever restoring it even if WKView later becomes
the first responder again. This is problematic when a text field or a editing host element had been
focused and selected prior to the resignation since the editing code uses the selection to determine
the editability of the element.

Fixed the bug by restoring selection in [WKView becomeFirstResponder] if the selection is empty.

* UIProcess/API/mac/WKView.mm:
(-[WKView becomeFirstResponder]):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::restoreSelectionInFocusedEditableElement):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::restoreSelectionInFocusedEditableElement):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (181971 => 181972)


--- trunk/Source/WebKit2/ChangeLog	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/ChangeLog	2015-03-25 21:19:05 UTC (rev 181972)
@@ -1,3 +1,28 @@
+2015-03-25  Ryosuke Niwa  <[email protected]>
+
+        Web Inspector: Switching tabs to window with inspector open prohibits typing into console
+        https://bugs.webkit.org/show_bug.cgi?id=126800
+
+        Reviewed by Anders Carlsson.
+
+        This is a regression from r85356 and r83814. These two patches made WKWebView clear its selection
+        when WKView resigns the first responder without ever restoring it even if WKView later becomes
+        the first responder again. This is problematic when a text field or a editing host element had been
+        focused and selected prior to the resignation since the editing code uses the selection to determine
+        the editability of the element.
+
+        Fixed the bug by restoring selection in [WKView becomeFirstResponder] if the selection is empty.
+
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView becomeFirstResponder]):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::restoreSelectionInFocusedEditableElement):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::restoreSelectionInFocusedEditableElement):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2015-03-25  Beth Dakin  <[email protected]>
 
         REGRESSION (r181660): Safari navigates to link after a starting and canceling a 

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


--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm	2015-03-25 21:19:05 UTC (rev 181972)
@@ -447,6 +447,8 @@
     
     [self _updateSecureInputState];
     _data->_page->viewStateDidChange(ViewState::IsFocused);
+    // Restore the selection in the editable region if resigning first responder cleared selection.
+    _data->_page->restoreSelectionInFocusedEditableElement();
 
     _data->_inBecomeFirstResponder = false;
     

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (181971 => 181972)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2015-03-25 21:19:05 UTC (rev 181972)
@@ -1444,6 +1444,13 @@
     m_process->send(Messages::WebPage::ClearSelection(), m_pageID);
 }
 
+void WebPageProxy::restoreSelectionInFocusedEditableElement()
+{
+    if (!isValid())
+        return;
+    m_process->send(Messages::WebPage::RestoreSelectionInFocusedEditableElement(), m_pageID);
+}
+
 void WebPageProxy::validateCommand(const String& commandName, std::function<void (const String&, bool, int32_t, CallbackBase::Error)> callbackFunction)
 {
     if (!isValid()) {

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (181971 => 181972)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2015-03-25 21:19:05 UTC (rev 181972)
@@ -393,6 +393,7 @@
     void setWindowResizerSize(const WebCore::IntSize&);
     
     void clearSelection();
+    void restoreSelectionInFocusedEditableElement();
 
     void setViewNeedsDisplay(const WebCore::IntRect&);
     void displayView();

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (181971 => 181972)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2015-03-25 21:19:05 UTC (rev 181972)
@@ -3366,6 +3366,18 @@
 }
 #endif
 
+void WebPage::restoreSelectionInFocusedEditableElement()
+{
+    Frame& frame = m_page->focusController().focusedOrMainFrame();
+    if (!frame.selection().isNone())
+        return;
+
+    if (auto document = frame.document()) {
+        if (auto element = document->focusedElement())
+            element->updateFocusAppearance(true /* restoreSelection */);
+    }
+}
+
 bool WebPage::mainFrameHasCustomContentProvider() const
 {
     if (Frame* frame = mainFrame()) {

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (181971 => 181972)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2015-03-25 21:19:05 UTC (rev 181972)
@@ -683,6 +683,7 @@
 
     void replaceSelectionWithText(WebCore::Frame*, const String&);
     void clearSelection();
+    void restoreSelectionInFocusedEditableElement();
 
 #if ENABLE(DRAG_SUPPORT)
 #if PLATFORM(GTK)

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (181971 => 181972)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-03-25 21:09:18 UTC (rev 181971)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2015-03-25 21:19:05 UTC (rev 181972)
@@ -143,6 +143,7 @@
     DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t navigationID, uint64_t downloadID)
 
     ClearSelection()
+    RestoreSelectionInFocusedEditableElement()
 
     # Callbacks.
     GetContentsAsString(uint64_t callbackID)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to