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 6e6b55b..a9b140e 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 bbb7cc6..78d7da3 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 3a0c620..a11d365 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 b467b40..0322ada 100644 (file)
@@ -393,6 +393,7 @@ public:
     void setWindowResizerSize(const WebCore::IntSize&);
     
     void clearSelection();
+    void restoreSelectionInFocusedEditableElement();
 
     void setViewNeedsDisplay(const WebCore::IntRect&);
     void displayView();
index 385411e..6e76570 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 6910d7a..5795059 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 4fcab8b..a7088fe 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)