[Engine] Support custom js event regarding state change of softkeyboard(ime)
authorYunchan Cho <yunchan.cho@samsung.com>
Tue, 6 Nov 2012 07:22:29 +0000 (16:22 +0900)
committerYunchan Cho <yunchan.cho@samsung.com>
Thu, 15 Nov 2012 07:04:14 +0000 (16:04 +0900)
[Issue#] There is needs that wrt fires custom js event on state change of softkeyboard
[Problem] N/A
[Cause] N/A
[Solution] register smart callback for softkeyboardchange event,
           and request to injected bundle to fire custome js event for softkeyboardchange

Change-Id: I71f988013440f4bd1fdcfae73844eeb9ba3c94c9

src/view/webkit/bundles/plugin_module_support.cpp
src/view/webkit/bundles/wrt-wk2-bundle.cpp
src/view/webkit/view_logic.cpp
src/view/webkit/view_logic.h

index 6abfc93..146d73f 100644 (file)
@@ -129,7 +129,15 @@ void dispatchJavaScriptEvent(
     str << eventType;
 
     // if needed, arguments for event should be set here
-    // do something
+    if (eventType == SoftKeyboardChangeCustomEvent) {
+        if (data) {
+            SoftKeyboardChangeArgs* args =
+                static_cast<SoftKeyboardChangeArgs *>(data);
+            str << " " << args->state;
+            str << " " << args->width;
+            str << " " << args->height;
+        }
+    }
 
     std::string msgString = str.str();
     const char* msg = msgString.c_str();
index a61e1e9..aeefceb 100644 (file)
@@ -386,8 +386,14 @@ void Bundle::didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody)
         std::stringstream ss(text);
         ss >> eventType;
 
+        using namespace WrtPlugins::W3C;
         // set arguments to be sent to js handler of this custom event
-        // do something
+        if (eventType == SoftKeyboardChangeCustomEvent) {
+            args = new SoftKeyboardChangeArgs;
+            ss >> static_cast<SoftKeyboardChangeArgs *>(args)->state;
+            ss >> static_cast<SoftKeyboardChangeArgs *>(args)->width;
+            ss >> static_cast<SoftKeyboardChangeArgs *>(args)->height;
+        }
 
         //apply for each context
         PageGlobalContext::iterator it = m_pageGlobalContext.begin();
index 0eb14c9..30fe6f8 100644 (file)
@@ -68,6 +68,9 @@ const char * const URICHANGE_PLUGIN_NO_CHANGE = "plugin_no_change";
 const char * const URICHANGE_BLOCKED_URL = "null";
 const char* PATTERN_URI_CHANGE = "^(([^:/\\?#]+)://[^\\?#]*)";
 const int MAX_NUM_CONTEXT_MENU_ITEMS = 10;
+// IME State value
+const char * const IME_STATE_ON = "on";
+const char * const IME_STATE_OFF = "off";
 
 // WKPageLoaderClient
 const char * const EWK_LOAD_STARTED = "load,started";
@@ -107,6 +110,10 @@ const char * const EWK_FULLSCREEN_EXIT = "fullscreen,exitfullscreen";
 // DataBase Use Ask Title
 const char * const DATABASE_USE_ASK_TITLE = "Increase Database Size?";
 const char * const FILESYSTEM_USE_ASK_TITLE = "Use FileSystem?";
+
+// IME Callback
+const char * const EWK_INPUTMETHOD_CHANGED = "inputmethod,changed";
+const char * const EWK_EDITORCLIENT_IME_CLOSED = "editorclient,ime,closed";
 }
 
 ViewLogic::ViewLogic():
@@ -631,6 +638,35 @@ void ViewLogic::ewkClientInit(Evas_Object *wkView) {
         EWK_FULLSCREEN_EXIT,
         exitFullscreenCallback,
         this);
+
+
+     // when ime start to be showed on the webview,
+     // this callback will be called 
+    evas_object_smart_callback_add(
+        wkView,
+        EWK_INPUTMETHOD_CHANGED,
+        imeOpenCallback,
+        this);
+
+    // this callback will be called
+    //  when ime finishes to be showed on the webview
+    // "event_info" arg of this callback is always NULL point
+    // if web content should know size of ime,
+    //  use "inputmethod,changed" instead of this.
+    //
+    //evas_object_smart_callback_add(
+    //        wkView,
+    //        "editorclient,ime,opened",
+    //        imeSomethingCallback,
+    //        this);
+
+    // when ime finished to be hidden,
+    // this callback will be called
+    evas_object_smart_callback_add(
+        wkView,
+        EWK_EDITORCLIENT_IME_CLOSED,
+        imeCloseCallback,
+        this);
 }
 
 void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
@@ -744,6 +780,16 @@ void ViewLogic::ewkClientDeinit(Evas_Object *wkView) {
         wkView,
         NULL,
         NULL);
+
+    // ime show/hide callback
+    evas_object_smart_callback_del(
+        wkView,
+        EWK_INPUTMETHOD_CHANGED,
+        imeOpenCallback);
+    evas_object_smart_callback_del(
+        wkView,
+        EWK_EDITORCLIENT_IME_CLOSED,
+        imeCloseCallback);
 }
 
 void ViewLogic::createEwkView()
@@ -1487,6 +1533,45 @@ void ViewLogic::exitFullscreenCallback(
     }
 }
 
+void ViewLogic::imeOpenCallback(
+        void* data,
+        Evas_Object* /*obj*/,
+        void* eventInfo)
+{
+    LogDebug("enter");
+    Assert(data);
+    Assert(eventInfo);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+    Eina_Rectangle *rect = static_cast<Eina_Rectangle *>(eventInfo);
+
+    using namespace WrtPlugins::W3C;
+    SoftKeyboardChangeArgs args;
+    args.state = IME_STATE_ON;
+    args.width = rect->w;
+    args.height = rect->h;
+    This->fireJavascriptEvent(
+            static_cast<int>(SoftKeyboardChangeCustomEvent),
+            &args);
+}
+
+void ViewLogic::imeCloseCallback(
+        void* data,
+        Evas_Object* /*obj*/,
+        void* /*eventInfo*/)
+{
+    LogDebug("enter");
+    Assert(data);
+    ViewLogic* This = static_cast<ViewLogic*>(data);
+
+    using namespace WrtPlugins::W3C;
+    SoftKeyboardChangeArgs args;
+    args.state = IME_STATE_OFF;
+
+    This->fireJavascriptEvent(
+            static_cast<int>(SoftKeyboardChangeCustomEvent),
+            &args);
+}
+
 void ViewLogic::didRunJavaScriptCallback(
         Evas_Object* /*obj*/,
         const char* result,
index 413af9e..89ccd05 100644 (file)
@@ -202,6 +202,16 @@ class ViewLogic : public ViewModule::IViewModule
             Evas_Object* obj,
             void* eventInfo);
 
+    // EWK IME Show/Hide Callback
+    static void imeOpenCallback(
+            void* data,
+            Evas_Object* obj,
+            void* eventInfo);
+    static void imeCloseCallback(
+            void* data,
+            Evas_Object* obj,
+            void* eventInfo);
+
     // JS execute callback
     static void didRunJavaScriptCallback(
             Evas_Object* obj,