Source/WebCore: WK2: Cannot set focus on an element when focus is outside of WKView
authorcfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Mar 2011 20:04:42 +0000 (20:04 +0000)
committercfleizach@apple.com <cfleizach@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Mar 2011 20:04:42 +0000 (20:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=55281

Reviewed by Sam Weinig.

In WK2, focus cannot be set from the WebProcess side because there's no platformWidget().
Instead, the focus/unfocus messages need to be sent to the UIProcess side.

* platform/mac/WidgetMac.mm:
(WebCore::Widget::setFocus):

Source/WebKit2: WK2: Cannot set focus on an element when focus is outside of WKView
https://bugs.webkit.org/show_bug.cgi?id=55281

Reviewed by Sam Weinig.

* UIProcess/API/mac/PageClientImpl.h:
* UIProcess/API/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::setFocus):
* UIProcess/API/qt/qwkpage_p.h:
(QWKPagePrivate::setFocus):
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::setFocus):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/win/WebView.h:
(WebKit::WebView::setFocus):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::focus):
(WebKit::WebChromeClient::unfocus):

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/mac/WidgetMac.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/mac/PageClientImpl.h
Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm
Source/WebKit2/UIProcess/API/qt/qwkpage_p.h
Source/WebKit2/UIProcess/PageClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/win/WebView.h
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

index adea477..99202f9 100644 (file)
@@ -1,3 +1,16 @@
+2011-03-08  Chris Fleizach  <cfleizach@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WK2: Cannot set focus on an element when focus is outside of WKView
+        https://bugs.webkit.org/show_bug.cgi?id=55281
+    
+        In WK2, focus cannot be set from the WebProcess side because there's no platformWidget().
+        Instead, the focus/unfocus messages need to be sent to the UIProcess side.
+
+        * platform/mac/WidgetMac.mm:
+        (WebCore::Widget::setFocus):
+
 2011-03-08  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Anders Carlsson.
index 96bcde2..f75faaa 100644 (file)
@@ -115,10 +115,15 @@ void Widget::setFocus(bool focused)
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
  
+    // If there's no platformWidget, WK2 is running. The focus() method needs to be used
+    // to bring focus to the right view on the UIProcess side.
     NSView *view = [platformWidget() _webcore_effectiveFirstResponder];
-    if (Page* page = frame->page())
-        page->chrome()->focusNSView(view);
-    
+    if (Page* page = frame->page()) {
+        if (!platformWidget())
+            page->chrome()->focus();
+        else
+            page->chrome()->focusNSView(view);
+    }
     END_BLOCK_OBJC_EXCEPTIONS;
 }
 
index 966c025..36eb0c7 100644 (file)
@@ -1,3 +1,26 @@
+2011-03-08  Chris Fleizach  <cfleizach@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        WK2: Cannot set focus on an element when focus is outside of WKView
+        https://bugs.webkit.org/show_bug.cgi?id=55281
+
+        * UIProcess/API/mac/PageClientImpl.h:
+        * UIProcess/API/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::setFocus):
+        * UIProcess/API/qt/qwkpage_p.h:
+        (QWKPagePrivate::setFocus):
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::setFocus):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/win/WebView.h:
+        (WebKit::WebView::setFocus):
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::focus):
+        (WebKit::WebChromeClient::unfocus):
+
 2011-03-08  Jeff Miller  <jeffm@apple.com>
 
         Unreviewed, fix last change so WKBaseWin.h is in alphabetical order in the project XML.
index 51b6461..7b6f53d 100644 (file)
@@ -62,6 +62,7 @@ private:
     virtual void processDidCrash();
     virtual void pageClosed();
     virtual void didRelaunchProcess();
+    virtual void setFocus(bool focused);
     virtual void takeFocus(bool direction);
     virtual void toolTipChanged(const String& oldToolTip, const String& newToolTip);
     virtual void setCursor(const WebCore::Cursor&);
index 81859dc..30385f0 100644 (file)
@@ -195,6 +195,15 @@ void PageClientImpl::didRelaunchProcess()
     [m_wkView _didRelaunchProcess];
 }
 
+void PageClientImpl::setFocus(bool focused)
+{
+    if (focused)
+        [[m_wkView window] makeFirstResponder:m_wkView];
+    else
+        // takeFocus in this context means take focus away from the WKView.
+        takeFocus(true);
+}
+    
 void PageClientImpl::takeFocus(bool direction)
 {
     [m_wkView _takeFocus:direction];
index ba6c8d1..79506a6 100644 (file)
@@ -72,6 +72,7 @@ public:
     virtual void setCursor(const WebCore::Cursor&);
     virtual void setViewportArguments(const WebCore::ViewportArguments&);
     virtual void takeFocus(bool direction);
+    virtual void setFocus(bool focused) { }
     virtual void toolTipChanged(const WTF::String&, const WTF::String&);
     virtual void registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo);
     virtual void clearAllEditCommands();
index 765885e..0e3a61e 100644 (file)
@@ -81,6 +81,7 @@ public:
     virtual void didRelaunchProcess() = 0;
     virtual void pageClosed() = 0;
 
+    virtual void setFocus(bool focused) = 0;
     virtual void takeFocus(bool direction) = 0;
     virtual void toolTipChanged(const String&, const String&) = 0;
 
index 76e9597..191b47a 100644 (file)
@@ -2346,6 +2346,11 @@ void WebPageProxy::ignoreWord(const String& word)
 
 // Other
 
+void WebPageProxy::setFocus(bool focused)
+{
+    m_pageClient->setFocus(focused);
+}
+
 void WebPageProxy::takeFocus(bool direction)
 {
     m_pageClient->takeFocus(direction);
index b6bcd08..1e7fadb 100644 (file)
@@ -611,6 +611,7 @@ private:
     void learnWord(const String& word);
     void ignoreWord(const String& word);
 
+    void setFocus(bool focused);
     void takeFocus(bool direction);
     void setToolTip(const String&);
     void setCursor(const WebCore::Cursor&);
index c481126..9c6da03 100644 (file)
@@ -35,6 +35,7 @@ messages -> WebPageProxy {
     SetCursor(WebCore::Cursor cursor)
     SetStatusText(WTF::String statusText)
     SetToolTip(WTF::String toolTip)
+    SetFocus(bool focused)
     TakeFocus(bool direction)
     FocusedFrameChanged(uint64_t frameID)
     FrameSetLargestFrameChanged(uint64_t frameID)
index d2b79a0..6cbacdf 100644 (file)
@@ -144,6 +144,7 @@ private:
     virtual void didRelaunchProcess();
     virtual void pageClosed();
     virtual void takeFocus(bool direction);
+    virtual void setFocus(bool focused) { }
     virtual void toolTipChanged(const WTF::String&, const WTF::String&);
     virtual void setCursor(const WebCore::Cursor&);
     virtual void setViewportArguments(const WebCore::ViewportArguments&);
index dd0a356..b00d350 100644 (file)
@@ -121,12 +121,12 @@ float WebChromeClient::scaleFactor()
 
 void WebChromeClient::focus()
 {
-    notImplemented();
+    m_page->send(Messages::WebPageProxy::SetFocus(true));
 }
 
 void WebChromeClient::unfocus()
 {
-    notImplemented();
+    m_page->send(Messages::WebPageProxy::SetFocus(false));
 }
 
 bool WebChromeClient::canTakeFocus(FocusDirection)