2007-12-11 George Wright <george.wright@collabora.co.uk>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2007 00:05:08 +0000 (00:05 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 12 Dec 2007 00:05:08 +0000 (00:05 +0000)
        Reviewed by Alp Toker.

        http://bugs.webkit.org/show_bug.cgi?id=14120
        [GDK] Support input methods

        This patch adds infrastructure for input method support.

        It also adds Hildon features for the Maemo mobile platform sufficient
        to support the virtual keyboard.

        * WebCoreSupport/EditorClientGtk.cpp:
        (WebKit::imContextCommitted):
        (WebKit::EditorClient::EditorClient):
        (WebKit::EditorClient::~EditorClient):
        (WebKit::EditorClient::textFieldDidBeginEditing):
        (WebKit::EditorClient::textFieldDidEndEditing):
        * WebCoreSupport/EditorClientGtk.h:
        * WebView/webkitprivate.h:
        * WebView/webkitwebview.cpp:

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

WebKit/gtk/ChangeLog
WebKit/gtk/WebCoreSupport/EditorClientGtk.cpp
WebKit/gtk/WebCoreSupport/EditorClientGtk.h
WebKit/gtk/WebView/webkitprivate.h
WebKit/gtk/WebView/webkitwebview.cpp

index d73117e..c680385 100644 (file)
@@ -1,3 +1,25 @@
+2007-12-11  George Wright  <george.wright@collabora.co.uk>
+
+        Reviewed by Alp Toker.
+
+        http://bugs.webkit.org/show_bug.cgi?id=14120
+        [GDK] Support input methods
+
+        This patch adds infrastructure for input method support.
+
+        It also adds Hildon features for the Maemo mobile platform sufficient
+        to support the virtual keyboard.
+
+        * WebCoreSupport/EditorClientGtk.cpp:
+        (WebKit::imContextCommitted):
+        (WebKit::EditorClient::EditorClient):
+        (WebKit::EditorClient::~EditorClient):
+        (WebKit::EditorClient::textFieldDidBeginEditing):
+        (WebKit::EditorClient::textFieldDidEndEditing):
+        * WebCoreSupport/EditorClientGtk.h:
+        * WebView/webkitprivate.h:
+        * WebView/webkitwebview.cpp:
+
 2007-12-07  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Darin.
index fb43879..fc76347 100644 (file)
@@ -48,6 +48,13 @@ using namespace WebCore;
 
 namespace WebKit {
 
+static void imContextCommitted(GtkIMContext* context, const char* str, EditorClient* client)
+{
+    WebKitWebViewPrivate* pageData = WEBKIT_WEB_VIEW_GET_PRIVATE(client->m_page);
+    Frame* frame = pageData->corePage->focusController()->focusedOrMainFrame();
+    frame->editor()->insertTextWithoutSendingTextEvent(str, false);
+}
+
 bool EditorClient::shouldDeleteRange(Range*)
 {
     notImplemented();
@@ -360,16 +367,29 @@ void EditorClient::handleInputMethodKeydown(KeyboardEvent*)
 EditorClient::EditorClient(WebKitWebView* page)
     : m_page(page)
 {
+    WebKitWebViewPrivate* pageData = WEBKIT_WEB_VIEW_GET_PRIVATE(m_page);
+    g_signal_connect(pageData->imContext, "commit", G_CALLBACK(imContextCommitted), this);
+}
+
+EditorClient::~EditorClient()
+{
+    WebKitWebViewPrivate* pageData = WEBKIT_WEB_VIEW_GET_PRIVATE(m_page);
+    g_signal_handlers_disconnect_by_func(pageData->imContext, (gpointer)imContextCommitted, this);
 }
 
 void EditorClient::textFieldDidBeginEditing(Element*)
 {
-    notImplemented();
+    gtk_im_context_focus_in(WEBKIT_WEB_VIEW_GET_PRIVATE(m_page)->imContext);
 }
 
 void EditorClient::textFieldDidEndEditing(Element*)
 {
-    notImplemented();
+    WebKitWebViewPrivate* pageData = WEBKIT_WEB_VIEW_GET_PRIVATE(m_page);
+
+    gtk_im_context_focus_out(pageData->imContext);
+#ifdef MAEMO_CHANGES
+    hildon_gtk_im_context_hide(pageData->imContext);
+#endif
 }
 
 void EditorClient::textDidChangeInTextField(Element*)
index 1a0f27d..ce741a9 100644 (file)
@@ -45,6 +45,7 @@ namespace WebKit {
     class EditorClient : public WebCore::EditorClient {
     public:
         EditorClient(WebKitWebView*);
+        ~EditorClient();
 
         // from EditorClient
         virtual void pageDestroyed();
@@ -108,7 +109,6 @@ namespace WebKit {
         virtual void getGuessesForWord(const WebCore::String&, WTF::Vector<WebCore::String>& guesses);
         virtual void setInputMethodState(bool enabled);
 
-    private:
         WebKitWebView* m_page;
     };
 }
index 841b0ee..df70be4 100644 (file)
@@ -61,6 +61,7 @@ extern "C" {
 
         HashSet<GtkWidget*> children;
         bool editable;
+        GtkIMContext* imContext;
     };
 
     #define WEBKIT_WEB_FRAME_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_FRAME, WebKitWebFramePrivate))
index 1ec76f8..f911816 100644 (file)
@@ -39,6 +39,7 @@
 #include "ChromeClientGtk.h"
 #include "ContextMenuClientGtk.h"
 #include "DragClientGtk.h"
+#include "Editor.h"
 #include "EditorClientGtk.h"
 #include "EventHandler.h"
 #include "FocusController.h"
@@ -171,6 +172,19 @@ static gboolean webkit_web_view_button_release_event(GtkWidget* widget, GdkEvent
 {
     Frame* frame = core(webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(widget)));
 
+    WebKitWebView* web_view = WEBKIT_WEB_VIEW(widget);
+    WebKitWebViewPrivate* webViewData = WEBKIT_WEB_VIEW_GET_PRIVATE(web_view);
+    Frame* focusedFrame = webViewData->corePage->focusController()->focusedFrame();
+
+    if (focusedFrame->editor()->canEdit()) {
+        GdkWindow* window = gtk_widget_get_parent_window(widget);
+        gtk_im_context_set_client_window(webViewData->imContext, window);
+#ifdef MAEMO_CHANGES
+        hildon_gtk_im_context_filter_event(webViewData->imContext, (GdkEvent*)event);
+        hildon_gtk_im_context_show(webViewData->imContext);
+#endif
+    }
+
     return frame->eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
 }
 
@@ -419,6 +433,7 @@ static void webkit_web_view_finalize(GObject* object)
     delete webViewData->corePage;
     delete webViewData->settings;
     g_object_unref(webViewData->mainFrame);
+    g_object_unref(webViewData->imContext);
     delete webViewData->userAgent;
 
     G_OBJECT_CLASS(webkit_web_view_parent_class)->finalize(object);
@@ -787,6 +802,7 @@ static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass)
 static void webkit_web_view_init(WebKitWebView* webView)
 {
     WebKitWebViewPrivate* webViewData = WEBKIT_WEB_VIEW_GET_PRIVATE(WEBKIT_WEB_VIEW(webView));
+    webViewData->imContext = gtk_im_multicontext_new();
     webViewData->corePage = new Page(new WebKit::ChromeClient(webView), new WebKit::ContextMenuClient, new WebKit::EditorClient(webView), new WebKit::DragClient, new WebKit::InspectorClient);
 
     Settings* settings = webViewData->corePage->settings();