[WebView] Dispatch input focus events to WebView.

This changelist passes back focus events from the WebEditorClient
to the WebView.

Test: manual
Change-Id: Id0f0d62c262a9101695cb2d6083100aa2a63f443
diff --git a/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.cpp b/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.cpp
index c820251..507fbbe 100644
--- a/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.cpp
+++ b/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.cpp
@@ -24,6 +24,11 @@
 using namespace WebCore;
 using namespace std;
 
+WebEditorClient::WebEditorClient(InputFocusDelegate delegate)
+{
+    m_inputFocusDelegate = delegate;
+}
+
 bool WebEditorClient::shouldDeleteRange(Range* range)
 {
     return true;
@@ -410,8 +415,7 @@
 
 void WebEditorClient::setInputMethodState(bool enabled)
 {
-    notImplemented();
-    UNUSED_PARAM(enabled);
+    m_inputFocusDelegate(enabled);
 }
 
 bool WebEditorClient::supportsGlobalSelection()
diff --git a/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.h b/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.h
index b6df768..f65def9 100644
--- a/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.h
+++ b/Source/WebKit/fuchsia/WebCoreSupport/WebEditorClient.h
@@ -5,10 +5,15 @@
 
 namespace WebKit {
 
+typedef std::function<void(bool)> InputFocusDelegate;
+
 class WebEditorClient final : public WebCore::EditorClient, public WebCore::TextCheckerClient {
 public:
+    WebEditorClient(InputFocusDelegate delegate);
 
 private:
+    InputFocusDelegate m_inputFocusDelegate;
+
     bool shouldDeleteRange(WebCore::Range*) final;
     bool smartInsertDeleteEnabled() final;
     bool isSelectTrailingWhitespaceEnabled() final;
diff --git a/Source/WebKit/fuchsia/WebView.cpp b/Source/WebKit/fuchsia/WebView.cpp
index 947617e..ef8fec9 100644
--- a/Source/WebKit/fuchsia/WebView.cpp
+++ b/Source/WebKit/fuchsia/WebView.cpp
@@ -168,7 +168,11 @@
 
     if (m_page == nullptr) {
         IntSize targetSize(targetWidth, targetHeight);
-        PageConfiguration pageConfiguration(makeUniqueRef<WebKit::WebEditorClient>(), SocketProvider::create());
+        std::function<void(bool)> delegate = [=](bool focused) {
+            this->dispatchInputFocusChange(focused);
+        };
+
+        PageConfiguration pageConfiguration(makeUniqueRef<WebKit::WebEditorClient>(delegate), SocketProvider::create());
         fillWithEmptyClients(pageConfiguration);
         m_frameLoaderClient = new WebFrameLoaderClient(targetSize, this);
         pageConfiguration.loaderClientForMainFrame = m_frameLoaderClient;
@@ -398,10 +402,20 @@
   }
 }
 
+void WebView::dispatchInputFocusChange(bool focused) {
+  if (m_inputFocusDelegate) {
+    m_inputFocusDelegate(focused);
+  }
+}
+
 void WebView::setWebRequestDelegate(WebRequestDelegate delegate) {
   m_webRequestDelegate = delegate;
 }
 
+void WebView::setInputFocusDelegate(InputFocusDelegate delegate) {
+  m_inputFocusDelegate = delegate;
+}
+
 void WebView::setDidFinishLoadDelegate(DidFinishLoadDelegate delegate) {
   m_didFinishLoadDelegate = delegate;
 }
diff --git a/Source/WebKit/fuchsia/WebView.h b/Source/WebKit/fuchsia/WebView.h
index 17d9814..1dd0cea 100644
--- a/Source/WebKit/fuchsia/WebView.h
+++ b/Source/WebKit/fuchsia/WebView.h
@@ -45,6 +45,7 @@
 typedef struct _cairo cairo_t;
 typedef struct _cairo_surface cairo_surface_t;
 typedef std::function<std::string(const std::string&)> WebRequestDelegate;
+typedef std::function<void(bool)> InputFocusDelegate;
 typedef std::function<void()> DidFinishLoadDelegate;
 typedef std::function<void()> CustomEventHandler;
 
@@ -81,6 +82,8 @@
     bool handleKeyEvent(uint8_t keycode, uint8_t charValue, bool pressed, bool repeat);
 
     void setWebRequestDelegate(WebRequestDelegate delegate);
+    void setInputFocusDelegate(InputFocusDelegate delegate);
+    void dispatchInputFocusChange(bool focused);
     void dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
 
     void setDidFinishLoadDelegate(DidFinishLoadDelegate delegate);
@@ -111,6 +114,7 @@
 
 private:
     WebRequestDelegate m_webRequestDelegate;
+    InputFocusDelegate m_inputFocusDelegate;
     DidFinishLoadDelegate m_didFinishLoadDelegate;
 
     void setURLInternal(const WebCore::URL& url);