Web Inspector: Switching tabs to window with inspector open prohibits typing into...
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2015 21:19:05 +0000 (21:19 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Mar 2015 21:19:05 +0000 (21:19 +0000)
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:

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index 6e6b55b9b0996a714011118e07c1edce77c953cc..a9b140e793eef3313e0f1f510a05caf996f6fc56 100644 (file)
@@ -1,3 +1,28 @@
+2015-03-25  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <bdakin@apple.com>
 
         REGRESSION (r181660): Safari navigates to link after a starting and canceling a 
index bbb7cc67b437ddb8b385f6e1f7214a5100a0c170..78d7da340116748f0414b474bdd64b8160e43a57 100644 (file)
@@ -447,6 +447,8 @@ struct WKViewInterpretKeyEventsParameters {
     
     [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;
     
index 3a0c62047d20df74dd6e28456cb04919416eda6c..a11d365dee04c73039124d40e29813b0c2c8f284 100644 (file)
@@ -1444,6 +1444,13 @@ void WebPageProxy::clearSelection()
     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()) {
index b467b4032e24f107f643f37a01ff48f402af4ddb..0322ada7d551b1aa2ba294ea6c8e9c7fd48fdd21 100644 (file)
@@ -393,6 +393,7 @@ public:
     void setWindowResizerSize(const WebCore::IntSize&);
     
     void clearSelection();
+    void restoreSelectionInFocusedEditableElement();
 
     void setViewNeedsDisplay(const WebCore::IntRect&);
     void displayView();
index 385411ef8ea5e95716f4e46c5b0305e83adfc27b..6e76570fa788589042b07f4a62d4f5cf31199f2c 100644 (file)
@@ -3366,6 +3366,18 @@ void WebPage::clearSelection()
 }
 #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()) {
index 6910d7a3f532e63540290fe4dcc3a75e3bcafff0..579505942ae34a86ebcb9e5893804634421d8a93 100644 (file)
@@ -683,6 +683,7 @@ public:
 
     void replaceSelectionWithText(WebCore::Frame*, const String&);
     void clearSelection();
+    void restoreSelectionInFocusedEditableElement();
 
 #if ENABLE(DRAG_SUPPORT)
 #if PLATFORM(GTK)
index 4fcab8b024799244d73c12b2d3b539b7ad08a9fc..a7088fe0848707cd2cc376c810b24c7ef8bc034a 100644 (file)
@@ -143,6 +143,7 @@ messages -> WebPage LegacyReceiver {
     DidReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, uint32_t policyAction, uint64_t navigationID, uint64_t downloadID)
 
     ClearSelection()
+    RestoreSelectionInFocusedEditableElement()
 
     # Callbacks.
     GetContentsAsString(uint64_t callbackID)